AssetInspector.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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 AssetInspector::onAdd(%this)
  23. {
  24. %this.titlebar = new GuiControl()
  25. {
  26. HorizSizing="width";
  27. VertSizing="top";
  28. Position="0 0";
  29. Extent="700 34";
  30. MinExtent="350 34";
  31. Text = "";
  32. };
  33. ThemeManager.setProfile(%this.titlebar, "panelProfile");
  34. %this.add(%this.titlebar);
  35. %this.titleDropDown = new GuiDropDownCtrl()
  36. {
  37. Position = "5 3";
  38. Extent = 320 SPC 26;
  39. ConstantThumbHeight = false;
  40. ScrollBarThickness = 12;
  41. ShowArrowButtons = true;
  42. Visible = false;
  43. };
  44. ThemeManager.setProfile(%this.titleDropDown, "dropDownProfile");
  45. ThemeManager.setProfile(%this.titleDropDown, "dropDownItemProfile", "listBoxProfile");
  46. ThemeManager.setProfile(%this.titleDropDown, "emptyProfile", "backgroundProfile");
  47. ThemeManager.setProfile(%this.titleDropDown, "scrollingPanelProfile", "ScrollProfile");
  48. ThemeManager.setProfile(%this.titleDropDown, "scrollingPanelThumbProfile", "ThumbProfile");
  49. ThemeManager.setProfile(%this.titleDropDown, "scrollingPanelTrackProfile", "TrackProfile");
  50. ThemeManager.setProfile(%this.titleDropDown, "scrollingPanelArrowProfile", "ArrowProfile");
  51. %this.titlebar.add(%this.titleDropDown);
  52. %this.deleteAssetButton = new GuiButtonCtrl()
  53. {
  54. HorizSizing = "left";
  55. Class = "EditorIconButton";
  56. Frame = 48;
  57. Position = "660 5";
  58. Command = %this.getId() @ ".deleteAsset();";
  59. Tooltip = "Delete Asset";
  60. Visible = false;
  61. };
  62. ThemeManager.setProfile(%this.deleteAssetButton, "iconButtonProfile");
  63. %this.add(%this.deleteAssetButton);
  64. %this.emitterButtonBar = new GuiChainCtrl()
  65. {
  66. Class = "EditorButtonBar";
  67. Position = "340 5";
  68. Extent = "0 24";
  69. ChildSpacing = 4;
  70. IsVertical = false;
  71. Tool = %this;
  72. Visible = false;
  73. };
  74. ThemeManager.setProfile(%this.emitterButtonBar, "emptyProfile");
  75. %this.add(%this.emitterButtonBar);
  76. %this.emitterButtonBar.addButton("AddEmitter", 25, "Add Emitter", "");
  77. %this.emitterButtonBar.addButton("MoveEmitterBackward", 27, "Move Emitter Backward", "getMoveEmitterBackwardEnabled");
  78. %this.emitterButtonBar.addButton("MoveEmitterForward", 28, "Move Emitter Forward", "getMoveEmitterForwardEnabled");
  79. %this.emitterButtonBar.addButton("RemoveEmitter", 23, "Remove Emitter", "getRemoveEmitterEnabled");
  80. %this.tabBook = new GuiTabBookCtrl()
  81. {
  82. Class = AssetInspectorTabBook;
  83. HorizSizing = width;
  84. VertSizing = height;
  85. Position = "0 34";
  86. Extent = "700 290";
  87. MinExtent="350 290";
  88. TabPosition = top;
  89. Visible = false;
  90. };
  91. ThemeManager.setProfile(%this.tabBook, "smallTabBookProfile");
  92. ThemeManager.setProfile(%this.tabBook, "smallTabProfile", "TabProfile");
  93. %this.add(%this.tabBook);
  94. //Inspector Tab
  95. %this.insPage = %this.createTabPage("Inspector", "");
  96. %this.insScroller = %this.createScroller();
  97. %this.insPage.add(%this.insScroller);
  98. %this.tabBook.add(%this.insPage);
  99. %this.inspector = %this.createInspector();
  100. %this.insScroller.add(%this.inspector);
  101. //Particle Graph Tool
  102. %this.scaleGraphPage = %this.createTabPage("Scale Graph", "AssetParticleGraphTool", "");
  103. //Emitter Graph Tool
  104. %this.emitterGraphPage = %this.createTabPage("Emitter Graph", "AssetParticleGraphEmitterTool", "AssetParticleGraphTool");
  105. //Image Frame Edit Tool
  106. %this.imageFrameEditPage = %this.createTabPage("Frame Edit", "AssetImageFrameEditTool", "");
  107. }
  108. function AssetInspector::createTabPage(%this, %name, %class, %superClass)
  109. {
  110. %page = new GuiTabPageCtrl()
  111. {
  112. Class = %class;
  113. SuperClass = %superClass;
  114. HorizSizing = width;
  115. VertSizing = height;
  116. Position = "0 0";
  117. Extent = "700 290";
  118. Text = %name;
  119. };
  120. ThemeManager.setProfile(%page, "tabPageProfile");
  121. return %page;
  122. }
  123. function AssetInspector::createScroller(%this)
  124. {
  125. %scroller = new GuiScrollCtrl()
  126. {
  127. HorizSizing="width";
  128. VertSizing="height";
  129. Position="0 0";
  130. Extent="700 290";
  131. hScrollBar="alwaysOff";
  132. vScrollBar="alwaysOn";
  133. constantThumbHeight="0";
  134. showArrowButtons="1";
  135. scrollBarThickness="14";
  136. };
  137. ThemeManager.setProfile(%scroller, "scrollingPanelProfile");
  138. ThemeManager.setProfile(%scroller, "scrollingPanelThumbProfile", "ThumbProfile");
  139. ThemeManager.setProfile(%scroller, "scrollingPanelTrackProfile", "TrackProfile");
  140. ThemeManager.setProfile(%scroller, "scrollingPanelArrowProfile", "ArrowProfile");
  141. return %scroller;
  142. }
  143. function AssetInspector::createInspector(%this)
  144. {
  145. %inspector = new GuiInspector()
  146. {
  147. HorizSizing="width";
  148. VertSizing="height";
  149. Position="0 0";
  150. Extent="686 290";
  151. FieldCellSize="300 40";
  152. ControlOffset="10 18";
  153. ConstantThumbHeight=false;
  154. ScrollBarThickness=12;
  155. ShowArrowButtons=true;
  156. };
  157. ThemeManager.setProfile(%inspector, "emptyProfile");
  158. ThemeManager.setProfile(%inspector, "panelProfile", "GroupPanelProfile");
  159. ThemeManager.setProfile(%inspector, "emptyProfile", "GroupGridProfile");
  160. ThemeManager.setProfile(%inspector, "labelProfile", "LabelProfile");
  161. ThemeManager.setProfile(%inspector, "textEditProfile", "textEditProfile");
  162. ThemeManager.setProfile(%inspector, "dropDownProfile", "dropDownProfile");
  163. ThemeManager.setProfile(%inspector, "dropDownItemProfile", "dropDownItemProfile");
  164. ThemeManager.setProfile(%inspector, "emptyProfile", "backgroundProfile");
  165. ThemeManager.setProfile(%inspector, "scrollingPanelProfile", "ScrollProfile");
  166. ThemeManager.setProfile(%inspector, "scrollingPanelThumbProfile", "ThumbProfile");
  167. ThemeManager.setProfile(%inspector, "scrollingPanelTrackProfile", "TrackProfile");
  168. ThemeManager.setProfile(%inspector, "scrollingPanelArrowProfile", "ArrowProfile");
  169. ThemeManager.setProfile(%inspector, "checkboxProfile", "checkboxProfile");
  170. ThemeManager.setProfile(%inspector, "buttonProfile", "buttonProfile");
  171. ThemeManager.setProfile(%inspector, "tipProfile", "tooltipProfile");
  172. return %inspector;
  173. }
  174. function AssetInspector::hideInspector(%this)
  175. {
  176. %this.titlebar.setText("");
  177. %this.titleDropDown.visible = false;
  178. %this.tabBook.Visible = false;
  179. %this.emitterButtonBar.visible = false;
  180. %this.deleteAssetButton.visible = false;
  181. }
  182. function AssetInspector::resetInspector(%this)
  183. {
  184. %this.titlebar.setText("");
  185. %this.titleDropDown.visible = false;
  186. %this.tabBook.Visible = true;
  187. %this.tabBook.selectPage(0);
  188. %this.tabBook.removeIfMember(%this.scaleGraphPage);
  189. %this.tabBook.removeIfMember(%this.emitterGraphPage);
  190. %this.emitterButtonBar.visible = false;
  191. %this.deleteAssetButton.visible = true;
  192. }
  193. function AssetInspector::loadImageAsset(%this, %imageAsset, %assetID)
  194. {
  195. %this.resetInspector();
  196. %this.tabBook.add(%this.imageFrameEditPage);
  197. %this.tabBook.selectPage(0);
  198. %this.titlebar.setText("Image Asset:" SPC %imageAsset.AssetName);
  199. %this.inspector.clearHiddenFields();
  200. %this.inspector.addHiddenField("hidden");
  201. %this.inspector.addHiddenField("locked");
  202. %this.inspector.addHiddenField("AssetInternal");
  203. %this.inspector.addHiddenField("AssetPrivate");
  204. %this.inspector.addHiddenField("ExplicitMode");
  205. %this.inspector.inspect(%imageAsset);
  206. %this.inspector.openGroupByIndex(0);
  207. %this.imageFrameEditPage.inspect(%imageAsset);
  208. }
  209. function AssetInspector::loadAnimationAsset(%this, %animationAsset, %assetID)
  210. {
  211. %this.resetInspector();
  212. %this.titlebar.setText("Animation Asset:" SPC %animationAsset.AssetName);
  213. %this.inspector.clearHiddenFields();
  214. %this.inspector.addHiddenField("hidden");
  215. %this.inspector.addHiddenField("locked");
  216. %this.inspector.addHiddenField("AssetInternal");
  217. %this.inspector.addHiddenField("AssetPrivate");
  218. %this.inspector.inspect(%animationAsset);
  219. %this.inspector.openGroupByIndex(0);
  220. }
  221. function AssetInspector::loadParticleAsset(%this, %particleAsset, %assetID)
  222. {
  223. %this.resetInspector();
  224. %this.titleDropDown.visible = true;
  225. %this.refreshParticleTitleDropDown(%particleAsset, 0);
  226. %this.titleDropDown.Command = %this.getId() @ ".onChooseParticleAsset(" @ %particleAsset.getId() @ ");";
  227. %this.onChooseParticleAsset(%particleAsset);
  228. }
  229. function AssetInspector::refreshParticleTitleDropDown(%this, %particleAsset, %index)
  230. {
  231. %this.titleDropDown.clearItems();
  232. %this.titleDropDown.addItem("Particle Asset:" SPC %particleAsset.AssetName);
  233. for(%i = 0; %i < %particleAsset.getEmitterCount(); %i++)
  234. {
  235. %emitter = %particleAsset.getEmitter(%i);
  236. %this.titleDropDown.addItem("Emitter:" SPC %emitter.EmitterName);
  237. %this.titleDropDown.setItemColor(%i + 1, ThemeManager.activeTheme.color5);
  238. }
  239. %this.titleDropDown.setCurSel(%index);
  240. }
  241. function AssetInspector::onChooseParticleAsset(%this, %particleAsset)
  242. {
  243. %index = %this.titleDropDown.getSelectedItem();
  244. %this.inspector.clearHiddenFields();
  245. %curSel = %this.tabBook.getSelectedPage();
  246. if(%index == 0)
  247. {
  248. %this.inspector.addHiddenField("hidden");
  249. %this.inspector.addHiddenField("locked");
  250. %this.inspector.addHiddenField("AssetInternal");
  251. %this.inspector.addHiddenField("AssetPrivate");
  252. %this.inspector.inspect(%particleAsset);
  253. %this.tabBook.removeIfMember(%this.emitterGraphPage);
  254. %this.tabBook.add(%this.scaleGraphPage);
  255. %this.scaleGraphPage.inspect(%particleAsset);
  256. }
  257. else if(%index > 0)
  258. {
  259. %this.inspector.addHiddenField("hidden");
  260. %this.inspector.addHiddenField("locked");
  261. %this.inspector.inspect(%particleAsset.getEmitter(%index - 1));
  262. %this.tabBook.removeIfMember(%this.scaleGraphPage);
  263. %this.tabBook.add(%this.emitterGraphPage);
  264. %this.emitterGraphPage.inspect(%particleAsset, %index - 1);
  265. }
  266. %this.tabBook.selectPage(%curSel);
  267. %this.inspector.openGroupByIndex(0);
  268. %this.emitterButtonBar.visible = true;
  269. %this.emitterButtonBar.refreshEnabled();
  270. }
  271. function AssetInspector::loadFontAsset(%this, %fontAsset, %assetID)
  272. {
  273. %this.resetInspector();
  274. %this.titlebar.setText("Font Asset:" SPC %fontAsset.AssetName);
  275. %this.inspector.clearHiddenFields();
  276. %this.inspector.addHiddenField("hidden");
  277. %this.inspector.addHiddenField("locked");
  278. %this.inspector.addHiddenField("AssetInternal");
  279. %this.inspector.addHiddenField("AssetPrivate");
  280. %this.inspector.inspect(%fontAsset);
  281. %this.inspector.openGroupByIndex(0);
  282. }
  283. function AssetInspector::loadAudioAsset(%this, %audioAsset, %assetID)
  284. {
  285. %this.resetInspector();
  286. %this.titlebar.setText("Audio Asset:" SPC %audioAsset.AssetName);
  287. %this.inspector.clearHiddenFields();
  288. %this.inspector.addHiddenField("hidden");
  289. %this.inspector.addHiddenField("locked");
  290. %this.inspector.addHiddenField("AssetInternal");
  291. %this.inspector.addHiddenField("AssetPrivate");
  292. %this.inspector.inspect(%audioAsset);
  293. %this.inspector.openGroupByIndex(0);
  294. }
  295. function AssetInspector::loadSpineAsset(%this, %spineAsset, %assetID)
  296. {
  297. %this.resetInspector();
  298. %this.titlebar.setText("Spine Asset:" SPC %spineAsset.AssetName);
  299. %this.inspector.clearHiddenFields();
  300. %this.inspector.addHiddenField("hidden");
  301. %this.inspector.addHiddenField("locked");
  302. %this.inspector.addHiddenField("AssetInternal");
  303. %this.inspector.addHiddenField("AssetPrivate");
  304. %this.inspector.inspect(%spineAsset);
  305. %this.inspector.openGroupByIndex(0);
  306. }
  307. function AssetInspector::deleteAsset(%this)
  308. {
  309. %asset = %this.inspector.getInspectObject();
  310. if(%this.titleDropDown.visible && %this.titleDropDown.getSelectedItem() != 0)
  311. {
  312. %asset = %asset.getOwner();
  313. }
  314. %width = 700;
  315. %height = 230;
  316. %dialog = new GuiControl()
  317. {
  318. class = "DeleteAssetDialog";
  319. superclass = "EditorDialog";
  320. dialogSize = (%width + 8) SPC (%height + 8);
  321. dialogCanClose = true;
  322. dialogText = "Delete Asset";
  323. doomedAsset = %asset;
  324. };
  325. %dialog.init(%width, %height);
  326. Canvas.pushDialog(%dialog);
  327. }
  328. function AssetInspector::addEmitter(%this)
  329. {
  330. %asset = %this.inspector.getInspectObject();
  331. if(%this.titleDropDown.getSelectedItem() != 0)
  332. {
  333. %asset = %asset.getOwner();
  334. }
  335. %width = 700;
  336. %height = 230;
  337. %dialog = new GuiControl()
  338. {
  339. class = "NewParticleEmitterDialog";
  340. superclass = "EditorDialog";
  341. dialogSize = (%width + 8) SPC (%height + 8);
  342. dialogCanClose = true;
  343. dialogText = "New Particle Emitter";
  344. parentAsset = %asset;
  345. };
  346. %dialog.init(%width, %height);
  347. Canvas.pushDialog(%dialog);
  348. }
  349. function AssetInspector::MoveEmitterForward(%this)
  350. {
  351. %emitter = %this.inspector.getInspectObject();
  352. %asset = %emitter.getOwner();
  353. %index = %this.titleDropDown.getSelectedItem();
  354. %asset.moveEmitter(%index-1, %index);
  355. %this.refreshParticleTitleDropDown(%asset, %index+1);
  356. %asset.refreshAsset();
  357. }
  358. function AssetInspector::MoveEmitterBackward(%this)
  359. {
  360. %emitter = %this.inspector.getInspectObject();
  361. %asset = %emitter.getOwner();
  362. %index = %this.titleDropDown.getSelectedItem();
  363. %asset.moveEmitter(%index-1, %index-2);
  364. %this.refreshParticleTitleDropDown(%asset, %index-1);
  365. %asset.refreshAsset();
  366. }
  367. function AssetInspector::RemoveEmitter(%this)
  368. {
  369. %emitter = %this.inspector.getInspectObject();
  370. %asset = %emitter.getOwner();
  371. %asset.RemoveEmitter(%emitter, true);
  372. %index = %this.titleDropDown.getSelectedItem();
  373. %this.titleDropDown.deleteItem(%index);
  374. if(%this.titleDropDown.getItemCount() <= %index)
  375. {
  376. %index = %this.titleDropDown.getItemCount() - 1;
  377. }
  378. %this.titleDropDown.setCurSel(%index);
  379. %this.inspector.inspect(%asset.getEmitter(%index - 1));
  380. %this.emitterGraphPage.inspect(%asset, %index - 1);
  381. %this.emitterButtonBar.refreshEnabled();
  382. %asset.refreshAsset();
  383. }
  384. function AssetInspector::getMoveEmitterForwardEnabled(%this)
  385. {
  386. if(isObject(%this.titleDropDown) && %this.titleDropDown.getSelectedItem() <= 0)
  387. {
  388. return false;
  389. }
  390. if(isObject(%this.inspector))
  391. {
  392. %asset = %this.inspector.getInspectObject();
  393. %emitterID = %this.emitterGraphPage.emitterID;
  394. return %emitterID != (%asset.getOwner().getEmitterCount() - 1);
  395. }
  396. return false;
  397. }
  398. function AssetInspector::getMoveEmitterBackwardEnabled(%this)
  399. {
  400. if(isObject(%this.titleDropDown) && %this.titleDropDown.getSelectedItem() <= 0)
  401. {
  402. return false;
  403. }
  404. if(isObject(%this.inspector))
  405. {
  406. return %this.emitterGraphPage.emitterID != 0;
  407. }
  408. return false;
  409. }
  410. function AssetInspector::getRemoveEmitterEnabled(%this)
  411. {
  412. if(isObject(%this.titleDropDown) && %this.titleDropDown.getSelectedItem() <= 0)
  413. {
  414. return false;
  415. }
  416. if(isObject(%this.inspector))
  417. {
  418. %asset = %this.inspector.getInspectObject();
  419. return %asset.getOwner().getEmitterCount() > 1;
  420. }
  421. return false;
  422. }