Skip to content

Commit a4eb7c0

Browse files
committed
Fixes several errors.
1 parent aa1151f commit a4eb7c0

File tree

15 files changed

+138
-166
lines changed

15 files changed

+138
-166
lines changed

deploy/SIGame.Setup/Product.wxs

+17-14
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@
6464

6565
<Fragment>
6666
<Directory Id="TARGETDIR" Name="SourceDir">
67-
<Directory Id="LocalAppDataFolder">
68-
<Directory Id="ManufacturerFolder" Name="$(var.ManufacturerEn)">
69-
<Directory Id="INSTALLLOCATION" Name="$(var.ProductNameEn)">
70-
<Directory Id="DataFolder" Name="Data" />
71-
<Directory Id="PhotoFolder" Name="Photo" />
72-
<Directory Id="SoundsFolder" Name="Sounds" />
73-
<Directory Id="LicensesFolder" Name="licenses" />
67+
<Directory Id="LocalAppDataFolder">
68+
<Directory Id="ManufacturerFolder" Name="$(var.ManufacturerEn)">
69+
<Directory Id="INSTALLLOCATION" Name="$(var.ProductNameEn)">
70+
<Directory Id="DataFolder" Name="Data" />
71+
<Directory Id="PhotoFolder" Name="Photo" />
72+
<Directory Id="SoundsFolder" Name="Sounds" />
73+
<Directory Id="LicensesFolder" Name="licenses" />
74+
</Directory>
75+
</Directory>
76+
</Directory>
77+
<Directory Id="ProgramMenuFolder">
78+
<Directory Id="ManufacturerProgramMenuFolder" Name="$(var.Manufacturer)">
79+
<Directory Id="ApplicationProgramMenuFolder" Name="$(var.ProductName)" />
80+
</Directory>
7481
</Directory>
75-
</Directory>
76-
</Directory>
77-
<Directory Id="ProgramMenuFolder">
78-
<Directory Id="ManufacturerProgramMenuFolder" Name="$(var.Manufacturer)">
79-
<Directory Id="ApplicationProgramMenuFolder" Name="$(var.ProductName)" />
80-
</Directory>
81-
</Directory>
8282
</Directory>
8383
</Fragment>
8484

@@ -107,6 +107,9 @@
107107
<Component Guid="{1627896d-65da-47fa-9802-a3cfe67cb0aa}">
108108
<File KeyPath="yes" Source="..\dlls\$(var.Platform)\api-ms-win-core-winrt-l1-1-0.dll" />
109109
</Component>
110+
<Component Guid="{4687DB8D-2AA3-46AD-8B85-A8469390E198}">
111+
<File KeyPath="yes" Source="$(var.PublishFolder)WebView2Loader.dll" />
112+
</Component>
110113
<Component Guid="{B6AFAEC8-30A0-4BD9-836A-920D1190DAF9}">
111114
<File KeyPath="yes" Source="$(var.PublishFolder)aspnetcorev2_inprocess.dll" />
112115
</Component>

src/Common/SIUI/Behaviors/FillManager.cs

+25-45
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void SetFill(DependencyObject obj, bool value)
3131

3232
public static void OnFillChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
3333
{
34-
if (!(d is TextBlock textBlock))
34+
if (d is not TextBlock textBlock)
3535
{
3636
return;
3737
}
@@ -48,39 +48,25 @@ public static void OnFillChanged(DependencyObject d, DependencyPropertyChangedEv
4848
}
4949
}
5050

51-
public static FrameworkElement GetParent(DependencyObject obj)
52-
{
53-
return (FrameworkElement)obj.GetValue(ParentProperty);
54-
}
51+
public static FrameworkElement GetParent(DependencyObject obj) => (FrameworkElement)obj.GetValue(ParentProperty);
5552

56-
public static void SetParent(DependencyObject obj, FrameworkElement value)
57-
{
58-
obj.SetValue(ParentProperty, value);
59-
}
53+
public static void SetParent(DependencyObject obj, FrameworkElement value) => obj.SetValue(ParentProperty, value);
6054

61-
// Using a DependencyProperty as the backing store for Parent. This enables animation, styling, binding, etc...
6255
public static readonly DependencyProperty ParentProperty =
6356
DependencyProperty.RegisterAttached("Parent", typeof(FrameworkElement), typeof(FillManager), new UIPropertyMetadata(null));
64-
65-
public static SizeChangedEventHandler GetHandler(DependencyObject obj)
66-
{
67-
return (SizeChangedEventHandler)obj.GetValue(HandlerProperty);
68-
}
6957

