1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-25 11:36:26 -05:00

Added more button logic. Fixed transparency issues

This commit is contained in:
Tim Sarbin 2018-11-22 18:06:15 -05:00
parent b693f799ed
commit 679c1ee71f
11 changed files with 83 additions and 33 deletions

View File

@ -10,7 +10,7 @@ namespace OpenDiablo2.Common.Interfaces
public interface ILabel : IDisposable
{
string Text { get; set; }
Point Position { get; set; }
Point Location { get; set; }
Size TextArea { get; set; }
Color TextColor { get; set; }
}

View File

@ -12,5 +12,6 @@ namespace OpenDiablo2.Common.Interfaces
int Frame { get; set; }
int TotalFrames { get; }
Palette CurrentPalette { get; set; }
bool Blend { get; set; }
}
}

View File

@ -22,11 +22,17 @@ namespace OpenDiablo2.Common
public static string CursorDefault = "data\\global\\ui\\CURSOR\\ohand.DC6";
// --- Fonts ---
public static string Font6 = "data\\local\\font\\latin\\font6";
public static string Font8 = "data\\local\\font\\latin\\font8";
public static string Font16 = "data\\local\\font\\latin\\font16";
public static string Font24 = "data\\local\\font\\latin\\font24";
public static string Font30 = "data\\local\\font\\latin\\font30";
public static string FontFormal12 = "data\\local\\font\\latin\\fontformal12";
public static string FontFormal11 = "data\\local\\font\\latin\\fontformal11";
public static string FontFormal10 = "data\\local\\font\\latin\\fontformal10";
public static string FontExocet10 = "data\\local\\font\\latin\\fontexocet10";
public static string FontExocet8 = "data\\local\\font\\latin\\fontexocet8";
// --- UI ---
public static string WideButtonBlank = "data\\global\\ui\\FrontEnd\\WideButtonBlank.dc6";

View File

@ -20,7 +20,7 @@ namespace OpenDiablo2.Core
builder.RegisterType<GameEngine>().AsImplementedInterfaces().SingleInstance();
builder.RegisterType<MPQProvider>().As<IMPQProvider>().SingleInstance();
builder.RegisterType<WideButton>().AsSelf().InstancePerRequest();
builder.RegisterType<WideButton>().AsSelf().InstancePerDependency();
}
}
}

View File

@ -16,11 +16,23 @@ namespace OpenDiablo2.Core.UI
public delegate void OnActivateDelegate();
public OnActivateDelegate OnActivate { get; set; }
public Point Position { get; set; } = new Point();
ISprite sprite;
IFont font;
ILabel label;
private Point location = new Point();
public Point Location
{
get => location;
set
{
location = value;
sprite.Location = value;
}
}
private ISprite sprite;
private IFont font;
private ILabel label;
private bool pressed;
private Point labelOffset = new Point();
private string text;
public string Text
@ -39,7 +51,8 @@ namespace OpenDiablo2.Core.UI
this.mouseInfoProvider = mouseInfoProvider;
sprite = renderWindow.LoadSprite(ResourcePaths.WideButtonBlank, Palettes.Act1);
font = renderWindow.LoadFont(ResourcePaths.Font24, Palettes.Static);
font = renderWindow.LoadFont(ResourcePaths.FontExocet10, Palettes.Menu4);
label = renderWindow.CreateLabel(font);
}
public void Update()
@ -47,14 +60,28 @@ namespace OpenDiablo2.Core.UI
}
public void Draw()
public void Render()
{
renderWindow.Draw(sprite, 2, 1, pressed ? 1 : 0);
var offset = pressed ? -5 : 0;
label.Location = new Point(location.X + offset + labelOffset.X, location.Y + offset + labelOffset.Y);
renderWindow.Draw(label);
}
private void UpdateText()
{
label.Text = text;
label.TextColor = Color.FromArgb(128, 128, 128);
// TODO: Less stupid way of doing this would be nice
sprite.Frame = 0;
int btnWidth = sprite.LocalFrameSize.Width;
sprite.Frame = 1;
btnWidth += sprite.LocalFrameSize.Width;
var offsetX = (btnWidth / 2) - (label.TextArea.Width / 2);
labelOffset = new Point(offsetX, -5);
}
}
}

View File

@ -16,7 +16,7 @@ namespace OpenDiablo2.SDL2_
private readonly IntPtr renderer;
internal IntPtr texture;
internal Size textureSize = new Size();
public Point Position { get; set; }
public Point Location { get; set; }
public Size TextArea { get; set; } = new Size();
private Color textColor = Color.White;
@ -56,7 +56,7 @@ namespace OpenDiablo2.SDL2_
{
var metric = font.font.CharacterMetric[(byte)ch];
w += metric.Width;
h = Math.Max(h, metric.Height);
h = Math.Max(Math.Max(h, metric.Height), font.sprite.FrameSize.Height);
}
return new Size(w, h);

View File

