@@ -7,25 +7,26 @@ namespace MicroMod
77{
88 internal class MessageManager
99 {
10- MicroEngineerMod _plugin ;
11- private Manager _manager ;
12- private UI _ui ;
13- internal List < BaseWindow > Windows ;
10+ private static MessageManager _instance ;
1411
15- internal MessageManager ( MicroEngineerMod plugin , Manager manager , UI ui )
12+ internal MessageManager ( )
13+ { }
14+
15+ public static MessageManager Instance
1616 {
17- _plugin = plugin ;
18- _manager = manager ;
19- _ui = ui ;
20- Windows = _manager . Windows ;
17+ get
18+ {
19+ if ( _instance == null )
20+ _instance = new MessageManager ( ) ;
2121
22- SubscribeToMessages ( ) ;
22+ return _instance ;
23+ }
2324 }
2425
2526 /// <summary>
2627 /// Subscribe to KSP2 messages
2728 /// </summary>
28- internal void SubscribeToMessages ( )
29+ public void SubscribeToMessages ( )
2930 {
3031 Utility . RefreshGameManager ( ) ;
3132
@@ -50,21 +51,21 @@ internal void SubscribeToMessages()
5051
5152 private void OnManeuverCreatedMessage ( MessageCenterMessage message )
5253 {
53- var maneuverWindow = Windows . Find ( w => w . GetType ( ) == typeof ( ManeuverWindow ) ) as ManeuverWindow ;
54+ var maneuverWindow = Manager . Instance . Windows . Find ( w => w . GetType ( ) == typeof ( ManeuverWindow ) ) as ManeuverWindow ;
5455 maneuverWindow . OnManeuverCreatedMessage ( message ) ;
5556 }
5657
5758 private void OnManeuverRemovedMessage ( MessageCenterMessage message )
5859 {
59- var maneuverWindow = Windows . Find ( w => w . GetType ( ) == typeof ( ManeuverWindow ) ) as ManeuverWindow ;
60+ var maneuverWindow = Manager . Instance . Windows . Find ( w => w . GetType ( ) == typeof ( ManeuverWindow ) ) as ManeuverWindow ;
6061 maneuverWindow . OnManeuverRemovedMessage ( message ) ;
6162 }
6263
6364 private void OnPartManipulationCompletedMessage ( MessageCenterMessage obj )
6465 {
65- EntryWindow stageInfoOabWindow = Windows . FindAll ( w => w is EntryWindow ) . Cast < EntryWindow > ( ) . ToList ( ) . Find ( w => w . MainWindow == MainWindow . StageInfoOAB ) ;
66+ EntryWindow stageInfoOabWindow = Manager . Instance . Windows . FindAll ( w => w is EntryWindow ) . Cast < EntryWindow > ( ) . ToList ( ) . Find ( w => w . MainWindow == MainWindow . StageInfoOAB ) ;
6667
67- Torque torque = ( Torque ) Windows . FindAll ( w => w is EntryWindow ) . Cast < EntryWindow > ( ) . ToList ( ) . Find ( w => w . MainWindow == MainWindow . StageInfoOAB ) . Entries . Find ( e => e . Name == "Torque" ) ;
68+ 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" ) ;
6869 torque . RefreshData ( ) ;
6970 }
7071
@@ -73,22 +74,20 @@ private void GameStateEntered(MessageCenterMessage obj)
7374 Utility . RefreshGameManager ( ) ;
7475 if ( Utility . GameState . GameState == GameState . FlightView || Utility . GameState . GameState == GameState . VehicleAssemblyBuilder || Utility . GameState . GameState == GameState . Map3DView )
7576 {
76- Utility . LoadLayout ( Windows ) ;
77- _manager . Windows = Windows ;
78- _ui . Windows = Windows ;
77+ Utility . LoadLayout ( Manager . Instance . Windows ) ;
7978
8079 if ( Utility . GameState . GameState == GameState . FlightView || Utility . GameState . GameState == GameState . Map3DView )
8180 {
82- _ui . ShowGuiFlight = Windows . OfType < MainGuiWindow > ( ) . FirstOrDefault ( ) . IsFlightActive ;
83- GameObject . Find ( "BTN-MicroEngineerBtn" ) ? . GetComponent < UIValue_WriteBool_Toggle > ( ) ? . SetValue ( _ui . ShowGuiFlight ) ;
81+ UI . Instance . ShowGuiFlight = Manager . Instance . Windows . OfType < MainGuiWindow > ( ) . FirstOrDefault ( ) . IsFlightActive ;
82+ GameObject . Find ( "BTN-MicroEngineerBtn" ) ? . GetComponent < UIValue_WriteBool_Toggle > ( ) ? . SetValue ( UI . Instance . ShowGuiFlight ) ;
8483 }
8584
8685 if ( Utility . GameState . GameState == GameState . VehicleAssemblyBuilder )
8786 {
88- _ui . ShowGuiOAB = Windows . FindAll ( w => w is EntryWindow ) . Cast < EntryWindow > ( ) . ToList ( ) . Find ( w => w . MainWindow == MainWindow . StageInfoOAB ) . IsEditorActive ;
89- GameObject . Find ( "BTN - MicroEngineerOAB" ) ? . GetComponent < UIValue_WriteBool_Toggle > ( ) ? . SetValue ( _ui . ShowGuiOAB ) ;
90- _ui . CelestialBodies . GetBodies ( ) ;
91- _ui . CelestialBodySelectionStageIndex = - 1 ;
87+ UI . Instance . ShowGuiOAB = Manager . Instance . Windows . FindAll ( w => w is EntryWindow ) . Cast < EntryWindow > ( ) . ToList ( ) . Find ( w => w . MainWindow == MainWindow . StageInfoOAB ) . IsEditorActive ;
88+ GameObject . Find ( "BTN - MicroEngineerOAB" ) ? . GetComponent < UIValue_WriteBool_Toggle > ( ) ? . SetValue ( UI . Instance . ShowGuiOAB ) ;
89+ UI . Instance . CelestialBodies . GetBodies ( ) ;
90+ UI . Instance . CelestialBodySelectionStageIndex = - 1 ;
9291 Styles . SetActiveTheme ( Theme . Gray ) ; // TODO implement other themes in OAB
9392 }
9493 }
@@ -99,13 +98,13 @@ private void GameStateLeft(MessageCenterMessage obj)
9998 Utility . RefreshGameManager ( ) ;
10099 if ( Utility . GameState . GameState == GameState . FlightView || Utility . GameState . GameState == GameState . VehicleAssemblyBuilder || Utility . GameState . GameState == GameState . Map3DView )
101100 {
102- Utility . SaveLayout ( Windows ) ;
101+ Utility . SaveLayout ( Manager . Instance . Windows ) ;
103102
104103 if ( Utility . GameState . GameState == GameState . FlightView || Utility . GameState . GameState == GameState . Map3DView )
105- _ui . ShowGuiFlight = false ;
104+ UI . Instance . ShowGuiFlight = false ;
106105
107106 if ( Utility . GameState . GameState == GameState . VehicleAssemblyBuilder )
108- _ui . ShowGuiOAB = false ;
107+ UI . Instance . ShowGuiOAB = false ;
109108 }
110109 }
111110
@@ -123,7 +122,7 @@ private void RefreshStagingDataOAB(MessageCenterMessage obj)
123122
124123 Utility . RefreshStagesOAB ( ) ;
125124
126- EntryWindow stageWindow = Windows . FindAll ( w => w is EntryWindow ) . Cast < EntryWindow > ( ) . ToList ( ) . Find ( w => w . MainWindow == MainWindow . StageInfoOAB ) ;
125+ EntryWindow stageWindow = Manager . Instance . Windows . FindAll ( w => w is EntryWindow ) . Cast < EntryWindow > ( ) . ToList ( ) . Find ( w => w . MainWindow == MainWindow . StageInfoOAB ) ;
127126
128127 if ( Utility . VesselDeltaVComponentOAB ? . StageInfo == null )
129128 {
0 commit comments