Skip to content

Commit

Permalink
Ensure panels have no drag+drop functionality if not in resizable mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 30, 2023
1 parent 7d149c4 commit 687baa9
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 25 deletions.
9 changes: 8 additions & 1 deletion EndlessClient/HUD/HudStateActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AutomaticTypeMapper;
using EndlessClient.ControlSets;
using EndlessClient.HUD.Panels;
using EndlessClient.Rendering;
using EOLib.Domain.Map;
using EOLib.IO.Repositories;
using EOLib.Localization;
Expand All @@ -18,16 +19,19 @@ public class HudStateActions : IHudStateActions
private readonly IHudControlProvider _hudControlProvider;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IMapFileProvider _mapFileProvider;
private readonly IClientWindowSizeProvider _clientWindowSizeProvider;

public HudStateActions(IStatusLabelSetter statusLabelSetter,
IHudControlProvider hudControlProvider,
ICurrentMapStateRepository currentMapStateRepository,
IMapFileProvider mapFileProvider)
IMapFileProvider mapFileProvider,
IClientWindowSizeProvider clientWindowSizeProvider)
{
_statusLabelSetter = statusLabelSetter;
_hudControlProvider = hudControlProvider;
_currentMapStateRepository = currentMapStateRepository;
_mapFileProvider = mapFileProvider;
_clientWindowSizeProvider = clientWindowSizeProvider;
}

public void SwitchToState(InGameStates newState)
Expand All @@ -38,6 +42,9 @@ public void SwitchToState(InGameStates newState)
if (newState != InGameStates.News)
_hudControlProvider.GetComponent<IHudPanel>(Controls.HudControlIdentifier.NewsPanel).Visible = false;

foreach (var panel in _hudControlProvider.HudPanels.Where(x => x.Visible))
panel.Visible = _clientWindowSizeProvider.Resizable;

var targetPanel = _hudControlProvider.HudPanels.Single(x => IsPanelForRequestedState(x, newState));
targetPanel.Visible = !targetPanel.Visible;

Expand Down
5 changes: 4 additions & 1 deletion EndlessClient/HUD/Panels/ActiveSpellsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using EndlessClient.Dialogs.Factories;
using EndlessClient.HUD.Controls;
using EndlessClient.HUD.Spells;
using EndlessClient.Rendering;
using EndlessClient.UIControls;
using EOLib;
using EOLib.Config;
Expand Down Expand Up @@ -81,7 +82,9 @@ public ActiveSpellsPanel(INativeGraphicsManager nativeGraphicsManager,
ISpellSlotDataRepository spellSlotDataRepository,
IHudControlProvider hudControlProvider,
ISfxPlayer sfxPlayer,
IConfigurationProvider configProvider)
IConfigurationProvider configProvider,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
NativeGraphicsManager = nativeGraphicsManager;
_trainingController = trainingController;
Expand Down
5 changes: 4 additions & 1 deletion EndlessClient/HUD/Panels/ChatPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using EndlessClient.ControlSets;
using EndlessClient.HUD.Chat;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Chat;
using EndlessClient.Rendering.Sprites;
using EndlessClient.UIControls;
Expand Down Expand Up @@ -32,7 +33,9 @@ public ChatPanel(INativeGraphicsManager nativeGraphicsManager,
IChatRenderableGenerator chatRenderableGenerator,
IChatProvider chatProvider,
IHudControlProvider hudControlProvider,
BitmapFont chatFont)
BitmapFont chatFont,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
_nativeGraphicsManager = nativeGraphicsManager;
_chatActions = chatActions;
Expand Down
18 changes: 17 additions & 1 deletion EndlessClient/HUD/Panels/DraggableHudPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MonoGame.Extended.Input.InputListeners;
using EndlessClient.Rendering;
using MonoGame.Extended.Input.InputListeners;
using Optional;
using System;
using XNAControls;
Expand All @@ -11,9 +12,15 @@ public class DraggableHudPanel : XNAPanel, IHudPanel
public event Action DragCompleted;

private static Option<DraggableHudPanel> _dragging;
private bool _enableDragging;

public bool IsBeingDragged => _dragging.HasValue;

