roadEditorGui.tscript 15 KB

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