stateMachineField.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. function BehaviorFieldStack::createStateMachineEditor(%this, %behavior, %fieldIndex)
  2. {
  3. %fieldInfo = %behavior.template.getBehaviorField(%fieldIndex);
  4. %name = getField(%fieldInfo, 0);
  5. %button = new GuiButtonCtrl()
  6. {
  7. class = EditStateMachineBtn;
  8. HorizSizing = "right";
  9. VertSizing = "bottom";
  10. Position = "0 2";
  11. Extent = (%this.extent.x - 8) SPC 13;
  12. text = "Edit States";
  13. tooltip = "Open window to edit the state machine";
  14. behavior = %behavior;
  15. };
  16. %this.add(%button);
  17. }
  18. function EditStateMachineBtn::onClick(%this)
  19. {
  20. Canvas.pushDialog(StateMachineEditor);
  21. StateMachineEditor.behavior = %this.behavior;
  22. StateMachineEditor.open();
  23. }
  24. function StateMachineEditor::open(%this)
  25. {
  26. //check our behavior and see if we have any existing state/field info to work with
  27. //if we do, load those up first
  28. for(%i = 0; %i < %this.behavior.stateMachine.count(); %i++)
  29. {
  30. %stateName = %this.behavior.stateMachine.getKey(%i);
  31. %this.addState(%stateName);
  32. }
  33. }
  34. function StateMachineEditor::addState(%this, %stateName)
  35. {
  36. if(%stateName $= "")
  37. %stateName = "New State";
  38. %state = new GuiControl() {
  39. position = "0 0";
  40. extent = "285 50";
  41. horizSizing = "horizResizeWidth";
  42. vertSizing = "vertResizeTop";
  43. isContainer = "1";
  44. new GuiTextEditCtrl() {
  45. position = "0 0";
  46. extent = "100 15";
  47. text = %stateName;
  48. };
  49. new GuiButtonCtrl() {
  50. //buttonMargin = "4 4";
  51. text = "Remove State";
  52. position = "184 0";
  53. extent = "100 15";
  54. //profile = "GuiButtonProfile";
  55. command = "ScriptEditorGui.save();";
  56. };
  57. new GuiSeparatorCtrl() {
  58. position = "0 15";
  59. extent = %this.extent.x SPC "10";
  60. type = "horizontal";
  61. };
  62. new GuiStackControl(%stateName@"StateStack")
  63. {
  64. //Profile = "EditorContainerProfile";
  65. HorizSizing = "right";
  66. VertSizing = "bottom";
  67. Position = "0 25";
  68. Extent = "285 20";
  69. padding = 4;
  70. new GuiButtonCtrl() {
  71. text = "Add field";
  72. position = "3 0";
  73. extent = "280 20";
  74. horizSizing = "left";
  75. vertSizing = "top";
  76. command = "StateMachineEditor.addField("@%stateName@");";
  77. };
  78. };
  79. };
  80. %this-->Stack.add(%state);
  81. //%this-->stateStackScroll.computeSizes();
  82. }
  83. function StateMachineEditor::addField(%this, %stateName)
  84. {
  85. %index = %this.behavior.stateMachine.count();
  86. %field = new GuiControl() {
  87. position = "0 0";
  88. extent = "285 20";
  89. horizSizing = "width";
  90. vertSizing = "height";
  91. isContainer = "1";
  92. fieldValueCtrl = "";
  93. fieldID = %index++;
  94. };
  95. %fieldList = new GuiPopUpMenuCtrlEx()
  96. {
  97. class = "stateMachineFieldList";
  98. Profile = "GuiPopupMenuProfile";
  99. HorizSizing = "width";
  100. VertSizing = "bottom";
  101. position = "0 1";
  102. Extent = "120 18";
  103. behavior = %this.behavior;
  104. };
  105. %field.add(%fieldList);
  106. %fieldList.refresh();
  107. (%stateName@"StateStack").addToStack(%field);
  108. %this-->Stack.updateStack();
  109. %this-->stateStackScroll.computeSizes();
  110. %this.behavior.addStateField(%stateName, "", "");
  111. return %field;
  112. }
  113. //==============================================================================
  114. function stateMachineFieldList::refresh(%this)
  115. {
  116. %this.clear();
  117. // Find all the types.
  118. %count = getWordCount(%this.behavior.stateFields);
  119. %index = 0;
  120. for (%j = 0; %j < %count; %j++)
  121. {
  122. %item = getWord(%this.behavior.stateFields, %j);
  123. %this.add(%item, %index);
  124. %this.fieldType[%index] = %item;
  125. %index++;
  126. }
  127. }
  128. function stateMachineFieldList::onSelect(%this)
  129. {
  130. //if(%this.getParent().fieldValueCtrl $= "")
  131. %this.fieldType = %this.fieldType[%this.getSelected()];
  132. if(%this.fieldType $= "transitionOnAnimEnd" || %this.fieldType $= "transitionOnAnimTrigger"
  133. || %this.fieldType $= "transitionOnTimeout")
  134. {
  135. %fieldCtrl = new GuiPopUpMenuCtrlEx()
  136. {
  137. class = "stateMachineFieldList";
  138. Profile = "GuiPopupMenuProfile";
  139. HorizSizing = "width";
  140. VertSizing = "bottom";
  141. position = "124 1";
  142. Extent = "120 18";
  143. };
  144. }
  145. else if(%this.fieldType $= "animation")
  146. {
  147. %fieldCtrl = new GuiPopUpMenuCtrlEx()
  148. {
  149. class = "stateMachineFieldList";
  150. Profile = "GuiPopupMenuProfile";
  151. HorizSizing = "width";
  152. VertSizing = "bottom";
  153. position = "124 1";
  154. Extent = "120 18";
  155. };
  156. %index = 0;
  157. %animBhvr = %this.behavior.owner.getBehavior("AnimationController");
  158. for(%i = 0; %i < %animBhvr.getAnimationCount(); %i++)
  159. {
  160. %item = %animBhvr.getAnimationName(%i);
  161. %fieldCtrl.add(%item, %index);
  162. %fieldCtrl.fieldValue[%index] = %item;
  163. %index++;
  164. }
  165. }
  166. else
  167. {
  168. %fieldCtrl = new GuiTextEditCtrl() {
  169. position = "124 1";
  170. extent = "120 10";
  171. text = "";
  172. };
  173. }
  174. //get the state machine entry
  175. %index = %this.getParent().fieldID;
  176. %oldValue = %this.behavior.stateMachine.getValue(%index);
  177. %this.behavior.stateMachine.setValue(%fieldType SPC %oldValue.y);
  178. %this.getParent().add(%fieldCtrl);
  179. }
  180. //==============================================================================
  181. //Now for the unique field types
  182. /*function stateMachineFieldList::refresh(%this)
  183. {
  184. }*/