AssetInspector.cs 15 KB

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