70-
public static void SetHandler(DependencyObject obj, SizeChangedEventHandler value)
71-
{
72-
obj.SetValue(HandlerProperty, value);
73-
}
58+
public static SizeChangedEventHandler GetHandler(DependencyObject obj) => (SizeChangedEventHandler)obj.GetValue(HandlerProperty);
59+
60+
public static void SetHandler(DependencyObject obj, SizeChangedEventHandler value) => obj.SetValue(HandlerProperty, value);
7461

75-
// Using a DependencyProperty as the backing store for Handler. This enables animation, styling, binding, etc...
7662
public static readonly DependencyProperty HandlerProperty =
7763
DependencyProperty.RegisterAttached("Handler", typeof(SizeChangedEventHandler), typeof(FillManager), new UIPropertyMetadata(null));
7864

7965
private static void TextBlock_Loaded(object sender, RoutedEventArgs e)
8066
{
8167
var textBlock = (TextBlock)sender;
8268

83-
if (!(VisualTreeHelper.GetParent(textBlock) is FrameworkElement parent))
69+
if (VisualTreeHelper.GetParent(textBlock) is not FrameworkElement parent)
8470
{
8571
return;
8672
}
@@ -113,39 +99,24 @@ private static void TextBlock_Unloaded(object sender, RoutedEventArgs e)
11399
TextDescriptor.RemoveValueChanged(textBlock, MeasureFontSize);
114100
FontFamilyDescriptor.RemoveValueChanged(textBlock, MeasureFontSize);
115101
}
116-
117-
public static double GetMaxFontSize(DependencyObject obj)
118-
{
119-
return (double)obj.GetValue(MaxFontSizeProperty);
120-
}
121102

122-
public static void SetMaxFontSize(DependencyObject obj, double value)
123-
{
124-
obj.SetValue(MaxFontSizeProperty, value);
125-
}
103+
public static double GetMaxFontSize(DependencyObject obj) => (double)obj.GetValue(MaxFontSizeProperty);
104+
105+
public static void SetMaxFontSize(DependencyObject obj, double value) => obj.SetValue(MaxFontSizeProperty, value);
126106

127107
// Using a DependencyProperty as the backing store for MaxFontSize. This enables animation, styling, binding, etc...
128108
public static readonly DependencyProperty MaxFontSizeProperty =
129109
DependencyProperty.RegisterAttached("MaxFontSize", typeof(double), typeof(FillManager), new UIPropertyMetadata(100.0));
130-
131-
public static double GetInterlinyage(DependencyObject obj)
132-
{
133-
return (double)obj.GetValue(InterlinyageProperty);
134-
}
135110

136-
public static void SetInterlinyage(DependencyObject obj, double value)
137-
{
138-
obj.SetValue(InterlinyageProperty, value);
139-
}
111+
public static double GetInterlinyage(DependencyObject obj) => (double)obj.GetValue(InterlinyageProperty);
112+
113+
public static void SetInterlinyage(DependencyObject obj, double value) => obj.SetValue(InterlinyageProperty, value);
140114

141115
// Using a DependencyProperty as the backing store for Interlinyage. This enables animation, styling, binding, etc...
142116
public static readonly DependencyProperty InterlinyageProperty =
143117
DependencyProperty.RegisterAttached("Interlinyage", typeof(double), typeof(FillManager), new UIPropertyMetadata(0.0, OnInterlinyageChanged));
144118

145-
public static void OnInterlinyageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
146-
{
147-
MeasureFontSize(d, EventArgs.Empty);
148-
}
119+
public static void OnInterlinyageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => MeasureFontSize(d, EventArgs.Empty);
149120

