Skip to content

Commit

Permalink
Merge branch 'develop' into yr/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBartlett committed Jan 8, 2025
2 parents ea26bf9 + bae3855 commit 9ee30ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
43 changes: 30 additions & 13 deletions DXMainClient/DXGUI/Multiplayer/GameInformationPanel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using Rampastring.XNAUI.XNAControls;
using Rampastring.XNAUI;
using Microsoft.Xna.Framework;
using DTAClient.Domain.Multiplayer;
using System;
using System.Diagnostics;

using ClientCore;
using ClientCore.Extensions;

using DTAClient.Domain.Multiplayer;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Rampastring.Tools;
using System.Net.NetworkInformation;
using System;
using ClientCore;

using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;

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

private GenericHostedGame game = null;
private Texture2D mapTexture;

private bool disposeTextures = false;
private Texture2D mapTexture = null;
private Texture2D noMapPreviewTexture = null;

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

if(AssetLoader.AssetExists("noMapPreview.png"))
if (AssetLoader.AssetExists("noMapPreview.png"))
noMapPreviewTexture = AssetLoader.LoadTexture("noMapPreview.png");

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

if (mapLoader != null)
{
mapTexture = mapLoader.GameModeMaps.Find(m => m.Map.Name == game.Map)?.Map.LoadPreviewTexture();
mapTexture = mapLoader.GameModeMaps.Find(m => m.Map.Name == game.Map && m.Map.IsPreviewTextureCached())?.Map?.LoadPreviewTexture();
if (mapTexture == null && noMapPreviewTexture != null)
{
Debug.Assert(!noMapPreviewTexture.IsDisposed, "noMapPreviewTexture should not be disposed.");
mapTexture = noMapPreviewTexture;
disposeTextures = false;
}
else
{
disposeTextures = true;
}
}
}

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

mapTexture?.Dispose();
mapTexture = null;
if (mapTexture != null && disposeTextures)
{
Debug.Assert(!mapTexture.IsDisposed, "mapTexture should not be disposed.");
mapTexture.Dispose();
mapTexture = null;
}
}

public override void Draw(GameTime gameTime)
Expand Down
3 changes: 3 additions & 0 deletions DXMainClient/Domain/Multiplayer/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ private void ParseSpawnIniOptions(IniFile forcedOptionsIni, string spawnIniOptio
}
}

public bool IsPreviewTextureCached() =>
SafePath.GetFile(ProgramConstants.GamePath, PreviewPath).Exists;

/// <summary>
/// Loads and returns the map preview texture.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion DXMainClient/Online/FileHashCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void CalculateHashes()
{
if (path.Exists)
{
foreach (string filename in path.EnumerateFiles("*", SearchOption.AllDirectories).Select(s => s.Name))
foreach (string filename in path.EnumerateFiles("*", SearchOption.AllDirectories).Select(s => s.FullName.Substring(path.FullName.Length)))
{
string fileRelativePath = SafePath.CombineFilePath(path.Name, filename);
string fileFullPath = SafePath.CombineFilePath(path.FullName, filename);
Expand Down

0 comments on commit 9ee30ed

Please sign in to comment.