1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-19 02:46:35 -05:00

Basic Character Panel and Inventory Panel drawing (#30)

* Initial minipanel work
* Character and Inventory panel implementation, frame included
* Separate panel frame from the actual inventory and character panels so they can be reused by other panels
This commit is contained in:
Diego M 2018-11-29 21:11:25 -03:00 committed by Tim Sarbin
parent baed1834b4
commit f3793e0a60
16 changed files with 457 additions and 199 deletions

View File

@ -0,0 +1,8 @@
namespace OpenDiablo2.Common.Enums
{
public enum ePanelFrameType
{
Left,
Right
}
}

View File

@ -0,0 +1,10 @@
using System;
namespace OpenDiablo2.Common.Interfaces
{
public interface ICharacterPanel : IDisposable
{
void Render();
void Update();
}
}

View File

@ -12,6 +12,12 @@ namespace OpenDiablo2.Common.Interfaces
string MapName { get; }
Palette CurrentPalette { get; }
bool ToggleShowInventoryPanel();
bool ShowInventoryPanel { get; set; }
bool ToggleShowCharacterPanel();
bool ShowCharacterPanel { get; set; }
void Initialize(string text, eHero value);
void Update(long ms);
IEnumerable<MapCellInfo> GetMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType);

View File

@ -0,0 +1,10 @@
using System;
namespace OpenDiablo2.Common.Interfaces
{
public interface IInventoryPanel : IDisposable
{
void Render();
void Update();
}
}

View File

@ -0,0 +1,11 @@
using OpenDiablo2.Common.Enums;
using System;
namespace OpenDiablo2.Common.Interfaces
{
public interface IPanelFrame : IDisposable
{
void Render();
void Update();
}
}

View File

@ -54,6 +54,7 @@
<ItemGroup>
<Compile Include="Attributes\SceneAttribute.cs" />
<Compile Include="AutofacModule.cs" />
<Compile Include="Enums\ePanelFrameType.cs" />
<Compile Include="Enums\eButtonType.cs" />
<Compile Include="Enums\eHero.cs" />
<Compile Include="Enums\eLevelId.cs" />
@ -63,6 +64,8 @@
<Compile Include="Enums\eTextAlign.cs" />
<Compile Include="Enums\eWildBorder.cs" />
<Compile Include="Interfaces\IButton.cs" />
<Compile Include="Interfaces\IPanelFrame.cs" />
<Compile Include="Interfaces\IInventoryPanel.cs" />
<Compile Include="Interfaces\IEngineDataManager.cs" />
<Compile Include="Interfaces\IFont.cs" />
<Compile Include="Interfaces\IGameEngine.cs" />
@ -71,6 +74,7 @@
<Compile Include="Interfaces\ILabel.cs" />
<Compile Include="Interfaces\IMapEngine.cs" />
<Compile Include="Interfaces\IMiniPanel.cs" />
<Compile Include="Interfaces\ICharacterPanel.cs" />
<Compile Include="Interfaces\IMouseCursor.cs" />
<Compile Include="Interfaces\IMPQProvider.cs" />
<Compile Include="Interfaces\IMusicProvider.cs" />

View File

@ -111,6 +111,9 @@ namespace OpenDiablo2.Common
public static string MinipanelSmall = "data\\global\\ui\\PANEL\\minipanel_s.dc6";
public static string MinipanelButton = "data\\global\\ui\\PANEL\\minipanelbtn.DC6";
public static string Frame = "data\\global\\ui\\PANEL\\800borderframe.dc6";
public static string InventoryCharacterPanel = "data\\global\\ui\\PANEL\\invchar.DC6";
public static string RunButton = "data\\global\\ui\\PANEL\\runbutton.dc6";
public static string MenuButton = "data\\global\\ui\\PANEL\\menubutton.DC6";

View File

@ -20,6 +20,9 @@ namespace OpenDiablo2.Core
builder.RegisterType<GameState>().As<IGameState>().SingleInstance();
builder.RegisterType<MapEngine>().As<IMapEngine>().SingleInstance();
builder.RegisterType<MiniPanel>().As<IMiniPanel>().InstancePerDependency();
builder.RegisterType<PanelFrame>().As<IPanelFrame>().InstancePerDependency();
builder.RegisterType<CharacterPanel>().As<ICharacterPanel>().InstancePerDependency();
builder.RegisterType<InventoryPanel>().As<IInventoryPanel>().InstancePerDependency();
builder.RegisterType<MPQProvider>().As<IMPQProvider>().SingleInstance();
builder.RegisterType<ResourceManager>().As<IResourceManager>().SingleInstance();
builder.RegisterType<TextDictionary>().As<ITextDictionary>().SingleInstance();

