AssetDictionary.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function AssetDictionary::onAdd(%this)
  23. {
  24. %this.newButton = new GuiButtonCtrl()
  25. {
  26. class = "NewAssetButton";
  27. Position = "5 27";
  28. Extent = "300 30";
  29. HorizSizing = "width";
  30. VertSizing = "height";
  31. Text = "New";
  32. };
  33. ThemeManager.setProfile(%this.newButton, "buttonProfile");
  34. %this.add(%this.newButton);
  35. %this.grid = new GuiGridCtrl()
  36. {
  37. Position="0 62";
  38. Extent = "310 50";
  39. HorizSizing = "width";
  40. VertSizing = "height";
  41. CellSizeX = 60;
  42. CellSizeY = 60;
  43. CellModeX = variable;
  44. CellSpacingX = 4;
  45. CellSpacingY = 4;
  46. OrderMode = "LRTB";
  47. };
  48. ThemeManager.setProfile(%this.grid, "emptyProfile");
  49. %this.add(%this.grid);
  50. }
  51. function AssetDictionary::load(%this)
  52. {
  53. %query = new AssetQuery();
  54. AssetDatabase.findAllAssets(%query);
  55. AssetDatabase.findAssetType(%query, %this.Type, true);
  56. for(%i = 0; %i < %query.getCount(); %i++)
  57. {
  58. %assetID = %query.getAsset(%i);
  59. if(!AssetDatabase.isAssetInternal(%assetID))
  60. {
  61. %this.addButton(%assetID);
  62. }
  63. }
  64. %query.delete();
  65. %this.newButton.text = "New" SPC %this.type;
  66. %this.newButton.type = %this.type;
  67. }
  68. function AssetDictionary::addButton(%this, %assetID)
  69. {
  70. %button = new GuiButtonCtrl()
  71. {
  72. Class = AssetDictionaryButton;
  73. HorizSizing="center";
  74. VertSizing="center";
  75. Extent = "100 100";
  76. Tooltip = AssetDatabase.getAssetName(%assetID);
  77. Text = "";
  78. AssetID = %assetID;
  79. Type = %this.Type;
  80. };
  81. ThemeManager.setProfile(%button, "itemSelectProfile");
  82. ThemeManager.setProfile(%button, "tipProfile", "TooltipProfile");
  83. %this.grid.add(%button);
  84. %this.fixSize();
  85. return %button;
  86. }
  87. function AssetDictionary::removeButton(%this, %assetID)
  88. {
  89. %button = %this.getButton(%assetID);
  90. if(isObject(%button))
  91. {
  92. %button.delete();
  93. %this.fixSize();
  94. return true;
  95. }
  96. return false;
  97. }
  98. function AssetDictionary::fixSize(%this)
  99. {
  100. if(%this.getExpanded())
  101. {
  102. %this.setExpanded(false);
  103. %this.setExpanded(true);
  104. }
  105. }
  106. function AssetDictionary::getButton(%this, %assetID)
  107. {
  108. for(%i = 0; %i < %this.grid.getCount(); %i++)
  109. {
  110. %button = %this.grid.getObject(%i);
  111. if(%button.AssetID $= %assetID)
  112. {
  113. return %button;
  114. }
  115. }
  116. return 0;
  117. }
  118. function AssetDictionary::unload(%this)
  119. {
  120. //Remove all the child gui controls
  121. for(%i = %this.grid.getCount() - 1; %i >= 0; %i--)
  122. {
  123. %obj = %this.grid.getObject(%i);
  124. %obj.delete();
  125. }
  126. }
  127. function AssetDictionary::reload(%this)
  128. {
  129. %this.unload();
  130. %this.load();
  131. }
  132. function AssetDictionarySprite::onAnimationEnd(%this, %animationAssetID)
  133. {
  134. %this.schedule(2000, "restartAnimation", %animationAssetID);
  135. }
  136. function AssetDictionarySprite::restartAnimation(%this, %animationAssetID)
  137. {
  138. %this.setAnimation(%animationAssetID);
  139. }