Skip to content

Commit 8614df8

Browse files
committed
SImulator: Notify player about oral answering; support changing table text and background color
1 parent c412c0e commit 8614df8

File tree

21 files changed

+130
-116
lines changed

21 files changed

+130
-116
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Copyright>Copyright © Khil-soft 2002 - 2025</Copyright>
66
<SIGameVersion>7.13.3</SIGameVersion>
77
<SIQuesterVersion>6.2.3</SIQuesterVersion>
8-
<SImulatorVersion>3.1.1</SImulatorVersion>
8+
<SImulatorVersion>3.2.0</SImulatorVersion>
99
</PropertyGroup>
1010

1111
<PropertyGroup>

src/Common/SIPackages/SIPackages.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SignAssembly>true</SignAssembly>
55
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
66
<Description>SIGame packages processor</Description>
7-
<Version>7.10.0</Version>
7+
<Version>$(SIGameVersion)</Version>
88
<PackageProjectUrl>https://github.com/VladimirKhil/SI</PackageProjectUrl>
99
<RepositoryUrl>https://github.com/VladimirKhil/SI</RepositoryUrl>
1010
<PackageTags>SIGame</PackageTags>

src/Common/SIUI.Model/SIUI.Model.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<SignAssembly>True</SignAssembly>
66
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
77
<Description>Game table model</Description>
8-
<Version>7.6.0</Version>
8+
<Version>$(SIGameVersion)</Version>
99
<Nullable>enable</Nullable>
1010
<ImplicitUsings>enable</ImplicitUsings>
1111
</PropertyGroup>

