diff --git a/EOLib/misc.cs b/EOLib/misc.cs index 5c1f3a631..c2ca69698 100644 --- a/EOLib/misc.cs +++ b/EOLib/misc.cs @@ -50,6 +50,7 @@ public static class Constants public const string InventoryFile = "config/inventory.ini"; public const string SpellsFile = "config/spells.ini"; + public const string PanelLayoutFile = "config/panels.ini"; public const string ChatLogFile = "chatlog.txt"; //Should be easily customizable between different clients (based on graphics) diff --git a/EndlessClient/GameExecution/GameStateActions.cs b/EndlessClient/GameExecution/GameStateActions.cs index 77f050162..5bd553611 100644 --- a/EndlessClient/GameExecution/GameStateActions.cs +++ b/EndlessClient/GameExecution/GameStateActions.cs @@ -10,6 +10,8 @@ using EndlessClient.Rendering; using Microsoft.Xna.Framework; using XNAControls.Input; +using EndlessClient.HUD.Panels; +using EOLib; namespace EndlessClient.GameExecution { @@ -21,6 +23,7 @@ public class GameStateActions : IGameStateActions private readonly IControlSetFactory _controlSetFactory; private readonly IEndlessGameProvider _endlessGameProvider; private readonly IPlayerInfoRepository _playerInfoRepository; + private readonly IClientWindowSizeProvider _clientWindowSizeProvider; private readonly ISfxPlayer _sfxPlayer; private readonly IMfxPlayer _mfxPlayer; @@ -29,6 +32,7 @@ public GameStateActions(IGameStateRepository gameStateRepository, IControlSetFactory controlSetFactory, IEndlessGameProvider endlessGameProvider, IPlayerInfoRepository playerInfoRepository, + IClientWindowSizeProvider clientWindowSizeProvider, ISfxPlayer sfxPlayer, IMfxPlayer mfxPlayer) { @@ -37,6 +41,7 @@ public GameStateActions(IGameStateRepository gameStateRepository, _controlSetFactory = controlSetFactory; _endlessGameProvider = endlessGameProvider; _playerInfoRepository = playerInfoRepository; + _clientWindowSizeProvider = clientWindowSizeProvider; _sfxPlayer = sfxPlayer; _mfxPlayer = mfxPlayer; } @@ -47,8 +52,13 @@ public void ChangeToState(GameStates newState) return; if (_gameStateRepository.CurrentState == GameStates.PlayingTheGame) + { _playerInfoRepository.PlayerIsInGame = false; + StorePanelLayout(Game, EventArgs.Empty); + Game.Exiting -= StorePanelLayout; + } + var currentSet = _controlSetRepository.CurrentControlSet; var nextSet = _controlSetFactory.CreateControlsForState(newState, currentSet); @@ -70,6 +80,11 @@ public void ChangeToState(GameStates newState) } break; case GameStates.LoggedIn: _sfxPlayer.PlaySfx(SoundEffectID.Login); break; + case GameStates.PlayingTheGame: + { + Game.Exiting += StorePanelLayout; + } + break; } } @@ -118,6 +133,24 @@ private List FindUnusedComponents(IControlSet current, IControlS .ToList(); } + private void StorePanelLayout(object sender, EventArgs e) + { + if (!_clientWindowSizeProvider.Resizable) return; + + var panelConfig = new EOLib.Config.IniReader(Constants.PanelLayoutFile); + panelConfig.Sections["PANELS"] = new SortedList(); + + var panels = _controlSetRepository.CurrentControlSet.AllComponents.OfType(); + foreach (var panel in panels) + { + panelConfig.Sections["PANELS"][$"{panel.GetType().Name}:X"] = ((int)panel.DrawPositionWithParentOffset.X).ToString(); + panelConfig.Sections["PANELS"][$"{panel.GetType().Name}:Y"] = ((int)panel.DrawPositionWithParentOffset.Y).ToString(); + panelConfig.Sections["PANELS"][$"{panel.GetType().Name}:Visible"] = panel.Visible.ToString(); + } + + panelConfig.Save(); + } + private IEndlessGame Game => _endlessGameProvider.Game; } } diff --git a/EndlessClient/GameExecution/IEndlessGame.cs b/EndlessClient/GameExecution/IEndlessGame.cs index c116d570d..682eb62e1 100644 --- a/EndlessClient/GameExecution/IEndlessGame.cs +++ b/EndlessClient/GameExecution/IEndlessGame.cs @@ -6,6 +6,8 @@ namespace EndlessClient.GameExecution { public interface IEndlessGame : IDisposable { + event EventHandler Exiting; + GameComponentCollection Components { get; } ContentManager Content { get; } diff --git a/EndlessClient/HUD/Controls/HudControlsFactory.cs b/EndlessClient/HUD/Controls/HudControlsFactory.cs index 34386e42a..eaa6a1d01 100644 --- a/EndlessClient/HUD/Controls/HudControlsFactory.cs +++ b/EndlessClient/HUD/Controls/HudControlsFactory.cs @@ -19,6 +19,8 @@ using EndlessClient.Rendering.Map; using EndlessClient.Rendering.NPC; using EndlessClient.UIControls; +using EOLib; +using EOLib.Config; using EOLib.Domain.Character; using EOLib.Domain.Login; using EOLib.Domain.Map; @@ -30,7 +32,6 @@ namespace EndlessClient.HUD.Controls { - //todo: this class is doing a lot. Might be a good idea to split it into multiple factories. [AutoMappedType(IsSingleton = true)] public class HudControlsFactory : IHudControlsFactory { @@ -399,6 +400,20 @@ private IGameComponent CreateStatePanel(InGameStates whichState) updateDrawArea(); _clientWindowSizeRepository.GameWindowSizeChanged += (_, _) => updateDrawArea(); + + var panelConfig = new IniReader(Constants.PanelLayoutFile); + if (panelConfig.Load()) + { + if (panelConfig.GetValue("PANELS", $"{retPanel.GetType().Name}:X", out int x) && + panelConfig.GetValue("PANELS", $"{retPanel.GetType().Name}:Y", out int y)) + { + retPanel.DrawPosition = new Vector2(x, y); + } + if (panelConfig.GetValue("PANELS", $"{retPanel.GetType().Name}:Visible", out bool visible)) + { + retPanel.Visible = visible; + } + } } return retPanel;