From 4c020c13bc47e4ae866238fb533784dae635a7bd Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Fri, 23 Nov 2018 18:03:29 -0500 Subject: [PATCH] Added button disable support. Added ability to darken sprite. Added ok button to char select --- OpenDiablo2.Common/Interfaces/ISprite.cs | 1 + OpenDiablo2.Core/UI/Button.cs | 27 ++++++++++++++++++++++++ OpenDiablo2.SDL2/SDL2Sprite.cs | 21 ++++++++++++++---- OpenDiablo2.Scenes/SelectHeroClass.cs | 22 ++++++++++++++++++- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/OpenDiablo2.Common/Interfaces/ISprite.cs b/OpenDiablo2.Common/Interfaces/ISprite.cs index 585b1e90..18059a47 100644 --- a/OpenDiablo2.Common/Interfaces/ISprite.cs +++ b/OpenDiablo2.Common/Interfaces/ISprite.cs @@ -13,5 +13,6 @@ namespace OpenDiablo2.Common.Interfaces int TotalFrames { get; } Palette CurrentPalette { get; set; } bool Blend { get; set; } + bool Darken { get; set; } } } diff --git a/OpenDiablo2.Core/UI/Button.cs b/OpenDiablo2.Core/UI/Button.cs index d365bb51..580c7f24 100644 --- a/OpenDiablo2.Core/UI/Button.cs +++ b/OpenDiablo2.Core/UI/Button.cs @@ -40,6 +40,20 @@ namespace OpenDiablo2.Core.UI 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 Point labelOffset = new Point(); + + private bool enabled = true; + public bool Enabled + { + get => enabled; + set + { + if (value == enabled) + return; + enabled = value; + + sprite.Darken = !enabled; + } + } private string text; public string Text @@ -82,6 +96,19 @@ namespace OpenDiablo2.Core.UI public void Update() { + if (!enabled) + { + // Prevent sticky locks + if (activeLock && mouseInfoProvider.ReserveMouse) + { + activeLock = false; + mouseInfoProvider.ReserveMouse = false; + } + + active = false; + return; + } + var hovered = (mouseInfoProvider.MouseX >= location.X && mouseInfoProvider.MouseX < (location.X + buttonWidth)) && (mouseInfoProvider.MouseY >= location.Y && mouseInfoProvider.MouseY < (location.Y + buttonHeight)); diff --git a/OpenDiablo2.SDL2/SDL2Sprite.cs b/OpenDiablo2.SDL2/SDL2Sprite.cs index 8fa7fe8d..b7b20ee3 100644 --- a/OpenDiablo2.SDL2/SDL2Sprite.cs +++ b/OpenDiablo2.SDL2/SDL2Sprite.cs @@ -19,6 +19,19 @@ namespace OpenDiablo2.SDL2_ public Point Location { get; set; } = new Point(); public Size FrameSize { get; set; } = new Size(); + private bool darken; + public bool Darken + { + get => darken; + set + { + if (darken == value) + return; + darken = value; + LoadFrame(frame); + } + } + private int frame = -1; public int Frame { @@ -75,7 +88,6 @@ namespace OpenDiablo2.SDL2_ public Size LocalFrameSize => new Size((int)source.Frames[Frame].Width, (int)source.Frames[Frame].Height); - // TODO: This is slow. Make fix. private void UpdateTextureData() { if (texture == IntPtr.Zero) @@ -87,7 +99,6 @@ namespace OpenDiablo2.SDL2_ Frame = 0; } - } private unsafe void LoadFrame(int index) @@ -114,8 +125,10 @@ namespace OpenDiablo2.SDL2_ continue; } - - data[x + (y * (pitch / 4))] = frame.GetColor(x, (int)(y - frameOffset), CurrentPalette); + var color = frame.GetColor(x, (int)(y - frameOffset), CurrentPalette); + if (darken) + color = ((color & 0xFF000000) > 0) ? (color >> 1) & 0xFF7F7F7F | 0xFF000000 : 0; + data[x + (y * (pitch / 4))] = color; } } } diff --git a/OpenDiablo2.Scenes/SelectHeroClass.cs b/OpenDiablo2.Scenes/SelectHeroClass.cs index 29068c0f..c19ac9f9 100644 --- a/OpenDiablo2.Scenes/SelectHeroClass.cs +++ b/OpenDiablo2.Scenes/SelectHeroClass.cs @@ -54,12 +54,13 @@ namespace OpenDiablo2.Scenes private readonly ISceneManager sceneManager; private readonly ITextDictionary textDictionary; + private bool showEntryUi = false; private eHero? selectedHero = null; private float secondTimer; private ISprite backgroundSprite, campfireSprite; private IFont headingFont, heroDescFont; private ILabel headingLabel, heroClassLabel, heroDesc1Label, heroDesc2Label, heroDesc3Label; - private Button exitButton; + private Button exitButton, okButton; private Dictionary heroRenderInfo = new Dictionary(); public SelectHeroClass( @@ -211,6 +212,18 @@ namespace OpenDiablo2.Scenes exitButton.Text = "EXIT"; exitButton.Location = new Point(30, 540); exitButton.OnActivate = OnExitClicked; + + okButton = createButton(eButtonType.Medium); + okButton.Text = "OK"; + okButton.Location = new Point(630, 540); + okButton.OnActivate = OnOkclicked; + okButton.Enabled = false; + + } + + private void OnOkclicked() + { + } private void OnExitClicked() @@ -221,6 +234,7 @@ namespace OpenDiablo2.Scenes heroRenderInfo[hero].SpecialFrameTime = 0; heroRenderInfo[hero].Stance = eHeroStance.Idle; } + showEntryUi = false; sceneManager.ChangeScene("Main Menu"); } @@ -240,7 +254,11 @@ namespace OpenDiablo2.Scenes renderWindow.Draw(heroDesc2Label); renderWindow.Draw(heroDesc3Label); } + exitButton.Render(); + + if (showEntryUi) + okButton.Render(); } private void RenderHeros() @@ -313,6 +331,7 @@ namespace OpenDiablo2.Scenes } exitButton.Update(); + okButton.Update(); } private void UpdateHeroSelectionHover(eHero hero, long ms, bool canSelect) @@ -365,6 +384,7 @@ namespace OpenDiablo2.Scenes if (mouseHover && mouseInfoProvider.LeftMouseDown) { + showEntryUi = true; renderInfo.Stance = eHeroStance.Approaching; renderInfo.SpecialFrameTime = 0;