View File

@ -34,6 +34,9 @@ namespace OpenDiablo2.Core.GameState_
public string MapName { get; private set; }
public Palette CurrentPalette => paletteProvider.PaletteTable[$"ACT{Act}"];
public bool ShowInventoryPanel { get; set; } = false;
public bool ShowCharacterPanel { get; set; } = false;
public int Seed { get; internal set; }
public GameState(
@ -223,6 +226,20 @@ namespace OpenDiablo2.Core.GameState_
}
public bool ToggleShowInventoryPanel()
{
ShowInventoryPanel = !ShowInventoryPanel;
return ShowInventoryPanel;
}
public bool ToggleShowCharacterPanel()
{
ShowCharacterPanel = !ShowCharacterPanel;
return ShowCharacterPanel;
}
private MapCellInfo GetMapCellInfo(
MapInfo map,

View File

@ -66,8 +66,11 @@
<Compile Include="ResourceManager.cs" />
<Compile Include="TextDictionary.cs" />
<Compile Include="UI\Button.cs" />
<Compile Include="UI\PanelFrame.cs" />
<Compile Include="UI\InventoryPanel.cs" />
<Compile Include="UI\TextBox.cs" />
<Compile Include="UI\MiniPanel.cs" />
<Compile Include="UI\CharacterPanel.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenDiablo2.Common\OpenDiablo2.Common.csproj">

View File

@ -0,0 +1,44 @@
using System;
using System.Drawing;
using OpenDiablo2.Common;
using OpenDiablo2.Common.Enums;
using OpenDiablo2.Common.Interfaces;
namespace OpenDiablo2.Core.UI
{
public sealed class CharacterPanel : ICharacterPanel
{
private readonly IRenderWindow renderWindow;
private ISprite sprite;
private IPanelFrame panelFrame;
public Point Location { get; set; }
public CharacterPanel(IRenderWindow renderWindow, Func<ePanelFrameType, IPanelFrame> createPanelFrame)
{
this.renderWindow = renderWindow;
this.panelFrame = createPanelFrame(ePanelFrameType.Left);
sprite = renderWindow.LoadSprite(ResourcePaths.InventoryCharacterPanel, Palettes.Units, new Point(79,61));
Location = new Point(0, 0);
}
public void Update()
{
}
public void Render()
{
panelFrame.Render();
renderWindow.Draw(sprite, 2, 2, 0);
}
public void Dispose()
{
sprite.Dispose();
}
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Drawing;
using OpenDiablo2.Common;
using OpenDiablo2.Common.Enums;
using OpenDiablo2.Common.Interfaces;
namespace OpenDiablo2.Core.UI
{
public sealed class InventoryPanel : IInventoryPanel
{
private readonly IRenderWindow renderWindow;
private ISprite sprite;
private IPanelFrame panelFrame;
public Point Location { get; set; }
public InventoryPanel(Func<ePanelFrameType, IPanelFrame> createPanelFrame, IRenderWindow renderWindow)
{
this.renderWindow = renderWindow;
this.panelFrame = createPanelFrame(ePanelFrameType.Right);
sprite = renderWindow.LoadSprite(ResourcePaths.InventoryCharacterPanel, Palettes.Units, new Point(402,61));
Location = new Point(400, 0);
}
public void Update()
{
}
public void Render()
{
panelFrame.Render();
renderWindow.Draw(sprite, 2, 2, 1);
}
public void Dispose()
{
sprite.Dispose();
}
}
}

View File

@ -6,7 +6,7 @@ using OpenDiablo2.Common.Interfaces;
namespace OpenDiablo2.Core.UI
{
// TODO: Allow to set Minipanel.buttons.character.OnAction or similar for button delegates
// TODO: Self-align when side panels are open
public sealed class MiniPanel : IMiniPanel
{
private readonly IRenderWindow renderWindow;
@ -28,7 +28,7 @@ namespace OpenDiablo2.Core.UI
}
}
public MiniPanel(IRenderWindow renderWindow, Func<eButtonType, IButton> createButton)
public MiniPanel(IRenderWindow renderWindow, IGameState gameState, Func<eButtonType, IButton> createButton)
{
this.renderWindow = renderWindow;
@ -37,9 +37,11 @@ namespace OpenDiablo2.Core.UI
characterBtn = createButton(eButtonType.MinipanelCharacter);
characterBtn.Location = new Point(3 + Location.X, 3 + Location.Y);
characterBtn.OnActivate = () => gameState.ToggleShowCharacterPanel();
inventoryBtn = createButton(eButtonType.MinipanelInventory);
inventoryBtn.Location = new Point(24 + Location.X, 3 + Location.Y);
inventoryBtn.OnActivate = () => gameState.ToggleShowInventoryPanel();
skillBtn = createButton(eButtonType.MinipanelSkill);
skillBtn.Location = new Point(45 + Location.X, 3 + Location.Y);

View File

@ -0,0 +1,67 @@
using System;
using System.Drawing;
using OpenDiablo2.Common;
using OpenDiablo2.Common.Enums;
using OpenDiablo2.Common.Interfaces;
namespace OpenDiablo2.Core.UI
{
public sealed class PanelFrame : IPanelFrame
{
private readonly IRenderWindow renderWindow;
private ISprite sprite;
private ePanelFrameType panelFrameType;
public Point Location { get; set; }
public PanelFrame(IRenderWindow renderWindow, ePanelFrameType panelFrameType)
{
this.renderWindow = renderWindow;
this.panelFrameType = panelFrameType;
sprite = renderWindow.LoadSprite(ResourcePaths.Frame, Palettes.Units, new Point(0, 0));
Location = new Point(0, 0);
}
private void DrawPanel()
{
switch(this.panelFrameType)
{
case ePanelFrameType.Left:
renderWindow.Draw(sprite, 0, new Point(0, 256));
renderWindow.Draw(sprite, 1, new Point(256, 66));
renderWindow.Draw(sprite, 2, new Point(0, 256 + 231));
renderWindow.Draw(sprite, 3, new Point(0, 256 + 231 + 66));
renderWindow.Draw(sprite, 4, new Point(256, 256 + 231 + 66));
break;
case ePanelFrameType.Right:
renderWindow.Draw(sprite, 5, new Point(400 + 0, 66));
renderWindow.Draw(sprite, 6, new Point(400 + 145, 256));
renderWindow.Draw(sprite, 7, new Point(400 + 145 + 169, 256 + 231));
renderWindow.Draw(sprite, 8, new Point(400 + 145, 256 + 231 + 66));
renderWindow.Draw(sprite, 9, new Point(400 + 0, 256 + 231 + 66));
break;
}
}
public void Update()
{
}
public void Render()
{
DrawPanel();
}
public void Dispose()
{
sprite.Dispose();
}
}
}

View File

@ -23,6 +23,9 @@ namespace OpenDiablo2.Scenes
private ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite;
private IMiniPanel minipanel;
private ICharacterPanel characterpanel;
private IInventoryPanel inventorypanel;
private bool showMinipanel = false;
private IButton runButton, menuButton;
@ -33,7 +36,9 @@ namespace OpenDiablo2.Scenes
IGameState gameState,
IKeyboardInfoProvider keyboardInfoProvider,
Func<eButtonType, IButton> createButton,
Func<IMiniPanel> createMiniPanel
Func<IMiniPanel> createMiniPanel,
Func<ICharacterPanel> createCharacterPanel,
Func<IInventoryPanel> createInventoryPanel
)
{
this.renderWindow = renderWindow;
@ -51,6 +56,9 @@ namespace OpenDiablo2.Scenes
// Maybe? Not sure.
// miniPanel.OnMenuActivate();
characterpanel = createCharacterPanel();
inventorypanel = createInventoryPanel();
runButton = createButton(eButtonType.Run);
runButton.Location = new Point(256, 570);
runButton.OnToggle = OnRunToggle;
@ -86,6 +94,16 @@ namespace OpenDiablo2.Scenes
private void DrawPanel()
{
if(gameState.ShowInventoryPanel)
{
inventorypanel.Render();
}
if (gameState.ShowCharacterPanel)
{
characterpanel.Render();
}
// Render the background bottom bar
renderWindow.Draw(panelSprite, 0, new Point(0, 600));
renderWindow.Draw(panelSprite, 1, new Point(166, 600));
@ -107,6 +125,8 @@ namespace OpenDiablo2.Scenes
minipanel.Render();
}
runButton.Render();
menuButton.Render();
}
@ -118,6 +138,8 @@ namespace OpenDiablo2.Scenes
minipanel.Update();
}
characterpanel.Update();
runButton.Update();
menuButton.Update();

View File

@ -68,6 +68,12 @@ namespace OpenDiablo2
return (buttonType) => componentContext.Resolve<IButton>(new NamedParameter("buttonLayout", ButtonLayout.Values[buttonType]));
});
containerBuilder.Register<Func<ePanelFrameType, IPanelFrame>>(c =>
{
var componentContext = c.Resolve<IComponentContext>();
return (panelFrameType) => componentContext.Resolve<IPanelFrame>(new NamedParameter("panelFrameType", panelFrameType));
});
/* Uncomment the below if we support multiple textbox types
containerBuilder.Register<Func<TextBox>>(c =>
{