AssetImageLayersEditRow.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. function AssetImageLayersEditRow::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.LayerIndex;
  13. FontSizeAdjust = 1.4;
  14. FontColor = %this.errorColor;
  15. };
  16. ThemeManager.setProfile(%this.indexBox, "codeProfile");
  17. %this.add(%this.indexBox);
  18. %this.imageBox = new GuiTextEditCtrl()
  19. {
  20. HorizSizing="width";
  21. VertSizing="height";
  22. Position="20 3";
  23. Extent="200 32";
  24. Text = %this.LayerImage;
  25. AltCommand = %this.getID() @ ".LayerImageChange();";
  26. FontColor = %this.errorColor;
  27. InputMode = "AllText";
  28. };
  29. ThemeManager.setProfile(%this.imageBox, "textEditProfile");
  30. %this.add(%this.imageBox);
  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.LayerPosition, 0);
  39. AltCommand = %this.getID() @ ".LayerPositionXChange();";
  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.LayerPosition, 1);
  53. AltCommand = %this.getID() @ ".LayerPositionYChange();";
  54. FontColor = %this.errorColor;
  55. InputMode = "Number";
  56. };
  57. ThemeManager.setProfile(%this.offsetYBox, "textEditProfile");
  58. %this.add(%this.offsetYBox);
  59. %this.LayerColor = %this.scrubColor(%this.LayerColor);
  60. %this.colorBox = new GuiTextEditCtrl()
  61. {
  62. HorizSizing="width";
  63. VertSizing="height";
  64. Position="392 3";
  65. Extent="164 32";
  66. Align = right;
  67. Text = %this.LayerColor;
  68. AltCommand = %this.getID() @ ".LayerColorChange();";
  69. FontColor = %this.errorColor;
  70. InputMode = "AllText";
  71. };
  72. ThemeManager.setProfile(%this.colorBox, "textEditProfile");
  73. %this.add(%this.colorBox);
  74. %this.buttonBar = new GuiChainCtrl()
  75. {
  76. Class = "EditorButtonBar";
  77. Position = "564 5";
  78. Extent = "0 24";
  79. ChildSpacing = 4;
  80. IsVertical = false;
  81. Tool = %this;
  82. };
  83. ThemeManager.setProfile(%this.buttonBar, "emptyProfile");
  84. %this.add(%this.buttonBar);
  85. if(%this.LayerIndex > 0)
  86. {
  87. %this.buttonBar.addButton("MoveLayerUp", 2, "Move Layer Up", "getMoveLayerUpEnabled");
  88. %this.buttonBar.addButton("MoveLayerDown", 6, "Move Layer Down", "getMoveLayerDownEnabled");
  89. %this.buttonBar.addButton("RemoveLayer", 23, "Remove Layer", "");
  90. }
  91. else
  92. {
  93. %this.imageBox.active = false;
  94. %this.offsetXBox.active = false;
  95. %this.offsetYBox.active = false;
  96. }
  97. }
  98. function AssetImageLayersEditRow::LayerImageChange(%this)
  99. {
  100. %name = %this.imageBox.getText();
  101. %name = stripChars(%name, " ");
  102. %this.imageBox.setText(%name);
  103. if(%name !$= %this.LayerImage)
  104. {
  105. if(%name $= "")
  106. {
  107. %this.setNameError(true);
  108. }
  109. else
  110. {
  111. %this.setNameError(false);
  112. %this.postEvent("LayerImageChange", %this SPC %name);
  113. }
  114. }
  115. }
  116. function AssetImageLayersEditRow::LayerPositionXChange(%this)
  117. {
  118. %x = %this.offsetXBox.getText();
  119. %x = stripChars(%x, " ");
  120. if(%x $= "")
  121. {
  122. %x = 0;
  123. }
  124. %this.offsetXBox.setText(%x);
  125. if(%x !$= getWord(%this.LayerPosition, 0))
  126. {
  127. %this.postEvent("LayerPositionChange", %this SPC %x SPC getWord(%this.LayerPosition, 1));
  128. }
  129. }
  130. function AssetImageLayersEditRow::LayerPositionYChange(%this)
  131. {
  132. %y = %this.offsetYBox.getText();
  133. %y = stripChars(%y, " ");
  134. if(%y $= "")
  135. {
  136. %y = 0;
  137. }
  138. %this.offsetYBox.setText(%y);
  139. if(%y !$= getWord(%this.CellOffset, 1))
  140. {
  141. %this.postEvent("LayerPositionChange", %this SPC getWord(%this.LayerPosition, 0) SPC %y);
  142. }
  143. }
  144. function AssetImageLayersEditRow::LayerColorChange(%this)
  145. {
  146. %color = %this.scrubColor(%this.colorBox.getText());
  147. %this.colorBox.setText(%color);
  148. if(%color !$= %this.LayerColor)
  149. {
  150. %this.postEvent("LayerColorChange", %this SPC %color);
  151. }
  152. }
  153. function AssetImageLayersEditRow::setNameError(%this, %hasError)
  154. {
  155. %this.imageBox.overrideFontColor = %hasError;
  156. %this.indexBox.overrideFontColor = %hasError;
  157. }
  158. function AssetImageLayersEditRow::getMoveLayerUpEnabled(%this)
  159. {
  160. return %this.LayerIndex != 1;
  161. }
  162. function AssetImageLayersEditRow::getMoveLayerDownEnabled(%this)
  163. {
  164. return %this.LayerIndex != %this.LayerCount;
  165. }
  166. function AssetImageLayersEditRow::getRemoveCellEnabled(%this)
  167. {
  168. return true;
  169. }
  170. function AssetImageLayersEditRow::updateLayerCount(%this, %newCount)
  171. {
  172. %this.LayerCount = %newCount;
  173. %this.buttonBar.refreshEnabled();
  174. }
  175. function AssetImageLayersEditRow::MoveLayerUp(%this)
  176. {
  177. %this.postEvent("swapLayers", (%this.LayerIndex - 1) SPC %this.LayerIndex);
  178. }
  179. function AssetImageLayersEditRow::MoveLayerDown(%this)
  180. {
  181. %this.postEvent("swapLayers", %this.LayerIndex SPC (%this.LayerIndex + 1));
  182. }
  183. function AssetImageLayersEditRow::RemoveLayer(%this)
  184. {
  185. %this.postEvent("removeLayer", %this.LayerIndex);
  186. }
  187. function AssetImageLayersEditRow::refresh(%this)
  188. {
  189. %this.indexBox.setText(%this.LayerIndex);
  190. %this.imageBox.setText(%this.LayerImage);
  191. %this.offsetXBox.setText(getWord(%this.LayerPosition, 0));
  192. %this.offsetYBox.setText(getWord(%this.LayerPosition, 1));
  193. %this.colorBox.setText(%this.LayerColor);
  194. }
  195. function AssetImageLayersEditRow::onRemove(%this)
  196. {
  197. %this.deleteObjects();
  198. }
  199. function AssetImageLayersEditRow::scrubColor(%this, %color)
  200. {
  201. %red = %this.scrubChannel(getWord(%color, 0));
  202. %green = %this.scrubChannel(getWord(%color, 1));
  203. %blue = %this.scrubChannel(getWord(%color, 2));
  204. %alpha = %this.scrubChannel(getWord(%color, 3));
  205. return %red SPC %green SPC %blue SPC %alpha;
  206. }
  207. function AssetImageLayersEditRow::scrubChannel(%this, %val)
  208. {
  209. %val = mFloatLength(mClamp(%val, 0, 1), 3);
  210. if(getSubStr(%val, 4, 1) !$= "0")
  211. {
  212. return %val;
  213. }
  214. %val = getSubStr(%val, 0, 4);
  215. if(getSubStr(%val, 3, 1) !$= "0")
  216. {
  217. return %val;
  218. }
  219. %val = getSubStr(%val, 0, 3);
  220. if(getSubStr(%val, 2, 1) !$= "0")
  221. {
  222. return %val;
  223. }
  224. return getSubStr(%val, 0, 1);
  225. }