AssetDictionaryButton.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 AssetDictionaryButton::onAdd(%this)
  23. {
  24. %this.call("load" @ %this.type, %this.assetID);
  25. }
  26. function AssetDictionaryButton::loadImageAsset(%this, %assetID)
  27. {
  28. %imageAsset = AssetDatabase.acquireAsset(%assetID);
  29. %texture = %this.buildIcon();
  30. %texture.setImage(%assetID);
  31. %this.ImageAsset = %imageAsset;
  32. %this.ImageAssetID = %assetID;
  33. %this.add(%texture);
  34. }
  35. function AssetDictionaryButton::loadAnimationAsset(%this, %assetID)
  36. {
  37. %animationAsset = AssetDatabase.acquireAsset(%assetID);
  38. %imageAssetID = %animationAsset.getImage();
  39. %imageAsset = AssetDatabase.acquireAsset(%imageAssetID);
  40. %texture = %this.buildIcon();
  41. %texture.setAnimation(%assetID);
  42. %this.ImageAsset = %imageAsset;
  43. %this.imageAssetID = %imageAssetID;
  44. %this.AnimationAsset = %animationAsset;
  45. %this.AnimationAssetID = %assetID;
  46. %this.add(%texture);
  47. }
  48. function AssetDictionaryButton::loadParticleAsset(%this, %assetID)
  49. {
  50. %particleAsset = AssetDatabase.acquireAsset(%assetID);
  51. %texture = %this.buildIcon();
  52. %texture.setImage("AssetAdmin:assetIcons");
  53. %texture.setImageFrame(0);
  54. %this.particleAsset = %particleAsset;
  55. %this.particleAssetID = %assetID;
  56. %this.add(%texture);
  57. }
  58. function AssetDictionaryButton::loadFontAsset(%this, %assetID)
  59. {
  60. %fontAsset = AssetDatabase.acquireAsset(%assetID);
  61. %texture = %this.buildIcon();
  62. %texture.setImage("AssetAdmin:assetIcons");
  63. %texture.setImageFrame(1);
  64. %this.fontAsset = %fontAsset;
  65. %this.fontAssetID = %assetID;
  66. %this.add(%texture);
  67. }
  68. function AssetDictionaryButton::loadAudioAsset(%this, %assetID)
  69. {
  70. %audioAsset = AssetDatabase.acquireAsset(%assetID);
  71. %texture = %this.buildIcon();
  72. %texture.setImage("AssetAdmin:assetIcons");
  73. %texture.setImageFrame(3);
  74. %this.audioAsset = %audioAsset;
  75. %this.audioAssetID = %assetID;
  76. %this.add(%texture);
  77. }
  78. function AssetDictionaryButton::loadSpineAsset(%this, %assetID)
  79. {
  80. %spineAsset = AssetDatabase.acquireAsset(%assetID);
  81. %texture = %this.buildIcon();
  82. %texture.setImage("AssetAdmin:assetIcons");
  83. %texture.setImageFrame(2);
  84. %this.spineAsset = %spineAsset;
  85. %this.spineAssetID = %assetID;
  86. %this.add(%texture);
  87. }
  88. function AssetDictionaryButton::buildIcon(%this)
  89. {
  90. %texture = new GuiSpriteCtrl()
  91. {
  92. class = "AssetDictionarySprite";
  93. HorizSizing="center";
  94. VertSizing="center";
  95. Extent = "50 50";
  96. minExtent = "50 50";
  97. Position = "0 0";
  98. constrainProportions = "1";
  99. fullSize = "1";
  100. };
  101. ThemeManager.setProfile(%texture, "spriteProfile");
  102. return %texture;
  103. }
  104. function AssetDictionaryButton::onClick(%this)
  105. {
  106. %firstLoad = false;
  107. if(AssetAdmin.chosenButton != %this)
  108. {
  109. if(isObject(AssetAdmin.chosenButton))
  110. {
  111. ThemeManager.setProfile(AssetAdmin.chosenButton, "itemSelectProfile");
  112. }
  113. ThemeManager.setProfile(%this, "itemSelectedProfile");
  114. %firstLoad = true;
  115. AssetAdmin.AssetWindow.resetCamera();
  116. }
  117. AssetAdmin.audioPlayButtonContainer.setVisible(false);
  118. AssetAdmin.AssetWindow.setVisible(true);
  119. if(isObject(%this.AnimationAsset) && %this.AnimationAssetID !$= "")
  120. {
  121. AssetAdmin.AssetWindow.displayAnimationAsset(%this.imageAsset, %this.AnimationAsset, %this.AnimationAssetID);
  122. if(%firstLoad)
  123. {
  124. AssetAdmin.inspector.loadAnimationAsset(%this.AnimationAsset, %this.AnimationAssetID);
  125. }
  126. }
  127. else if(isObject(%this.ImageAsset) && %this.ImageAssetID !$= "")
  128. {
  129. AssetAdmin.AssetWindow.displayImageAsset(%this.ImageAsset, %this.ImageAssetID);
  130. if(%firstLoad)
  131. {
  132. AssetAdmin.inspector.loadImageAsset(%this.ImageAsset, %this.ImageAssetID);
  133. }
  134. }
  135. else if(isObject(%this.ParticleAsset) && %this.ParticleAssetID !$= "")
  136. {
  137. AssetAdmin.AssetWindow.displayParticleAsset(%this.ParticleAsset, %this.ParticleAssetID);
  138. if(%firstLoad)
  139. {
  140. AssetAdmin.inspector.loadParticleAsset(%this.ParticleAsset, %this.ParticleAssetID);
  141. }
  142. }
  143. else if(isObject(%this.FontAsset) && %this.FontAssetID !$= "")
  144. {
  145. AssetAdmin.AssetWindow.displayFontAsset(%this.FontAsset, %this.FontAssetID);
  146. if(%firstLoad)
  147. {
  148. AssetAdmin.inspector.loadFontAsset(%this.FontAsset, %this.FontAssetID);
  149. }
  150. }
  151. else if(isObject(%this.AudioAsset) && %this.AudioAssetID !$= "")
  152. {
  153. AssetAdmin.AssetWindow.displayAudioAsset(%this.AudioAsset, %this.AudioAssetID);
  154. if(%firstLoad)
  155. {
  156. AssetAdmin.inspector.loadAudioAsset(%this.AudioAsset, %this.AudioAssetID);
  157. }
  158. }
  159. else if(isObject(%this.SpineAsset) && %this.SpineAssetID !$= "")
  160. {
  161. AssetAdmin.AssetWindow.displaySpineAsset(%this.SpineAsset, %this.SpineAssetID);
  162. if(%firstLoad)
  163. {
  164. AssetAdmin.inspector.loadSpineAsset(%this.SpineAsset, %this.SpineAssetID);
  165. }
  166. }
  167. AssetAdmin.chosenButton = %this;
  168. }
  169. function AssetDictionaryButton::onRemove(%this)
  170. {
  171. if(isObject(%this.ImageAsset))
  172. {
  173. AssetDatabase.releaseAsset(%this.ImageAssetID);
  174. }
  175. if(isObject(%this.AnimationAsset))
  176. {
  177. AssetDatabase.releaseAsset(%this.AnimationAssetID);
  178. }
  179. }