missionAreaEditorGui.ed.tscript 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. //------------------------------------------------------------------------------
  23. function MissionAreaEditorGui::onWake(%this)
  24. {
  25. %fixedWindow = MissionAreaEditorTerrainWindow;
  26. %fluidWindow = MissionAreaEditorPropertiesWindow;
  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. }
  42. function MissionAreaEditorGui::maxSize(%this, %window)
  43. {
  44. // Resize the windows to the max height
  45. // and force these to the right side if set
  46. if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1 && %this.resizing == true)
  47. {
  48. // prevent onResize after a resize
  49. %this.resizing = false;
  50. %fixedWindow = MissionAreaEditorTerrainWindow;
  51. %fluidWindow = MissionAreaEditorPropertiesWindow;
  52. %offset = -1; // tweak the vertical offset so that it aligns neatly
  53. %top = EditorGuiToolbar.extent.y + %offset;
  54. %bottom = %top + 59;
  55. %maxHeight = Canvas.extent.y - %top - %bottom;
  56. // --- Fixed window (top) ------------------------------------------------
  57. // put it back if it moved
  58. %fixedWindow.position.x = Canvas.extent.x - %fixedWindow.extent.x;
  59. %fixedWindow.position.y = %top;
  60. // don't go beyond the canvas
  61. if(%fixedWindow.extent.y > %maxHeight)
  62. %fixedWindow.extent.y = %maxHeight - %fluidWindow.extent.y;
  63. %position = %fixedWindow.position.x SPC %fixedWindow.position.y;
  64. %extent = %window.extent.x SPC %fixedWindow.extent.y;
  65. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  66. // --- Fluid window (bottom) ---------------------------------------------
  67. // position is relative to the top window
  68. %position = %fixedWindow.position.x SPC %fixedWindow.extent.y + %top;
  69. %extent = %window.extent.x SPC Canvas.extent.y - %fixedWindow.extent.y - %bottom;
  70. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  71. // --- AssetBrowser window ----------------------------------------------
  72. if(isObject(AssetBrowserWindow))
  73. {
  74. // Only resize the AssetBrowser if it's docked
  75. if(AssetBrowserWindow.docked == true)
  76. {
  77. // The width is relative to the sidepanel
  78. %browserWidth = Canvas.extent.x - %extent.x;
  79. %browserHeight = AssetBrowserWindow.extent.y;
  80. %browserPosY = Canvas.extent.y - AssetBrowserWindow.extent.y - 33;
  81. AssetBrowserWindow.resize(0, %browserPosY, %browserWidth, %browserHeight);
  82. }
  83. }
  84. // --- Windowed Console --------------------------------------------------
  85. if(isObject(windowConsoleControl))
  86. {
  87. // Only resize the AssetBrowser if it's docked
  88. if(windowConsoleControl.docked == true)
  89. {
  90. // The width is relative to the sidepanel
  91. %consoleWidth = Canvas.extent.x - %extent.x;
  92. %consoleHeight = windowConsoleControl.extent.y;
  93. %consolePosY = Canvas.extent.y - windowConsoleControl.extent.y - 33;
  94. windowConsoleControl.resize(0, %consolePosY, %consoleWidth, %consoleHeight);
  95. }
  96. }
  97. }
  98. }
  99. function MissionAreaEditorTerrainWindow::onMouseDragged(%this)
  100. {
  101. %parent = MissionAreaEditorGui;
  102. if(%parent.panelHidden == true)
  103. {
  104. %parent.showSidePanel();
  105. }
  106. if(%parent.resizing == false && %parent.docked == true)
  107. {
  108. %parent.resizing = true;
  109. %parent.maxSize(%this);
  110. }
  111. }
  112. function MissionAreaEditorPropertiesWindow::onMouseDragged(%this)
  113. {
  114. %parent = MissionAreaEditorGui;
  115. if(%parent.panelHidden == true)
  116. {
  117. %parent.showSidePanel();
  118. }
  119. if(%parent.resizing == false && %parent.docked == true)
  120. {
  121. %parent.resizing = true;
  122. %parent.maxSize(%this);
  123. }
  124. }
  125. function MissionAreaEditorGui::onResize(%this, %newPosition, %newExtent)
  126. {
  127. // Window to focus on (mostly the fluid window)
  128. %window = MissionAreaEditorPropertiesWindow;
  129. if(%window.panelHidden == true)
  130. {
  131. %window.showSidePanel();
  132. }
  133. if(%this.resizing == false && %this.docked == true)
  134. {
  135. // Only resize once
  136. %this.resizing = true;
  137. %this.maxSize(%window);
  138. }
  139. }
  140. function MissionAreaEditorGui::dockSidePanel()
  141. {
  142. %parent = MissionAreaEditorGui;
  143. %fixedWindow = MissionAreaEditorTerrainWindow;
  144. %fluidWindow = MissionAreaEditorPropertiesWindow;
  145. if(%parent.docked == true)
  146. return;
  147. // Move and resize the window(s)
  148. %parent.resizing = true;
  149. %parent.maxSize(%fluidWindow);
  150. %parent.docked = true;
  151. %fluidWindow.onMouseDragged();
  152. // Lock the windows in place
  153. %fixedWindow.canCollapse = "0";
  154. %fixedWindow.canMove = "0";
  155. %fluidWindow.canCollapse = "0";
  156. %fluidWindow.canMove = "0";
  157. MissionAreaEditorGui_UnDockBtn.Visible = "1";
  158. MissionAreaEditorGui_DockBtn.Visible = "0";
  159. MissionAreaEditorGui_showBtn.Visible = "0";
  160. MissionAreaEditorGui_hideBtn.Visible = "1";
  161. }
  162. function MissionAreaEditorGui::releaseSidePanel()
  163. {
  164. %parent = MissionAreaEditorGui;
  165. %fixedWindow = MissionAreaEditorTerrainWindow;
  166. %fluidWindow = MissionAreaEditorPropertiesWindow;
  167. if(%parent.docked == false)
  168. return;
  169. // Unlock the windows so that be moved
  170. %fixedWindow.canCollapse = "1";
  171. %fixedWindow.canMove = "1";
  172. %fluidWindow.canCollapse = "1";
  173. %fluidWindow.canMove = "1";
  174. MissionAreaEditorGui_UnDockBtn.Visible = "0";
  175. MissionAreaEditorGui_DockBtn.Visible = "1";
  176. MissionAreaEditorGui_showBtn.Visible = "0";
  177. MissionAreaEditorGui_hideBtn.Visible = "0";
  178. // Let's do a small resize so it's visually clear we're undocking
  179. %position = %fixedWindow.position.x - 6 SPC %fixedWindow.position.y + 6;
  180. %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y;
  181. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  182. %position = %fluidWindow.position.x - 6 SPC %fluidWindow.position.y + 6;
  183. %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y - 12;
  184. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  185. %parent.docked = false;
  186. %parent.resizing = false;
  187. }
  188. function MissionAreaEditorGui::hideSidePanel()
  189. {
  190. %parent = MissionAreaEditorGui;
  191. %fixedWindow = MissionAreaEditorTerrainWindow;
  192. %fluidWindow = MissionAreaEditorPropertiesWindow;
  193. MissionAreaEditorGui_showBtn.Visible = "1";
  194. MissionAreaEditorGui_hideBtn.Visible = "0";
  195. // hide the content of the panels
  196. %fixedWindow.titleText = %fixedWindow.text;
  197. %fluidWindow.titleText = %fluidWindow.text;
  198. %fixedWindow.text = "";
  199. MissionAreaEditorTerrainPanel.Visible = "0";
  200. %fluidWindow.text = "";
  201. MissionAreaEditorPropertiesPanel.Visible = "0";
  202. MissionAreaInspectorPanel.Visible = "0";
  203. MissionAreaFieldInfoControlPanel.Visible = "0";
  204. // Let's do a resize so that the panel is collapsed to the side
  205. %position = Canvas.extent.x - 24 SPC %fixedWindow.position.y;
  206. %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y;
  207. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  208. %position = Canvas.extent.x - 24 SPC %fluidWindow.position.y;
  209. %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y;
  210. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  211. %parent.panelHidden = true;
  212. }
  213. function MissionAreaEditorGui::showSidePanel()
  214. {
  215. %parent = MissionAreaEditorGui;
  216. %fixedWindow = MissionAreaEditorTerrainWindow;
  217. %fluidWindow = MissionAreaEditorPropertiesWindow;
  218. MissionAreaEditorGui_showBtn.Visible = "0";
  219. MissionAreaEditorGui_hideBtn.Visible = "1";
  220. // show the content of the panels
  221. %fixedWindow.text = %fixedWindow.titleText;
  222. MissionAreaEditorTerrainPanel.Visible = "1";
  223. %fluidWindow.text = %fluidWindow.titleText;
  224. MissionAreaEditorPropertiesPanel.Visible = "1";
  225. MissionAreaInspectorPanel.Visible = "1";
  226. MissionAreaFieldInfoControlPanel.Visible = "1";
  227. %parent.resizing = true;
  228. %parent.maxSize(%fluidWindow);
  229. %parent.panelHidden = false;
  230. }
  231. //------------------------------------------------------------------------------
  232. function MissionAreaEditorGui::onEditorActivated( %this )
  233. {
  234. EWorldEditor.clearSelection();
  235. %ma = getMissionAreaServerObject();
  236. if( isObject( %ma ) )
  237. {
  238. EWorldEditor.selectObject( %ma );
  239. EWorldEditor.syncGui();
  240. MissionAreaEditorTerrainEditor.updateTerrain();
  241. %this.setSelectedMissionArea( %ma );
  242. %this.onMissionAreaSelected( %this.getSelectedMissionArea() );
  243. }
  244. }
  245. function MissionAreaEditorGui::onEditorDeactivated( %this )
  246. {
  247. }
  248. function MissionAreaEditorGui::onMissionAreaSelected( %this, %missionArea )
  249. {
  250. %this.missionArea = %missionArea;
  251. MissionAreaEditorTerrainEditor.setMissionArea( %missionArea );
  252. MissionAreaInspector.inspect( %missionArea );
  253. }
  254. //-----------------------------------------------------------------------------
  255. function MissionAreaEditorTerrainEditor::onMissionAreaModified( %this )
  256. {
  257. MissionAreaInspector.refresh();
  258. }
  259. function MissionAreaEditorTerrainEditor::onUndo( %this )
  260. {
  261. MissionAreaInspector.refresh();
  262. }
  263. //-----------------------------------------------------------------------------
  264. function MissionAreaInspector::inspect( %this, %obj )
  265. {
  266. %name = "";
  267. if ( isObject( %obj ) )
  268. %name = %obj.getName();
  269. else
  270. MissionAreaFieldInfoControl.setText( "" );
  271. //RiverInspectorNameEdit.setValue( %name );
  272. Parent::inspect( %this, %obj );
  273. }
  274. function MissionAreaInspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue )
  275. {
  276. // Same work to do as for the regular WorldEditor Inspector.
  277. Inspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue );
  278. }
  279. function MissionAreaInspector::onFieldSelected( %this, %fieldName, %fieldTypeStr, %fieldDoc )
  280. {
  281. MissionAreaFieldInfoControl.setText( "<font:" @ $Gui::fontTypeBold @ ":16>" @ %fieldName @ "<font:" @ $Gui::fontTypeItalic @ ":16> (" @ %fieldTypeStr @ ") " NL "<font:" @ $Gui::fontTypeRegular @ ":16>" @ %fieldDoc );
  282. }