public DraggableHudPanel(bool enableDragging)
{
_enableDragging = enableDragging;
}

protected override bool HandleClick(IXNAControl control, MouseEventArgs eventArgs)
{
Activated?.Invoke();
Expand All @@ -22,12 +29,18 @@ protected override bool HandleClick(IXNAControl control, MouseEventArgs eventArg

protected override bool HandleDragStart(IXNAControl control, MouseEventArgs eventArgs)
{
if (!_enableDragging)
return false;

Activated?.Invoke();
return true;
}

protected override bool HandleDrag(IXNAControl control, MouseEventArgs eventArgs)
{
if (!_enableDragging)
return false;

_dragging
.FlatMap(p => p.NoneWhen(q => p == this))
.MatchNone(() =>
Expand All @@ -41,6 +54,9 @@ protected override bool HandleDrag(IXNAControl control, MouseEventArgs eventArgs

protected override bool HandleDragEnd(IXNAControl control, MouseEventArgs eventArgs)
{
if (!_enableDragging)
return false;

_dragging = Option.None<DraggableHudPanel>();
DragCompleted?.Invoke();

Expand Down
7 changes: 5 additions & 2 deletions EndlessClient/HUD/Panels/HelpPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EOLib.Graphics;
using EndlessClient.Rendering;
using EOLib.Graphics;
using Microsoft.Xna.Framework;
using XNAControls;

Expand All @@ -8,7 +9,9 @@ public class HelpPanel : DraggableHudPanel
{
private readonly INativeGraphicsManager _nativeGraphicsManager;

public HelpPanel(INativeGraphicsManager nativeGraphicsManager)
public HelpPanel(INativeGraphicsManager nativeGraphicsManager,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
_nativeGraphicsManager = nativeGraphicsManager;

Expand Down
32 changes: 21 additions & 11 deletions EndlessClient/HUD/Panels/HudPanelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EndlessClient.Dialogs.Factories;
using EndlessClient.HUD.Inventory;
using EndlessClient.HUD.Spells;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Chat;
using EndlessClient.Services;
using EOLib;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class HudPanelFactory : IHudPanelFactory
private readonly IPartyActions _partyActions;
private readonly IPartyDataProvider _partyDataProvider;
private readonly IConfigurationProvider _configurationProvider;
private readonly IClientWindowSizeProvider _clientWindowSizeProvider;

public HudPanelFactory(INativeGraphicsManager nativeGraphicsManager,
IInventoryController inventoryController,
Expand Down Expand Up @@ -88,7 +90,8 @@ public HudPanelFactory(INativeGraphicsManager nativeGraphicsManager,
ISfxPlayer sfxPlayer,
IPartyActions partyActions,
IPartyDataProvider partyDataProvider,
IConfigurationProvider configurationProvider)
IConfigurationProvider configurationProvider,
IClientWindowSizeProvider clientWindowSizeProvider)
{
_nativeGraphicsManager = nativeGraphicsManager;
_inventoryController = inventoryController;
Expand Down Expand Up @@ -120,6 +123,7 @@ public HudPanelFactory(INativeGraphicsManager nativeGraphicsManager,
_partyActions = partyActions;
_partyDataProvider = partyDataProvider;
_configurationProvider = configurationProvider;
_clientWindowSizeProvider = clientWindowSizeProvider;
}

public NewsPanel CreateNewsPanel()
Expand All @@ -129,7 +133,8 @@ public NewsPanel CreateNewsPanel()
return new NewsPanel(_nativeGraphicsManager,
new ChatRenderableGenerator(_nativeGraphicsManager, _friendIgnoreListService, chatFont),
_newsProvider,
chatFont) { DrawOrder = HUD_CONTROL_LAYER };
chatFont,
_clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public InventoryPanel CreateInventoryPanel()
Expand All @@ -148,7 +153,8 @@ public InventoryPanel CreateInventoryPanel()
_hudControlProvider,
_activeDialogProvider,
_sfxPlayer,
_configurationProvider) { DrawOrder = HUD_CONTROL_LAYER };
_configurationProvider,
_clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public ActiveSpellsPanel CreateActiveSpellsPanel()
Expand All @@ -164,12 +170,13 @@ public ActiveSpellsPanel CreateActiveSpellsPanel()
_spellSlotDataRepository,
_hudControlProvider,
_sfxPlayer,
_configurationProvider) { DrawOrder = HUD_CONTROL_LAYER };
_configurationProvider,
_clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public PassiveSpellsPanel CreatePassiveSpellsPanel()
{
return new PassiveSpellsPanel(_nativeGraphicsManager) { DrawOrder = HUD_CONTROL_LAYER };
return new PassiveSpellsPanel(_nativeGraphicsManager, _clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public ChatPanel CreateChatPanel()
Expand All @@ -181,7 +188,8 @@ public ChatPanel CreateChatPanel()
new ChatRenderableGenerator(_nativeGraphicsManager, _friendIgnoreListService, chatFont),
_chatProvider,
_hudControlProvider,
chatFont) { DrawOrder = HUD_CONTROL_LAYER };
chatFont,
_clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public StatsPanel CreateStatsPanel()
Expand All @@ -191,18 +199,19 @@ public StatsPanel CreateStatsPanel()
_characterInventoryProvider,
_experienceTableProvider,
_messageBoxFactory,
_trainingController) { DrawOrder = HUD_CONTROL_LAYER };
_trainingController,
_clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public OnlineListPanel CreateOnlineListPanel()
{
var chatFont = _contentProvider.Fonts[Constants.FontSize08];
return new OnlineListPanel(_nativeGraphicsManager, _hudControlProvider, _onlinePlayerProvider, _partyDataProvider, _friendIgnoreListService, _sfxPlayer, chatFont) { DrawOrder = HUD_CONTROL_LAYER };
return new OnlineListPanel(_nativeGraphicsManager, _hudControlProvider, _onlinePlayerProvider, _partyDataProvider, _friendIgnoreListService, _sfxPlayer, chatFont, _clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public PartyPanel CreatePartyPanel()
{
return new PartyPanel(_nativeGraphicsManager, _partyActions, _contentProvider, _partyDataProvider, _characterProvider) { DrawOrder = HUD_CONTROL_LAYER };
return new PartyPanel(_nativeGraphicsManager, _partyActions, _contentProvider, _partyDataProvider, _characterProvider, _clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public SettingsPanel CreateSettingsPanel()
Expand All @@ -214,12 +223,13 @@ public SettingsPanel CreateSettingsPanel()
_localizedStringFinder,
_messageBoxFactory,
_configurationRepository,
_sfxPlayer) { DrawOrder = HUD_CONTROL_LAYER };
_sfxPlayer,
_clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public HelpPanel CreateHelpPanel()
{
return new HelpPanel(_nativeGraphicsManager) { DrawOrder = HUD_CONTROL_LAYER };
return new HelpPanel(_nativeGraphicsManager, _clientWindowSizeProvider) { DrawOrder = HUD_CONTROL_LAYER };
}
}
}
5 changes: 4 additions & 1 deletion EndlessClient/HUD/Panels/InventoryPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using EndlessClient.Dialogs;
using EndlessClient.HUD.Controls;
using EndlessClient.HUD.Inventory;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Map;
using EOLib;
using EOLib.Config;
Expand Down Expand Up @@ -78,7 +79,9 @@ public InventoryPanel(INativeGraphicsManager nativeGraphicsManager,
IHudControlProvider hudControlProvider,
IActiveDialogProvider activeDialogProvider,
ISfxPlayer sfxPlayer,
IConfigurationProvider configProvider)
IConfigurationProvider configProvider,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
NativeGraphicsManager = nativeGraphicsManager;
_inventoryController = inventoryController;
Expand Down
5 changes: 4 additions & 1 deletion EndlessClient/HUD/Panels/NewsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System.Linq;
using EndlessClient.Rendering;

namespace EndlessClient.HUD.Panels
{
Expand All @@ -30,7 +31,9 @@ public class NewsPanel : DraggableHudPanel
public NewsPanel(INativeGraphicsManager nativeGraphicsManager,
IChatRenderableGenerator chatRenderableGenerator,
INewsProvider newsProvider,
BitmapFont chatFont)
BitmapFont chatFont,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
_nativeGraphicsManager = nativeGraphicsManager;
_chatRenderableGenerator = chatRenderableGenerator;
Expand Down
5 changes: 4 additions & 1 deletion EndlessClient/HUD/Panels/OnlineListPanel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EndlessClient.Audio;
using EndlessClient.ControlSets;
using EndlessClient.HUD.Controls;
using EndlessClient.Rendering;
using EndlessClient.Services;
using EndlessClient.UIControls;
using EOLib;
Expand Down Expand Up @@ -64,7 +65,9 @@ public OnlineListPanel(INativeGraphicsManager nativeGraphicsManager,
IPartyDataProvider partyDataProvider,
IFriendIgnoreListService friendIgnoreListService,
ISfxPlayer sfxPlayer,
BitmapFont chatFont)
BitmapFont chatFont,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
_nativeGraphicsManager = nativeGraphicsManager;
_hudControlProvider = hudControlProvider;
Expand Down
5 changes: 4 additions & 1 deletion EndlessClient/HUD/Panels/PartyPanel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using EndlessClient.Content;
using EndlessClient.HUD.Party;
using EndlessClient.Rendering;
using EndlessClient.UIControls;
using EOLib;
using EOLib.Domain.Character;
Expand Down Expand Up @@ -32,7 +33,9 @@ public PartyPanel(INativeGraphicsManager nativeGraphicsManager,
IPartyActions partyActions,
IContentProvider contentProvider,
IPartyDataProvider partyDataProvider,
ICharacterProvider characterProvider)
ICharacterProvider characterProvider,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
_nativeGraphicsManager = nativeGraphicsManager;
_partyActions = partyActions;
Expand Down
7 changes: 5 additions & 2 deletions EndlessClient/HUD/Panels/PassiveSpellsPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EOLib.Graphics;
using EndlessClient.Rendering;
using EOLib.Graphics;
using Microsoft.Xna.Framework;

namespace EndlessClient.HUD.Panels
Expand All @@ -7,7 +8,9 @@ public class PassiveSpellsPanel : DraggableHudPanel
{
private readonly INativeGraphicsManager _nativeGraphicsManager;

public PassiveSpellsPanel(INativeGraphicsManager nativeGraphicsManager)
public PassiveSpellsPanel(INativeGraphicsManager nativeGraphicsManager,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
_nativeGraphicsManager = nativeGraphicsManager;

Expand Down
5 changes: 4 additions & 1 deletion EndlessClient/HUD/Panels/SettingsPanel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EndlessClient.Audio;
using EndlessClient.Dialogs;
using EndlessClient.Dialogs.Factories;
using EndlessClient.Rendering;
using EOLib;
using EOLib.Config;
using EOLib.Domain.Chat;
Expand Down Expand Up @@ -60,7 +61,9 @@ public SettingsPanel(INativeGraphicsManager nativeGraphicsManager,
ILocalizedStringFinder localizedStringFinder,
IEOMessageBoxFactory messageBoxFactory,
IConfigurationRepository configurationRepository,
ISfxPlayer sfxPlayer)
ISfxPlayer sfxPlayer,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
_nativeGraphicsManager = nativeGraphicsManager;
_chatActions = chatActions;
Expand Down
5 changes: 4 additions & 1 deletion EndlessClient/HUD/Panels/StatsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EndlessClient.Controllers;
using EndlessClient.Dialogs;
using EndlessClient.Dialogs.Factories;
using EndlessClient.Rendering;
using EOLib;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
Expand Down Expand Up @@ -42,7 +43,9 @@ public StatsPanel(INativeGraphicsManager nativeGraphicsManager,
ICharacterInventoryProvider characterInventoryProvider,
IExperienceTableProvider experienceTableProvider,
IEOMessageBoxFactory messageBoxFactory,
ITrainingController trainingController)
ITrainingController trainingController,
IClientWindowSizeProvider clientWindowSizeProvider)
: base(clientWindowSizeProvider.Resizable)
{
_characterProvider = characterProvider;
_characterInventoryProvider = characterInventoryProvider;
Expand Down

0 comments on commit 687baa9

Please sign in to comment.