AssetInspector.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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.tabBook.add(%this.insPage);
  97. %this.insScroller = %this.createScroller();
  98. %this.insPage.add(%this.insScroller);
  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. }
  106. function AssetInspector::createTabPage(%this, %name, %class, %superClass)
  107. {
  108. %page = new GuiTabPageCtrl()
  109. {
  110. Class = %class;
  111. SuperClass = %superClass;
  112. HorizSizing = width;
  113. VertSizing = height;
  114. Position = "0 0";
  115. Extent = "700 290";
  116. Text = %name;
  117. };
  118. ThemeManager.setProfile(%page, "tabPageProfile");
  119. return %page;
  120. }
  121. function AssetInspector::createScroller(%this)
  122. {
  123. %scroller = new GuiScrollCtrl()
  124. {
  125. HorizSizing="width";
  126. VertSizing="height";
  127. Position="0 0";
  128. Extent="700 290";
  129. hScrollBar="alwaysOff";
  130. vScrollBar="alwaysOn";
  131. constantThumbHeight="0";
  132. showArrowButtons="1";
  133. scrollBarThickness="14";
  134. };
  135. ThemeManager.setProfile(%scroller, "scrollingPanelProfile");
  136. ThemeManager.setProfile(%scroller, "scrollingPanelThumbProfile", "ThumbProfile");
  137. ThemeManager.setProfile(%scroller, "scrollingPanelTrackProfile", "TrackProfile");
  138. ThemeManager.setProfile(%scroller, "scrollingPanelArrowProfile", "ArrowProfile");
  139. return %scroller;
  140. }
  141. function AssetInspector::createInspector(%this)
  142. {
  143. %inspector = new GuiInspector()
  144. {
  145. HorizSizing="width";
  146. VertSizing="height";
  147. Position="0 0";
  148. Extent="686 290";
  149. FieldCellSize="300 40";
  150. ControlOffset="10 18";
  151. ConstantThumbHeight=false;
  152. ScrollBarThickness=12;
  153. ShowArrowButtons=true;
  154. };
  155. ThemeManager.setProfile(%inspector, "emptyProfile");
  156. ThemeManager.setProfile(%inspector, "panelProfile", "GroupPanelProfile");
  157. ThemeManager.setProfile(%inspector, "emptyProfile", "GroupGridProfile");
  158. ThemeManager.setProfile(%inspector, "labelProfile", "LabelProfile");
  159. ThemeManager.setProfile(%inspector, "textEditProfile", "textEditProfile");
  160. ThemeManager.setProfile(%inspector, "dropDownProfile", "dropDownProfile");
  161. ThemeManager.setProfile(%inspector, "dropDownItemProfile", "dropDownItemProfile");
  162. ThemeManager.setProfile(%inspector, "emptyProfile", "backgroundProfile");
  163. ThemeManager.setProfile(%inspector, "scrollingPanelProfile", "ScrollProfile");
  164. ThemeManager.setProfile(%inspector, "scrollingPanelThumbProfile", "ThumbProfile");
  165. ThemeManager.setProfile(%inspector, "scrollingPanelTrackProfile", "TrackProfile");
  166. ThemeManager.setProfile(%inspector, "scrollingPanelArrowProfile", "ArrowProfile");
  167. ThemeManager.setProfile(%inspector, "checkboxProfile", "checkboxProfile");
  168. ThemeManager.setProfile(%inspector, "buttonProfile", "buttonProfile");
  169. ThemeManager.setProfile(%inspector, "tipProfile", "tooltipProfile");
  170. return %inspector;
  171. }
  172. function AssetInspector::hideInspector(%this)
  173. {
  174. %this.titlebar.setText("");
  175. %this.titleDropDown.visible = false;
  176. %this.tabBook.Visible = false;
  177. %this.emitterButtonBar.visible = false;
  178. %this.deleteAssetButton.visible = false;
  179. }
  180. function AssetInspector::resetInspector(%this)
  181. {
  182. %this.titlebar.setText("");
  183. %this.titleDropDown.visible = false;
  184. %this.tabBook.Visible = true;
  185. %this.tabBook.selectPage(0);
  186. if(%this.tabBook.isMember(%this.scaleGraphPage))
  187. {
  188. %this.tabBook.remove(%this.scaleGraphPage);
  189. }
  190. if(%this.tabBook.isMember(%this.emitterGraphPage))
  191. {
  192. %this.tabBook.remove(%this.emitterGraphPage);
  193. }
  194. %this.emitterButtonBar.visible = false;
  195. %this.deleteAssetButton.visible = true;
  196. }
  197. function AssetInspector::loadImageAsset(%this, %imageAsset, %assetID)
  198. {
  199. %this.resetInspector();
  200. %this.titlebar.setText("Image Asset:" SPC %imageAsset.AssetName);
  201. %this.inspector.clearHiddenFields();
  202. %this.inspector.addHiddenField("hidden");
  203. %this.inspector.addHiddenField("locked");
  204. %this.inspector.addHiddenField("AssetInternal");
  205. %this.inspector.addHiddenField("AssetPrivate");
  206. %this.inspector.addHiddenField("ExplicitMode");
  207. %this.inspector.inspect(%imageAsset);
  208. %this.inspector.openGroupByIndex(0);
  209. }
  210. function AssetInspector::loadAnimationAsset(%this, %animationAsset, %assetID)
  211. {
  212. %this.resetInspector();
  213. %this.titlebar.setText("Animation Asset:" SPC %animationAsset.AssetName);
  214. %this.inspector.clearHiddenFields();
  215. %this.inspector.addHiddenField("hidden");
  216. %this.inspector.addHiddenField("locked");
  217. %this.inspector.addHiddenField("AssetInternal");
  218. %this.inspector.addHiddenField("AssetPrivate");
  219. %this.inspector.inspect(%animationAsset);
  220. %this.inspector.openGroupByIndex(0);
  221. }
  222. function AssetInspector::loadParticleAsset(%this, %particleAsset, %assetID)
  223. {
  224. %this.resetInspector();
  225. %this.titleDropDown.visible = true;
  226. %this.refreshParticleTitleDropDown(%particleAsset, 0);
  227. %this.titleDropDown.Command = %this.getId() @ ".onChooseParticleAsset(" @ %particleAsset.getId() @ ");";
  228. %this.onChooseParticleAsset(%particleAsset);
  229. }
  230. function AssetInspector::refreshParticleTitleDropDown(%this, %particleAsset, %index)
  231. {
  232. %this.titleDropDown.clearItems();
  233. %this.titleDropDown.addItem("Particle Asset:" SPC %particleAsset.AssetName);
  234. for(%i = 0; %i < %particleAsset.getEmitterCount(); %i++)
  235. {
  236. %emitter = %particleAsset.getEmitter(%i);
  237. %this.titleDropDown.addItem("Emitter:" SPC %emitter.EmitterName);
  238. %this.titleDropDown.setItemColor(%i + 1, ThemeManager.activeTheme.color5);
  239. }
  240. %this.titleDropDown.setCurSel(%index);
  241. }
  242. function AssetInspector::onChooseParticleAsset(%this, %particleAsset)
  243. {
  244. %index = %this.titleDropDown.getSelectedItem();
  245. %this.inspector.clearHiddenFields();
  246. %curSel = %this.tabBook.getSelectedPage();
  247. if(%index == 0)
  248. {
  249. %this.inspector.addHiddenField("hidden");
  250. %this.inspector.addHiddenField("locked");
  251. %this.inspector.addHiddenField("AssetInternal");
  252. %this.inspector.addHiddenField("AssetPrivate");
  253. %this.inspector.inspect(%particleAsset);
  254. if(%this.tabBook.isMember(%this.emitterGraphPage))
  255. {
  256. %this.tabBook.remove(%this.emitterGraphPage);
  257. }
  258. %this.tabBook.add(%this.scaleGraphPage);
  259. %this.scaleGraphPage.inspect(%particleAsset);
  260. }
  261. else if(%index > 0)
  262. {
  263. %this.inspector.addHiddenField("hidden");
  264. %this.inspector.addHiddenField("locked");
  265. %this.inspector.inspect(%particleAsset.getEmitter(%index - 1));
  266. if(%this.tabBook.isMember(%this.scaleGraphPage))
  267. {
  268. %this.tabBook.remove(%this.scaleGraphPage);
  269. }
  270. %this.tabBook.add(%this.emitterGraphPage);
  271. %this.emitterGraphPage.inspect(%particleAsset, %index - 1);
  272. }
  273. %this.tabBook.selectPage(%curSel);
  274. %this.inspector.openGroupByIndex(0);
  275. %this.emitterButtonBar.visible = true;
  276. %this.emitterButtonBar.refreshEnabled();
  277. }
  278. function AssetInspector::loadFontAsset(%this, %fontAsset, %assetID)
  279. {
  280. %this.resetInspector();
  281. %this.titlebar.setText("Font Asset:" SPC %fontAsset.AssetName);
  282. %this.inspector.clearHiddenFields();
  283. %this.inspector.addHiddenField("hidden");
  284. %this.inspector.addHiddenField("locked");
  285. %this.inspector.addHiddenField("AssetInternal");
  286. %this.inspector.addHiddenField("AssetPrivate");
  287. %this.inspector.inspect(%fontAsset);
  288. %this.inspector.openGroupByIndex(0);
  289. }
  290. function AssetInspector::loadAudioAsset(%this, %audioAsset, %assetID)
  291. {
  292. %this.resetInspector();
  293. %this.titlebar.setText("Audio Asset:" SPC %audioAsset.AssetName);
  294. %this.inspector.clearHiddenFields();
  295. %this.inspector.addHiddenField("hidden");
  296. %this.inspector.addHiddenField("locked");
  297. %this.inspector.addHiddenField("AssetInternal");
  298. %this.inspector.addHiddenField("AssetPrivate");
  299. %this.inspector.inspect(%audioAsset);
  300. %this.inspector.openGroupByIndex(0);
  301. }
  302. function AssetInspector::loadSpineAsset(%this, %spineAsset, %assetID)
  303. {
  304. %this.resetInspector();
  305. %this.titlebar.setText("Spine Asset:" SPC %spineAsset.AssetName);
  306. %this.inspector.clearHiddenFields();
  307. %this.inspector.addHiddenField("hidden");
  308. %this.inspector.addHiddenField("locked");
  309. %this.inspector.addHiddenField("AssetInternal");
  310. %this.inspector.addHiddenField("AssetPrivate");
  311. %this.inspector.inspect(%spineAsset);
  312. %this.inspector.openGroupByIndex(0);
  313. }
  314. function AssetInspector::deleteAsset(%this)
  315. {
  316. %asset = %this.inspector.getInspectObject();
  317. if(%this.titleDropDown.visible && %this.titleDropDown.getSelectedItem() != 0)
  318. {
  319. %asset = %asset.getOwner();
  320. }
  321. %width = 700;
  322. %height = 230;
  323. %dialog = new GuiControl()
  324. {
  325. class = "DeleteAssetDialog";
  326. superclass = "EditorDialog";
  327. dialogSize = (%width + 8) SPC (%height + 8);
  328. dialogCanClose = true;
  329. dialogText = "Delete Asset";
  330. doomedAsset = %asset;
  331. };
  332. %dialog.init(%width, %height);
  333. Canvas.pushDialog(%dialog);
  334. }
  335. function AssetInspector::addEmitter(%this)
  336. {
  337. %asset = %this.inspector.getInspectObject();
  338. if(%this.titleDropDown.getSelectedItem() != 0)
  339. {
  340. %asset = %asset.getOwner();
  341. }
  342. %width = 700;
  343. %height = 230;
  344. %dialog = new GuiControl()
  345. {
  346. class = "NewParticleEmitterDialog";
  347. superclass = "EditorDialog";
  348. dialogSize = (%width + 8) SPC (%height + 8);
  349. dialogCanClose = true;
  350. dialogText = "New Particle Emitter";
  351. parentAsset = %asset;
  352. };
  353. %dialog.init(%width, %height);
  354. Canvas.pushDialog(%dialog);
  355. }
  356. function AssetInspector::MoveEmitterForward(%this)
  357. {
  358. %emitter = %this.inspector.getInspectObject();
  359. %asset = %emitter.getOwner();
  360. %index = %this.titleDropDown.getSelectedItem();
  361. %asset.moveEmitter(%index-1, %index);
  362. %this.refreshParticleTitleDropDown(%asset, %index+1);
  363. %asset.refreshAsset();
  364. }
  365. function AssetInspector::MoveEmitterBackward(%this)
  366. {
  367. %emitter = %this.inspector.getInspectObject();
  368. %asset = %emitter.getOwner();
  369. %index = %this.titleDropDown.getSelectedItem();
  370. %asset.moveEmitter(%index-1, %index-2);
  371. %this.refreshParticleTitleDropDown(%asset, %index-1);
  372. %asset.refreshAsset();
  373. }
  374. function AssetInspector::RemoveEmitter(%this)
  375. {
  376. %emitter = %this.inspector.getInspectObject();
  377. %asset = %emitter.getOwner();
  378. %asset.RemoveEmitter(%emitter, true);
  379. %index = %this.titleDropDown.getSelectedItem();
  380. %this.titleDropDown.deleteItem(%index);
  381. if(%this.titleDropDown.getItemCount() <= %index)
  382. {
  383. %index = %this.titleDropDown.getItemCount() - 1;
  384. }
  385. %this.titleDropDown.setCurSel(%index);
  386. %this.inspector.inspect(%asset.getEmitter(%index - 1));
  387. %this.emitterGraphPage.inspect(%asset, %index - 1);
  388. %this.emitterButtonBar.refreshEnabled();
  389. %asset.refreshAsset();
  390. }
  391. function AssetInspector::getMoveEmitterForwardEnabled(%this)
  392. {
  393. if(isObject(%this.titleDropDown) && %this.titleDropDown.getSelectedItem() <= 0)
  394. {
  395. return false;
  396. }
  397. if(isObject(%this.inspector))
  398. {
  399. %asset = %this.inspector.getInspectObject();
  400. %emitterID = %this.emitterGraphPage.emitterID;
  401. return %emitterID != (%asset.getOwner().getEmitterCount() - 1);
  402. }
  403. return false;
  404. }
  405. function AssetInspector::getMoveEmitterBackwardEnabled(%this)
  406. {
  407. if(isObject(%this.titleDropDown) && %this.titleDropDown.getSelectedItem() <= 0)
  408. {
  409. return false;
  410. }
  411. if(isObject(%this.inspector))
  412. {
  413. return %this.emitterGraphPage.emitterID != 0;
  414. }
  415. return false;
  416. }
  417. function AssetInspector::getRemoveEmitterEnabled(%this)
  418. {
  419. if(isObject(%this.titleDropDown) && %this.titleDropDown.getSelectedItem() <= 0)
  420. {
  421. return false;
  422. }
  423. if(isObject(%this.inspector))
  424. {
  425. %asset = %this.inspector.getInspectObject();
  426. return %asset.getOwner().getEmitterCount() > 1;
  427. }
  428. return false;
  429. }