From 4c822df63e5a29e037e462789b6591ff0c628c8e Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Thu, 24 Mar 2022 10:48:16 -0700 Subject: [PATCH] Abstract content manager away from consuming classes --- EndlessClient/Content/ContentProvider.cs | 94 +++++++++++++++++++ .../Content/IContentManagerRepository.cs | 22 ----- .../ControlSets/BackButtonControlSet.cs | 6 +- EndlessClient/ControlSets/BaseControlSet.cs | 12 +-- .../ControlSets/ControlSetFactory.cs | 8 +- .../ControlSets/CreateAccountControlSet.cs | 6 +- EndlessClient/ControlSets/EmptyControlSet.cs | 4 +- EndlessClient/ControlSets/IControlSet.cs | 6 +- .../ControlSets/InitialControlSet.cs | 5 +- .../ControlSets/IntermediateControlSet.cs | 6 +- .../ControlSets/LoginPromptControlSet.cs | 5 +- EndlessClient/Dialogs/ChangePasswordDialog.cs | 4 +- .../Dialogs/CreateCharacterDialog.cs | 6 +- .../Factories/ChangePasswordDialogFactory.cs | 8 +- .../CreateAccountWarningDialogFactory.cs | 5 + .../Factories/CreateCharacterDialogFactory.cs | 8 +- .../Factories/TextInputDialogFactory.cs | 8 +- .../Dialogs/ScrollingMessageDialog.cs | 4 +- EndlessClient/Dialogs/TextInputDialog.cs | 4 +- EndlessClient/GameExecution/EndlessGame.cs | 9 +- .../GameExecution/GameStateActions.cs | 3 +- .../HUD/Controls/HudControlsFactory.cs | 8 +- EndlessClient/HUD/Panels/HudPanelFactory.cs | 12 +-- .../EndlessClientInitializer.cs | 10 +- .../Chat/ChatBubbleTextureProvider.cs | 28 +++--- EndlessClient/UIControls/ChatTextBox.cs | 4 +- 26 files changed, 189 insertions(+), 106 deletions(-) create mode 100644 EndlessClient/Content/ContentProvider.cs delete mode 100644 EndlessClient/Content/IContentManagerRepository.cs diff --git a/EndlessClient/Content/ContentProvider.cs b/EndlessClient/Content/ContentProvider.cs new file mode 100644 index 000000000..7994ee752 --- /dev/null +++ b/EndlessClient/Content/ContentProvider.cs @@ -0,0 +1,94 @@ +using AutomaticTypeMapper; +using EOLib; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System.Collections.Generic; + +namespace EndlessClient.Content +{ + public interface IContentProvider + { + IReadOnlyDictionary Textures { get; } + + IReadOnlyDictionary Fonts { get; } + + void SetContentManager(ContentManager content); + + void Load(); + } + + [AutoMappedType(IsSingleton = true)] + public class ContentProvider : IContentProvider + { + private readonly Dictionary _textures; + private readonly Dictionary _fonts; + + private ContentManager _content; + + public const string Cursor = "cursor"; + + public const string TBBack = "tbBack"; + public const string TBLeft = "tbLeft"; + public const string TBRight = "tbRight"; + + public const string ChatTL = @"ChatBubble\TL"; + public const string ChatTM = @"ChatBubble\TM"; + public const string ChatTR = @"ChatBubble\TR"; + public const string ChatML = @"ChatBubble\ML"; + public const string ChatMM = @"ChatBubble\MM"; + public const string ChatMR = @"ChatBubble\MR"; + public const string ChatRL = @"ChatBubble\RL"; + public const string ChatRM = @"ChatBubble\RM"; + public const string ChatRR = @"ChatBubble\RR"; + public const string ChatNUB = @"ChatBubble\NUB"; + + public IReadOnlyDictionary Textures => _textures; + + public IReadOnlyDictionary Fonts => _fonts; + + public ContentProvider() + { + _textures = new Dictionary(); + _fonts = new Dictionary(); + } + + public void SetContentManager(ContentManager content) + { + _content = content; + } + + public void Load() + { + RefreshTextures(); + RefreshFonts(); + } + + private void RefreshTextures() + { + if (_content == null) + return; + + _textures[Cursor] = _content.Load(Cursor); + + _textures[TBBack] = _content.Load(TBBack); + _textures[TBLeft] = _content.Load(TBLeft); + _textures[TBRight] = _content.Load(TBRight); + + _textures[ChatTL] = _content.Load(ChatTL); + _textures[ChatTM] = _content.Load(ChatTM); + _textures[ChatTR] = _content.Load(ChatTR); + _textures[ChatML] = _content.Load(ChatML); + _textures[ChatMM] = _content.Load(ChatMM); + _textures[ChatMR] = _content.Load(ChatMR); + _textures[ChatRL] = _content.Load(ChatRL); + _textures[ChatRM] = _content.Load(ChatRM); + _textures[ChatRR] = _content.Load(ChatRR); + _textures[ChatNUB] = _content.Load(ChatNUB); + } + + private void RefreshFonts() + { + _fonts[Constants.FontSize08] = _content.Load(Constants.FontSize08); + } + } +} diff --git a/EndlessClient/Content/IContentManagerRepository.cs b/EndlessClient/Content/IContentManagerRepository.cs deleted file mode 100644 index b2ea957eb..000000000 --- a/EndlessClient/Content/IContentManagerRepository.cs +++ /dev/null @@ -1,22 +0,0 @@ -using AutomaticTypeMapper; -using Microsoft.Xna.Framework.Content; - -namespace EndlessClient.Content -{ - public interface IContentManagerRepository - { - ContentManager Content { get; set; } - } - - public interface IContentManagerProvider - { - ContentManager Content { get; } - } - - [MappedType(BaseType = typeof(IContentManagerProvider), IsSingleton = true)] - [MappedType(BaseType = typeof(IContentManagerRepository), IsSingleton = true)] - public class ContentManagerRepository : IContentManagerRepository, IContentManagerProvider - { - public ContentManager Content { get; set; } - } -} diff --git a/EndlessClient/ControlSets/BackButtonControlSet.cs b/EndlessClient/ControlSets/BackButtonControlSet.cs index aab1a1a96..01dbdb4e3 100644 --- a/EndlessClient/ControlSets/BackButtonControlSet.cs +++ b/EndlessClient/ControlSets/BackButtonControlSet.cs @@ -1,8 +1,8 @@ using System; +using EndlessClient.Content; using EndlessClient.Controllers; using EOLib.Graphics; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using XNAControls; @@ -21,9 +21,9 @@ protected BackButtonControlSet(IMainButtonController mainButtonController) _mainButtonController = mainButtonController; } - public override void InitializeResources(INativeGraphicsManager gfxManager, ContentManager xnaContentManager) + public override void InitializeResources(INativeGraphicsManager gfxManager, IContentProvider contentProvider) { - base.InitializeResources(gfxManager, xnaContentManager); + base.InitializeResources(gfxManager, contentProvider); _backButtonTexture = gfxManager.TextureFromResource(GFXTypes.PreLoginUI, 24, true); } diff --git a/EndlessClient/ControlSets/BaseControlSet.cs b/EndlessClient/ControlSets/BaseControlSet.cs index 3259aba02..f8efc399e 100644 --- a/EndlessClient/ControlSets/BaseControlSet.cs +++ b/EndlessClient/ControlSets/BaseControlSet.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using EndlessClient.Content; using EndlessClient.GameExecution; using EOLib.Graphics; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using XNAControls; @@ -43,7 +43,7 @@ protected BaseControlSet() } public virtual void InitializeResources(INativeGraphicsManager gfxManager, - ContentManager xnaContentManager) + IContentProvider contentProvider) { if (_resourcesInitialized) throw new InvalidOperationException("Error initializing resources: resources have already been initialized"); @@ -52,10 +52,10 @@ protected BaseControlSet() _secondaryButtonTexture = gfxManager.TextureFromResource(GFXTypes.PreLoginUI, 14, true); _smallButtonSheet = gfxManager.TextureFromResource(GFXTypes.PreLoginUI, 15, true); - _textBoxBackground = xnaContentManager.Load("tbBack"); - _textBoxLeft = xnaContentManager.Load("tbLeft"); - _textBoxRight = xnaContentManager.Load("tbRight"); - _textBoxCursor = xnaContentManager.Load("cursor"); + _textBoxBackground = contentProvider.Textures[ContentProvider.TBBack]; + _textBoxLeft = contentProvider.Textures[ContentProvider.TBLeft]; + _textBoxRight = contentProvider.Textures[ContentProvider.TBRight]; + _textBoxCursor = contentProvider.Textures[ContentProvider.Cursor]; _backgroundImages = new Texture2D[7]; for (int i = 0; i < _backgroundImages.Length; ++i) diff --git a/EndlessClient/ControlSets/ControlSetFactory.cs b/EndlessClient/ControlSets/ControlSetFactory.cs index 08812c294..b5c378419 100644 --- a/EndlessClient/ControlSets/ControlSetFactory.cs +++ b/EndlessClient/ControlSets/ControlSetFactory.cs @@ -18,7 +18,7 @@ public class ControlSetFactory : IControlSetFactory private readonly INativeGraphicsManager _nativeGraphicsManager; private readonly IEOMessageBoxFactory _messageBoxFactory; private readonly IHudControlsFactory _hudControlsFactory; - private readonly IContentManagerProvider _contentManagerProvider; + private readonly IContentProvider _contentProvider; private readonly IKeyboardDispatcherProvider _keyboardDispatcherProvider; private readonly IConfigurationProvider _configProvider; private readonly ICharacterInfoPanelFactory _characterInfoPanelFactory; @@ -30,7 +30,7 @@ public class ControlSetFactory : IControlSetFactory public ControlSetFactory(INativeGraphicsManager nativeGraphicsManager, IEOMessageBoxFactory messageBoxFactory, IHudControlsFactory hudControlsFactory, - IContentManagerProvider contentManagerProvider, + IContentProvider contentProvider, IKeyboardDispatcherProvider keyboardDispatcherProvider, IConfigurationProvider configProvider, ICharacterInfoPanelFactory characterInfoPanelFactory) @@ -38,7 +38,7 @@ public class ControlSetFactory : IControlSetFactory _nativeGraphicsManager = nativeGraphicsManager; _messageBoxFactory = messageBoxFactory; _hudControlsFactory = hudControlsFactory; - _contentManagerProvider = contentManagerProvider; + _contentProvider = contentProvider; _keyboardDispatcherProvider = keyboardDispatcherProvider; _configProvider = configProvider; _characterInfoPanelFactory = characterInfoPanelFactory; @@ -51,7 +51,7 @@ public IControlSet CreateControlsForState(GameStates newState, IControlSet curre throw new InvalidOperationException("Missing controllers - the Unity container was initialized incorrectly"); var controlSet = GetSetBasedOnState(newState); - controlSet.InitializeResources(_nativeGraphicsManager, _contentManagerProvider.Content); + controlSet.InitializeResources(_nativeGraphicsManager, _contentProvider); controlSet.InitializeControls(currentControlSet); return controlSet; } diff --git a/EndlessClient/ControlSets/CreateAccountControlSet.cs b/EndlessClient/ControlSets/CreateAccountControlSet.cs index 2fbfaa4a2..e87eb133a 100644 --- a/EndlessClient/ControlSets/CreateAccountControlSet.cs +++ b/EndlessClient/ControlSets/CreateAccountControlSet.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using EndlessClient.Content; using EndlessClient.Controllers; using EndlessClient.GameExecution; using EndlessClient.Input; @@ -7,7 +8,6 @@ using EOLib.Domain.Account; using EOLib.Graphics; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using XNAControls; @@ -41,9 +41,9 @@ public class CreateAccountControlSet : IntermediateControlSet _accountController = accountController; } - public override void InitializeResources(INativeGraphicsManager gfxManager, ContentManager xnaContentManager) + public override void InitializeResources(INativeGraphicsManager gfxManager, IContentProvider contentProvider) { - base.InitializeResources(gfxManager, xnaContentManager); + base.InitializeResources(gfxManager, contentProvider); _labelsTexture = gfxManager.TextureFromResource(GFXTypes.PreLoginUI, 12, true); } diff --git a/EndlessClient/ControlSets/EmptyControlSet.cs b/EndlessClient/ControlSets/EmptyControlSet.cs index 07f70c38a..2318b7edb 100644 --- a/EndlessClient/ControlSets/EmptyControlSet.cs +++ b/EndlessClient/ControlSets/EmptyControlSet.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; +using EndlessClient.Content; using EndlessClient.GameExecution; using EOLib.Graphics; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; using XNAControls; namespace EndlessClient.ControlSets @@ -19,7 +19,7 @@ public class EmptyControlSet : IControlSet public IReadOnlyList XNAControlComponents => AllComponents.OfType().ToList(); - public void InitializeResources(INativeGraphicsManager gfxManager, ContentManager xnaContentManager) + public void InitializeResources(INativeGraphicsManager gfxManager, IContentProvider contentProvider) { } diff --git a/EndlessClient/ControlSets/IControlSet.cs b/EndlessClient/ControlSets/IControlSet.cs index 4a64fead4..59e344c63 100644 --- a/EndlessClient/ControlSets/IControlSet.cs +++ b/EndlessClient/ControlSets/IControlSet.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; +using EndlessClient.Content; using EndlessClient.GameExecution; using EOLib.Graphics; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; using XNAControls; namespace EndlessClient.ControlSets @@ -29,8 +29,8 @@ public interface IControlSet : IDisposable /// Initialize the required resources for the control set from the resource dependencies. Should be called before InitializeControls() /// /// An initialized native graphics manager - /// The ContentManager for the game - void InitializeResources(INativeGraphicsManager gfxManager, ContentManager xnaContentManager); + /// The ContentProvider for the game + void InitializeResources(INativeGraphicsManager gfxManager, IContentProvider contentProvider); /// /// Create the controls for this IControlSet based on an existing set of controls diff --git a/EndlessClient/ControlSets/InitialControlSet.cs b/EndlessClient/ControlSets/InitialControlSet.cs index a4b230a42..af79295cd 100644 --- a/EndlessClient/ControlSets/InitialControlSet.cs +++ b/EndlessClient/ControlSets/InitialControlSet.cs @@ -1,4 +1,5 @@ using System; +using EndlessClient.Content; using EndlessClient.Controllers; using EndlessClient.GameExecution; using EOLib; @@ -38,9 +39,9 @@ public class InitialControlSet : BaseControlSet _randomGen = new Random(); } - public override void InitializeResources(INativeGraphicsManager gfxManager, ContentManager xnaContentManager) + public override void InitializeResources(INativeGraphicsManager gfxManager, IContentProvider contentProvider) { - base.InitializeResources(gfxManager, xnaContentManager); + base.InitializeResources(gfxManager, contentProvider); for (int i = 0; i < _personSet1.Length; ++i) _personSet1[i] = gfxManager.TextureFromResource(GFXTypes.PreLoginUI, 41 + i, true); diff --git a/EndlessClient/ControlSets/IntermediateControlSet.cs b/EndlessClient/ControlSets/IntermediateControlSet.cs index a7ac163a6..1c5fe6ea2 100644 --- a/EndlessClient/ControlSets/IntermediateControlSet.cs +++ b/EndlessClient/ControlSets/IntermediateControlSet.cs @@ -1,9 +1,9 @@ using System; +using EndlessClient.Content; using EndlessClient.Controllers; using EndlessClient.GameExecution; using EOLib.Graphics; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using XNAControls; @@ -27,9 +27,9 @@ public abstract class IntermediateControlSet : BackButtonControlSet _randomGen = new Random(); } - public override void InitializeResources(INativeGraphicsManager gfxManager, ContentManager xnaContentManager) + public override void InitializeResources(INativeGraphicsManager gfxManager, IContentProvider contentProvider) { - base.InitializeResources(gfxManager, xnaContentManager); + base.InitializeResources(gfxManager, contentProvider); for (int i = 0; i < _personSet2.Length; ++i) _personSet2[i] = gfxManager.TextureFromResource(GFXTypes.PreLoginUI, 61 + i, true); diff --git a/EndlessClient/ControlSets/LoginPromptControlSet.cs b/EndlessClient/ControlSets/LoginPromptControlSet.cs index 21241da8d..3c9e4efb9 100644 --- a/EndlessClient/ControlSets/LoginPromptControlSet.cs +++ b/EndlessClient/ControlSets/LoginPromptControlSet.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading; +using EndlessClient.Content; using EndlessClient.Controllers; using EndlessClient.GameExecution; using EndlessClient.Input; @@ -44,9 +45,9 @@ public class LoginPromptControlSet : InitialControlSet _loginController = loginController; } - public override void InitializeResources(INativeGraphicsManager gfxManager, ContentManager xnaContentManager) + public override void InitializeResources(INativeGraphicsManager gfxManager, IContentProvider contentProvider) { - base.InitializeResources(gfxManager, xnaContentManager); + base.InitializeResources(gfxManager, contentProvider); _loginBackgroundTexture = gfxManager.TextureFromResource(GFXTypes.PreLoginUI, 2); } diff --git a/EndlessClient/Dialogs/ChangePasswordDialog.cs b/EndlessClient/Dialogs/ChangePasswordDialog.cs index 984cd896b..7ca699875 100644 --- a/EndlessClient/Dialogs/ChangePasswordDialog.cs +++ b/EndlessClient/Dialogs/ChangePasswordDialog.cs @@ -35,7 +35,7 @@ public class ChangePasswordDialog : BaseEODialog public ChangePasswordDialog(INativeGraphicsManager nativeGraphicsManager, IGameStateProvider gameStateProvider, - IContentManagerProvider contentManagerProvider, + IContentProvider contentProvider, IEOMessageBoxFactory eoMessageBoxFactory, IKeyboardDispatcherProvider keyboardDispatcherProvider, IPlayerInfoProvider playerInfoProvider, @@ -48,7 +48,7 @@ public class ChangePasswordDialog : BaseEODialog BackgroundTexture = nativeGraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 21); - var cursorTexture = contentManagerProvider.Content.Load("Cursor"); + var cursorTexture = contentProvider.Textures[ContentProvider.Cursor]; _inputBoxes = new IXNATextBox[4]; for (int i = 0; i < _inputBoxes.Length; ++i) diff --git a/EndlessClient/Dialogs/CreateCharacterDialog.cs b/EndlessClient/Dialogs/CreateCharacterDialog.cs index 98548a89c..eb78b117e 100644 --- a/EndlessClient/Dialogs/CreateCharacterDialog.cs +++ b/EndlessClient/Dialogs/CreateCharacterDialog.cs @@ -1,4 +1,5 @@ using System; +using EndlessClient.Content; using EndlessClient.Dialogs.Factories; using EndlessClient.Dialogs.Services; using EndlessClient.GameExecution; @@ -9,7 +10,6 @@ using EOLib.Graphics; using EOLib.Localization; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using XNAControls; @@ -41,7 +41,7 @@ public class CreateCharacterDialog : BaseEODialog INativeGraphicsManager nativeGraphicsManager, IGameStateProvider gameStateProvider, ICharacterRendererFactory rendererFactory, - ContentManager contentManager, + IContentProvider contentProvider, KeyboardDispatcher dispatcher, IEOMessageBoxFactory messageBoxFactory, IEODialogButtonService eoDialogButtonService) @@ -52,7 +52,7 @@ public class CreateCharacterDialog : BaseEODialog _charCreateSheet = nativeGraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 22); - var cursorTexture = contentManager.Load("cursor"); + var cursorTexture = contentProvider.Textures[ContentProvider.Cursor]; _inputBox = new XNATextBox(new Rectangle(80, 57, 138, 19), Constants.FontSize08, caretTexture: cursorTexture) { LeftPadding = 5, diff --git a/EndlessClient/Dialogs/Factories/ChangePasswordDialogFactory.cs b/EndlessClient/Dialogs/Factories/ChangePasswordDialogFactory.cs index 8ef219613..1720446f5 100644 --- a/EndlessClient/Dialogs/Factories/ChangePasswordDialogFactory.cs +++ b/EndlessClient/Dialogs/Factories/ChangePasswordDialogFactory.cs @@ -13,7 +13,7 @@ public class ChangePasswordDialogFactory : IChangePasswordDialogFactory { private readonly INativeGraphicsManager _nativeGraphicsManager; private readonly IGameStateProvider _gameStateProvider; - private readonly IContentManagerProvider _contentManagerProvider; + private readonly IContentProvider _contentProvider; private readonly IEOMessageBoxFactory _eoMessageBoxFactory; private readonly IKeyboardDispatcherProvider _keyboardDispatcherProvider; private readonly IPlayerInfoProvider _playerInfoProvider; @@ -21,7 +21,7 @@ public class ChangePasswordDialogFactory : IChangePasswordDialogFactory public ChangePasswordDialogFactory(INativeGraphicsManager nativeGraphicsManager, IGameStateProvider gameStateProvider, - IContentManagerProvider contentManagerProvider, + IContentProvider contentProvider, IEOMessageBoxFactory eoMessageBoxFactory, IKeyboardDispatcherProvider keyboardDispatcherProvider, IPlayerInfoProvider playerInfoProvider, @@ -29,7 +29,7 @@ public class ChangePasswordDialogFactory : IChangePasswordDialogFactory { _nativeGraphicsManager = nativeGraphicsManager; _gameStateProvider = gameStateProvider; - _contentManagerProvider = contentManagerProvider; + _contentProvider = contentProvider; _eoMessageBoxFactory = eoMessageBoxFactory; _keyboardDispatcherProvider = keyboardDispatcherProvider; _playerInfoProvider = playerInfoProvider; @@ -40,7 +40,7 @@ public ChangePasswordDialog BuildChangePasswordDialog() { return new ChangePasswordDialog(_nativeGraphicsManager, _gameStateProvider, - _contentManagerProvider, + _contentProvider, _eoMessageBoxFactory, _keyboardDispatcherProvider, _playerInfoProvider, diff --git a/EndlessClient/Dialogs/Factories/CreateAccountWarningDialogFactory.cs b/EndlessClient/Dialogs/Factories/CreateAccountWarningDialogFactory.cs index ec6afd21b..291f845d0 100644 --- a/EndlessClient/Dialogs/Factories/CreateAccountWarningDialogFactory.cs +++ b/EndlessClient/Dialogs/Factories/CreateAccountWarningDialogFactory.cs @@ -1,4 +1,5 @@ using AutomaticTypeMapper; +using EndlessClient.Content; using EndlessClient.Dialogs.Services; using EndlessClient.GameExecution; using EOLib.Graphics; @@ -10,15 +11,18 @@ namespace EndlessClient.Dialogs.Factories public class CreateAccountWarningDialogFactory : ICreateAccountWarningDialogFactory { private readonly INativeGraphicsManager _nativeGraphicsManager; + private readonly IContentProvider _contentProvider; private readonly IGameStateProvider _gameStateProvider; private readonly IEODialogButtonService _eoDialogButtonService; public CreateAccountWarningDialogFactory( INativeGraphicsManager nativeGraphicsManager, + IContentProvider contentProvider, IGameStateProvider gameStateProvider, IEODialogButtonService eoDialogButtonService) { _nativeGraphicsManager = nativeGraphicsManager; + _contentProvider = contentProvider; _gameStateProvider = gameStateProvider; _eoDialogButtonService = eoDialogButtonService; } @@ -27,6 +31,7 @@ public IXNADialog ShowCreateAccountWarningDialog(string warningMessage) { return new ScrollingMessageDialog( _nativeGraphicsManager, + _contentProvider, _gameStateProvider, _eoDialogButtonService) { diff --git a/EndlessClient/Dialogs/Factories/CreateCharacterDialogFactory.cs b/EndlessClient/Dialogs/Factories/CreateCharacterDialogFactory.cs index a4b8c355a..a6a7b108a 100644 --- a/EndlessClient/Dialogs/Factories/CreateCharacterDialogFactory.cs +++ b/EndlessClient/Dialogs/Factories/CreateCharacterDialogFactory.cs @@ -14,7 +14,7 @@ public class CreateCharacterDialogFactory : ICreateCharacterDialogFactory private readonly INativeGraphicsManager _nativeGraphicsManager; private readonly IGameStateProvider _gameStateProvider; private readonly ICharacterRendererFactory _characterRendererFactory; - private readonly IContentManagerProvider _contentManagerProvider; + private readonly IContentProvider _contentProvider; private readonly IKeyboardDispatcherProvider _keyboardDispatcherProvider; private readonly IEOMessageBoxFactory _eoMessageBoxFactory; private readonly IEODialogButtonService _dialogButtonService; @@ -22,7 +22,7 @@ public class CreateCharacterDialogFactory : ICreateCharacterDialogFactory public CreateCharacterDialogFactory(INativeGraphicsManager nativeGraphicsManager, IGameStateProvider gameStateProvider, ICharacterRendererFactory characterRendererFactory, - IContentManagerProvider contentManagerProvider, + IContentProvider contentProvider, IKeyboardDispatcherProvider keyboardDispatcherProvider, IEOMessageBoxFactory eoMessageBoxFactory, IEODialogButtonService dialogButtonService) @@ -30,7 +30,7 @@ public class CreateCharacterDialogFactory : ICreateCharacterDialogFactory _nativeGraphicsManager = nativeGraphicsManager; _gameStateProvider = gameStateProvider; _characterRendererFactory = characterRendererFactory; - _contentManagerProvider = contentManagerProvider; + _contentProvider = contentProvider; _keyboardDispatcherProvider = keyboardDispatcherProvider; _eoMessageBoxFactory = eoMessageBoxFactory; _dialogButtonService = dialogButtonService; @@ -41,7 +41,7 @@ public CreateCharacterDialog BuildCreateCharacterDialog() return new CreateCharacterDialog(_nativeGraphicsManager, _gameStateProvider, _characterRendererFactory, - _contentManagerProvider.Content, + _contentProvider, _keyboardDispatcherProvider.Dispatcher, _eoMessageBoxFactory, _dialogButtonService); diff --git a/EndlessClient/Dialogs/Factories/TextInputDialogFactory.cs b/EndlessClient/Dialogs/Factories/TextInputDialogFactory.cs index ba48ca80f..fb619c806 100644 --- a/EndlessClient/Dialogs/Factories/TextInputDialogFactory.cs +++ b/EndlessClient/Dialogs/Factories/TextInputDialogFactory.cs @@ -14,19 +14,19 @@ public class TextInputDialogFactory : ITextInputDialogFactory private readonly INativeGraphicsManager _nativeGraphicsManager; private readonly IEODialogButtonService _eoDialogButtonService; private readonly IKeyboardDispatcherRepository _keyboardDispatcherRepository; - private readonly IContentManagerProvider _contentManagerProvider; + private readonly IContentProvider _contentProvider; public TextInputDialogFactory(IGameStateProvider gameStateProvider, INativeGraphicsManager nativeGraphicsManager, IEODialogButtonService eoDialogButtonService, IKeyboardDispatcherRepository keyboardDispatcherRepository, - IContentManagerProvider contentManagerProvider) + IContentProvider contentProvider) { _gameStateProvider = gameStateProvider; _nativeGraphicsManager = nativeGraphicsManager; _eoDialogButtonService = eoDialogButtonService; _keyboardDispatcherRepository = keyboardDispatcherRepository; - _contentManagerProvider = contentManagerProvider; + _contentProvider = contentProvider; } public TextInputDialog Create(string prompt, int maxInputChars = 12) @@ -35,7 +35,7 @@ public TextInputDialog Create(string prompt, int maxInputChars = 12) _nativeGraphicsManager, _eoDialogButtonService, _keyboardDispatcherRepository, - _contentManagerProvider, + _contentProvider, prompt, maxInputChars); } diff --git a/EndlessClient/Dialogs/ScrollingMessageDialog.cs b/EndlessClient/Dialogs/ScrollingMessageDialog.cs index e8235c874..e77349389 100644 --- a/EndlessClient/Dialogs/ScrollingMessageDialog.cs +++ b/EndlessClient/Dialogs/ScrollingMessageDialog.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using EndlessClient.Content; using EndlessClient.Dialogs.Services; using EndlessClient.GameExecution; using EndlessClient.UIControls; @@ -52,11 +53,12 @@ public string MessageText } public ScrollingMessageDialog(INativeGraphicsManager nativeGraphicsManager, + IContentProvider contentProvider, IGameStateProvider gameStateProvider, IEODialogButtonService eoDialogButtonService) : base(gameStateProvider) { - _font = Game.Content.Load(Constants.FontSize08); + _font = contentProvider.Fonts[Constants.FontSize08]; _textSplitter = new TextSplitter("", _font) { LineLength = 275 }; BackgroundTexture = nativeGraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 40); diff --git a/EndlessClient/Dialogs/TextInputDialog.cs b/EndlessClient/Dialogs/TextInputDialog.cs index 2df523e22..a3380f0a7 100644 --- a/EndlessClient/Dialogs/TextInputDialog.cs +++ b/EndlessClient/Dialogs/TextInputDialog.cs @@ -23,7 +23,7 @@ public class TextInputDialog : BaseEODialog INativeGraphicsManager nativeGraphicsManager, IEODialogButtonService eoDialogButtonService, IKeyboardDispatcherRepository keyboardDispatcherRepository, - IContentManagerProvider contentManagerProvider, + IContentProvider contentProvider, string prompt, int maxInputChars = 12) : base(gameStateProvider) @@ -44,7 +44,7 @@ public class TextInputDialog : BaseEODialog lblPrompt.Initialize(); lblPrompt.SetParentControl(this); - _inputBox = new XNATextBox(new Rectangle(37, 74, 192, 19), Constants.FontSize08, caretTexture: contentManagerProvider.Content.Load("cursor")) + _inputBox = new XNATextBox(new Rectangle(37, 74, 192, 19), Constants.FontSize08, caretTexture: contentProvider.Textures[ContentProvider.Cursor]) { MaxChars = maxInputChars, LeftPadding = 4, diff --git a/EndlessClient/GameExecution/EndlessGame.cs b/EndlessClient/GameExecution/EndlessGame.cs index 9c5d348ac..0560213c0 100644 --- a/EndlessClient/GameExecution/EndlessGame.cs +++ b/EndlessClient/GameExecution/EndlessGame.cs @@ -20,6 +20,7 @@ namespace EndlessClient.GameExecution public class EndlessGame : Game, IEndlessGame { private readonly IClientWindowSizeProvider _windowSizeProvider; + private readonly IContentProvider _contentProvider; private readonly IGraphicsDeviceRepository _graphicsDeviceRepository; private readonly IControlSetRepository _controlSetRepository; private readonly IControlSetFactory _controlSetFactory; @@ -33,6 +34,7 @@ public class EndlessGame : Game, IEndlessGame private KeyboardState _previousKeyState; public EndlessGame(IClientWindowSizeProvider windowSizeProvider, + IContentProvider contentProvider, IGraphicsDeviceRepository graphicsDeviceRepository, IControlSetRepository controlSetRepository, IControlSetFactory controlSetFactory, @@ -43,6 +45,7 @@ public class EndlessGame : Game, IEndlessGame IShaderRepository shaderRepository) { _windowSizeProvider = windowSizeProvider; + _contentProvider = contentProvider; _graphicsDeviceRepository = graphicsDeviceRepository; _controlSetRepository = controlSetRepository; _controlSetFactory = controlSetFactory; @@ -70,12 +73,12 @@ protected override void Initialize() _graphicsDeviceManager.PreferredBackBufferWidth = _windowSizeProvider.Width; _graphicsDeviceManager.PreferredBackBufferHeight = _windowSizeProvider.Height; _graphicsDeviceManager.ApplyChanges(); - - SetUpInitialControlSet(); } protected override void LoadContent() { + _contentProvider.Load(); + //todo: all the things that should load stuff as part of game's load/initialize should be broken into a pattern _chatBubbleTextureProvider.LoadContent(); @@ -94,6 +97,8 @@ protected override void LoadContent() _shaderRepository.Shaders[ShaderRepository.HairClip] = new Effect(GraphicsDevice, shaderBytes); } + SetUpInitialControlSet(); + base.LoadContent(); } diff --git a/EndlessClient/GameExecution/GameStateActions.cs b/EndlessClient/GameExecution/GameStateActions.cs index 92f438bc6..c8b6d299e 100644 --- a/EndlessClient/GameExecution/GameStateActions.cs +++ b/EndlessClient/GameExecution/GameStateActions.cs @@ -70,8 +70,7 @@ private void RemoveOldComponents(IControlSet currentSet, IControlSet nextSet) var componentsToRemove = FindUnusedComponents(currentSet, nextSet); var disposableComponents = componentsToRemove .Where(x => !(x is PacketHandlerGameComponent)) - .OfType() - .ToList(); + .OfType(); foreach (var component in disposableComponents) component.Dispose(); diff --git a/EndlessClient/HUD/Controls/HudControlsFactory.cs b/EndlessClient/HUD/Controls/HudControlsFactory.cs index c2ab539dc..b22523fcd 100644 --- a/EndlessClient/HUD/Controls/HudControlsFactory.cs +++ b/EndlessClient/HUD/Controls/HudControlsFactory.cs @@ -44,7 +44,7 @@ public class HudControlsFactory : IHudControlsFactory private readonly IUserInputRepository _userInputRepository; private readonly IStatusLabelSetter _statusLabelSetter; private readonly IStatusLabelTextProvider _statusLabelTextProvider; - private readonly IContentManagerProvider _contentManagerProvider; + private readonly IContentProvider _contentProvider; private readonly IHudControlProvider _hudControlProvider; private readonly ICurrentMapProvider _currentMapProvider; private readonly IChatModeCalculator _chatModeCalculator; @@ -68,7 +68,7 @@ public class HudControlsFactory : IHudControlsFactory IUserInputRepository userInputRepository, IStatusLabelSetter statusLabelSetter, IStatusLabelTextProvider statusLabelTextProvider, - IContentManagerProvider contentManagerProvider, + IContentProvider contentProvider, IHudControlProvider hudControlProvider, ICurrentMapProvider currentMapProvider, IChatModeCalculator chatModeCalculator, @@ -91,7 +91,7 @@ public class HudControlsFactory : IHudControlsFactory _userInputRepository = userInputRepository; _statusLabelSetter = statusLabelSetter; _statusLabelTextProvider = statusLabelTextProvider; - _contentManagerProvider = contentManagerProvider; + _contentProvider = contentProvider; _hudControlProvider = hudControlProvider; _currentMapProvider = currentMapProvider; _chatModeCalculator = chatModeCalculator; @@ -336,7 +336,7 @@ private ChatModePictureBox CreateChatModePictureBox() private ChatTextBox CreateChatTextBox() { - var chatTextBox = new ChatTextBox(_contentManagerProvider) + var chatTextBox = new ChatTextBox(_contentProvider) { Text = "", Selected = true, diff --git a/EndlessClient/HUD/Panels/HudPanelFactory.cs b/EndlessClient/HUD/Panels/HudPanelFactory.cs index cf2408a76..07755e770 100644 --- a/EndlessClient/HUD/Panels/HudPanelFactory.cs +++ b/EndlessClient/HUD/Panels/HudPanelFactory.cs @@ -20,7 +20,7 @@ public class HudPanelFactory : IHudPanelFactory private const int HUD_CONTROL_LAYER = 130; private readonly INativeGraphicsManager _nativeGraphicsManager; - private readonly IContentManagerProvider _contentManagerProvider; + private readonly IContentProvider _contentProvider; private readonly IHudControlProvider _hudControlProvider; private readonly INewsProvider _newsProvider; private readonly IChatProvider _chatProvider; @@ -32,7 +32,7 @@ public class HudPanelFactory : IHudPanelFactory private readonly IFriendIgnoreListService _friendIgnoreListService; public HudPanelFactory(INativeGraphicsManager nativeGraphicsManager, - IContentManagerProvider contentManagerProvider, + IContentProvider contentProvider, IHudControlProvider hudControlProvider, INewsProvider newsProvider, IChatProvider chatProvider, @@ -44,7 +44,7 @@ public class HudPanelFactory : IHudPanelFactory IFriendIgnoreListService friendIgnoreListService) { _nativeGraphicsManager = nativeGraphicsManager; - _contentManagerProvider = contentManagerProvider; + _contentProvider = contentProvider; _hudControlProvider = hudControlProvider; _newsProvider = newsProvider; _chatProvider = chatProvider; @@ -58,7 +58,7 @@ public class HudPanelFactory : IHudPanelFactory public NewsPanel CreateNewsPanel() { - var chatFont = _contentManagerProvider.Content.Load(Constants.FontSize08); + var chatFont = _contentProvider.Fonts[Constants.FontSize08]; return new NewsPanel(_nativeGraphicsManager, new ChatRenderableGenerator(_friendIgnoreListService, chatFont), @@ -83,7 +83,7 @@ public PassiveSpellsPanel CreatePassiveSpellsPanel() public ChatPanel CreateChatPanel() { - var chatFont = _contentManagerProvider.Content.Load(Constants.FontSize08); + var chatFont = _contentProvider.Fonts[Constants.FontSize08]; return new ChatPanel(_nativeGraphicsManager, new ChatRenderableGenerator(_friendIgnoreListService, chatFont), @@ -104,7 +104,7 @@ public StatsPanel CreateStatsPanel() public OnlineListPanel CreateOnlineListPanel() { - var chatFont = _contentManagerProvider.Content.Load(Constants.FontSize08); + var chatFont = _contentProvider.Fonts[Constants.FontSize08]; return new OnlineListPanel(_nativeGraphicsManager, _hudControlProvider, _friendIgnoreListService, chatFont) { DrawOrder = HUD_CONTROL_LAYER }; } diff --git a/EndlessClient/Initialization/EndlessClientInitializer.cs b/EndlessClient/Initialization/EndlessClientInitializer.cs index b7682b095..d56dac75e 100644 --- a/EndlessClient/Initialization/EndlessClientInitializer.cs +++ b/EndlessClient/Initialization/EndlessClientInitializer.cs @@ -18,7 +18,7 @@ public class EndlessClientInitializer : IGameInitializer { private readonly IEndlessGame _game; private readonly IEndlessGameRepository _endlessGameRepository; - private readonly IContentManagerRepository _contentManagerRepository; + private readonly IContentProvider _contentProvider; private readonly IKeyboardDispatcherRepository _keyboardDispatcherRepository; private readonly PacketHandlerGameComponent _packetHandlerGameComponent; @@ -33,7 +33,7 @@ public class EndlessClientInitializer : IGameInitializer public EndlessClientInitializer(IEndlessGame game, IEndlessGameRepository endlessGameRepository, - IContentManagerRepository contentManagerRepository, + IContentProvider contentProvider, IKeyboardDispatcherRepository keyboardDispatcherRepository, PacketHandlerGameComponent packetHandlerGameComponent, @@ -49,7 +49,7 @@ public class EndlessClientInitializer : IGameInitializer { _game = game; _endlessGameRepository = endlessGameRepository; - _contentManagerRepository = contentManagerRepository; + _contentProvider = contentProvider; _keyboardDispatcherRepository = keyboardDispatcherRepository; _packetHandlerGameComponent = packetHandlerGameComponent; _mainButtonController = mainButtonController; @@ -69,8 +69,8 @@ public void Initialize() _game.Components.Add(_packetHandlerGameComponent); _endlessGameRepository.Game = _game; - _contentManagerRepository.Content = _game.Content; - _contentManagerRepository.Content.RootDirectory = "ContentPipeline"; + _game.Content.RootDirectory = "ContentPipeline"; + _contentProvider.SetContentManager(_game.Content); _keyboardDispatcherRepository.Dispatcher = new KeyboardDispatcher(_game.Window); diff --git a/EndlessClient/Rendering/Chat/ChatBubbleTextureProvider.cs b/EndlessClient/Rendering/Chat/ChatBubbleTextureProvider.cs index 9dbde7109..903921620 100644 --- a/EndlessClient/Rendering/Chat/ChatBubbleTextureProvider.cs +++ b/EndlessClient/Rendering/Chat/ChatBubbleTextureProvider.cs @@ -9,33 +9,31 @@ namespace EndlessClient.Rendering.Chat [MappedType(BaseType = typeof(IChatBubbleTextureProvider), IsSingleton = true)] public class ChatBubbleTextureProvider : IChatBubbleTextureProvider { - private readonly IContentManagerProvider _contentManagerProvider; + private readonly IContentProvider _contentProvider; private readonly Dictionary _chatBubbleTextures; public IReadOnlyDictionary ChatBubbleTextures => _chatBubbleTextures; - public ChatBubbleTextureProvider(IContentManagerProvider contentManagerProvider) + public ChatBubbleTextureProvider(IContentProvider contentProvider) { - _contentManagerProvider = contentManagerProvider; + _contentProvider = contentProvider; _chatBubbleTextures = new Dictionary(); } public void LoadContent() { - _chatBubbleTextures.Add(ChatBubbleTexture.TopLeft, Content.Load("ChatBubble\\TL")); - _chatBubbleTextures.Add(ChatBubbleTexture.TopMiddle, Content.Load("ChatBubble\\TM")); - _chatBubbleTextures.Add(ChatBubbleTexture.TopRight, Content.Load("ChatBubble\\TR")); - _chatBubbleTextures.Add(ChatBubbleTexture.MiddleLeft, Content.Load("ChatBubble\\ML")); - _chatBubbleTextures.Add(ChatBubbleTexture.MiddleMiddle, Content.Load("ChatBubble\\MM")); - _chatBubbleTextures.Add(ChatBubbleTexture.MiddleRight, Content.Load("ChatBubble\\MR")); + _chatBubbleTextures.Add(ChatBubbleTexture.TopLeft, _contentProvider.Textures[ContentProvider.ChatTL]); + _chatBubbleTextures.Add(ChatBubbleTexture.TopMiddle, _contentProvider.Textures[ContentProvider.ChatTM]); + _chatBubbleTextures.Add(ChatBubbleTexture.TopRight, _contentProvider.Textures[ContentProvider.ChatTR]); + _chatBubbleTextures.Add(ChatBubbleTexture.MiddleLeft, _contentProvider.Textures[ContentProvider.ChatML]); + _chatBubbleTextures.Add(ChatBubbleTexture.MiddleMiddle, _contentProvider.Textures[ContentProvider.ChatMM]); + _chatBubbleTextures.Add(ChatBubbleTexture.MiddleRight, _contentProvider.Textures[ContentProvider.ChatMR]); //todo: change the first 'R' to a 'B' (for bottom) - _chatBubbleTextures.Add(ChatBubbleTexture.BottomLeft, Content.Load("ChatBubble\\RL")); - _chatBubbleTextures.Add(ChatBubbleTexture.BottomMiddle, Content.Load("ChatBubble\\RM")); - _chatBubbleTextures.Add(ChatBubbleTexture.BottomRight, Content.Load("ChatBubble\\RR")); - _chatBubbleTextures.Add(ChatBubbleTexture.Nubbin, Content.Load("ChatBubble\\NUB")); + _chatBubbleTextures.Add(ChatBubbleTexture.BottomLeft, _contentProvider.Textures[ContentProvider.ChatRL]); + _chatBubbleTextures.Add(ChatBubbleTexture.BottomMiddle, _contentProvider.Textures[ContentProvider.ChatRM]); + _chatBubbleTextures.Add(ChatBubbleTexture.BottomRight, _contentProvider.Textures[ContentProvider.ChatRR]); + _chatBubbleTextures.Add(ChatBubbleTexture.Nubbin, _contentProvider.Textures[ContentProvider.ChatNUB]); } - - private ContentManager Content => _contentManagerProvider.Content; } public interface IChatBubbleTextureProvider diff --git a/EndlessClient/UIControls/ChatTextBox.cs b/EndlessClient/UIControls/ChatTextBox.cs index 832060280..eec3ef6e7 100644 --- a/EndlessClient/UIControls/ChatTextBox.cs +++ b/EndlessClient/UIControls/ChatTextBox.cs @@ -17,10 +17,10 @@ public class ChatTextBox : XNATextBox private bool _ignoreAllInput; private Option _endMuteTime; - public ChatTextBox(IContentManagerProvider contentManagerProvider) + public ChatTextBox(IContentProvider contentManagerProvider) : base(new Rectangle(124, 308, 440, 19), Constants.FontSize08, - caretTexture: contentManagerProvider.Content.Load("cursor")) + caretTexture: contentManagerProvider.Textures[ContentProvider.Cursor]) { MaxChars = 140; _endMuteTime = Option.None();