mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-25 19:46:50 -05:00
Detatched Core from Scenes
This commit is contained in:
parent
e4283e5f88
commit
ba6455317f
7
OpenDiablo2.Common/AutofacModule.cs
Normal file
7
OpenDiablo2.Common/AutofacModule.cs
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
* Hi there.
|
||||
* Looking to register an object from Common into DI, are ya?
|
||||
* Well don't. Go to the Slack channel and talk about it there.
|
||||
* If you add an autofac module to this project, your PR will be
|
||||
* rejected.
|
||||
*/
|
24
OpenDiablo2.Common/Interfaces/IButton.cs
Normal file
24
OpenDiablo2.Common/Interfaces/IButton.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public delegate void OnActivateDelegate();
|
||||
public delegate void OnToggleDelegate(bool isToggled);
|
||||
|
||||
public interface IButton : IDisposable
|
||||
{
|
||||
OnActivateDelegate OnActivate { get; set; }
|
||||
bool Enabled { get; set; }
|
||||
Point Location { get; set; }
|
||||
OnToggleDelegate OnToggle { get; set; }
|
||||
string Text { get; set; }
|
||||
|
||||
void Update();
|
||||
void Render();
|
||||
}
|
||||
}
|
14
OpenDiablo2.Common/Interfaces/IMiniPanel.cs
Normal file
14
OpenDiablo2.Common/Interfaces/IMiniPanel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface IMiniPanel : IDisposable
|
||||
{
|
||||
void Render();
|
||||
void Update();
|
||||
}
|
||||
}
|
17
OpenDiablo2.Common/Interfaces/ITextBox.cs
Normal file
17
OpenDiablo2.Common/Interfaces/ITextBox.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
public interface ITextBox : IDisposable
|
||||
{
|
||||
string Text { get; set; }
|
||||
Point Location { get; set; }
|
||||
void Render();
|
||||
void Update(long ms);
|
||||
}
|
||||
}
|
@ -70,11 +70,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes\SceneAttribute.cs" />
|
||||
<Compile Include="AutofacModule.cs" />
|
||||
<Compile Include="Enums\eButtonType.cs" />
|
||||
<Compile Include="Enums\eHero.cs" />
|
||||
<Compile Include="Enums\eLevelId.cs" />
|
||||
<Compile Include="Enums\eMPQFormatVersion.cs" />
|
||||
<Compile Include="Enums\eRenderCellType.cs" />
|
||||
<Compile Include="Interfaces\IButton.cs" />
|
||||
<Compile Include="Interfaces\IEngineDataManager.cs" />
|
||||
<Compile Include="Interfaces\IFont.cs" />
|
||||
<Compile Include="Interfaces\IGameEngine.cs" />
|
||||
@ -82,6 +84,7 @@
|
||||
<Compile Include="Interfaces\IKeyboardInfoProvider.cs" />
|
||||
<Compile Include="Interfaces\ILabel.cs" />
|
||||
<Compile Include="Interfaces\IMapEngine.cs" />
|
||||
<Compile Include="Interfaces\IMiniPanel.cs" />
|
||||
<Compile Include="Interfaces\IMPQProvider.cs" />
|
||||
<Compile Include="Interfaces\IMusicProvider.cs" />
|
||||
<Compile Include="Interfaces\IPaletteProvider.cs" />
|
||||
@ -92,6 +95,7 @@
|
||||
<Compile Include="Interfaces\ISceneManager.cs" />
|
||||
<Compile Include="Interfaces\ISprite.cs" />
|
||||
<Compile Include="Interfaces\IMouseInfoProvider.cs" />
|
||||
<Compile Include="Interfaces\ITextBox.cs" />
|
||||
<Compile Include="Interfaces\ITextDictionary.cs" />
|
||||
<Compile Include="Interfaces\ITextLabel.cs" />
|
||||
<Compile Include="Models\BitStream.cs" />
|
||||
|
@ -3,11 +3,6 @@ using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Core.GameState_;
|
||||
using OpenDiablo2.Core.Map_Engine;
|
||||
using OpenDiablo2.Core.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Core
|
||||
{
|
||||
@ -19,15 +14,16 @@ namespace OpenDiablo2.Core
|
||||
{
|
||||
log.Info("Configuring OpenDiablo2.Core service implementations.");
|
||||
|
||||
builder.RegisterType<Button>().As<IButton>().InstancePerDependency();
|
||||
builder.RegisterType<EngineDataManager>().As<IEngineDataManager>().SingleInstance();
|
||||
builder.RegisterType<GameEngine>().AsImplementedInterfaces().SingleInstance();
|
||||
builder.RegisterType<GameState>().As<IGameState>().SingleInstance();
|
||||
builder.RegisterType<MapEngine>().As<IMapEngine>().SingleInstance();
|
||||
builder.RegisterType<MiniPanel>().As<IMiniPanel>().InstancePerDependency();
|
||||
builder.RegisterType<MPQProvider>().As<IMPQProvider>().SingleInstance();
|
||||
builder.RegisterType<ResourceManager>().As<IResourceManager>().SingleInstance();
|
||||
builder.RegisterType<TextDictionary>().As<ITextDictionary>().SingleInstance();
|
||||
builder.RegisterType<Button>().AsSelf().InstancePerDependency(); // TODO: Never register as Self() if we aren't in common...
|
||||
builder.RegisterType<TextBox>().AsSelf().InstancePerDependency(); // TODO: Never register as Self() if we aren't in common...
|
||||
builder.RegisterType<GameState>().As<IGameState>().SingleInstance();
|
||||
builder.RegisterType<EngineDataManager>().As<IEngineDataManager>().SingleInstance();
|
||||
builder.RegisterType<MapEngine>().As<IMapEngine>().SingleInstance();
|
||||
builder.RegisterType<TextBox>().As<ITextBox>().InstancePerDependency();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@
|
||||
<Compile Include="TextDictionary.cs" />
|
||||
<Compile Include="UI\Button.cs" />
|
||||
<Compile Include="UI\TextBox.cs" />
|
||||
<Compile Include="UI\Minipanel.cs" />
|
||||
<Compile Include="UI\MiniPanel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenDiablo2.Common\OpenDiablo2.Common.csproj">
|
||||
@ -95,4 +95,4 @@
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
@ -1,217 +1,214 @@
|
||||
using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Common.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Core.UI
|
||||
{
|
||||
|
||||
|
||||
public sealed class Button : IDisposable
|
||||
{
|
||||
private readonly IMouseInfoProvider mouseInfoProvider;
|
||||
private readonly IRenderWindow renderWindow;
|
||||
private readonly ButtonLayout buttonLayout;
|
||||
|
||||
public delegate void OnActivateDelegate();
|
||||
public OnActivateDelegate OnActivate { get; set; }
|
||||
|
||||
public delegate void OnToggleDelegate(bool isToggled);
|
||||
public OnToggleDelegate OnToggle { get; set; }
|
||||
|
||||
private Point location = new Point();
|
||||
public Point Location
|
||||
{
|
||||
get => location;
|
||||
set
|
||||
{
|
||||
location = value;
|
||||
sprite.Location = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int buttonWidth, buttonHeight;
|
||||
private ISprite sprite;
|
||||
private IFont font;
|
||||
private ILabel label;
|
||||
private bool pressed = false;
|
||||
private bool active = false; // When true, button is actively being focus pressed
|
||||
private bool activeLock = false; // When true, we have locked the mouse from everything else
|
||||
private bool toggled = false;
|
||||
|
||||
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
|
||||
{
|
||||
get => text;
|
||||
set
|
||||
{
|
||||
text = value;
|
||||
UpdateText();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Button(
|
||||
ButtonLayout buttonLayout,
|
||||
IRenderWindow renderWindow,
|
||||
IMouseInfoProvider mouseInfoProvider
|
||||
)
|
||||
{
|
||||
this.buttonLayout = buttonLayout;
|
||||
this.renderWindow = renderWindow;
|
||||
this.mouseInfoProvider = mouseInfoProvider;
|
||||
|
||||
font = renderWindow.LoadFont(ResourcePaths.FontExocet10, Palettes.Units);
|
||||
label = renderWindow.CreateLabel(font);
|
||||
|
||||
|
||||
sprite = renderWindow.LoadSprite(buttonLayout.ResourceName, buttonLayout.PaletteName);
|
||||
|
||||
// TODO: Less stupid way of doing this would be nice
|
||||
buttonWidth = 0;
|
||||
buttonHeight = 0;
|
||||
for (int i = 0; i < buttonLayout.XSegments; i++)
|
||||
{
|
||||
sprite.Frame = i;
|
||||
buttonWidth += sprite.LocalFrameSize.Width;
|
||||
buttonHeight = Math.Max(buttonHeight, sprite.LocalFrameSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Toggle()
|
||||
{
|
||||
toggled = !toggled;
|
||||
|
||||
OnToggle?.Invoke(toggled);
|
||||
|
||||
return toggled;
|
||||
}
|
||||
|
||||
public bool Toggle(bool isToggled)
|
||||
{
|
||||
using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Common.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Core.UI
|
||||
{
|
||||
|
||||
|
||||
public sealed class Button : IButton
|
||||
{
|
||||
private readonly IMouseInfoProvider mouseInfoProvider;
|
||||
private readonly IRenderWindow renderWindow;
|
||||
private readonly ButtonLayout buttonLayout;
|
||||
|
||||
public OnActivateDelegate OnActivate { get; set; }
|
||||
public OnToggleDelegate OnToggle { get; set; }
|
||||
|
||||
private Point location = new Point();
|
||||
public Point Location
|
||||
{
|
||||
get => location;
|
||||
set
|
||||
{
|
||||
location = value;
|
||||
sprite.Location = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int buttonWidth, buttonHeight;
|
||||
private ISprite sprite;
|
||||
private IFont font;
|
||||
private ILabel label;
|
||||
private bool pressed = false;
|
||||
private bool active = false; // When true, button is actively being focus pressed
|
||||
private bool activeLock = false; // When true, we have locked the mouse from everything else
|
||||
private bool toggled = false;
|
||||
|
||||
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
|
||||
{
|
||||
get => text;
|
||||
set
|
||||
{
|
||||
text = value;
|
||||
UpdateText();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Button(
|
||||
ButtonLayout buttonLayout,
|
||||
IRenderWindow renderWindow,
|
||||
IMouseInfoProvider mouseInfoProvider
|
||||
)
|
||||
{
|
||||
this.buttonLayout = buttonLayout;
|
||||
this.renderWindow = renderWindow;
|
||||
this.mouseInfoProvider = mouseInfoProvider;
|
||||
|
||||
font = renderWindow.LoadFont(ResourcePaths.FontExocet10, Palettes.Units);
|
||||
label = renderWindow.CreateLabel(font);
|
||||
|
||||
|
||||
sprite = renderWindow.LoadSprite(buttonLayout.ResourceName, buttonLayout.PaletteName);
|
||||
|
||||
// TODO: Less stupid way of doing this would be nice
|
||||
buttonWidth = 0;
|
||||
buttonHeight = 0;
|
||||
for (int i = 0; i < buttonLayout.XSegments; i++)
|
||||
{
|
||||
sprite.Frame = i;
|
||||
buttonWidth += sprite.LocalFrameSize.Width;
|
||||
buttonHeight = Math.Max(buttonHeight, sprite.LocalFrameSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Toggle()
|
||||
{
|
||||
toggled = !toggled;
|
||||
|
||||
OnToggle?.Invoke(toggled);
|
||||
|
||||
return toggled;
|
||||
}
|
||||
|
||||
public bool Toggle(bool isToggled)
|
||||
{
|
||||
if(toggled != isToggled)
|
||||
{
|
||||
OnToggle?.Invoke(isToggled);
|
||||
|
||||
toggled = isToggled;
|
||||
}
|
||||
|
||||
return isToggled;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
|
||||
if (!activeLock && hovered && mouseInfoProvider.LeftMouseDown && !mouseInfoProvider.ReserveMouse)
|
||||
{
|
||||
// The button is being pressed down
|
||||
mouseInfoProvider.ReserveMouse = true;
|
||||
active = true;
|
||||
|
||||
}
|
||||
else if (active && !mouseInfoProvider.LeftMouseDown)
|
||||
{
|
||||
mouseInfoProvider.ReserveMouse = false;
|
||||
active = false;
|
||||
|
||||
if (hovered)
|
||||
{
|
||||
OnActivate?.Invoke();
|
||||
|
||||
if (buttonLayout.Toggleable)
|
||||
{
|
||||
Toggle();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (!active && mouseInfoProvider.LeftMouseDown)
|
||||
{
|
||||
activeLock = true;
|
||||
}
|
||||
else if (activeLock && !mouseInfoProvider.LeftMouseDown)
|
||||
{
|
||||
activeLock = false;
|
||||
}
|
||||
|
||||
pressed = (hovered && mouseInfoProvider.LeftMouseDown && active);
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
var frame = buttonLayout.BaseFrame;
|
||||
|
||||
if(toggled && pressed)
|
||||
{
|
||||
frame = buttonLayout.BaseFrame + 3;
|
||||
}
|
||||
else if(pressed)
|
||||
{
|
||||
frame = buttonLayout.BaseFrame + 1;
|
||||
}
|
||||
else if(toggled)
|
||||
{
|
||||
frame = buttonLayout.BaseFrame + 2;
|
||||
}
|
||||
|
||||
renderWindow.Draw(sprite, buttonLayout.XSegments, 1, frame);
|
||||
var offset = pressed ? -2 : 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(75, 75, 75);
|
||||
|
||||
var offsetX = (buttonWidth / 2) - (label.TextArea.Width / 2);
|
||||
labelOffset = new Point(offsetX, -5);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
sprite.Dispose();
|
||||
font.Dispose();
|
||||
label.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isToggled;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
|
||||
if (!activeLock && hovered && mouseInfoProvider.LeftMouseDown && !mouseInfoProvider.ReserveMouse)
|
||||
{
|
||||
// The button is being pressed down
|
||||
mouseInfoProvider.ReserveMouse = true;
|
||||
active = true;
|
||||
|
||||
}
|
||||
else if (active && !mouseInfoProvider.LeftMouseDown)
|
||||
{
|
||||
mouseInfoProvider.ReserveMouse = false;
|
||||
active = false;
|
||||
|
||||
if (hovered)
|
||||
{
|
||||
OnActivate?.Invoke();
|
||||
|
||||
if (buttonLayout.Toggleable)
|
||||
{
|
||||
Toggle();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (!active && mouseInfoProvider.LeftMouseDown)
|
||||
{
|
||||
activeLock = true;
|
||||
}
|
||||
else if (activeLock && !mouseInfoProvider.LeftMouseDown)
|
||||
{
|
||||
activeLock = false;
|
||||
}
|
||||
|
||||
pressed = (hovered && mouseInfoProvider.LeftMouseDown && active);
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
var frame = buttonLayout.BaseFrame;
|
||||
|
||||
if(toggled && pressed)
|
||||
{
|
||||
frame = buttonLayout.BaseFrame + 3;
|
||||
}
|
||||
else if(pressed)
|
||||
{
|
||||
frame = buttonLayout.BaseFrame + 1;
|
||||
}
|
||||
else if(toggled)
|
||||
{
|
||||
frame = buttonLayout.BaseFrame + 2;
|
||||
}
|
||||
|
||||
renderWindow.Draw(sprite, buttonLayout.XSegments, 1, frame);
|
||||
var offset = pressed ? -2 : 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(75, 75, 75);
|
||||
|
||||
var offsetX = (buttonWidth / 2) - (label.TextArea.Width / 2);
|
||||
labelOffset = new Point(offsetX, -5);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
sprite.Dispose();
|
||||
font.Dispose();
|
||||
label.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenDiablo2.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
|
||||
namespace OpenDiablo2.Core.UI
|
||||
{
|
||||
// TODO: Allow to set Minipanel.buttons.character.OnAction or similar for button delegates
|
||||
public sealed class Minipanel : IDisposable
|
||||
{
|
||||
private readonly IRenderWindow renderWindow;
|
||||
private ISprite sprite;
|
||||
|
||||
private Button characterBtn, inventoryBtn, skillBtn, automapBtn, messageBtn, questBtn, menuBtn;
|
||||
|
||||
private Point location = new Point();
|
||||
public Point Location
|
||||
{
|
||||
get => location;
|
||||
set
|
||||
{
|
||||
if (location == value)
|
||||
return;
|
||||
location = value;
|
||||
|
||||
sprite.Location = new Point(value.X, value.Y + sprite.LocalFrameSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public Minipanel(IRenderWindow renderWindow, Func<eButtonType, Button> createButton)
|
||||
{
|
||||
this.renderWindow = renderWindow;
|
||||
|
||||
sprite = renderWindow.LoadSprite(ResourcePaths.MinipanelSmall, Palettes.Units);
|
||||
Location = new Point(800/2-sprite.LocalFrameSize.Width/2, 526);
|
||||
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
|
||||
namespace OpenDiablo2.Core.UI
|
||||
{
|
||||
// TODO: Allow to set Minipanel.buttons.character.OnAction or similar for button delegates
|
||||
public sealed class MiniPanel : IMiniPanel
|
||||
{
|
||||
private readonly IRenderWindow renderWindow;
|
||||
private ISprite sprite;
|
||||
|
||||
private IButton characterBtn, inventoryBtn, skillBtn, automapBtn, messageBtn, questBtn, menuBtn;
|
||||
|
||||
private Point location = new Point();
|
||||
public Point Location
|
||||
{
|
||||
get => location;
|
||||
set
|
||||
{
|
||||
if (location == value)
|
||||
return;
|
||||
location = value;
|
||||
|
||||
sprite.Location = new Point(value.X, value.Y + sprite.LocalFrameSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public MiniPanel(IRenderWindow renderWindow, Func<eButtonType, IButton> createButton)
|
||||
{
|
||||
this.renderWindow = renderWindow;
|
||||
|
||||
sprite = renderWindow.LoadSprite(ResourcePaths.MinipanelSmall, Palettes.Units);
|
||||
Location = new Point(800/2-sprite.LocalFrameSize.Width/2, 526);
|
||||
|
||||
characterBtn = createButton(eButtonType.MinipanelCharacter);
|
||||
characterBtn.Location = new Point(3 + Location.X, 3 + Location.Y);
|
||||
|
||||
@ -49,44 +49,44 @@ namespace OpenDiablo2.Core.UI
|
||||
skillBtn.Location = new Point(45 + Location.X, 3 + Location.Y);
|
||||
|
||||
automapBtn = createButton(eButtonType.MinipanelAutomap);
|
||||
automapBtn.Location = new Point(66 + Location.X, 3 + Location.Y);
|
||||
|
||||
automapBtn.Location = new Point(66 + Location.X, 3 + Location.Y);
|
||||
|
||||
messageBtn = createButton(eButtonType.MinipanelMessage);
|
||||
messageBtn.Location = new Point(87 + Location.X, 3 + Location.Y);
|
||||
|
||||
questBtn = createButton(eButtonType.MinipanelQuest);
|
||||
questBtn.Location = new Point(108 + Location.X, 3 + Location.Y);
|
||||
|
||||
questBtn.Location = new Point(108 + Location.X, 3 + Location.Y);
|
||||
|
||||
menuBtn = createButton(eButtonType.MinipanelMenu);
|
||||
menuBtn.Location = new Point(129 + Location.X, 3 + Location.Y);
|
||||
}
|
||||
|
||||
|
||||
public void Update()
|
||||
{
|
||||
menuBtn.Location = new Point(129 + Location.X, 3 + Location.Y);
|
||||
}
|
||||
|
||||
|
||||
public void Update()
|
||||
{
|
||||
characterBtn.Update();
|
||||
inventoryBtn.Update();
|
||||
skillBtn.Update();
|
||||
automapBtn.Update();
|
||||
automapBtn.Update();
|
||||
messageBtn.Update();
|
||||
questBtn.Update();
|
||||
menuBtn.Update();
|
||||
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
renderWindow.Draw(sprite);
|
||||
questBtn.Update();
|
||||
menuBtn.Update();
|
||||
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
renderWindow.Draw(sprite);
|
||||
|
||||
characterBtn.Render();
|
||||
inventoryBtn.Render();
|
||||
skillBtn.Render();
|
||||
automapBtn.Render();
|
||||
automapBtn.Render();
|
||||
messageBtn.Render();
|
||||
questBtn.Render();
|
||||
menuBtn.Render();
|
||||
}
|
||||
|
||||
questBtn.Render();
|
||||
menuBtn.Render();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
characterBtn.Dispose();
|
||||
@ -98,6 +98,6 @@ namespace OpenDiablo2.Core.UI
|
||||
menuBtn.Dispose();
|
||||
|
||||
sprite.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ using OpenDiablo2.Common.Interfaces;
|
||||
|
||||
namespace OpenDiablo2.Core.UI
|
||||
{
|
||||
public sealed class TextBox
|
||||
public sealed class TextBox : ITextBox
|
||||
{
|
||||
private readonly IRenderWindow renderWindow;
|
||||
private ISprite sprite;
|
||||
@ -97,5 +97,10 @@ namespace OpenDiablo2.Core.UI
|
||||
if (frameTime < 0.5)
|
||||
renderWindow.Draw(linebar);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Attributes;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Core.GameState_;
|
||||
using OpenDiablo2.Core.UI;
|
||||
|
||||
namespace OpenDiablo2.Scenes
|
||||
{
|
||||
@ -28,9 +26,9 @@ namespace OpenDiablo2.Scenes
|
||||
|
||||
private ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite;
|
||||
|
||||
private Minipanel minipanel;
|
||||
private IMiniPanel minipanel;
|
||||
private bool showMinipanel = false;
|
||||
private Button runButton, menuButton;
|
||||
private IButton runButton, menuButton;
|
||||
|
||||
public Game(
|
||||
IRenderWindow renderWindow,
|
||||
@ -38,7 +36,8 @@ namespace OpenDiablo2.Scenes
|
||||
IMapEngine mapEngine,
|
||||
IGameState gameState,
|
||||
IKeyboardInfoProvider keyboardInfoProvider,
|
||||
Func<eButtonType, Button> createButton
|
||||
Func<eButtonType, IButton> createButton,
|
||||
Func<IMiniPanel> createMiniPanel
|
||||
)
|
||||
{
|
||||
this.renderWindow = renderWindow;
|
||||
@ -52,7 +51,7 @@ namespace OpenDiablo2.Scenes
|
||||
healthManaSprite = renderWindow.LoadSprite(ResourcePaths.HealthMana, Palettes.Act1);
|
||||
gameGlobeOverlapSprite = renderWindow.LoadSprite(ResourcePaths.GameGlobeOverlap, Palettes.Act1);
|
||||
|
||||
minipanel = new Minipanel(renderWindow, createButton);
|
||||
minipanel = createMiniPanel();
|
||||
// Maybe? Not sure.
|
||||
// miniPanel.OnMenuActivate();
|
||||
|
||||
|
@ -3,7 +3,6 @@ using OpenDiablo2.Common.Attributes;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Common.Models;
|
||||
using OpenDiablo2.Core.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
@ -30,7 +29,7 @@ namespace OpenDiablo2.Scenes
|
||||
private ISprite backgroundSprite, diabloLogoLeft, diabloLogoRight, diabloLogoLeftBlack, diabloLogoRightBlack;
|
||||
private IFont labelFont;
|
||||
private ILabel versionLabel, urlLabel;
|
||||
private Button btnSinglePlayer, btnExit, btnWebsite;
|
||||
private IButton btnSinglePlayer, btnExit, btnWebsite;
|
||||
|
||||
public MainMenu(
|
||||
IRenderWindow renderWindow,
|
||||
@ -40,7 +39,7 @@ namespace OpenDiablo2.Scenes
|
||||
IMusicProvider musicProvider,
|
||||
ISceneManager sceneManager,
|
||||
IResourceManager resourceManager,
|
||||
Func<eButtonType, Button> createButton,
|
||||
Func<eButtonType, IButton> createButton,
|
||||
Func<string, IScene> getScene // Temporary until SDL load functions are sped up
|
||||
)
|
||||
{
|
||||
|
@ -60,10 +60,6 @@
|
||||
<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" />
|
||||
|
@ -2,13 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenDiablo2.Common;
|
||||
using OpenDiablo2.Common.Attributes;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Core.UI;
|
||||
|
||||
namespace OpenDiablo2.Scenes
|
||||
{
|
||||
@ -52,8 +49,8 @@ namespace OpenDiablo2.Scenes
|
||||
private ISprite backgroundSprite, campfireSprite;
|
||||
private IFont headingFont, heroDescFont, uiFont;
|
||||
private ILabel headingLabel, heroClassLabel, heroDesc1Label, heroDesc2Label, heroDesc3Label, characterNameLabel;
|
||||
private Button exitButton, okButton;
|
||||
private TextBox characterNameTextBox;
|
||||
private IButton exitButton, okButton;
|
||||
private ITextBox characterNameTextBox;
|
||||
private Dictionary<eHero, HeroRenderInfo> heroRenderInfo = new Dictionary<eHero, HeroRenderInfo>();
|
||||
|
||||
public SelectHeroClass(
|
||||
@ -63,8 +60,8 @@ namespace OpenDiablo2.Scenes
|
||||
IMouseInfoProvider mouseInfoProvider,
|
||||
IMusicProvider musicProvider,
|
||||
ISceneManager sceneManager,
|
||||
Func<eButtonType, Button> createButton,
|
||||
Func<TextBox> createTextBox,
|
||||
Func<eButtonType, IButton> createButton,
|
||||
Func<ITextBox> createTextBox,
|
||||
ITextDictionary textDictionary,
|
||||
IKeyboardInfoProvider keyboardInfoProvider,
|
||||
IGameState gameState
|
||||
|
@ -66,10 +66,10 @@ namespace OpenDiablo2
|
||||
return (sceneName) => componentContext.ResolveKeyed<IScene>(sceneName);
|
||||
});
|
||||
|
||||
containerBuilder.Register<Func<eButtonType, Button>>(c =>
|
||||
containerBuilder.Register<Func<eButtonType, IButton>>(c =>
|
||||
{
|
||||
var componentContext = c.Resolve<IComponentContext>();
|
||||
return (buttonType) => componentContext.Resolve<Button>(new NamedParameter("buttonLayout", ButtonLayout.Values[buttonType]));
|
||||
return (buttonType) => componentContext.Resolve<IButton>(new NamedParameter("buttonLayout", ButtonLayout.Values[buttonType]));
|
||||
});
|
||||
|
||||
/* Uncomment the below if we support multiple textbox types
|
||||
|
Loading…
Reference in New Issue
Block a user