From 38cd6218f9e0860ea77da8e0f3c09ac44ca85768 Mon Sep 17 00:00:00 2001 From: kaczy Date: Thu, 9 Nov 2023 08:48:50 +0100 Subject: [PATCH] Made a lot of stuff static or statically available --- CentrED/{CentrED.cs => Application.cs} | 25 ++++++++------- CentrED/CentrEDGame.cs | 27 +++++++--------- CentrED/Map/MapManager.cs | 2 +- CentrED/Map/RadarMap.cs | 15 +++++---- CentrED/Tools/DrawTool.cs | 25 +++++++-------- CentrED/Tools/ElevateTool.cs | 12 +++---- CentrED/Tools/HueTool.cs | 11 +++---- CentrED/Tools/MoveTool.cs | 8 ++--- CentrED/Tools/RemoveTool.cs | 5 ++- CentrED/Tools/SelectTool.cs | 7 ++-- CentrED/Tools/Tool.cs | 7 ---- CentrED/UI/UIManager.cs | 44 +++++++++++++------------- CentrED/UI/Windows/ConnectWindow.cs | 19 ++++++----- CentrED/UI/Windows/DebugWindow.cs | 31 +++++++++--------- CentrED/UI/Windows/HuesWindow.cs | 11 ++++--- CentrED/UI/Windows/InfoWindow.cs | 6 ++-- CentrED/UI/Windows/MinimapWindow.cs | 12 +++---- CentrED/UI/Windows/OptionsWindow.cs | 1 - CentrED/UI/Windows/ServerWindow.cs | 16 +++++----- CentrED/UI/Windows/TilesWindow.cs | 23 +++++++------- CentrED/UI/Windows/ToolboxWindow.cs | 14 ++++---- CentrED/UI/Windows/Window.cs | 9 +----- 22 files changed, 154 insertions(+), 176 deletions(-) rename CentrED/{CentrED.cs => Application.cs} (86%) diff --git a/CentrED/CentrED.cs b/CentrED/Application.cs similarity index 86% rename from CentrED/CentrED.cs rename to CentrED/Application.cs index 3c13f5e..d957ec3 100644 --- a/CentrED/CentrED.cs +++ b/CentrED/Application.cs @@ -4,11 +4,10 @@ using System.Runtime.Loader; using CentrED.Client; using CentrED.Server; -using Microsoft.Xna.Framework; namespace CentrED; -public class CentrED { +public class Application { static private AssemblyLoadContext _loadContext; static private string? _rootDir; @@ -85,8 +84,9 @@ static private IntPtr ResolveUnmanagedDll(Assembly assembly, string unmanagedDll [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetDllDirectory(string lpPathName); - public static CEDServer? Server; - public static readonly CentrEDClient Client = new(); + public static CentrEDGame CEDGame { get; private set; } = null!; + public static CEDServer? CEDServer; + public static readonly CentrEDClient CEDClient = new(); [STAThread] public static void Main(string[] args) @@ -99,14 +99,15 @@ public static void Main(string[] args) _loadContext = AssemblyLoadContext.Default; _loadContext.ResolvingUnmanagedDll += ResolveUnmanagedDll; _loadContext.Resolving += ResolveAssembly; - - using Game g = new CentrEDGame(); - try { - g.Run(); - } - catch (Exception e) { - Console.WriteLine(e.ToString()); - File.WriteAllText("Crash.log", e.ToString()); + + using (CEDGame = new CentrEDGame()) { + try { + CEDGame.Run(); + } + catch (Exception e) { + Console.WriteLine(e.ToString()); + File.WriteAllText("Crash.log", e.ToString()); + } } } } \ No newline at end of file diff --git a/CentrED/CentrEDGame.cs b/CentrED/CentrEDGame.cs index ed6a2e0..3300409 100644 --- a/CentrED/CentrEDGame.cs +++ b/CentrED/CentrEDGame.cs @@ -1,5 +1,4 @@ using System.Runtime.InteropServices; -using CentrED.Client; using CentrED.Map; using CentrED.UI; using ClassicUO.Utility.Logging; @@ -10,12 +9,10 @@ namespace CentrED; public class CentrEDGame : Game { - private readonly GraphicsDeviceManager _gdm; + public readonly GraphicsDeviceManager _gdm; - private CentrEDClient _centredClient; - private MapManager _mapManager; - private UIManager _uiManager; - private HuesManager _huesManager; + public MapManager MapManager; + public UIManager UIManager; public CentrEDGame() { @@ -32,7 +29,7 @@ public CentrEDGame() Window.ClientSizeChanged += OnWindowResized; } - protected override unsafe void Initialize() + protected override void Initialize() { if (_gdm.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef)) { @@ -44,8 +41,8 @@ protected override unsafe void Initialize() NativeLibrary.Load(Path.Combine(AppContext.BaseDirectory, "x64", "zlib.dll")); Log.Start(LogTypes.All); var background = Content.Load("background"); - _mapManager = new MapManager(_gdm.GraphicsDevice, background); - _uiManager = new UIManager(this, _gdm.GraphicsDevice, _mapManager); + MapManager = new MapManager(_gdm.GraphicsDevice, background); + UIManager = new UIManager(_gdm.GraphicsDevice); base.Initialize(); } @@ -62,9 +59,9 @@ protected override void UnloadContent() protected override void Update(GameTime gameTime) { - CentrED.Client.Update(); - _uiManager.Update(gameTime, IsActive); - _mapManager.Update(gameTime, IsActive, !_uiManager.CapturingMouse, !_uiManager.CapturingKeyboard); + Application.CEDClient.Update(); + UIManager.Update(gameTime, IsActive); + MapManager.Update(gameTime, IsActive, !UIManager.CapturingMouse, !UIManager.CapturingKeyboard); base.Update(gameTime); } @@ -74,8 +71,8 @@ protected override void Draw(GameTime gameTime) // if (!IsActive) // return; - _mapManager.Draw(); - _uiManager.Draw(gameTime); + MapManager.Draw(); + UIManager.Draw(gameTime); base.Draw(gameTime); } @@ -84,6 +81,6 @@ protected override void Draw(GameTime gameTime) private void OnWindowResized(object? sender, EventArgs e) { GameWindow window = sender as GameWindow; if (window != null) - _mapManager.OnWindowsResized(window); + MapManager.OnWindowsResized(window); } } \ No newline at end of file diff --git a/CentrED/Map/MapManager.cs b/CentrED/Map/MapManager.cs index f8cbc9e..90ae2a5 100644 --- a/CentrED/Map/MapManager.cs +++ b/CentrED/Map/MapManager.cs @@ -94,7 +94,7 @@ public MapManager(GraphicsDevice gd, Texture2D background) _spriteBatch = new SpriteBatch(gd); _background = background; - Client = CentrED.Client; + Client = Application.CEDClient; Client.LandTileReplaced += (tile, newId) => { LandTiles.Find(l => l.LandTile.Equals(tile))?.UpdateId(newId); }; diff --git a/CentrED/Map/RadarMap.cs b/CentrED/Map/RadarMap.cs index 24e0983..5900064 100644 --- a/CentrED/Map/RadarMap.cs +++ b/CentrED/Map/RadarMap.cs @@ -2,6 +2,7 @@ using ClassicUO.Utility; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using static CentrED.Application; namespace CentrED.Map; @@ -13,13 +14,13 @@ public class RadarMap { public Texture2D Texture => _texture; private RadarMap(GraphicsDevice gd) { - CentrED.Client.Connected += () => { - _texture = new Texture2D(gd, CentrED.Client.Width, CentrED.Client.Height ); - CentrED.Client.Send(new RequestRadarMapPacket()); + CEDClient.Connected += () => { + _texture = new Texture2D(gd, CEDClient.Width, CEDClient.Height ); + CEDClient.Send(new RequestRadarMapPacket()); }; - CentrED.Client.RadarData += RadarData; - CentrED.Client.RadarUpdate += RadarUpdate; + CEDClient.RadarData += RadarData; + CEDClient.RadarUpdate += RadarUpdate; } public static void Initialize(GraphicsDevice gd) { @@ -27,8 +28,8 @@ public static void Initialize(GraphicsDevice gd) { } private unsafe void RadarData(ushort[] data) { - var width = CentrED.Client.Width; - var height = CentrED.Client.Height; + var width = CEDClient.Width; + var height = CEDClient.Height; uint[] buffer = System.Buffers.ArrayPool.Shared.Rent(data.Length); for (ushort x = 0; x < width; x++) { for (ushort y = 0; y < height; y++) { diff --git a/CentrED/Tools/DrawTool.cs b/CentrED/Tools/DrawTool.cs index 36f0392..22675f9 100644 --- a/CentrED/Tools/DrawTool.cs +++ b/CentrED/Tools/DrawTool.cs @@ -1,13 +1,12 @@ using CentrED.Map; -using CentrED.UI; using CentrED.UI.Windows; using ClassicUO.Assets; using ImGuiNET; +using static CentrED.Application; namespace CentrED.Tools; public class DrawTool : Tool { - internal DrawTool(UIManager uiManager) : base(uiManager) { } public override string Name => "DrawTool"; private bool _pressed; @@ -43,12 +42,12 @@ public override void OnMouseEnter(MapObject? o) { _ => 0 }; - var newId = _uiManager._tilesWindow._selectedId; + var newId = CEDGame.UIManager._tilesWindow._selectedId; if (TilesWindow.IsLandTile(newId)) { if (o is LandObject lo) { lo.Visible = false; var newTile = new LandTile((ushort)newId, lo.Tile.X, lo.Tile.Y, lo.Tile.Z); - _mapManager.GhostLandTiles.Add(new LandObject(_mapManager.Client, newTile)); + CEDGame.MapManager.GhostLandTiles.Add(new LandObject(CEDClient, newTile)); } } else { @@ -66,22 +65,22 @@ public override void OnMouseEnter(MapObject? o) { tileX, tileY, (sbyte)newZ, - (ushort)(_withHue ? _uiManager._huesWindow.SelectedId + 1 : 0)); - _mapManager.GhostStaticTiles.Add(new StaticObject(newTile)); + (ushort)(_withHue ? CEDGame.UIManager._huesWindow.SelectedId + 1 : 0)); + CEDGame.MapManager.GhostStaticTiles.Add(new StaticObject(newTile)); } } public override void OnMouseLeave(MapObject? o) { - if (TilesWindow.IsLandTile(_uiManager._tilesWindow._selectedId)) { + if (TilesWindow.IsLandTile(CEDGame.UIManager._tilesWindow._selectedId)) { if (o is LandObject lo) { lo.Visible = true; - _mapManager.GhostLandTiles.Clear(); + CEDGame.MapManager.GhostLandTiles.Clear(); } } else { if (o != null) o.Visible = true; - _mapManager.GhostStaticTiles.Clear(); + CEDGame.MapManager.GhostStaticTiles.Clear(); } } @@ -93,13 +92,13 @@ public override void OnMousePressed(MapObject? o) { public override void OnMouseReleased(MapObject? o) { if (_pressed && o == _focusObject) { - var newId = _uiManager._tilesWindow._selectedId; + var newId = CEDGame.UIManager._tilesWindow._selectedId; if (TilesWindow.IsLandTile(newId) && o is LandObject lo) { - lo.LandTile.Id = (ushort)_uiManager._tilesWindow._selectedId; + lo.LandTile.Id = (ushort)CEDGame.UIManager._tilesWindow._selectedId; } else { - var newTile = _mapManager.GhostStaticTiles[0].StaticTile; - _mapManager.Client.Add(newTile); + var newTile = CEDGame.MapManager.GhostStaticTiles[0].StaticTile; + CEDGame.MapManager.Client.Add(newTile); } } _pressed = false; diff --git a/CentrED/Tools/ElevateTool.cs b/CentrED/Tools/ElevateTool.cs index 832c52c..41ba0fa 100644 --- a/CentrED/Tools/ElevateTool.cs +++ b/CentrED/Tools/ElevateTool.cs @@ -1,12 +1,10 @@ using CentrED.Map; -using CentrED.UI; using ImGuiNET; +using static CentrED.Application; namespace CentrED.Tools; public class ElevateTool : Tool { - internal ElevateTool(UIManager uiManager) : base(uiManager) { } - [Flags] enum ZMode { INC = 0, @@ -44,22 +42,22 @@ public override void OnMouseEnter(MapObject? o) { var tile = so.StaticTile; so.Alpha = 0.3f; var newTile = new StaticTile(tile.Id, tile.X, tile.Y, NewZ(tile), tile.Hue); - _mapManager.GhostStaticTiles.Add(new StaticObject(newTile)); + CEDGame.MapManager.GhostStaticTiles.Add(new StaticObject(newTile)); } else if (o is LandObject lo) { var tile = lo.LandTile; lo.Visible = false; var newTile = new LandTile(tile.Id, tile.X, tile.Y, NewZ(tile)); - _mapManager.GhostLandTiles.Add(new LandObject(_mapManager.Client, newTile)); + CEDGame.MapManager.GhostLandTiles.Add(new LandObject(CEDGame.MapManager.Client, newTile)); } } public override void OnMouseLeave(MapObject? o) { if (o is StaticObject so) { so.Alpha = 1f; - _mapManager.GhostStaticTiles.Clear(); + CEDGame.MapManager.GhostStaticTiles.Clear(); } else if (o is LandObject lo) { lo.Visible = true; - _mapManager.GhostLandTiles.Clear(); + CEDGame.MapManager.GhostLandTiles.Clear(); } } diff --git a/CentrED/Tools/HueTool.cs b/CentrED/Tools/HueTool.cs index e0dfc73..f3a29b4 100644 --- a/CentrED/Tools/HueTool.cs +++ b/CentrED/Tools/HueTool.cs @@ -1,10 +1,9 @@ using CentrED.Map; -using CentrED.UI; +using static CentrED.Application; namespace CentrED.Tools; public class HueTool : Tool { - internal HueTool(UIManager uiManager) : base(uiManager) { } public override string Name => "HueTool"; @@ -12,12 +11,12 @@ internal HueTool(UIManager uiManager) : base(uiManager) { } private StaticObject _focusObject; public override void OnActivated(MapObject? o) { - _uiManager._huesWindow.Show = true; + CEDGame.UIManager._huesWindow.Show = true; } public override void OnMouseEnter(MapObject? o) { if (o is StaticObject so) { - so.Hue = (ushort)_uiManager._huesWindow.SelectedId; + so.Hue = (ushort)CEDGame.UIManager._huesWindow.SelectedId; } } @@ -36,8 +35,8 @@ public override void OnMousePressed(MapObject? o) { public override void OnMouseReleased(MapObject? o) { if (_pressed && o is StaticObject so && so == _focusObject) { - if(_uiManager._huesWindow.SelectedId != -1) - so.StaticTile.Hue = (ushort)_uiManager._huesWindow.SelectedId; + if(CEDGame.UIManager._huesWindow.SelectedId != -1) + so.StaticTile.Hue = (ushort)CEDGame.UIManager._huesWindow.SelectedId; } _pressed = false; } diff --git a/CentrED/Tools/MoveTool.cs b/CentrED/Tools/MoveTool.cs index c8f2b3e..6864bab 100644 --- a/CentrED/Tools/MoveTool.cs +++ b/CentrED/Tools/MoveTool.cs @@ -1,12 +1,10 @@ using CentrED.Map; -using CentrED.UI; using ImGuiNET; +using static CentrED.Application; namespace CentrED.Tools; public class MoveTool : Tool { - internal MoveTool(UIManager uiManager) : base(uiManager) { } - public override string Name => "MoveTool"; private int _xDelta; @@ -33,14 +31,14 @@ public override void OnMouseEnter(MapObject? o) { so.StaticTile.Z, so.StaticTile.Hue ); - _mapManager.GhostStaticTiles.Add(new StaticObject(newTile)); + CEDGame.MapManager.GhostStaticTiles.Add(new StaticObject(newTile)); } } public override void OnMouseLeave(MapObject? o) { if (o is StaticObject so) { so.Alpha = 1f; - _mapManager.GhostStaticTiles.Clear(); + CEDGame.MapManager.GhostStaticTiles.Clear(); } } diff --git a/CentrED/Tools/RemoveTool.cs b/CentrED/Tools/RemoveTool.cs index 0814ec1..005a67d 100644 --- a/CentrED/Tools/RemoveTool.cs +++ b/CentrED/Tools/RemoveTool.cs @@ -1,10 +1,9 @@ using CentrED.Map; -using CentrED.UI; +using static CentrED.Application; namespace CentrED.Tools; public class RemoveTool : Tool { - internal RemoveTool(UIManager uiManager) : base(uiManager) { } public override string Name => "RemoveTool"; private bool _pressed; @@ -31,7 +30,7 @@ public override void OnMousePressed(MapObject? o) { public override void OnMouseReleased(MapObject? o) { if (_pressed && o is StaticObject so && so == _focusObject) { - _mapManager.Client.Remove(_focusObject.StaticTile); + CEDClient.Remove(_focusObject.StaticTile); } _pressed = false; } diff --git a/CentrED/Tools/SelectTool.cs b/CentrED/Tools/SelectTool.cs index 2fc28f3..d236805 100644 --- a/CentrED/Tools/SelectTool.cs +++ b/CentrED/Tools/SelectTool.cs @@ -1,18 +1,17 @@ using CentrED.Map; -using CentrED.UI; +using static CentrED.Application; namespace CentrED.Tools; public class SelectTool : Tool { - internal SelectTool(UIManager uiManager) : base(uiManager) { } public override string Name => "Select"; public override void OnMousePressed(MapObject? selected) { - _uiManager._infoWindow.Selected = selected; + CEDGame.UIManager._infoWindow.Selected = selected; } public override void OnActivated(MapObject? o) { - _uiManager._infoWindow.Show = true; + CEDGame.UIManager._infoWindow.Show = true; } } \ No newline at end of file diff --git a/CentrED/Tools/Tool.cs b/CentrED/Tools/Tool.cs index dff9ab9..1d1091d 100644 --- a/CentrED/Tools/Tool.cs +++ b/CentrED/Tools/Tool.cs @@ -1,15 +1,8 @@ using CentrED.Map; -using CentrED.UI; namespace CentrED.Tools; public abstract class Tool { - internal UIManager _uiManager; - internal MapManager _mapManager; - internal Tool(UIManager uiManager) { - _uiManager = uiManager; - _mapManager = uiManager._mapManager; - } public abstract string Name { get; } internal virtual void DrawWindow() { diff --git a/CentrED/UI/UIManager.cs b/CentrED/UI/UIManager.cs index d2e32c1..4608f37 100644 --- a/CentrED/UI/UIManager.cs +++ b/CentrED/UI/UIManager.cs @@ -6,6 +6,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using static CentrED.Application; using Vector2 = System.Numerics.Vector2; using Vector4 = System.Numerics.Vector4; @@ -16,10 +17,8 @@ public class UIManager { public static Vector4 Green = new (0, 1, 0, 1); public static Vector4 Blue = new (0, 0, 1, 1); - private CentrEDGame _game; internal UIRenderer _uiRenderer; internal GraphicsDevice _graphicsDevice; - internal readonly MapManager _mapManager; // Input private int _scrollWheelValue; @@ -30,17 +29,16 @@ public class UIManager { internal ToolboxWindow _toolboxWindow; internal TilesWindow _tilesWindow; internal HuesWindow _huesWindow; + internal FilterWindow _filterWindow; private DebugWindow _debugWindow; internal List tools = new(); internal List mainWindows = new(); internal List toolsWindows = new(); - public UIManager(CentrEDGame game, GraphicsDevice gd, MapManager mapManager) { - _game = game; + public UIManager(GraphicsDevice gd) { _graphicsDevice = gd; _uiRenderer = new UIRenderer(_graphicsDevice); - _mapManager = mapManager; var context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); @@ -54,28 +52,30 @@ public UIManager(CentrEDGame game, GraphicsDevice gd, MapManager mapManager) { _uiRenderer.RebuildFontAtlas(); - mainWindows.Add(new ConnectWindow(this)); - mainWindows.Add(new ServerWindow(this)); - mainWindows.Add(new OptionsWindow(this)); + mainWindows.Add(new ConnectWindow()); + mainWindows.Add(new ServerWindow()); + mainWindows.Add(new OptionsWindow()); - _infoWindow = new InfoWindow(this); - _toolboxWindow = new ToolboxWindow(this); - _tilesWindow = new TilesWindow(this); - _huesWindow = new HuesWindow(this); + _infoWindow = new InfoWindow(); + _toolboxWindow = new ToolboxWindow(); + _tilesWindow = new TilesWindow(); + _huesWindow = new HuesWindow(); + _filterWindow = new FilterWindow(); toolsWindows.Add(_infoWindow); toolsWindows.Add(_toolboxWindow); toolsWindows.Add(_tilesWindow); toolsWindows.Add(_huesWindow); - toolsWindows.Add(new MinimapWindow(this)); + toolsWindows.Add(_filterWindow); + toolsWindows.Add(new MinimapWindow()); - tools.Add(new SelectTool(this)); - tools.Add(new DrawTool(this)); - tools.Add(new RemoveTool(this)); - tools.Add(new MoveTool(this)); - tools.Add( new ElevateTool(this)); - tools.Add(new HueTool(this)); + tools.Add(new SelectTool()); + tools.Add(new DrawTool()); + tools.Add(new RemoveTool()); + tools.Add(new MoveTool()); + tools.Add( new ElevateTool()); + tools.Add(new HueTool()); - _debugWindow = new DebugWindow(this); + _debugWindow = new DebugWindow(); } public void Update(GameTime gameTime, bool isActive) @@ -203,7 +203,7 @@ private void DrawContextMenu() { if (ImGui.BeginPopup("MainPopup")) { var mousePos = ImGui.GetMousePosOnOpeningCurrentPopup(); - var selected = _mapManager.GetMouseSelection((int)mousePos.X, (int)mousePos.Y); + var selected = CEDGame.MapManager.GetMouseSelection((int)mousePos.X, (int)mousePos.Y); if (selected != null) { if (ImGui.Button("Grab TileId")) { _tilesWindow.UpdateSelectedId(selected); @@ -228,7 +228,7 @@ private void DrawMainMenu() { if (ImGui.BeginMenu("CentrED")) { mainWindows.ForEach(w => w.DrawMenuItem()); ImGui.Separator(); - if (ImGui.MenuItem("Quit")) _game.Exit(); + if (ImGui.MenuItem("Quit")) CEDGame.Exit(); ImGui.EndMenu(); } diff --git a/CentrED/UI/Windows/ConnectWindow.cs b/CentrED/UI/Windows/ConnectWindow.cs index 02f650d..d6d184b 100644 --- a/CentrED/UI/Windows/ConnectWindow.cs +++ b/CentrED/UI/Windows/ConnectWindow.cs @@ -2,6 +2,7 @@ using System.Numerics; using ClassicUO.Utility; using ImGuiNET; +using static CentrED.Application; namespace CentrED.UI.Windows; @@ -22,8 +23,6 @@ public class ConnectWindow : Window { private string _info = ""; private string _profileName = ""; - public ConnectWindow(UIManager uiManager) : base(uiManager){ } - public override void Draw() { if (!Show) return; @@ -104,27 +103,27 @@ public override void Draw() { ImGui.BeginDisabled( _hostname.Length == 0 || _password.Length == 0 || _username.Length == 0 || _clientPath.Length == 0 || _clientVersion.Length == 0 || _buttonDisabled); - if (_uiManager._mapManager.Client.Running) { + if (CEDGame.MapManager.Client.Running) { if (ImGui.Button("Disconnect")) { - _uiManager._mapManager.Client.Disconnect(); - _uiManager._mapManager.Reset(); + CEDGame.MapManager.Client.Disconnect(); + CEDGame.MapManager.Reset(); _info = "Disconnected"; } } else { if (ImGui.Button("Connect")) { - _uiManager._mapManager.Reset(); + CEDGame.MapManager.Reset(); _buttonDisabled = true; new Task(() => { try { _infoColor = UIManager.Blue; _info = "Loading"; - _uiManager._mapManager.Load(_clientPath, _clientVersion); + CEDGame.MapManager.Load(_clientPath, _clientVersion); _info = "Connecting"; - _uiManager._mapManager.Client.Connect(_hostname, _port, _username, + CEDClient.Connect(_hostname, _port, _username, _password); - _info = _uiManager._mapManager.Client.Status; - _infoColor = _uiManager._mapManager.Client.Running ? UIManager.Blue : UIManager.Red; + _info = CEDClient.Status; + _infoColor = CEDClient.Running ? UIManager.Blue : UIManager.Red; } catch (SocketException e) { _info = "Unable to connect"; diff --git a/CentrED/UI/Windows/DebugWindow.cs b/CentrED/UI/Windows/DebugWindow.cs index f078a9a..23fe1c3 100644 --- a/CentrED/UI/Windows/DebugWindow.cs +++ b/CentrED/UI/Windows/DebugWindow.cs @@ -4,7 +4,6 @@ namespace CentrED.UI.Windows; public class DebugWindow : Window { - public DebugWindow(UIManager uiManager) : base(uiManager) { } public override string Name => "Debug"; private int _gotoX; @@ -19,30 +18,32 @@ public override void Draw() { // _graphicsDevice.PresentationParameters.BackBufferHeight / 2 // ), // ImGuiCond.FirstUseEver); + var uiManager = Application.CEDGame.UIManager; + var mapManager = Application.CEDGame.MapManager; ImGui.Begin(Id, ref _show, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoResize); - ImGui.Text($"FPS: {_uiManager._framesPerSecond:F1}"); - ImGui.Text($"Resolution: {_uiManager._graphicsDevice.PresentationParameters.BackBufferWidth}x{_uiManager._graphicsDevice.PresentationParameters.BackBufferHeight}"); - ImGui.Text($"Land tiles: {_mapManager.LandTiles.Count}"); - ImGui.Text($"Static tiles: {_mapManager.StaticTiles.Count}"); - ImGui.Text($"Camera focus tile {_mapManager.Camera.LookAt / _mapManager.TILE_SIZE}"); + ImGui.Text($"FPS: {uiManager._framesPerSecond:F1}"); + ImGui.Text($"Resolution: {uiManager._graphicsDevice.PresentationParameters.BackBufferWidth}x{uiManager._graphicsDevice.PresentationParameters.BackBufferHeight}"); + ImGui.Text($"Land tiles: {mapManager.LandTiles.Count}"); + ImGui.Text($"Static tiles: {mapManager.StaticTiles.Count}"); + ImGui.Text($"Camera focus tile {mapManager.Camera.LookAt / mapManager.TILE_SIZE}"); ImGui.Separator(); - ImGui.Checkbox("DrawLand", ref _mapManager.IsDrawLand); - ImGui.Checkbox("DrawStatics", ref _mapManager.IsDrawStatic); - ImGui.Checkbox("DrawShadows", ref _mapManager.IsDrawShadows); - ImGui.SliderInt("Min Z render", ref _mapManager.MIN_Z, -127, 127); - ImGui.SliderInt("Max Z render", ref _mapManager.MAX_Z, -127, 127); - ImGui.SliderFloat("Zoom", ref _mapManager.Camera.Zoom, 0.2f, 10.0f); + ImGui.Checkbox("DrawLand", ref mapManager.IsDrawLand); + ImGui.Checkbox("DrawStatics", ref mapManager.IsDrawStatic); + ImGui.Checkbox("DrawShadows", ref mapManager.IsDrawShadows); + ImGui.SliderInt("Min Z render", ref mapManager.MIN_Z, -127, 127); + ImGui.SliderInt("Max Z render", ref mapManager.MAX_Z, -127, 127); + ImGui.SliderFloat("Zoom", ref mapManager.Camera.Zoom, 0.2f, 10.0f); ImGui.Separator(); ImGui.InputInt("Camera x", ref _gotoX); ImGui.InputInt("Camera y", ref _gotoY); if (ImGui.Button("Update pos")) { - _mapManager.SetPos((ushort)_gotoX, (ushort)_gotoY); + mapManager.SetPos((ushort)_gotoX, (ushort)_gotoY); } ImGui.Separator(); - if (ImGui.Button("Server Flush")) _mapManager.Client.Flush(); - if (ImGui.Button("Clear cache")) _mapManager.Reset(); + if (ImGui.Button("Server Flush")) mapManager.Client.Flush(); + if (ImGui.Button("Clear cache")) mapManager.Reset(); // if (ImGui.Button("Render 4K")) _mapManager.DrawHighRes(); if (ImGui.Button("Test Window")) _showTestWindow = !_showTestWindow; if (_showTestWindow) diff --git a/CentrED/UI/Windows/HuesWindow.cs b/CentrED/UI/Windows/HuesWindow.cs index a877dd4..71a9f41 100644 --- a/CentrED/UI/Windows/HuesWindow.cs +++ b/CentrED/UI/Windows/HuesWindow.cs @@ -1,12 +1,13 @@ using ImGuiNET; using Microsoft.Xna.Framework; +using static CentrED.Application; using Vector2 = System.Numerics.Vector2; namespace CentrED.UI.Windows; public class HuesWindow : Window{ - public HuesWindow(UIManager uiManager) : base(uiManager) { - _mapManager.Client.Connected += FilterHues; + public HuesWindow() { + CEDClient.Connected += FilterHues; } public override string Name => "Hues"; @@ -39,7 +40,7 @@ private void FilterHues() { } public override void Draw() { if (!Show) return; - ImGui.SetNextWindowSize(new Vector2(250, _uiManager._graphicsDevice.PresentationParameters.BackBufferHeight - _uiManager._mainMenuHeight), ImGuiCond.FirstUseEver); + ImGui.SetNextWindowSize(new Vector2(250, CEDGame._gdm.GraphicsDevice.PresentationParameters.BackBufferHeight - CEDGame.UIManager._mainMenuHeight), ImGuiCond.FirstUseEver); ImGui.Begin("Hues", ref _show); if (ImGui.Button("Scroll to selected")) { _updateScroll = true; @@ -51,7 +52,7 @@ public override void Draw() { } var huesPosY = ImGui.GetCursorPosY(); ImGui.BeginChild("Hues", new Vector2(), false, ImGuiWindowFlags.Modal); - if (ImGui.BeginTable("TilesTable", 2) && _mapManager.Client.Initialized) { + if (ImGui.BeginTable("TilesTable", 2) && CEDClient.Initialized) { unsafe { ImGuiListClipperPtr clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper()); ImGui.TableSetupColumn("Id", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("0x0000").X); @@ -99,7 +100,7 @@ private void HuesDrawElement(int index) { if (index == 0) ImGui.TextColored(UIManager.Red , name); else { - _uiManager.DrawImage(HuesManager.Instance.Texture, new Rectangle(0, index - 1, 32, 1), + CEDGame.UIManager.DrawImage(HuesManager.Instance.Texture, new Rectangle(0, index - 1, 32, 1), new Vector2(ImGui.GetContentRegionAvail().X, _huesRowHeight)); } diff --git a/CentrED/UI/Windows/InfoWindow.cs b/CentrED/UI/Windows/InfoWindow.cs index 1558283..522fc45 100644 --- a/CentrED/UI/Windows/InfoWindow.cs +++ b/CentrED/UI/Windows/InfoWindow.cs @@ -2,11 +2,11 @@ using ClassicUO.Assets; using ImGuiNET; using Microsoft.Xna.Framework; +using static CentrED.Application; namespace CentrED.UI.Windows; public class InfoWindow : Window{ - public InfoWindow(UIManager uiManager) : base(uiManager) { } public override string Name => "Info"; public MapObject? Selected; @@ -18,7 +18,7 @@ public override void Draw() { var land = lo.Tile; ImGui.Text("Land"); var texture = ArtLoader.Instance.GetLandTexture(land.Id, out var bounds); - _uiManager.DrawImage(texture, bounds); + CEDGame.UIManager.DrawImage(texture, bounds); ImGui.Text($"x:{land.X} y:{land.Y} z:{land.Z}"); ImGui.Text($"id: 0x{land.Id:X4} ({land.Id})"); } @@ -27,7 +27,7 @@ public override void Draw() { ImGui.Text("Static"); var texture = ArtLoader.Instance.GetStaticTexture(staticTile.Id, out var bounds); var realBounds = ArtLoader.Instance.GetRealArtBounds(staticTile.Id); - _uiManager.DrawImage(texture, new Rectangle(bounds.X + realBounds.X, bounds.Y + realBounds.Y, realBounds.Width, realBounds.Height)); + CEDGame.UIManager.DrawImage(texture, new Rectangle(bounds.X + realBounds.X, bounds.Y + realBounds.Y, realBounds.Width, realBounds.Height)); ImGui.Text($"x:{staticTile.X} y:{staticTile.Y} z:{staticTile.Z}"); ImGui.Text($"id: 0x{staticTile.Id:X4} ({staticTile.Id})"); ImGui.Text($"hue: 0x{staticTile.Hue:X4} ({staticTile.Hue})"); diff --git a/CentrED/UI/Windows/MinimapWindow.cs b/CentrED/UI/Windows/MinimapWindow.cs index a84df28..b7a2d10 100644 --- a/CentrED/UI/Windows/MinimapWindow.cs +++ b/CentrED/UI/Windows/MinimapWindow.cs @@ -1,12 +1,12 @@ using System.Numerics; using CentrED.Client; using ImGuiNET; +using static CentrED.Application; using RadarMap = CentrED.Map.RadarMap; namespace CentrED.UI.Windows; public class MinimapWindow : Window{ - public MinimapWindow(UIManager uiManager) : base(uiManager) { } public override string Name => "Minimap"; private string _coordsText = ""; @@ -15,14 +15,14 @@ public override void Draw() { ImGui.Begin("Minimap", ref _show, ImGuiWindowFlags.AlwaysAutoResize); - if (_mapManager.Client.Initialized) { + if (CEDGame.MapManager.Client.Initialized) { var currentPos = ImGui.GetCursorScreenPos(); var tex = RadarMap.Instance.Texture; - _uiManager.DrawImage(tex, tex.Bounds); + CEDGame.UIManager.DrawImage(tex, tex.Bounds); if (ImGui.BeginPopupContextItem()) { if (ImGui.Button("Reload")) { - _mapManager.Client.Send(new RequestRadarMapPacket()); + CEDClient.Send(new RequestRadarMapPacket()); ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); @@ -30,12 +30,12 @@ public override void Draw() { if (ImGui.IsMouseHoveringRect(currentPos, new(currentPos.X + tex.Bounds.Width, currentPos.Y + tex.Bounds.Height), true)) { var coords = ImGui.GetMousePos() - currentPos; if (ImGui.IsWindowFocused() && ImGui.IsMouseDown(ImGuiMouseButton.Left)) { - _mapManager.SetPos((ushort)(coords.X * 8), (ushort)(coords.Y * 8)); + CEDGame.MapManager.SetPos((ushort)(coords.X * 8), (ushort)(coords.Y * 8)); } _coordsText = $"x:{coords.X * 8} y:{coords.Y * 8}"; } - _mapManager.CalculateViewRange(_mapManager.Camera, out var rect); + CEDGame.MapManager.CalculateViewRange(CEDGame.MapManager.Camera, out var rect); var p1 = currentPos + new Vector2(rect.Left / 8, rect.Top / 8); var p2 = currentPos + new Vector2(rect.Right / 8, rect.Bottom / 8); ImGui.GetWindowDrawList().AddRect(p1, p2, ImGui.GetColorU32(UIManager.Red)); diff --git a/CentrED/UI/Windows/OptionsWindow.cs b/CentrED/UI/Windows/OptionsWindow.cs index ffec7ff..1c692ff 100644 --- a/CentrED/UI/Windows/OptionsWindow.cs +++ b/CentrED/UI/Windows/OptionsWindow.cs @@ -3,7 +3,6 @@ namespace CentrED.UI.Windows; public class OptionsWindow : Window{ - public OptionsWindow(UIManager uiManager) : base(uiManager) { } public override string Name => "Options"; public override void Draw() { if (!Show) return; diff --git a/CentrED/UI/Windows/ServerWindow.cs b/CentrED/UI/Windows/ServerWindow.cs index 3cfac2d..647f6de 100644 --- a/CentrED/UI/Windows/ServerWindow.cs +++ b/CentrED/UI/Windows/ServerWindow.cs @@ -2,11 +2,11 @@ using System.Text; using CentrED.Server; using ImGuiNET; +using static CentrED.Application; namespace CentrED.UI.Windows; public class ServerWindow : Window { - public ServerWindow(UIManager uiManager) : base(uiManager) { } public override string Name => "Local Server"; private string _configPath = Config.ServerConfigPath; private Vector4 _statusColor = UIManager.Red; @@ -34,16 +34,16 @@ public override void Draw() { ImGui.EndPopup(); } - if (CentrED.Server != null && CentrED.Server.Running) { + if (Application.CEDServer != null && Application.CEDServer.Running) { if (ImGui.Button("Stop")) { - CentrED.Client.Disconnect(); - CentrED.Server.Quit = true; + CEDClient.Disconnect(); + Application.CEDServer.Quit = true; } } else { if (ImGui.Button("Start")) { - if (CentrED.Server != null) { - CentrED.Server.Dispose(); + if (Application.CEDServer != null) { + Application.CEDServer.Dispose(); } _log.Clear(); @@ -57,11 +57,11 @@ public override void Draw() { new StreamWriter(File.Open("cedserver.log", FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) { AutoFlush = true }; _logReader = new StreamReader(File.Open("cedserver.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); - CentrED.Server = new CEDServer(new[] { _configPath }, logWriter); + Application.CEDServer = new CEDServer(new[] { _configPath }, logWriter); _statusColor = UIManager.Green; _statusText = "Running"; - CentrED.Server.Run(); + Application.CEDServer.Run(); } catch (Exception e) { Console.WriteLine("Server stopped"); diff --git a/CentrED/UI/Windows/TilesWindow.cs b/CentrED/UI/Windows/TilesWindow.cs index 22a7130..80d71a1 100644 --- a/CentrED/UI/Windows/TilesWindow.cs +++ b/CentrED/UI/Windows/TilesWindow.cs @@ -3,13 +3,14 @@ using ImGuiNET; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using static CentrED.Application; using Vector2 = System.Numerics.Vector2; namespace CentrED.UI.Windows; public class TilesWindow : Window{ - public TilesWindow(UIManager uiManager) : base(uiManager) { - _mapManager.Client.Connected += FilterTiles; + public TilesWindow() { + CEDClient.Connected += FilterTiles; } public override string Name => "Tiles"; @@ -27,16 +28,16 @@ public TilesWindow(UIManager uiManager) : base(uiManager) { private void FilterTiles() { if (_filter.Length == 0) { - _matchedLandIds = new int[_mapManager.ValidLandIds.Length]; - _mapManager.ValidLandIds.CopyTo(_matchedLandIds, 0); + _matchedLandIds = new int[CEDGame.MapManager.ValidLandIds.Length]; + CEDGame.MapManager.ValidLandIds.CopyTo(_matchedLandIds, 0); - _matchedStaticIds = new int[_mapManager.ValidStaticIds.Length]; - _mapManager.ValidStaticIds.CopyTo(_matchedStaticIds, 0); + _matchedStaticIds = new int[CEDGame.MapManager.ValidStaticIds.Length]; + CEDGame.MapManager.ValidStaticIds.CopyTo(_matchedStaticIds, 0); } else { var filter = _filter.ToLower(); var matchedLandIds = new List(); - foreach (var index in _mapManager.ValidLandIds) { + foreach (var index in CEDGame.MapManager.ValidLandIds) { var name = TileDataLoader.Instance.LandData[index].Name?.ToLower() ?? ""; if(name.Contains(filter) || $"{index}".Contains(_filter) || $"0x{index:x4}".Contains(filter)) matchedLandIds.Add(index); @@ -44,7 +45,7 @@ private void FilterTiles() { _matchedLandIds = matchedLandIds.ToArray(); var matchedStaticIds = new List(); - foreach (var index in _mapManager.ValidStaticIds) { + foreach (var index in CEDGame.MapManager.ValidStaticIds) { var name = TileDataLoader.Instance.StaticData[index].Name?.ToLower() ?? ""; if(name.Contains(filter) || $"{index}".Contains(_filter) || $"0x{index:x4}".Contains(filter)) matchedStaticIds.Add(index); @@ -54,7 +55,7 @@ private void FilterTiles() { } public override void Draw() { if (!Show) return; - ImGui.SetNextWindowSize(new Vector2(250, _uiManager._graphicsDevice.PresentationParameters.BackBufferHeight - _uiManager._mainMenuHeight), ImGuiCond.FirstUseEver); + ImGui.SetNextWindowSize(new Vector2(250, CEDGame._gdm.GraphicsDevice.PresentationParameters.BackBufferHeight - CEDGame.UIManager._mainMenuHeight), ImGuiCond.FirstUseEver); ImGui.Begin(Id, ref _show); if (ImGui.Button("Scroll to selected")) { _updateScroll = true; @@ -78,7 +79,7 @@ public override void Draw() { } var tilesPosY = ImGui.GetCursorPosY(); - if (ImGui.BeginTable("TilesTable", 3) && _mapManager.Client.Initialized) { + if (ImGui.BeginTable("TilesTable", 3) && CEDClient.Initialized) { unsafe { ImGuiListClipperPtr clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper()); ImGui.TableSetupColumn("Id", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("0x0000").X); @@ -148,7 +149,7 @@ private void TilesDrawRow(int index, int realIndex, Texture2D texture, Rectangle } if (ImGui.TableNextColumn()) { - _uiManager.DrawImage(texture, bounds, _tilesDimensions); + CEDGame.UIManager.DrawImage(texture, bounds, _tilesDimensions); } if (ImGui.TableNextColumn()) { diff --git a/CentrED/UI/Windows/ToolboxWindow.cs b/CentrED/UI/Windows/ToolboxWindow.cs index 0b48f4d..710ea82 100644 --- a/CentrED/UI/Windows/ToolboxWindow.cs +++ b/CentrED/UI/Windows/ToolboxWindow.cs @@ -1,25 +1,25 @@ using CentrED.Tools; using ImGuiNET; +using static CentrED.Application; namespace CentrED.UI.Windows; public class ToolboxWindow : Window { - public ToolboxWindow(UIManager uiManager) : base(uiManager) { } public override string Name => "Toolbox"; public override void Draw() { if (!Show) return; ImGui.Begin(Id, ref _show); - _uiManager.tools.ForEach(ToolButton); + CEDGame.UIManager.tools.ForEach(ToolButton); ImGui.End(); - _mapManager.ActiveTool?.DrawWindow(); + CEDGame.MapManager.ActiveTool?.DrawWindow(); } private void ToolButton(Tool tool) { - if (ImGui.RadioButton(tool.Name, _mapManager.ActiveTool == tool)) { - _mapManager.ActiveTool?.OnDeactivated(_mapManager.Selected); - _mapManager.ActiveTool = tool; - _mapManager.ActiveTool?.OnActivated(_mapManager.Selected); + if (ImGui.RadioButton(tool.Name, CEDGame.MapManager.ActiveTool == tool)) { + CEDGame.MapManager.ActiveTool?.OnDeactivated(CEDGame.MapManager.Selected); + CEDGame.MapManager.ActiveTool = tool; + CEDGame.MapManager.ActiveTool?.OnActivated(CEDGame.MapManager.Selected); } } } \ No newline at end of file diff --git a/CentrED/UI/Windows/Window.cs b/CentrED/UI/Windows/Window.cs index 1fd3c7e..bfa666f 100644 --- a/CentrED/UI/Windows/Window.cs +++ b/CentrED/UI/Windows/Window.cs @@ -1,15 +1,8 @@ -using CentrED.Map; -using ImGuiNET; +using ImGuiNET; namespace CentrED.UI.Windows; public abstract class Window { - protected UIManager _uiManager; - protected MapManager _mapManager; - internal Window(UIManager uiManager) { - _uiManager = uiManager; - _mapManager = uiManager._mapManager; - } public abstract string Name { get; }