mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-07 09:07:00 -05:00
Added hero label text. Added dictionary. Fixed text redraw bug
This commit is contained in:
parent
e348d7b1e1
commit
6877df0b5a
13
OpenDiablo2.Common/Interfaces/ITextDictionary.cs
Normal file
13
OpenDiablo2.Common/Interfaces/ITextDictionary.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface ITextDictionary
|
||||
{
|
||||
string Translate(string key);
|
||||
}
|
||||
}
|
@ -85,6 +85,7 @@
|
||||
<Compile Include="Interfaces\ISceneManager.cs" />
|
||||
<Compile Include="Interfaces\ISprite.cs" />
|
||||
<Compile Include="Interfaces\IMouseInfoProvider.cs" />
|
||||
<Compile Include="Interfaces\ITextDictionary.cs" />
|
||||
<Compile Include="Interfaces\ITextLabel.cs" />
|
||||
<Compile Include="Models\BitStream.cs" />
|
||||
<Compile Include="Models\ButtonLayout.cs" />
|
||||
|
@ -74,7 +74,6 @@ namespace OpenDiablo2.Common
|
||||
public static string CharacterSelectDruidForwardWalk = "data\\global\\ui\\FrontEnd\\druid\\DZFW.DC6";
|
||||
public static string CharacterSelectDruidBackWalk = "data\\global\\ui\\FrontEnd\\druid\\DZBW.DC6";
|
||||
|
||||
|
||||
// --- Mouse Pointers ---
|
||||
public static string CursorDefault = "data\\global\\ui\\CURSOR\\ohand.DC6";
|
||||
|
||||
@ -90,11 +89,13 @@ namespace OpenDiablo2.Common
|
||||
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";
|
||||
public static string MediumButtonBlank = "data\\global\\ui\\FrontEnd\\MediumButtonBlank.dc6";
|
||||
public static string CancelButton = "data\\global\\ui\\FrontEnd\\CancelButtonBlank.dc6";
|
||||
|
||||
// --- Data ---
|
||||
// TODO: Doesn't sound right :)
|
||||
public static string EnglishTable = "data\\local\\lng\\eng\\English.txt";
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace OpenDiablo2.Core
|
||||
builder.RegisterType<GameEngine>().AsImplementedInterfaces().SingleInstance();
|
||||
builder.RegisterType<MPQProvider>().As<IMPQProvider>().SingleInstance();
|
||||
builder.RegisterType<ResourceManager>().As<IResourceManager>().SingleInstance();
|
||||
|
||||
builder.RegisterType<TextDictionary>().As<ITextDictionary>().SingleInstance();
|
||||
builder.RegisterType<Button>().AsSelf().InstancePerDependency();
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,7 @@
|
||||
<Compile Include="MPQProvider.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ResourceManager.cs" />
|
||||
<Compile Include="TextDictionary.cs" />
|
||||
<Compile Include="UI\Button.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
35
OpenDiablo2.Core/TextDictionary.cs
Normal file
35
OpenDiablo2.Core/TextDictionary.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
|
||||
namespace OpenDiablo2.Core
|
||||
{
|
||||
public sealed class TextDictionary : ITextDictionary
|
||||
{
|
||||
private readonly IMPQProvider mpqProvider;
|
||||
|
||||
private Dictionary<string, string> lookupTable = new Dictionary<string, string>();
|
||||
|
||||
public TextDictionary(IMPQProvider mpqProvider)
|
||||
{
|
||||
this.mpqProvider = mpqProvider;
|
||||
LoadDictionary();
|
||||
}
|
||||
|
||||
private void LoadDictionary()
|
||||
{
|
||||
var text = mpqProvider.GetTextFile(ResourcePaths.EnglishTable).First();
|
||||
|
||||
var rowstoLoad = text.Where(x => x.Split(',').Count() == 3).Select(x => x.Split(',').Select(z => z.Trim()).ToArray());
|
||||
foreach(var row in rowstoLoad)
|
||||
lookupTable[row[1]] = !(row[2].StartsWith("\"") && row[2].EndsWith("\"")) ? row[2] : row[2].Substring(1, row[2].Length - 2);
|
||||
|
||||
}
|
||||
|
||||
public string Translate(string key) => lookupTable[key];
|
||||
}
|
||||
}
|
@ -79,15 +79,15 @@ namespace OpenDiablo2.SDL2_
|
||||
|
||||
TextArea = CalculateSize();
|
||||
textureSize = new Size(Pow2(TextArea.Width), Pow2(TextArea.Height));
|
||||
texture = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, textureSize.Width, textureSize.Height);
|
||||
|
||||
texture = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, textureSize.Width, textureSize.Height);
|
||||
if (texture == IntPtr.Zero)
|
||||
throw new ApplicationException("Unaple to initialize texture.");
|
||||
|
||||
SDL.SDL_SetTextureBlendMode(texture, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
|
||||
SDL.SDL_SetRenderTarget(renderer, texture);
|
||||
SDL.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL.SDL_RenderFillRect(renderer, IntPtr.Zero);
|
||||
SDL.SDL_RenderClear(renderer);
|
||||
SDL.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
|
||||
int cx = 0;
|
||||
|
@ -90,15 +90,6 @@ namespace OpenDiablo2.SDL2_
|
||||
|
||||
}
|
||||
|
||||
// TODO: Less dumb color correction
|
||||
private Color AdjustColor(Color source)
|
||||
=> Color.FromArgb(
|
||||
source.A,
|
||||
(byte)Math.Min((float)source.R * 1.2, 255),
|
||||
(byte)Math.Min((float)source.G * 1.2, 255),
|
||||
(byte)Math.Min((float)source.B * 1.2, 255)
|
||||
);
|
||||
|
||||
private unsafe void LoadFrame(int index)
|
||||
{
|
||||
var frame = source.Frames[index];
|
||||
@ -124,9 +115,7 @@ namespace OpenDiablo2.SDL2_
|
||||
}
|
||||
|
||||
|
||||
var palColor = frame.GetColor(x, (int)(y - frameOffset), CurrentPalette);
|
||||
//var col = AdjustColor(palColor);
|
||||
data[x + (y * (pitch / 4))] = palColor;
|
||||
data[x + (y * (pitch / 4))] = frame.GetColor(x, (int)(y - frameOffset), CurrentPalette);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,11 +52,13 @@ namespace OpenDiablo2.Scenes
|
||||
private readonly IMouseInfoProvider mouseInfoProvider;
|
||||
private readonly IMusicProvider musicProvider;
|
||||
private readonly ISceneManager sceneManager;
|
||||
private readonly ITextDictionary textDictionary;
|
||||
|
||||
private eHero? selectedHero = null;
|
||||
private float secondTimer;
|
||||
private ISprite backgroundSprite, campfireSprite;
|
||||
private IFont headingFont;
|
||||
private ILabel headingLabel;
|
||||
private ILabel headingLabel, heroClassLabel;
|
||||
private Button exitButton;
|
||||
private Dictionary<eHero, HeroRenderInfo> heroRenderInfo = new Dictionary<eHero, HeroRenderInfo>();
|
||||
|
||||
@ -67,7 +69,8 @@ namespace OpenDiablo2.Scenes
|
||||
IMouseInfoProvider mouseInfoProvider,
|
||||
IMusicProvider musicProvider,
|
||||
ISceneManager sceneManager,
|
||||
Func<eButtonType, Button> createButton
|
||||
Func<eButtonType, Button> createButton,
|
||||
ITextDictionary textDictionary
|
||||
)
|
||||
{
|
||||
this.renderWindow = renderWindow;
|
||||
@ -75,6 +78,7 @@ namespace OpenDiablo2.Scenes
|
||||
this.mpqProvider = mpqProvider;
|
||||
this.mouseInfoProvider = mouseInfoProvider;
|
||||
this.sceneManager = sceneManager;
|
||||
this.textDictionary = textDictionary;
|
||||
|
||||
|
||||
backgroundSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectBackground, Palettes.Fechar);
|
||||
@ -189,10 +193,15 @@ namespace OpenDiablo2.Scenes
|
||||
};
|
||||
|
||||
headingFont = renderWindow.LoadFont(ResourcePaths.Font30, Palettes.Units);
|
||||
|
||||
headingLabel = renderWindow.CreateLabel(headingFont);
|
||||
headingLabel.Text = "Select Hero Class";
|
||||
headingLabel.Text = textDictionary.Translate("strSelectHeroClass");
|
||||
headingLabel.Location = new Point(400 - (headingLabel.TextArea.Width / 2), 17);
|
||||
|
||||
heroClassLabel = renderWindow.CreateLabel(headingFont);
|
||||
heroClassLabel.Text = "";
|
||||
heroClassLabel.Location = new Point(400 - (heroClassLabel.TextArea.Width / 2), 65);
|
||||
|
||||
exitButton = createButton(eButtonType.Medium);
|
||||
exitButton.Text = "EXIT";
|
||||
exitButton.Location = new Point(30, 540);
|
||||
@ -219,6 +228,8 @@ namespace OpenDiablo2.Scenes
|
||||
|
||||
renderWindow.Draw(campfireSprite, (int)(campfireSprite.TotalFrames * secondTimer));
|
||||
renderWindow.Draw(headingLabel);
|
||||
if (selectedHero.HasValue)
|
||||
renderWindow.Draw(heroClassLabel);
|
||||
exitButton.Render();
|
||||
}
|
||||
|
||||
@ -286,6 +297,11 @@ namespace OpenDiablo2.Scenes
|
||||
foreach (var hero in Enum.GetValues(typeof(eHero)).Cast<eHero>())
|
||||
UpdateHeroSelectionHover(hero, ms, canSelect);
|
||||
|
||||
if (selectedHero.HasValue && heroRenderInfo.All(x => x.Value.Stance == eHeroStance.Idle))
|
||||
{
|
||||
selectedHero = null;
|
||||
}
|
||||
|
||||
exitButton.Update();
|
||||
}
|
||||
|
||||
@ -353,10 +369,53 @@ namespace OpenDiablo2.Scenes
|
||||
break;
|
||||
}
|
||||
|
||||
selectedHero = hero;
|
||||
UpdateHeroText();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
heroRenderInfo[hero].Stance = mouseHover ? eHeroStance.IdleSelected : eHeroStance.Idle;
|
||||
|
||||
if (selectedHero == null && mouseHover)
|
||||
{
|
||||
selectedHero = hero;
|
||||
UpdateHeroText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void UpdateHeroText()
|
||||
{
|
||||
if (selectedHero == null)
|
||||
return;
|
||||
|
||||
switch (selectedHero.Value)
|
||||
{
|
||||
case eHero.Barbarian:
|
||||
heroClassLabel.Text = textDictionary.Translate("strBarbarian");
|
||||
break;
|
||||
case eHero.Necromancer:
|
||||
heroClassLabel.Text = textDictionary.Translate("strNecromancer");
|
||||
break;
|
||||
case eHero.Paladin:
|
||||
heroClassLabel.Text = textDictionary.Translate("strPaladin");
|
||||
break;
|
||||
case eHero.Assassin:
|
||||
heroClassLabel.Text = textDictionary.Translate("strAssassin");
|
||||
break;
|
||||
case eHero.Sorceress:
|
||||
heroClassLabel.Text = textDictionary.Translate("strSorceress");
|
||||
break;
|
||||
case eHero.Amazon:
|
||||
heroClassLabel.Text = textDictionary.Translate("strAmazon");
|
||||
break;
|
||||
case eHero.Druid:
|
||||
heroClassLabel.Text = textDictionary.Translate("strDruid");
|
||||
break;
|
||||
}
|
||||
|
||||
heroClassLabel.Location = new Point(400 - (heroClassLabel.TextArea.Width / 2), 65);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
Loading…
Reference in New Issue
Block a user