AssetImageFrameEditRow.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. function AssetImageFrameEditRow::onAdd(%this)
  2. {
  3. %this.errorColor = "255 0 0 255";
  4. %this.indexBox = new GuiControl()
  5. {
  6. HorizSizing="width";
  7. VertSizing="height";
  8. Position="0 0";
  9. Extent="20 40";
  10. Align = center;
  11. vAlign = middle;
  12. Text = %this.CellIndex;
  13. FontSizeAdjust = 1.4;
  14. FontColor = %this.errorColor;
  15. };
  16. ThemeManager.setProfile(%this.indexBox, "codeProfile");
  17. %this.add(%this.indexBox);
  18. %this.nameBox = new GuiTextEditCtrl()
  19. {
  20. HorizSizing="width";
  21. VertSizing="height";
  22. Position="20 3";
  23. Extent="200 32";
  24. Text = %this.CellName;
  25. AltCommand = %this.getID() @ ".CellNameChange();";
  26. FontColor = %this.errorColor;
  27. InputMode = "AlphaNumeric";
  28. };
  29. ThemeManager.setProfile(%this.nameBox, "textEditProfile");
  30. %this.add(%this.nameBox);
  31. %this.offsetXBox = new GuiTextEditCtrl()
  32. {
  33. HorizSizing="width";
  34. VertSizing="height";
  35. Position="224 3";
  36. Extent="80 32";
  37. Align = right;
  38. Text = getWord(%this.CellOffset, 0);
  39. AltCommand = %this.getID() @ ".CellOffsetXChange();";
  40. FontColor = %this.errorColor;
  41. InputMode = "Number";
  42. };
  43. ThemeManager.setProfile(%this.offsetXBox, "textEditProfile");
  44. %this.add(%this.offsetXBox);
  45. %this.offsetYBox = new GuiTextEditCtrl()
  46. {
  47. HorizSizing="width";
  48. VertSizing="height";
  49. Position="308 3";
  50. Extent="80 32";
  51. Align = right;
  52. Text = getWord(%this.CellOffset, 1);
  53. AltCommand = %this.getID() @ ".CellOffsetYChange();";
  54. FontColor = %this.errorColor;
  55. InputMode = "Number";
  56. };
  57. ThemeManager.setProfile(%this.offsetYBox, "textEditProfile");
  58. %this.add(%this.offsetYBox);
  59. %this.widthBox = new GuiTextEditCtrl()
  60. {
  61. HorizSizing="width";
  62. VertSizing="height";
  63. Position="392 3";
  64. Extent="80 32";
  65. Align = right;
  66. Text = %this.CellWidth;
  67. AltCommand = %this.getID() @ ".CellWidthChange();";
  68. FontColor = %this.errorColor;
  69. InputMode = "Number";
  70. };
  71. ThemeManager.setProfile(%this.widthBox, "textEditProfile");
  72. %this.add(%this.widthBox);
  73. %this.heightBox = new GuiTextEditCtrl()
  74. {
  75. HorizSizing="width";
  76. VertSizing="height";
  77. Position="476 3";
  78. Extent="80 32";
  79. Align = right;
  80. Text = %this.CellHeight;
  81. AltCommand = %this.getID() @ ".CellHeightChange();";
  82. FontColor = %this.errorColor;
  83. InputMode = "Number";
  84. };
  85. ThemeManager.setProfile(%this.heightBox, "textEditProfile");
  86. %this.add(%this.heightBox);
  87. %this.buttonBar = new GuiChainCtrl()
  88. {
  89. Class = "EditorButtonBar";
  90. Position = "564 5";
  91. Extent = "0 24";
  92. ChildSpacing = 4;
  93. IsVertical = false;
  94. Tool = %this;
  95. };
  96. ThemeManager.setProfile(%this.buttonBar, "emptyProfile");
  97. %this.add(%this.buttonBar);
  98. %this.buttonBar.addButton("MoveCellUp", 2, "Move Cell Up", "getMoveCellUpEnabled");
  99. %this.buttonBar.addButton("MoveCellDown", 6, "Move Cell Down", "getMoveCellDownEnabled");
  100. %this.buttonBar.addButton("RemoveCell", 23, "Remove Cell", "getRemoveCellEnabled");
  101. }
  102. function AssetImageFrameEditRow::CellNameChange(%this)
  103. {
  104. %name = %this.nameBox.getText();
  105. %name = stripChars(%name, " ");
  106. %this.nameBox.setText(%name);
  107. if(%name !$= %this.CellName)
  108. {
  109. if(%name $= "")
  110. {
  111. %this.setNameError(true);
  112. }
  113. else
  114. {
  115. %this.setNameError(false);
  116. %this.postEvent("CellNameChange", %this SPC %name);
  117. }
  118. }
  119. }
  120. function AssetImageFrameEditRow::CellOffsetXChange(%this)
  121. {
  122. %x = %this.offsetXBox.getText();
  123. %x = stripChars(%x, " ");
  124. if(%x $= "")
  125. {
  126. %x = 0;
  127. }
  128. %x = mClamp(%x, 0, %this.ImageWidth - 1);
  129. %this.offsetXBox.setText(%x);
  130. if(%x !$= getWord(%this.CellOffset, 0))
  131. {
  132. %width = %this.CellWidth;
  133. if((%x + %width) > %this.ImageWidth)
  134. {
  135. %width = %this.ImageWidth - %x;
  136. %this.widthBox.setText(%width);
  137. }
  138. %this.postEvent("CellSizeChange", %this SPC %x SPC getWord(%this.CellOffset, 1) SPC %width SPC %this.CellHeight);
  139. }
  140. }
  141. function AssetImageFrameEditRow::CellOffsetYChange(%this)
  142. {
  143. %y = %this.offsetYBox.getText();
  144. %y = stripChars(%y, " ");
  145. if(%y $= "")
  146. {
  147. %y = 0;
  148. }
  149. %y = mClamp(%y, 0, %this.ImageHeight - 1);
  150. %this.offsetYBox.setText(%y);
  151. if(%y !$= getWord(%this.CellOffset, 1))
  152. {
  153. %height = %this.CellHeight;
  154. if((%y + %height) > %this.ImageHeight)
  155. {
  156. %height = %this.ImageHeight - %y;
  157. %this.heightBox.setText(%height);
  158. }
  159. %this.postEvent("CellSizeChange", %this SPC getWord(%this.CellOffset, 0) SPC %y SPC %this.CellWidth SPC %height);
  160. }
  161. }
  162. function AssetImageFrameEditRow::CellWidthChange(%this)
  163. {
  164. %width = %this.widthBox.getText();
  165. %width = stripChars(%width, " ");
  166. if(%width $= "")
  167. {
  168. %width = 1;
  169. }
  170. %width = mClamp(%width, 1, %this.ImageWidth);
  171. %this.widthBox.setText(%width);
  172. if(%width !$= %this.CellWidth)
  173. {
  174. %x = getWord(%this.CellOffset, 0);
  175. if((%x + %width) > %this.ImageWidth)
  176. {
  177. %x = %this.ImageWidth - %width;
  178. %this.offsetXBox.setText(%x);
  179. }
  180. %this.postEvent("CellSizeChange", %this SPC %x SPC getWord(%this.CellOffset, 1) SPC %width SPC %this.CellHeight);
  181. }
  182. }
  183. function AssetImageFrameEditRow::CellHeightChange(%this)
  184. {
  185. %height = %this.heightBox.getText();
  186. %height = stripChars(%height, " ");
  187. if(%height $= "")
  188. {
  189. %height = 1;
  190. }
  191. %height = mClamp(%height, 1, %this.ImageHeight);
  192. %this.heightBox.setText(%height);
  193. if(%height !$= %this.CellHeight)
  194. {
  195. %y = getWord(%this.CellOffset, 1);
  196. if((%y + %height) > %this.ImageHeight)
  197. {
  198. %y = %this.ImageHeight - %height;
  199. %this.offsetYBox.setText(%y);
  200. }
  201. %this.postEvent("CellSizeChange", %this SPC getWord(%this.CellOffset, 0) SPC %y SPC %this.CellWidth SPC %height);
  202. }
  203. }
  204. function AssetImageFrameEditRow::setNameError(%this, %hasError)
  205. {
  206. %this.nameBox.overrideFontColor = %hasError;
  207. %this.indexBox.overrideFontColor = %hasError;
  208. }
  209. function AssetImageFrameEditRow::getMoveCellUpEnabled(%this)
  210. {
  211. return %this.CellIndex != 0;
  212. }
  213. function AssetImageFrameEditRow::getMoveCellDownEnabled(%this)
  214. {
  215. return %this.CellIndex < (%this.CellCount - 1);
  216. }
  217. function AssetImageFrameEditRow::getRemoveCellEnabled(%this)
  218. {
  219. return %this.CellCount > 1;
  220. }
  221. function AssetImageFrameEditRow::updateCellCount(%this, %newCount)
  222. {
  223. %this.CellCount = %newCount;
  224. %this.buttonBar.refreshEnabled();
  225. }
  226. function AssetImageFrameEditRow::MoveCellUp(%this)
  227. {
  228. %this.postEvent("swapCells", (%this.CellIndex - 1) SPC %this.CellIndex);
  229. }
  230. function AssetImageFrameEditRow::MoveCellDown(%this)
  231. {
  232. %this.postEvent("swapCells", %this.CellIndex SPC (%this.CellIndex + 1));
  233. }
  234. function AssetImageFrameEditRow::RemoveCell(%this)
  235. {
  236. %this.postEvent("removeCell", %this.CellIndex);
  237. }
  238. function AssetImageFrameEditRow::refresh(%this)
  239. {
  240. %this.indexBox.setText(%this.CellIndex);
  241. %this.nameBox.setText(%this.CellName);
  242. %this.offsetXBox.setText(getWord(%this.CellOffset, 0));
  243. %this.offsetYBox.setText(getWord(%this.CellOffset, 1));
  244. %this.widthBox.setText(%this.CellWidth);
  245. %this.heightBox.setText(%this.CellHeight);
  246. }
  247. function AssetImageFrameEditRow::onRemove(%this)
  248. {
  249. %this.deleteObjects();
  250. }