Skip to content

Commit

Permalink
Correctly handle SM mode toggle and changing systems
Browse files Browse the repository at this point in the history
  • Loading branch information
behindcurtain3 committed Apr 4, 2024
1 parent 69575ee commit c23bd78
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 138 deletions.
11 changes: 3 additions & 8 deletions Pulsar4X/Pulsar4X.Client/DebugAndPData/DebugGUIWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Pulsar4X.SDL2UI
public class DebugGUIWindow : PulsarGuiWindow
{

private DebugGUIWindow()
private DebugGUIWindow()
{

}
internal static DebugGUIWindow GetInstance()
{
Expand Down Expand Up @@ -45,7 +45,7 @@ internal override void Display()
ImGui.Text("Window Width: " + ImGui.GetContentRegionAvail().X);

string datetimenow = DateTime.Now.ToString();


}

Expand All @@ -61,10 +61,5 @@ public override void OnGameTickChange(DateTime newDate)
public override void OnSystemTickChange(DateTime newDate)
{
}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
throw new NotImplementedException();
}
}
}
5 changes: 0 additions & 5 deletions Pulsar4X/Pulsar4X.Client/DebugAndPData/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,10 +1293,5 @@ public override void OnSystemTickChange(DateTime newDate)
public override void OnGameTickChange(DateTime newDate)
{
}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
throw new NotImplementedException();
}
}
}
5 changes: 0 additions & 5 deletions Pulsar4X/Pulsar4X.Client/DebugAndPData/PerformanceWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,5 @@ public override void OnSystemTickChange(DateTime newDate)
{

}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
throw new NotImplementedException();
}
}
}
5 changes: 0 additions & 5 deletions Pulsar4X/Pulsar4X.Client/DebugAndPData/SensorDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,6 @@ public override void OnSystemTickChange(DateTime newDate)
{

}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
throw new NotImplementedException();
}
}

public class WaveDrawData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,5 @@ internal override void Display()
public override void OnGameTickChange(DateTime newDate)
{
}

public override void OnSystemTickChange(DateTime newDate)
{
}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
throw new NotImplementedException();
}
}
}
11 changes: 3 additions & 8 deletions Pulsar4X/Pulsar4X.Client/EmpireManagement/DistanceRuler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private DistanceRuler() {
//_flags = ImGuiWindowFlags.NoCollapse;
}



internal static DistanceRuler GetInstance() {

Expand All @@ -40,7 +40,7 @@ internal static DistanceRuler GetInstance() {
{
thisItem = (DistanceRuler)_uiState.LoadedWindows[typeof(DistanceRuler)];
}


return thisItem;

Expand Down Expand Up @@ -71,7 +71,7 @@ internal override void MapClicked(Orbital.Vector3 worldPos_m, MouseButtons butto
}
}
}

}
internal override void Display()
{
Expand Down Expand Up @@ -137,10 +137,5 @@ public override void OnGameTickChange(DateTime newDate)
public override void OnSystemTickChange(DateTime newDate)
{
}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
throw new NotImplementedException();
}
}
}
10 changes: 2 additions & 8 deletions Pulsar4X/Pulsar4X.Client/EntityManagement/CargoTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ public override void OnSystemTickChange(DateTime newDate)
Update();
}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
throw new NotImplementedException();
}


}

