Skip to content

Commit 096166d

Browse files
committed
Add minimize to MainGUI window
1 parent 8b3ac5d commit 096166d

File tree

8 files changed

+49
-14
lines changed

8 files changed

+49
-14
lines changed

MicroEngineerProject/MicroEngineer/MicroEngineerMod.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace MicroMod
1111
{
12-
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.3.2")]
12+
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.4.0")]
1313
[BepInDependency(SpaceWarpPlugin.ModGuid, SpaceWarpPlugin.ModVer)]
1414
public class MicroEngineerMod : BaseSpaceWarpPlugin
1515
{
@@ -32,7 +32,11 @@ public override void OnInitialized()
3232
isOpen =>
3333
{
3434
if (isOpen)
35-
Manager.Instance.Windows.Find(w => w.GetType() == typeof(MainGuiWindow)).IsFlightActive = isOpen;
35+
{
36+
var mainWindow = Manager.Instance.Windows.Find(w => w is MainGuiWindow) as MainGuiWindow;
37+
mainWindow.IsFlightActive = true;
38+
mainWindow.IsFlightMinimized = false;
39+
}
3640
FlightSceneController.Instance.ShowGui = isOpen;
3741
Utility.SaveLayout();
3842
});
@@ -59,15 +63,29 @@ public void Update()
5963
{
6064
if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.Map3DView)
6165
{
62-
bool guiState = FlightSceneController.Instance.ShowGui;
63-
FlightSceneController.Instance.ShowGui = !guiState;
64-
Manager.Instance.Windows.Find(w => w.GetType() == typeof(MainGuiWindow)).IsFlightActive = !guiState;
66+
var mainWindow = Manager.Instance.Windows.Find(w => w is MainGuiWindow) as MainGuiWindow;
67+
68+
// if MainGUI is minimized then treat it like it isn't open at all
69+
if (mainWindow.IsFlightMinimized)
70+
{
71+
mainWindow.IsFlightMinimized = false;
72+
mainWindow.IsFlightActive = true;
73+
FlightSceneController.Instance.ShowGui = true;
74+
}
75+
else
76+
{
77+
bool guiState = FlightSceneController.Instance.ShowGui;
78+
FlightSceneController.Instance.ShowGui = !guiState;
79+
mainWindow.IsFlightActive = !guiState;
80+
}
81+
Utility.SaveLayout();
6582
}
6683
else if (Utility.GameState.GameState == GameState.VehicleAssemblyBuilder)
6784
{
6885
bool guiState = OABSceneController.Instance.ShowGui;
6986
OABSceneController.Instance.ShowGui = !guiState;
7087
Manager.Instance.Windows.Find(w => w.GetType() == typeof(StageInfoOabWindow)).IsEditorActive = !guiState;
88+
Utility.SaveLayout();
7189
}
7290
}
7391
}

