Skip to content

Commit 6215a66

Browse files
authored
Merge pull request #2 from benpollarduk/events-and-styling
Added events, updated styling
2 parents fb9e03d + 194f81e commit 6215a66

8 files changed

Lines changed: 273 additions & 25 deletions

File tree

NetAF.WPF.TestApp/MainWindow.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:layouts="clr-namespace:NetAF.Targets.WPF.InputLayouts;assembly=NetAF.WPF"
77
xmlns:controls="clr-namespace:NetAF.Targets.WPF.Controls;assembly=NetAF.WPF"
88
xmlns:outputlayouts="clr-namespace:NetAF.Targets.WPF.OutputLayouts;assembly=NetAF.WPF"
9+
xmlns:effects="clr-namespace:LoFiEffects.WPF.Effects;assembly=LoFiEffects.WPF"
910
mc:Ignorable="d"
1011
Title="NetAF.WPF.TestApp" Height="850" Width="1000">
1112
<Window.Resources>
@@ -22,7 +23,11 @@
2223
<RowDefinition Height="Auto"/>
2324
<RowDefinition Height="Auto"/>
2425
</Grid.RowDefinitions>
25-
<controls:NetAFMarkupTerminal x:Name="Terminal" Style="{StaticResource DarkMarkupTerminalStyle}" Margin="10" Grid.Row="0"/>
26+
<controls:NetAFMarkupTerminal x:Name="Terminal" Style="{StaticResource DarkMarkupTerminalStyle}" Margin="10" Grid.Row="0">
27+
<controls:NetAFMarkupTerminal.Effect>
28+
<effects:CrtEffect Intensity="0.5" CurvatureIntensity="0.15" IncludeScanlines="True"/>
29+
</controls:NetAFMarkupTerminal.Effect>
30+
</controls:NetAFMarkupTerminal>
2631
<Expander Header="Prompt" Style="{StaticResource DarkExpanderStyle}" Padding="6" Margin="10,0,10,10" Grid.Row="1">
2732
<controls:NetAFPrompt Style="{StaticResource DarkPromptStyle}"/>
2833
</Expander>

NetAF.WPF.TestApp/NetAF.WPF.TestApp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="LoFiEffects.WPF" Version="1.3.0" />
22-
<PackageReference Include="NetAF" Version="3.13.4" />
21+
<PackageReference Include="LoFiEffects.WPF" Version="1.5.1" />
22+
<PackageReference Include="NetAF" Version="3.13.5" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

NetAF.WPF/NetAF.WPF.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
</ItemGroup>
5151

5252
<ItemGroup>
53-
<PackageReference Include="LoFiEffects.WPF" Version="1.3.0" />
54-
<PackageReference Include="NetAF" Version="3.13.4" />
53+
<PackageReference Include="LoFiEffects.WPF" Version="1.5.1" />
54+
<PackageReference Include="NetAF" Version="3.13.5" />
5555
</ItemGroup>
5656

5757
<ItemGroup>

NetAF.WPF/Targets/WPF/Controls/NetAFCommandPicker.xaml.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,31 @@ public bool ShowAcknowledgeButton
312312
set { SetValue(ShowAcknowledgeButtonProperty, value); }
313313
}
314314

315+
/// <summary>
316+
/// Occurs when a command is selected.
317+
/// </summary>
318+
public event EventHandler<CommandHelp> CommandSelected;
319+
320+
/// <summary>
321+
/// Occurs when a command is executed.
322+
/// </summary>
323+
public event EventHandler<string> CommandExecuted;
324+
325+
/// <summary>
326+
/// Occurs when a prompt is selected.
327+
/// </summary>
328+
public event EventHandler<Prompt> PromptSelected;
329+
330+
/// <summary>
331+
/// Occurs when acknowledge is selected.
332+
/// </summary>
333+
public event EventHandler AcknowledgeSelected;
334+
335+
/// <summary>
336+
/// Occurs when clear is selected.
337+
/// </summary>
338+
public event EventHandler ClearSelected;
339+
315340
#endregion
316341

