Skip to content

Commit

Permalink
Implement drag to paperdoll to equip
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 1, 2022
1 parent 14188b3 commit 86a0cf9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
12 changes: 7 additions & 5 deletions EndlessClient/HUD/Panels/HudPanelFactory.cs
Expand Up @@ -2,7 +2,7 @@
using EndlessClient.Content;
using EndlessClient.Controllers;
using EndlessClient.ControlSets;
using EndlessClient.Dialogs.Actions;
using EndlessClient.Dialogs;
using EndlessClient.Dialogs.Factories;
using EndlessClient.HUD.Inventory;
using EndlessClient.Rendering.Chat;
Expand All @@ -12,10 +12,8 @@
using EOLib.Domain.Chat;
using EOLib.Domain.Item;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Graphics;
using EOLib.IO.Repositories;
using Microsoft.Xna.Framework.Graphics;

namespace EndlessClient.HUD.Panels
{
Expand Down Expand Up @@ -43,6 +41,7 @@ public class HudPanelFactory : IHudPanelFactory
private readonly IItemStringService _itemStringService;
private readonly IItemNameColorService _itemNameColorService;
private readonly IInventoryService _inventoryService;
private readonly IActiveDialogProvider _activeDialogProvider;

public HudPanelFactory(INativeGraphicsManager nativeGraphicsManager,
IInventoryController inventoryController,
Expand All @@ -62,7 +61,8 @@ public class HudPanelFactory : IHudPanelFactory
IStatusLabelSetter statusLabelSetter,
IItemStringService itemStringService,
IItemNameColorService itemNameColorService,
IInventoryService inventoryService)
IInventoryService inventoryService,
IActiveDialogProvider activeDialogProvider)
{
_nativeGraphicsManager = nativeGraphicsManager;
_inventoryController = inventoryController;
Expand All @@ -83,6 +83,7 @@ public class HudPanelFactory : IHudPanelFactory
_itemStringService = itemStringService;
_itemNameColorService = itemNameColorService;
_inventoryService = inventoryService;
_activeDialogProvider = activeDialogProvider;
}

public NewsPanel CreateNewsPanel()
Expand All @@ -108,7 +109,8 @@ public InventoryPanel CreateInventoryPanel()
_characterProvider,
_characterInventoryProvider,
_pubFileProvider,
_hudControlProvider) { DrawOrder = HUD_CONTROL_LAYER };
_hudControlProvider,
_activeDialogProvider) { DrawOrder = HUD_CONTROL_LAYER };
}

public ActiveSpellsPanel CreateActiveSpellsPanel()
Expand Down
70 changes: 36 additions & 34 deletions EndlessClient/HUD/Panels/InventoryPanel.cs
@@ -1,5 +1,6 @@
using EndlessClient.Controllers;
using EndlessClient.ControlSets;
using EndlessClient.Dialogs;
using EndlessClient.HUD.Controls;
using EndlessClient.HUD.Inventory;
using EndlessClient.Rendering.Map;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class InventoryPanel : XNAPanel, IHudPanel
private readonly ICharacterInventoryProvider _characterInventoryProvider;
private readonly IPubFileProvider _pubFileProvider; // todo: this can probably become EIFFileProvider
private readonly IHudControlProvider _hudControlProvider;
private readonly IActiveDialogProvider _activeDialogProvider;
private readonly Dictionary<int, int> _itemSlotMap;
private readonly List<InventoryPanelItem> _childItems = new List<InventoryPanelItem>();

Expand All @@ -67,7 +69,8 @@ public class InventoryPanel : XNAPanel, IHudPanel
ICharacterProvider characterProvider,
ICharacterInventoryProvider characterInventoryProvider,
IPubFileProvider pubFileProvider,
IHudControlProvider hudControlProvider)
IHudControlProvider hudControlProvider,
IActiveDialogProvider activeDialogProvider)
{
NativeGraphicsManager = nativeGraphicsManager;
_inventoryController = inventoryController;
Expand All @@ -81,6 +84,7 @@ public class InventoryPanel : XNAPanel, IHudPanel
_characterInventoryProvider = characterInventoryProvider;
_pubFileProvider = pubFileProvider;
_hudControlProvider = hudControlProvider;
_activeDialogProvider = activeDialogProvider;
_weightLabel = new XNALabel(Constants.FontSize08pt5)
{
DrawArea = new Rectangle(385, 37, 88, 18),
Expand Down Expand Up @@ -349,20 +353,40 @@ private void HandleItemDoneDragging(object sender, InventoryPanelItem.ItemDragCo

var oldSlot = item.Slot;

var mapRenderer = _hudControlProvider.GetComponent<IMapRenderer>(HudControlIdentifier.MapRenderer);

// todo: if this is a chained drag, restoring the original slot could overlap with another item
if (_drop.MouseOver || mapRenderer.MouseOver)
if (_activeDialogProvider.ActiveDialogs.All(x => !x.HasValue))
{
e.RestoreOriginalSlot = true;
_inventoryController.DropItem(item.Data, item.InventoryItem);
return;
var mapRenderer = _hudControlProvider.GetComponent<IMapRenderer>(HudControlIdentifier.MapRenderer);
// todo: if this is a chained drag, restoring the original slot could overlap with another item
if (_drop.MouseOver || mapRenderer.MouseOver)
{
e.RestoreOriginalSlot = true;
_inventoryController.DropItem(item.Data, item.InventoryItem);
return;
}
else if (_junk.MouseOver)
{
e.RestoreOriginalSlot = true;
_inventoryController.JunkItem(item.Data, item.InventoryItem);
return;
}
}
else if (_junk.MouseOver)
else
{
e.RestoreOriginalSlot = true;
_inventoryController.JunkItem(item.Data, item.InventoryItem);
return;
var dialogDrop = false;
_activeDialogProvider.PaperdollDialog.MatchSome(x =>
{
if (x.MouseOver && x.MouseOverPreviously && item.Data.GetEquipLocation() != EquipLocation.PAPERDOLL_MAX)
{
dialogDrop = true;
_inventoryController.EquipItem(item.Data);
}
});

if (dialogDrop)
{
e.RestoreOriginalSlot = true;
return;
}
}

var fitsInOldSlot = _inventoryService.FitsInSlot(_inventorySlotRepository.FilledSlots, oldSlot, e.Data.Size);
Expand Down Expand Up @@ -433,28 +457,6 @@ private void HandleItemDoneDragging(object sender, InventoryPanelItem.ItemDragCo
EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
}
}
else if (EOPaperdollDialog.Instance != null && EOPaperdollDialog.Instance.MouseOver && EOPaperdollDialog.Instance.MouseOverPreviously)
{
//equipable items should be equipped
//other item types should do nothing
switch (m_itemData.Type)
{
case ItemType.Accessory:
case ItemType.Armlet:
case ItemType.Armor:
case ItemType.Belt:
case ItemType.Boots:
case ItemType.Bracer:
case ItemType.Gloves:
case ItemType.Hat:
case ItemType.Necklace:
case ItemType.Ring:
case ItemType.Shield:
case ItemType.Weapon:
_handleDoubleClick();
break;
}
}
else if (LockerDialog.Instance != null && LockerDialog.Instance.MouseOver && LockerDialog.Instance.MouseOverPreviously)
{
byte x = LockerDialog.Instance.X;
Expand Down

0 comments on commit 86a0cf9

Please sign in to comment.