Skip to content

Commit 86ab563

Browse files
committed
improve precision for gui textures verifier
1 parent 6140c88 commit 86ab563

2 files changed

Lines changed: 41 additions & 11 deletions

File tree

src/ModVerify/Verifiers/GuiDialogs/GuiDialogsVerifier.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sealed class GuiDialogsVerifier : GameVerifier
1818
{
1919
internal const string DefaultComponentIdentifier = "<<DEFAULT>>";
2020

21-
private static readonly GuiComponentType[] GuiComponentTypes =
21+
private static readonly IReadOnlyList<GuiComponentType> GuiComponentTypes =
2222
Enum.GetValues(typeof(GuiComponentType)).OfType<GuiComponentType>().ToArray();
2323

2424
private readonly IAlreadyVerifiedCache? _cache;
@@ -85,13 +85,18 @@ private void VerifyMegaTexturesExist(CancellationToken token)
8585

8686
private void VerifyGuiComponentTexturesExist(string component)
8787
{
88-
var middleButtonInRepoMode = false;
88+
var buttonSpecialMode = false;
8989

9090
var entriesForComponent = GetTextureEntriesForComponents(component, out var defined);
9191
if (!defined)
9292
return;
9393

94-
// TODO: Button Middle needs to be checked first as the engine checks this first
94+
if (entriesForComponent.TryGetValue(GuiComponentType.ButtonMiddle, out var middleTexture))
95+
{
96+
GameEngine.GuiDialogManager.TextureExists(middleTexture, out var origin, out _);
97+
if (origin == GuiTextureOrigin.Repository)
98+
buttonSpecialMode = true;
99+
}
95100

96101
foreach (var componentType in GuiComponentTypes)
97102
{
@@ -100,11 +105,17 @@ private void VerifyGuiComponentTexturesExist(string component)
100105
if (!entriesForComponent.TryGetValue(componentType, out var texture))
101106
continue;
102107

108+
if (buttonSpecialMode && componentType.IsButton() && !componentType.SupportsSpecialTextureMode())
109+
{
110+
// If we are in special button mode, non-supported button textures won't be loaded anyway.
111+
continue;
112+
}
113+
103114
var cached = _cache?.GetEntry(texture.Texture);
104115
if (cached?.AlreadyVerified is true)
105116
{
106117
// If we are in a special case we don't want to skip
107-
if (!middleButtonInRepoMode &&
118+
if (!buttonSpecialMode &&
108119
componentType is not GuiComponentType.ButtonMiddle &&
109120
componentType is not GuiComponentType.Scanlines &&
110121
componentType is not GuiComponentType.FrameBackground)
@@ -115,7 +126,7 @@ componentType is not GuiComponentType.Scanlines &&
115126
texture,
116127
out var origin,
117128
out var isNone,
118-
middleButtonInRepoMode);
129+
buttonSpecialMode);
119130

120131
if (!exists && !isNone)
121132
{
@@ -130,16 +141,13 @@ componentType is not GuiComponentType.Scanlines &&
130141
AddNotFoundError(texture, component, origin);
131142
}
132143
}
133-
134-
if (componentType is GuiComponentType.ButtonMiddle && origin is GuiTextureOrigin.Repository)
135-
middleButtonInRepoMode = true;
136-
144+
137145
_cache?.TryAddEntry(texture.Texture, exists);
138146
}
139147
finally
140148
{
141-
if (componentType >= GuiComponentType.ButtonRightDisabled)
142-
middleButtonInRepoMode = false;
149+
if (!componentType.IsButton())
150+
buttonSpecialMode = false;
143151
}
144152
}
145153
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace PG.StarWarsGame.Engine.GuiDialog;
2+
3+
public static class ExtensionMethods
4+
{
5+
extension(GuiComponentType componentType)
6+
{
7+
public bool IsButton()
8+
{
9+
return componentType <= GuiComponentType.ButtonRightDisabled;
10+
}
11+
12+
public bool SupportsSpecialTextureMode()
13+
{
14+
return componentType is GuiComponentType.ButtonMiddle
15+
or GuiComponentType.ButtonMiddleMouseOver
16+
or GuiComponentType.ButtonMiddlePressed
17+
or GuiComponentType.ButtonMiddleDisabled
18+
or GuiComponentType.Scanlines
19+
or GuiComponentType.FrameBackground;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)