317342
#region DependencyProperties
@@ -656,6 +681,9 @@ private static void OnSelectedCommandPropertyChanged(DependencyObject sender, De
656681
if (control.AvailablePrompts == null || control.AvailablePrompts.Length == 0)
657682
{
658683
GameExecutor.Update(newCommand.Command);
684+
685+
control.CommandExecuted?.Invoke(control, newCommand.Command);
686+
659687
control.SelectedCommand = null;
660688
}
661689
}
@@ -678,23 +706,47 @@ private static void OnAvailablePromptsPropertyChanged(DependencyObject sender, D
678706

679707
private void CommandSelectedCommand_Executed(object sender, ExecutedRoutedEventArgs e)
680708
{
681-
SelectedCommand = e.Parameter as CommandHelp;
709+
var commandHelp = e.Parameter as CommandHelp;
710+
711+
if (commandHelp == null)
712+
return;
713+
714+
CommandSelected?.Invoke(this, commandHelp);
715+
716+
SelectedCommand = commandHelp;
682717
}
683718

684719
private void PromptSelectedCommand_Executed(object sender, ExecutedRoutedEventArgs e)
685720
{
686-
GameExecutor.Update($"{SelectedCommand?.Command ?? string.Empty} {(e.Parameter as Prompt)?.Entry}");
721+
var prompt = e.Parameter as Prompt;
722+
723+
if (prompt == null)
724+
return;
725+
726+
PromptSelected?.Invoke(this, prompt);
727+
728+
var command = $"{SelectedCommand?.Command ?? string.Empty} {prompt.Entry}";
729+
730+
GameExecutor.Update(command);
731+
732+
CommandExecuted?.Invoke(this, command);
733+
687734
SelectedCommand = null;
688735
}
689736

690737
private void ClearSelectedCommand_Executed(object sender, ExecutedRoutedEventArgs e)
691738
{
739+
ClearSelected?.Invoke(this, EventArgs.Empty);
740+
692741
Update(GameExecutor.ExecutingGame);
693742
}
694743

695744
private void AcknowledgeSelectedCommand_Executed(object sender, ExecutedRoutedEventArgs e)
696745
{
746+
AcknowledgeSelected?.Invoke(this, EventArgs.Empty);
747+
697748
GameExecutor.Update();
749+
698750
SelectedCommand = null;
699751
}
700752

NetAF.WPF/Targets/WPF/Controls/NetAFMovementCommandPicker.xaml.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NetAF.Commands.Scene;
1+
using NetAF.Commands;
2+
using NetAF.Commands.Scene;
23
using NetAF.Logic;
34
using NetAF.Logic.Modes;
45
using System.Windows;
@@ -77,6 +78,16 @@ public double SectionSpacing
7778
set { SetValue(SectionSpacingProperty, value); }
7879
}
7980

81+
/// <summary>
82+
/// Occurs when a command is selected.
83+
/// </summary>
84+
public event EventHandler<CommandHelp> CommandSelected;
85+
86+
/// <summary>
87+
/// Occurs when a command is executed.
88+
/// </summary>
89+
public event EventHandler<string> CommandExecuted;
90+
8091
#endregion
8192

8293
#region DependencyProperties
@@ -130,36 +141,49 @@ public NetAFMovementCommandPicker()
130141

131142
#endregion
132143

144+
#region Methods
145+
146+
private void ExecuteCommand(CommandHelp command)
147+
{
148+
CommandSelected?.Invoke(this, command);
149+
150+
GameExecutor.Update(command.Command);
151+
152+
CommandExecuted?.Invoke(this, command.Command);
153+
}
154+
155+
#endregion
156+
133157
#region EventHandlers
134158

135159
private void NorthSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
136160
{
137-
GameExecutor.Update(Move.NorthCommandHelp.Command);
161+
ExecuteCommand(Move.NorthCommandHelp);
138162
}
139163

140164
private void EastSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
141165
{
142-
GameExecutor.Update(Move.EastCommandHelp.Command);
166+
ExecuteCommand(Move.EastCommandHelp);
143167
}
144168

145169
private void SouthSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
146170
{
147-
GameExecutor.Update(Move.SouthCommandHelp.Command);
171+
ExecuteCommand(Move.SouthCommandHelp);
148172
}
149173

150174
private void WestSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
151175
{
152-
GameExecutor.Update(Move.WestCommandHelp.Command);
176+
ExecuteCommand(Move.WestCommandHelp);
153177
}
154178

155179
private void UpSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
156180
{
157-
GameExecutor.Update(Move.UpCommandHelp.Command);
181+
ExecuteCommand(Move.UpCommandHelp);
158182
}
159183

160184
private void DownSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
161185
{
162-
GameExecutor.Update(Move.DownCommandHelp.Command);
186+
ExecuteCommand(Move.DownCommandHelp);
163187
}
164188

