Skip to content

Commit

Permalink
Merge pull request #298 from ethanmoffat/resizable_display_3
Browse files Browse the repository at this point in the history
Resizable in-game display. Rework GUI to be responsive to resize operations.
  • Loading branch information
ethanmoffat committed May 4, 2023
2 parents a39029f + 1126967 commit b991303
Show file tree
Hide file tree
Showing 97 changed files with 1,605 additions and 531 deletions.
4 changes: 4 additions & 0 deletions EOLib.Config.Test/ConfigFileLoadActionsTest.cs
Expand Up @@ -82,6 +82,8 @@ public void ValidConfigFile_LoadsSpecifiedSettings()
ShowShadows=no
ShowTransition=true
EnableLogging=true
InGameWidth=123
InGameHeight=321
[CUSTOM]
NPCDropProtectTime=5000
PlayerDropProtectTime=10000
Expand Down Expand Up @@ -115,6 +117,8 @@ public void ValidConfigFile_LoadsSpecifiedSettings()
Assert.IsFalse(_configurationRepository.ShowShadows);
Assert.IsFalse(_configurationRepository.ShowChatBubbles);
Assert.IsTrue(_configurationRepository.ShowTransition);
Assert.AreEqual(123, _configurationRepository.InGameWidth);
Assert.AreEqual(321, _configurationRepository.InGameHeight);

Assert.IsTrue(_configurationRepository.MusicEnabled);
Assert.IsTrue(_configurationRepository.SoundEnabled);
Expand Down
3 changes: 3 additions & 0 deletions EOLib.Config/ConfigFileLoadActions.cs
Expand Up @@ -69,6 +69,9 @@ public void LoadConfigFile()
string host;
_configRepository.Host = configFile.GetValue(ConfigStrings.Connection, ConfigStrings.Host, out host) ? host : ConfigDefaults.Host;
_configRepository.Port = configFile.GetValue(ConfigStrings.Connection, ConfigStrings.Port, out tempInt) ? tempInt : ConfigDefaults.Port;

_configRepository.InGameWidth = configFile.GetValue(ConfigStrings.Settings, ConfigStrings.InGameWidth, out tempInt) ? tempInt : 0;
_configRepository.InGameHeight = configFile.GetValue(ConfigStrings.Settings, ConfigStrings.InGameHeight, out tempInt) ? tempInt : 0;
}
}
}
3 changes: 3 additions & 0 deletions EOLib.Config/ConfigStrings.cs
Expand Up @@ -24,6 +24,9 @@ public static class ConfigStrings
public const string Sound = "Sound";
public const string ShowBaloons = "ShowBaloons";

public const string InGameWidth = nameof(InGameWidth);
public static string InGameHeight = nameof(InGameHeight);

public const string Custom = "CUSTOM";
public const string NPCDropProtectTime = "NPCDropProtectTime";
public const string PlayerDropProtectTime = "PlayerDropProtectTime";
Expand Down
9 changes: 9 additions & 0 deletions EOLib.Config/IConfigurationRepository.cs
Expand Up @@ -33,6 +33,9 @@ public interface IConfigurationRepository
TimeSpan AccountCreateTimeout { get; set; }

bool EnableLog { get; set; }

int InGameWidth { get; set; }
int InGameHeight { get; set; }
}

public interface IConfigurationProvider
Expand Down Expand Up @@ -65,6 +68,9 @@ public interface IConfigurationProvider
TimeSpan AccountCreateTimeout { get; }

bool EnableLog { get; }

int InGameWidth { get; }
int InGameHeight { get; }
}

[AutoMappedType(IsSingleton = true)]
Expand Down Expand Up @@ -98,5 +104,8 @@ public class ConfigurationRepository : IConfigurationRepository, IConfigurationP
public TimeSpan AccountCreateTimeout { get; set; }

public bool EnableLog { get; set; }

public int InGameWidth { get; set; }
public int InGameHeight { get; set; }
}
}
7 changes: 7 additions & 0 deletions EOLib.Graphics/IGraphicsDeviceRepository.cs
@@ -1,22 +1,29 @@
using AutomaticTypeMapper;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace EOLib.Graphics
{
public interface IGraphicsDeviceRepository
{
GraphicsDevice GraphicsDevice { get; set; }

GraphicsDeviceManager GraphicsDeviceManager { get; set; }
}

public interface IGraphicsDeviceProvider
{
GraphicsDevice GraphicsDevice { get; }

GraphicsDeviceManager GraphicsDeviceManager { get; }
}

[MappedType(BaseType = typeof(IGraphicsDeviceRepository), IsSingleton = true)]
[MappedType(BaseType = typeof(IGraphicsDeviceProvider), IsSingleton = true)]
public class GraphicsDeviceRepository : IGraphicsDeviceRepository, IGraphicsDeviceProvider
{
public GraphicsDevice GraphicsDevice { get; set; }

public GraphicsDeviceManager GraphicsDeviceManager { get; set; }
}
}
9 changes: 7 additions & 2 deletions EOLib/Domain/Character/Character.cs
@@ -1,4 +1,5 @@
using Amadevus.RecordGenerator;
using EOLib.Domain.Extensions;
using EOLib.Domain.Spells;

