CreateNewNavMeshDlg.gui 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. //--- OBJECT WRITE BEGIN ---
  2. %guiContent = new GuiControl(CreateNewNavMeshDlg) {
  3. position = "0 0";
  4. extent = "1024 768";
  5. minExtent = "8 2";
  6. horizSizing = "right";
  7. vertSizing = "bottom";
  8. profile = "GuiDefaultProfile";
  9. visible = "1";
  10. active = "1";
  11. tooltipProfile = "GuiToolTipProfile";
  12. hovertime = "1000";
  13. isContainer = "1";
  14. canSave = "1";
  15. canSaveDynamicFields = "1";
  16. new GuiWindowCtrl() {
  17. text = "New NavMesh";
  18. resizeWidth = "0";
  19. resizeHeight = "0";
  20. canMove = "1";
  21. canClose = "1";
  22. canMinimize = "0";
  23. canMaximize = "0";
  24. canCollapse = "0";
  25. closeCommand = "Canvas.popDialog(CreateNewNavMeshDlg);";
  26. edgeSnap = "1";
  27. margin = "0 0 0 0";
  28. padding = "0 0 0 0";
  29. anchorTop = "1";
  30. anchorBottom = "0";
  31. anchorLeft = "1";
  32. anchorRight = "0";
  33. position = "283 240";
  34. extent = "200 176";
  35. minExtent = "8 2";
  36. horizSizing = "right";
  37. vertSizing = "bottom";
  38. profile = "GuiWindowProfile";
  39. visible = "1";
  40. active = "1";
  41. tooltipProfile = "GuiToolTipProfile";
  42. hovertime = "1000";
  43. isContainer = "1";
  44. canSave = "1";
  45. canSaveDynamicFields = "0";
  46. new GuiTextCtrl() {
  47. text = "Name:";
  48. maxLength = "1024";
  49. margin = "0 0 0 0";
  50. padding = "0 0 0 0";
  51. anchorTop = "1";
  52. anchorBottom = "0";
  53. anchorLeft = "1";
  54. anchorRight = "0";
  55. position = "12 29";
  56. extent = "39 21";
  57. minExtent = "8 2";
  58. horizSizing = "right";
  59. vertSizing = "bottom";
  60. profile = "GuiTextRightProfile";
  61. visible = "1";
  62. active = "1";
  63. tooltipProfile = "GuiToolTipProfile";
  64. hovertime = "1000";
  65. isContainer = "1";
  66. canSave = "1";
  67. canSaveDynamicFields = "0";
  68. };
  69. new GuiTextEditCtrl() {
  70. historySize = "0";
  71. tabComplete = "0";
  72. sinkAllKeyEvents = "0";
  73. password = "0";
  74. passwordMask = "*";
  75. text = "Nav";
  76. maxLength = "1024";
  77. margin = "0 0 0 0";
  78. padding = "0 0 0 0";
  79. anchorTop = "1";
  80. anchorBottom = "0";
  81. anchorLeft = "1";
  82. anchorRight = "0";
  83. position = "59 30";
  84. extent = "129 18";
  85. minExtent = "8 2";
  86. horizSizing = "right";
  87. vertSizing = "bottom";
  88. profile = "GuiTextEditProfile";
  89. visible = "1";
  90. active = "1";
  91. tooltipProfile = "GuiToolTipProfile";
  92. hovertime = "1000";
  93. isContainer = "1";
  94. internalName = "MeshName";
  95. canSave = "1";
  96. canSaveDynamicFields = "0";
  97. };
  98. new GuiTextCtrl() {
  99. text = "Position:";
  100. maxLength = "1024";
  101. margin = "0 0 0 0";
  102. padding = "0 0 0 0";
  103. anchorTop = "1";
  104. anchorBottom = "0";
  105. anchorLeft = "1";
  106. anchorRight = "0";
  107. position = "12 51";
  108. extent = "39 21";
  109. minExtent = "8 2";
  110. horizSizing = "right";
  111. vertSizing = "bottom";
  112. profile = "GuiTextRightProfile";
  113. visible = "1";
  114. active = "1";
  115. tooltipProfile = "GuiToolTipProfile";
  116. hovertime = "1000";
  117. isContainer = "1";
  118. canSave = "1";
  119. canSaveDynamicFields = "0";
  120. };
  121. new GuiTextEditCtrl() {
  122. historySize = "0";
  123. tabComplete = "0";
  124. sinkAllKeyEvents = "0";
  125. password = "0";
  126. passwordMask = "*";
  127. text = "0 0 0";
  128. maxLength = "1024";
  129. margin = "0 0 0 0";
  130. padding = "0 0 0 0";
  131. anchorTop = "1";
  132. anchorBottom = "0";
  133. anchorLeft = "1";
  134. anchorRight = "0";
  135. position = "59 52";
  136. extent = "129 18";
  137. minExtent = "8 2";
  138. horizSizing = "right";
  139. vertSizing = "bottom";
  140. profile = "GuiTextEditProfile";
  141. visible = "1";
  142. active = "1";
  143. tooltipProfile = "GuiToolTipProfile";
  144. hovertime = "1000";
  145. isContainer = "1";
  146. internalName = "MeshPosition";
  147. canSave = "1";
  148. canSaveDynamicFields = "0";
  149. };
  150. new GuiTextCtrl() {
  151. text = "Scale:";
  152. maxLength = "1024";
  153. margin = "0 0 0 0";
  154. padding = "0 0 0 0";
  155. anchorTop = "1";
  156. anchorBottom = "0";
  157. anchorLeft = "1";
  158. anchorRight = "0";
  159. position = "12 73";
  160. extent = "39 21";
  161. minExtent = "8 2";
  162. horizSizing = "right";
  163. vertSizing = "bottom";
  164. profile = "GuiTextRightProfile";
  165. visible = "1";
  166. active = "1";
  167. tooltipProfile = "GuiToolTipProfile";
  168. hovertime = "1000";
  169. isContainer = "1";
  170. canSave = "1";
  171. canSaveDynamicFields = "0";
  172. };
  173. new GuiTextEditCtrl() {
  174. historySize = "0";
  175. tabComplete = "0";
  176. sinkAllKeyEvents = "0";
  177. password = "0";
  178. passwordMask = "*";
  179. text = "50 50 20";
  180. maxLength = "1024";
  181. margin = "0 0 0 0";
  182. padding = "0 0 0 0";
  183. anchorTop = "1";
  184. anchorBottom = "0";
  185. anchorLeft = "1";
  186. anchorRight = "0";
  187. position = "59 74";
  188. extent = "129 18";
  189. minExtent = "8 2";
  190. horizSizing = "right";
  191. vertSizing = "bottom";
  192. profile = "GuiTextEditProfile";
  193. visible = "1";
  194. active = "1";
  195. tooltipProfile = "GuiToolTipProfile";
  196. hovertime = "1000";
  197. isContainer = "1";
  198. internalName = "MeshScale";
  199. canSave = "1";
  200. canSaveDynamicFields = "0";
  201. };
  202. new GuiCheckBoxCtrl(MeshMissionBounds) {
  203. text = " Fit NavMesh to mission area";
  204. groupNum = "-1";
  205. buttonType = "ToggleButton";
  206. useMouseEvents = "1";
  207. position = "22 99";
  208. extent = "159 15";
  209. minExtent = "8 2";
  210. horizSizing = "right";
  211. vertSizing = "bottom";
  212. profile = "GuiCheckBoxProfile";
  213. visible = "1";
  214. active = "1";
  215. tooltipProfile = "GuiToolTipProfile";
  216. tooltip = "Positions and scales the NavMesh so it includes all your mission objects.";
  217. hovertime = "1000";
  218. isContainer = "0";
  219. canSave = "1";
  220. canSaveDynamicFields = "0";
  221. };
  222. new GuiCheckBoxCtrl(MeshTerrainBounds) {
  223. text = " Include terrain";
  224. groupNum = "-1";
  225. buttonType = "ToggleButton";
  226. useMouseEvents = "0";
  227. position = "22 121";
  228. extent = "159 15";
  229. minExtent = "8 2";
  230. horizSizing = "right";
  231. vertSizing = "bottom";
  232. profile = "GuiCheckBoxProfile";
  233. visible = "1";
  234. active = "0";
  235. tooltipProfile = "GuiToolTipProfile";
  236. tooltip = "Consider terrain when calculating NavMesh bounds.";
  237. hovertime = "1000";
  238. isContainer = "0";
  239. canSave = "1";
  240. canSaveDynamicFields = "0";
  241. };
  242. new GuiButtonCtrl() {
  243. text = "Create!";
  244. groupNum = "-1";
  245. buttonType = "PushButton";
  246. useMouseEvents = "0";
  247. position = "12 146";
  248. extent = "87 19";
  249. minExtent = "8 2";
  250. horizSizing = "right";
  251. vertSizing = "bottom";
  252. profile = "GuiButtonProfile";
  253. visible = "1";
  254. active = "1";
  255. command = "CreateNewNavMeshDlg.create();";
  256. tooltipProfile = "GuiToolTipProfile";
  257. hovertime = "1000";
  258. isContainer = "0";
  259. canSave = "1";
  260. canSaveDynamicFields = "0";
  261. };
  262. new GuiButtonCtrl() {
  263. text = "Cancel";
  264. groupNum = "-1";
  265. buttonType = "PushButton";
  266. useMouseEvents = "0";
  267. position = "104 146";
  268. extent = "84 19";
  269. minExtent = "8 2";
  270. horizSizing = "right";
  271. vertSizing = "bottom";
  272. profile = "GuiButtonProfile";
  273. visible = "1";
  274. active = "1";
  275. command = "Canvas.popDialog(CreateNewNavMeshDlg);";
  276. tooltipProfile = "GuiToolTipProfile";
  277. hovertime = "1000";
  278. isContainer = "0";
  279. canSave = "1";
  280. canSaveDynamicFields = "0";
  281. };
  282. };
  283. };
  284. //--- OBJECT WRITE END ---
  285. function CreateNewNavMeshDlg::onWake(%this)
  286. {
  287. %this-->MeshName.setText("Nav");
  288. %this-->MeshPosition.setText("0 0 0");
  289. %this-->MeshScale.setText("50 50 20");
  290. MeshMissionBounds.setStateOn(false);
  291. MeshTerrainBounds.setStateOn(true);
  292. }
  293. function MissionBoundsExtents(%group)
  294. {
  295. %box = "0 0 0 0 0 0";
  296. foreach(%obj in %group)
  297. {
  298. %cls = %obj.getClassName();
  299. if(%cls $= "SimGroup" || %cls $= "SimSet" || %cls $= "Path")
  300. {
  301. // Need to recursively check grouped objects.
  302. %wbox = MissionBoundsExtents(%obj);
  303. }
  304. else
  305. {
  306. // Skip objects that are too big and shouldn't really be considered
  307. // part of the scene, or are global bounds and we therefore can't get
  308. // any sensible information out of them.
  309. if(%cls $= "LevelInfo")
  310. continue;
  311. if(!MeshTerrainBounds.isStateOn() && %cls $= "TerrainBlock")
  312. continue;
  313. if(!(%obj.getType() & $TypeMasks::StaticObjectType) ||
  314. %obj.getType() & $TypeMasks::EnvironmentObjectType)
  315. continue;
  316. if(%obj.isGlobalBounds())
  317. continue;
  318. %wbox = %obj.getWorldBox();
  319. }
  320. // Update min point.
  321. for(%j = 0; %j < 3; %j++)
  322. {
  323. if(GetWord(%box, %j) > GetWord(%wbox, %j))
  324. %box = SetWord(%box, %j, GetWord(%wbox, %j));
  325. }
  326. // Update max point.
  327. for(%j = 3; %j < 6; %j++)
  328. {
  329. if(GetWord(%box, %j) < GetWord(%wbox, %j))
  330. %box = SetWord(%box, %j, GetWord(%wbox, %j));
  331. }
  332. }
  333. return %box;
  334. }
  335. function CreateNewNavMeshDlg::create(%this)
  336. {
  337. %name = %this-->MeshName.getText();
  338. if(%name $= "" || nameToID(%name) != -1)
  339. {
  340. MessageBoxOk("Error", "A NavMesh must have a unique name!");
  341. return;
  342. }
  343. %mesh = 0;
  344. if(MeshMissionBounds.isStateOn())
  345. {
  346. if(!isObject(MissionGroup))
  347. {
  348. MessageBoxOk("Error", "You must have a MissionGroup to use the mission bounds function.");
  349. return;
  350. }
  351. // Get maximum extents of all objects.
  352. %box = MissionBoundsExtents(MissionGroup);
  353. %pos = GetBoxCenter(%box);
  354. %scale = (GetWord(%box, 3) - GetWord(%box, 0)) / 2 + 5
  355. SPC (GetWord(%box, 4) - GetWord(%box, 1)) / 2 + 5
  356. SPC (GetWord(%box, 5) - GetWord(%box, 2)) / 2 + 5;
  357. %mesh = new NavMesh(%name)
  358. {
  359. position = %pos;
  360. scale = %scale;
  361. };
  362. }
  363. else
  364. {
  365. %mesh = new NavMesh(%name)
  366. {
  367. position = %this-->MeshPosition.getText();
  368. scale = %this-->MeshScale.getText();
  369. };
  370. }
  371. MissionGroup.add(%mesh);
  372. NavEditorGui.selectObject(%mesh);
  373. Canvas.popDialog(CreateNewNavMeshDlg);
  374. }
  375. function MeshMissionBounds::onClick(%this)
  376. {
  377. MeshTerrainBounds.setActive(%this.isStateOn());
  378. }