165189
#endregion

NetAF.WPF/Targets/WPF/Controls/NetAFPrompt.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ namespace NetAF.Targets.WPF.Controls
99
/// </summary>
1010
public partial class NetAFPrompt : UserControl
1111
{
12+
#region Properties
13+
14+
/// <summary>
15+
/// Occurs when a key is pressed.
16+
/// </summary>
17+
public event EventHandler<Key> KeyPressed;
18+
19+
#endregion
20+
1221
#region Constructors
1322

1423
/// <summary>
@@ -25,6 +34,8 @@ public NetAFPrompt()
2534

2635
private void InputTextBox_PreviewKeyUp(object sender, KeyEventArgs e)
2736
{
37+
KeyPressed?.Invoke(this, e.Key);
38+
2839
if (e.Key != Key.Enter)
2940
return;
3041

NetAF.WPF/Targets/WPF/Controls/NetAFRegionMapCommandPicker.xaml.cs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NetAF.Commands.Global;
1+
using NetAF.Commands;
2+
using NetAF.Commands.Global;
23
using NetAF.Commands.RegionMap;
34
using NetAF.Logic;
45
using NetAF.Logic.Modes;
@@ -114,6 +115,16 @@ public double SectionSpacing
114115
set { SetValue(SectionSpacingProperty, value); }
115116
}
116117

118+
/// <summary>
119+
/// Occurs when a command is selected.
120+
/// </summary>
121+
public event EventHandler<CommandHelp> CommandSelected;
122+
123+
/// <summary>
124+
/// Occurs when a command is executed.
125+
/// </summary>
126+
public event EventHandler<string> CommandExecuted;
127+
117128
#endregion
118129

119130
#region DependencyProperties
@@ -187,56 +198,69 @@ public NetAFRegionMapCommandPicker()
187198

188199
#endregion
189200

201+
#region Methods
202+
203+
private void ExecuteCommand(CommandHelp command)
204+
{
205+
CommandSelected?.Invoke(this, command);
206+
207+
GameExecutor.Update(command.Command);
208+
209+
CommandExecuted?.Invoke(this, command.Command);
210+
}
211+
212+
#endregion
213+
190214
#region EventHandlers
191215

192216
private void PanNorthSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
193217
{
194-
GameExecutor.Update(Pan.NorthCommandHelp.Command);
218+
ExecuteCommand(Pan.NorthCommandHelp);
195219
}
196220

197221
private void PanEastSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
198222
{
199-
GameExecutor.Update(Pan.EastCommandHelp.Command);
223+
ExecuteCommand(Pan.EastCommandHelp);
200224
}
201225

202226
private void PanSouthSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
203227
{
204-
GameExecutor.Update(Pan.SouthCommandHelp.Command);
228+
ExecuteCommand(Pan.SouthCommandHelp);
205229
}
206230

207231
private void PanWestSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
208232
{
209-
GameExecutor.Update(Pan.WestCommandHelp.Command);
233+
ExecuteCommand(Pan.WestCommandHelp);
210234
}
211235

212236
private void PanUpSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
213237
{
214-
GameExecutor.Update(Pan.UpCommandHelp.Command);
238+
ExecuteCommand(Pan.UpCommandHelp);
215239
}
216240

217241
private void PanDownSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
218242
{
219-
GameExecutor.Update(Pan.DownCommandHelp.Command);
243+
ExecuteCommand(Pan.DownCommandHelp);
220244
}
221245

222246
private void ZoomInSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
223247
{
224-
GameExecutor.Update(ZoomIn.CommandHelp.Command);
248+
ExecuteCommand(ZoomIn.CommandHelp);
225249
}
226250

227251
private void PanResetSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
228252
{
229-
GameExecutor.Update(PanReset.CommandHelp.Command);
253+
ExecuteCommand(PanReset.CommandHelp);
230254
}
231255

232256
private void ZoomOutSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
233257
{
234-
GameExecutor.Update(ZoomOut.CommandHelp.Command);
258+
ExecuteCommand(ZoomOut.CommandHelp);
235259
}
236260

237261
private void EndSelectedCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
238262
{
239-
GameExecutor.Update(End.CommandHelp.Command);
263+
ExecuteCommand(End.CommandHelp);
240264
}
241265

242266
#endregion

0 commit comments

Comments
 (0)