Skip to content

Commit

Permalink
Merge pull request #28 from Falki-git/snap-windows-and-rename-entries
Browse files Browse the repository at this point in the history
Snap windows and rename entries
  • Loading branch information
Falki-git authored May 26, 2023
2 parents 5540ac0 + 2e2c90c commit 9e63990
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 127 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Micrologist
Copyright (c) 2023 Micrologist, Falki-git

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions MicroEngineerProject/MicroEngineer/Entries/BaseEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class BaseEntry
[JsonProperty]
public string Name;
[JsonProperty]
public Guid Id;
public string Description;
[JsonProperty]
public MicroEntryCategory Category;
Expand Down
41 changes: 30 additions & 11 deletions MicroEngineerProject/MicroEngineer/Managers/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ namespace MicroMod
{
internal class Manager
{
private static Manager _instance;

internal List<BaseWindow> Windows;
internal List<BaseEntry> Entries;
internal UI UI;
internal MessageManager MessageManager;
private MicroEngineerMod _plugin;

private static readonly ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("MicroEngineer.Manager");

internal Manager(MicroEngineerMod plugin)
public List<string> TextFieldNames = new List<string>();

internal Manager()
{
_plugin = plugin;
Entries = InitializeEntries();
Windows = InitializeWindows();
}

// Load window positions and states from disk, if file exists
Utility.LoadLayout(Windows);
public static Manager Instance
{
get
{
if (_instance == null)
_instance = new Manager();

return _instance;
}
}

public void Update()
Expand Down Expand Up @@ -297,17 +305,28 @@ internal void ResetLayout()
Entries.Clear();
Entries = InitializeEntries();
Windows = InitializeWindows();
UI.Windows = Windows;
MessageManager.Windows = Windows;
}

internal void LoadLayout()
{
Utility.LoadLayout(Windows);
UI.Windows = Windows;
MessageManager.Windows = Windows;
}

internal void SaveLayout() => Utility.SaveLayout(Windows);

public void PupulateTextFieldNames(List<BaseEntry> entries)
{
TextFieldNames.Clear();
TextFieldNames.Add(Utility.InputDisableWindowAbbreviation);
TextFieldNames.Add(Utility.InputDisableWindowName);

foreach (var entry in entries)
{
entry.Id = Guid.NewGuid();
TextFieldNames.Add(entry.Id.ToString());
}
}

public void AddTextFieldName(string name) => TextFieldNames.Add(name);
}
}
55 changes: 27 additions & 28 deletions MicroEngineerProject/MicroEngineer/Managers/MessageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ namespace MicroMod
{
internal class MessageManager
{
MicroEngineerMod _plugin;
private Manager _manager;
private UI _ui;
internal List<BaseWindow> Windows;
private static MessageManager _instance;

internal MessageManager(MicroEngineerMod plugin, Manager manager, UI ui)
internal MessageManager()
{ }

public static MessageManager Instance
{
_plugin = plugin;
_manager = manager;
_ui = ui;
Windows = _manager.Windows;
get
{
if (_instance == null)
_instance = new MessageManager();

SubscribeToMessages();
return _instance;
}
}

/// <summary>
/// Subscribe to KSP2 messages
/// </summary>
internal void SubscribeToMessages()
public void SubscribeToMessages()
{
Utility.RefreshGameManager();

Expand All @@ -50,21 +51,21 @@ internal void SubscribeToMessages()

private void OnManeuverCreatedMessage(MessageCenterMessage message)
{
var maneuverWindow = Windows.Find(w => w.GetType() == typeof(ManeuverWindow)) as ManeuverWindow;
var maneuverWindow = Manager.Instance.Windows.Find(w => w.GetType() == typeof(ManeuverWindow)) as ManeuverWindow;
maneuverWindow.OnManeuverCreatedMessage(message);
}

private void OnManeuverRemovedMessage(MessageCenterMessage message)
{
var maneuverWindow = Windows.Find(w => w.GetType() == typeof(ManeuverWindow)) as ManeuverWindow;
var maneuverWindow = Manager.Instance.Windows.Find(w => w.GetType() == typeof(ManeuverWindow)) as ManeuverWindow;
maneuverWindow.OnManeuverRemovedMessage(message);
}

private void OnPartManipulationCompletedMessage(MessageCenterMessage obj)
{
EntryWindow stageInfoOabWindow = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB);
EntryWindow stageInfoOabWindow = Manager.Instance.Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB);

Torque torque = (Torque)Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB).Entries.Find(e => e.Name == "Torque");
Torque torque = (Torque)Manager.Instance.Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB).Entries.Find(e => e.Name == "Torque");
torque.RefreshData();
}

Expand All @@ -73,22 +74,20 @@ private void GameStateEntered(MessageCenterMessage obj)
Utility.RefreshGameManager();
if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.VehicleAssemblyBuilder || Utility.GameState.GameState == GameState.Map3DView)
{
Utility.LoadLayout(Windows);
_manager.Windows = Windows;
_ui.Windows = Windows;
Utility.LoadLayout(Manager.Instance.Windows);

if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.Map3DView)
{
_ui.ShowGuiFlight = Windows.OfType<MainGuiWindow>().FirstOrDefault().IsFlightActive;
GameObject.Find("BTN-MicroEngineerBtn")?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(_ui.ShowGuiFlight);
UI.Instance.ShowGuiFlight = Manager.Instance.Windows.OfType<MainGuiWindow>().FirstOrDefault().IsFlightActive;
GameObject.Find("BTN-MicroEngineerBtn")?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(UI.Instance.ShowGuiFlight);
}

if (Utility.GameState.GameState == GameState.VehicleAssemblyBuilder)
{
_ui.ShowGuiOAB = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB).IsEditorActive;
GameObject.Find("BTN - MicroEngineerOAB")?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(_ui.ShowGuiOAB);
_ui.CelestialBodies.GetBodies();
_ui.CelestialBodySelectionStageIndex = -1;
UI.Instance.ShowGuiOAB = Manager.Instance.Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB).IsEditorActive;
GameObject.Find("BTN - MicroEngineerOAB")?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(UI.Instance.ShowGuiOAB);
UI.Instance.CelestialBodies.GetBodies();
UI.Instance.CelestialBodySelectionStageIndex = -1;
Styles.SetActiveTheme(Theme.Gray); // TODO implement other themes in OAB
}
}
Expand All @@ -99,13 +98,13 @@ private void GameStateLeft(MessageCenterMessage obj)
Utility.RefreshGameManager();
if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.VehicleAssemblyBuilder || Utility.GameState.GameState == GameState.Map3DView)
{
Utility.SaveLayout(Windows);
Utility.SaveLayout(Manager.Instance.Windows);

if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.Map3DView)
_ui.ShowGuiFlight = false;
UI.Instance.ShowGuiFlight = false;

if (Utility.GameState.GameState == GameState.VehicleAssemblyBuilder)
_ui.ShowGuiOAB = false;
UI.Instance.ShowGuiOAB = false;
}
}

Expand All @@ -123,7 +122,7 @@ private void RefreshStagingDataOAB(MessageCenterMessage obj)

Utility.RefreshStagesOAB();

EntryWindow stageWindow = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB);
EntryWindow stageWindow = Manager.Instance.Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB);

if (Utility.VesselDeltaVComponentOAB?.StageInfo == null)
{
Expand Down
Loading

0 comments on commit 9e63990

Please sign in to comment.