diff --git a/EOLib/Domain/Character/Character.cs b/EOLib/Domain/Character/Character.cs index 2ac580cc4..b954d907a 100644 --- a/EOLib/Domain/Character/Character.cs +++ b/EOLib/Domain/Character/Character.cs @@ -28,6 +28,12 @@ public class Character : ICharacter public bool NoWall { get; private set; } + public Character() + { + RenderProperties = new CharacterRenderProperties(); + Stats = new CharacterStats(); + } + public ICharacter WithID(int id) { var character = MakeCopy(this); diff --git a/EndlessClient/ControlSets/ControlSetFactory.cs b/EndlessClient/ControlSets/ControlSetFactory.cs index b5c378419..2e8a87d6b 100644 --- a/EndlessClient/ControlSets/ControlSetFactory.cs +++ b/EndlessClient/ControlSets/ControlSetFactory.cs @@ -8,6 +8,7 @@ using EndlessClient.Input; using EndlessClient.UIControls; using EOLib.Config; +using EOLib.Domain.Login; using EOLib.Graphics; namespace EndlessClient.ControlSets @@ -22,6 +23,7 @@ public class ControlSetFactory : IControlSetFactory private readonly IKeyboardDispatcherProvider _keyboardDispatcherProvider; private readonly IConfigurationProvider _configProvider; private readonly ICharacterInfoPanelFactory _characterInfoPanelFactory; + private readonly ICharacterSelectorProvider _characterSelectorProvider; private IMainButtonController _mainButtonController; private IAccountController _accountController; private ILoginController _loginController; @@ -33,7 +35,8 @@ public ControlSetFactory(INativeGraphicsManager nativeGraphicsManager, IContentProvider contentProvider, IKeyboardDispatcherProvider keyboardDispatcherProvider, IConfigurationProvider configProvider, - ICharacterInfoPanelFactory characterInfoPanelFactory) + ICharacterInfoPanelFactory characterInfoPanelFactory, + ICharacterSelectorProvider characterSelectorProvider) { _nativeGraphicsManager = nativeGraphicsManager; _messageBoxFactory = messageBoxFactory; @@ -42,6 +45,7 @@ public ControlSetFactory(INativeGraphicsManager nativeGraphicsManager, _keyboardDispatcherProvider = keyboardDispatcherProvider; _configProvider = configProvider; _characterInfoPanelFactory = characterInfoPanelFactory; + _characterSelectorProvider = characterSelectorProvider; } public IControlSet CreateControlsForState(GameStates newState, IControlSet currentControlSet) @@ -89,6 +93,7 @@ private IControlSet GetSetBasedOnState(GameStates newState) _keyboardDispatcherProvider.Dispatcher, _mainButtonController, _characterInfoPanelFactory, + _characterSelectorProvider, _characterManagementController, _accountController); case GameStates.PlayingTheGame: diff --git a/EndlessClient/ControlSets/LoggedInControlSet.cs b/EndlessClient/ControlSets/LoggedInControlSet.cs index da285ad6d..0fefcadf4 100644 --- a/EndlessClient/ControlSets/LoggedInControlSet.cs +++ b/EndlessClient/ControlSets/LoggedInControlSet.cs @@ -4,6 +4,7 @@ using EndlessClient.Controllers; using EndlessClient.GameExecution; using EndlessClient.UIControls; +using EOLib.Domain.Login; using Microsoft.Xna.Framework; using XNAControls; @@ -12,6 +13,7 @@ namespace EndlessClient.ControlSets public class LoggedInControlSet : IntermediateControlSet { private readonly ICharacterInfoPanelFactory _characterInfoPanelFactory; + private readonly ICharacterSelectorProvider _characterSelectorProvider; private readonly ICharacterManagementController _characterManagementController; private readonly IAccountController _accountController; private readonly List _characterInfoPanels; @@ -25,11 +27,13 @@ public class LoggedInControlSet : IntermediateControlSet public LoggedInControlSet(KeyboardDispatcher dispatcher, IMainButtonController mainButtonController, ICharacterInfoPanelFactory characterInfoPanelFactory, + ICharacterSelectorProvider characterSelectorProvider, ICharacterManagementController characterManagementController, IAccountController accountController) : base(dispatcher, mainButtonController) { _characterInfoPanelFactory = characterInfoPanelFactory; + _characterSelectorProvider = characterSelectorProvider; _characterManagementController = characterManagementController; _accountController = accountController; _characterInfoPanels = new List(); @@ -40,7 +44,7 @@ protected override void InitializeControlsHelper(IControlSet currentControlSet) base.InitializeControlsHelper(currentControlSet); _changePasswordButton = GetControl(currentControlSet, GameControlIdentifier.ChangePasswordButton, GetPasswordButton); - _characterInfoPanels.AddRange(_characterInfoPanelFactory.CreatePanels()); + _characterInfoPanels.AddRange(_characterInfoPanelFactory.CreatePanels(_characterSelectorProvider.Characters)); _allComponents.Add(_changePasswordButton); _allComponents.AddRange(_characterInfoPanels); diff --git a/EndlessClient/GameExecution/EndlessGame.cs b/EndlessClient/GameExecution/EndlessGame.cs index 0560213c0..85921c70d 100644 --- a/EndlessClient/GameExecution/EndlessGame.cs +++ b/EndlessClient/GameExecution/EndlessGame.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Linq; using System.Runtime.InteropServices; using AutomaticTypeMapper; using EndlessClient.Content; @@ -6,6 +7,8 @@ using EndlessClient.Rendering; using EndlessClient.Rendering.Chat; using EndlessClient.Test; +using EndlessClient.UIControls; +using EOLib.Domain.Character; using EOLib.Graphics; using EOLib.IO; using EOLib.IO.Actions; @@ -29,6 +32,7 @@ public class EndlessGame : Game, IEndlessGame private readonly ILoggerProvider _loggerProvider; private readonly IChatBubbleTextureProvider _chatBubbleTextureProvider; private readonly IShaderRepository _shaderRepository; + private readonly ICharacterInfoPanelFactory _characterInfoPanelFactory; private GraphicsDeviceManager _graphicsDeviceManager; private KeyboardState _previousKeyState; @@ -42,7 +46,8 @@ public EndlessGame(IClientWindowSizeProvider windowSizeProvider, IPubFileLoadActions pubFileLoadActions, ILoggerProvider loggerProvider, IChatBubbleTextureProvider chatBubbleTextureProvider, - IShaderRepository shaderRepository) + IShaderRepository shaderRepository, + ICharacterInfoPanelFactory characterInfoPanelFactory) { _windowSizeProvider = windowSizeProvider; _contentProvider = contentProvider; @@ -54,6 +59,7 @@ public EndlessGame(IClientWindowSizeProvider windowSizeProvider, _loggerProvider = loggerProvider; _chatBubbleTextureProvider = chatBubbleTextureProvider; _shaderRepository = shaderRepository; + _characterInfoPanelFactory = characterInfoPanelFactory; _graphicsDeviceManager = new GraphicsDeviceManager(this); @@ -97,6 +103,14 @@ protected override void LoadContent() _shaderRepository.Shaders[ShaderRepository.HairClip] = new Effect(GraphicsDevice, shaderBytes); } + // for some reason initializing these and then killing them speeds up transition from Login -> LoggedIn state + // TODO: figure out why this happens???? + foreach (var panel in _characterInfoPanelFactory.CreatePanels(Enumerable.Repeat(new Character(), 3))) + { + panel.Initialize(); + panel.Dispose(); + } + SetUpInitialControlSet(); base.LoadContent(); diff --git a/EndlessClient/Rendering/Character/CharacterRenderer.cs b/EndlessClient/Rendering/Character/CharacterRenderer.cs index 02db0c3ba..8a866cb48 100644 --- a/EndlessClient/Rendering/Character/CharacterRenderer.cs +++ b/EndlessClient/Rendering/Character/CharacterRenderer.cs @@ -117,26 +117,31 @@ public override void Initialize() _charRenderTarget = _renderTargetFactory.CreateRenderTarget(); _sb = new SpriteBatch(Game.GraphicsDevice); - _nameLabel = new BlinkingLabel(Constants.FontSize08pt5) + if (_gameStateProvider.CurrentState == GameStates.PlayingTheGame) { - Visible = _gameStateProvider.CurrentState == GameStates.PlayingTheGame, - TextWidth = 89, - TextAlign = LabelAlignment.MiddleCenter, - ForeColor = Color.White, - AutoSize = true, - Text = _character?.Name ?? string.Empty, - DrawOrder = 30, - KeepInClientWindowBounds = false, - }; - _nameLabel.Initialize(); - - if (!_nameLabel.Game.Components.Contains(_nameLabel)) - _nameLabel.Game.Components.Add(_nameLabel); + _nameLabel = new BlinkingLabel(Constants.FontSize08pt5) + { + Visible = true, + TextWidth = 89, + TextAlign = LabelAlignment.MiddleCenter, + ForeColor = Color.White, + AutoSize = true, + Text = _character?.Name ?? string.Empty, + DrawOrder = 30, + KeepInClientWindowBounds = false, + }; + _nameLabel.Initialize(); + + if (!_nameLabel.Game.Components.Contains(_nameLabel)) + _nameLabel.Game.Components.Add(_nameLabel); + + _nameLabel.DrawPosition = GetNameLabelPosition(); + + _healthBarRenderer = _healthBarRendererFactory.CreateHealthBarRenderer(this); + } - _nameLabel.DrawPosition = GetNameLabelPosition(); _previousMouseState = _currentMouseState = Mouse.GetState(); - _healthBarRenderer = _healthBarRendererFactory.CreateHealthBarRenderer(this); base.Initialize(); } @@ -184,9 +189,9 @@ public override void Update(GameTime gameTime) { _mapInteractionController.RightClick(new MapCellState { Character = Option.Some(Character) }); } - } - _healthBarRenderer.Update(gameTime); + _healthBarRenderer.Update(gameTime); + } _previousMouseState = _currentMouseState; @@ -239,7 +244,8 @@ public void DrawToSpriteBatch(SpriteBatch spriteBatch) spriteBatch.Draw(_charRenderTarget, new Vector2(0, GetSteppingStoneOffset(Character.RenderProperties)), GetAlphaColor()); _effectRenderer.DrawInFrontOfTarget(spriteBatch); - _healthBarRenderer.DrawToSpriteBatch(spriteBatch); + if (_gameStateProvider.CurrentState == GameStates.PlayingTheGame) + _healthBarRenderer.DrawToSpriteBatch(spriteBatch); } #endregion @@ -328,6 +334,9 @@ private int GetMainCharacterOffsetY() private void UpdateNameLabel(GameTime gameTime) { + if (_gameStateProvider.CurrentState != GameStates.PlayingTheGame) + return; + if (_healthBarRenderer.Visible) { _nameLabel.Visible = false; @@ -473,10 +482,10 @@ protected override void Dispose(bool disposing) if (disposing) { _outline?.Dispose(); - _nameLabel.Dispose(); + _nameLabel?.Dispose(); - _sb.Dispose(); - _charRenderTarget.Dispose(); + _sb?.Dispose(); + _charRenderTarget?.Dispose(); } base.Dispose(disposing); diff --git a/EndlessClient/UIControls/CharacterInfoPanel.cs b/EndlessClient/UIControls/CharacterInfoPanel.cs index f309baa6d..da5567d8a 100644 --- a/EndlessClient/UIControls/CharacterInfoPanel.cs +++ b/EndlessClient/UIControls/CharacterInfoPanel.cs @@ -199,7 +199,7 @@ private Vector2 GetAdminGraphicLocation() private static string CapitalizeName(string name) { - return (char)(name[0] - 32) + name.Substring(1); + return string.IsNullOrEmpty(name) ? string.Empty : (char)(name[0] - 32) + name.Substring(1); } private ISpriteSheet CreateAdminGraphic(AdminLevel adminLevel) diff --git a/EndlessClient/UIControls/CharacterInfoPanelFactory.cs b/EndlessClient/UIControls/CharacterInfoPanelFactory.cs index 0232f6492..2a053c0bc 100644 --- a/EndlessClient/UIControls/CharacterInfoPanelFactory.cs +++ b/EndlessClient/UIControls/CharacterInfoPanelFactory.cs @@ -5,12 +5,13 @@ using EndlessClient.Dialogs.Services; using EndlessClient.Rendering; using EndlessClient.Rendering.Factories; +using EOLib.Domain.Character; using EOLib.Domain.Login; using EOLib.Graphics; namespace EndlessClient.UIControls { - [MappedType(BaseType = typeof(ICharacterInfoPanelFactory), IsSingleton = true)] + [AutoMappedType(IsSingleton = true)] public class CharacterInfoPanelFactory : ICharacterInfoPanelFactory { private readonly ICharacterSelectorProvider _characterProvider; @@ -45,16 +46,15 @@ public void InjectCharacterManagementController(ICharacterManagementController c _characterManagementController = characterManagementController; } - public IEnumerable CreatePanels() + public IEnumerable CreatePanels(IEnumerable characters) { if(_loginController == null || _characterManagementController == null) throw new InvalidOperationException("Missing controllers - the Unity container was initialized incorrectly"); int i = 0; - for (; i < _characterProvider.Characters.Count; ++i) + foreach (var character in characters) { - var character = _characterProvider.Characters[i]; - yield return new CharacterInfoPanel(i, + yield return new CharacterInfoPanel(i++, character, _nativeGraphicsManager, _eoDialogButtonService, diff --git a/EndlessClient/UIControls/ICharacterInfoPanelFactory.cs b/EndlessClient/UIControls/ICharacterInfoPanelFactory.cs index 93c87f455..ff8e41531 100644 --- a/EndlessClient/UIControls/ICharacterInfoPanelFactory.cs +++ b/EndlessClient/UIControls/ICharacterInfoPanelFactory.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; using EndlessClient.Controllers; +using EOLib.Domain.Character; namespace EndlessClient.UIControls { public interface ICharacterInfoPanelFactory { - IEnumerable CreatePanels(); + IEnumerable CreatePanels(IEnumerable characters); void InjectLoginController(ILoginController loginController); void InjectCharacterManagementController(ICharacterManagementController characterManagementController); }