mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-02 06:36:28 -05:00
parent
4a77e47ddd
commit
a3208e26f2
15
OpenDiablo2.Common/Enums/eItemContainerType.cs
Normal file
15
OpenDiablo2.Common/Enums/eItemContainerType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace OpenDiablo2.Common.Enums
|
||||
{
|
||||
public enum eItemContainerType
|
||||
{
|
||||
Helm,
|
||||
Glove,
|
||||
Armor,
|
||||
Belt,
|
||||
Boots,
|
||||
Weapon,
|
||||
Amulet,
|
||||
Ring,
|
||||
Generic
|
||||
}
|
||||
}
|
10
OpenDiablo2.Common/Interfaces/ICharacterPanel.cs
Normal file
10
OpenDiablo2.Common/Interfaces/ICharacterPanel.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface ICharacterPanel : IDisposable
|
||||
{
|
||||
void Render();
|
||||
void Update();
|
||||
}
|
||||
}
|
@ -8,5 +8,6 @@ namespace OpenDiablo2.Common.Interfaces
|
||||
List<LevelPreset> LevelPresets { get; }
|
||||
List<LevelType> LevelTypes { get; }
|
||||
List<LevelDetail> LevelDetails { get; }
|
||||
List<Item> Items { get; }
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ namespace OpenDiablo2.Common.Interfaces
|
||||
bool ToggleShowCharacterPanel();
|
||||
bool ShowCharacterPanel { get; set; }
|
||||
|
||||
Item SelectedItem { get; }
|
||||
void SelectItem(Item item);
|
||||
|
||||
void Initialize(string text, eHero value, eSessionType sessionType);
|
||||
void Update(long ms);
|
||||
IEnumerable<MapCellInfo> GetMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType);
|
||||
|
10
OpenDiablo2.Common/Interfaces/IInventoryPanel.cs
Normal file
10
OpenDiablo2.Common/Interfaces/IInventoryPanel.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface IInventoryPanel : IDisposable
|
||||
{
|
||||
void Render();
|
||||
void Update();
|
||||
}
|
||||
}
|
10
OpenDiablo2.Common/Interfaces/IItem.cs
Normal file
10
OpenDiablo2.Common/Interfaces/IItem.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface IItem
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Code { get; set; }
|
||||
}
|
||||
}
|
10
OpenDiablo2.Common/Interfaces/IItemManager.cs
Normal file
10
OpenDiablo2.Common/Interfaces/IItemManager.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenDiablo2.Common.Models;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface IItemManager
|
||||
{
|
||||
Item getItem(string code);
|
||||
}
|
||||
}
|
11
OpenDiablo2.Common/Interfaces/IPanelFrame.cs
Normal file
11
OpenDiablo2.Common/Interfaces/IPanelFrame.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using System;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface IPanelFrame : IDisposable
|
||||
{
|
||||
void Render();
|
||||
void Update();
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
int MouseX { get; }
|
||||
int MouseY { get; }
|
||||
bool LeftMouseDown { get; }
|
||||
bool LeftMousePressed { get; }
|
||||
bool RightMouseDown { get; }
|
||||
bool ReserveMouse { get; set; }
|
||||
}
|
||||
|
16
OpenDiablo2.Common/Interfaces/UI/IItemContainer.cs
Normal file
16
OpenDiablo2.Common/Interfaces/UI/IItemContainer.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using OpenDiablo2.Common.Models;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface IItemContainer : IDisposable
|
||||
{
|
||||
Item ContainedItem { get; }
|
||||
Point Location { get; set; }
|
||||
|
||||
void SetContainedItem(Item containedItem);
|
||||
void Render();
|
||||
void Update();
|
||||
}
|
||||
}
|
25
OpenDiablo2.Common/Models/Item/Armor.cs
Normal file
25
OpenDiablo2.Common/Models/Item/Armor.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Models
|
||||
{
|
||||
public sealed class Armor : Item
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static class ArmorHelper
|
||||
{
|
||||
public static Armor ToArmor(this string[] row)
|
||||
=> new Armor
|
||||
{
|
||||
Name = row[0],
|
||||
Code = row[17],
|
||||
InvFile = row[33]
|
||||
};
|
||||
}
|
||||
}
|
19
OpenDiablo2.Common/Models/Item/Item.cs
Normal file
19
OpenDiablo2.Common/Models/Item/Item.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Models
|
||||
{
|
||||
/**
|
||||
* Base Item class, contains common attributes for all item types.
|
||||
**/
|
||||
public abstract class Item
|
||||
{
|
||||
public string Code { get; internal set; } // Internal code
|
||||
public string Name { get; internal set; } // Item name
|
||||
public string InvFile { get; internal set; } // Sprite used for the inventory and mouse cursor
|
||||
}
|
||||
}
|
25
OpenDiablo2.Common/Models/Item/Misc.cs
Normal file
25
OpenDiablo2.Common/Models/Item/Misc.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Models
|
||||
{
|
||||
public sealed class Misc : Item
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static class MiscHelper
|
||||
{
|
||||
public static Misc ToMisc(this string[] row)
|
||||
=> new Misc
|
||||
{
|
||||
Name = row[0],
|
||||
Code = row[12],
|
||||
InvFile = row[21]
|
||||
};
|
||||
}
|
||||
}
|
25
OpenDiablo2.Common/Models/Item/Weapon.cs
Normal file
25
OpenDiablo2.Common/Models/Item/Weapon.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Models
|
||||
{
|
||||
public sealed class Weapon : Item
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static class WeaponHelper
|
||||
{
|
||||
public static Weapon ToWeapon(this string[] row)
|
||||
=> new Weapon
|
||||
{
|
||||
Name = row[0],
|
||||
Code = row[2],
|
||||
InvFile = row[45]
|
||||
};
|
||||
}
|
||||
}
|
29
OpenDiablo2.Common/Models/ItemContainerLayout.cs
Normal file
29
OpenDiablo2.Common/Models/ItemContainerLayout.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
|
||||
namespace OpenDiablo2.Common.Models
|
||||
{
|
||||
public class ItemContainerLayout
|
||||
{
|
||||
public string ResourceName { get; internal set; }
|
||||
public string PaletteName { get; internal set; } = Palettes.Units;
|
||||
public int BaseFrame { get; internal set; } = 0;
|
||||
|
||||
public static Dictionary<eItemContainerType, ItemContainerLayout> Values = new Dictionary<eItemContainerType, ItemContainerLayout>
|
||||
{
|
||||
{eItemContainerType.Helm, new ItemContainerLayout { ResourceName = ResourcePaths.HelmGlovePlaceholder, BaseFrame = 1 } },
|
||||
{eItemContainerType.Amulet, new ItemContainerLayout{ ResourceName = ResourcePaths.RingAmuletPlaceholder } },
|
||||
{eItemContainerType.Armor, new ItemContainerLayout { ResourceName = ResourcePaths.ArmorPlaceholder } },
|
||||
{eItemContainerType.Weapon, new ItemContainerLayout { ResourceName = ResourcePaths.WeaponsPlaceholder } },
|
||||
{eItemContainerType.Belt, new ItemContainerLayout { ResourceName = ResourcePaths.BeltPlaceholder } },
|
||||
{eItemContainerType.Ring, new ItemContainerLayout { ResourceName = ResourcePaths.RingAmuletPlaceholder, BaseFrame = 1 } },
|
||||
{eItemContainerType.Glove, new ItemContainerLayout { ResourceName = ResourcePaths.HelmGlovePlaceholder } },
|
||||
{eItemContainerType.Boots, new ItemContainerLayout { ResourceName = ResourcePaths.BootsPlaceholder } },
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -55,6 +55,7 @@
|
||||
<Compile Include="Attributes\MessageFrameAttribute.cs" />
|
||||
<Compile Include="Attributes\SceneAttribute.cs" />
|
||||
<Compile Include="AutofacModule.cs" />
|
||||
<Compile Include="Enums\eItemContainerType.cs" />
|
||||
<Compile Include="Enums\eMessageFrameType.cs" />
|
||||
<Compile Include="Enums\eMovementType.cs" />
|
||||
<Compile Include="Enums\ePanelFrameType.cs" />
|
||||
@ -70,15 +71,18 @@
|
||||
<Compile Include="Enums\Mobs\eDamageTypes.cs" />
|
||||
<Compile Include="Enums\Mobs\eMobFlags.cs" />
|
||||
<Compile Include="Enums\Mobs\eStatModifierType.cs" />
|
||||
<Compile Include="Interfaces\IItemManager.cs" />
|
||||
<Compile Include="Extensions\MobManagerExtensions.cs" />
|
||||
<Compile Include="Interfaces\IGameServer.cs" />
|
||||
<Compile Include="Interfaces\MessageBus\ISessionEventProvider.cs" />
|
||||
<Compile Include="Interfaces\MessageBus\IMessageFrame.cs" />
|
||||
<Compile Include="Interfaces\MessageBus\ISessionManager.cs" />
|
||||
<Compile Include="Interfaces\MessageBus\ISessionServer.cs" />
|
||||
<Compile Include="Models\ItemContainerLayout.cs" />
|
||||
<Compile Include="Models\PlayerInfo.cs" />
|
||||
<Compile Include="Models\PlayerLocationDetails.cs" />
|
||||
<Compile Include="Interfaces\UI\IButton.cs" />
|
||||
<Compile Include="Interfaces\UI\IItemContainer.cs" />
|
||||
<Compile Include="Interfaces\UI\IPanelFrame.cs" />
|
||||
<Compile Include="Interfaces\UI\IInventoryPanel.cs" />
|
||||
<Compile Include="Interfaces\IEngineDataManager.cs" />
|
||||
@ -111,6 +115,10 @@
|
||||
<Compile Include="Models\BitStream.cs" />
|
||||
<Compile Include="Models\ButtonLayout.cs" />
|
||||
<Compile Include="Models\LevelDetail.cs" />
|
||||
<Compile Include="Models\Item\Item.cs" />
|
||||
<Compile Include="Models\Item\Armor.cs" />
|
||||
<Compile Include="Models\Item\Weapon.cs" />
|
||||
<Compile Include="Models\Item\Misc.cs" />
|
||||
<Compile Include="Models\LevelPreset.cs" />
|
||||
<Compile Include="Models\LevelType.cs" />
|
||||
<Compile Include="Models\MapCellInfo.cs" />
|
||||
|
@ -117,6 +117,13 @@ namespace OpenDiablo2.Common
|
||||
public static string RunButton = "data\\global\\ui\\PANEL\\runbutton.dc6";
|
||||
public static string MenuButton = "data\\global\\ui\\PANEL\\menubutton.DC6";
|
||||
|
||||
public static string ArmorPlaceholder = "data\\global\\ui\\PANEL\\inv_armor.DC6";
|
||||
public static string BeltPlaceholder = "data\\global\\ui\\PANEL\\inv_belt.DC6";
|
||||
public static string BootsPlaceholder = "data\\global\\ui\\PANEL\\inv_boots.DC6";
|
||||
public static string HelmGlovePlaceholder = "data\\global\\ui\\PANEL\\inv_helm_glove.DC6";
|
||||
public static string RingAmuletPlaceholder = "data\\global\\ui\\PANEL\\inv_ring_amulet.DC6";
|
||||
public static string WeaponsPlaceholder = "data\\global\\ui\\PANEL\\inv_weapons.DC6";
|
||||
|
||||
// --- Data ---
|
||||
// TODO: Doesn't sound right :)
|
||||
public static string EnglishTable = "data\\local\\lng\\eng\\English.txt";
|
||||
@ -125,6 +132,14 @@ namespace OpenDiablo2.Common
|
||||
public static string LevelType = "data\\global\\excel\\LvlTypes.txt";
|
||||
public static string LevelDetails = "data\\global\\excel\\Levels.txt";
|
||||
|
||||
// --- Inventory Data ---
|
||||
public static string Weapons = "data\\global\\excel\\weapons.txt";
|
||||
public static string Armor = "data\\global\\excel\\armor.txt";
|
||||
public static string Misc = "data\\global\\excel\\misc.txt";
|
||||
|
||||
public static string GeneratePathForItem(string spriteName)
|
||||
{
|
||||
return $"data\\global\\items\\{spriteName}.dc6";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ namespace OpenDiablo2.Core
|
||||
|
||||
builder.RegisterType<Button>().As<IButton>().InstancePerDependency();
|
||||
builder.RegisterType<EngineDataManager>().As<IEngineDataManager>().SingleInstance();
|
||||
builder.RegisterType<ItemManager>().As<IItemManager>().SingleInstance();
|
||||
builder.RegisterType<GameEngine>().AsImplementedInterfaces().SingleInstance();
|
||||
builder.RegisterType<GameState>().As<IGameState>().SingleInstance();
|
||||
builder.RegisterType<MapEngine>().As<IMapEngine>().SingleInstance();
|
||||
@ -24,6 +25,7 @@ namespace OpenDiablo2.Core
|
||||
builder.RegisterType<PanelFrame>().As<IPanelFrame>().InstancePerDependency();
|
||||
builder.RegisterType<CharacterPanel>().As<ICharacterPanel>().InstancePerDependency();
|
||||
builder.RegisterType<InventoryPanel>().As<IInventoryPanel>().InstancePerDependency();
|
||||
builder.RegisterType<ItemContainer>().As<IItemContainer>().InstancePerDependency();
|
||||
builder.RegisterType<MPQProvider>().As<IMPQProvider>().SingleInstance();
|
||||
builder.RegisterType<ResourceManager>().As<IResourceManager>().SingleInstance();
|
||||
builder.RegisterType<TextDictionary>().As<ITextDictionary>().SingleInstance();
|
||||
|
@ -16,6 +16,7 @@ namespace OpenDiablo2.Core
|
||||
public List<LevelPreset> LevelPresets { get; internal set; }
|
||||
public List<LevelType> LevelTypes { get; internal set; }
|
||||
public List<LevelDetail> LevelDetails { get; internal set; }
|
||||
public List<Item> Items { get; internal set; } = new List<Item>();
|
||||
|
||||
public EngineDataManager(IMPQProvider mpqProvider)
|
||||
{
|
||||
@ -24,6 +25,8 @@ namespace OpenDiablo2.Core
|
||||
LoadLevelPresets();
|
||||
LoadLevelTypes();
|
||||
LoadLevelDetails();
|
||||
|
||||
LoadItemData();
|
||||
}
|
||||
|
||||
private void LoadLevelTypes()
|
||||
@ -67,5 +70,59 @@ namespace OpenDiablo2.Core
|
||||
|
||||
LevelDetails = new List<LevelDetail>(data);
|
||||
}
|
||||
|
||||
private void LoadItemData()
|
||||
{
|
||||
var weaponData = LoadWeaponData();
|
||||
var armorData = LoadArmorData();
|
||||
var miscData = LoadMiscData();
|
||||
|
||||
Items.AddRange(weaponData);
|
||||
Items.AddRange(armorData);
|
||||
Items.AddRange(miscData);
|
||||
}
|
||||
|
||||
private IEnumerable<Weapon> LoadWeaponData()
|
||||
{
|
||||
var data = mpqProvider
|
||||
.GetTextFile(ResourcePaths.Weapons)
|
||||
.Skip(1)
|
||||
.Where(x => !String.IsNullOrWhiteSpace(x))
|
||||
.Select(x => x.Split('\t'))
|
||||
//.Where(x => !String.IsNullOrWhiteSpace(x[27]))
|
||||
.ToArray()
|
||||
.Select(x => x.ToWeapon());
|
||||
|
||||
return data;
|
||||
;
|
||||
}
|
||||
|
||||
private IEnumerable<Armor> LoadArmorData()
|
||||
{
|
||||
var data = mpqProvider
|
||||
.GetTextFile(ResourcePaths.Armor)
|
||||
.Skip(1)
|
||||
.Where(x => !String.IsNullOrWhiteSpace(x))
|
||||
.Select(x => x.Split('\t'))
|
||||
//.Where(x => !String.IsNullOrWhiteSpace(x[27]))
|
||||
.ToArray()
|
||||
.Select(x => x.ToArmor());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private IEnumerable<Misc> LoadMiscData()
|
||||
{
|
||||
var data = mpqProvider
|
||||
.GetTextFile(ResourcePaths.Misc)
|
||||
.Skip(1)
|
||||
.Where(x => !String.IsNullOrWhiteSpace(x))
|
||||
.Select(x => x.Split('\t'))
|
||||
//.Where(x => !String.IsNullOrWhiteSpace(x[27]))
|
||||
.ToArray()
|
||||
.Select(x => x.ToMisc());
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Common.Models;
|
||||
@ -34,8 +35,11 @@ namespace OpenDiablo2.Core.GameState_
|
||||
public bool ShowInventoryPanel { get; set; } = false;
|
||||
public bool ShowCharacterPanel { get; set; } = false;
|
||||
|
||||
readonly private IMouseCursor originalMouseCursor;
|
||||
|
||||
public int Seed { get; internal set; }
|
||||
|
||||
public Item SelectedItem { get; internal set; }
|
||||
public object ThreadLocker { get; } = new object();
|
||||
|
||||
IEnumerable<PlayerInfo> IGameState.PlayerInfos => PlayerInfos;
|
||||
@ -60,6 +64,8 @@ namespace OpenDiablo2.Core.GameState_
|
||||
this.engineDataManager = engineDataManager;
|
||||
this.renderWindow = renderWindow;
|
||||
|
||||
this.originalMouseCursor = renderWindow.MouseCursor;
|
||||
|
||||
}
|
||||
|
||||
public void Initialize(string characterName, eHero hero, eSessionType sessionType)
|
||||
@ -244,6 +250,20 @@ namespace OpenDiablo2.Core.GameState_
|
||||
return ShowCharacterPanel;
|
||||
}
|
||||
|
||||
public void SelectItem(Item item)
|
||||
{
|
||||
if(item == null)
|
||||
{
|
||||
renderWindow.MouseCursor = this.originalMouseCursor;
|
||||
} else {
|
||||
var cursorsprite = renderWindow.LoadSprite(ResourcePaths.GeneratePathForItem(item.InvFile), Palettes.Units);
|
||||
|
||||
renderWindow.MouseCursor = renderWindow.LoadCursor(cursorsprite, 0, new Point(cursorsprite.FrameSize.Width / 2, cursorsprite.FrameSize.Height / 2));
|
||||
}
|
||||
|
||||
this.SelectedItem = item;
|
||||
}
|
||||
|
||||
private MapCellInfo GetMapCellInfo(MapInfo map, int cellX, int cellY, MPQDS1TileProps props, eRenderCellType cellType, MPQDS1WallOrientationTileProps wallOrientations = null)
|
||||
{
|
||||
if (!map.CellInfo.ContainsKey(cellType))
|
||||
|
29
OpenDiablo2.Core/ItemManager.cs
Normal file
29
OpenDiablo2.Core/ItemManager.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Common.Models;
|
||||
|
||||
namespace OpenDiablo2.Core
|
||||
{
|
||||
public sealed class ItemManager : IItemManager
|
||||
{
|
||||
private IEngineDataManager engineDataManager;
|
||||
|
||||
public ItemManager(IEngineDataManager engineDataManager)
|
||||
{
|
||||
this.engineDataManager = engineDataManager;
|
||||
}
|
||||
|
||||
public Item getItem(string code)
|
||||
{
|
||||
Item item = engineDataManager.Items.Where(x => x.Code == code).FirstOrDefault();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -56,6 +56,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AutofacModule.cs" />
|
||||
<Compile Include="ItemManager.cs" />
|
||||
<Compile Include="EngineDataManager.cs" />
|
||||
<Compile Include="GameEngine.cs" />
|
||||
<Compile Include="GameState\GameState.cs" />
|
||||
@ -67,6 +68,7 @@
|
||||
<Compile Include="ResourceManager.cs" />
|
||||
<Compile Include="TextDictionary.cs" />
|
||||
<Compile Include="UI\Button.cs" />
|
||||
<Compile Include="UI\ItemContainer.cs" />
|
||||
<Compile Include="UI\PanelFrame.cs" />
|
||||
<Compile Include="UI\InventoryPanel.cs" />
|
||||
<Compile Include="UI\TextBox.cs" />
|
||||
|
@ -6,32 +6,111 @@ using OpenDiablo2.Common.Interfaces;
|
||||
|
||||
namespace OpenDiablo2.Core.UI
|
||||
{
|
||||
/**
|
||||
* TODO: Check positioning, it's probably not exact
|
||||
* TODO: Add logic so it can be used as an element in inventory grid
|
||||
**/
|
||||
public sealed class InventoryPanel : IInventoryPanel
|
||||
{
|
||||
private readonly IRenderWindow renderWindow;
|
||||
private ISprite sprite;
|
||||
private IPanelFrame panelFrame;
|
||||
private Point location;
|
||||
|
||||
public Point Location { get; set; }
|
||||
public Point Location {
|
||||
get => location;
|
||||
set {
|
||||
previouslyContainedItem = location;
|
||||
location = value;
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryPanel(Func<ePanelFrameType, IPanelFrame> createPanelFrame, IRenderWindow renderWindow)
|
||||
// Test vars
|
||||
public IItemContainer helmContainer, armorContainer, weaponLeftContainer, weaponRightContainer, beltContainer, gloveContainer, bootsContainer;
|
||||
private Point previouslyContainedItem;
|
||||
private IItemContainer ringtLeftContainer;
|
||||
private IItemContainer ringtRightContainer;
|
||||
private IItemContainer amuletContainer;
|
||||
|
||||
public InventoryPanel(Func<ePanelFrameType, IPanelFrame> createPanelFrame, IRenderWindow renderWindow, IItemManager itemManager, Func<eItemContainerType, IItemContainer> createItemContainer)
|
||||
{
|
||||
this.renderWindow = renderWindow;
|
||||
this.panelFrame = createPanelFrame(ePanelFrameType.Right);
|
||||
|
||||
sprite = renderWindow.LoadSprite(ResourcePaths.InventoryCharacterPanel, Palettes.Units, new Point(402,61));
|
||||
Location = new Point(400, 0);
|
||||
|
||||
this.helmContainer = createItemContainer(eItemContainerType.Helm);
|
||||
this.helmContainer.Location = new Point(Location.X + 138, Location.Y + 68);
|
||||
this.helmContainer.SetContainedItem(itemManager.getItem("cap"));
|
||||
|
||||
this.amuletContainer = createItemContainer(eItemContainerType.Amulet);
|
||||
this.amuletContainer.Location = new Point(Location.X + 211, Location.Y + 92);
|
||||
this.amuletContainer.SetContainedItem(itemManager.getItem("vip"));
|
||||
|
||||
this.armorContainer = createItemContainer(eItemContainerType.Armor);
|
||||
this.armorContainer.Location = new Point(Location.X + 138, Location.Y + 138);
|
||||
this.armorContainer.SetContainedItem(itemManager.getItem("hla"));
|
||||
|
||||
this.weaponLeftContainer = createItemContainer(eItemContainerType.Weapon);
|
||||
this.weaponLeftContainer.Location = new Point(Location.X + 22, Location.Y + 108);
|
||||
this.weaponLeftContainer.SetContainedItem(itemManager.getItem("ame"));
|
||||
|
||||
this.weaponRightContainer = createItemContainer(eItemContainerType.Weapon);
|
||||
this.weaponRightContainer.Location = new Point(Location.X + 255, Location.Y + 108);
|
||||
this.weaponRightContainer.SetContainedItem(itemManager.getItem("paf"));
|
||||
|
||||
this.beltContainer = createItemContainer(eItemContainerType.Belt);
|
||||
this.beltContainer.Location = new Point(Location.X + 138, Location.Y + 238);
|
||||
this.beltContainer.SetContainedItem(itemManager.getItem("vbl"));
|
||||
|
||||
this.ringtLeftContainer = createItemContainer(eItemContainerType.Ring);
|
||||
this.ringtLeftContainer.Location = new Point(Location.X + 97, Location.Y + 238);
|
||||
this.ringtLeftContainer.SetContainedItem(itemManager.getItem("rin"));
|
||||
|
||||
this.ringtRightContainer = createItemContainer(eItemContainerType.Ring);
|
||||
this.ringtRightContainer.Location = new Point(Location.X + 211, Location.Y + 238);
|
||||
this.ringtRightContainer.SetContainedItem(itemManager.getItem("rin"));
|
||||
|
||||
this.gloveContainer = createItemContainer(eItemContainerType.Glove);
|
||||
this.gloveContainer.Location = new Point(Location.X + 22, Location.Y + 238);
|
||||
this.gloveContainer.SetContainedItem(itemManager.getItem("tgl"));
|
||||
|
||||
this.bootsContainer = createItemContainer(eItemContainerType.Boots);
|
||||
this.bootsContainer.Location = new Point(Location.X + 255, Location.Y + 238);
|
||||
this.bootsContainer.SetContainedItem(itemManager.getItem("lbt"));
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
helmContainer.Update();
|
||||
amuletContainer.Update();
|
||||
armorContainer.Update();
|
||||
weaponLeftContainer.Update();
|
||||
weaponRightContainer.Update();
|
||||
beltContainer.Update();
|
||||
ringtLeftContainer.Update();
|
||||
ringtRightContainer.Update();
|
||||
gloveContainer.Update();
|
||||
bootsContainer.Update();
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
panelFrame.Render();
|
||||
renderWindow.Draw(sprite, 2, 2, 1);
|
||||
|
||||
helmContainer.Render();
|
||||
amuletContainer.Render();
|
||||
armorContainer.Render();
|
||||
weaponLeftContainer.Render();
|
||||
weaponRightContainer.Render();
|
||||
beltContainer.Render();
|
||||
ringtLeftContainer.Render();
|
||||
ringtRightContainer.Render();
|
||||
gloveContainer.Render();
|
||||
bootsContainer.Render();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
115
OpenDiablo2.Core/UI/ItemContainer.cs
Normal file
115
OpenDiablo2.Core/UI/ItemContainer.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Common.Models;
|
||||
|
||||
namespace OpenDiablo2.Core.UI
|
||||
{
|
||||
// TODO: Self-align when side panels are open
|
||||
public sealed class ItemContainer : IItemContainer
|
||||
{
|
||||
private readonly IRenderWindow renderWindow;
|
||||
private readonly IGameState gameState;
|
||||
private ISprite sprite;
|
||||
|
||||
private ItemContainerLayout itemContainerLayout;
|
||||
private IMouseInfoProvider mouseInfoProvider;
|
||||
|
||||
public Item ContainedItem { get; internal set; }
|
||||
|
||||
private Dictionary<eItemContainerType, ISprite> sprites = new Dictionary<eItemContainerType, ISprite>();
|
||||
|
||||
private Point location = new Point();
|
||||
|
||||
public Point Location
|
||||
{
|
||||
get => location;
|
||||
set
|
||||
{
|
||||
if (location == value)
|
||||
return;
|
||||
location = value;
|
||||
|
||||
placeholderSprite.Location = new Point(value.X, value.Y + placeholderSprite.LocalFrameSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
private ISprite placeholderSprite;
|
||||
|
||||
public Size Size { get; internal set; }
|
||||
|
||||
public ItemContainer(IRenderWindow renderWindow, IGameState gameState, ItemContainerLayout itemContainerLayout, IMouseInfoProvider mouseInfoProvider)
|
||||
{
|
||||
this.renderWindow = renderWindow;
|
||||
this.gameState = gameState;
|
||||
this.itemContainerLayout = itemContainerLayout;
|
||||
this.mouseInfoProvider = mouseInfoProvider;
|
||||
|
||||
placeholderSprite = renderWindow.LoadSprite(itemContainerLayout.ResourceName, itemContainerLayout.PaletteName);
|
||||
placeholderSprite.Location = new Point(location.X, location.Y + placeholderSprite.LocalFrameSize.Height);
|
||||
this.Size = placeholderSprite.FrameSize; // For all but generic size is equal to the placeholder size. Source: me.
|
||||
}
|
||||
|
||||
public void SetContainedItem(Item containedItem)
|
||||
{
|
||||
ContainedItem = containedItem;
|
||||
|
||||
if (ContainedItem != null)
|
||||
{
|
||||
sprite = renderWindow.LoadSprite(ResourcePaths.GeneratePathForItem(this.ContainedItem.InvFile), Palettes.Units);
|
||||
sprite.Location = new Point(location.X, location.Y + sprite.LocalFrameSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
var hovered = (mouseInfoProvider.MouseX >= location.X && mouseInfoProvider.MouseX < (location.X + this.Size.Width))
|
||||
&& (mouseInfoProvider.MouseY >= location.Y && mouseInfoProvider.MouseY < (location.Y + this.Size.Height));
|
||||
|
||||
if (hovered && mouseInfoProvider.LeftMousePressed)
|
||||
{
|
||||
// If there is an item contained, remove from container and send to mouse
|
||||
if (this.ContainedItem != null)
|
||||
{
|
||||
if (this.gameState.SelectedItem != null)
|
||||
{
|
||||
var switchItem = this.gameState.SelectedItem;
|
||||
|
||||
this.gameState.SelectItem(this.ContainedItem);
|
||||
this.SetContainedItem(switchItem);
|
||||
} else
|
||||
{
|
||||
this.gameState.SelectItem(this.ContainedItem);
|
||||
this.SetContainedItem(null);
|
||||
}
|
||||
|
||||
}
|
||||
else if (this.gameState.SelectedItem != null)
|
||||
{
|
||||
this.SetContainedItem(this.gameState.SelectedItem);
|
||||
this.gameState.SelectItem(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
if (this.ContainedItem == null)
|
||||
{
|
||||
renderWindow.Draw(placeholderSprite, this.itemContainerLayout.BaseFrame);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderWindow.Draw(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
sprite.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ namespace OpenDiablo2.SDL2_
|
||||
public int MouseX { get; internal set; } = 0;
|
||||
public int MouseY { get; internal set; } = 0;
|
||||
public bool LeftMouseDown { get; internal set; } = false;
|
||||
public bool LeftMousePressed { get; internal set; } = false;
|
||||
public bool RightMouseDown { get; internal set; } = false;
|
||||
public bool ReserveMouse { get; set; } = false;
|
||||
|
||||
@ -141,6 +142,8 @@ namespace OpenDiablo2.SDL2_
|
||||
|
||||
public unsafe void Update()
|
||||
{
|
||||
LeftMousePressed = false;
|
||||
|
||||
while (SDL.SDL_PollEvent(out SDL.SDL_Event evt) != 0)
|
||||
{
|
||||
if (evt.type == SDL.SDL_EventType.SDL_MOUSEMOTION)
|
||||
@ -155,6 +158,7 @@ namespace OpenDiablo2.SDL2_
|
||||
switch ((uint)evt.button.button)
|
||||
{
|
||||
case SDL.SDL_BUTTON_LEFT:
|
||||
LeftMousePressed = true; // Cannot find a better to handle a single press
|
||||
LeftMouseDown = true;
|
||||
break;
|
||||
case SDL.SDL_BUTTON_RIGHT:
|
||||
@ -439,8 +443,8 @@ namespace OpenDiablo2.SDL2_
|
||||
var multiple = globalConfig.HardwareMouseScale;
|
||||
var spr = sprite as SDL2Sprite;
|
||||
var surface = SDL.SDL_CreateRGBSurface(0, spr.LocalFrameSize.Width * multiple, spr.LocalFrameSize.Height * multiple, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
|
||||
var yOffset = (spr.FrameSize.Height - spr.LocalFrameSize.Height);
|
||||
var XOffset = (spr.FrameSize.Width - spr.LocalFrameSize.Width);
|
||||
var yOffset = 0; //(spr.FrameSize.Height - spr.LocalFrameSize.Height);
|
||||
var XOffset = 0; //(spr.FrameSize.Width - spr.LocalFrameSize.Width);
|
||||
var pixels = (UInt32*)((SDL.SDL_Surface*)surface)->pixels;
|
||||
for (var y = 0; y < (spr.LocalFrameSize.Height * multiple) - 1; y++)
|
||||
for (var x = 0; x < (spr.LocalFrameSize.Width * multiple) - 1; x++)
|
||||
|
@ -43,6 +43,7 @@ namespace OpenDiablo2.Scenes
|
||||
IGameState gameState,
|
||||
IMouseInfoProvider mouseInfoProvider,
|
||||
IKeyboardInfoProvider keyboardInfoProvider,
|
||||
IItemManager itemManager,
|
||||
ISessionManager sessionManager,
|
||||
Func<eButtonType, IButton> createButton,
|
||||
Func<IMiniPanel> createMiniPanel,
|
||||
@ -77,6 +78,11 @@ namespace OpenDiablo2.Scenes
|
||||
menuButton = createButton(eButtonType.Menu);
|
||||
menuButton.Location = new Point(393, 561);
|
||||
menuButton.OnToggle = OnMenuToggle;
|
||||
|
||||
/*var item = itemManager.getItem("hdm");
|
||||
var cursorsprite = renderWindow.LoadSprite(ResourcePaths.GeneratePathForItem(item.InvFile), Palettes.Units);
|
||||
|
||||
renderWindow.MouseCursor = renderWindow.LoadCursor(cursorsprite, 0, new Point(cursorsprite.FrameSize.Width/2, cursorsprite.FrameSize.Height / 2));*/
|
||||
}
|
||||
|
||||
private void OnMenuToggle(bool isToggled)
|
||||
@ -148,7 +154,15 @@ namespace OpenDiablo2.Scenes
|
||||
minipanel.Update();
|
||||
}
|
||||
|
||||
characterpanel.Update();
|
||||
if (gameState.ShowInventoryPanel)
|
||||
{
|
||||
inventorypanel.Update();
|
||||
}
|
||||
|
||||
if (gameState.ShowCharacterPanel)
|
||||
{
|
||||
characterpanel.Update();
|
||||
}
|
||||
|
||||
runButton.Update();
|
||||
menuButton.Update();
|
||||
|
@ -12,6 +12,7 @@
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
@ -24,7 +25,6 @@
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
|
@ -85,6 +85,12 @@ namespace OpenDiablo2
|
||||
return (panelFrameType) => componentContext.Resolve<IPanelFrame>(new NamedParameter("panelFrameType", panelFrameType));
|
||||
});
|
||||
|
||||
containerBuilder.Register<Func<eItemContainerType, IItemContainer>>(c =>
|
||||
{
|
||||
var componentContext = c.Resolve<IComponentContext>();
|
||||
return (itemContainerType) => componentContext.Resolve<IItemContainer>(new NamedParameter("itemContainerLayout", ItemContainerLayout.Values[itemContainerType]));
|
||||
});
|
||||
|
||||
/* Uncomment the below if we support multiple textbox types
|
||||
containerBuilder.Register<Func<TextBox>>(c =>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user