namespace EOLib.Domain.Character
Expand All @@ -18,9 +19,13 @@ public sealed partial class Character : ISpellTargetable

public int Index => ID;

public int X => RenderProperties.MapX;
public int X => RenderProperties.IsActing(CharacterActionState.Walking)
? RenderProperties.GetDestinationX()
: RenderProperties.MapX;

public int Y => RenderProperties.MapY;
public int Y => RenderProperties.IsActing(CharacterActionState.Walking)
? RenderProperties.GetDestinationY()
: RenderProperties.MapY;

public string Name { get; }

Expand Down
6 changes: 3 additions & 3 deletions EOLib/Domain/Character/CharacterSessionRepository.cs
Expand Up @@ -11,7 +11,7 @@ public interface ICharacterSessionRepository : IResettable

int LastKillExp { get; set; }

int TodayTotalExp { get; set; }
ulong TodayTotalExp { get; set; }
}

public interface ICharacterSessionProvider : IResettable
Expand All @@ -22,7 +22,7 @@ public interface ICharacterSessionProvider : IResettable

int LastKillExp { get; }

int TodayTotalExp { get; }
ulong TodayTotalExp { get; }
}

[AutoMappedType(IsSingleton = true)]
Expand All @@ -34,7 +34,7 @@ public class CharacterSessionRepository : ICharacterSessionRepository, ICharacte

public int LastKillExp { get; set; }

public int TodayTotalExp { get; set; }
public ulong TodayTotalExp { get; set; }

public CharacterSessionRepository()
{
Expand Down
2 changes: 1 addition & 1 deletion EOLib/PacketHandlers/NPC/NPCSpecHandler.cs
Expand Up @@ -92,7 +92,7 @@ public override bool HandlePacket(IPacket packet)
_characterSessionRepository.LastKillExp = expDifference;
if (expDifference > _characterSessionRepository.BestKillExp)
_characterSessionRepository.BestKillExp = expDifference;
_characterSessionRepository.TodayTotalExp += expDifference;
_characterSessionRepository.TodayTotalExp += Convert.ToUInt64(Math.Max(expDifference, 0));
}

if (droppedItemID > 0)
Expand Down
1 change: 1 addition & 0 deletions EOLib/misc.cs
Expand Up @@ -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/layout.ini";
public const string ChatLogFile = "chatlog.txt";

