mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-19 19:06:45 -05:00
Merged PR - Added UI toggle box
* ui stuff * More ui stuff * Toggleable stuff * Some debug messages
This commit is contained in:
parent
3a0cbe4b8e
commit
2cd64677f2
@ -4,6 +4,10 @@
|
|||||||
{
|
{
|
||||||
Wide,
|
Wide,
|
||||||
Medium,
|
Medium,
|
||||||
Cancel
|
Narrow,
|
||||||
|
Cancel,
|
||||||
|
// Game UI
|
||||||
|
Run,
|
||||||
|
Menu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,16 @@ namespace OpenDiablo2.Common.Models
|
|||||||
public int XSegments { get; internal set; }
|
public int XSegments { get; internal set; }
|
||||||
public string ResourceName { get; internal set; }
|
public string ResourceName { get; internal set; }
|
||||||
public string PaletteName { get; internal set; }
|
public string PaletteName { get; internal set; }
|
||||||
|
public bool Toggleable { get; internal set; } = false;
|
||||||
|
|
||||||
public static Dictionary<eButtonType, ButtonLayout> Values = new Dictionary<eButtonType, ButtonLayout>
|
public static Dictionary<eButtonType, ButtonLayout> Values = new Dictionary<eButtonType, ButtonLayout>
|
||||||
{
|
{
|
||||||
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } },
|
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } },
|
||||||
{eButtonType.Medium, new ButtonLayout{ XSegments = 1, ResourceName=ResourcePaths.MediumButtonBlank, PaletteName = Palettes.Units } },
|
{eButtonType.Medium, new ButtonLayout{ XSegments = 1, ResourceName=ResourcePaths.MediumButtonBlank, PaletteName = Palettes.Units } },
|
||||||
{eButtonType.Cancel, new ButtonLayout {XSegments = 1,ResourceName = ResourcePaths.CancelButton,PaletteName = Palettes.Units } }
|
{eButtonType.Narrow, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.NarrowButtonBlank,PaletteName = Palettes.Units } },
|
||||||
|
{eButtonType.Cancel, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.CancelButton,PaletteName = Palettes.Units } },
|
||||||
|
{eButtonType.Run, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.RunButton,PaletteName = Palettes.Units, Toggleable = true } },
|
||||||
|
{eButtonType.Menu, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.MenuButton,PaletteName = Palettes.Units, Toggleable = true } },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +100,13 @@ namespace OpenDiablo2.Common
|
|||||||
public static string WideButtonBlank = "data\\global\\ui\\FrontEnd\\WideButtonBlank.dc6";
|
public static string WideButtonBlank = "data\\global\\ui\\FrontEnd\\WideButtonBlank.dc6";
|
||||||
public static string MediumButtonBlank = "data\\global\\ui\\FrontEnd\\MediumButtonBlank.dc6";
|
public static string MediumButtonBlank = "data\\global\\ui\\FrontEnd\\MediumButtonBlank.dc6";
|
||||||
public static string CancelButton = "data\\global\\ui\\FrontEnd\\CancelButtonBlank.dc6";
|
public static string CancelButton = "data\\global\\ui\\FrontEnd\\CancelButtonBlank.dc6";
|
||||||
|
public static string NarrowButtonBlank = "data\\global\\ui\\FrontEnd\\NarrowButtonBlank.dc6";
|
||||||
public static string TextBox2 = "data\\global\\ui\\FrontEnd\\textbox2.dc6";
|
public static string TextBox2 = "data\\global\\ui\\FrontEnd\\textbox2.dc6";
|
||||||
|
|
||||||
|
// --- GAME UI ---
|
||||||
|
public static string RunButton = "data\\global\\ui\\PANEL\\runbutton.dc6";
|
||||||
|
public static string MenuButton = "data\\global\\ui\\PANEL\\menubutton.DC6";
|
||||||
|
|
||||||
// --- Data ---
|
// --- Data ---
|
||||||
// TODO: Doesn't sound right :)
|
// TODO: Doesn't sound right :)
|
||||||
public static string EnglishTable = "data\\local\\lng\\eng\\English.txt";
|
public static string EnglishTable = "data\\local\\lng\\eng\\English.txt";
|
||||||
|
@ -21,6 +21,9 @@ namespace OpenDiablo2.Core.UI
|
|||||||
public delegate void OnActivateDelegate();
|
public delegate void OnActivateDelegate();
|
||||||
public OnActivateDelegate OnActivate { get; set; }
|
public OnActivateDelegate OnActivate { get; set; }
|
||||||
|
|
||||||
|
public delegate void OnToggleDelegate(bool isToggled);
|
||||||
|
public OnToggleDelegate OnToggle { get; set; }
|
||||||
|
|
||||||
private Point location = new Point();
|
private Point location = new Point();
|
||||||
public Point Location
|
public Point Location
|
||||||
{
|
{
|
||||||
@ -39,6 +42,8 @@ namespace OpenDiablo2.Core.UI
|
|||||||
private bool pressed = false;
|
private bool pressed = false;
|
||||||
private bool active = false; // When true, button is actively being focus pressed
|
private bool active = false; // When true, button is actively being focus pressed
|
||||||
private bool activeLock = false; // When true, something else is being pressed so ignore everything
|
private bool activeLock = false; // When true, something else is being pressed so ignore everything
|
||||||
|
private bool toggled = false;
|
||||||
|
|
||||||
private Point labelOffset = new Point();
|
private Point labelOffset = new Point();
|
||||||
|
|
||||||
private bool enabled = true;
|
private bool enabled = true;
|
||||||
@ -94,6 +99,15 @@ namespace OpenDiablo2.Core.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Toggle()
|
||||||
|
{
|
||||||
|
toggled = !toggled;
|
||||||
|
|
||||||
|
OnToggle?.Invoke(toggled);
|
||||||
|
|
||||||
|
return toggled;
|
||||||
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
@ -126,7 +140,15 @@ namespace OpenDiablo2.Core.UI
|
|||||||
active = false;
|
active = false;
|
||||||
|
|
||||||
if (hovered)
|
if (hovered)
|
||||||
|
{
|
||||||
OnActivate?.Invoke();
|
OnActivate?.Invoke();
|
||||||
|
|
||||||
|
if (buttonLayout.Toggleable)
|
||||||
|
{
|
||||||
|
Toggle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (!active && mouseInfoProvider.LeftMouseDown)
|
else if (!active && mouseInfoProvider.LeftMouseDown)
|
||||||
{
|
{
|
||||||
@ -142,7 +164,22 @@ namespace OpenDiablo2.Core.UI
|
|||||||
|
|
||||||
public void Render()
|
public void Render()
|
||||||
{
|
{
|
||||||
renderWindow.Draw(sprite, buttonLayout.XSegments, 1, pressed ? 1 : 0);
|
var frame = 0;
|
||||||
|
|
||||||
|
if(toggled && pressed)
|
||||||
|
{
|
||||||
|
frame = 3;
|
||||||
|
}
|
||||||
|
else if(pressed)
|
||||||
|
{
|
||||||
|
frame = 1;
|
||||||
|
}
|
||||||
|
else if(toggled)
|
||||||
|
{
|
||||||
|
frame = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderWindow.Draw(sprite, buttonLayout.XSegments, 1, frame);
|
||||||
var offset = pressed ? -2 : 0;
|
var offset = pressed ? -2 : 0;
|
||||||
|
|
||||||
label.Location = new Point(location.X + offset + labelOffset.X, location.Y - offset + labelOffset.Y);
|
label.Location = new Point(location.X + offset + labelOffset.X, location.Y - offset + labelOffset.Y);
|
||||||
|
@ -8,12 +8,16 @@ using OpenDiablo2.Common;
|
|||||||
using OpenDiablo2.Common.Attributes;
|
using OpenDiablo2.Common.Attributes;
|
||||||
using OpenDiablo2.Common.Enums;
|
using OpenDiablo2.Common.Enums;
|
||||||
using OpenDiablo2.Common.Interfaces;
|
using OpenDiablo2.Common.Interfaces;
|
||||||
|
using OpenDiablo2.Core.GameState_;
|
||||||
|
using OpenDiablo2.Core.UI;
|
||||||
|
|
||||||
namespace OpenDiablo2.Scenes
|
namespace OpenDiablo2.Scenes
|
||||||
{
|
{
|
||||||
[Scene("Game")]
|
[Scene("Game")]
|
||||||
public sealed class Game : IScene
|
public sealed class Game : IScene
|
||||||
{
|
{
|
||||||
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private readonly IRenderWindow renderWindow;
|
private readonly IRenderWindow renderWindow;
|
||||||
private readonly IResourceManager resourceManager;
|
private readonly IResourceManager resourceManager;
|
||||||
private readonly IMapEngine mapEngine;
|
private readonly IMapEngine mapEngine;
|
||||||
@ -24,12 +28,15 @@ namespace OpenDiablo2.Scenes
|
|||||||
|
|
||||||
private ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite;
|
private ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite;
|
||||||
|
|
||||||
|
private Button runButton, menuButton;
|
||||||
|
|
||||||
public Game(
|
public Game(
|
||||||
IRenderWindow renderWindow,
|
IRenderWindow renderWindow,
|
||||||
IResourceManager resourceManager,
|
IResourceManager resourceManager,
|
||||||
IMapEngine mapEngine,
|
IMapEngine mapEngine,
|
||||||
IGameState gameState,
|
IGameState gameState,
|
||||||
IKeyboardInfoProvider keyboardInfoProvider
|
IKeyboardInfoProvider keyboardInfoProvider,
|
||||||
|
Func<eButtonType, Button> createButton
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.renderWindow = renderWindow;
|
this.renderWindow = renderWindow;
|
||||||
@ -38,9 +45,28 @@ namespace OpenDiablo2.Scenes
|
|||||||
this.gameState = gameState;
|
this.gameState = gameState;
|
||||||
this.keyboardInfoProvider = keyboardInfoProvider;
|
this.keyboardInfoProvider = keyboardInfoProvider;
|
||||||
|
|
||||||
|
|
||||||
panelSprite = renderWindow.LoadSprite(ResourcePaths.GamePanels, Palettes.Act1);
|
panelSprite = renderWindow.LoadSprite(ResourcePaths.GamePanels, Palettes.Act1);
|
||||||
healthManaSprite = renderWindow.LoadSprite(ResourcePaths.HealthMana, Palettes.Act1);
|
healthManaSprite = renderWindow.LoadSprite(ResourcePaths.HealthMana, Palettes.Act1);
|
||||||
gameGlobeOverlapSprite = renderWindow.LoadSprite(ResourcePaths.GameGlobeOverlap, Palettes.Act1);
|
gameGlobeOverlapSprite = renderWindow.LoadSprite(ResourcePaths.GameGlobeOverlap, Palettes.Act1);
|
||||||
|
|
||||||
|
runButton = createButton(eButtonType.Run);
|
||||||
|
runButton.Location = new Point(256, 570);
|
||||||
|
runButton.OnToggle = OnRunToggle;
|
||||||
|
|
||||||
|
menuButton = createButton(eButtonType.Menu);
|
||||||
|
menuButton.Location = new Point(393, 561);
|
||||||
|
menuButton.OnToggle = OnMenuToggle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMenuToggle(bool isToggled)
|
||||||
|
{
|
||||||
|
log.Debug("Menu Toggle: " + isToggled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRunToggle(bool isToggled)
|
||||||
|
{
|
||||||
|
log.Debug("Run Toggle: " + isToggled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render()
|
public void Render()
|
||||||
@ -75,10 +101,15 @@ namespace OpenDiablo2.Scenes
|
|||||||
renderWindow.Draw(healthManaSprite, 1, new Point(692, 588));
|
renderWindow.Draw(healthManaSprite, 1, new Point(692, 588));
|
||||||
renderWindow.Draw(gameGlobeOverlapSprite, 1, new Point(693, 591));
|
renderWindow.Draw(gameGlobeOverlapSprite, 1, new Point(693, 591));
|
||||||
|
|
||||||
|
runButton.Render();
|
||||||
|
menuButton.Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(long ms)
|
public void Update(long ms)
|
||||||
{
|
{
|
||||||
|
runButton.Update();
|
||||||
|
menuButton.Update();
|
||||||
|
|
||||||
var seconds = (float)ms / 1000f;
|
var seconds = (float)ms / 1000f;
|
||||||
var xMod = 0f;
|
var xMod = 0f;
|
||||||
var yMod = 0f;
|
var yMod = 0f;
|
||||||
|
Loading…
Reference in New Issue
Block a user