mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-07 09:07:00 -05:00
Added button disable support. Added ability to darken sprite. Added ok button to char select
This commit is contained in:
parent
caa9c88d4e
commit
4c020c13bc
@ -13,5 +13,6 @@ namespace OpenDiablo2.Common.Interfaces
|
||||
int TotalFrames { get; }
|
||||
Palette CurrentPalette { get; set; }
|
||||
bool Blend { get; set; }
|
||||
bool Darken { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<eHero, HeroRenderInfo> heroRenderInfo = new Dictionary<eHero, HeroRenderInfo>();
|
||||
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user