Skip to content

Commit bae3855

Browse files
authored
Disable showing map preview for maps without texture files (#629)
* Disable showing map preview for maps without texture files * Enforce coding style * Update GameInformationPanel.cs * Fix noMapPreview get disposed * Update GameInformationPanel.cs
1 parent d866451 commit bae3855

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

DXMainClient/DXGUI/Multiplayer/GameInformationPanel.cs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
using Rampastring.XNAUI.XNAControls;
2-
using Rampastring.XNAUI;
3-
using Microsoft.Xna.Framework;
4-
using DTAClient.Domain.Multiplayer;
1+
using System;
2+
using System.Diagnostics;
3+
4+
using ClientCore;
55
using ClientCore.Extensions;
6+
7+
using DTAClient.Domain.Multiplayer;
8+
9+
using Microsoft.Xna.Framework;
610
using Microsoft.Xna.Framework.Graphics;
7-
using Rampastring.Tools;
8-
using System.Net.NetworkInformation;
9-
using System;
10-
using ClientCore;
11+
12+
using Rampastring.XNAUI;
13+
using Rampastring.XNAUI.XNAControls;
1114

1215
namespace DTAClient.DXGUI.Multiplayer
1316
{
@@ -39,7 +42,9 @@ public GameInformationPanel(WindowManager windowManager, MapLoader mapLoader)
3942
private XNALabel[] lblPlayerNames;
4043

4144
private GenericHostedGame game = null;
42-
private Texture2D mapTexture;
45+
46+
private bool disposeTextures = false;
47+
private Texture2D mapTexture = null;
4348
private Texture2D noMapPreviewTexture = null;
4449

4550
private const int leftColumnPositionX = 10;
@@ -65,7 +70,7 @@ public override void Initialize()
6570
lblGameInformation.FontIndex = 1;
6671
lblGameInformation.Text = "GAME INFORMATION".L10N("Client:Main:GameInfo");
6772

68-
if(AssetLoader.AssetExists("noMapPreview.png"))
73+
if (AssetLoader.AssetExists("noMapPreview.png"))
6974
noMapPreviewTexture = AssetLoader.LoadTexture("noMapPreview.png");
7075

7176
rightColumnPositionX = Width / 2 - columnMargin;
@@ -189,9 +194,17 @@ public void SetInfo(GenericHostedGame game)
189194

190195
if (mapLoader != null)
191196
{
192-
mapTexture = mapLoader.GameModeMaps.Find(m => m.Map.Name == game.Map)?.Map.LoadPreviewTexture();
197+
mapTexture = mapLoader.GameModeMaps.Find(m => m.Map.Name == game.Map && m.Map.IsPreviewTextureCached())?.Map?.LoadPreviewTexture();
193198
if (mapTexture == null && noMapPreviewTexture != null)
199+
{
200+
Debug.Assert(!noMapPreviewTexture.IsDisposed, "noMapPreviewTexture should not be disposed.");
194201
mapTexture = noMapPreviewTexture;
202+
disposeTextures = false;
203+
}
204+
else
205+
{
206+
disposeTextures = true;
207+
}
195208
}
196209
}
197210

@@ -208,8 +221,12 @@ public void ClearInfo()
208221
foreach (XNALabel label in lblPlayerNames)
209222
label.Visible = false;
210223

211-
mapTexture?.Dispose();
212-
mapTexture = null;
224+
if (mapTexture != null && disposeTextures)
225+
{
226+
Debug.Assert(!mapTexture.IsDisposed, "mapTexture should not be disposed.");
227+
mapTexture.Dispose();
228+
mapTexture = null;
229+
}
213230
}
214231

215232
public override void Draw(GameTime gameTime)

DXMainClient/Domain/Multiplayer/Map.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ private void ParseSpawnIniOptions(IniFile forcedOptionsIni, string spawnIniOptio
680680
}
681681
}
682682

683+
public bool IsPreviewTextureCached() =>
684+
SafePath.GetFile(ProgramConstants.GamePath, PreviewPath).Exists;
685+
683686
/// <summary>
684687
/// Loads and returns the map preview texture.
685688
/// </summary>

0 commit comments

Comments
 (0)