riverEditorGui.tscript 17 KB

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