Skip to content

Commit d6e1851

Browse files
committed
window and tooltip fixes
1 parent 258562c commit d6e1851

File tree

16 files changed

+486
-306
lines changed

16 files changed

+486
-306
lines changed

Intersect.Client.Core/Interface/Debugging/DebugWindow.cs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Intersect.Async;
22
using Intersect.Client.Core;
3+
using Intersect.Client.Framework.Content;
34
using Intersect.Client.Framework.Graphics;
45
using Intersect.Client.Framework.Gwen;
56
using Intersect.Client.Framework.Gwen.Control;
@@ -39,28 +40,83 @@ public DebugWindow(Base parent) : base(parent, Strings.Debug.Title, false, nameo
3940
TableDebugStats = CreateInfoTableDebugStats(TabInfo.Page);
4041

4142
TabAssets = Tabs.AddPage(Strings.Debug.TabLabelAssets);
42-
AssetsList = CreateAssetsList(TabAssets.Page);
4343
AssetsToolsTable = CreateAssetsToolsTable(TabAssets.Page);
44+
AssetsList = CreateAssetsList(TabAssets.Page);
45+
AssetsButtonReloadAsset = CreateAssetsButtonReloadAsset(AssetsToolsTable, AssetsList);
46+
47+
AssetsToolsTable.SizeToChildren();
4448

4549
IsHidden = true;
4650
}
4751

4852
private SearchableTree CreateAssetsList(Base parent)
4953
{
5054
var dataProvider = new TexturesSearchableTreeDataProvider(Current, this);
51-
SearchableTree textureList = new(parent, dataProvider)
55+
SearchableTree assetList = new(parent, dataProvider)
5256
{
5357
Dock = Pos.Fill,
5458
FontSearch = _defaultFont,
5559
FontTree = _defaultFont,
60+
Margin = new Margin(0, 4, 0, 0),
61+
SearchPlaceholderText = Strings.Debug.AssetsSearchPlaceholder,
5662
};
5763

58-
return textureList;
64+
return assetList;
5965
}
6066

6167
private Table CreateAssetsToolsTable(Base assetsTabPage)
6268
{
63-
return new Table(assetsTabPage, nameof(AssetsToolsTable));
69+
Table table = new(assetsTabPage, nameof(AssetsToolsTable))
70+
{
71+
ColumnCount = 2,
72+
Dock = Pos.Top,
73+
};
74+
75+
return table;
76+
}
77+
78+
private Button CreateAssetsButtonReloadAsset(Table table, SearchableTree assetList)
79+
{
80+
var row = table.AddRow();
81+
82+
Button buttonReloadAsset = new(row, name: nameof(AssetsButtonReloadAsset))
83+
{
84+
IsDisabled = assetList.SelectedNodes.Length < 1,
85+
Font = _defaultFont,
86+
Text = Strings.Debug.ReloadAsset,
87+
};
88+
89+
assetList.SelectionChanged += (_, _) =>
90+
buttonReloadAsset.IsDisabled = assetList.SelectedNodes.All(
91+
node => node.UserData is not SearchableTreeDataEntry { UserData: GameTexture }
92+
);
93+
94+
buttonReloadAsset.Clicked += (_, _) =>
95+
{
96+
foreach (var node in assetList.SelectedNodes)
97+
{
98+
if (node.UserData is not SearchableTreeDataEntry entry)
99+
{
100+
continue;
101+
}
102+
103+
if (entry.UserData is not IAsset asset)
104+
{
105+
continue;
106+
}
107+
108+
// TODO: Audio reloading?
109+
if (asset is not GameTexture texture)
110+
{
111+
continue;
112+
}
113+
114+
texture.Reload();
115+
}
116+
};
117+
row.SetCellContents(0, buttonReloadAsset, enableMouseInput: true);
118+
119+
return buttonReloadAsset;
64120
}
65121

66122
private TabControl Tabs { get; }
@@ -73,6 +129,8 @@ private Table CreateAssetsToolsTable(Base assetsTabPage)
73129

74130
private Table AssetsToolsTable { get; }
75131

132+
private Button AssetsButtonReloadAsset { get; }
133+
76134
private LabeledCheckBox CheckboxDrawDebugOutlines { get; }
77135

78136
private LabeledCheckBox CheckboxEnableLayoutHotReloading { get; }

Intersect.Client.Core/Interface/Debugging/TexturesSearchableTreeDataProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ private SearchableTreeDataEntry EntryForAsset(string parentId, IAsset asset)
109109
DisplayText: displayText,
110110
DisplayColor: displayColor,
111111
Name: assetName,
112-
ParentId: parentId
112+
ParentId: parentId,
113+
UserData: asset
113114
);
114115

115116
void OnAssetStateChanged(IAsset changedAsset)

