@@ -26,7 +26,7 @@ public class MicroEngineerMod : BaseSpaceWarpPlugin
2626
2727 private readonly int windowWidth = 290 ;
2828 private readonly int windowHeight = 700 ;
29- private Rect mainGuiRect , vesGuiRect , orbGuiRect , surGuiRect , fltGuiRect , manGuiRect , tgtGuiRect , stgGuiRect ;
29+ public Rect mainGuiRect , settingsGuiRect , vesGuiRect , orbGuiRect , surGuiRect , fltGuiRect , manGuiRect , tgtGuiRect , stgGuiRect ;
3030 private Rect closeBtnRect ;
3131
3232 private GUISkin _spaceWarpUISkin ;
@@ -35,28 +35,30 @@ public class MicroEngineerMod : BaseSpaceWarpPlugin
3535 private GUIStyle popoutWindowStyle ;
3636 private GUIStyle sectionToggleStyle ;
3737 private GUIStyle closeBtnStyle ;
38+ private GUIStyle saveLoadBtnStyle ;
39+ private GUIStyle loadBtnStyle ;
3840 private GUIStyle nameLabelStyle ;
3941 private GUIStyle valueLabelStyle ;
4042 private GUIStyle unitLabelStyle ;
4143 private GUIStyle tableHeaderLabelStyle ;
4244
4345 private string unitColorHex ;
4446
45-
4647 private int spacingAfterHeader = - 12 ;
4748 private int spacingAfterEntry = - 12 ;
4849 private int spacingAfterSection = 5 ;
4950 private float spacingBelowPopout = 10 ;
5051
51- private bool showVes = true ;
52- private bool showOrb = true ;
53- private bool showSur = true ;
54- private bool showFlt = false ;
55- private bool showMan = true ;
56- private bool showTgt = false ;
57- private bool showStg = true ;
52+ public bool showSettings = false ;
53+ public bool showVes = true ;
54+ public bool showOrb = true ;
55+ public bool showSur = true ;
56+ public bool showFlt = false ;
57+ public bool showMan = true ;
58+ public bool showTgt = false ;
59+ public bool showStg = true ;
5860
59- private bool popoutVes , popoutOrb , popoutSur , popoutMan , popoutTgt , popoutFlt , popoutStg ;
61+ public bool popoutSettings , popoutVes , popoutOrb , popoutSur , popoutMan , popoutTgt , popoutFlt , popoutStg ;
6062
6163 private VesselComponent activeVessel ;
6264 private SimulationObjectModel currentTarget ;
@@ -132,6 +134,11 @@ public override void OnInitialized()
132134 fontSize = 8
133135 } ;
134136
137+ saveLoadBtnStyle = new GUIStyle ( _spaceWarpUISkin . button )
138+ {
139+ alignment = TextAnchor . MiddleCenter
140+ } ;
141+
135142 closeBtnRect = new Rect ( windowWidth - 23 , 6 , 16 , 16 ) ;
136143
137144 tableHeaderLabelStyle = new GUIStyle ( nameLabelStyle ) { alignment = TextAnchor . MiddleRight } ;
@@ -141,20 +148,33 @@ public override void OnInitialized()
141148 "BTN-MicroEngineerBtn" ,
142149 AssetManager . GetAsset < Texture2D > ( $ "{ SpaceWarpMetadata . ModID } /images/icon.png") ,
143150 delegate { showGUI = ! showGUI ; }
144-
145151 ) ;
152+
153+
154+ InitializeRects ( ) ;
155+ ResetLayout ( ) ;
156+ // load window positions and states from disk, if file exists
157+ LoadLayoutState ( ) ;
158+ }
159+
160+ private void InitializeRects ( )
161+ {
162+ mainGuiRect = settingsGuiRect = vesGuiRect = orbGuiRect = surGuiRect = fltGuiRect = manGuiRect = tgtGuiRect = stgGuiRect = new ( ) ;
146163 }
147164
148- void Awake ( )
165+ private void ResetLayout ( )
149166 {
150- mainGuiRect = new Rect ( Screen . width * 0.8f , Screen . height * 0.3f , 0 , 0 ) ;
151- vesGuiRect = new Rect ( Screen . width * 0.6f , Screen . height * 0.3f , 0 , 0 ) ;
152- orbGuiRect = new Rect ( Screen . width * 0.6f , Screen . height * 0.3f , 0 , 0 ) ;
153- surGuiRect = new Rect ( Screen . width * 0.6f , Screen . height * 0.3f , 0 , 0 ) ;
154- fltGuiRect = new Rect ( Screen . width * 0.6f , Screen . height * 0.3f , 0 , 0 ) ;
155- manGuiRect = new Rect ( Screen . width * 0.6f , Screen . height * 0.3f , 0 , 0 ) ;
156- tgtGuiRect = new Rect ( Screen . width * 0.6f , Screen . height * 0.3f , 0 , 0 ) ;
157- stgGuiRect = new Rect ( Screen . width * 0.6f , Screen . height * 0.3f , 0 , 0 ) ;
167+ popoutVes = popoutStg = popoutOrb = popoutSur = popoutFlt = popoutTgt = popoutMan = popoutSettings = false ;
168+ mainGuiRect . position = new ( Screen . width * 0.8f , Screen . height * 0.2f ) ;
169+ Vector2 popoutWindowPosition = new ( Screen . width * 0.6f , Screen . height * 0.2f ) ;
170+ vesGuiRect . position = popoutWindowPosition ;
171+ stgGuiRect . position = popoutWindowPosition ;
172+ orbGuiRect . position = popoutWindowPosition ;
173+ surGuiRect . position = popoutWindowPosition ;
174+ fltGuiRect . position = popoutWindowPosition ;
175+ tgtGuiRect . position = popoutWindowPosition ;
176+ manGuiRect . position = popoutWindowPosition ;
177+ settingsGuiRect . position = popoutWindowPosition ;
158178 }
159179
160180 private void OnGUI ( )
@@ -176,6 +196,11 @@ private void OnGUI()
176196 ) ;
177197 mainGuiRect . position = ClampToScreen ( mainGuiRect . position , mainGuiRect . size ) ;
178198
199+ if ( showSettings && popoutSettings )
200+ {
201+ DrawPopoutWindow ( ref settingsGuiRect , FillSettings ) ;
202+ }
203+
179204 if ( showVes && popoutVes )
180205 {
181206 DrawPopoutWindow ( ref vesGuiRect , FillVessel ) ;
@@ -256,11 +281,10 @@ private void FillMainGUI(int windowID)
256281 showTgt = GUILayout . Toggle ( showTgt , "<b>TGT</b>" , sectionToggleStyle ) ;
257282 GUILayout . EndHorizontal ( ) ;
258283
259-
260- GUILayout . Space ( - 10 ) ;
261-
262284 GUILayout . BeginHorizontal ( ) ;
263285 showMan = GUILayout . Toggle ( showMan , "<b>MAN</b>" , sectionToggleStyle ) ;
286+ GUILayout . Space ( 26 ) ;
287+ showSettings = GUILayout . Toggle ( showSettings , "<b>SET</b>" , sectionToggleStyle ) ;
264288 GUILayout . EndHorizontal ( ) ;
265289
266290
@@ -269,6 +293,11 @@ private void FillMainGUI(int windowID)
269293 GUILayout . BeginHorizontal ( ) ;
270294 GUILayout . EndHorizontal ( ) ;
271295
296+ if ( showSettings && ! popoutSettings )
297+ {
298+ FillSettings ( ) ;
299+ }
300+
272301 if ( showVes && ! popoutVes )
273302 {
274303 FillVessel ( ) ;
@@ -307,6 +336,25 @@ private void FillMainGUI(int windowID)
307336 GUI . DragWindow ( new Rect ( 0 , 0 , windowWidth , windowHeight ) ) ;
308337 }
309338
339+ private void FillSettings ( int _ = 0 )
340+ {
341+ DrawSectionHeader ( "Settings" , ref popoutSettings ) ;
342+
343+ GUILayout . Space ( 10 ) ;
344+ GUILayout . BeginHorizontal ( ) ;
345+ if ( GUILayout . Button ( "SAVE LAYOUT" , saveLoadBtnStyle ) )
346+ SaveLayoutState ( ) ;
347+ GUILayout . Space ( 5 ) ;
348+ if ( GUILayout . Button ( "LOAD LAYOUT" , saveLoadBtnStyle ) )
349+ LoadLayoutState ( ) ;
350+ GUILayout . Space ( 5 ) ;
351+ if ( GUILayout . Button ( "RESET" , saveLoadBtnStyle ) )
352+ ResetLayout ( ) ;
353+ GUILayout . EndHorizontal ( ) ;
354+
355+ DrawSectionEnd ( popoutSettings ) ;
356+ }
357+
310358 private void FillVessel ( int _ = 0 )
311359 {
312360 DrawSectionHeader ( "Vessel" , ref popoutVes , activeVessel . DisplayName ) ;
@@ -556,7 +604,7 @@ private string SituationToString(VesselSituations situation)
556604 VesselSituations . SubOrbital => "Suborbital" ,
557605 VesselSituations . Orbiting => "Orbiting" ,
558606 VesselSituations . Escaping => "Escaping" ,
559- _ => "UNNOWN " ,
607+ _ => "UNKNOWN " ,
560608 } ;
561609 }
562610
@@ -671,5 +719,45 @@ private void GetAeroStats()
671719 }
672720 }
673721 }
722+
723+ private void SaveLayoutState ( )
724+ {
725+ LayoutState state = new ( this ) ;
726+ state . Save ( ) ;
727+ }
728+
729+ private void LoadLayoutState ( )
730+ {
731+ LayoutState state = LayoutState . Load ( ) ;
732+
733+ if ( state != null )
734+ {
735+ showSettings = false ;
736+ showVes = state . ShowVes ;
737+ showOrb = state . ShowOrb ;
738+ showSur = state . ShowSur ;
739+ showFlt = state . ShowFlt ;
740+ showMan = state . ShowMan ;
741+ showTgt = state . ShowTgt ;
742+ showStg = state . ShowStg ;
743+ popoutSettings = state . IsPopoutSettings ;
744+ popoutVes = state . IsPopoutVes ;
745+ popoutOrb = state . IsPopoutOrb ;
746+ popoutSur = state . IsPopoutSur ;
747+ popoutFlt = state . IsPopOutFlt ;
748+ popoutMan = state . IsPopOutMan ;
749+ popoutTgt = state . IsPopOutTgt ;
750+ popoutStg = state . IsPopOutStg ;
751+ mainGuiRect . position = state . MainGuiPosition ;
752+ settingsGuiRect . position = state . SettingsPosition ;
753+ vesGuiRect . position = state . VesPosition ;
754+ orbGuiRect . position = state . OrbPosition ;
755+ surGuiRect . position = state . SurPosition ;
756+ fltGuiRect . position = state . FltPosition ;
757+ manGuiRect . position = state . ManPosition ;
758+ tgtGuiRect . position = state . TgtPosition ;
759+ stgGuiRect . position = state . StgPosition ;
760+ }
761+ }
674762 }
675763}
0 commit comments