Skip to content

Commit b12ff26

Browse files
committed
colorized input prompts, guild window button visibility fixes
1 parent 51b231b commit b12ff26

File tree

7 files changed

+118
-50
lines changed

7 files changed

+118
-50
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ partial class GuildWindow : Window
2828
private readonly MenuItem _kickOption;
2929
private readonly MenuItem _transferOption;
3030

31-
private readonly bool _addButtonUsed;
32-
private readonly bool _addPopupButtonUsed;
31+
private bool _addButtonUsed;
32+
private bool _addPopupButtonUsed;
3333
private GuildMember? _selectedMember;
3434

3535
public GuildWindow(Canvas gameCanvas) : base(gameCanvas, Globals.Me?.Guild, false, nameof(GuildWindow))
@@ -162,9 +162,6 @@ public GuildWindow(Canvas gameCanvas) : base(gameCanvas, Globals.Me?.Guild, fals
162162
_transferOption.Clicked += transferOption_Clicked;
163163

164164
#endregion
165-
166-
_addButtonUsed = !_buttonAdd.IsHidden;
167-
_addPopupButtonUsed = !_buttonAddPopup.IsHidden;
168165
}
169166

170167
protected override void EnsureInitialized()
@@ -173,6 +170,9 @@ protected override void EnsureInitialized()
173170

174171
_contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer?.GetResolutionString());
175172
LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer?.GetResolutionString());
173+
174+
_addButtonUsed = !_buttonAdd.IsHidden;
175+
_addPopupButtonUsed = !_buttonAddPopup.IsHidden;
176176
}
177177

178178
//Methods
@@ -449,7 +449,7 @@ private void transferOption_Clicked(Base sender, MouseButtonState arguments)
449449

450450
_ = new InputBox(
451451
Strings.Guilds.TransferTitle,
452-
Strings.Guilds.TransferPrompt.ToString(_selectedMember?.Name, rank.Title, Globals.Me?.Guild),
452+
Strings.Guilds.TransferToMemberPrompt.ToString(_selectedMember?.Name, rank.Title, Globals.Me?.Guild),
453453
InputType.TextInput,
454454
userData: _selectedMember,
455455
onSubmit: (sender, args) =>

Intersect.Client.Core/Interface/Shared/InputBox.cs

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ private InvalidOperationException CreateInvalidInputTypeException() =>
6161
Dock = Pos.Fill,
6262
};
6363

64-
var promptLabel = new Label(inputPanel, name: nameof(_promptLabel))
64+
var promptScroller = new ScrollControl(inputPanel, name: nameof(_promptScroller))
65+
{
66+
Dock = Pos.Fill,
67+
};
68+
69+
var promptLabel = new RichLabel(promptScroller, name: nameof(_promptLabel))
6570
{
66-
AutoSizeToContents = false,
6771
Dock = Pos.Fill,
6872
Font = _defaultFont,
69-
TextAlign = Pos.CenterH,
70-
WrappingBehavior = WrappingBehavior.Wrapped,
7173
};
7274

7375
var buttonsPanel = new Panel(this, name: nameof(_buttonPanel))
@@ -103,13 +105,15 @@ private void OkayButtonOnClicked(Base @base, MouseButtonState mouseButtonState)
103105
Dock = Pos.Fill,
104106
};
105107

106-
var promptLabel = new Label(inputPanel, name: nameof(_promptLabel))
108+
var promptScroller = new ScrollControl(inputPanel, name: nameof(_promptScroller))
109+
{
110+
Dock = Pos.Fill,
111+
};
112+
113+
var promptLabel = new RichLabel(promptScroller, name: nameof(_promptLabel))
107114
{
108-
AutoSizeToContents = false,
109115
Dock = Pos.Fill,
110116
Font = _defaultFont,
111-
TextAlign = Pos.CenterH,
112-
WrappingBehavior = WrappingBehavior.Wrapped,
113117
};
114118

115119
var buttonsPanel = new Panel(this, name: nameof(_buttonPanel))
@@ -151,13 +155,15 @@ private void OkayButtonOnClicked(Base @base, MouseButtonState mouseButtonState)
151155
Dock = Pos.Fill,
152156
};
153157