150121
/// <summary>
151122
/// Задаёт как можно больший размер шрифта текстового блока исходя из доступной для него области
@@ -155,7 +126,8 @@ public static void OnInterlinyageChanged(DependencyObject d, DependencyPropertyC
155126
private static void MeasureFontSize(object sender, EventArgs e)
156127
{
157128
var textBlock = sender as TextBlock;
158-
if (!(VisualTreeHelper.GetParent(textBlock) is FrameworkElement parent))
129+
130+
if (VisualTreeHelper.GetParent(textBlock) is not FrameworkElement parent)
159131
{
160132
return;
161133
}
@@ -186,6 +158,7 @@ private static void MeasureFontSize(object sender, EventArgs e)
186158
};
187159

188160
var lineHeight = GetInterlinyage(textBlock);
161+
189162
if (lineHeight < textBlock.FontFamily.LineSpacing)
190163
{
191164
lineHeight = textBlock.FontFamily.LineSpacing;
@@ -194,6 +167,7 @@ private static void MeasureFontSize(object sender, EventArgs e)
194167
var coef = lineHeight / textBlock.FontFamily.LineSpacing;
195168

196169
double fontSize;
170+
197171
if (textBlock.TextWrapping == TextWrapping.NoWrap)
198172
{
199173
fontSize = GetMaxFontSize(textBlock);
@@ -223,12 +197,18 @@ private static void MeasureFontSize(object sender, EventArgs e)
223197
ft.SetFontSize(fontSize);
224198
double textHeight = ft.Height * coef;
225199

226-
if (fontSize > 1.0 && (textHeight > height || (textBlock.TextWrapping == TextWrapping.NoWrap ? ft.Width > width * 0.97 : ft.MinWidth > ft.MaxTextWidth)))
200+
if (fontSize > 1.0
201+
&& (textHeight > height
202+
|| (textBlock.TextWrapping == TextWrapping.NoWrap
203+
? ft.Width > width * 0.97
204+
: ft.MinWidth > ft.MaxTextWidth)))
227205
{
228206
var lower = 1.0;
229207

230208
if (textHeight > height && textBlock.TextWrapping == TextWrapping.NoWrap)
209+
{
231210
lower = Math.Max(lower, (textHeight - height) / lineHeight);
211+
}
232212

233213
fontSize -= lower;
234214
continue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.Web.WebView2.Core;
2+
using Microsoft.Web.WebView2.WinForms;
3+
using System;
4+
using System.Diagnostics;
5+
using System.Windows;
6+
7+
namespace SIUI.Behaviors
8+
{
9+
/// <summary>
10+
/// Attaches additional behavior for WebView2 control.
11+
/// </summary>
12+
internal static class WebView2Behavior
13+
{
14+
public static bool GetIsAttached(DependencyObject obj) => (bool)obj.GetValue(IsAttachedProperty);
15+
16+
public static void SetIsAttached(DependencyObject obj, bool value) => obj.SetValue(IsAttachedProperty, value);
17+
18+
public static readonly DependencyProperty IsAttachedProperty =
19+
DependencyProperty.RegisterAttached("IsAttached", typeof(bool), typeof(WebView2), new PropertyMetadata(false, OnIsAttachedChanged));
20+
21+
public static void OnIsAttachedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
22+
{
23+
if (!(bool)e.NewValue)
24+
{
25+
return;
26+
}
27+
28+
var webView2 = (Microsoft.Web.WebView2.Wpf.WebView2)d;
29+
30+
UpdateWebView2Environment(webView2);
31+
}
32+
33+
private static async void UpdateWebView2Environment(Microsoft.Web.WebView2.Wpf.WebView2 webView2)
34+
{
35+
try
36+
{
37+
var options = new CoreWebView2EnvironmentOptions("--autoplay-policy=no-user-gesture-required");
38+
var environment = await CoreWebView2Environment.CreateAsync(null, null, options);
39+
40+
await webView2.EnsureCoreWebView2Async(environment);
41+
}
42+
catch (Exception exc)
43+
{
44+
Trace.TraceError(exc.ToString());
45+
}
46+
}
47+
}
48+
}

src/Common/SIUI/Table.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@
372372
</DataTemplate>
373373

374374
<DataTemplate x:Key="{x:Static vm:QuestionContentType.Html}">
375-
<wv2:WebView2 Source="{Binding MediaSource.Uri}" />
375+
<wv2:WebView2 Source="{Binding MediaSource.Uri}" lb:WebView2Behavior.IsAttached="True" />
376376
</DataTemplate>
377377

378378
<DataTemplate x:Key="{x:Static vm:QuestionContentType.SpecialText}">

src/SICore/SICore/Clients/Game/Game.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1724,9 +1724,17 @@ private void OnPass(Message message)
17241724
}
17251725
}
17261726

1727-
if (canPressChanged && !ClientData.TInfo.Pause && ClientData.IsThinking && ClientData.Players.All(p => !p.CanPress))
1727+
if (canPressChanged && ClientData.Players.All(p => !p.CanPress) && !ClientData.TInfo.Pause)
17281728
{
1729-
_logic.ScheduleExecution(Tasks.WaitTry, 3, force: true);
1729+
if (!ClientData.IsAnswer)
1730+
{
1731+
if (!ClientData.IsQuestionFinished)
1732+
{
1733+
_logic.Engine.MoveToAnswer();
1734+
}
1735+
1736+
_logic.ExecuteImmediate();
1737+
}
17301738
}
17311739
}
17321740

src/SICore/SICore/Clients/Game/GameLogic.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ private bool OnDecisionAnswerValidating()
11571157

11581158
var s = new StringBuilder(GetRandomString(LO[showmanReplic]));
11591159

1160-
var canonicalAnswer = _data.Question.GetRightAnswers().FirstOrDefault();
1160+
var canonicalAnswer = _data.Question.Right.FirstOrDefault();
11611161
var isAnswerCanonical = canonicalAnswer != null && _data.Answerer.Answer.Simplify().Contains(canonicalAnswer.Simplify());
11621162

11631163
if (!IsFinalRound())
@@ -1296,14 +1296,14 @@ public void ContinueQuestion()
12961296
{
12971297
if (!ClientData.Settings.AppSettings.FalseStart)
12981298
{
1299-
_gameActions.SendMessage(Messages.Resume); // Для возобновления мультимедиа
1299+
_gameActions.SendMessage(Messages.Resume); // To resume the media
13001300
}
13011301

13021302
ScheduleExecution(Tasks.AskToTry, 10, force: true);
13031303
return;
13041304
}
13051305

1306-
// Возобновить чтение вопроса
1306+
// Resume question playing
13071307
if (_data.IsPartial && _data.AtomType == AtomTypes.Text)
13081308
{
13091309
ScheduleExecution(Tasks.PrintPartial, 5, force: true);
@@ -2569,6 +2569,12 @@ private void PrintStakeQuestion()
25692569

25702570
private void AskToTry()
25712571
{
2572+
if (ClientData.Players.All(p => !p.CanPress))
2573+
{
2574+
ScheduleExecution(Tasks.WaitTry, 3, force: true);
2575+
return;
2576+
}
2577+
25722578
if (_data.Settings.AppSettings.FalseStart)
25732579
{
25742580
_gameActions.SendMessage(Messages.Try);

src/SICore/SICore/Clients/IPerson.cs

-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,5 @@ public interface IPerson : IViewer
3838
/// Определение стоимости Вопроса с секретом
3939
/// </summary>
4040
void CatCost();
41-
42-
void Table();
43-
44-
void FinalThemes();
4541
}
4642
}

src/SICore/SICore/Clients/Player/Player.cs

+4-22
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ protected override async ValueTask OnSystemMessageReceivedAsync(string[] mparams
325325
ClientData.PersonDataExtensions.SendStake.CanBeExecuted = mparams[2] == "+";
326326
ClientData.PersonDataExtensions.SendPass.CanBeExecuted = mparams[3] == "+";
327327
ClientData.PersonDataExtensions.SendVabank.CanBeExecuted = mparams[4] == "+";
328+
328329
for (int i = 0; i < 4; i++)
329330
{
330331
ClientData.PersonDataExtensions.Var[i] = mparams[i + 1] == "+";
@@ -379,27 +380,6 @@ protected override async ValueTask OnSystemMessageReceivedAsync(string[] mparams
379380
_logic.PersonAnswered(playerIndex, isRight);
380381
break;
381382

382-
case Messages.Table:
383-
{
384-
#region Tablo2
385-
386-
_logic.Table();
387-
388-
#endregion
389-
break;
390-
}
391-
392-
case Messages.RoundThemes:
393-
{
394-
#region RoundThemes
395-
396-
if (ClientData.Stage == GameStage.Final)
397-
_logic.FinalThemes();
398-
399-
#endregion
400-
break;
401-
}
402-
403383
case Messages.Report:
404384
var report = new StringBuilder();
405385
for (int r = 1; r < mparams.Length; r++)
@@ -425,16 +405,18 @@ private void OnValidation(string[] mparams)
425405
ClientData.PersonDataExtensions.ValidatorName = mparams[1];
426406
ClientData.PersonDataExtensions.Answer = mparams[2];
427407
_logic.IsRight(mparams[3] == "+");
428-
int.TryParse(mparams[4], out var rightAnswersCount);
408+
_ = int.TryParse(mparams[4], out var rightAnswersCount);
429409
rightAnswersCount = Math.Min(rightAnswersCount, mparams.Length - 5);
430410

431411
var right = new List<string>();
412+
432413
for (int i = 0; i < rightAnswersCount; i++)
433414
{
434415
right.Add(mparams[5 + i]);
435416
}
436417

437418
var wrong = new List<string>();
419+
438420
for (int i = 5 + rightAnswersCount; i < mparams.Length; i++)
439421
{
440422
wrong.Add(mparams[i]);

src/SICore/SICore/Clients/Player/PlayerComputerLogic.cs

-10
Original file line numberDiff line numberDiff line change
@@ -1662,16 +1662,6 @@ public void ApellateChanged()
16621662

16631663
}
16641664

1665-
public void Table()
1666-
{
1667-
1668-
}
1669-
1670-
public void FinalThemes()
1671-
{
1672-
1673-
}
1674-
16751665
public void Clear()
16761666
{
16771667

0 commit comments

Comments
 (0)