1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-17 00:36:10 -04:00
OpenDiablo2/OpenDiablo2.Core/UI/Minipanel.cs
Diego M cb8916c085 UI: (Small) Minipanel Implementation (#15)
* ui stuff
* Toggleable stuff
* Initial minipanel work
* Partial work commit to fix random error, still missing relative rendering
* Toggle Minipanel with HUD menu button
* Fix line breaks
2018-11-25 13:13:24 -05:00

104 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenDiablo2.Common;
using OpenDiablo2.Common.Enums;
using OpenDiablo2.Common.Interfaces;
namespace OpenDiablo2.Core.UI
{
// TODO: Allow to set Minipanel.buttons.character.OnAction or similar for button delegates
public sealed class Minipanel : IDisposable
{
private readonly IRenderWindow renderWindow;
private ISprite sprite;
private Button characterBtn, inventoryBtn, skillBtn, automapBtn, messageBtn, questBtn, menuBtn;
private Point location = new Point();
public Point Location
{
get => location;
set
{
if (location == value)
return;
location = value;
sprite.Location = new Point(value.X, value.Y + sprite.LocalFrameSize.Height);
}
}
public Minipanel(IRenderWindow renderWindow, Func<eButtonType, Button> createButton)
{
this.renderWindow = renderWindow;
sprite = renderWindow.LoadSprite(ResourcePaths.MinipanelSmall, Palettes.Units);
Location = new Point(800/2-sprite.LocalFrameSize.Width/2, 526);
characterBtn = createButton(eButtonType.MinipanelCharacter);
characterBtn.Location = new Point(3 + Location.X, 3 + Location.Y);
inventoryBtn = createButton(eButtonType.MinipanelInventory);
inventoryBtn.Location = new Point(24 + Location.X, 3 + Location.Y);
skillBtn = createButton(eButtonType.MinipanelSkill);
skillBtn.Location = new Point(45 + Location.X, 3 + Location.Y);
automapBtn = createButton(eButtonType.MinipanelAutomap);
automapBtn.Location = new Point(66 + Location.X, 3 + Location.Y);
messageBtn = createButton(eButtonType.MinipanelMessage);
messageBtn.Location = new Point(87 + Location.X, 3 + Location.Y);
questBtn = createButton(eButtonType.MinipanelQuest);
questBtn.Location = new Point(108 + Location.X, 3 + Location.Y);
menuBtn = createButton(eButtonType.MinipanelMenu);
menuBtn.Location = new Point(129 + Location.X, 3 + Location.Y);
}
public void Update()
{
characterBtn.Update();
inventoryBtn.Update();
skillBtn.Update();
automapBtn.Update();
messageBtn.Update();
questBtn.Update();
menuBtn.Update();
}
public void Render()
{
renderWindow.Draw(sprite);
characterBtn.Render();
inventoryBtn.Render();
skillBtn.Render();
automapBtn.Render();
messageBtn.Render();
questBtn.Render();
menuBtn.Render();
}
public void Dispose()
{
characterBtn.Dispose();
inventoryBtn.Dispose();
skillBtn.Dispose();
automapBtn.Dispose();
messageBtn.Dispose();
questBtn.Dispose();
menuBtn.Dispose();
sprite.Dispose();
}
}
}