2018-11-22 20:23:00 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-11-23 12:18:59 -05:00
|
|
|
|
using System.Drawing;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using OpenDiablo2.Common;
|
|
|
|
|
using OpenDiablo2.Common.Attributes;
|
2018-11-22 22:53:05 -05:00
|
|
|
|
using OpenDiablo2.Common.Enums;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
using OpenDiablo2.Common.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace OpenDiablo2.Scenes
|
|
|
|
|
{
|
2018-11-23 11:43:21 -05:00
|
|
|
|
|
|
|
|
|
enum eHeroStance
|
|
|
|
|
{
|
|
|
|
|
Idle,
|
|
|
|
|
IdleSelected,
|
|
|
|
|
Approaching,
|
|
|
|
|
Selected,
|
|
|
|
|
Retreating
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 12:18:59 -05:00
|
|
|
|
class HeroRenderInfo
|
2018-11-23 11:43:21 -05:00
|
|
|
|
{
|
2018-11-23 14:19:48 -05:00
|
|
|
|
public ISprite IdleSprite, IdleSelectedSprite, ForwardWalkSprite, ForwardWalkSpriteOverlay, SelectedSprite, SelectedSpriteOverlay, BackWalkSprite, BackWalkSpriteOverlay;
|
2018-11-23 11:43:21 -05:00
|
|
|
|
public eHeroStance Stance;
|
2018-11-23 14:19:48 -05:00
|
|
|
|
public long ForwardWalkTimeMs, BackWalkTimeMs;
|
|
|
|
|
public long SpecialFrameTime;
|
2018-11-23 12:18:59 -05:00
|
|
|
|
public Rectangle SelectionBounds = new Rectangle();
|
2018-11-23 11:43:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-08 09:12:40 -05:00
|
|
|
|
[Scene(eSceneType.SelectHeroClass)]
|
2018-11-22 20:23:00 -05:00
|
|
|
|
public sealed class SelectHeroClass : IScene
|
|
|
|
|
{
|
|
|
|
|
private readonly IRenderWindow renderWindow;
|
|
|
|
|
private readonly IMouseInfoProvider mouseInfoProvider;
|
|
|
|
|
private readonly ISceneManager sceneManager;
|
2018-11-23 16:38:21 -05:00
|
|
|
|
private readonly ITextDictionary textDictionary;
|
2018-11-23 20:51:32 -05:00
|
|
|
|
private readonly IKeyboardInfoProvider keyboardInfoProvider;
|
2018-11-24 22:34:16 -05:00
|
|
|
|
private readonly IGameState gameState;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
|
2018-11-23 18:03:29 -05:00
|
|
|
|
private bool showEntryUi = false;
|
2018-11-23 16:38:21 -05:00
|
|
|
|
private eHero? selectedHero = null;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
private float secondTimer;
|
2018-12-08 09:32:09 -05:00
|
|
|
|
private readonly ISprite backgroundSprite, campfireSprite;
|
|
|
|
|
private readonly IFont headingFont;
|
|
|
|
|
private readonly IFont heroDescFont;
|
|
|
|
|
private readonly IFont uiFont;
|
|
|
|
|
private readonly ILabel headingLabel, heroClassLabel, heroDesc1Label, heroDesc2Label, heroDesc3Label, characterNameLabel;
|
|
|
|
|
private readonly IButton exitButton, okButton;
|
|
|
|
|
private readonly ITextBox characterNameTextBox;
|
|
|
|
|
private readonly Dictionary<eHero, HeroRenderInfo> heroRenderInfo = new Dictionary<eHero, HeroRenderInfo>();
|
2018-11-22 20:23:00 -05:00
|
|
|
|
|
|
|
|
|
public SelectHeroClass(
|
|
|
|
|
IRenderWindow renderWindow,
|
|
|
|
|
IMouseInfoProvider mouseInfoProvider,
|
2018-11-22 22:53:05 -05:00
|
|
|
|
ISceneManager sceneManager,
|
2018-11-26 18:18:23 -05:00
|
|
|
|
Func<eButtonType, IButton> createButton,
|
|
|
|
|
Func<ITextBox> createTextBox,
|
2018-11-23 20:51:32 -05:00
|
|
|
|
ITextDictionary textDictionary,
|
2018-11-23 21:56:30 -05:00
|
|
|
|
IKeyboardInfoProvider keyboardInfoProvider,
|
2018-11-24 22:34:16 -05:00
|
|
|
|
IGameState gameState
|
2018-11-22 20:23:00 -05:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
this.renderWindow = renderWindow;
|
|
|
|
|
this.mouseInfoProvider = mouseInfoProvider;
|
|
|
|
|
this.sceneManager = sceneManager;
|
2018-11-23 16:38:21 -05:00
|
|
|
|
this.textDictionary = textDictionary;
|
2018-11-23 20:51:32 -05:00
|
|
|
|
this.keyboardInfoProvider = keyboardInfoProvider;
|
2018-11-23 21:56:30 -05:00
|
|
|
|
this.gameState = gameState;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
|
2018-11-23 11:43:21 -05:00
|
|
|
|
|
2018-11-22 20:23:00 -05:00
|
|
|
|
backgroundSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectBackground, Palettes.Fechar);
|
2018-11-23 14:19:48 -05:00
|
|
|
|
campfireSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectCampfire, Palettes.Fechar, new Point(380, 335));
|
|
|
|
|
campfireSprite.Blend = true;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
|
2018-11-23 11:43:21 -05:00
|
|
|
|
heroRenderInfo[eHero.Barbarian] = new HeroRenderInfo
|
|
|
|
|
{
|
|
|
|
|
Stance = eHeroStance.Idle,
|
2018-11-23 14:19:48 -05:00
|
|
|
|
IdleSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectBarbarianUnselected, Palettes.Fechar, new Point(400, 330)),
|
|
|
|
|
IdleSelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectBarbarianUnselectedH, Palettes.Fechar, new Point(400, 330)),
|
|
|
|
|
ForwardWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectBarbarianForwardWalk, Palettes.Fechar, new Point(400, 330)),
|
|
|
|
|
ForwardWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelectBarbarianForwardWalkOverlay, Palettes.Fechar, new Point(400, 330)),
|
|
|
|
|
SelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectBarbarianSelected, Palettes.Fechar, new Point(400, 330)),
|
|
|
|
|
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectBarbarianBackWalk, Palettes.Fechar, new Point(400, 330)),
|
|
|
|
|
SelectionBounds = new Rectangle(364, 201, 90, 170),
|
|
|
|
|
ForwardWalkTimeMs = 3000,
|
|
|
|
|
BackWalkTimeMs = 1000
|
2018-11-23 11:43:21 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
heroRenderInfo[eHero.Sorceress] = new HeroRenderInfo
|
|
|
|
|
{
|
|
|
|
|
Stance = eHeroStance.Idle,
|
2018-11-23 14:19:48 -05:00
|
|
|
|
IdleSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecSorceressUnselected, Palettes.Fechar, new Point(626, 352)),
|
|
|
|
|
IdleSelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecSorceressUnselectedH, Palettes.Fechar, new Point(626, 352)),
|
|
|
|
|
ForwardWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecSorceressForwardWalk, Palettes.Fechar, new Point(626, 352)),
|
|
|
|
|
ForwardWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecSorceressForwardWalkOverlay, Palettes.Fechar, new Point(626, 352)),
|
|
|
|
|
SelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecSorceressSelected, Palettes.Fechar, new Point(626, 352)),
|
|
|
|
|
SelectedSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecSorceressSelectedOverlay, Palettes.Fechar, new Point(626, 352)),
|
|
|
|
|
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecSorceressBackWalk, Palettes.Fechar, new Point(626, 352)),
|
|
|
|
|
BackWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecSorceressBackWalkOverlay, Palettes.Fechar, new Point(626, 352)),
|
|
|
|
|
SelectionBounds = new Rectangle(580, 240, 65, 160),
|
|
|
|
|
ForwardWalkTimeMs = 3000,
|
|
|
|
|
BackWalkTimeMs = 1200
|
2018-11-23 11:43:21 -05:00
|
|
|
|
};
|
2018-11-23 14:19:48 -05:00
|
|
|
|
heroRenderInfo[eHero.Sorceress].SelectedSpriteOverlay.Blend = true;
|
|
|
|
|
heroRenderInfo[eHero.Sorceress].ForwardWalkSpriteOverlay.Blend = true;
|
|
|
|
|
heroRenderInfo[eHero.Sorceress].BackWalkSpriteOverlay.Blend = true;
|
|
|
|
|
|
2018-11-23 11:43:21 -05:00
|
|
|
|
|
|
|
|
|
heroRenderInfo[eHero.Necromancer] = new HeroRenderInfo
|
|
|
|
|
{
|
|
|
|
|
Stance = eHeroStance.Idle,
|
2018-11-23 14:19:48 -05:00
|
|
|
|
IdleSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectNecromancerUnselected, Palettes.Fechar, new Point(300, 335)),
|
|
|
|
|
IdleSelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectNecromancerUnselectedH, Palettes.Fechar, new Point(300, 335)),
|
|
|
|
|
ForwardWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerForwardWalk, Palettes.Fechar, new Point(300, 335)),
|
|
|
|
|
ForwardWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerForwardWalkOverlay, Palettes.Fechar, new Point(300, 335)),
|
|
|
|
|
SelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerSelected, Palettes.Fechar, new Point(300, 335)),
|
|
|
|
|
SelectedSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerSelectedOverlay, Palettes.Fechar, new Point(300, 335)),
|
|
|
|
|
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalk, Palettes.Fechar, new Point(300, 335)),
|
|
|
|
|
BackWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalkOverlay, Palettes.Fechar, new Point(300, 335)),
|
|
|
|
|
SelectionBounds = new Rectangle(265, 220, 55, 175),
|
2018-11-25 09:42:39 -05:00
|
|
|
|
ForwardWalkTimeMs = 2000,
|
2018-11-23 14:19:48 -05:00
|
|
|
|
BackWalkTimeMs = 1500,
|
2018-11-23 11:43:21 -05:00
|
|
|
|
};
|
2018-11-23 14:19:48 -05:00
|
|
|
|
heroRenderInfo[eHero.Necromancer].ForwardWalkSpriteOverlay.Blend = true;
|
|
|
|
|
heroRenderInfo[eHero.Necromancer].BackWalkSpriteOverlay.Blend = true;
|
|
|
|
|
heroRenderInfo[eHero.Necromancer].SelectedSpriteOverlay.Blend = true;
|
2018-11-23 11:43:21 -05:00
|
|
|
|
|
|
|
|
|
heroRenderInfo[eHero.Paladin] = new HeroRenderInfo
|
|
|
|
|
{
|
|
|
|
|
Stance = eHeroStance.Idle,
|
2018-11-23 14:19:48 -05:00
|
|
|
|
IdleSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectPaladinUnselected, Palettes.Fechar, new Point(521, 338)),
|
|
|
|
|
IdleSelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectPaladinUnselectedH, Palettes.Fechar, new Point(521, 338)),
|
|
|
|
|
ForwardWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecPaladinForwardWalk, Palettes.Fechar, new Point(521, 338)),
|
|
|
|
|
ForwardWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecPaladinForwardWalkOverlay, Palettes.Fechar, new Point(521, 338)),
|
|
|
|
|
SelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecPaladinSelected, Palettes.Fechar, new Point(521, 338)),
|
|
|
|
|
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecPaladinBackWalk, Palettes.Fechar, new Point(521, 338)),
|
|
|
|
|
SelectionBounds = new Rectangle(490, 210, 65, 180),
|
|
|
|
|
ForwardWalkTimeMs = 4000,
|
|
|
|
|
BackWalkTimeMs = 1300
|
2018-11-23 11:43:21 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
heroRenderInfo[eHero.Amazon] = new HeroRenderInfo
|
|
|
|
|
{
|
|
|
|
|
Stance = eHeroStance.Idle,
|
2018-11-23 14:19:48 -05:00
|
|
|
|
IdleSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectAmazonUnselected, Palettes.Fechar, new Point(100, 339)),
|
|
|
|
|
IdleSelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectAmazonUnselectedH, Palettes.Fechar, new Point(100, 339)),
|
|
|
|
|
ForwardWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecAmazonForwardWalk, Palettes.Fechar, new Point(100, 339)),
|
|
|
|
|
//ForwardWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecAmazonForwardWalkOverlay, Palettes.Fechar, new Point(100, 339)),
|
|
|
|
|
SelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecAmazonSelected, Palettes.Fechar, new Point(100, 339)),
|
|
|
|
|
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecAmazonBackWalk, Palettes.Fechar, new Point(100, 339)),
|
|
|
|
|
SelectionBounds = new Rectangle(70, 220, 55, 200),
|
|
|
|
|
ForwardWalkTimeMs = 2600,
|
|
|
|
|
BackWalkTimeMs = 1500
|
2018-11-23 11:43:21 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
heroRenderInfo[eHero.Assassin] = new HeroRenderInfo
|
|
|
|
|
{
|
|
|
|
|
Stance = eHeroStance.Idle,
|
2018-11-23 14:19:48 -05:00
|
|
|
|
IdleSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectAssassinUnselected, Palettes.Fechar, new Point(231, 365)),
|
|
|
|
|
IdleSelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectAssassinUnselectedH, Palettes.Fechar, new Point(231, 365)),
|
|
|
|
|
ForwardWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectAssassinForwardWalk, Palettes.Fechar, new Point(231, 365)),
|
|
|
|
|
SelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectAssassinSelected, Palettes.Fechar, new Point(231, 365)),
|
|
|
|
|
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectAssassinBackWalk, Palettes.Fechar, new Point(231, 365)),
|
|
|
|
|
SelectionBounds = new Rectangle(175, 235, 50, 180),
|
|
|
|
|
ForwardWalkTimeMs = 3000,
|
|
|
|
|
BackWalkTimeMs = 1500
|
2018-11-23 11:43:21 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
heroRenderInfo[eHero.Druid] = new HeroRenderInfo
|
|
|
|
|
{
|
|
|
|
|
Stance = eHeroStance.Idle,
|
2018-11-23 14:19:48 -05:00
|
|
|
|
IdleSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectDruidUnselected, Palettes.Fechar, new Point(720, 370)),
|
|
|
|
|
IdleSelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectDruidUnselectedH, Palettes.Fechar, new Point(720, 370)),
|
|
|
|
|
ForwardWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectDruidForwardWalk, Palettes.Fechar, new Point(720, 370)),
|
|
|
|
|
SelectedSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectDruidSelected, Palettes.Fechar, new Point(720, 370)),
|
|
|
|
|
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelectDruidBackWalk, Palettes.Fechar, new Point(720, 370)),
|
|
|
|
|
SelectionBounds = new Rectangle(680, 220, 70, 195),
|
|
|
|
|
ForwardWalkTimeMs = 3000,
|
|
|
|
|
BackWalkTimeMs = 1500
|
2018-11-23 11:43:21 -05:00
|
|
|
|
};
|
2018-11-23 00:41:39 -05:00
|
|
|
|
|
2018-11-22 20:23:00 -05:00
|
|
|
|
headingFont = renderWindow.LoadFont(ResourcePaths.Font30, Palettes.Units);
|
2018-11-23 16:50:22 -05:00
|
|
|
|
heroDescFont = renderWindow.LoadFont(ResourcePaths.Font16, Palettes.Units);
|
2018-11-23 20:51:32 -05:00
|
|
|
|
uiFont = renderWindow.LoadFont(ResourcePaths.Font16, Palettes.Units);
|
2018-11-23 16:38:21 -05:00
|
|
|
|
|
2018-11-22 20:23:00 -05:00
|
|
|
|
headingLabel = renderWindow.CreateLabel(headingFont);
|
2018-11-23 16:38:21 -05:00
|
|
|
|
headingLabel.Text = textDictionary.Translate("strSelectHeroClass");
|
2018-11-23 14:19:48 -05:00
|
|
|
|
headingLabel.Location = new Point(400 - (headingLabel.TextArea.Width / 2), 17);
|
2018-11-22 20:23:00 -05:00
|
|
|
|
|
2018-11-23 16:38:21 -05:00
|
|
|
|
heroClassLabel = renderWindow.CreateLabel(headingFont);
|
|
|
|
|
heroClassLabel.Text = "";
|
|
|
|
|
heroClassLabel.Location = new Point(400 - (heroClassLabel.TextArea.Width / 2), 65);
|
|
|
|
|
|
2018-11-23 16:50:22 -05:00
|
|
|
|
heroDesc1Label = renderWindow.CreateLabel(heroDescFont);
|
|
|
|
|
heroDesc2Label = renderWindow.CreateLabel(heroDescFont);
|
|
|
|
|
heroDesc3Label = renderWindow.CreateLabel(heroDescFont);
|
|
|
|
|
|
2018-11-23 20:51:32 -05:00
|
|
|
|
characterNameLabel = renderWindow.CreateLabel(uiFont);
|
2018-11-25 19:06:22 -05:00
|
|
|
|
characterNameLabel.Text = textDictionary.Translate("strCharacterName");
|
2018-11-23 20:51:32 -05:00
|
|
|
|
characterNameLabel.Location = new Point(320, 475);
|
|
|
|
|
characterNameLabel.TextColor = Color.FromArgb(216, 196, 128);
|
|
|
|
|
|
2018-11-22 23:44:01 -05:00
|
|
|
|
exitButton = createButton(eButtonType.Medium);
|
2018-11-25 19:06:22 -05:00
|
|
|
|
exitButton.Text = textDictionary.Translate("strExit");
|
2018-11-28 22:25:08 -05:00
|
|
|
|
exitButton.Location = new Point(33, 540);
|
2018-11-22 22:53:05 -05:00
|
|
|
|
exitButton.OnActivate = OnExitClicked;
|
2018-11-23 18:03:29 -05:00
|
|
|
|
|
|
|
|
|
okButton = createButton(eButtonType.Medium);
|
2018-11-25 19:06:22 -05:00
|
|
|
|
okButton.Text = textDictionary.Translate("strOk");
|
2018-11-23 18:03:29 -05:00
|
|
|
|
okButton.Location = new Point(630, 540);
|
|
|
|
|
okButton.OnActivate = OnOkclicked;
|
|
|
|
|
okButton.Enabled = false;
|
|
|
|
|
|
2018-11-23 20:51:32 -05:00
|
|
|
|
characterNameTextBox = createTextBox();
|
|
|
|
|
characterNameTextBox.Text = "";
|
|
|
|
|
characterNameTextBox.Location = new Point(320, 493);
|
|
|
|
|
|
2018-11-23 18:03:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnOkclicked()
|
|
|
|
|
{
|
2018-11-29 23:26:51 -05:00
|
|
|
|
// TODO: Support other session types
|
|
|
|
|
gameState.Initialize(characterNameTextBox.Text, selectedHero.Value, eSessionType.Local);
|
2018-11-22 22:53:05 -05:00
|
|
|
|
}
|
2018-11-22 20:23:00 -05:00
|
|
|
|
|
2018-11-22 22:53:05 -05:00
|
|
|
|
private void OnExitClicked()
|
|
|
|
|
{
|
2018-11-23 14:19:48 -05:00
|
|
|
|
var heros = Enum.GetValues(typeof(eHero)).Cast<eHero>();
|
|
|
|
|
foreach(var hero in heros)
|
|
|
|
|
{
|
|
|
|
|
heroRenderInfo[hero].SpecialFrameTime = 0;
|
|
|
|
|
heroRenderInfo[hero].Stance = eHeroStance.Idle;
|
|
|
|
|
}
|
2018-11-23 18:03:29 -05:00
|
|
|
|
showEntryUi = false;
|
2018-11-23 20:51:32 -05:00
|
|
|
|
keyboardInfoProvider.KeyPressCallback = null;
|
|
|
|
|
characterNameTextBox.Text = "";
|
|
|
|
|
okButton.Enabled = false;
|
2018-11-27 00:32:50 -05:00
|
|
|
|
selectedHero = null;
|
2018-11-23 14:19:48 -05:00
|
|
|
|
|
2018-12-08 09:12:40 -05:00
|
|
|
|
sceneManager.ChangeScene(eSceneType.SelectCharacter);
|
2018-11-22 20:23:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Render()
|
|
|
|
|
{
|
|
|
|
|
renderWindow.Draw(backgroundSprite, 4, 3, 0);
|
2018-11-23 00:41:39 -05:00
|
|
|
|
|
2018-11-23 11:43:21 -05:00
|
|
|
|
RenderHeros();
|
2018-11-23 00:41:39 -05:00
|
|
|
|
|
2018-11-22 20:23:00 -05:00
|
|
|
|
renderWindow.Draw(campfireSprite, (int)(campfireSprite.TotalFrames * secondTimer));
|
2018-11-22 22:53:05 -05:00
|
|
|
|
renderWindow.Draw(headingLabel);
|
2018-11-23 16:38:21 -05:00
|
|
|
|
if (selectedHero.HasValue)
|
2018-11-23 16:50:22 -05:00
|
|
|
|
{
|
2018-11-23 16:38:21 -05:00
|
|
|
|
renderWindow.Draw(heroClassLabel);
|
2018-11-23 16:50:22 -05:00
|
|
|
|
renderWindow.Draw(heroDesc1Label);
|
|
|
|
|
renderWindow.Draw(heroDesc2Label);
|
|
|
|
|
renderWindow.Draw(heroDesc3Label);
|
|
|
|
|
}
|
2018-11-23 18:03:29 -05:00
|
|
|
|
|
2018-11-22 22:53:05 -05:00
|
|
|
|
exitButton.Render();
|
2018-11-23 18:03:29 -05:00
|
|
|
|
|
|
|
|
|
if (showEntryUi)
|
2018-11-23 20:51:32 -05:00
|
|
|
|
{
|
|
|
|
|
renderWindow.Draw(characterNameLabel);
|
2018-11-23 18:03:29 -05:00
|
|
|
|
okButton.Render();
|
2018-11-23 20:51:32 -05:00
|
|
|
|
characterNameTextBox.Render();
|
|
|
|
|
}
|
2018-11-22 20:23:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 11:43:21 -05:00
|
|
|
|
private void RenderHeros()
|
|
|
|
|
{
|
2018-11-23 14:19:48 -05:00
|
|
|
|
var heros = Enum.GetValues(typeof(eHero)).Cast<eHero>();
|
|
|
|
|
foreach (var hero in heros)
|
|
|
|
|
if (heroRenderInfo[hero].Stance == eHeroStance.Idle || heroRenderInfo[hero].Stance == eHeroStance.IdleSelected)
|
|
|
|
|
RenderHero(hero);
|
|
|
|
|
|
|
|
|
|
foreach (var hero in heros)
|
|
|
|
|
if (heroRenderInfo[hero].Stance != eHeroStance.Idle && heroRenderInfo[hero].Stance != eHeroStance.IdleSelected)
|
|
|
|
|
RenderHero(hero);
|
2018-11-23 11:43:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RenderHero(eHero hero)
|
|
|
|
|
{
|
|
|
|
|
var renderInfo = heroRenderInfo[hero];
|
|
|
|
|
switch (renderInfo.Stance)
|
|
|
|
|
{
|
|
|
|
|
case eHeroStance.Idle:
|
|
|
|
|
renderWindow.Draw(renderInfo.IdleSprite, (int)(renderInfo.IdleSprite.TotalFrames * secondTimer));
|
|
|
|
|
break;
|
|
|
|
|
case eHeroStance.IdleSelected:
|
|
|
|
|
renderWindow.Draw(renderInfo.IdleSelectedSprite, (int)(renderInfo.IdleSelectedSprite.TotalFrames * secondTimer));
|
|
|
|
|
break;
|
|
|
|
|
case eHeroStance.Approaching:
|
2018-11-23 14:19:48 -05:00
|
|
|
|
{
|
2018-12-08 13:31:50 -05:00
|
|
|
|
var framePct = renderInfo.SpecialFrameTime / (float)renderInfo.ForwardWalkTimeMs;
|
2018-11-23 14:19:48 -05:00
|
|
|
|
renderWindow.Draw(renderInfo.ForwardWalkSprite, (int)(renderInfo.ForwardWalkSprite.TotalFrames * framePct));
|
|
|
|
|
if (renderInfo.ForwardWalkSpriteOverlay != null)
|
|
|
|
|
renderWindow.Draw(renderInfo.ForwardWalkSpriteOverlay, (int)(renderInfo.ForwardWalkSpriteOverlay.TotalFrames * framePct));
|
|
|
|
|
}
|
2018-11-23 11:43:21 -05:00
|
|
|
|
break;
|
|
|
|
|
case eHeroStance.Selected:
|
2018-11-23 14:19:48 -05:00
|
|
|
|
{
|
2018-12-08 13:31:50 -05:00
|
|
|
|
var framePct = renderInfo.SpecialFrameTime / (float)1000;
|
2018-11-23 14:19:48 -05:00
|
|
|
|
renderWindow.Draw(renderInfo.SelectedSprite, (int)(renderInfo.SelectedSprite.TotalFrames * framePct));
|
|
|
|
|
if (renderInfo.SelectedSpriteOverlay != null)
|
|
|
|
|
renderWindow.Draw(renderInfo.SelectedSpriteOverlay, (int)(renderInfo.SelectedSpriteOverlay.TotalFrames * framePct));
|
|
|
|
|
}
|
2018-11-23 11:43:21 -05:00
|
|
|
|
break;
|
|
|
|
|
case eHeroStance.Retreating:
|
2018-11-23 14:19:48 -05:00
|
|
|
|
{
|
2018-12-08 13:31:50 -05:00
|
|
|
|
var framePct = renderInfo.SpecialFrameTime / (float)renderInfo.BackWalkTimeMs;
|
2018-11-23 14:19:48 -05:00
|
|
|
|
renderWindow.Draw(renderInfo.BackWalkSprite, (int)(renderInfo.BackWalkSprite.TotalFrames * framePct));
|
|
|
|
|
if (renderInfo.BackWalkSpriteOverlay != null)
|
|
|
|
|
renderWindow.Draw(renderInfo.BackWalkSpriteOverlay, (int)(renderInfo.BackWalkSpriteOverlay.TotalFrames * framePct));
|
|
|
|
|
}
|
2018-11-23 11:43:21 -05:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 20:51:32 -05:00
|
|
|
|
private void OnKeyPressed(char charcode)
|
|
|
|
|
{
|
|
|
|
|
if (charcode == '\b')
|
|
|
|
|
{
|
|
|
|
|
if (characterNameTextBox.Text.Length == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
characterNameTextBox.Text = characterNameTextBox.Text.Substring(0, characterNameTextBox.Text.Length - 1);
|
|
|
|
|
okButton.Enabled = characterNameTextBox.Text.Length >= 2;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-26 19:12:36 -05:00
|
|
|
|
if (characterNameTextBox.Text.Length >= 15 || !selectedHero.HasValue)
|
2018-11-23 20:51:32 -05:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(charcode))
|
|
|
|
|
return;
|
|
|
|
|
characterNameTextBox.Text += charcode;
|
|
|
|
|
okButton.Enabled = characterNameTextBox.Text.Length >= 2;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 20:23:00 -05:00
|
|
|
|
public void Update(long ms)
|
|
|
|
|
{
|
2018-12-08 13:31:50 -05:00
|
|
|
|
float seconds = ms / 1500f;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
secondTimer += seconds;
|
|
|
|
|
while (secondTimer >= 1f)
|
|
|
|
|
secondTimer -= 1f;
|
|
|
|
|
|
2018-11-23 20:51:32 -05:00
|
|
|
|
if (keyboardInfoProvider.KeyPressCallback == null)
|
|
|
|
|
keyboardInfoProvider.KeyPressCallback = OnKeyPressed;
|
|
|
|
|
|
2018-11-23 12:18:59 -05:00
|
|
|
|
// Don't update hero selection if one of them is walking to or from the campfire
|
2018-11-23 14:19:48 -05:00
|
|
|
|
var canSelect = heroRenderInfo.All(x => x.Value.Stance == eHeroStance.Idle || x.Value.Stance == eHeroStance.IdleSelected || x.Value.Stance == eHeroStance.Selected);
|
|
|
|
|
|
|
|
|
|
foreach (var hero in Enum.GetValues(typeof(eHero)).Cast<eHero>())
|
|
|
|
|
UpdateHeroSelectionHover(hero, ms, canSelect);
|
2018-11-23 12:18:59 -05:00
|
|
|
|
|
2018-11-23 16:38:21 -05:00
|
|
|
|
if (selectedHero.HasValue && heroRenderInfo.All(x => x.Value.Stance == eHeroStance.Idle))
|
|
|
|
|
{
|
|
|
|
|
selectedHero = null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 22:53:05 -05:00
|
|
|
|
exitButton.Update();
|
2018-11-23 18:03:29 -05:00
|
|
|
|
okButton.Update();
|
2018-11-23 20:51:32 -05:00
|
|
|
|
characterNameTextBox.Update(ms);
|
2018-11-22 20:23:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 14:19:48 -05:00
|
|
|
|
private void UpdateHeroSelectionHover(eHero hero, long ms, bool canSelect)
|
2018-11-23 12:18:59 -05:00
|
|
|
|
{
|
2018-11-23 14:19:48 -05:00
|
|
|
|
var renderInfo = heroRenderInfo[hero];
|
|
|
|
|
if (renderInfo.Stance == eHeroStance.Approaching)
|
|
|
|
|
{
|
|
|
|
|
renderInfo.SpecialFrameTime += ms;
|
|
|
|
|
if (renderInfo.SpecialFrameTime >= renderInfo.ForwardWalkTimeMs)
|
|
|
|
|
{
|
|
|
|
|
renderInfo.Stance = eHeroStance.Selected;
|
|
|
|
|
renderInfo.SpecialFrameTime = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (renderInfo.Stance == eHeroStance.Retreating)
|
|
|
|
|
{
|
|
|
|
|
renderInfo.SpecialFrameTime += ms;
|
|
|
|
|
if (renderInfo.SpecialFrameTime >= renderInfo.BackWalkTimeMs)
|
|
|
|
|
{
|
|
|
|
|
renderInfo.Stance = eHeroStance.Idle;
|
|
|
|
|
renderInfo.SpecialFrameTime = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (renderInfo.Stance == eHeroStance.Selected)
|
|
|
|
|
{
|
|
|
|
|
renderInfo.SpecialFrameTime += ms;
|
|
|
|
|
while (renderInfo.SpecialFrameTime >= 1000)
|
|
|
|
|
renderInfo.SpecialFrameTime -= 1000;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!canSelect)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-11-23 12:18:59 -05:00
|
|
|
|
// No need to highlight a hero if they are next to the campfire
|
2018-11-23 14:19:48 -05:00
|
|
|
|
if (renderInfo.Stance == eHeroStance.Selected)
|
2018-11-23 12:18:59 -05:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var mouseX = mouseInfoProvider.MouseX;
|
|
|
|
|
var mouseY = mouseInfoProvider.MouseY;
|
|
|
|
|
|
2018-11-23 14:19:48 -05:00
|
|
|
|
var b = renderInfo.SelectionBounds;
|
2018-11-23 12:18:59 -05:00
|
|
|
|
var mouseHover = (mouseX >= b.Left) && (mouseX <= b.Left + b.Width) && (mouseY >= b.Top) && (mouseY <= b.Top + b.Height);
|
|
|
|
|
|
2018-11-23 14:19:48 -05:00
|
|
|
|
if (mouseHover && mouseInfoProvider.LeftMouseDown)
|
|
|
|
|
{
|
2018-11-23 18:03:29 -05:00
|
|
|
|
showEntryUi = true;
|
2018-11-23 14:19:48 -05:00
|
|
|
|
renderInfo.Stance = eHeroStance.Approaching;
|
|
|
|
|
renderInfo.SpecialFrameTime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach(var ri in heroRenderInfo)
|
|
|
|
|
{
|
|
|
|
|
if (ri.Value.Stance != eHeroStance.Selected)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ri.Value.Stance = eHeroStance.Retreating;
|
|
|
|
|
ri.Value.SpecialFrameTime = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 16:38:21 -05:00
|
|
|
|
selectedHero = hero;
|
|
|
|
|
UpdateHeroText();
|
|
|
|
|
|
2018-11-23 14:19:48 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 12:18:59 -05:00
|
|
|
|
heroRenderInfo[hero].Stance = mouseHover ? eHeroStance.IdleSelected : eHeroStance.Idle;
|
2018-11-23 16:38:21 -05:00
|
|
|
|
|
|
|
|
|
if (selectedHero == null && mouseHover)
|
|
|
|
|
{
|
|
|
|
|
selectedHero = hero;
|
|
|
|
|
UpdateHeroText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-08 09:32:09 -05:00
|
|
|
|
private void SetDescLabels(string descKey)
|
2018-11-25 19:06:22 -05:00
|
|
|
|
{
|
|
|
|
|
var heroDesc = textDictionary.Translate(descKey);
|
|
|
|
|
var parts = StringUtils.SplitIntoLinesWithMaxWidth(heroDesc, 37);
|
|
|
|
|
heroDesc1Label.Text = parts.Count > 0 ? parts[0] : "";
|
|
|
|
|
heroDesc2Label.Text = parts.Count > 1 ? parts[1] : "";
|
|
|
|
|
heroDesc3Label.Text = parts.Count > 2 ? parts[2] : "";
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 16:38:21 -05:00
|
|
|
|
private void UpdateHeroText()
|
|
|
|
|
{
|
|
|
|
|
if (selectedHero == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (selectedHero.Value)
|
|
|
|
|
{
|
|
|
|
|
case eHero.Barbarian:
|
|
|
|
|
heroClassLabel.Text = textDictionary.Translate("strBarbarian");
|
2018-12-08 09:32:09 -05:00
|
|
|
|
SetDescLabels("strBarbDesc");
|
2018-11-23 16:38:21 -05:00
|
|
|
|
break;
|
|
|
|
|
case eHero.Necromancer:
|
|
|
|
|
heroClassLabel.Text = textDictionary.Translate("strNecromancer");
|
2018-12-08 09:32:09 -05:00
|
|
|
|
SetDescLabels("strNecroDesc");
|
2018-11-23 16:38:21 -05:00
|
|
|
|
break;
|
|
|
|
|
case eHero.Paladin:
|
|
|
|
|
heroClassLabel.Text = textDictionary.Translate("strPaladin");
|
2018-12-08 09:32:09 -05:00
|
|
|
|
SetDescLabels("strPalDesc");
|
2018-11-23 16:38:21 -05:00
|
|
|
|
break;
|
|
|
|
|
case eHero.Assassin:
|
|
|
|
|
heroClassLabel.Text = textDictionary.Translate("strAssassin");
|
2018-11-23 16:50:22 -05:00
|
|
|
|
heroDesc1Label.Text = "Schooled in the Material Arts. Her";
|
|
|
|
|
heroDesc2Label.Text = "mind and body are deadly weapons.";
|
|
|
|
|
heroDesc3Label.Text = "";
|
2018-11-23 16:38:21 -05:00
|
|
|
|
break;
|
|
|
|
|
case eHero.Sorceress:
|
|
|
|
|
heroClassLabel.Text = textDictionary.Translate("strSorceress");
|
2018-12-08 09:32:09 -05:00
|
|
|
|
SetDescLabels("strSorcDesc");
|
2018-11-23 16:38:21 -05:00
|
|
|
|
break;
|
|
|
|
|
case eHero.Amazon:
|
|
|
|
|
heroClassLabel.Text = textDictionary.Translate("strAmazon");
|
2018-12-08 09:32:09 -05:00
|
|
|
|
SetDescLabels("strAmazonDesc");
|
2018-11-23 16:38:21 -05:00
|
|
|
|
break;
|
|
|
|
|
case eHero.Druid:
|
|
|
|
|
heroClassLabel.Text = textDictionary.Translate("strDruid");
|
2018-11-23 16:50:22 -05:00
|
|
|
|
heroDesc1Label.Text = "Commanding the forces of nature, he";
|
|
|
|
|
heroDesc2Label.Text = "summons wild beasts and raging";
|
|
|
|
|
heroDesc3Label.Text = "storms to his side.";
|
2018-11-23 16:38:21 -05:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
heroClassLabel.Location = new Point(400 - (heroClassLabel.TextArea.Width / 2), 65);
|
2018-11-23 16:50:22 -05:00
|
|
|
|
heroDesc1Label.Location = new Point(400 - (heroDesc1Label.TextArea.Width / 2), 100);
|
|
|
|
|
heroDesc2Label.Location = new Point(400 - (heroDesc2Label.TextArea.Width / 2), 115);
|
|
|
|
|
heroDesc3Label.Location = new Point(400 - (heroDesc3Label.TextArea.Width / 2), 130);
|
2018-11-23 12:18:59 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 20:23:00 -05:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2018-11-22 22:53:05 -05:00
|
|
|
|
backgroundSprite.Dispose();
|
|
|
|
|
campfireSprite.Dispose();
|
|
|
|
|
headingFont.Dispose();
|
|
|
|
|
headingLabel.Dispose();
|
2018-11-22 20:23:00 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|