Intersect.Client.Core/Interface/Game/Admin/AdminWindow.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public AdminWindow(Base gameCanvas) : base(
3636
)
3737
{
3838
DisableResizing();
39+
MinimumSize = new Point(320, 320);
3940
Margin = Margin.Zero;
4041
Padding = Padding.Zero;
4142

@@ -280,19 +281,17 @@ public void SetName(string name)
280281
private void UpdateMapList()
281282
{
282283
_mapList?.Dispose();
283-
_mapList = new TreeControl(this)
284+
var mapListY = 330;
285+
var mapListHeight = (_innerPanel?.Height ?? Height) - (mapListY + 4);
286+
_mapList = new TreeControl(this, nameof(_mapList))
284287
{
285288
X = 4,
286-
Y = 330,
289+
Y = mapListY,
287290
Width = Width - 8,
288-
Height = 80,
289-
RenderColor = Color.FromArgb(
290-
255,
291-
255,
292-
255,
293-
255
294-
),
291+
Height = mapListHeight,
295292
MaximumSize = new Point(4096, 999999),
293+
Font = Current?.GetFont("sourcesansproblack", 10),
294+
TextColorOverride = Color.White,
296295
};
297296
_mapList.SelectionChanged += MapList_SelectionChanged;
298297

Intersect.Client.Core/Localization/Strings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,12 @@ public partial struct Debug
985985

986986
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
987987
public static LocalizedString TabLabelAssets = @"Assets";
988+
989+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
990+
public static LocalizedString ReloadAsset = @"Reload Asset";
991+
992+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
993+
public static LocalizedString AssetsSearchPlaceholder = @"Filter assets...";
988994
}
989995

990996
public partial struct EntityBox

Intersect.Client.Core/MonoGame/Graphics/MonoTexture.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public MonoTexture(GraphicsDevice graphicsDevice, string filename, GameTexturePa
8484

8585
private void Load(Stream stream)
8686
{
87+
_texture?.Dispose();
88+
8789
_texture = Texture2D.FromStream(_graphicsDevice, stream);
8890
if (_texture == null)
8991
{
@@ -97,9 +99,9 @@ private void Load(Stream stream)
9799
EmitLoaded();
98100
}
99101

100-
public void LoadTexture()
102+
public void LoadTexture(bool force = false)
101103
{
102-
if (_texture != null)
104+
if (!force && _texture != null)
103105
{
104106
return;
105107
}
@@ -113,7 +115,7 @@ public void LoadTexture()
113115

114116
if (_packFrame != null)
115117
{
116-
((MonoTexture) _packFrame.PackTexture)?.LoadTexture();
118+
((MonoTexture) _packFrame.PackTexture)?.LoadTexture(force: force);
117119

118120
return;
119121
}
@@ -236,6 +238,8 @@ public override int Height
236238
return _texture;
237239
}
238240

241+
public override void Reload() => LoadTexture(force: true);
242+
239243
public override Color GetPixel(int x1, int y1)
240244
{
241245
if (_texture == null)

Intersect.Client.Framework/Graphics/GameRenderTexture.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ protected GameRenderTexture(int width, int height) : this(width, height, ++_next
3939
/// </summary>
4040
public abstract void End();
4141

42-
public bool SetActive(bool active)
43-
{
44-
return true;
45-
}
42+
public override void Reload() { }
4643

4744
/// <summary>
4845
/// Clears everything off the render target with a specified color.

Intersect.Client.Framework/Graphics/GameTexture.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public GameTexturePackFrame? TexturePackFrame
107107

108108
public abstract object? GetTexture();
109109

110+
public abstract void Reload();
111+
110112
[MethodImpl(MethodImplOptions.AggressiveInlining)]
111113
public TPlatformTexture? GetTexture<TPlatformTexture>() where TPlatformTexture : class =>
112114
GetTexture() as TPlatformTexture;

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ public bool IsVisible
789789
return false;
790790
}
791791

792-
return Parent == null || Parent.IsVisible;
792+
return Parent == null || Parent.IsVisible || ToolTip.IsActiveTooltip(Parent);
793793
}
794794
set => IsHidden = !value;
795795
}
@@ -1479,6 +1479,7 @@ public virtual void SetToolTipText(string? text)
14791479
labelTooltip = new Label(this, name: "Tooltip")
14801480
{
14811481
AutoSizeToContents = true,
1482+
Font = mToolTipFont ?? GameContentManager.Current?.GetFont("sourcesansproblack", 10),
14821483
MaximumSize = new Point(300, 0),
14831484
Padding = new Padding(
14841485
5,
@@ -1487,21 +1488,11 @@ public virtual void SetToolTipText(string? text)
14871488
3
14881489
),
14891490
TextColor = Skin.Colors.TooltipText,
1490-
TextColorOverride = Skin.Colors.TooltipText,
1491+
TextColorOverride = _tooltipTextColor ?? Skin.Colors.TooltipText,
14911492
ToolTipBackground = _tooltipBackground,
14921493
WrappingBehavior = WrappingBehavior.Wrapped,
14931494
};
14941495

1495-
if (mToolTipFont != default)
1496-
{
1497-
labelTooltip.Font = mToolTipFont;
1498-
}
1499-
1500-
if (_tooltipTextColor != default)
1501-
{
1502-
labelTooltip.TextColorOverride = _tooltipTextColor;
1503-
}
1504-
15051496
Tooltip = labelTooltip;
15061497
}
15071498

@@ -2357,6 +2348,11 @@ protected virtual void RenderRecursive(Skin.Base skin, Rectangle clipRect)
23572348

23582349
foreach (var child in childrenToRender)
23592350
{
2351+
if (!child.IsVisible)
2352+
{
2353+
continue;
2354+
}
2355+
23602356
child.DoRender(skin);
23612357
}
23622358

@@ -2734,6 +2730,8 @@ public virtual Base GetControlAt(int x, int y)
27342730
/// <param name="skin">Skin to use.</param>
27352731
protected virtual void Layout(Skin.Base skin)
27362732
{
2733+
UpdateColors();
2734+
27372735
if (skin?.Renderer.Ctt != null && ShouldCacheToTexture)
27382736
{
27392737
skin.Renderer.Ctt.CreateControlCacheTexture(this);

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public enum ControlState
5454
/// Initializes a new instance of the <see cref="Label" /> class.
5555
/// </summary>
5656
/// <param name="parent">Parent control.</param>
57+
/// <param name="name"></param>
58+
/// <param name="disableText"></param>
5759
public Label(Base parent, string? name = default, bool disableText = false) : base(parent, name)
5860
{
5961
_textElement = new Text(this)
6062
{
6163
IsHidden = disableText,
6264
};
6365

64-
//m_Text.Font = Skin.DefaultFont;
65-
6666
MouseInputEnabled = false;
6767
SetSize(100, 10);
6868
TextAlign = Pos.Left | Pos.Top;
@@ -138,7 +138,7 @@ public virtual string? Text
138138
/// <summary>
139139
/// Font.
140140
/// </summary>
141-
public GameFont? Font
141+
public virtual GameFont? Font
142142
{
143143
get => _textElement.Font;
144144
set
@@ -163,9 +163,9 @@ public GameFont? Font
163163
/// <summary>
164164
/// Font Name
165165
/// </summary>
166-
public string FontName
166+
public string? FontName
167167
{
168-
get => _textElement.Font.GetName();
168+
get => _textElement.Font?.GetName();
169169
set => Font = GameContentManager.Current?.GetFont(value, FontSize);
170170
}
171171

@@ -513,49 +513,54 @@ protected override void Layout(Skin.Base skin)
513513
{
514514
base.Layout(skin);
515515

516-
var align = mAlign;
517-
518516
if (mAutoSizeToContents)
519517
{
520518
SizeToContents();
521519
}
522520

521+
AlignTextElement(_textElement);
522+
}
523+
524+
protected void AlignTextElement(Text textElement)
525+
{
526+
var align = mAlign;
527+
523528
var x = mTextPadding.Left + Padding.Left;
524529
var y = mTextPadding.Top + Padding.Top;
525530

526531
if (0 != (align & Pos.Right))
527532
{
528-
x = Width - _textElement.Width - mTextPadding.Right - Padding.Right;
533+
x = Width - textElement.Width - mTextPadding.Right - Padding.Right;
529534
}
530535

531536
if (0 != (align & Pos.CenterH))
532537
{
533538
x = (int)(mTextPadding.Left +
534-
Padding.Left +
535-
(Width -
536-
_textElement.Width -
537-
mTextPadding.Left -
538-
Padding.Left -
539-
mTextPadding.Right -
540-
Padding.Right) *
541-
0.5f);
539+
Padding.Left +
540+
(Width -
541+
textElement.Width -
542+
mTextPadding.Left -
543+
Padding.Left -
544+
mTextPadding.Right -
545+
Padding.Right) *
546+
0.5f);
542547
}
543548

544549
if (0 != (align & Pos.CenterV))
545550
{
546551
y = (int)(mTextPadding.Top +
547-
Padding.Top +
548-
(Height - _textElement.Height) * 0.5f -
549-
mTextPadding.Bottom -
550-
Padding.Bottom);
552+
Padding.Top +
553+
(Height - textElement.Height) * 0.5f -
554+
mTextPadding.Bottom -
555+
Padding.Bottom);
551556
}
552557

553558
if (0 != (align & Pos.Bottom))
554559
{
555-
y = Height - _textElement.Height - mTextPadding.Bottom - Padding.Bottom;
560+
y = Height - textElement.Height - mTextPadding.Bottom - Padding.Bottom;
556561
}
557562

558-
_textElement.SetPosition(x, y);
563+
textElement.SetPosition(x, y);
559564
}
560565

561566
/// <summary>

0 commit comments

Comments
 (0)