AssetImageLayersEditTool.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. function AssetImageLayersEditTool::onAdd(%this)
  2. {
  3. %this.toolScroll = new GuiScrollCtrl()
  4. {
  5. HorizSizing="width";
  6. VertSizing="height";
  7. Position="0 40";
  8. Extent= getWord(%this.extent, 0) SPC (getWord(%this.extent, 1) - 40);
  9. hScrollBar="dynamic";
  10. vScrollBar="dynamic";
  11. constantThumbHeight="0";
  12. showArrowButtons="1";
  13. scrollBarThickness="14";
  14. };
  15. ThemeManager.setProfile(%this.toolScroll, "scrollingPanelProfile");
  16. ThemeManager.setProfile(%this.toolScroll, "scrollingPanelThumbProfile", "ThumbProfile");
  17. ThemeManager.setProfile(%this.toolScroll, "scrollingPanelTrackProfile", "TrackProfile");
  18. ThemeManager.setProfile(%this.toolScroll, "scrollingPanelArrowProfile", "ArrowProfile");
  19. %this.add(%this.toolScroll);
  20. %this.rowChain = new GuiChainCtrl()
  21. {
  22. HorizSizing="right";
  23. VertSizing="bottom";
  24. Position="0 0";
  25. Extent= "662" SPC getWord(%this.toolScroll.extent, 1);
  26. IsVertical="1";
  27. ChildSpacing="2";
  28. };
  29. ThemeManager.setProfile(%this.rowChain, "emptyProfile");
  30. %this.toolScroll.add(%this.rowChain);
  31. %this.addNewLayerButton = new GuiButtonCtrl()
  32. {
  33. HorizSizing="left";
  34. VertSizing="bottom";
  35. Position="580 5";
  36. Extent= "110 26";
  37. Text = "Add Layer";
  38. command = %this.getID() @ ".addNewLayer();";
  39. };
  40. ThemeManager.setProfile(%this.addNewLayerButton, "buttonProfile");
  41. %this.add(%this.addNewLayerButton);
  42. }
  43. function AssetImageLayersEditTool::inspect(%this, %asset)
  44. {
  45. %this.asset = %asset;
  46. %this.rowChain.deleteObjects();
  47. %this.addHeaderRow();
  48. %this.createRows();
  49. }
  50. function AssetImageLayersEditTool::createRows(%this)
  51. {
  52. %this.addImageLayerRow(%this.asset.getRelativeImageFile(), "0 0", %this.asset.getBlendColor(), 0);
  53. %count = %this.asset.getLayerCount();
  54. for(%i = 1; %i <= %count; %i++)
  55. {
  56. %image = %this.asset.getLayerImage(%i);
  57. %position = %this.asset.getLayerPosition(%i);
  58. %color = %this.asset.getLayerBlendColor(%i);
  59. %this.addImageLayerRow(%image, %position, %color, %i);
  60. }
  61. }
  62. function AssetImageLayersEditTool::addHeaderRow(%this)
  63. {
  64. %row = new GuiControl()
  65. {
  66. Class = "AssetImageLayersHeaderRow";
  67. HorizSizing="right";
  68. VertSizing="bottom";
  69. Position="0 0";
  70. Extent="560 22";
  71. };
  72. ThemeManager.setProfile(%row, "emptyProfile");
  73. %this.rowChain.add(%row);
  74. }
  75. function AssetImageLayersEditTool::addImageLayerRow(%this, %image, %position, %color, %index)
  76. {
  77. %row = new GuiControl()
  78. {
  79. Class = "AssetImageLayersEditRow";
  80. HorizSizing="right";
  81. VertSizing="bottom";
  82. Position="0 0";
  83. Extent="662 40";
  84. LayerImage = %image;
  85. LayerPosition = %position;
  86. LayerColor = %color;
  87. LayerIndex = %index;
  88. LayerCount = %this.asset.getLayerCount();
  89. };
  90. ThemeManager.setProfile(%row, "emptyProfile");
  91. %this.rowChain.add(%row);
  92. %this.startListening(%row);
  93. }
  94. function AssetImageLayersEditTool::addNewLayer(%this)
  95. {
  96. %index = %this.asset.getLayerCount();
  97. %image = %this.asset.getRelativeImageFile();
  98. %this.rowChain.callOnChildrenNoRecurse("updateLayerCount", %index + 1);
  99. %this.asset.addLayer(%image, "0 0", "1 1 1 1");
  100. %this.addImageLayerRow(%image, "0 0", "1 1 1 1", %index + 1);
  101. }
  102. function AssetImageLayersEditTool::onLayerImageChange(%this, %data)
  103. {
  104. %row = getWord(%data, 0);
  105. %image = getWord(%data, 1);
  106. %this.asset.setLayerImage(%row.LayerIndex, %image);
  107. %row.LayerImage = %image;
  108. }
  109. function AssetImageLayersEditTool::onLayerPositionChange(%this, %data)
  110. {
  111. %row = getWord(%data, 0);
  112. %x = getWord(%data, 1);
  113. %y = getWord(%data, 2);
  114. %this.asset.setLayerPosition(%row.LayerIndex, %x SPC %y);
  115. %row.LayerPosition = %x SPC %y;
  116. }
  117. function AssetImageLayersEditTool::onLayerColorChange(%this, %data)
  118. {
  119. %row = getWord(%data, 0);
  120. %color = getWord(%data, 1) SPC getWord(%data, 2) SPC getWord(%data, 3) SPC getWord(%data, 4);
  121. if(%row.LayerIndex == 0)
  122. {
  123. %this.asset.setBlendColor(%color);
  124. }
  125. else
  126. {
  127. %this.asset.setLayerBlendColor(%row.LayerIndex, %color);
  128. }
  129. %row.LayerColor = %color;
  130. }
  131. function AssetImageLayersEditTool::onSwapLayers(%this, %data)
  132. {
  133. %index1 = getWord(%data, 0);
  134. %index2 = getWord(%data, 1);
  135. %image1 = %this.asset.getLayerImage(%index1);
  136. %offset1 = %this.asset.getLayerPosition(%index1);
  137. %color1 = %this.asset.getLayerBlendColor(%index1);
  138. %image2 = %this.asset.getLayerImage(%index2);
  139. %offset2 = %this.asset.getLayerPosition(%index2);
  140. %color2 = %this.asset.getLayerBlendColor(%index2);
  141. %this.asset.moveLayerForward(%index1);
  142. %row1 = %this.rowChain.getObject(%index1 + 1);
  143. %row2 = %this.rowChain.getObject(%index2 + 1);
  144. %row1.LayerPosition = %offset2;
  145. %row1.LayerColor = %color2;
  146. %row1.LayerImage = %image2;
  147. %row2.LayerPosition = %offset1;
  148. %row2.LayerColor = %color1;
  149. %row2.LayerImage = %image1;
  150. %row1.refresh();
  151. %row2.refresh();
  152. }
  153. function AssetImageLayersEditTool::onRemoveLayer(%this, %index)
  154. {
  155. %this.schedule(50, "onRemoveLayer2", %index);
  156. }
  157. function AssetImageLayersEditTool::onRemoveLayer2(%this, %index)
  158. {
  159. %this.asset.removeLayer(%index);
  160. %row = %this.rowChain.getObject(%index + 1);
  161. %row.delete();
  162. %count = %this.asset.getLayerCount();
  163. for(%i = 0; %i < %this.rowChain.getCount(); %i++)
  164. {
  165. %row = %this.rowChain.getObject(%i);
  166. if(%row.isMethod("refresh"))
  167. {
  168. %row.LayerIndex = (%i - 1);
  169. %row.updateLayerCount(%count);
  170. %row.refresh();
  171. }
  172. }
  173. }