154-
var promptLabel = new Label(inputPanel, name: nameof(_promptLabel))
158+
var promptScroller = new ScrollControl(inputPanel, name: nameof(_promptScroller))
159+
{
160+
Dock = Pos.Fill,
161+
};
162+
163+
var promptLabel = new RichLabel(promptScroller, name: nameof(_promptLabel))
155164
{
156-
AutoSizeToContents = false,
157165
Dock = Pos.Fill,
158166
Font = _defaultFont,
159-
TextAlign = Pos.CenterH,
160-
WrappingBehavior = WrappingBehavior.Wrapped,
161167
};
162168

163169
var buttonsPanel = new Panel(this, name: nameof(_buttonPanel))
@@ -223,20 +229,23 @@ private void NoButtonOnClicked(Base sender, MouseButtonState arguments)
223229
Dock = Pos.Fill,
224230
};
225231

226-
var promptLabel = new Label(inputPanel, name: nameof(_promptLabel))
232+
var promptScroller = new ScrollControl(inputPanel, name: nameof(_promptScroller))
233+
{
234+
Dock = Pos.Fill,
235+
};
236+
237+
var promptLabel = new RichLabel(promptScroller, name: nameof(_promptLabel))
227238
{
228-
AutoSizeToContents = false,
229239
Dock = Pos.Fill,
230240
Font = _defaultFont,
231-
TextAlign = Pos.CenterH,
232-
WrappingBehavior = WrappingBehavior.Wrapped,
233241
};
234242

235243
var numericInput = new TextBoxNumeric(inputPanel, name: nameof(_numericInputTextbox))
236244
{
237245
AutoSizeToContents = false,
238246
Dock = Pos.Bottom,
239247
Font = _defaultFont,
248+
Margin = new Margin(0, 8, 0, 0),
240249
TextAlign = Pos.Left,
241250
WrappingBehavior = WrappingBehavior.NoWrap,
242251
};
@@ -288,20 +297,23 @@ private void NumericInputOnValueChanged(TextBoxNumeric sender, ValueChangedEvent
288297
Dock = Pos.Fill,
289298
};
290299

291-
var promptLabel = new Label(inputPanel, name: nameof(_promptLabel))
300+
var promptScroller = new ScrollControl(inputPanel, name: nameof(_promptScroller))
301+
{
302+
Dock = Pos.Fill,
303+
};
304+
305+
var promptLabel = new RichLabel(promptScroller, name: nameof(_promptLabel))
292306
{
293-
AutoSizeToContents = false,
294307
Dock = Pos.Fill,
295308
Font = _defaultFont,
296-
TextAlign = Pos.CenterH,
297-
WrappingBehavior = WrappingBehavior.Wrapped,
298309
};
299310

300311
var numericSliderInput = new LabeledSlider(inputPanel, name: nameof(_numericInputSlider))
301312
{
302313
AutoSizeToContents = false,
303314
Dock = Pos.Bottom,
304315
Font = _defaultFont,
316+
Margin = new Margin(0, 8, 0, 0),
305317
Rounding = 0,
306318
};
307319
numericSliderInput.ValueChanged += NumericSliderInputOnValueChanged;
@@ -348,20 +360,23 @@ private void NumericSliderInputOnValueChanged(Base sender, ValueChangedEventArgs
348360
Dock = Pos.Fill,
349361
};
350362

351-
var promptLabel = new Label(inputPanel, name: nameof(_promptLabel))
363+
var promptScroller = new ScrollControl(inputPanel, name: nameof(_promptScroller))
364+
{
365+
Dock = Pos.Fill,
366+
};
367+
368+
var promptLabel = new RichLabel(promptScroller, name: nameof(_promptLabel))
352369
{
353-
AutoSizeToContents = false,
354370
Dock = Pos.Fill,
355371
Font = _defaultFont,
356-
TextAlign = Pos.CenterH,
357-
WrappingBehavior = WrappingBehavior.Wrapped,
358372
};
359373

