-
Notifications
You must be signed in to change notification settings - Fork 16
/
CreateCharacterDialog.cs
181 lines (154 loc) · 6.68 KB
/
CreateCharacterDialog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using EndlessClient.Content;
using EndlessClient.Dialogs.Factories;
using EndlessClient.Dialogs.Services;
using EndlessClient.GameExecution;
using EndlessClient.Rendering.Factories;
using EndlessClient.UIControls;
using EOLib;
using EOLib.Domain.Character;
using EOLib.Graphics;
using EOLib.Localization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using XNAControls;
namespace EndlessClient.Dialogs
{
public class CreateCharacterDialog : BaseEODialog
{
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly IXNATextBox _inputBox;
private readonly IXNAButton[] _arrowButtons = new IXNAButton[4];
private readonly IXNAButton _ok, _cancel;
private readonly CreateCharacterControl _characterControl;
private readonly Rectangle[] _srcRectangles = new Rectangle[4];
private readonly Texture2D _charCreateSheet;
public string Name => _inputBox.Text.Trim();
private ICharacterRenderProperties RenderProperties => _characterControl.RenderProperties;
public byte Gender => RenderProperties.Gender;
public byte HairStyle => RenderProperties.HairStyle;
public byte HairColor => RenderProperties.HairColor;
public byte Race => RenderProperties.Race;
public CreateCharacterDialog(
INativeGraphicsManager nativeGraphicsManager,
IGameStateProvider gameStateProvider,
ICharacterRendererFactory rendererFactory,
IContentProvider contentProvider,
KeyboardDispatcher dispatcher,
IEOMessageBoxFactory messageBoxFactory,
IEODialogButtonService eoDialogButtonService)
: base(gameStateProvider)
{
_messageBoxFactory = messageBoxFactory;
BackgroundTexture = nativeGraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 20);
_charCreateSheet = nativeGraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 22);
var cursorTexture = contentProvider.Textures[ContentProvider.Cursor];
_inputBox = new XNATextBox(new Rectangle(80, 57, 138, 19), Constants.FontSize08, caretTexture: cursorTexture)
{
LeftPadding = 5,
DefaultText = " ",
Text = " ",
MaxChars = 12,
Selected = true,
TextColor = ColorConstants.LightBeigeText,
Visible = true
};
_inputBox.SetParentControl(this);
dispatcher.Subscriber = _inputBox;
for (int i = 0; i < _arrowButtons.Length; ++i)
{
var btn = new XNAButton(_charCreateSheet,
new Vector2(196, 85 + i * 26),
new Rectangle(185, 38, 19, 19),
new Rectangle(206, 38, 19, 19));
btn.OnClick += ArrowButtonClick;
btn.SetParentControl(this);
_arrowButtons[i] = btn;
}
_characterControl = new CreateCharacterControl(rendererFactory)
{
DrawPosition = new Vector2(235, 58)
};
_characterControl.SetParentControl(this);
_srcRectangles[0] = new Rectangle(0, 38, 23, 19);
_srcRectangles[1] = new Rectangle(0, 19, 23, 19);
_srcRectangles[2] = new Rectangle(0, 0, 23, 19);
_srcRectangles[3] = new Rectangle(46, 38, 23, 19);
_ok = new XNAButton(eoDialogButtonService.SmallButtonSheet,
new Vector2(157, 195),
eoDialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Ok),
eoDialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Ok));
_ok.OnClick += (s, e) => ClickOk();
_ok.SetParentControl(this);
_cancel = new XNAButton(eoDialogButtonService.SmallButtonSheet,
new Vector2(250, 195),
eoDialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Cancel),
eoDialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Cancel));
_cancel.OnClick += (s, e) => Close(XNADialogResult.Cancel);
_cancel.SetParentControl(this);
CenterInGameView();
}
public override void Initialize()
{
_characterControl.Initialize();
_inputBox.Initialize();
foreach (var button in _arrowButtons)
button.Initialize();
_ok.Initialize();
_cancel.Initialize();
base.Initialize();
}
protected override void OnDrawControl(GameTime gt)
{
base.OnDrawControl(gt);
_spriteBatch.Begin();
for (int i = 0; i < 4; ++i)
{
_spriteBatch.Draw(_charCreateSheet,
new Vector2(170 + DrawPositionWithParentOffset.X,
84 + i*27 + DrawPositionWithParentOffset.Y),
_srcRectangles[i], Color.White);
}
_spriteBatch.End();
}
private void ArrowButtonClick(object sender, EventArgs e)
{
if (sender == _arrowButtons[0])
{
_characterControl.NextGender();
_srcRectangles[0] = new Rectangle(0 + 23 * RenderProperties.Gender, 38, 23, 19);
}
else if (sender == _arrowButtons[1])
{
_characterControl.NextHairStyle();
if (RenderProperties.HairStyle == 0) //skip bald
_characterControl.NextHairStyle();
_srcRectangles[1] = new Rectangle(0 + 23 * (RenderProperties.HairStyle - 1), 19, 23, 19);
}
else if (sender == _arrowButtons[2])
{
_characterControl.NextHairColor();
_srcRectangles[2] = new Rectangle(0 + 23 * RenderProperties.HairColor, 0, 23, 19);
}
else if (sender == _arrowButtons[3])
{
_characterControl.NextRace();
_srcRectangles[3] = new Rectangle(46 + 23 * RenderProperties.Race, 38, 23, 19);
}
}
private void ClickOk()
{
if (_inputBox.Text.Length < 4)
{
var messageBox = _messageBoxFactory.CreateMessageBox(DialogResourceID.CHARACTER_CREATE_NAME_TOO_SHORT,
EODialogButtons.Ok,
EOMessageBoxStyle.SmallDialogLargeHeader);
messageBox.ShowDialog();
}
else
{
Close(XNADialogResult.OK);
}
}
}
}