1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-19 19:06:45 -05:00

Added attribute/skill buttons to the HUD (#47)

This commit is contained in:
Kacper Drobny 2018-12-11 19:09:21 +01:00 committed by Tim Sarbin
parent de83a86aeb
commit c277cb2d89
14 changed files with 107 additions and 9 deletions

View File

@ -8,6 +8,7 @@
Cancel,
Tall,
// Game UI
Skill,
Run,
Menu,
GoldCoin,

View File

@ -0,0 +1,14 @@
namespace OpenDiablo2.Common.Enums
{
public enum ePanelType
{
None,
Character,
Inventory,
Skill,
Automap,
Message,
Quest,
Menu
}
}

View File

@ -38,5 +38,28 @@ namespace OpenDiablo2.Common.Extensions
log.Warn($"Unknown panel positon, {value}");
return default(Point);
}
public static ePanelType GetPanelType(this eButtonType value)
{
switch(value)
{
case eButtonType.MinipanelAutomap:
return ePanelType.Automap;
case eButtonType.MinipanelCharacter:
return ePanelType.Character;
case eButtonType.MinipanelInventory:
return ePanelType.Inventory;
case eButtonType.MinipanelMenu:
return ePanelType.Menu;
case eButtonType.MinipanelMessage:
return ePanelType.Message;
case eButtonType.MinipanelQuest:
return ePanelType.Quest;
case eButtonType.MinipanelSkill:
return ePanelType.Skill;
default:
return ePanelType.None;
}
}
}
}

View File

@ -14,6 +14,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using OpenDiablo2.Common.Enums;
namespace OpenDiablo2.Common.Interfaces
{
public interface IGameHUD
@ -23,6 +25,7 @@ namespace OpenDiablo2.Common.Interfaces
bool IsRightPanelVisible { get; }
bool IsMouseOver();
void TogglePanel(ePanelType panelType);
void TogglePanel(IPanel panel);
void OpenPanels(IPanel leftPanel, IPanel rightPanel);
void ClosePanels();

View File

@ -1,4 +1,5 @@
using System;
using OpenDiablo2.Common.Enums;
using System;
namespace OpenDiablo2.Common.Interfaces
{
@ -8,6 +9,7 @@ namespace OpenDiablo2.Common.Interfaces
{
event OnPanelToggledEvent OnPanelToggled;
IPanel GetPanel(ePanelType panelType);
bool IsMouseOver();
void UpdatePanelLocation();
void OnMenuToggle(bool isToggled);

View File

@ -25,7 +25,7 @@ namespace OpenDiablo2.Common.Interfaces
{
event OnPanelClosedEvent OnPanelClosed;
eButtonType PanelType { get; }
ePanelType PanelType { get; }
ePanelFrameType FrameType { get; }
void Render();
void Update();

View File

@ -12,6 +12,9 @@ namespace OpenDiablo2.Common.Models
public string PaletteName { get; internal set; }
public bool Toggleable { get; internal set; } = false;
public int BaseFrame { get; internal set; } = 0;
public int DisabledFrame { get; internal set; } = -1;
public bool IsDarkenedWhenDisabled => DisabledFrame == -1;
public static ImmutableDictionary<eButtonType, ButtonLayout> Values { get; } = new Dictionary<eButtonType, ButtonLayout>
{
@ -34,6 +37,7 @@ namespace OpenDiablo2.Common.Models
{eButtonType.Menu, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.MenuButton,PaletteName = Palettes.Units, Toggleable = true } },
{eButtonType.GoldCoin, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.GoldCoinButton,PaletteName = Palettes.Units } },
{eButtonType.Close, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.SquareButton,PaletteName = Palettes.Units, BaseFrame = 10 } },
{eButtonType.Skill, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.AddSkillButton, PaletteName = Palettes.Units, DisabledFrame = 2 } },
}.ToImmutableDictionary();
}

View File

@ -75,6 +75,7 @@
<Compile Include="Enums\eLevelId.cs" />
<Compile Include="Enums\eLevelSubType.cs" />
<Compile Include="Enums\eMPQFormatVersion.cs" />
<Compile Include="Enums\ePanelType.cs" />
<Compile Include="Enums\eRenderCellType.cs" />
<Compile Include="Enums\eSceneType.cs" />
<Compile Include="Enums\eSessionType.cs" />

View File

@ -95,6 +95,7 @@ namespace OpenDiablo2.Common
public const string HealthMana = @"data\global\ui\PANEL\hlthmana.DC6";
public const string GameSmallMenuButton = @"data\global\ui\PANEL\menubutton.DC6"; // TODO: Used for inventory popout
public const string SkillIcon = @"data\global\ui\PANEL\Skillicon.DC6"; // TODO: Used for skill icon button
public const string AddSkillButton = @"data\global\ui\PANEL\level.DC6";
// --- Mouse Pointers ---
public const string CursorDefault = @"data\global\ui\CURSOR\ohand.DC6";