@ -184,7 +184,7 @@ namespace OpenDiablo2.SDL2_
var result = new SDL2Label(font, renderer)
{
Text = text,
Position = position
Location = position
};
return result;
@ -193,7 +193,7 @@ namespace OpenDiablo2.SDL2_
public void Draw(ILabel label)
{
var lbl = label as SDL2Label;
var loc = lbl.Position;
var loc = lbl.Location;
var destRect = new SDL.SDL_Rect
{
@ -202,6 +202,7 @@ namespace OpenDiablo2.SDL2_
w = lbl.textureSize.Width,
h = lbl.textureSize.Height
};
SDL.SDL_RenderCopy(renderer, lbl.texture, IntPtr.Zero, ref destRect);
}
}

View File

@ -19,6 +19,18 @@ namespace OpenDiablo2.SDL2_
public int Frame { get; set; }
public int TotalFrames { get; internal set; }
private bool blend = false;
public bool Blend
{
get => blend;
set
{
blend = value;
foreach (var texture in textures)
SDL.SDL_SetTextureBlendMode(texture, blend ? SDL.SDL_BlendMode.SDL_BLENDMODE_ADD : SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
}
}
private Palette palette;
public Palette CurrentPalette
{

View File

@ -2,6 +2,7 @@
using OpenDiablo2.Common.Attributes;
using OpenDiablo2.Common.Interfaces;
using OpenDiablo2.Common.Models;
using OpenDiablo2.Core.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
@ -27,13 +28,15 @@ namespace OpenDiablo2.Scenes
private ISprite backgroundSprite, diabloLogoLeft, diabloLogoRight, diabloLogoLeftBlack, diabloLogoRightBlack;
private IFont labelFont;
private ILabel versionLabel, urlLabel;
private WideButton btnSinglePlayer;
public MainMenu(
IRenderWindow renderWindow,
IPaletteProvider paletteProvider,
IMPQProvider mpqProvider,
IMouseInfoProvider mouseInfoProvider,
IMusicProvider musicProvider
IMusicProvider musicProvider,
Func<WideButton> createWideButton
)
{
this.renderWindow = renderWindow;
@ -43,11 +46,15 @@ namespace OpenDiablo2.Scenes
backgroundSprite = renderWindow.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky);
diabloLogoLeft = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, Palettes.Units, new Point(400, 120));
diabloLogoLeft.Blend = true;
diabloLogoRight = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireRight, Palettes.Units, new Point(400, 120));
diabloLogoRight.Blend = true;
diabloLogoLeftBlack = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoBlackLeft, Palettes.Units, new Point(400, 120));
diabloLogoRightBlack = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoBlackRight, Palettes.Units, new Point(400, 120));
btnSinglePlayer = createWideButton();
btnSinglePlayer.Text = "Single Player".ToUpper();
btnSinglePlayer.Location = new Point(264, 290);
labelFont = renderWindow.LoadFont(ResourcePaths.Font16, Palettes.Static);
versionLabel = renderWindow.CreateLabel(labelFont, new Point(50, 555), "v0.01 Pre-Alpha");
@ -93,6 +100,8 @@ namespace OpenDiablo2.Scenes
renderWindow.Draw(urlLabel);
// Render the UI buttons
btnSinglePlayer.Render();
//wideButton.Location = new Point(264, 290);
//renderWindow.Draw(wideButton, 2, 1, 0);
}
@ -104,11 +113,18 @@ namespace OpenDiablo2.Scenes
while (logoFrame >= 1f)
logoFrame -= 1f;
btnSinglePlayer.Update();
}
public void Dispose()
{
}
private void OnSinglePlayerClicked()
{
}
}
}

View File

@ -13,23 +13,6 @@
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
@ -75,6 +58,10 @@
<Project>{b743160e-a0bb-45dc-9998-967a85e50562}</Project>
<Name>OpenDiablo2.Common</Name>
</ProjectReference>
<ProjectReference Include="..\OpenDiablo2.Core\OpenDiablo2.Core.csproj">
<Project>{8FC6BF7D-835A-47C1-A6B2-125495FA0900}</Project>
<Name>OpenDiablo2.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@ -37,8 +37,8 @@ Global
{1F8731D5-393B-4561-9CEA-887A2F466576}.Release|x64.Build.0 = Release|x64
{05224FE7-293F-4184-B1D6-89F5171B60E0}.Debug|x64.ActiveCfg = Debug|x64
{05224FE7-293F-4184-B1D6-89F5171B60E0}.Debug|x64.Build.0 = Debug|x64
{05224FE7-293F-4184-B1D6-89F5171B60E0}.Release|x64.ActiveCfg = Release|Any CPU
{05224FE7-293F-4184-B1D6-89F5171B60E0}.Release|x64.Build.0 = Release|Any CPU
{05224FE7-293F-4184-B1D6-89F5171B60E0}.Release|x64.ActiveCfg = Release|x64
{05224FE7-293F-4184-B1D6-89F5171B60E0}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE