Skip to content

Commit 1d5a8a2

Browse files
committed
Handle "none" GUI textures and unify repo lookups
Refactored texture existence checks by introducing IsNone and GuiSpecialTextureExists helpers. Special cases for "none" textures now avoid false warnings and are consistently cached. Centralized repository lookup logic for Scanlines, ButtonMiddle, and FrameBackground types. Improved error messages by clarifying origin labeling and adjusting error context.
1 parent 12b170b commit 1d5a8a2

2 files changed

Lines changed: 41 additions & 32 deletions

File tree

src/ModVerify/Verifiers/GuiDialogs/GuiDialogsVerifier.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ private void VerifyGuiComponentTexturesExist(string component)
119119
componentType is not GuiComponentType.ButtonMiddle &&
120120
componentType is not GuiComponentType.Scanlines &&
121121
componentType is not GuiComponentType.FrameBackground)
122+
{
123+
if (!cached.Value.AssetExists)
124+
AddNotFoundError(texture, component, null);
122125
continue;
126+
}
123127
}
124128

125129
var exists = GameEngine.GuiDialogManager.TextureExists(
@@ -141,8 +145,9 @@ componentType is not GuiComponentType.Scanlines &&
141145
AddNotFoundError(texture, component, origin);
142146
}
143147
}
144-
145-
_cache?.TryAddEntry(texture.Texture, exists);
148+
149+
// If the texture is "none" we store it as "asset exists" in order to reduce false warnings
150+
_cache?.TryAddEntry(texture.Texture, exists || isNone);
146151
}
147152
finally
148153
{
@@ -155,16 +160,18 @@ componentType is not GuiComponentType.Scanlines &&
155160
private void AddNotFoundError(ComponentTextureEntry texture, string component, GuiTextureOrigin? origin)
156161
{
157162
var sb = new StringBuilder($"Could not find GUI texture '{texture.Texture}'");
158-
if (origin is not null)
159-
sb.Append($" at location '{origin}'");
163+
if (origin is not null)
164+
sb.Append($" at origin '{origin}'");
165+
sb.Append($" for component '{component}'");
160166
sb.Append('.');
161167

162168
if (texture.Texture.Length > PGConstants.MaxMegEntryPathLength)
163169
sb.Append(" The file name is too long.");
164170

165171
AddError(VerificationError.Create(this, VerifierErrorCodes.FileNotFound,
166-
sb.ToString(), VerificationSeverity.Error,
167-
[component, origin.ToString()], texture.Texture));
172+
sb.ToString(), VerificationSeverity.Error,
173+
[component], // Origin is not interesting for context, but might be for the error message
174+
texture.Texture));
168175
}
169176

170177
private IReadOnlyDictionary<GuiComponentType, ComponentTextureEntry> GetTextureEntriesForComponents(string component, out bool defined)

src/PetroglyphTools/PG.StarWarsGame.Engine/GuiDialog/GuiDialogGameManager.cs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,50 +116,39 @@ public bool TryGetTextureEntry(string component, GuiComponentType key, out Compo
116116

117117
return textures.TryGetValue(key, out texture);
118118
}
119-
119+
120+
private static bool IsNone(string texture)
121+
{
122+
return texture.Equals("none", StringComparison.OrdinalIgnoreCase);
123+
}
124+
120125
public bool TextureExists(
121126
in ComponentTextureEntry textureInfo,
122127
out GuiTextureOrigin textureOrigin,
123128
out bool isNone,
124129
bool buttonMiddleInRepoMode = false)
125130
{
126-
if (textureInfo.Texture == "none")
127-
{
128-
textureOrigin = default;
129-
isNone = true;
130-
return false;
131-
}
132-
133131
isNone = false;
134-
135-
// Apparently, Scanlines only use the repository and not the MTD.
132+
133+
// Scanlines use the repository and not the MTD.
136134
if (textureInfo.ComponentType == GuiComponentType.Scanlines)
137-
{
138-
textureOrigin = GuiTextureOrigin.Repository;
139-
return GameRepository.TextureRepository.FileExists(textureInfo.Texture);
140-
}
135+
return GuiSpecialTextureExists(textureInfo, out textureOrigin, out isNone);
141136

142137
// The engine uses ButtonMiddle to switch to the special button mode.
143138
// It searches first in the repo and then falls back to MTD
144139
// (but only for this very type; the variants do not fallback to MTD).
145140
if (textureInfo.ComponentType == GuiComponentType.ButtonMiddle)
146141
{
147-
if (GameRepository.TextureRepository.FileExists(textureInfo.Texture))
148-
{
149-
textureOrigin = GuiTextureOrigin.Repository;
142+
if (GuiSpecialTextureExists(textureInfo, out textureOrigin, out isNone))
150143
return true;
151-
}
152144
}
153145

154146
// The engine does not fallback to MTD once it is in this special Button mode.
155147
if (buttonMiddleInRepoMode && textureInfo.ComponentType is
156148
GuiComponentType.ButtonMiddleDisabled or
157149
GuiComponentType.ButtonMiddleMouseOver or
158150
GuiComponentType.ButtonMiddlePressed)
159-
{
160-
textureOrigin = GuiTextureOrigin.Repository;
161-
return GameRepository.TextureRepository.FileExists(textureInfo.Texture);
162-
}
151+
return GuiSpecialTextureExists(textureInfo, out textureOrigin, out isNone);
163152

164153
if (textureInfo.Texture.Length <= 63 && MtdFile is not null && _megaTextureExists)
165154
{
@@ -173,12 +162,25 @@ GuiComponentType.ButtonMiddleMouseOver or
173162

174163
// The background image for frames include a fallback the repository.
175164
if (textureInfo.ComponentType == GuiComponentType.FrameBackground)
176-
{
177-
textureOrigin = GuiTextureOrigin.Repository;
178-
return GameRepository.TextureRepository.FileExists(textureInfo.Texture);
179-
}
165+
return GuiSpecialTextureExists(textureInfo, out textureOrigin, out isNone);
180166

181167
textureOrigin = default;
182168
return false;
183169
}
170+
171+
private bool GuiSpecialTextureExists(
172+
in ComponentTextureEntry textureInfo,
173+
out GuiTextureOrigin textureOrigin,
174+
out bool isNone)
175+
{
176+
isNone = IsNone(textureInfo.Texture);
177+
if (isNone)
178+
{
179+
textureOrigin = default;
180+
return false;
181+
}
182+
183+
textureOrigin = GuiTextureOrigin.Repository;
184+
return GameRepository.TextureRepository.FileExists(textureInfo.Texture);
185+
}
184186
}

0 commit comments

Comments
 (0)