View File

@ -53,7 +53,8 @@ namespace OpenDiablo2.Core.UI
return;
enabled = value;
sprite.Darken = !enabled;
if(buttonLayout.IsDarkenedWhenDisabled)
sprite.Darken = !enabled;
}
}
@ -186,7 +187,11 @@ namespace OpenDiablo2.Core.UI
if (AllowFrameChange)
{
if (Toggled && pressed)
if(!Enabled && buttonLayout.DisabledFrame >= 0)
{
frame = buttonLayout.DisabledFrame;
}
else if (Toggled && pressed)
{
frame = buttonLayout.BaseFrame + 3;
}

View File

@ -45,7 +45,7 @@ namespace OpenDiablo2.Core.UI
closeButton.OnActivate = () => OnPanelClosed?.Invoke(this);
}
public eButtonType PanelType => eButtonType.MinipanelCharacter;
public ePanelType PanelType => ePanelType.Character;
public ePanelFrameType FrameType => ePanelFrameType.Left;
public void Update()

View File

@ -32,10 +32,14 @@ namespace OpenDiablo2.Core.UI
private readonly IMouseInfoProvider mouseInfoProvider;
private readonly IMiniPanel minipanel;
private readonly IButton runButton, menuButton;
private readonly IButton runButton, menuButton, addStatButton, addSkillButton;
private readonly ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite;
private readonly IPanelFrame leftPanelFrame, rightPanelFrame;
// Test fields
private bool addNewAttribute = true;
private bool addNewSkill = false;
public GameHUD(
IRenderWindow renderWindow,
IGameState gameState,
@ -62,6 +66,15 @@ namespace OpenDiablo2.Core.UI
menuButton.OnToggle = minipanel.OnMenuToggle;
menuButton.Toggle();
addStatButton = createButton(eButtonType.Skill);
addStatButton.Location = new Point(207, 562);
addStatButton.Enabled = addNewAttribute;
addStatButton.OnActivate = () => TogglePanel(ePanelType.Character);
addSkillButton = createButton(eButtonType.Skill);
addSkillButton.Location = new Point(564, 562);
addSkillButton.Enabled = addNewSkill;
panelSprite = renderWindow.LoadSprite(ResourcePaths.GamePanels, Palettes.Act1, true);
healthManaSprite = renderWindow.LoadSprite(ResourcePaths.HealthMana, Palettes.Act1, true);
gameGlobeOverlapSprite = renderWindow.LoadSprite(ResourcePaths.GameGlobeOverlap, Palettes.Act1, true);
@ -75,6 +88,11 @@ namespace OpenDiablo2.Core.UI
public bool IsRightPanelVisible => RightPanel != null;
public bool IsRunningEnabled => runButton.Toggled;
public void TogglePanel(ePanelType panelType)
{
TogglePanel(minipanel.GetPanel(panelType));
}
public void TogglePanel(IPanel panel)
{
switch (panel.FrameType)
@ -168,12 +186,16 @@ namespace OpenDiablo2.Core.UI
runButton.Render();
menuButton.Render();
addStatButton.Render();
addSkillButton.Render();
}
public void Update()
{
runButton.Update();
menuButton.Update();
addStatButton.Update();
addSkillButton.Update();
if (IsLeftPanelVisible)
{

View File

@ -105,7 +105,7 @@ namespace OpenDiablo2.Core.UI
bootsContainer.Location = panelSprite.Location + new Size(251, 178);
}
public eButtonType PanelType => eButtonType.MinipanelInventory;
public ePanelType PanelType => ePanelType.Inventory;
public ePanelFrameType FrameType => ePanelFrameType.Right;
public bool IsSecondaryEquipped { get; private set; }

View File

@ -1,5 +1,22 @@
using OpenDiablo2.Common;
/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using OpenDiablo2.Common;
using OpenDiablo2.Common.Enums;
using OpenDiablo2.Common.Extensions;
using OpenDiablo2.Common.Interfaces;
using System;
using System.Collections.Generic;
@ -40,7 +57,7 @@ namespace OpenDiablo2.Core.UI
buttons = panelButtons.Select((x, i) =>
{
var newBtn = createButton(x);
var panel = panels.SingleOrDefault(o => o.PanelType == x);
var panel = panels.SingleOrDefault(o => o.PanelType == x.GetPanelType());
if (panel != null)
{
@ -55,6 +72,11 @@ namespace OpenDiablo2.Core.UI
public void OnMenuToggle(bool isToggled) => isPanelVisible = isToggled;
public IPanel GetPanel(ePanelType panelType)
{
return panels.SingleOrDefault(o => o.PanelType == panelType);
}
public bool IsMouseOver()
{
int xDiff = mouseInfoProvider.MouseX - sprite.Location.X;