360374
var stringInput = new TextBox(inputPanel, name: nameof(_stringInput))
361375
{
362376
AutoSizeToContents = false,
363377
Dock = Pos.Bottom,
364378
Font = _defaultFont,
379+
Margin = new Margin(0, 8, 0, 0),
365380
TextAlign = Pos.Left,
366381
WrappingBehavior = WrappingBehavior.NoWrap,
367382
};
@@ -417,7 +432,8 @@ private void StringInputOnTextChanged(TextBox sender, ValueChangedEventArgs<stri
417432
//
418433
// NumericSliderInput,
419434

420-
private readonly Label _promptLabel;
435+
private readonly ScrollControl _promptScroller;
436+
private readonly RichLabel _promptLabel;
421437

422438
private readonly LabeledSlider? _numericInputSlider;
423439
private readonly TextBoxNumeric? _numericInputTextbox;
@@ -453,6 +469,9 @@ public InputBox(
453469
{
454470
}
455471

472+
private int _initialScrollerInnerHeight;
473+
private int _initialMinimumHeight;
474+
456475
protected InputBox(
457476
string name,
458477
string title,
@@ -500,7 +519,10 @@ protected InputBox(
500519
_okayButton = _inputPanel.FindChildByName<Button>(nameof(_okayButton));
501520
_yesButton = _inputPanel.FindChildByName<Button>(nameof(_yesButton));
502521

503-
_promptLabel = _inputPanel.FindChildByName<Label>(nameof(_promptLabel)) ??
522+
_promptScroller = _inputPanel.FindChildByName<ScrollControl>(nameof(_promptScroller)) ??
523+
throw new InvalidOperationException("Prompt scroller wasn't created");
524+
525+
_promptLabel = _promptScroller.FindChildByName<RichLabel>(nameof(_promptLabel)) ??
504526
throw new InvalidOperationException("Prompt label wasn't created");
505527

506528
_promptLabel.Text = prompt;
@@ -612,6 +634,26 @@ protected override void EnsureInitialized()
612634
Name = $"{GetType().GetName(qualified: false)}_{InputType}";
613635
LoadJsonUi(GameContentManager.UI.Shared, Graphics.Renderer?.GetResolutionString());
614636

637+
var promptScrollerInnerPanelPadding = _promptScroller.InnerPanel.Padding;
638+
var promptScrollerInnerPanelPaddingV =
639+
promptScrollerInnerPanelPadding.Bottom + promptScrollerInnerPanelPadding.Top;
640+
_initialScrollerInnerHeight = _promptScroller.InnerHeight - promptScrollerInnerPanelPaddingV;
641+
_initialMinimumHeight = MinimumSize.Y;
642+
643+
_promptLabel.Rebuilt += (_, _) =>
644+
{
645+
var newHeight = _promptLabel.Height;
646+
newHeight = Math.Min(400, newHeight);
647+
var delta = newHeight - _initialScrollerInnerHeight;
648+
MinimumSize = MinimumSize with
649+
{
650+
Y = _initialMinimumHeight + delta,
651+
};
652+
SizeToChildren();
653+
};
654+
655+
_promptLabel.ForceImmediateRebuild();
656+
615657
Show();
616658
Focus();
617659
}

Intersect.Client.Core/Localization/Strings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,9 @@ public partial struct Guilds
13281328
public static LocalizedString Transfer = @"Transfer";
13291329

13301330
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
1331-
public static LocalizedString TransferPrompt = @"This action will completely transfer all ownership of your guild to {00} and you will lose your rank of {01}. If you are sure you want to hand over your guild enter '{02}' below.";
1331+
public static LocalizedString TransferToMemberPrompt = @"This action will completely transfer all ownership of your guild to \c{{#80ff80}}{00}\c{{}} and you will lose your rank of \c{{#ff9f40}}{01}\c{{}}.
1332+
1333+
If you are sure you want to hand over your guild enter '\c{{#ff8080}}{02}\c{{}}' below.";
13321334

13331335
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
13341336
public static LocalizedString TransferTitle = @"Transfer Guild";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Intersect.Client.Utilities;
2+
3+
public record struct ColorizedText(string Text, Color? Color);

Intersect.Client.Framework/Gwen/Control/Base.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,13 @@ public Point MinimumSize
941941
get => _minimumSize;
942942
set
943943
{
944+
var oldValue = _minimumSize;
944945
_minimumSize = value;
945946
if (_innerPanel != null)
946947
{
947948
_innerPanel.MinimumSize = InnerPanelSizeFrom(value);
948949
}
950+
OnMinimumSizeChanged(oldValue, value);
949951
}
950952
}
951953

@@ -957,11 +959,13 @@ public Point MaximumSize
957959
get => _maximumSize;
958960
set
959961
{
962+
var oldValue = _maximumSize;
960963
_maximumSize = value;
961964
if (_innerPanel != null)
962965
{
963966
_innerPanel.MaximumSize = InnerPanelSizeFrom(value);
964967
}
968+
OnMaximumSizeChanged(oldValue, value);
965969
}
966970
}
967971

@@ -2389,6 +2393,13 @@ public virtual bool SetBounds(Point position, Point size) => SetBounds(
23892393
/// </returns>
23902394
public virtual bool SetBounds(float x, float y, float width, float height) => SetBounds((int) x, (int) y, (int) width, (int) height);
23912395

2396+
protected virtual void OnMaximumSizeChanged(Point oldSize, Point newSize)
2397+
{
2398+
}
2399+
protected virtual void OnMinimumSizeChanged(Point oldSize, Point newSize)
2400+
{
2401+
}
2402+
23922403
protected virtual void OnSizeChanged(Point oldSize, Point newSize)
23932404
{
23942405
Parent?.OnChildSizeChanged(this, oldSize, newSize);

Intersect.Client.Framework/Gwen/Control/RichLabel.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Intersect.Client.Framework.File_Management;
22
using Intersect.Client.Framework.GenericClasses;
33
using Intersect.Client.Framework.Graphics;
4+
using Intersect.Client.Utilities;
45
using Intersect.Core;
56
using Microsoft.Extensions.Logging;
67
using Newtonsoft.Json.Linq;
@@ -35,6 +36,16 @@ public GameFont? Font
3536
}
3637
}
3738

39+
public string? Text
40+
{
41+
get => string.Join('\n', _textBlocks.Select(block => block.Text));
42+
set
43+
{
44+
ClearText();
45+
AddText(value ?? string.Empty, default(Color));
46+
}
47+
}
48+
3849
/// <summary>
3950
/// Initializes a new instance of the <see cref="RichLabel" /> class.
4051
/// </summary>
@@ -89,7 +100,7 @@ public override void LoadJson(JToken obj, bool isRoot = default)
89100
/// </summary>
90101
/// <param name="text">Text to add</param>
91102
/// <param name="template">Label to use as a template</param>
92-
public void AddText(string text, Label? template)
103+
public void AddText(string? text, Label? template)
93104
{
94105
AddText(
95106
text,
@@ -99,7 +110,7 @@ public void AddText(string text, Label? template)
99110
);
100111
}
101112

102-
public void AddText(string text, Color? color) => AddText(text, color, Alignments.Left);
113+
public void AddText(string? text, Color? color) => AddText(text, color, Alignments.Left);
103114

104115
/// <summary>
105116
/// Adds text to the control.
@@ -108,13 +119,24 @@ public void AddText(string text, Label? template)
108119
/// <param name="color">Text color.</param>
109120
/// <param name="alignment"></param>
110121
/// <param name="font">Font to use.</param>
111-
public void AddText(string text, Color? color, Alignments alignment, GameFont? font = default)
122+
public void AddText(string? text, Color? color, Alignments alignment, GameFont? font = default)
112123
{
113124
if (string.IsNullOrEmpty(text))
114125
{
115126
return;
116127
}
117128

129+
if (text.Contains("\\c"))
130+
{
131+
var colorizedSegments = TextColorParser.Parse(text, color);
132+
foreach (var segment in colorizedSegments)
133+
{
134+
AddText(segment.Text, segment.Color ?? color, alignment, font);
135+
}
136+
137+
return;
138+
}
139+
118140
font ??= _font;
119141

120142
var lines = text.Split(_newlines, StringSplitOptions.None);
@@ -502,9 +524,9 @@ private void Rebuild()
502524
}
503525
}
504526

505-
Rebuilt?.Invoke(this, EventArgs.Empty);
506527
var resizeX = !Dock.HasFlag(Pos.Fill) || _dockFillSize == default || _dockFillSize.X != Width;
507528
base.SizeToChildren(resizeX: resizeX, resizeY: true);
529+
Rebuilt?.Invoke(this, EventArgs.Empty);
508530
}
509531

510532
// protected override void OnBoundsChanged(Rectangle oldBounds, Rectangle newBounds)

0 commit comments

Comments
 (0)