AssetDictionary.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. Text = "New";
  30. };
  31. ThemeManager.setProfile(%this.newButton, "buttonProfile");
  32. %this.add(%this.newButton);
  33. %this.grid = new GuiGridCtrl()
  34. {
  35. Position="0 62";
  36. Extent = "310 50";
  37. CellSizeX = 60;
  38. CellSizeY = 60;
  39. CellModeX = variable;
  40. CellSpacingX = 4;
  41. CellSpacingY = 4;
  42. OrderMode = "LRTB";
  43. };
  44. ThemeManager.setProfile(%this.grid, "emptyProfile");
  45. %this.add(%this.grid);
  46. }
  47. function AssetDictionary::load(%this)
  48. {
  49. %query = new AssetQuery();
  50. AssetDatabase.findAllAssets(%query);
  51. AssetDatabase.findAssetType(%query, %this.Type, true);
  52. for(%i = 0; %i < %query.getCount(); %i++)
  53. {
  54. %assetID = %query.getAsset(%i);
  55. if(!AssetDatabase.isAssetInternal(%assetID))
  56. {
  57. %this.addButton(%assetID);
  58. }
  59. }
  60. %query.delete();
  61. %this.newButton.text = "New" SPC %this.type;
  62. %this.newButton.type = %this.type;
  63. }
  64. function AssetDictionary::addButton(%this, %assetID)
  65. {
  66. %button = new GuiButtonCtrl()
  67. {
  68. Class = AssetDictionaryButton;
  69. HorizSizing="center";
  70. VertSizing="center";
  71. Extent = "100 100";
  72. Tooltip = AssetDatabase.getAssetName(%assetID);
  73. Text = "";
  74. AssetID = %assetID;
  75. Type = %this.Type;
  76. };
  77. ThemeManager.setProfile(%button, "itemSelectProfile");
  78. ThemeManager.setProfile(%button, "tipProfile", "TooltipProfile");
  79. %this.grid.add(%button);
  80. %this.fixSize();
  81. return %button;
  82. }
  83. function AssetDictionary::removeButton(%this, %assetID)
  84. {
  85. %button = %this.getButton(%assetID);
  86. if(isObject(%button))
  87. {
  88. %button.delete();
  89. %this.fixSize();
  90. return true;
  91. }
  92. return false;
  93. }
  94. function AssetDictionary::fixSize(%this)
  95. {
  96. if(%this.getExpanded())
  97. {
  98. %this.setExpanded(false);
  99. %this.setExpanded(true);
  100. }
  101. }
  102. function AssetDictionary::getButton(%this, %assetID)
  103. {
  104. for(%i = 0; %i < %this.grid.getCount(); %i++)
  105. {
  106. %button = %this.grid.getObject(%i);
  107. if(%button.AssetID $= %assetID)
  108. {
  109. return %button;
  110. }
  111. }
  112. return 0;
  113. }
  114. function AssetDictionary::unload(%this)
  115. {
  116. //Remove all the child gui controls
  117. for(%i = %this.grid.getCount() - 1; %i >= 0; %i--)
  118. {
  119. %obj = %this.grid.getObject(%i);
  120. %obj.delete();
  121. }
  122. }
  123. function AssetDictionary::reload(%this)
  124. {
  125. %this.unload();
  126. %this.load();
  127. }
  128. function AssetDictionarySprite::onAnimationEnd(%this, %animationAssetID)
  129. {
  130. %this.schedule(2000, "restartAnimation", %animationAssetID);
  131. }
  132. function AssetDictionarySprite::restartAnimation(%this, %animationAssetID)
  133. {
  134. %this.setAnimation(%animationAssetID);
  135. }