meshRoadEditorGui.tscript 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  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. $MeshRoad::wireframe = true;
  23. $MeshRoad::showSpline = true;
  24. $MeshRoad::showReflectPlane = false;
  25. $MeshRoad::showRoad = true;
  26. $MeshRoad::showRoadProfile = false;
  27. $MeshRoad::breakAngle = 3.0;
  28. // MeshRoadEditorGui Script Methods
  29. //-----------------------------------------------------------------------------
  30. function MeshRoadEditorGui::maxSize(%this, %window)
  31. {
  32. // Resize the windows to the max height
  33. // and force these to the right side if set
  34. if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1 && %this.resizing == true)
  35. {
  36. // prevent onResize after a resize
  37. %this.resizing = false;
  38. %fixedWindow = MeshRoadEditorTreeWindow;
  39. %fluidWindow = MeshRoadEditorOptionsWindow;
  40. %offset = -1; // tweak the vertical offset so that it aligns neatly
  41. %top = EditorGuiToolbar.extent.y + %offset;
  42. %bottom = %top + 59;
  43. %maxHeight = Canvas.extent.y - %top - %bottom;
  44. // --- Fixed window (top) ------------------------------------------------
  45. // put it back if it moved
  46. %fixedWindow.position.x = Canvas.extent.x - %fixedWindow.extent.x;
  47. %fixedWindow.position.y = %top;
  48. // don't go beyond the canvas
  49. if(%fixedWindow.extent.y > %maxHeight)
  50. %fixedWindow.extent.y = %maxHeight - %fluidWindow.extent.y;
  51. %position = %fixedWindow.position.x SPC %fixedWindow.position.y;
  52. %extent = %window.extent.x SPC %fixedWindow.extent.y;
  53. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  54. // --- Fluid window (bottom) ---------------------------------------------
  55. // position is relative to the top window
  56. %position = %fixedWindow.position.x SPC %fixedWindow.extent.y + %top;
  57. %extent = %window.extent.x SPC Canvas.extent.y - %fixedWindow.extent.y - %bottom;
  58. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  59. // --- AssetBrowser window ----------------------------------------------
  60. if(isObject(AssetBrowserWindow))
  61. {
  62. // Only resize the AssetBrowser if it's docked
  63. if(AssetBrowserWindow.docked == true)
  64. {
  65. // The width is relative to the sidepanel
  66. %browserWidth = Canvas.extent.x - %extent.x;
  67. %browserHeight = AssetBrowserWindow.extent.y;
  68. %browserPosY = Canvas.extent.y - AssetBrowserWindow.extent.y - 33;
  69. AssetBrowserWindow.resize(0, %browserPosY, %browserWidth, %browserHeight);
  70. }
  71. }
  72. // --- Windowed Console --------------------------------------------------
  73. if(isObject(windowConsoleControl))
  74. {
  75. // Only resize the AssetBrowser if it's docked
  76. if(windowConsoleControl.docked == true)
  77. {
  78. // The width is relative to the sidepanel
  79. %consoleWidth = Canvas.extent.x - %extent.x;
  80. %consoleHeight = windowConsoleControl.extent.y;
  81. %consolePosY = Canvas.extent.y - windowConsoleControl.extent.y - 33;
  82. windowConsoleControl.resize(0, %consolePosY, %consoleWidth, %consoleHeight);
  83. }
  84. }
  85. }
  86. }
  87. function MeshRoadEditorTreeWindow::onMouseDragged(%this)
  88. {
  89. %parent = MeshRoadEditorGui;
  90. if(%parent.panelHidden == true)
  91. {
  92. %parent.showSidePanel();
  93. }
  94. if(%parent.resizing == false && %parent.docked == true)
  95. {
  96. %parent.resizing = true;
  97. %parent.maxSize(%this);
  98. }
  99. }
  100. function MeshRoadEditorOptionsWindow::onMouseDragged(%this)
  101. {
  102. %parent = MeshRoadEditorGui;
  103. if(%parent.panelHidden == true)
  104. {
  105. %parent.showSidePanel();
  106. }
  107. if(%parent.resizing == false && %parent.docked == true)
  108. {
  109. %parent.resizing = true;
  110. %parent.maxSize(%this);
  111. }
  112. }
  113. function MeshRoadEditorGui::onResize(%this, %newPosition, %newExtent)
  114. {
  115. // Window to focus on (mostly the fluid window)
  116. %window = MeshRoadEditorOptionsWindow;
  117. if(%window.panelHidden == true)
  118. {
  119. %window.showSidePanel();
  120. }
  121. if(%this.resizing == false && %this.docked == true)
  122. {
  123. // Only resize once
  124. %this.resizing = true;
  125. %this.maxSize(%window);
  126. }
  127. }
  128. function MeshRoadEditorGui::dockSidePanel()
  129. {
  130. %parent = MeshRoadEditorGui;
  131. %fixedWindow = MeshRoadEditorTreeWindow;
  132. %fluidWindow = MeshRoadEditorOptionsWindow;
  133. if(%parent.docked == true)
  134. return;
  135. // Move and resize the window(s)
  136. %parent.resizing = true;
  137. %parent.maxSize(%fluidWindow);
  138. %parent.docked = true;
  139. %fluidWindow.onMouseDragged();
  140. // Lock the windows in place
  141. %fixedWindow.canCollapse = "0";
  142. %fixedWindow.canMove = "0";
  143. %fluidWindow.canCollapse = "0";
  144. %fluidWindow.canMove = "0";
  145. MeshRoadEditorGui_UnDockBtn.Visible = "1";
  146. MeshRoadEditorGui_DockBtn.Visible = "0";
  147. MeshRoadEditorGui_showBtn.Visible = "0";
  148. MeshRoadEditorGui_hideBtn.Visible = "1";
  149. }
  150. function MeshRoadEditorGui::releaseSidePanel()
  151. {
  152. %parent = MeshRoadEditorGui;
  153. %fixedWindow = MeshRoadEditorTreeWindow;
  154. %fluidWindow = MeshRoadEditorOptionsWindow;
  155. if(%parent.docked == false)
  156. return;
  157. // Unlock the windows so that be moved
  158. %fixedWindow.canCollapse = "1";
  159. %fixedWindow.canMove = "1";
  160. %fluidWindow.canCollapse = "1";
  161. %fluidWindow.canMove = "1";
  162. MeshRoadEditorGui_UnDockBtn.Visible = "0";
  163. MeshRoadEditorGui_DockBtn.Visible = "1";
  164. MeshRoadEditorGui_showBtn.Visible = "0";
  165. MeshRoadEditorGui_hideBtn.Visible = "0";
  166. // Let's do a small resize so it's visually clear we're undocking
  167. %position = %fixedWindow.position.x - 6 SPC %fixedWindow.position.y + 6;
  168. %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y;
  169. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  170. %position = %fluidWindow.position.x - 6 SPC %fluidWindow.position.y + 6;
  171. %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y - 12;
  172. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  173. %parent.docked = false;
  174. %parent.resizing = false;
  175. }
  176. function MeshRoadEditorGui::hideSidePanel()
  177. {
  178. %parent = MeshRoadEditorGui;
  179. %fixedWindow = MeshRoadEditorTreeWindow;
  180. %fluidWindow = MeshRoadEditorOptionsWindow;
  181. MeshRoadEditorGui_showBtn.Visible = "1";
  182. MeshRoadEditorGui_hideBtn.Visible = "0";
  183. // hide the content of the panels
  184. %fixedWindow.titleText = %fixedWindow.text;
  185. %fluidWindow.titleText = %fluidWindow.text;
  186. %fixedWindow.text = "";
  187. MeshRoadEditorRoadsPanel.Visible = "0";
  188. %fluidWindow.text = "";
  189. MeshRoadNodesPanel.Visible = "0";
  190. MeshRoadPropertiesPanel.Visible = "0";
  191. MeshRoadInspectorPanel.Visible = "0";
  192. MeshRoadFieldInfoControl.Visible = "0";
  193. // Let's do a resize so that the panel is collapsed to the side
  194. %position = Canvas.extent.x - 24 SPC %fixedWindow.position.y;
  195. %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y;
  196. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  197. %position = Canvas.extent.x - 24 SPC %fluidWindow.position.y;
  198. %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y;
  199. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  200. %parent.panelHidden = true;
  201. }
  202. function MeshRoadEditorGui::showSidePanel()
  203. {
  204. %parent = MeshRoadEditorGui;
  205. %fixedWindow = MeshRoadEditorTreeWindow;
  206. %fluidWindow = MeshRoadEditorOptionsWindow;
  207. MeshRoadEditorGui_showBtn.Visible = "0";
  208. MeshRoadEditorGui_hideBtn.Visible = "1";
  209. // show the content of the panels
  210. // hide the content of the panels
  211. %fixedWindow.text = %fixedWindow.titleText;
  212. MeshRoadEditorRoadsPanel.Visible = "1";
  213. %fluidWindow.text = %fluidWindow.titleText;
  214. MeshRoadNodesPanel.Visible = "1";
  215. MeshRoadPropertiesPanel.Visible = "1";
  216. MeshRoadInspectorPanel.Visible = "1";
  217. MeshRoadFieldInfoControl.Visible = "1";
  218. %parent.resizing = true;
  219. %parent.maxSize(%fluidWindow);
  220. %parent.panelHidden = false;
  221. }
  222. //------------------------------------------------------------------------------
  223. function MeshRoadEditorGui::onWake( %this )
  224. {
  225. $MeshRoad::EditorOpen = true;
  226. // Maximize windows when set ------------------------------------
  227. %fixedWindow = MeshRoadEditorTreeWindow;
  228. %fluidWindow = MeshRoadEditorOptionsWindow;
  229. if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1)
  230. {
  231. // Let's dock the side panel to the right side
  232. %this.docked = false;
  233. %this.resizing = true;
  234. %this.dockSidePanel();
  235. }
  236. else
  237. {
  238. // Let's release the side panel so it can be moved
  239. %this.docked = true;
  240. %this.resizing = false;
  241. %this.releaseSidePanel();
  242. }
  243. // --------------------------------------------------------------
  244. %count = EWorldEditor.getSelectionSize();
  245. for ( %i = 0; %i < %count; %i++ )
  246. {
  247. %obj = EWorldEditor.getSelectedObject(%i);
  248. if ( %obj.getClassName() !$= "MeshRoad" )
  249. EWorldEditor.unselectObject();
  250. else
  251. %this.setSelectedRoad( %obj );
  252. }
  253. //%this-->TabBook.selectPage(0);
  254. %this.onNodeSelected(-1);
  255. }
  256. function MeshRoadEditorGui::onSleep( %this )
  257. {
  258. $MeshRoad::EditorOpen = false;
  259. }
  260. function MeshRoadEditorGui::paletteSync( %this, %mode )
  261. {
  262. %evalShortcut = "ToolsPaletteArray-->" @ %mode @ ".setStateOn(1);";
  263. eval(%evalShortcut);
  264. }
  265. function MeshRoadEditorGui::onEscapePressed( %this )
  266. {
  267. if( %this.getMode() $= "MeshRoadEditorAddNodeMode" )
  268. {
  269. %this.prepSelectionMode();
  270. return true;
  271. }
  272. return false;
  273. }
  274. function MeshRoadEditorGui::onRoadSelected( %this, %road )
  275. {
  276. %this.road = %road;
  277. // Update the materialEditorList
  278. if( isObject( %road ) )
  279. $Tools::materialEditorList = %road.getId();
  280. MeshRoadInspector.inspect( %road );
  281. MeshRoadTreeView.buildVisibleTree(true);
  282. if( MeshRoadTreeView.getSelectedObject() != %road )
  283. {
  284. MeshRoadTreeView.clearSelection();
  285. %treeId = MeshRoadTreeView.findItemByObjectId( %road );
  286. MeshRoadTreeView.selectItem( %treeId );
  287. }
  288. }
  289. function MeshRoadEditorGui::onRoadCreation( %this )
  290. {
  291. %this.road.TopMaterialAsset = "Core_GameObjects:DefaultDecalRoadMaterial";
  292. %this.road.SideMaterialAsset = "Core_GameObjects:DefaultRoadMaterialOther";
  293. %this.road.BottomMaterialAsset = "Core_GameObjects:DefaultRoadMaterialOther";
  294. }
  295. function MeshRoadEditorGui::onNodeSelected( %this, %nodeIdx )
  296. {
  297. if ( %nodeIdx == -1 )
  298. {
  299. MeshRoadEditorOptionsWindow-->position.setActive( false );
  300. MeshRoadEditorOptionsWindow-->position.setValue( "" );
  301. MeshRoadEditorOptionsWindow-->rotation.setActive( false );
  302. MeshRoadEditorOptionsWindow-->rotation.setValue( "" );
  303. MeshRoadEditorOptionsWindow-->width.setActive( false );
  304. MeshRoadEditorOptionsWindow-->width.setValue( "" );
  305. MeshRoadEditorOptionsWindow-->depth.setActive( false );
  306. MeshRoadEditorOptionsWindow-->depth.setValue( "" );
  307. }
  308. else
  309. {
  310. MeshRoadEditorOptionsWindow-->position.setActive( true );
  311. MeshRoadEditorOptionsWindow-->position.setValue( %this.getNodePosition() );
  312. MeshRoadEditorOptionsWindow-->rotation.setActive( true );
  313. MeshRoadEditorOptionsWindow-->rotation.setValue( %this.getNodeNormal() );
  314. MeshRoadEditorOptionsWindow-->width.setActive( true );
  315. MeshRoadEditorOptionsWindow-->width.setValue( %this.getNodeWidth() );
  316. MeshRoadEditorOptionsWindow-->depth.setActive( true );
  317. MeshRoadEditorOptionsWindow-->depth.setValue( %this.getNodeDepth() );
  318. }
  319. }
  320. function MeshRoadEditorGui::onNodeModified( %this, %nodeIdx )
  321. {
  322. MeshRoadEditorOptionsWindow-->position.setValue( %this.getNodePosition() );
  323. MeshRoadEditorOptionsWindow-->rotation.setValue( %this.getNodeNormal() );
  324. MeshRoadEditorOptionsWindow-->width.setValue( %this.getNodeWidth() );
  325. MeshRoadEditorOptionsWindow-->depth.setValue( %this.getNodeDepth() );
  326. }
  327. function MeshRoadEditorGui::editNodeDetails( %this )
  328. {
  329. %this.setNodePosition( MeshRoadEditorOptionsWindow-->position.getText() );
  330. %this.setNodeNormal( MeshRoadEditorOptionsWindow-->rotation.getText() );
  331. %this.setNodeWidth( MeshRoadEditorOptionsWindow-->width.getText() );
  332. %this.setNodeDepth( MeshRoadEditorOptionsWindow-->depth.getText() );
  333. }
  334. function MeshRoadEditorGui::onBrowseClicked( %this )
  335. {
  336. %filename = RETextureFileCtrl.getText();
  337. %dlg = new OpenFileDialog()
  338. {
  339. Filters = "All Files (*.*)|*.*|";
  340. DefaultPath = MeshRoadEditorGui.lastPath;
  341. DefaultFile = %filename;
  342. ChangePath = false;
  343. MustExist = true;
  344. };
  345. %ret = %dlg.Execute();
  346. if(%ret)
  347. {
  348. MeshRoadEditorGui.lastPath = filePath( %dlg.FileName );
  349. %filename = %dlg.FileName;
  350. MeshRoadEditorGui.setTextureFile( %filename );
  351. MeshRoadEditorTextureFileCtrl.setText( %filename );
  352. }
  353. %dlg.delete();
  354. }
  355. function MeshRoadInspector::inspect( %this, %obj )
  356. {
  357. %name = "";
  358. if ( isObject( %obj ) )
  359. %name = %obj.getName();
  360. else
  361. MeshRoadFieldInfoControl.setText( "" );
  362. //RiverInspectorNameEdit.setValue( %name );
  363. Parent::inspect( %this, %obj );
  364. }
  365. function MeshRoadInspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue )
  366. {
  367. // Same work to do as for the regular WorldEditor Inspector.
  368. Inspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue );
  369. }
  370. function MeshRoadInspector::onFieldSelected( %this, %fieldName, %fieldTypeStr, %fieldDoc )
  371. {
  372. MeshRoadFieldInfoControl.setText( "<font:" @ $Gui::fontTypeBold @ ":16>" @ %fieldName @ "<font:" @ $Gui::fontTypeItalic @ ":16> (" @ %fieldTypeStr @ ") " NL "<font:" @ $Gui::fontTypeRegular @ ":16>" @ %fieldDoc );
  373. }
  374. function MeshRoadTreeView::onInspect(%this, %obj)
  375. {
  376. MeshRoadInspector.inspect(%obj);
  377. }
  378. function MeshRoadTreeView::onSelect(%this, %obj)
  379. {
  380. MeshRoadEditorGui.road = %obj;
  381. MeshRoadInspector.inspect( %obj );
  382. if(%obj != MeshRoadEditorGui.getSelectedRoad())
  383. {
  384. MeshRoadEditorGui.setSelectedRoad( %obj );
  385. }
  386. }
  387. function MeshRoadEditorGui::prepSelectionMode( %this )
  388. {
  389. %mode = %this.getMode();
  390. if ( %mode $= "MeshRoadEditorAddNodeMode" )
  391. {
  392. if ( isObject( %this.getSelectedRoad() ) )
  393. %this.deleteNode();
  394. }
  395. %this.setMode( "MeshRoadEditorSelectMode" );
  396. ToolsPaletteArray-->MeshRoadEditorSelectMode.setStateOn(1);
  397. }
  398. //------------------------------------------------------------------------------
  399. function ESettingsWindow::getMeshRoadEditorSettings(%this)
  400. {
  401. SettingsInspector.startGroup("Defaults");
  402. SettingsInspector.addSettingsField("MeshRoadEditor/DefaultWidth", "Width", "string", "");
  403. SettingsInspector.addSettingsField("MeshRoadEditor/DefaultDepth", "Depth", "string", "");
  404. SettingsInspector.addSettingsField("MeshRoadEditor/DefaultNormal", "Normal", "string", "");
  405. SettingsInspector.addSettingsField("MeshRoadEditor/TopMaterialName", "Top Material", "string", "");
  406. SettingsInspector.addSettingsField("MeshRoadEditor/BottomMaterialName", "Bottom Material", "string", "");
  407. SettingsInspector.addSettingsField("MeshRoadEditor/SideMaterialName", "Side Material", "string", "");
  408. SettingsInspector.endGroup();
  409. SettingsInspector.startGroup("Colors");
  410. SettingsInspector.addSettingsField("MeshRoadEditor/HoverSplineColor", "Hover Spline", "colorI", "");
  411. SettingsInspector.addSettingsField("MeshRoadEditor/SelectedSplineColor", "Selected Spline", "colorI", "");
  412. SettingsInspector.endGroup();
  413. }
  414. //------------------------------------------------------------------------------
  415. function EMeshRoadEditorSelectModeBtn::onClick(%this)
  416. {
  417. EditorGuiStatusBar.setInfo(%this.ToolTip);
  418. }
  419. function EMeshRoadEditorAddModeBtn::onClick(%this)
  420. {
  421. EditorGuiStatusBar.setInfo(%this.ToolTip);
  422. }
  423. function EMeshRoadEditorMoveModeBtn::onClick(%this)
  424. {
  425. EditorGuiStatusBar.setInfo(%this.ToolTip);
  426. }
  427. function EMeshRoadEditorRotateModeBtn::onClick(%this)
  428. {
  429. EditorGuiStatusBar.setInfo(%this.ToolTip);
  430. }
  431. function EMeshRoadEditorScaleModeBtn::onClick(%this)
  432. {
  433. EditorGuiStatusBar.setInfo(%this.ToolTip);
  434. }
  435. function EMeshRoadEditorInsertModeBtn::onClick(%this)
  436. {
  437. EditorGuiStatusBar.setInfo(%this.ToolTip);
  438. }
  439. function EMeshRoadEditorRemoveModeBtn::onClick(%this)
  440. {
  441. EditorGuiStatusBar.setInfo(%this.ToolTip);
  442. }
  443. function MeshRoadDefaultWidthSliderCtrlContainer::onWake(%this)
  444. {
  445. MeshRoadDefaultWidthSliderCtrlContainer-->slider.setValue(MeshRoadDefaultWidthTextEditContainer-->textEdit.getText());
  446. }
  447. function MeshRoadDefaultDepthSliderCtrlContainer::onWake(%this)
  448. {
  449. MeshRoadDefaultDepthSliderCtrlContainer-->slider.setValue(MeshRoadDefaultDepthTextEditContainer-->textEdit.getText());
  450. }