Skip to content

Commit 660c0a5

Browse files
Refactor UI and add async message display
Changed `move.GuessPegs` iteration to use `Count`, fixed to compile for the collection type. Added `ShowMessageAsync` method in `WinFormsDialogService` for asynchronous message display as defined by the interface.
1 parent 7bdfac0 commit 660c0a5

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/Codebreaker.WinForms/MainForm.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
namespace Codebreaker.WinForms;
22

3+
using Codebreaker.ViewModels.Contracts.Services;
4+
using Codebreaker.ViewModels.Models;
5+
36
/// <summary>
47
/// Main form for the Codebreaker game.
58
/// </summary>
69
public partial class MainForm : Form
710
{
811
private readonly GamePageViewModel _viewModel;
912
private readonly IInfoBarService _infoBarService;
10-
13+
1114
// UI Controls
1215
private Panel _startGamePanel = default!;
1316
private TextBox _usernameTextBox = default!;
@@ -20,6 +23,7 @@ public partial class MainForm : Form
2023
private ListBox _movesListBox = default!;
2124
private Label _statusLabel = default!;
2225
private ProgressBar _progressBar = default!;
26+
2327
private TextBox _infoBarTextBox = default!;
2428

2529
public MainForm()
@@ -71,7 +75,6 @@ private void InitializeComponent()
7175
_movesListBox.DrawItem += MovesListBox_DrawItem;
7276
_movesListBox.MeasureItem += MovesListBox_MeasureItem;
7377
mainLayout.Controls.Add(_movesListBox, 0, 1);
74-
7578
// 4. Status panel
7679
var statusPanel = new Panel { Dock = DockStyle.Fill };
7780
_statusLabel = new Label
@@ -188,7 +191,7 @@ private void SetupDataBindings()
188191

189192
private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
190193
{
191-
this.Invoke(() =>
194+
Invoke(() =>
192195
{
193196
if (e.PropertyName == nameof(GamePageViewModel.GameStatus))
194197
{
@@ -214,7 +217,7 @@ private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs
214217

215218
private void Messages_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
216219
{
217-
this.Invoke(() =>
220+
Invoke(() =>
218221
{
219222
if (e.NewItems != null)
220223
{
@@ -363,7 +366,7 @@ private void MovesListBox_DrawItem(object? sender, DrawItemEventArgs e)
363366
int spacing = 5;
364367

365368
// Draw guess pegs
366-
for (int i = 0; i < move.GuessPegs.Length; i++)
369+
for (int i = 0; i < move.GuessPegs.Count; i++)
367370
{
368371
var colorName = move.GuessPegs[i];
369372
var color = Helpers.ColorHelper.GetColorFromName(colorName);

src/Codebreaker.WinForms/Services/WinFormsDialogService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public Task ShowMessageAsync(string title, string message)
1313
return Task.CompletedTask;
1414
}
1515

16+
public Task ShowMessageAsync(string message)
17+
{
18+
MessageBox.Show(message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
19+
return Task.CompletedTask;
20+
}
21+
1622
public Task ShowErrorAsync(string title, string message)
1723
{
1824
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Error);

0 commit comments

Comments
 (0)