diff --git a/Pulsar4X/Pulsar4X.ECSLib/Entity/EntityManager.cs b/Pulsar4X/Pulsar4X.ECSLib/Entity/EntityManager.cs index c7c156658..57324cbc3 100644 --- a/Pulsar4X/Pulsar4X.ECSLib/Entity/EntityManager.cs +++ b/Pulsar4X/Pulsar4X.ECSLib/Entity/EntityManager.cs @@ -33,8 +33,13 @@ public class EntityManager : ISerializable internal List EntityListners = new List(); - public Dictionary FactionSensorContacts = new Dictionary(); - + internal Dictionary FactionSensorContacts = new Dictionary(); + public SystemSensorContacts GetSensorContacts(Guid factionGuid) + { + if (!FactionSensorContacts.ContainsKey(factionGuid)) + return new SystemSensorContacts(this, GetGlobalEntityByGuid(factionGuid)); + return FactionSensorContacts[factionGuid]; + } Dictionary> EntitesByFaction = new Dictionary>(); public List GetEntitiesByFaction(Guid factionGuid) { @@ -396,7 +401,7 @@ public List GetAllEntitiesWithDataBlob(AuthenticationToken authToken) /// /// Thrown when T is not derived from BaseDataBlob. [NotNull] - internal List GetAllEntitiesWithDataBlob() where T : BaseDataBlob + public List GetAllEntitiesWithDataBlob() where T : BaseDataBlob { int typeIndex = GetTypeIndex(); @@ -540,7 +545,7 @@ public Entity GetFirstEntityWithDataBlob(AuthenticationToken authToken) where /// /// Thrown when T is not derived from BaseDataBlob. [NotNull] - internal Entity GetFirstEntityWithDataBlob() where T : BaseDataBlob + public Entity GetFirstEntityWithDataBlob() where T : BaseDataBlob { return GetFirstEntityWithDataBlob(GetTypeIndex()); } diff --git a/Pulsar4X/Pulsar4X.ECSLib/Faction/FactionInfoDB.cs b/Pulsar4X/Pulsar4X.ECSLib/Faction/FactionInfoDB.cs index 438ca3b4a..16f3e2e3a 100644 --- a/Pulsar4X/Pulsar4X.ECSLib/Faction/FactionInfoDB.cs +++ b/Pulsar4X/Pulsar4X.ECSLib/Faction/FactionInfoDB.cs @@ -10,11 +10,11 @@ public class FactionInfoDB : BaseDataBlob, IGetValuesHash { [JsonProperty] - public List Species { get; internal set; } + public List Species { get; internal set; } = new List(); [JsonProperty] - public List KnownSystems { get; internal set; } + public List KnownSystems { get; internal set; } = new List(); public ReadOnlyDictionary> KnownJumpPoints => new ReadOnlyDictionary>(InternalKnownJumpPoints); @@ -23,15 +23,15 @@ public class FactionInfoDB : BaseDataBlob, IGetValuesHash [JsonProperty] - public List KnownFactions { get; internal set; } + public List KnownFactions { get; internal set; } = new List(); [PublicAPI] [JsonProperty] - public List Colonies { get; internal set; } + public List Colonies { get; internal set; } = new List(); [JsonProperty] - public List ShipClasses { get; internal set; } + public List ShipClasses { get; internal set; } = new List(); public ReadOnlyDictionary ComponentDesigns => new ReadOnlyDictionary(InternalComponentDesigns); @@ -51,7 +51,7 @@ public class FactionInfoDB : BaseDataBlob, IGetValuesHash internal Dictionary SensorContacts = new Dictionary(); - public FactionInfoDB() : this(new List(), new List(), new List(), new List() ) { } + public FactionInfoDB() { } public FactionInfoDB( List species, diff --git a/Pulsar4X/Pulsar4X.ECSLib/Game.cs b/Pulsar4X/Pulsar4X.ECSLib/Game.cs index 0bc32c364..f1383428f 100644 --- a/Pulsar4X/Pulsar4X.ECSLib/Game.cs +++ b/Pulsar4X/Pulsar4X.ECSLib/Game.cs @@ -36,12 +36,12 @@ public DateTime CurrentDateTime } internal ProcessorManager ProcessorManager; - + /// /// List of StarSystems currently in the game. /// [JsonProperty] - internal Dictionary Systems { get; private set; } = new Dictionary(); + public Dictionary Systems { get; private set; } = new Dictionary(); [JsonProperty] public readonly EntityManager GlobalManager; diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/DebugWindow.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/DebugWindow.cs index 03d2eed40..ed864c373 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/DebugWindow.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/DebugWindow.cs @@ -47,7 +47,7 @@ internal static DebugWindow GetInstance() instance._selectedEntityState = _state.LastClickedEntity; } instance._selectedEntityState = _state.LastClickedEntity; - instance._systemState = _state.StarSystemStates[_state.ActiveSystem.Guid]; + instance._systemState = _state.StarSystemStates[_state.PrimarySystem.Guid]; return instance; } @@ -58,7 +58,7 @@ internal void SetGameEvents() if (_state.Game != null) { _state.Game.GameLoop.GameGlobalDateChangedEvent += GameLoop_GameGlobalDateChangedEvent; - _state.MapRendering.SysMap.SystemSubpulse.SystemDateChangedEvent += SystemSubpulse_SystemDateChangedEvent; + _state.PrimarySystem.ManagerSubpulses.SystemDateChangedEvent += SystemSubpulse_SystemDateChangedEvent; _state.EntityClickedEvent += _state_EntityClicked; } } @@ -138,7 +138,7 @@ internal override void Display() SetFrameRateArray(); if (ImGui.Begin("debug", ref IsActive)) { - ImGui.Text(_state.CurrentSystemDateTime.ToString()); + ImGui.Text(_state.PrimarySystemDateTime.ToString()); ImGui.Text("Cursor World Coordinate:"); var mouseWorldCoord = _state.Camera.MouseWorldCoordinate(); ImGui.Text("x" + mouseWorldCoord.X); @@ -173,7 +173,7 @@ internal override void Display() if (ImGui.CollapsingHeader("Entity List")) { - List factionOwnedEntites = _state.ActiveSystem.GetEntitiesByFaction(_state.Faction.Guid); + List factionOwnedEntites = _state.PrimarySystem.GetEntitiesByFaction(_state.Faction.Guid); List entityNames = new List(); foreach (var entity in factionOwnedEntites) { @@ -226,9 +226,9 @@ internal override void Display() //if (_state.CurrentSystemDateTime != lastDate) //{ - pos = OrbitProcessor.GetAbsolutePosition_AU(orbitDB, _state.CurrentSystemDateTime); - truAnomoly = OrbitProcessor.GetTrueAnomaly(orbitDB, _state.CurrentSystemDateTime); - lastDate = _state.CurrentSystemDateTime; + pos = OrbitProcessor.GetAbsolutePosition_AU(orbitDB, _state.PrimarySystemDateTime); + truAnomoly = OrbitProcessor.GetTrueAnomaly(orbitDB, _state.PrimarySystemDateTime); + lastDate = _state.PrimarySystemDateTime; //} ImGui.Text("x: " + pos.X); @@ -314,7 +314,7 @@ internal override void Display() ImGui.SameLine(); double distancekm = Distance.AuToKm(distance); ImGui.Text(distancekm.ToString() + " KM"); - var timeToTarget = db.PredictedExitTime - _state.CurrentSystemDateTime; + var timeToTarget = db.PredictedExitTime - _state.PrimarySystemDateTime; ImGui.Text("Remaining TTT " + timeToTarget); var totalTime = db.PredictedExitTime - db.EntryDateTime; ImGui.Text("Total TTT " + totalTime); @@ -323,7 +323,7 @@ internal override void Display() ImGui.Text("LastDateTime: "); ImGui.Text(db.LastProcessDateTime.ToString()); ImGui.Text("Time Since Last: "); - var timelen = _state.CurrentSystemDateTime - db.LastProcessDateTime; + var timelen = _state.PrimarySystemDateTime - db.LastProcessDateTime; ImGui.Text(timelen.ToString()); } diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/EntityContextMenu.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/EntityContextMenu.cs index 7fed4da0d..05fc45f3b 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/EntityContextMenu.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/EntityContextMenu.cs @@ -19,7 +19,7 @@ public EntityContextMenu(GlobalUIState state, Guid entityGuid) _state = state; //_state.OpenWindows.Add(this); //IsActive = true; - _entityState = state.StarSystemStates[state.ActiveSystem.Guid].EntityStates[entityGuid]; + _entityState = state.StarSystemStates[state.PrimarySystem.Guid].EntityStates[entityGuid]; } diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/GlobalUIState.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/GlobalUIState.cs index 53654fb7d..55ab7a8fe 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/GlobalUIState.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/GlobalUIState.cs @@ -15,7 +15,6 @@ public class GlobalUIState internal FactionVM FactionUIState; internal bool IsGameLoaded { get { return Game != null; } } internal Entity Faction { get { return FactionUIState.FactionEntity; } } - internal StarSystem ActiveSystem; internal bool ShowMetrixWindow; internal bool ShowImgDbg; internal bool ShowDemoWindow; @@ -25,7 +24,12 @@ public class GlobalUIState //internal MainMenuItems MainMenu { get; } //internal NewGameOptions NewGameOptions { get; } //internal SettingsWindow SettingsWindow { get; } - internal SystemMapRendering MapRendering { get; set; } + internal GalacticMapRender GalacticMap; + + internal StarSystem PrimarySystem; + internal SystemMapRendering PrimaryMapRender { get { return GalacticMap.PrimarySysMap; } } + internal DateTime PrimarySystemDateTime; //= new DateTime(); + internal EntityContextMenu ContextMenu { get; set; } //internal IOrderWindow ActiveOrderWidow { get; set; } //internal DebugWindow Debug { get; set; } @@ -47,7 +51,7 @@ public class GlobalUIState internal EntityState LastClickedEntity; internal ECSLib.Vector4 LastWorldPointClicked; - internal DateTime CurrentSystemDateTime; //= new DateTime(); + internal SpaceMasterVM SpaceMasterVM; @@ -93,6 +97,32 @@ internal void LoadImg(string name, string path) SDLImageDictionary.Add(name, sdltexture); } + internal void SetFaction(Entity factionEntity) + { + FactionInfoDB factionInfo = factionEntity.GetDataBlob(); + StarSystemStates = new Dictionary(); + foreach (var guid in factionInfo.KnownSystems) + { + StarSystemStates[guid] = new SystemState(Game.Systems[guid], factionEntity); + } + GalacticMap.SetFaction(); + } + + internal void SetActiveSystem(Guid activeSysID) + { + PrimarySystem = StarSystemStates[activeSysID].StarSystem; + PrimarySystemDateTime = PrimarySystem.ManagerSubpulses.SystemLocalDateTime; + GalacticMap.PrimarySysMap = GalacticMap.RenderedMaps[activeSysID]; + } + + internal void EnableGameMaster() + { + StarSystemStates = new Dictionary(); + foreach (var system in Game.Systems) + { + StarSystemStates[system.Key] = SystemState.GetMasterState(system.Value); + } + } internal void MapClicked(ECSLib.Vector4 worldCoord, MouseButtons button) { @@ -105,21 +135,21 @@ internal void MapClicked(ECSLib.Vector4 worldCoord, MouseButtons button) internal void EntityClicked(Guid entityGuid, MouseButtons button) { - LastClickedEntity = StarSystemStates[ActiveSystem.Guid].EntityStates[entityGuid]; + LastClickedEntity = StarSystemStates[PrimarySystem.Guid].EntityStates[entityGuid]; EntityClickedEvent?.Invoke(LastClickedEntity, button); if (ActiveWindow != null) - ActiveWindow.EntityClicked(StarSystemStates[ActiveSystem.Guid].EntityStates[entityGuid], button); + ActiveWindow.EntityClicked(StarSystemStates[PrimarySystem.Guid].EntityStates[entityGuid], button); OnEntitySelected(); } void OnEntitySelected() { - MapRendering.SelectedEntityExtras = new List(); + PrimaryMapRender.SelectedEntityExtras = new List(); if(LastClickedEntity.DebugOrbitOrder != null) { - MapRendering.SelectedEntityExtras.Add(LastClickedEntity.DebugOrbitOrder); + PrimaryMapRender.SelectedEntityExtras.Add(LastClickedEntity.DebugOrbitOrder); } } diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/GalacticMapRender.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/GalacticMapRender.cs new file mode 100644 index 000000000..ed38f1a8f --- /dev/null +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/GalacticMapRender.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using ImGuiSDL2CS; + +namespace Pulsar4X.SDL2UI +{ + public class GalacticMapRender + { + GlobalUIState _state; + List SystemStates = new List(); + internal Dictionary RenderedMaps = new Dictionary(); + ImGuiSDL2CSWindow _window; + internal SystemMapRendering PrimarySysMap { get; set; } + + public GalacticMapRender(ImGuiSDL2CSWindow window, GlobalUIState state) + { + _state = state; + _window = window; + + } + + internal void SetFaction() + { + int i = 0; + double startangle = Math.PI * 0.5; + float angleIncrease = 0.01f; + int startR = 32; + int radInc = 5; + foreach (var item in _state.StarSystemStates) + { + + SystemMapRendering map = new SystemMapRendering(_window, _state); + map.SetSystem(item.Value.StarSystem); + RenderedMaps[item.Key] = map; + var x = (startR + radInc * i) * Math.Sin(startangle - angleIncrease * i); + var y = (startR + radInc * i) * Math.Cos(startangle - angleIncrease * i); + map.GalacticMapPosition.X = x; + map.GalacticMapPosition.Y = y; + i++; + } + } + + internal void DrawNameIcons() + { + foreach (var kvp in RenderedMaps) + { + var sysid = kvp.Key; + var sysmap = kvp.Value; + sysmap.DrawNameIcons(); + } + } + + internal void Draw() + { + foreach (var kvp in RenderedMaps) + { + var sysid = kvp.Key; + var sysmap = kvp.Value; + sysmap.Draw(); + } + } + } +} diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/GalaxyMap.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/GalaxyMap.cs new file mode 100644 index 000000000..2c958b633 --- /dev/null +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/GalaxyMap.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using ImGuiSDL2CS; +using Pulsar4X.ECSLib; +using SDL2; + +namespace Pulsar4X.SDL2UI +{ + public class SystemIcon + { + public PointD _mapPosition; + public float Scale = 1; + public PointD ViewScreenPos; + StarIcon _starIcon; + //public Shape[] DrawShapes; + + public SystemIcon(SystemState starSystemState) + { + _starIcon = new StarIcon(starSystemState.StarSystem.GetFirstEntityWithDataBlob()); + } + + public virtual void OnFrameUpdate(Matrix matrix, Camera camera) + { + + + _starIcon.OnFrameUpdate(matrix, camera); + } + + + public virtual void Draw(IntPtr rendererPtr, Camera camera) + { + _starIcon.Draw(rendererPtr, camera); + + } + } + public class GalaxyMap : PulsarGuiWindow + { + Dictionary KnownSystems = new Dictionary(); + ImGuiSDL2CSWindow _window; + Dictionary SystemIcons = new Dictionary(); + private GalaxyMap(Entity faction) + { + int i = 0; + double startangle = Math.PI * 0.5; + float angleIncrease = 0.01f; + int startR = 32; + int radInc = 5; + foreach (var item in _state.StarSystemStates) + { + KnownSystems[item.Key] = item.Value; + var icon = new SystemIcon(item.Value); + var x = (startR + radInc * i) * Math.Sin(startangle - angleIncrease * i); + var y = (startR + radInc * i) * Math.Cos(startangle - angleIncrease * i); + icon._mapPosition.X = x; + icon._mapPosition.Y = y; + SystemIcons[item.Key] = icon; + i++; + } + } + + internal static GalaxyMap GetInstance(ImGuiSDL2CSWindow window, Entity faction) + { + GalaxyMap instance; + if (!_state.LoadedWindows.ContainsKey(typeof(GalaxyMap))) + { + instance = new GalaxyMap(faction); + } + else + instance = (GalaxyMap)_state.LoadedWindows[typeof(GalaxyMap)]; + instance._window = window; + + return instance; + } + + internal override void Display() + { + if(IsActive) + { + + + + + + + } + } + + internal void Draw(IntPtr renderPtr, Camera camera) + { + foreach (var icon in SystemIcons) + { + icon.Value.Draw(renderPtr, camera); + } + + + } + } +} diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/Icons/TranslateMoveOrderWidget.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/Icons/TranslateMoveOrderWidget.cs index 4c29eb21d..d2bbb8841 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/Icons/TranslateMoveOrderWidget.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/Icons/TranslateMoveOrderWidget.cs @@ -35,7 +35,7 @@ public class TranslateMoveOrderWidget : IDrawData public TranslateMoveOrderWidget(GlobalUIState state, Entity orderingEntity) { _state = state; - _currentDateTime = _state.CurrentSystemDateTime; + _currentDateTime = _state.PrimarySystemDateTime; _movingEntity = orderingEntity; @@ -101,7 +101,7 @@ public void SetArivalProgradeAngle(double angle) public void OnPhysicsUpdate() { - _currentDateTime = _state.CurrentSystemDateTime; + _currentDateTime = _state.PrimarySystemDateTime; if (_transitLeaveDateTime < _currentDateTime) _transitLeaveDateTime = _currentDateTime; diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/SystemMapRendering.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/SystemMapRendering.cs index 93e17750c..6948ea77e 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/SystemMapRendering.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/SystemMapRendering.cs @@ -43,8 +43,8 @@ internal class SystemMapRendering internal ConcurrentDictionary _nameIcons = new ConcurrentDictionary(); internal List SelectedEntityExtras = new List(); - - internal SystemMap_DrawableVM SysMap; + internal PointD GalacticMapPosition = new PointD(); + //internal SystemMap_DrawableVM SysMap; Entity _faction; internal SystemMapRendering(ImGuiSDL2CSWindow window, GlobalUIState state) @@ -72,14 +72,17 @@ internal void SetSystem(FactionVM factionVM) _sysState = new SystemState(factionVM.SystemMap.StarSystem, factionVM.FactionEntity); _state.StarSystemStates[_sysState.StarSystem.Guid] = _sysState; } - - SysMap = factionVM.SystemMap; + var starSys = _sysState.StarSystem; _faction = _state.Faction; - SysMap.SystemSubpulse.SystemDateChangedEvent += OnSystemDateChange; - _state.CurrentSystemDateTime = SysMap.SystemSubpulse.SystemLocalDateTime; - _state.ActiveSystem = SysMap.StarSystem; - _sensorMgr = SysMap.StarSystem.FactionSensorContacts[_faction.Guid]; + starSys.ManagerSubpulses.SystemDateChangedEvent += OnSystemDateChange; + _sensorMgr = starSys.GetSensorContacts(_faction.Guid); _sensorChanges = _sensorMgr.Changes.Subscribe(); + + + + _state.SetActiveSystem(starSys.Guid); + + foreach (var entityItem in _sysState.EntityStates.Values) { AddIconable(entityItem); @@ -89,6 +92,34 @@ internal void SetSystem(FactionVM factionVM) } + internal void SetSystem(StarSystem starSys) + { + if (_state.StarSystemStates.ContainsKey(starSys.Guid)) + _sysState = _state.StarSystemStates[starSys.Guid]; + else + { + _sysState = new SystemState(starSys, _state.Faction); + _state.StarSystemStates[_sysState.StarSystem.Guid] = _sysState; + } + + + _faction = _state.Faction; + + starSys.ManagerSubpulses.SystemDateChangedEvent += OnSystemDateChange; + _sensorMgr = starSys.GetSensorContacts(_faction.Guid); + + + _sensorChanges = _sensorMgr.Changes.Subscribe(); + foreach (var entityItem in _sysState.EntityStates.Values) + { + AddIconable(entityItem); + } + + //_state.LastClickedEntity = _sysState.EntityStates.Values.ElementAt(0); + + + } + void AddIconable(EntityState entityState) { @@ -149,7 +180,7 @@ void RemoveIconable(Guid entityGuid) void OnSystemDateChange(DateTime newDate) { - _state.CurrentSystemDateTime = newDate; + _state.PrimarySystemDateTime = newDate; @@ -241,73 +272,7 @@ void HandleChanges(EntityState entityState) } } - /* - void HandleChanges() - { - var updates = SysMap.GetUpdates(); - foreach (var changeData in updates) - { - if(changeData.ChangeType == EntityChangeData.EntityChangeType.EntityAdded) - { - //AddIconable(changeData.Entity); - } - - if (changeData.ChangeType == EntityChangeData.EntityChangeType.EntityRemoved) - { - RemoveIconable(changeData.Entity.Guid); - } - - if (changeData.ChangeType == EntityChangeData.EntityChangeType.DBAdded) - { - if (changeData.Datablob is OrbitDB && changeData.Entity.GetDataBlob().Parent != null) - { - if (!((OrbitDB)changeData.Datablob).IsStationary) - { - EntityState entityState; - if (IconEntityStates.ContainsKey(changeData.Entity.Guid)) - entityState = IconEntityStates[changeData.Entity.Guid]; - else - entityState = new EntityState(changeData.Entity) { Name = "Unknown" }; - - _orbitRings[changeData.Entity.Guid] = new OrbitIcon(entityState, _state.UserOrbitSettings); - - } - } - if (changeData.Datablob is TranslateMoveDB) - { - var widget = new ShipMoveWidget(changeData.Entity); - //Matrix matrix = new Matrix(); - //matrix.Scale(_camera.ZoomLevel); - //widget.OnFrameUpdate(matrix, _camera); - _moveIcons[changeData.Entity.Guid] = widget; - //_moveIcons.Add(changeData.Entity.Guid, widget); - } - //if (changeData.Datablob is NameDB) - //TextIconList[changeData.Entity.Guid] = new TextIcon(changeData.Entity, _camera); - - //_entityIcons[changeData.Entity.Guid] = new EntityIcon(changeData.Entity, _camera); - } - if (changeData.ChangeType == EntityChangeData.EntityChangeType.DBRemoved) - { - if (changeData.Datablob is OrbitDB) - { - IDrawData foo; - _orbitRings.TryRemove(changeData.Entity.Guid, out foo); - } - if (changeData.Datablob is TranslateMoveDB) - { - IDrawData foo; - _moveIcons.TryRemove(changeData.Entity.Guid, out foo); - } - - //if (changeData.Datablob is NameDB) - //TextIconList.Remove(changeData.Entity.Guid); - } - } - } - */ - - public void TextIconsDistribute() + void TextIconsDistribute() { if (_nameIcons.Count == 0) return; @@ -410,6 +375,7 @@ internal void Draw() var matrix =_camera.GetZoomMatrix(); + /* if (SysMap == null) { foreach (var icon in _testIcons.Values) @@ -420,7 +386,7 @@ internal void Draw() } else { - + */ UpdateAndDraw(UIWidgets, matrix); UpdateAndDraw(_orbitRings, matrix); @@ -444,7 +410,7 @@ internal void Draw() SDL.SDL_SetRenderDrawColor(rendererPtr, oR, oG, oB, oA); SDL.SDL_SetRenderDrawBlendMode(rendererPtr, blendMode); - } + //} } public void DrawNameIcons() diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/SystemState.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/SystemState.cs index 5ef219651..2e5d3440b 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/SystemState.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/SystemState.cs @@ -29,7 +29,7 @@ public class SystemState public SystemState(StarSystem system, Entity faction) { StarSystem = system; - SystemContacts = system.FactionSensorContacts[faction.Guid]; + SystemContacts = system.GetSensorContacts(faction.Guid); _sensorChanges = SystemContacts.Changes.Subscribe(); PulseMgr = system.ManagerSubpulses; @@ -56,6 +56,39 @@ public SystemState(StarSystem system, Entity faction) } + public static SystemState GetMasterState(StarSystem starSystem) + { + return new SystemState(starSystem); + } + + private SystemState(StarSystem system) + { + StarSystem = system; + //SystemContacts = system.FactionSensorContacts[faction.Guid]; + //_sensorChanges = SystemContacts.Changes.Subscribe(); + PulseMgr = system.ManagerSubpulses; + + foreach (Entity entityItem in StarSystem.GetAllEntitiesWithDataBlob()) + { + if (entityItem.HasDataBlob()) + { + var entityState = new EntityState(entityItem) { Name = "Unknown" }; + EntityStates.Add(entityItem.Guid, entityState); + } + } + + var listnerblobs = new List(); + listnerblobs.Add(EntityManager.DataBlobTypes[typeof(PositionDB)]); + //EntityChangeListner changeListner = new EntityChangeListner(StarSystem, faction, new List());//, listnerblobs); + //_changeListner = changeListner; + /* + foreach (SensorContact sensorContact in SystemContacts.GetAllContacts()) + { + var entityState = new EntityState(sensorContact) { Name = "Unknown" }; + EntityStates.Add(sensorContact.ActualEntity.Guid, entityState); + }*/ + } + void HandleUpdates(EntityChangeData change) { diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/NewGameOptions.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/NewGameOptions.cs index 59160a570..8ab42e318 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/NewGameOptions.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/NewGameOptions.cs @@ -95,8 +95,10 @@ void CreateNewGame(string name) factionVM.CreateDefaultFaction(factionNameString, passString); + _state.SetFaction(factionVM.FactionEntity); //_state.MapRendering.SetSystem(factionVM.KnownSystems[0]); - _state.MapRendering.SetSystem(factionVM); + //_state.MapRendering.SetSystem(factionVM); + _state.SetActiveSystem(factionVM.KnownSystems[0].Guid); DebugWindow.GetInstance().SetGameEvents(); IsActive = false; TimeControl.GetInstance().IsActive = true; diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/ChangeCurrentOrbitWindow.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/ChangeCurrentOrbitWindow.cs index 4562ad639..53dcdd7e5 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/ChangeCurrentOrbitWindow.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/ChangeCurrentOrbitWindow.cs @@ -80,7 +80,7 @@ internal static ChangeCurrentOrbitWindow GetInstance(EntityState entity) var instance = (ChangeCurrentOrbitWindow)_state.LoadedWindows[typeof(ChangeCurrentOrbitWindow)]; if(instance.OrderingEntity != entity) instance.OnEntityChange(entity); - _state.ActiveSystem.ManagerSubpulses.SystemDateChangedEvent += instance.OnSystemDateTimeChange; + _state.PrimarySystem.ManagerSubpulses.SystemDateChangedEvent += instance.OnSystemDateTimeChange; return instance; } @@ -88,7 +88,7 @@ internal static ChangeCurrentOrbitWindow GetInstance(EntityState entity) void OnEntityChange(EntityState entity) { OrderingEntity = entity; - _actionDateTime = _state.CurrentSystemDateTime; + _actionDateTime = _state.PrimarySystemDateTime; _orderEntityOrbit = entity.Entity.GetDataBlob(); _massParentBody = _orderEntityOrbit.Parent.GetDataBlob().Mass; @@ -111,7 +111,7 @@ internal override void Display() if (_orbitWidget == null) { _orbitWidget = new OrbitOrderWiget(_orderEntityOrbit.Parent); - _state.MapRendering.UIWidgets.Add(_orbitWidget); + _state.PrimaryMapRender.UIWidgets.Add(_orbitWidget); } var maxprogradeDV = _maxDV - Math.Abs(_radialDV); @@ -190,11 +190,11 @@ void Calcs() internal void CloseWindow() { IsActive = false; - _state.ActiveSystem.ManagerSubpulses.SystemDateChangedEvent -= OnSystemDateTimeChange; + _state.PrimarySystem.ManagerSubpulses.SystemDateChangedEvent -= OnSystemDateTimeChange; if (_orbitWidget != null) { - _state.MapRendering.UIWidgets.Remove(_orbitWidget); + _state.PrimaryMapRender.UIWidgets.Remove(_orbitWidget); _orbitWidget = null; } diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitOrderWindow.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitOrderWindow.cs index 18769c56a..8200cc974 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitOrderWindow.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitOrderWindow.cs @@ -84,7 +84,7 @@ private OrbitOrderWindow(EntityState entity, bool smMode = false) if (_moveWidget == null) { _moveWidget = new TranslateMoveOrderWidget(_state, OrderingEntity.Entity); - _state.MapRendering.UIWidgets.Add(_moveWidget); + _state.PrimaryMapRender.UIWidgets.Add(_moveWidget); } } @@ -115,8 +115,8 @@ internal static OrbitOrderWindow GetInstance(EntityState entity, bool SMMode = f var instance = (OrbitOrderWindow)_state.LoadedWindows[typeof(OrbitOrderWindow)]; instance.OrderingEntity = entity; instance.CurrentState = States.NeedsTarget; - instance._departureDateTime = _state.CurrentSystemDateTime; - _state.ActiveSystem.ManagerSubpulses.SystemDateChangedEvent += instance.OnSystemDateTimeChange; + instance._departureDateTime = _state.PrimarySystemDateTime; + _state.PrimarySystem.ManagerSubpulses.SystemDateChangedEvent += instance.OnSystemDateTimeChange; instance.EntitySelected(); return instance; } @@ -135,7 +135,7 @@ void EntitySelected() if (_moveWidget == null) { _moveWidget = new TranslateMoveOrderWidget(_state, OrderingEntity.Entity); - _state.MapRendering.UIWidgets.Add(_moveWidget); + _state.PrimaryMapRender.UIWidgets.Add(_moveWidget); } DepartureCalcs(); @@ -179,17 +179,17 @@ void TargetSelected() if (_orbitWidget != null) { - int index = _state.MapRendering.UIWidgets.IndexOf(_orbitWidget); + int index = _state.PrimaryMapRender.UIWidgets.IndexOf(_orbitWidget); _orbitWidget = new OrbitOrderWiget(TargetEntity.Entity); if (index != -1) - _state.MapRendering.UIWidgets[index] = _orbitWidget; + _state.PrimaryMapRender.UIWidgets[index] = _orbitWidget; else - _state.MapRendering.UIWidgets.Add(_orbitWidget); + _state.PrimaryMapRender.UIWidgets.Add(_orbitWidget); } else { _orbitWidget = new OrbitOrderWiget(TargetEntity.Entity); - _state.MapRendering.UIWidgets.Add(_orbitWidget); + _state.PrimaryMapRender.UIWidgets.Add(_orbitWidget); } @@ -227,7 +227,7 @@ void ActionCmd() } void ActionAddDB() { - _state.SpaceMasterVM.SMSetOrbitToEntity(OrderingEntity.Entity, TargetEntity.Entity, PointDFunctions.Length(_orbitWidget.Periapsis), _state.CurrentSystemDateTime); + _state.SpaceMasterVM.SMSetOrbitToEntity(OrderingEntity.Entity, TargetEntity.Entity, PointDFunctions.Length(_orbitWidget.Periapsis), _state.PrimarySystemDateTime); CloseWindow(); } @@ -544,16 +544,16 @@ void CloseWindow() { IsActive = false; CurrentState = States.NeedsEntity; - _state.ActiveSystem.ManagerSubpulses.SystemDateChangedEvent -= OnSystemDateTimeChange; + _state.PrimarySystem.ManagerSubpulses.SystemDateChangedEvent -= OnSystemDateTimeChange; if (_orbitWidget != null) { - _state.MapRendering.UIWidgets.Remove(_orbitWidget); + _state.PrimaryMapRender.UIWidgets.Remove(_orbitWidget); _orbitWidget = null; } if (_moveWidget != null) { - _state.MapRendering.UIWidgets.Remove(_moveWidget); + _state.PrimaryMapRender.UIWidgets.Remove(_moveWidget); _moveWidget = null; } } diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitalDebugWidget.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitalDebugWidget.cs index 4418ffc6a..c9beada1b 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitalDebugWidget.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitalDebugWidget.cs @@ -31,14 +31,14 @@ public void Enable(bool enable, GlobalUIState state) { if (enable && !_isEnabled) { - if (!state.MapRendering.SelectedEntityExtras.Contains(_debugWidget)) - state.MapRendering.SelectedEntityExtras.Add(_debugWidget); + if (!state.PrimaryMapRender.SelectedEntityExtras.Contains(_debugWidget)) + state.PrimaryMapRender.SelectedEntityExtras.Add(_debugWidget); _isEnabled = true; } else if(!enable && _isEnabled) { - if (state.MapRendering.SelectedEntityExtras.Contains(_debugWidget)) - state.MapRendering.SelectedEntityExtras.Remove(_debugWidget); + if (state.PrimaryMapRender.SelectedEntityExtras.Contains(_debugWidget)) + state.PrimaryMapRender.SelectedEntityExtras.Remove(_debugWidget); _isEnabled = false; } } diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/Program.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/Program.cs index 7a8290078..2e0774b2d 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/Program.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/Program.cs @@ -56,7 +56,8 @@ public PulsarMainWindow() */ backColor = new ImVec3(0 / 255f, 0 / 255f, 28 / 255f); - _state.MapRendering = new SystemMapRendering(this, _state); + _state.GalacticMap = new GalacticMapRender(this, _state); + //_state.MapRendering = new SystemMapRendering(this, _state); OnEvent = MyEventHandler; @@ -151,7 +152,8 @@ public override void ImGuiRender() GL.ClearColor(backColor.X, backColor.Y, backColor.Z, 1f); GL.Clear(GL.Enum.GL_COLOR_BUFFER_BIT); - _state.MapRendering.Draw(); + _state.GalacticMap.Draw(); + //_state.MapRendering.Draw(); // Render ImGui on top of the rest. this eventualy calls overide void ImGuiLayout(); base.ImGuiRender(); @@ -193,7 +195,7 @@ public unsafe override void ImGuiLayout() } //because the nameIcons are IMGUI not SDL we draw them here. - _state.MapRendering.DrawNameIcons(); + _state.GalacticMap.DrawNameIcons(); ImGui.GetOverlayDrawList().AddText(new System.Numerics.Vector2(500, 500), 16777215, "FooBarBaz"); diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/Pulsar4X.ImGuiNetUI.csproj b/Pulsar4X/Pulsar4X.ImGuiNetUI/Pulsar4X.ImGuiNetUI.csproj index bd1dc475f..f1d736d00 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/Pulsar4X.ImGuiNetUI.csproj +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/Pulsar4X.ImGuiNetUI.csproj @@ -150,4 +150,7 @@ PreserveNewest + + + diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/SettingsWindow.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/SettingsWindow.cs index 10c2c8a5c..46f4cdcdc 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/SettingsWindow.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/SettingsWindow.cs @@ -76,12 +76,12 @@ internal override void Display() { //TODO: make this a knob/dial? need to create a custom control: https://github.com/ocornut/imgui/issues/942 if (ImGui.SliderAngle("Sweep Angle", ref _userOrbitSettings.EllipseSweepRadians, 1f, 360f)) - _state.MapRendering.UpdateUserOrbitSettings(); + _state.PrimaryMapRender.UpdateUserOrbitSettings(); if (ImGui.SliderInt("Number Of Segments", ref _arcSegments, 1, 255, _userOrbitSettings.NumberOfArcSegments.ToString())) { _userOrbitSettings.NumberOfArcSegments = (byte)_arcSegments; - _state.MapRendering.UpdateUserOrbitSettings(); + _state.PrimaryMapRender.UpdateUserOrbitSettings(); } if (ImGui.ColorEdit3("Orbit Ring Colour", ref _colour)) @@ -93,13 +93,13 @@ internal override void Display() if (ImGui.SliderInt("Max Alpha", ref _maxAlpha, _minAlpha, 255, "")) { _userOrbitSettings.MaxAlpha = (byte)_maxAlpha; - _state.MapRendering.UpdateUserOrbitSettings(); + _state.PrimaryMapRender.UpdateUserOrbitSettings(); } if (ImGui.SliderInt("Min Alpha", ref _minAlpha, 0, _maxAlpha, "")) { _userOrbitSettings.MinAlpha = (byte)_minAlpha; - _state.MapRendering.UpdateUserOrbitSettings(); + _state.PrimaryMapRender.UpdateUserOrbitSettings(); } } diff --git a/Pulsar4X/Pulsar4X.ImGuiNetUI/WeaponTargetingControl.cs b/Pulsar4X/Pulsar4X.ImGuiNetUI/WeaponTargetingControl.cs index 6146ee700..7aa744d43 100644 --- a/Pulsar4X/Pulsar4X.ImGuiNetUI/WeaponTargetingControl.cs +++ b/Pulsar4X/Pulsar4X.ImGuiNetUI/WeaponTargetingControl.cs @@ -47,8 +47,8 @@ internal static WeaponTargetingControl GetInstance(EntityState entity) else instance = (WeaponTargetingControl)_state.LoadedWindows[typeof(WeaponTargetingControl)]; instance.SetOrderEntity(entity); - instance._sysState = _state.StarSystemStates[_state.ActiveSystem.Guid]; - _state.ActiveSystem.ManagerSubpulses.SystemDateChangedEvent += instance.ManagerSubpulses_SystemDateChangedEvent; + instance._sysState = _state.StarSystemStates[_state.PrimarySystem.Guid]; + _state.PrimarySystem.ManagerSubpulses.SystemDateChangedEvent += instance.ManagerSubpulses_SystemDateChangedEvent; return instance; @@ -75,7 +75,7 @@ internal void SetOrderEntity(EntityState entity) if (weaponInstanace.OwningEntity.GetDataBlob().FireControl == null) _unAssignedWeapons.Add(weaponInstanace.OwningEntity.Guid); } - foreach (var item in _state.ActiveSystem.FactionSensorContacts[_state.Faction.Guid].GetAllContacts()) + foreach (var item in _state.PrimarySystem.GetSensorContacts(_state.Faction.Guid).GetAllContacts()) { var entityItem = item.ActualEntity; string name = entityItem.GetDataBlob().GetName(_state.Faction); @@ -232,7 +232,7 @@ internal override void Display() _unAssignedWeapons.Add(wpn); _selectedFCAssignedWeapons.Remove(wpn); - SetWeaponsFireControlOrder.CreateCommand(_state.Game, _state.CurrentSystemDateTime, _state.Faction.Guid, _orderingEntity.Guid, _selectedFC, _selectedFCAssignedWeapons); + SetWeaponsFireControlOrder.CreateCommand(_state.Game, _state.PrimarySystemDateTime, _state.Faction.Guid, _orderingEntity.Guid, _selectedFC, _selectedFCAssignedWeapons); } } ImGui.EndGroup(); @@ -247,7 +247,7 @@ internal override void Display() { _selectedFCAssignedWeapons.Add(wpn); _unAssignedWeapons.Remove(wpn); - SetWeaponsFireControlOrder.CreateCommand(_state.Game, _state.CurrentSystemDateTime, _state.Faction.Guid, _orderingEntity.Guid, _selectedFC, _selectedFCAssignedWeapons); + SetWeaponsFireControlOrder.CreateCommand(_state.Game, _state.PrimarySystemDateTime, _state.Faction.Guid, _orderingEntity.Guid, _selectedFC, _selectedFCAssignedWeapons); } } ImGui.EndGroup(); @@ -263,7 +263,7 @@ internal override void Display() { if (ImGui.SmallButton(item.Value)) { - SetTargetFireControlOrder.CreateCommand(_state.Game, _state.CurrentSystemDateTime, _state.Faction.Guid, _orderingEntity.Guid, _selectedFC, item.Key); + SetTargetFireControlOrder.CreateCommand(_state.Game, _state.PrimarySystemDateTime, _state.Faction.Guid, _orderingEntity.Guid, _selectedFC, item.Key); } } @@ -292,7 +292,7 @@ internal override void Display() void OnClose() { - _state.ActiveSystem.ManagerSubpulses.SystemDateChangedEvent -= ManagerSubpulses_SystemDateChangedEvent; + _state.PrimarySystem.ManagerSubpulses.SystemDateChangedEvent -= ManagerSubpulses_SystemDateChangedEvent; } }