AssetDictionaryButton.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. UseInput = false;
  101. };
  102. ThemeManager.setProfile(%texture, "spriteProfile");
  103. return %texture;
  104. }
  105. function AssetDictionaryButton::onClick(%this)
  106. {
  107. %firstLoad = false;
  108. if(AssetAdmin.chosenButton != %this)
  109. {
  110. if(isObject(AssetAdmin.chosenButton))
  111. {
  112. ThemeManager.setProfile(AssetAdmin.chosenButton, "itemSelectProfile");
  113. }
  114. ThemeManager.setProfile(%this, "itemSelectedProfile");
  115. %firstLoad = true;
  116. AssetAdmin.AssetWindow.resetCamera();
  117. }
  118. AssetAdmin.audioPlayButtonContainer.setVisible(false);
  119. AssetAdmin.AssetWindow.setVisible(true);
  120. if(isObject(%this.AnimationAsset) && %this.AnimationAssetID !$= "")
  121. {
  122. AssetAdmin.AssetWindow.displayAnimationAsset(%this.imageAsset, %this.AnimationAsset, %this.AnimationAssetID);
  123. if(%firstLoad)
  124. {
  125. AssetAdmin.inspector.loadAnimationAsset(%this.AnimationAsset, %this.AnimationAssetID);
  126. }
  127. }
  128. else if(isObject(%this.ImageAsset) && %this.ImageAssetID !$= "")
  129. {
  130. AssetAdmin.AssetWindow.displayImageAsset(%this.ImageAsset, %this.ImageAssetID);
  131. if(%firstLoad)
  132. {
  133. AssetAdmin.inspector.loadImageAsset(%this.ImageAsset, %this.ImageAssetID);
  134. }
  135. }
  136. else if(isObject(%this.ParticleAsset) && %this.ParticleAssetID !$= "")
  137. {
  138. AssetAdmin.AssetWindow.displayParticleAsset(%this.ParticleAsset, %this.ParticleAssetID);
  139. if(%firstLoad)
  140. {
  141. AssetAdmin.inspector.loadParticleAsset(%this.ParticleAsset, %this.ParticleAssetID);
  142. }
  143. }
  144. else if(isObject(%this.FontAsset) && %this.FontAssetID !$= "")
  145. {
  146. AssetAdmin.AssetWindow.displayFontAsset(%this.FontAsset, %this.FontAssetID);
  147. if(%firstLoad)
  148. {
  149. AssetAdmin.inspector.loadFontAsset(%this.FontAsset, %this.FontAssetID);
  150. }
  151. }
  152. else if(isObject(%this.AudioAsset) && %this.AudioAssetID !$= "")
  153. {
  154. AssetAdmin.AssetWindow.displayAudioAsset(%this.AudioAsset, %this.AudioAssetID);
  155. if(%firstLoad)
  156. {
  157. AssetAdmin.inspector.loadAudioAsset(%this.AudioAsset, %this.AudioAssetID);
  158. }
  159. }
  160. else if(isObject(%this.SpineAsset) && %this.SpineAssetID !$= "")
  161. {
  162. AssetAdmin.AssetWindow.displaySpineAsset(%this.SpineAsset, %this.SpineAssetID);
  163. if(%firstLoad)
  164. {
  165. AssetAdmin.inspector.loadSpineAsset(%this.SpineAsset, %this.SpineAssetID);
  166. }
  167. }
  168. AssetAdmin.chosenButton = %this;
  169. }
  170. function AssetDictionaryButton::onRemove(%this)
  171. {
  172. if(isObject(%this.ImageAsset))
  173. {
  174. AssetDatabase.releaseAsset(%this.ImageAssetID);
  175. }
  176. if(isObject(%this.AnimationAsset))
  177. {
  178. AssetDatabase.releaseAsset(%this.AnimationAssetID);
  179. }
  180. }