AssetInspector.cs 15 KB

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