MicroEngineerProject/MicroEngineer/UI/Controllers/FlightSceneController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public bool ShowGui
2525
set
2626
{
2727
_showGui = value;
28-
29-
GameObject.Find("BTN-MicroEngineerBtn")?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(value);
3028

3129
RebuildUI();
3230

@@ -76,9 +74,12 @@ public static FlightSceneController Instance
7674
public void InitializeUI()
7775
{
7876
//Build MainGui
79-
MainGui = Window.CreateFromUxml(Uxmls.Instance.BaseWindow, "MainGui", null, true);
80-
MainGuiController mainGuiController = MainGui.gameObject.AddComponent<MainGuiController>();
81-
MainGui.rootVisualElement[0].RegisterCallback<PointerMoveEvent>(evt => Utility.ClampToScreenUitk(MainGui.rootVisualElement[0]));
77+
if ((Manager.Instance.Windows.Find(w => w is MainGuiWindow) as MainGuiWindow).IsFlightMinimized == false)
78+
{
79+
MainGui = Window.CreateFromUxml(Uxmls.Instance.BaseWindow, "MainGui", null, true);
80+
MainGuiController mainGuiController = MainGui.gameObject.AddComponent<MainGuiController>();
81+
MainGui.rootVisualElement[0].RegisterCallback<PointerMoveEvent>(evt => Utility.ClampToScreenUitk(MainGui.rootVisualElement[0]));
82+
}
8283

8384
//Build poppedout windows
8485
foreach (EntryWindow poppedOutWindow in Manager.Instance.Windows.Where(w => w is EntryWindow && ((EntryWindow)w).IsFlightPoppedOut))

MicroEngineerProject/MicroEngineer/UI/Controllers/MainGuiController.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MicroMod;
1+
using KSP.UI.Binding;
2+
using MicroMod;
23
using UnityEngine;
34
using UnityEngine.UIElements;
45

@@ -12,6 +13,7 @@ public class MainGuiController : MonoBehaviour
1213
public VisualElement Header { get; set; }
1314
public Button EditWindowsButton { get; set; }
1415
public Button CloseButton { get; set; }
16+
public Button MinimizeButton { get; set; }
1517
public VisualElement Body { get; set; }
1618

1719
public MainGuiController()
@@ -51,6 +53,8 @@ private void BuildMainGuiHeader()
5153
var mainGuiHeader = Uxmls.Instance.MainGuiHeader.CloneTree();
5254
CloseButton = mainGuiHeader.Q<Button>("close-button");
5355
CloseButton.RegisterCallback<ClickEvent>(OnCloseButton);
56+
MinimizeButton = mainGuiHeader.Q<Button>("minimize-button");
57+
MinimizeButton.RegisterCallback<ClickEvent>(OnMinimizeButton);
5458
EditWindowsButton = mainGuiHeader.Q<Button>("editwindows-button");
5559
EditWindowsButton.RegisterCallback<ClickEvent>(evt => FlightSceneController.Instance.ToggleEditWindows());
5660
Header.Add(mainGuiHeader);
@@ -72,6 +76,15 @@ private void OnCloseButton(ClickEvent evt)
7276

7377
Utility.SaveLayout();
7478
FlightSceneController.Instance.ShowGui = false;
79+
GameObject.Find("BTN-MicroEngineerBtn")?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(false);
80+
}
81+
82+
private void OnMinimizeButton(ClickEvent evt)
83+
{
84+
MainGuiWindow.IsFlightMinimized = true;
85+
86+
Utility.SaveLayout();
87+
FlightSceneController.Instance.RebuildUI();
7588
}
7689
}
7790
}

MicroEngineerProject/MicroEngineer/Windows/MainGuiWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ public class MainGuiWindow : BaseWindow
66
{
77
[JsonProperty]
88
public int LayoutVersion;
9+
[JsonProperty]
10+
public bool IsFlightMinimized;
911
}
1012
}
169 Bytes
Loading
23.7 KB
Binary file not shown.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ Mod folder will be placed in ..\Kerbal Space Program 2\BepInEx\plugins\
2525

2626
# Usage
2727
* While in flight or VAB, open the mod window by clicking its entry on the APP BAR
28-
* Or press ALT + E to toggle windows
28+
* Or press CTRL + E to toggle windows
2929

3030
### Flight:
3131
* Pop out windows and drag the where you want
32-
* Popped out windows will snap to each other when being near
32+
* Minimize the main window to hide irrelevant data
33+
* Popped out windows will snap to each other when being near
3334
* Open Edit windows by clicking on the gear icon
3435
* Edit windows:
3536
* add or remove any entry from any window any way you like

Staging/BepInEx/plugins/micro_engineer/swinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Micro Engineer",
66
"description": "Get in-flight and VAB information about your current vessel",
77
"source": "https://github.com/Micrologist/MicroEngineer",
8-
"version": "1.3.2",
8+
"version": "1.4.0",
99
"version_check": "https://raw.githubusercontent.com/Micrologist/MicroEngineer/main/Staging/BepInEx/plugins/micro_engineer/swinfo.json",
1010
"dependencies": [
1111
{

0 commit comments

Comments
 (0)