navEditor.tscript 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2014 Daniel Buckmaster
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. $Nav::EditorOpen = false;
  23. function NavEditorGui::onEditorActivated(%this)
  24. {
  25. if(%this.selectedObject)
  26. %this.selectObject(%this.selectedObject);
  27. %this.prepSelectionMode();
  28. }
  29. function NavEditorGui::onEditorDeactivated(%this)
  30. {
  31. if(%this.getMesh())
  32. %this.deselect();
  33. }
  34. function NavEditorGui::onModeSet(%this, %mode)
  35. {
  36. // Callback when the nav editor changes mode. Set the appropriate dynamic
  37. // GUI contents in the properties/actions boxes.
  38. NavInspector.setVisible(false);
  39. %actions = NavEditorOptionsWindow->ActionsBox;
  40. %actions->SelectActions.setVisible(false);
  41. %actions->LinkActions.setVisible(false);
  42. %actions->CoverActions.setVisible(false);
  43. %actions->TileActions.setVisible(false);
  44. %actions->TestActions.setVisible(false);
  45. %properties = NavEditorOptionsWindow->PropertiesBox;
  46. %properties->LinkProperties.setVisible(false);
  47. %properties->TileProperties.setVisible(false);
  48. %properties->TestProperties.setVisible(false);
  49. switch$(%mode)
  50. {
  51. case "SelectMode":
  52. NavInspector.setVisible(true);
  53. %actions->SelectActions.setVisible(true);
  54. case "LinkMode":
  55. %actions->LinkActions.setVisible(true);
  56. %properties->LinkProperties.setVisible(true);
  57. case "CoverMode":
  58. //
  59. %actions->CoverActions.setVisible(true);
  60. case "TileMode":
  61. %actions->TileActions.setVisible(true);
  62. %properties->TileProperties.setVisible(true);
  63. case "TestMode":
  64. %actions->TestActions.setVisible(true);
  65. %properties->TestProperties.setVisible(true);
  66. }
  67. }
  68. function NavEditorGui::paletteSync(%this, %mode)
  69. {
  70. // Synchronise the palette (small buttons on the left) with the actual mode
  71. // the nav editor is in.
  72. %evalShortcut = "ToolsPaletteArray-->" @ %mode @ ".setStateOn(1);";
  73. eval(%evalShortcut);
  74. }
  75. function NavEditorGui::onEscapePressed(%this)
  76. {
  77. return false;
  78. }
  79. function NavEditorGui::selectObject(%this, %obj)
  80. {
  81. NavTreeView.clearSelection();
  82. if(isObject(%obj))
  83. NavTreeView.selectItem(%obj);
  84. %this.onObjectSelected(%obj);
  85. }
  86. function NavEditorGui::onObjectSelected(%this, %obj)
  87. {
  88. if(isObject(%this.selectedObject))
  89. %this.deselect();
  90. %this.selectedObject = %obj;
  91. if(isObject(%obj))
  92. {
  93. %this.selectMesh(%obj);
  94. NavInspector.inspect(%obj);
  95. }
  96. }
  97. function NavEditorGui::deleteMesh(%this)
  98. {
  99. if(isObject(%this.selectedObject))
  100. {
  101. %this.selectedObject.delete();
  102. %this.selectObject(-1);
  103. }
  104. }
  105. function NavEditorGui::deleteSelected(%this)
  106. {
  107. switch$(%this.getMode())
  108. {
  109. case "SelectMode":
  110. // Try to delete the selected NavMesh.
  111. if(isObject(NavEditorGui.selectedObject))
  112. toolsMessageBoxYesNo("Warning",
  113. "Are you sure you want to delete" SPC NavEditorGui.selectedObject.getName(),
  114. "NavEditorGui.deleteMesh();");
  115. case "TestMode":
  116. %this.getPlayer().delete();
  117. %this.onPlayerDeselected();
  118. case "LinkMode":
  119. %this.deleteLink();
  120. %this.isDirty = true;
  121. }
  122. }
  123. function NavEditorGui::buildSelectedMeshes(%this)
  124. {
  125. if(isObject(%this.getMesh()))
  126. {
  127. %this.getMesh().build(NavEditorGui.backgroundBuild, NavEditorGui.saveIntermediates);
  128. %this.isDirty = true;
  129. }
  130. }
  131. function NavEditorGui::buildLinks(%this)
  132. {
  133. if(isObject(%this.getMesh()))
  134. {
  135. %this.getMesh().buildLinks();
  136. %this.isDirty = true;
  137. }
  138. }
  139. function updateLinkData(%control, %flags)
  140. {
  141. %control->LinkWalkFlag.setActive(true);
  142. %control->LinkJumpFlag.setActive(true);
  143. %control->LinkDropFlag.setActive(true);
  144. %control->LinkLedgeFlag.setActive(true);
  145. %control->LinkClimbFlag.setActive(true);
  146. %control->LinkTeleportFlag.setActive(true);
  147. %control->LinkWalkFlag.setStateOn(%flags & $Nav::WalkFlag);
  148. %control->LinkJumpFlag.setStateOn(%flags & $Nav::JumpFlag);
  149. %control->LinkDropFlag.setStateOn(%flags & $Nav::DropFlag);
  150. %control->LinkLedgeFlag.setStateOn(%flags & $Nav::LedgeFlag);
  151. %control->LinkClimbFlag.setStateOn(%flags & $Nav::ClimbFlag);
  152. %control->LinkTeleportFlag.setStateOn(%flags & $Nav::TeleportFlag);
  153. }
  154. function getLinkFlags(%control)
  155. {
  156. return (%control->LinkWalkFlag.isStateOn() ? $Nav::WalkFlag : 0) |
  157. (%control->LinkJumpFlag.isStateOn() ? $Nav::JumpFlag : 0) |
  158. (%control->LinkDropFlag.isStateOn() ? $Nav::DropFlag : 0) |
  159. (%control->LinkLedgeFlag.isStateOn() ? $Nav::LedgeFlag : 0) |
  160. (%control->LinkClimbFlag.isStateOn() ? $Nav::ClimbFlag : 0) |
  161. (%control->LinkTeleportFlag.isStateOn() ? $Nav::TeleportFlag : 0);
  162. }
  163. function disableLinkData(%control)
  164. {
  165. %control->LinkWalkFlag.setActive(false);
  166. %control->LinkJumpFlag.setActive(false);
  167. %control->LinkDropFlag.setActive(false);
  168. %control->LinkLedgeFlag.setActive(false);
  169. %control->LinkClimbFlag.setActive(false);
  170. %control->LinkTeleportFlag.setActive(false);
  171. }
  172. function NavEditorGui::onLinkSelected(%this, %flags)
  173. {
  174. updateLinkData(NavEditorOptionsWindow-->LinkProperties, %flags);
  175. }
  176. function NavEditorGui::onPlayerSelected(%this, %flags)
  177. {
  178. updateLinkData(NavEditorOptionsWindow-->TestProperties, %flags);
  179. }
  180. function NavEditorGui::updateLinkFlags(%this)
  181. {
  182. if(isObject(%this.getMesh()))
  183. {
  184. %properties = NavEditorOptionsWindow-->LinkProperties;
  185. %this.setLinkFlags(getLinkFlags(%properties));
  186. %this.isDirty = true;
  187. }
  188. }
  189. function NavEditorGui::updateTestFlags(%this)
  190. {
  191. if(isObject(%this.getPlayer()))
  192. {
  193. %properties = NavEditorOptionsWindow-->TestProperties;
  194. %player = %this.getPlayer();
  195. %player.allowWwalk = %properties->LinkWalkFlag.isStateOn();
  196. %player.allowJump = %properties->LinkJumpFlag.isStateOn();
  197. %player.allowDrop = %properties->LinkDropFlag.isStateOn();
  198. %player.allowLedge = %properties->LinkLedgeFlag.isStateOn();
  199. %player.allowClimb = %properties->LinkClimbFlag.isStateOn();
  200. %player.allowTeleport = %properties->LinkTeleportFlag.isStateOn();
  201. %this.isDirty = true;
  202. }
  203. }
  204. function NavEditorGui::onLinkDeselected(%this)
  205. {
  206. disableLinkData(NavEditorOptionsWindow-->LinkProperties);
  207. }
  208. function NavEditorGui::onPlayerDeselected(%this)
  209. {
  210. disableLinkData(NavEditorOptionsWindow-->TestProperties);
  211. }
  212. function NavEditorGui::createCoverPoints(%this)
  213. {
  214. if(isObject(%this.getMesh()))
  215. {
  216. %this.getMesh().createCoverPoints();
  217. %this.isDirty = true;
  218. }
  219. }
  220. function NavEditorGui::deleteCoverPoints(%this)
  221. {
  222. if(isObject(%this.getMesh()))
  223. {
  224. %this.getMesh().deleteCoverPoints();
  225. %this.isDirty = true;
  226. }
  227. }
  228. function NavEditorGui::findCover(%this)
  229. {
  230. if(%this.getMode() $= "TestMode" && isObject(%this.getPlayer()))
  231. {
  232. %pos = LocalClientConnection.getControlObject().getPosition();
  233. %text = NavEditorOptionsWindow-->TestProperties->CoverPosition.getText();
  234. if(%text !$= "")
  235. %pos = eval("return " @ %text);
  236. %this.getPlayer().findCover(%pos, NavEditorOptionsWindow-->TestProperties->CoverRadius.getText());
  237. }
  238. }
  239. function NavEditorGui::followObject(%this)
  240. {
  241. if(%this.getMode() $= "TestMode" && isObject(%this.getPlayer()))
  242. {
  243. %obj = LocalClientConnection.player;
  244. %text = NavEditorOptionsWindow-->TestProperties->FollowObject.getText();
  245. if(%text !$= "")
  246. {
  247. %command = "return " @ %text;
  248. if(!endsWith(%command, ";"))
  249. %command = %command @ ";";
  250. %obj = eval(%command);
  251. if(!isObject(%obj))
  252. toolsMessageBoxOk("Error", "Cannot find object" SPC %text);
  253. }
  254. if(isObject(%obj))
  255. %this.getPlayer().followObject(%obj, NavEditorOptionsWindow-->TestProperties->FollowRadius.getText());
  256. }
  257. }
  258. function NavInspector::inspect(%this, %obj)
  259. {
  260. %name = "";
  261. if(isObject(%obj))
  262. %name = %obj.getName();
  263. else
  264. NavFieldInfoControl.setText("");
  265. Parent::inspect(%this, %obj);
  266. }
  267. function NavInspector::onInspectorFieldModified(%this, %object, %fieldName, %arrayIndex, %oldValue, %newValue)
  268. {
  269. // Same work to do as for the regular WorldEditor Inspector.
  270. Inspector::onInspectorFieldModified(%this, %object, %fieldName, %arrayIndex, %oldValue, %newValue);
  271. }
  272. function NavInspector::onFieldSelected(%this, %fieldName, %fieldTypeStr, %fieldDoc)
  273. {
  274. NavFieldInfoControl.setText("<font:Arial Bold:14>" @ %fieldName @ "<font:Arial Italic:14> (" @ %fieldTypeStr @ ") " NL "<font:Arial:14>" @ %fieldDoc);
  275. }
  276. function NavTreeView::onInspect(%this, %obj)
  277. {
  278. NavInspector.inspect(%obj);
  279. }
  280. function NavTreeView::onSelect(%this, %obj)
  281. {
  282. NavInspector.inspect(%obj);
  283. NavEditorGui.onObjectSelected(%obj);
  284. }
  285. function NavEditorGui::prepSelectionMode(%this)
  286. {
  287. %this.setMode("SelectMode");
  288. ToolsPaletteArray-->NavEditorSelectMode.setStateOn(1);
  289. }
  290. //-----------------------------------------------------------------------------
  291. function ENavEditorPaletteButton::onClick(%this)
  292. {
  293. // When clicking on a pelette button, add its description to the bottom of
  294. // the editor window.
  295. EditorGuiStatusBar.setInfo(%this.DetailedDesc);
  296. }
  297. //-----------------------------------------------------------------------------
  298. function NavMeshLinkFlagButton::onClick(%this)
  299. {
  300. NavEditorGui.updateLinkFlags();
  301. }
  302. function NavMeshTestFlagButton::onClick(%this)
  303. {
  304. NavEditorGui.updateTestFlags();
  305. }
  306. singleton GuiControlProfile(NavEditorProfile)
  307. {
  308. canKeyFocus = true;
  309. opaque = true;
  310. fillColor = "192 192 192 192";
  311. category = "Editor";
  312. };