Skip to content

Commit 51bc166

Browse files
committed
fix: don't initialize TypeWriter if it's disabled
1 parent 723e39b commit 51bc166

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

Intersect.Client.Core/Interface/Game/EventWindow.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using Intersect.Client.Core.Controls;
33
using Intersect.Client.Entities.Events;
44
using Intersect.Client.Framework.Content;
5+
using Intersect.Client.Framework.Database;
56
using Intersect.Client.Framework.File_Management;
67
using Intersect.Client.Framework.Gwen.Control;
78
using Intersect.Client.General;
89
using Intersect.Client.Interface.Game.Typewriting;
910
using Intersect.Client.Localization;
11+
using Intersect.Client.MonoGame.Database;
1012
using Intersect.Client.Networking;
1113
using Intersect.Configuration;
1214
using Intersect.Enums;
@@ -28,7 +30,7 @@ public partial class EventWindow : ImagePanel
2830
private readonly Button _buttonEventResponse3;
2931
private readonly Button _buttonEventResponse4;
3032

31-
private readonly Typewriter _writer;
33+
private readonly Typewriter? _writer;
3234
private bool _isTypewriting = false;
3335
private readonly long _typewriterResponseDelay = ClientConfiguration.Instance.TypewriterResponseDelay;
3436

@@ -62,7 +64,7 @@ public EventWindow(Canvas gameCanvas) : base(gameCanvas, nameof(EventWindow))
6264
_buttonEventResponse4 = new Button(this, "Response4Button");
6365
_buttonEventResponse4.Clicked += (s, e) => CloseEventResponse(EventResponseType.FourOption);
6466

65-
_writer = new Typewriter();
67+
_writer = Globals.Database.TypewriterBehavior == TypewriterBehavior.Off ? default : new Typewriter();
6668

6769
Clicked += (s, e) => SkipTypewriting();
6870
Hide();
@@ -93,15 +95,15 @@ public void Update()
9395
var voiceIdx = Randomization.Next(0, ClientConfiguration.Instance.TypewriterSounds.Count);
9496

9597
// Always show option 1 ("continue" if options empty)
96-
_buttonEventResponse1.IsHidden = !_writer.IsDone;
97-
_buttonEventResponse2.IsHidden = !_writer.IsDone || string.IsNullOrEmpty(CurrentDialog.Opt2);
98-
_buttonEventResponse3.IsHidden = !_writer.IsDone || string.IsNullOrEmpty(CurrentDialog.Opt3);
99-
_buttonEventResponse4.IsHidden = !_writer.IsDone || string.IsNullOrEmpty(CurrentDialog.Opt4);
98+
_buttonEventResponse1.IsHidden = !(_writer?.IsDone ?? true);
99+
_buttonEventResponse2.IsHidden = !(_writer?.IsDone ?? true) || string.IsNullOrEmpty(CurrentDialog.Opt2);
100+
_buttonEventResponse3.IsHidden = !(_writer?.IsDone ?? true) || string.IsNullOrEmpty(CurrentDialog.Opt3);
101+
_buttonEventResponse4.IsHidden = !(_writer?.IsDone ?? true) || string.IsNullOrEmpty(CurrentDialog.Opt4);
100102

101-
_writer.Write(ClientConfiguration.Instance.TypewriterSounds.ElementAtOrDefault(voiceIdx));
102-
if (_writer.IsDone)
103+
_writer?.Write(ClientConfiguration.Instance.TypewriterSounds.ElementAtOrDefault(voiceIdx));
104+
if (_writer?.IsDone ?? true)
103105
{
104-
var disableResponse = Timing.Global.MillisecondsUtc - _writer.DoneAtMilliseconds < _typewriterResponseDelay;
106+
var disableResponse = _writer != default && Timing.Global.MillisecondsUtc - _writer.DoneAtMilliseconds < _typewriterResponseDelay;
105107
_buttonEventResponse1.IsDisabled = disableResponse;
106108
_buttonEventResponse2.IsDisabled = disableResponse;
107109
_buttonEventResponse3.IsDisabled = disableResponse;
@@ -205,7 +207,7 @@ private void ShowDialog(RichLabel dialogLabel, Label dialogLabelTemplate, Scroll
205207
// Do this _after_ sizing so we have lines broken up
206208
if (_isTypewriting)
207209
{
208-
_writer.Initialize(dialogLabel.FormattedLabels);
210+
_writer?.Initialize(dialogLabel.FormattedLabels);
209211
_buttonEventResponse1.Hide();
210212
_buttonEventResponse2.Hide();
211213
_buttonEventResponse3.Hide();
@@ -217,7 +219,7 @@ private void ShowDialog(RichLabel dialogLabel, Label dialogLabelTemplate, Scroll
217219

218220
public void CloseEventResponse(EventResponseType response)
219221
{
220-
if (!_writer.IsDone)
222+
if (!(_writer?.IsDone ?? true))
221223
{
222224
SkipTypewriting();
223225
return;

Intersect.Client.Core/Interface/Game/Typewriting/Typewriter.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public void Initialize(List<Label> labels)
2929
_nextUpdateTime = Timing.Global.MillisecondsUtc;
3030
_labels = labels;
3131
_lines = _labels.Select(l => l.Text).ToArray();
32-
_labels.ForEach(l =>
33-
l.SetText(string.Empty)); // Clear the text from the labels. The writer is the captain now
32+
foreach (var label in _labels)
33+
{
34+
label.SetText(string.Empty);
35+
}
3436
_lineIndex = 0;
3537
_charIndex = 0;
3638
_lastChar = null;
@@ -58,7 +60,7 @@ public void Write(string? voice)
5860
return;
5961
}
6062

61-
if (_lineIndex >= _lineCount || _labels[_lineIndex] == null)
63+
if (_lineIndex != Math.Clamp(_lineIndex, 0, Math.Min(_lineCount, _labels.Count)))
6264
{
6365
End();
6466
return;
@@ -86,7 +88,7 @@ public void Write(string? voice)
8688
}
8789

8890
_lastChar = currentLine[_charIndex - 1];
89-
var written = currentLine.Substring(0, _charIndex);
91+
var written = currentLine[.._charIndex];
9092
_labels[_lineIndex].SetText(written);
9193

9294
_nextUpdateTime = Timing.Global.MillisecondsUtc + GetTypingDelayFor(currentLine[_charIndex], _lastChar);

Intersect.Client.Framework/Database/GameDatabase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ public abstract partial class GameDatabase
5858
public bool ShowHealthAsPercentage { get; set; }
5959

6060
public bool ShowManaAsPercentage { get; set; }
61-
61+
6262
public bool SimplifiedEscapeMenu { get; set; }
6363

6464
public TypewriterBehavior TypewriterBehavior { get; set; }
6565

66+
public bool TypewriterEnabled => TypewriterBehavior != TypewriterBehavior.Off;
67+
6668
public float UIScale { get; set; } = 1.0f;
6769

6870
public float WorldZoom { get; set; } = 1.0f;

0 commit comments

Comments
 (0)