AssetImageFrameEditTool.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. function AssetImageFrameEditTool::onAdd(%this)
  2. {
  3. %this.explicitModeCheckbox = new GuiCheckboxCtrl()
  4. {
  5. HorizSizing="right";
  6. VertSizing="bottom";
  7. Position="10 3";
  8. Extent= "285 30";
  9. Text = "Use Explicit Frame Mode";
  10. TextExtent = "280 30";
  11. command = %this.getID() @ ".toggleExplicitMode();";
  12. };
  13. ThemeManager.setProfile(%this.explicitModeCheckbox, "checkboxProfile");
  14. %this.add(%this.explicitModeCheckbox);
  15. %this.toolScroll = new GuiScrollCtrl()
  16. {
  17. HorizSizing="width";
  18. VertSizing="height";
  19. Position="0 40";
  20. Extent= getWord(%this.extent, 0) SPC (getWord(%this.extent, 1) - 40);
  21. hScrollBar="dynamic";
  22. vScrollBar="dynamic";
  23. constantThumbHeight="0";
  24. showArrowButtons="1";
  25. scrollBarThickness="14";
  26. };
  27. ThemeManager.setProfile(%this.toolScroll, "scrollingPanelProfile");
  28. ThemeManager.setProfile(%this.toolScroll, "scrollingPanelThumbProfile", "ThumbProfile");
  29. ThemeManager.setProfile(%this.toolScroll, "scrollingPanelTrackProfile", "TrackProfile");
  30. ThemeManager.setProfile(%this.toolScroll, "scrollingPanelArrowProfile", "ArrowProfile");
  31. %this.add(%this.toolScroll);
  32. %this.rowChain = new GuiChainCtrl()
  33. {
  34. HorizSizing="right";
  35. VertSizing="bottom";
  36. Position="0 0";
  37. Extent= "662" SPC getWord(%this.toolScroll.extent, 1);
  38. IsVertical="1";
  39. ChildSpacing="2";
  40. };
  41. ThemeManager.setProfile(%this.rowChain, "emptyProfile");
  42. %this.toolScroll.add(%this.rowChain);
  43. %this.addNewCellButton = new GuiButtonCtrl()
  44. {
  45. HorizSizing="left";
  46. VertSizing="bottom";
  47. Position="580 5";
  48. Extent= "110 26";
  49. Text = "Add Cell";
  50. command = %this.getID() @ ".addNewCell();";
  51. };
  52. ThemeManager.setProfile(%this.addNewCellButton, "buttonProfile");
  53. %this.add(%this.addNewCellButton);
  54. }
  55. function AssetImageFrameEditTool::inspect(%this, %asset)
  56. {
  57. %this.asset = %asset;
  58. %this.explicitModeCheckbox.setStateOn(%asset.ExplicitMode);
  59. %this.rowChain.deleteObjects();
  60. %this.addHeaderRow();
  61. %this.toggleExplicitMode();
  62. }
  63. function AssetImageFrameEditTool::createRows(%this)
  64. {
  65. %cellCount = %this.asset.getExplicitCellCount();
  66. for(%i = 0; %i < %cellCount; %i++)
  67. {
  68. %name = %this.asset.getExplicitCellName(%i);
  69. %width = %this.asset.getExplicitCellWidth(%i);
  70. %height = %this.asset.getExplicitCellHeight(%i);
  71. %offset = %this.asset.getExplicitCellOffset(%i);
  72. %this.addImageFrameRow(%name, %offset, %width, %height, %i);
  73. }
  74. }
  75. function AssetImageFrameEditTool::toggleExplicitMode(%this)
  76. {
  77. %explicitModeOn = %this.explicitModeCheckbox.getStateOn();
  78. %this.toolScroll.setVisible(%explicitModeOn);
  79. %this.addNewCellButton.setVisible(%explicitModeOn);
  80. %this.asset.setExplicitMode(%explicitModeOn);
  81. if(%explicitModeOn && %this.asset.getExplicitCellCount() == 0)
  82. {
  83. %this.addNewCell();
  84. }
  85. else if(%explicitModeOn)
  86. {
  87. %this.createRows();
  88. }
  89. else
  90. {
  91. %this.rowChain.deleteObjects();
  92. %this.addHeaderRow();
  93. }
  94. }
  95. function AssetImageFrameEditTool::addHeaderRow(%this)
  96. {
  97. %row = new GuiControl()
  98. {
  99. Class = "AssetImageFrameHeaderRow";
  100. HorizSizing="right";
  101. VertSizing="bottom";
  102. Position="0 0";
  103. Extent="560 22";
  104. };
  105. ThemeManager.setProfile(%row, "emptyProfile");
  106. %this.rowChain.add(%row);
  107. }
  108. function AssetImageFrameEditTool::addImageFrameRow(%this, %name, %offset, %width, %height, %index)
  109. {
  110. %row = new GuiControl()
  111. {
  112. Class = "AssetImageFrameEditRow";
  113. HorizSizing="right";
  114. VertSizing="bottom";
  115. Position="0 0";
  116. Extent="662 40";
  117. CellName = %name;
  118. CellOffset = %offset;
  119. CellWidth = %width;
  120. CellHeight = %height;
  121. CellIndex = %index;
  122. ImageWidth = %this.asset.getImageWidth();
  123. ImageHeight = %this.asset.getImageHeight();
  124. CellCount = %this.asset.getExplicitCellCount();
  125. };
  126. ThemeManager.setProfile(%row, "emptyProfile");
  127. %this.rowChain.add(%row);
  128. %this.startListening(%row);
  129. }
  130. function AssetImageFrameEditTool::addNewCell(%this)
  131. {
  132. %index = %this.asset.getExplicitCellCount();
  133. %name = "Frame" @ %index;
  134. %x = 0;
  135. %y = 0;
  136. %width = %this.asset.getImageWidth();
  137. %height = %this.asset.getImageHeight();
  138. %this.rowChain.callOnChildrenNoRecurse("updateCellCount", %index + 1);
  139. %this.asset.addExplicitCell(%x, %y, %width, %height, %name);
  140. %this.addImageFrameRow(%name, %x SPC %y, %width, %height, %index);
  141. }
  142. function AssetImageFrameEditTool::onCellNameChange(%this, %data)
  143. {
  144. %row = getWord(%data, 0);
  145. %name = getWord(%data, 1);
  146. if(%this.asset.getExplicitCellIndex(%name) != -1)
  147. {
  148. %row.setNameError(true);
  149. }
  150. else
  151. {
  152. %this.asset.setExplicitCell(%row.CellIndex, getWord(%row.CellOffset, 0), getWord(%row.CellOffset, 1), %row.CellWidth, %row.CellHeight, %name);
  153. %row.CellName = %name;
  154. }
  155. }
  156. function AssetImageFrameEditTool::onCellSizeChange(%this, %data)
  157. {
  158. %row = getWord(%data, 0);
  159. %x = getWord(%data, 1);
  160. %y = getWord(%data, 2);
  161. %width = getWord(%data, 3);
  162. %height = getWord(%data, 4);
  163. %this.asset.setExplicitCell(%row.CellIndex, %x, %y, %width, %height, %row.CellName);
  164. %row.CellOffset = %x SPC %y;
  165. %row.CellWidth = %width;
  166. %row.CellHeight = %height;
  167. }
  168. function AssetImageFrameEditTool::onSwapCells(%this, %data)
  169. {
  170. %index1 = getWord(%data, 0);
  171. %index2 = getWord(%data, 1);
  172. %name1 = %this.asset.getExplicitCellName(%index1);
  173. %width1 = %this.asset.getExplicitCellWidth(%index1);
  174. %height1 = %this.asset.getExplicitCellHeight(%index1);
  175. %offset1 = %this.asset.getExplicitCellOffset(%index1);
  176. %name2 = %this.asset.getExplicitCellName(%index2);
  177. %width2 = %this.asset.getExplicitCellWidth(%index2);
  178. %height2 = %this.asset.getExplicitCellHeight(%index2);
  179. %offset2 = %this.asset.getExplicitCellOffset(%index2);
  180. %this.asset.setExplicitCell(%index1, getWord(%offset2, 0), getWord(%offset2, 1), %width2, %height2, %name2);
  181. %this.asset.setExplicitCell(%index2, getWord(%offset1, 0), getWord(%offset1, 1), %width1, %height1, %name1);
  182. %row1 = %this.rowChain.getObject(%index1 + 1);
  183. %row2 = %this.rowChain.getObject(%index2 + 1);
  184. %row1.CellOffset = %offset2;
  185. %row1.CellWidth = %width2;
  186. %row1.CellHeight = %height2;
  187. %row1.CellName = %name2;
  188. %row2.CellOffset = %offset1;
  189. %row2.CellWidth = %width1;
  190. %row2.CellHeight = %height1;
  191. %row2.CellName = %name1;
  192. %row1.refresh();
  193. %row2.refresh();
  194. }
  195. function AssetImageFrameEditTool::onRemoveCell(%this, %index)
  196. {
  197. %this.schedule(50, "onRemoveCell2", %index);
  198. }
  199. function AssetImageFrameEditTool::onRemoveCell2(%this, %index)
  200. {
  201. %this.asset.removeExplicitCell(%index);
  202. %row = %this.rowChain.getObject(%index + 1);
  203. %row.delete();
  204. %count = %this.asset.getExplicitCellCount();
  205. for(%i = 0; %i < %this.rowChain.getCount(); %i++)
  206. {
  207. %row = %this.rowChain.getObject(%i);
  208. if(%row.isMethod("refresh"))
  209. {
  210. %row.CellIndex = (%i - 1);
  211. %row.updateCellCount(%count);
  212. %row.refresh();
  213. }
  214. }
  215. }