//Should be easily customizable between different clients (based on graphics)
Expand Down
Binary file modified EndlessClient/ContentPipeline/HairClip.mgfx
Binary file not shown.
14 changes: 11 additions & 3 deletions EndlessClient/ControlSets/BackButtonControlSet.cs
@@ -1,6 +1,7 @@
using System;
using EndlessClient.Content;
using EndlessClient.Controllers;
using EndlessClient.Rendering;
using EOLib.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
Expand All @@ -11,14 +12,16 @@ namespace EndlessClient.ControlSets
public abstract class BackButtonControlSet : BaseControlSet
{
protected readonly IMainButtonController _mainButtonController;

private readonly IClientWindowSizeRepository _clientWindowSizeRepository;
private Texture2D _backButtonTexture;

private XNAButton _backButton;

protected BackButtonControlSet(IMainButtonController mainButtonController)
protected BackButtonControlSet(IMainButtonController mainButtonController,
IClientWindowSizeRepository clientWindowSizeRepository)
{
_mainButtonController = mainButtonController;
_clientWindowSizeRepository = clientWindowSizeRepository;
}

public override void InitializeResources(INativeGraphicsManager gfxManager, IContentProvider contentProvider)
Expand All @@ -39,7 +42,7 @@ private XNAButton GetBackButton()
{
var button = new XNAButton(
_backButtonTexture,
new Vector2(589, 0),
new Vector2(_clientWindowSizeRepository.Width - _backButtonTexture.Width, 0),
new Rectangle(0, 0, _backButtonTexture.Width, _backButtonTexture.Height / 2),
new Rectangle(0, _backButtonTexture.Height / 2, _backButtonTexture.Width, _backButtonTexture.Height / 2))
{
Expand All @@ -49,6 +52,11 @@ private XNAButton GetBackButton()
};
button.OnClick += DoBackButtonClick;

_clientWindowSizeRepository.GameWindowSizeChanged += (o, e) =>
{
button.DrawPosition = new Vector2(_clientWindowSizeRepository.Width - _backButtonTexture.Width, 0);
};

return button;
}

Expand Down
15 changes: 10 additions & 5 deletions EndlessClient/ControlSets/ControlSetFactory.cs
@@ -1,5 +1,4 @@
using System;
using AutomaticTypeMapper;
using AutomaticTypeMapper;
using EndlessClient.Content;
using EndlessClient.Controllers;
using EndlessClient.Dialogs;
Expand All @@ -12,6 +11,7 @@
using EOLib.Config;
using EOLib.Domain.Login;
using EOLib.Graphics;
using System;

namespace EndlessClient.ControlSets
{
Expand All @@ -28,7 +28,9 @@ public class ControlSetFactory : IControlSetFactory
private readonly IEndlessGameProvider _endlessGameProvider;
private readonly IUserInputRepository _userInputRepository;
private readonly IActiveDialogRepository _activeDialogRepository;
private readonly IClientWindowSizeRepository _clientWindowSizeRepository;
private readonly IFixedTimeStepRepository _fixedTimeStepRepository;

private IMainButtonController _mainButtonController;
private IAccountController _accountController;
private ILoginController _loginController;
Expand All @@ -44,6 +46,7 @@ public class ControlSetFactory : IControlSetFactory
IEndlessGameProvider endlessGameProvider,
IUserInputRepository userInputRepository,
IActiveDialogRepository activeDialogRepository,
IClientWindowSizeRepository clientWindowSizeRepository,
IFixedTimeStepRepository fixedTimeStepRepository)
{
_nativeGraphicsManager = nativeGraphicsManager;
Expand All @@ -56,6 +59,7 @@ public class ControlSetFactory : IControlSetFactory
_endlessGameProvider = endlessGameProvider;
_userInputRepository = userInputRepository;
_activeDialogRepository = activeDialogRepository;
_clientWindowSizeRepository = clientWindowSizeRepository;
_fixedTimeStepRepository = fixedTimeStepRepository;
}

Expand Down Expand Up @@ -88,7 +92,7 @@ private IControlSet GetSetBasedOnState(GameStates newState)
{
case GameStates.Initial: return new InitialControlSet(_configProvider, _mainButtonController);
case GameStates.CreateAccount:
return new CreateAccountControlSet(_mainButtonController, _accountController);
return new CreateAccountControlSet(_mainButtonController, _accountController, _clientWindowSizeRepository);
case GameStates.Login:
return new LoginPromptControlSet(_configProvider, _mainButtonController, _loginController);
case GameStates.ViewCredits: return new ViewCreditsControlSet(_configProvider, _mainButtonController);
Expand All @@ -101,9 +105,10 @@ private IControlSet GetSetBasedOnState(GameStates newState)
_accountController,
_endlessGameProvider,
_userInputRepository,
_fixedTimeStepRepository);
_fixedTimeStepRepository,
_clientWindowSizeRepository);
case GameStates.PlayingTheGame:
return new InGameControlSet(_mainButtonController, _messageBoxFactory, _hudControlsFactory, _activeDialogRepository);
return new InGameControlSet(_mainButtonController, _messageBoxFactory, _hudControlsFactory, _activeDialogRepository, _clientWindowSizeRepository);
default: throw new ArgumentOutOfRangeException(nameof(newState), newState, null);
}
}
Expand Down
7 changes: 5 additions & 2 deletions EndlessClient/ControlSets/CreateAccountControlSet.cs
@@ -1,6 +1,8 @@
using EndlessClient.Content;
using EndlessClient.Controllers;
using EndlessClient.GameExecution;
using EndlessClient.Input;
using EndlessClient.Rendering;
using EOLib;
using EOLib.Domain.Account;
using EOLib.Graphics;
Expand Down Expand Up @@ -33,8 +35,9 @@ public class CreateAccountControlSet : IntermediateControlSet
public override GameStates GameState => GameStates.CreateAccount;