public delegate void CargoItemSelectedHandler(CargoListPanelComplex cargoPannel);
Expand Down Expand Up @@ -405,8 +399,8 @@ public class CargoTransfer : PulsarGuiWindow
CargoListPanelComplex? CargoListLeft
{
get { return _cargoList1; }
set
{
set
{
_cargoList1 = value;
if(value != null)
value.CargoItemSelectedEvent += OnCargoItemSelectedEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,5 @@ public override void OnGameTickChange(DateTime newDate)
public override void OnSystemTickChange(DateTime newDate)
{
}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void SetActive(bool ActiveVal = true)
IsActive = ActiveVal;
else
IsActive = false;

}

public void ToggleActive()
Expand All @@ -42,8 +42,8 @@ protected PulsarGuiWindow()
}


/*An example of how the constructor should be for a derived class.
*
/*An example of how the constructor should be for a derived class.
*
private DerivedClass (GlobalUIState state):base(state)
{
any other DerivedClass specific constrctor stuff here.
Expand Down Expand Up @@ -73,9 +73,5 @@ public override void OnGameTickChange(DateTime newDate)
public override void OnSystemTickChange(DateTime newDate)
{
}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Pulsar4X.Engine;
using System;
using System.Collections.Generic;
using System.Text;
using System;

namespace Pulsar4X.SDL2UI
{
Expand All @@ -14,8 +11,6 @@ public abstract class UpdateWindowState
public abstract void OnGameTickChange(DateTime newDate);
public abstract void OnSystemTickChange(DateTime newDate);

public abstract void OnSelectedSystemChange(StarSystem newStarSys);

protected UpdateWindowState()
{
_uiState.UpdateableWindows.Add(this);
Expand Down
30 changes: 11 additions & 19 deletions Pulsar4X/Pulsar4X.Client/GameManagment/GlobalUIState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ namespace Pulsar4X.SDL2UI
public delegate void EntityClickedEventHandler(EntityState entityState, MouseButtons mouseButton);

public delegate void FactionChangedEventHandler(GlobalUIState uIState);
public delegate void StarSystemChangedEventHandler(GlobalUIState uIState);

public class GlobalUIState
{
public event FactionChangedEventHandler OnFactionChanged;
public event StarSystemChangedEventHandler OnStarSystemChanged;

public bool debugnewgame = true;
//internal PulsarGuiWindow distanceRulerWindow { get; set; }
Expand Down Expand Up @@ -63,7 +65,7 @@ public class GlobalUIState
internal StarSystem SelectedSystem { get { return StarSystemStates[SelectedStarSysGuid].StarSystem; } }
internal DateTime SelectedSystemTime { get { return StarSystemStates[SelectedStarSysGuid].StarSystem.StarSysDateTime; } }
internal DateTime SelectedSysLastUpdateTime = new ();
internal string SelectedStarSysGuid { get { return GalacticMap.SelectedStarSysGuid; } }
internal string SelectedStarSysGuid { get; private set; }
internal SystemMapRendering SelectedSysMapRender { get { return GalacticMap.SelectedSysMapRender; } }
internal DateTime PrimarySystemDateTime;
internal EntityContextMenu ContextMenu { get; set; }
Expand Down Expand Up @@ -157,52 +159,42 @@ internal void SetFaction(Entity factionEntity, bool setAsPlayer = false)
var system = Game.Systems.First(s => s.Guid.Equals(guid));
StarSystemStates[guid] = new SystemState(system, factionEntity);
}
GalacticMap.SetFaction();

OnFactionChanged?.Invoke(this);
}

internal void SetActiveSystem(string activeSysID, bool refresh = false)
{
if(activeSysID != SelectedStarSysGuid || refresh){
//DeactivateAllClosableWindows();
if(!activeSysID.Equals(SelectedStarSysGuid) || refresh){
SelectedStarSysGuid = activeSysID;

var SelectedSys = StarSystemStates[activeSysID].StarSystem;
PrimarySystemDateTime = SelectedSys.ManagerSubpulses.StarSysDateTime;
GalacticMap.SelectedStarSysGuid = activeSysID;
DebugWindow.GetInstance().SystemState = StarSystemStates[activeSysID];
DebugWindow.GetInstance().SystemState = StarSystemStates[activeSysID]; // Fix this, should be handled internally in the window
LastClickedEntity = null;
PrimaryEntity = null;

OnStarSystemChanged?.Invoke(this);
}

}

internal void RefreshStarSystemStates()
{
SetFaction(Faction);
SetActiveSystem(SelectedStarSysGuid ,true);
SetActiveSystem(SelectedStarSysGuid, true);
}

internal void EnableGameMaster()
{
SMenabled = true;
StarSystemStates = new Dictionary<string, SystemState>();
var masterFaction = Game.GameMasterFaction;
SetFaction(masterFaction);
if(Game != null)
{
foreach (var system in Game.Systems)
{
StarSystemStates[system.Guid] = SystemState.GetMasterState((StarSystem)system);
}
}
SelectedSysMapRender.OnSelectedSystemChange(SelectedSystem);
SetFaction(Game.GameMasterFaction);
}

internal void DisableGameMaster()
{
SMenabled = false;
SetFaction(PlayerFaction);
SelectedSysMapRender.OnSelectedSystemChange(SelectedSystem);
}

internal void ToggleGameMaster()
Expand Down
5 changes: 0 additions & 5 deletions Pulsar4X/Pulsar4X.Client/GameManagment/MainMenuItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,5 @@ public override void OnGameTickChange(DateTime newDate)
public override void OnSystemTickChange(DateTime newDate)
{
}

public override void OnSelectedSystemChange(StarSystem newStarSys)
{
throw new NotImplementedException();
}
}
}
11 changes: 1 addition & 10 deletions Pulsar4X/Pulsar4X.Client/GameManagment/NewGameOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ void CreateNewGame()
GameName = ImGuiSDL2CSHelper.StringFromBytes(_nameInputBuffer),
MaxSystems = _maxSystems,
SMPassword = ImGuiSDL2CSHelper.StringFromBytes(_smPassInputbuffer),
//DataSets = options.SelectedModList.Select(dvi => dvi.Directory),
CreatePlayerFaction = true,
DefaultFactionName = ImGuiSDL2CSHelper.StringFromBytes(_factionInputBuffer),
DefaultPlayerPassword = ImGuiSDL2CSHelper.StringFromBytes(_passInputBuffer),
Expand All @@ -107,20 +106,12 @@ void CreateNewGame()

Pulsar4X.Engine.Game game = new Pulsar4X.Engine.Game(gameSettings, modDataStore);

var factionName = ImGuiSDL2CSHelper.StringFromBytes(_factionInputBuffer);
var factionPasswd = ImGuiSDL2CSHelper.StringFromBytes(_passInputBuffer);

// TODO: need to add the implementation for a random start
var (newGameFaction, systemId) = Pulsar4X.Engine.DefaultStartFactory.LoadFromJson(game, "Data/basemod/defaultStart.json");

if(newGameFaction == null) return;

//TODO: Tidyup: new Game(gameSettings) doesn't currently create a default faction as per the settings.
//this should probilby be fixed, either we create it there or we... dont.
//_uiState.Game = new ECSLib.Game(gameSettings);
_uiState.Game = game;

// var factionEntity = DefaultStartFactory.DefaultHumans(game, factionName);
// AuthProcessor.StorePasswordAsHash(StaticRefLib.Game, factionEntity, factionPasswd);
_uiState.SetFaction(newGameFaction, true);
_uiState.SetActiveSystem(systemId);

Expand Down
Loading

0 comments on commit c23bd78

Please sign in to comment.