src/Common/SIUI.ViewModel/Core/Settings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class Settings : INotifyPropertyChanged
1313
{
1414
public const string DefaultTableFontFamily = "_Default";
1515
public const string DefaultTableColorString = "White";
16-
public const string DefaultTableBackColorString = "#FF000451";
16+
public const string DefaultTableBackColorString = "#FF0A0E30";
1717
public const string DefaultTableGridColorString = null;
1818
public const string DefaultAnswererColorString = "#DD1D1F77";
1919
public const double DefaultQuestionLineSpacing = 1.5;

src/Common/SIUI.ViewModel/SIUI.ViewModel.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>net6.0</TargetFramework>
44
<SignAssembly>true</SignAssembly>
55
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
6-
<Version>7.6.0</Version>
6+
<Version>$(SIGameVersion)</Version>
77
<Description>Game table view model</Description>
88
<Nullable>enable</Nullable>
99
<ImplicitUsings>enable</ImplicitUsings>

src/Common/SIUI.ViewModel/SettingsViewModel.cs

-72
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,8 @@ namespace SIUI.ViewModel;
77
/// </summary>
88
public sealed class SettingsViewModel : ViewModelBase<Settings>
99
{
10-
public double TableColorR
11-
{
12-
get => Convert.ToByte(_model.TableColorString.Substring(3, 2), 16);
13-
set
14-
{
15-
_model.TableColorString = _model.TableColorString.Substring(0, 3)
16-
+ ((byte)value).ToString("x2")
17-
+ _model.TableColorString.Substring(5);
18-
19-
OnPropertyChanged(nameof(TableColorString));
20-
}
21-
}
22-
23-
public double TableColorG
24-
{
25-
get => Convert.ToByte(_model.TableColorString.Substring(5, 2), 16);
26-
set
27-
{
28-
_model.TableColorString = _model.TableColorString.Substring(0, 5)
29-
+ ((byte)value).ToString("x2")
30-
+ _model.TableColorString.Substring(7);
31-
32-
OnPropertyChanged(nameof(TableColorString));
33-
}
34-
}
35-
36-
public double TableColorB
37-
{
38-
get => Convert.ToByte(_model.TableColorString.Substring(7, 2), 16);
39-
set
40-
{
41-
_model.TableColorString = _model.TableColorString.Substring(0, 7) + ((byte)value).ToString("x2");
42-
OnPropertyChanged(nameof(TableColorString));
43-
}
44-
}
45-
4610
public string TableColorString => _model.TableColorString;
4711

48-
public double TableBackColorR
49-
{
50-
get => Convert.ToByte(_model.TableBackColorString.Substring(3, 2), 16);
51-
set
52-
{
53-
_model.TableBackColorString = _model.TableBackColorString.Substring(0, 3)
54-
+ ((byte)value).ToString("x2")
55-
+ _model.TableBackColorString.Substring(5);
56-
57-
OnPropertyChanged(nameof(TableBackColorString));
58-
}
59-
}
60-
61-
public double TableBackColorG
62-
{
63-
get => Convert.ToByte(_model.TableBackColorString.Substring(5, 2), 16);
64-
set
65-
{
66-
_model.TableBackColorString = _model.TableBackColorString.Substring(0, 5)
67-
+ ((byte)value).ToString("x2")
68-
+ _model.TableBackColorString.Substring(7);
69-
70-
OnPropertyChanged(nameof(TableBackColorString));
71-
}
72-
}
73-
74-
public double TableBackColorB
75-
{
76-
get => Convert.ToByte(_model.TableBackColorString.Substring(7, 2), 16);
77-
set
78-
{
79-
_model.TableBackColorString = _model.TableBackColorString.Substring(0, 7) + ((byte)value).ToString("x2");
80-
OnPropertyChanged(nameof(TableBackColorString));
81-
}
82-
}
83-
8412
public string TableBackColorString => _model.TableBackColorString;
8513

8614
public string TableGridColorString => _model.TableGridColorString;

src/Common/Utils/Utils.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5-
<Version>7.6.0</Version>
65
<Product>Utils</Product>
76
<Description>SIGame utils</Description>
87
<SignAssembly>True</SignAssembly>

src/SImulator/SImulator.ViewModel/Contracts/ICommandExecutor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ public interface ICommandExecutor
88

99
void AskTextAnswer();
1010

11+
void AskOralAnswer();
12+
1113
void Cancel();
1214
}

src/SImulator/SImulator.ViewModel/Controllers/WebPresentationController.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using SIUI.ViewModel;
88
using SIUI.ViewModel.Core;
99
using System.Diagnostics;
10+
using System.Drawing;
1011
using System.Text.Json;
1112
using Utils;
1213
using Utils.Web;
@@ -423,10 +424,22 @@ public void UpdatePlayerInfo(int playerIndex, PlayerInfo player, string? propert
423424
}
424425

425426
public void OnFinalThink() => SendMessage(new { Type = "finalThink" });
427+
428+
public void UpdateSettings(Settings settings) => SendMessage(new
429+
{
430+
Type = "setOptions",
431+
TableTextColor = ConvertWpfToHtmlColor(settings.TableColorString),
432+
TableBackgroundColor = ConvertWpfToHtmlColor(settings.TableBackColorString)
433+
});
426434

427-
public void UpdateSettings(Settings settings)
435+
private static string ConvertWpfToHtmlColor(string wpfColor)
428436
{
429-
// TODO: will be implemented in the future
437+
if (wpfColor.Length == 9 && wpfColor.StartsWith("#"))
438+
{
439+
return $"#{wpfColor.Substring(3)}{wpfColor.Substring(1, 2)}";
440+
}
441+
442+
return wpfColor; // Return as-is if not in expected format
430443
}
431444

432445
public void UpdateShowPlayers(bool showPlayers) => SendMessage(new

src/SImulator/SImulator.ViewModel/PlatformSpecific/PlatformManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected PlatformManager()
3737

3838
public abstract int GetKeyNumber(GameKey key);
3939

40-
public abstract Task<IPackageSource?> AskSelectPackageAsync(object arg);
40+
public abstract Task<IPackageSource?> AskSelectPackageAsync(string arg);
4141

4242
public abstract string? AskSelectColor();
4343

src/SImulator/SImulator.ViewModel/SImulator.ViewModel.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<Product>SImulator.ViewModel</Product>
77
<Description>SImulator view model</Description>
88
<Version>$(SImulatorVersion)</Version>
9-
<Copyright>Copyright © Khil-soft 2010 - 2024</Copyright>
109
<Nullable>enable</Nullable>
1110
<ImplicitUsings>enable</ImplicitUsings>
1211
</PropertyGroup>

src/SImulator/SImulator.ViewModel/ViewModel/GameViewModel.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1165,10 +1165,10 @@ public void StopThinkingTimer_Executed(object? arg)
11651165
ThinkingTime = 0;
11661166
}
11671167

1168+
_buttonManager?.TryGetCommandExecutor()?.Cancel();
1169+
11681170
if (ActiveQuestion?.TypeName == QuestionTypes.StakeAll || ActiveQuestion?.TypeName == QuestionTypes.ForAll)
11691171
{
1170-
_buttonManager?.TryGetCommandExecutor()?.Cancel();
1171-
11721172
foreach (var player in Players)
11731173
{
11741174
player.IsPreliminaryAnswer = false;
@@ -1493,7 +1493,12 @@ internal void PlayQuestionType(string typeName, bool isDefault)
14931493
break;
14941494

14951495
case QuestionTypes.Stake:
1496-
PrintQuestionType(typeName, Resources.StakeQuestion.ToUpper(), Settings.Model.SpecialsAliases.StakeQuestionAlias, ActiveRound.Themes.IndexOf(ActiveTheme));
1496+
PrintQuestionType(
1497+
typeName,
1498+
Resources.StakeQuestion.ToUpper(),
1499+
Settings.Model.SpecialsAliases.StakeQuestionAlias,
1500+
ActiveTheme != null ? ActiveRound.Themes.IndexOf(ActiveTheme) : -1);
1501+
14971502
break;
14981503

14991504
case QuestionTypes.NoRisk:
@@ -2148,6 +2153,7 @@ private bool ProcessPlayerPress(int index, PlayerInfo player)
21482153

21492154
SetSound(Settings.Model.Sounds.PlayerPressed);
21502155
PresentationController.SetActivePlayerIndex(index);
2156+
_buttonManager?.TryGetCommandExecutor()?.AskOralAnswer();
21512157

21522158
_previousState = State;
21532159
State = QuestionState.Pressed;
@@ -2369,6 +2375,11 @@ internal bool SelectStake(NumberSet availableRange)
23692375

23702376
internal void OnSetNoRiskPrice()
23712377
{
2378+
if (_activeQuestion == null)
2379+
{
2380+
return;
2381+
}
2382+
23722383
Price = _activeQuestion.Price * 2;
23732384
NegativePrice = 0;
23742385
}
@@ -2555,6 +2566,12 @@ private void SetStakerToAnswer()
25552566
{
25562567
StakerIndex = _stakers[0];
25572568
var staker = Staker;
2569+
2570+
if (staker == null)
2571+
{
2572+
return;
2573+
}
2574+
25582575
staker.IsSelected = true;
25592576
_selectedPlayer = staker;
25602577
Chooser = _selectedPlayer;

src/SImulator/SImulator.ViewModel/ViewModel/MainViewModel.cs

+25-11
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ public ICommand ActivePlayerButtonCommand
9292

9393
public ICommand OpenLicensesFolder { get; private set; }
9494

95-
private IPackageSource _packageSource;
95+
private IPackageSource? _packageSource;
9696

9797
/// <summary>
98-
/// Путь к отыгрываемому документу
98+
/// Package source.
9999
/// </summary>
100-
public IPackageSource PackageSource
100+
public IPackageSource? PackageSource
101101
{
102102
get => _packageSource;
103103
set
@@ -231,7 +231,7 @@ public MainViewModel(AppSettings settings)
231231

232232
OpenLicensesFolder = new SimpleCommand(OpenLicensesFolder_Executed);
233233

234-
ActivePlayerButtonCommand = _addPlayerButton;
234+
_activePlayerButtonCommand = _addPlayerButton;
235235

236236
UpdateStartCommand();
237237
UpdateCanAddPlayerButton();
@@ -378,6 +378,11 @@ private void Settings_PropertyChanged(object? sender, PropertyChangedEventArgs e
378378

379379
private async Task<SIDocument> PreparePackageAsync(CancellationToken cancellationToken = default)
380380
{
381+
if (_packageSource == null)
382+
{
383+
throw new InvalidOperationException("_packageSource == null");
384+
}
385+
381386
var (filePath, isTemporary) = await _packageSource.GetPackageFileAsync(cancellationToken);
382387

383388
var tempDir = Path.Combine(Path.GetTempPath(), AppSettings.AppName, Guid.NewGuid().ToString());
@@ -455,6 +460,11 @@ private async Task Start_Executed(object? _)
455460
{
456461
try
457462
{
463+
if (_packageSource == null)
464+
{
465+
throw new InvalidOperationException("_packageSource == null");
466+
}
467+
458468
var screenIndex = SettingsViewModel.Model.ScreenNumber;
459469

460470
if (screenIndex < 0 || screenIndex >= Screens.Length)
@@ -615,12 +625,8 @@ private async Task EndGameAsync()
615625

616626
private async void SelectPackage_Executed(object? arg)
617627
{
618-
if (arg == null)
619-
{
620-
throw new ArgumentNullException(nameof(arg));
621-
}
622-
623-
var packageSource = await PlatformManager.Instance.AskSelectPackageAsync(arg);
628+
var stringArg = (arg?.ToString()) ?? throw new ArgumentNullException(nameof(arg));
629+
var packageSource = await PlatformManager.Instance.AskSelectPackageAsync(stringArg);
624630

625631
if (packageSource != null)
626632
{
@@ -772,7 +778,10 @@ public async Task OnButtonsLeftAsync()
772778

773779
private void RemovePlayerButton_Executed(object? arg)
774780
{
775-
var key = (GameKey)arg;
781+
if (arg is not GameKey key)
782+
{
783+
return;
784+
}
776785

777786
if (Settings.PlayerKeys2.Contains(key))
778787
{
@@ -815,6 +824,11 @@ private void OnModeChanged()
815824

816825
private void UpdatePlayersView()
817826
{
827+
if (_game == null)
828+
{
829+
return;
830+
}
831+
818832
if (Settings.PlayersView == PlayersViewMode.Separate && _mode == GameMode.Moderator)
819833
{
820834
PlatformManager.Instance.CreatePlayersView(_game);

0 commit comments

Comments
 (0)