public CreateAccountControlSet(IMainButtonController mainButtonController,
IAccountController accountController)
: base(mainButtonController)
IAccountController accountController,
IClientWindowSizeRepository clientWindowSizeRepository)
: base(mainButtonController, clientWindowSizeRepository)
{
_accountController = accountController;
}
Expand Down
6 changes: 3 additions & 3 deletions EndlessClient/ControlSets/IHudControlProvider.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using AutomaticTypeMapper;
using AutomaticTypeMapper;
using EndlessClient.GameExecution;
using EndlessClient.HUD.Controls;
using EndlessClient.HUD.Panels;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;

namespace EndlessClient.ControlSets
{
Expand Down
14 changes: 8 additions & 6 deletions EndlessClient/ControlSets/InGameControlSet.cs
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EndlessClient.Controllers;
using EndlessClient.Controllers;
using EndlessClient.Dialogs;
using EndlessClient.Dialogs.Factories;
using EndlessClient.GameExecution;
using EndlessClient.HUD.Controls;
using EndlessClient.Rendering;
using EOLib.Localization;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using XNAControls;

namespace EndlessClient.ControlSets
Expand All @@ -24,8 +25,9 @@ public class InGameControlSet : BackButtonControlSet
public InGameControlSet(IMainButtonController mainButtonController,
IEOMessageBoxFactory messageBoxFactory,
IHudControlsFactory hudControlsFactory,
IActiveDialogRepository activeDialogRepository)
: base(mainButtonController)
IActiveDialogRepository activeDialogRepository,
IClientWindowSizeRepository clientWindowSizeRepository)
: base(mainButtonController, clientWindowSizeRepository)
{
_messageBoxFactory = messageBoxFactory;
_hudControlsFactory = hudControlsFactory;
Expand Down
6 changes: 4 additions & 2 deletions EndlessClient/ControlSets/IntermediateControlSet.cs
Expand Up @@ -2,6 +2,7 @@
using EndlessClient.Content;
using EndlessClient.Controllers;
using EndlessClient.GameExecution;
using EndlessClient.Rendering;
using EOLib.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
Expand All @@ -17,8 +18,9 @@ public abstract class IntermediateControlSet : BackButtonControlSet
private IXNAButton _btnCreate;
private IXNAPictureBox _person2Picture;

protected IntermediateControlSet(IMainButtonController mainButtonController)
: base(mainButtonController)
protected IntermediateControlSet(IMainButtonController mainButtonController,
IClientWindowSizeRepository clientWindowSizeRepository)
: base(mainButtonController, clientWindowSizeRepository)
{
_personSet2 = new Texture2D[8];
_randomGen = new Random();
Expand Down
5 changes: 3 additions & 2 deletions EndlessClient/ControlSets/LoggedInControlSet.cs
Expand Up @@ -36,8 +36,9 @@ public class LoggedInControlSet : IntermediateControlSet
IAccountController accountController,
IEndlessGameProvider endlessGameProvider,
IUserInputRepository userInputRepository,
IFixedTimeStepRepository fixedTimeStepRepository)
: base(mainButtonController)
IFixedTimeStepRepository fixedTimeStepRepository,
IClientWindowSizeRepository clientWindowSizeRepository)
: base(mainButtonController, clientWindowSizeRepository)
{
_characterInfoPanelFactory = characterInfoPanelFactory;
_characterSelectorProvider = characterSelectorProvider;
Expand Down
4 changes: 3 additions & 1 deletion EndlessClient/Controllers/InventoryController.cs
Expand Up @@ -5,6 +5,7 @@
using EndlessClient.Dialogs.Factories;
using EndlessClient.HUD;
using EndlessClient.HUD.Controls;
using EndlessClient.HUD.Panels;
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.Map;
using EOLib;
Expand Down Expand Up @@ -199,11 +200,12 @@ public void UnequipItem(EquipLocation equipLocation)
public void DropItem(EIFRecord itemData, InventoryItem inventoryItem)
{
var mapRenderer = _hudControlProvider.GetComponent<IMapRenderer>(HudControlIdentifier.MapRenderer);
var inventoryPanel = _hudControlProvider.GetComponent<InventoryPanel>(HudControlIdentifier.InventoryPanel);
if (_activeDialogProvider.ActiveDialogs.Any(x => x.HasValue) && mapRenderer.MouseOver)
return;

var rp = _characterProvider.MainCharacter.RenderProperties;
var dropPoint = mapRenderer.MouseOver
var dropPoint = mapRenderer.MouseOver && !inventoryPanel.MouseOver
? mapRenderer.GridCoordinates
: new MapCoordinate(rp.MapX, rp.MapY);

Expand Down

0 comments on commit b991303

Please sign in to comment.