Skip to content

Commit c193cf2

Browse files
authored
Merge pull request #813 from CnCNet/develop
Release 2.12.8
2 parents 22b36dc + dc909d3 commit c193cf2

18 files changed

+157
-87
lines changed

ClientCore/ClientConfiguration.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public class ClientConfiguration
2121
private const string TRANSLATIONS = "Translations";
2222
private const string USER_DEFAULTS = "UserDefaults";
2323

24-
private const string CLIENT_SETTINGS = "DTACnCNetClient.ini";
25-
private const string GAME_OPTIONS = "GameOptions.ini";
26-
private const string CLIENT_DEFS = "ClientDefinitions.ini";
27-
private const string NETWORK_DEFS_LOCAL = "NetworkDefinitions.local.ini";
28-
private const string NETWORK_DEFS = "NetworkDefinitions.ini";
24+
public const string CLIENT_SETTINGS = "DTACnCNetClient.ini";
25+
public const string GAME_OPTIONS = "GameOptions.ini";
26+
public const string CLIENT_DEFS = "ClientDefinitions.ini";
27+
public const string NETWORK_DEFS_LOCAL = "NetworkDefinitions.local.ini";
28+
public const string NETWORK_DEFS = "NetworkDefinitions.ini";
2929

3030
private static ClientConfiguration _instance;
3131

ClientCore/Extensions/IniFileExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@ namespace ClientCore.Extensions
88
{
99
public static class IniFileExtensions
1010
{
11+
// Clone() method is not officially available now. https://github.com/Rampastring/Rampastring.Tools/issues/12
12+
public static IniFile Clone(this IniFile oldIniFile)
13+
{
14+
var newIni = new IniFile();
15+
foreach (string sectionName in oldIniFile.GetSections())
16+
{
17+
IniSection oldSection = oldIniFile.GetSection(sectionName);
18+
newIni.AddSection(oldSection.Clone());
19+
}
20+
21+
return newIni;
22+
}
23+
24+
public static IniSection Clone(this IniSection oldSection)
25+
{
26+
IniSection newSection = new(oldSection.SectionName);
27+
28+
foreach ((var key, var value) in oldSection.Keys)
29+
{
30+
newSection.AddKey(key, value);
31+
}
32+
33+
return newSection;
34+
}
35+
1136
public static IniSection GetOrAddSection(this IniFile iniFile, string sectionName)
1237
{
1338
var section = iniFile.GetSection(sectionName);

ClientCore/Settings/UserINISettings.cs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
using ClientCore.Settings;
2-
using Rampastring.Tools;
31
using System;
42
using System.Collections.Generic;
3+
using System.IO;
54
using System.Linq;
5+
66
using ClientCore.Enums;
77
using ClientCore.Extensions;
8+
using ClientCore.Settings;
9+
10+
using Rampastring.Tools;
811

912
namespace ClientCore
1013
{
@@ -37,14 +40,47 @@ public static UserINISettings Instance
3740
}
3841
}
3942

40-
public static void Initialize(string iniFileName)
43+
public static void Initialize(string userIniFileName)
4144
{
4245
if (_instance != null)
4346
throw new InvalidOperationException("UserINISettings has already been initialized!");
4447

45-
var iniFile = new IniFile(SafePath.CombineFilePath(ProgramConstants.GamePath, iniFileName));
48+
var userIni = new IniFile(SafePath.CombineFilePath(ProgramConstants.GamePath, userIniFileName));
49+
50+
string userDefaultIniFilePath = SafePath.CombineFilePath(ProgramConstants.GetResourcePath(), "UserDefaults.ini");
51+
52+
if (!File.Exists(userDefaultIniFilePath))
53+
{
54+
_instance = new UserINISettings(userIni);
55+
return;
56+
}
57+
58+
var userDefaultIni = new IniFile(userDefaultIniFilePath);
59+
60+
var combinedUserIni = userDefaultIni.Clone();
61+
combinedUserIni.FileName = null;
62+
63+
// Combine userIni and userDefaultIni
64+
foreach (string sectionName in userIni.GetSections())
65+
{
66+
IniSection userSection = userIni.GetSection(sectionName);
67+
68+
IniSection combinedUserSection = combinedUserIni.GetSection(sectionName);
69+
if (combinedUserSection == null)
70+
{
71+
combinedUserSection = new IniSection(sectionName);
72+
combinedUserIni.AddSection(combinedUserSection);
73+
}
74+
75+
foreach ((var key, var value) in userSection.Keys)
76+
{
77+
combinedUserSection.AddOrReplaceKey(key, value);
78+
}
79+
}
80+
81+
combinedUserIni.FileName = userIni.FileName;
4682

47-
_instance = new UserINISettings(iniFile);
83+
_instance = new UserINISettings(combinedUserIni);
4884
}
4985

5086
protected UserINISettings(IniFile iniFile)
@@ -356,7 +392,7 @@ public void SaveSettings()
356392
public bool IsGameFiltersApplied()
357393
=> ShowFriendGamesOnly.Value != DEFAULT_SHOW_FRIENDS_ONLY_GAMES
358394
|| HideLockedGames.Value != DEFAULT_HIDE_LOCKED_GAMES
359-
|| HidePasswordedGames.Value != DEFAULT_HIDE_PASSWORDED_GAMES
395+
|| HidePasswordedGames.Value != DEFAULT_HIDE_PASSWORDED_GAMES
360396
|| HideIncompatibleGames.Value != DEFAULT_HIDE_INCOMPATIBLE_GAMES
361397
|| MaxPlayerCount.Value != DEFAULT_MAX_PLAYER_COUNT;
362398

ClientGUI/XNAClientColorDropDown.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ protected override void ParseControlINIAttribute(IniFile iniFile, string key, st
7878
RandomColorTexture = AssetLoader.LoadTexture(value);
7979
Items[0].Texture = RandomColorTexture;
8080
break;
81+
case nameof(DisabledItemTexture):
82+
DisabledItemTexture = AssetLoader.LoadTexture(value);
83+
break;
8184
default:
8285
base.ParseControlINIAttribute(iniFile, key, value);
8386
return;

ClientGUI/XNAClientDropDown.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ protected override void ParseControlINIAttribute(IniFile iniFile, string key, st
4646
base.ParseControlINIAttribute(iniFile, key, value);
4747
}
4848

49-
public override void OnMouseLeftDown()
49+
public override void OnMouseLeftDown(InputEventArgs inputEventArgs)
5050
{
51-
base.OnMouseLeftDown();
51+
// no need to set Handled to true since we're not "consuming" the event here, just augmenting
52+
base.OnMouseLeftDown(inputEventArgs);
5253
UpdateToolTipBlock();
5354
}
5455

ClientGUI/XNAClientLinkLabel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ public override void OnMouseLeave()
9999
TextColor = IdleColor;
100100
}
101101

102-
public override void OnLeftClick()
102+
public override void OnLeftClick(InputEventArgs inputEventArgs)
103103
{
104+
inputEventArgs.Handled = true;
105+
104106
ClickSoundEffect?.Play();
105107

106108
OSVersion osVersion = ClientConfiguration.Instance.GetOperatingSystemVersion();
@@ -110,7 +112,7 @@ public override void OnLeftClick()
110112
else if (!string.IsNullOrEmpty(URL))
111113
ProcessLauncher.StartShellProcess(URL);
112114

113-
base.OnLeftClick();
115+
base.OnLeftClick(inputEventArgs);
114116
}
115117
}
116118
}

ClientGUI/XNALinkButton.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ protected override void ParseControlINIAttribute(IniFile iniFile, string key, st
3636
base.ParseControlINIAttribute(iniFile, key, value);
3737
}
3838

39-
public override void OnLeftClick()
39+
public override void OnLeftClick(InputEventArgs inputEventArgs)
4040
{
41+
inputEventArgs.Handled = true;
42+
4143
OSVersion osVersion = ClientConfiguration.Instance.GetOperatingSystemVersion();
4244

4345
if (osVersion == OSVersion.UNIX && !string.IsNullOrEmpty(UnixURL))
4446
ProcessLauncher.StartShellProcess(UnixURL, Arguments);
4547
else if (!string.IsNullOrEmpty(URL))
4648
ProcessLauncher.StartShellProcess(URL, Arguments);
4749

48-
base.OnLeftClick();
50+
base.OnLeftClick(inputEventArgs);
4951
}
5052
}
5153
}

DXMainClient/DXGUI/Generic/GameInProgressWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void SharedUILogic_GameProcessStarted()
129129

130130
private void SharedUILogic_GameProcessExited()
131131
{
132-
AddCallback(new Action(HandleGameProcessExited), null);
132+
WindowManager.AddCallback(new Action(HandleGameProcessExited), null);
133133
}
134134

135135
private void HandleGameProcessExited()

DXMainClient/DXGUI/Generic/MainMenu.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,14 +679,21 @@ private void LoadThemeSong()
679679
string songExtension = "wma";
680680
#endif
681681

682-
FileInfo mainMenuMusicFile = SafePath.GetFile(ProgramConstants.GamePath, ProgramConstants.BASE_RESOURCE_PATH,
682+
FileInfo mainMenuMusicFile = SafePath.GetFile(ProgramConstants.GamePath, ProgramConstants.BASE_RESOURCE_PATH,
683683
FormattableString.Invariant($"{ClientConfiguration.Instance.MainMenuMusicName}.{songExtension}"));
684684

685685
if (!mainMenuMusicFile.Exists)
686686
return;
687687

688-
Song song = Song.FromUri(ClientConfiguration.Instance.MainMenuMusicName, new Uri(mainMenuMusicFile.FullName));
689-
themeSong = song;
688+
try
689+
{
690+
themeSong = Song.FromUri(ClientConfiguration.Instance.MainMenuMusicName, new Uri(mainMenuMusicFile.FullName));
691+
}
692+
catch (Exception ex)
693+
{
694+
Logger.Log($"Error loading the theme song. Fallback to the legacy method. Have you installed 'Media Feature Pack for Windows 10/11 N'? Exception: {ex.ToString()}");
695+
themeSong = AssetLoader.LoadSong(ClientConfiguration.Instance.MainMenuMusicName);
696+
}
690697
#endif
691698
}
692699

DXMainClient/DXGUI/Multiplayer/CnCNet/PrivateMessagingPanel.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,14 @@ public PrivateMessagingPanel(WindowManager windowManager) : base(windowManager)
1313
{
1414
}
1515

16-
public override void OnLeftClick()
16+
public override void OnLeftClick(InputEventArgs inputEventArgs)
1717
{
18-
bool hideControl = true;
19-
20-
foreach (var child in Children)
21-
{
22-
if (child.IsActive)
23-
{
24-
hideControl = false;
25-
break;
26-
}
27-
}
28-
29-
if (hideControl)
18+
inputEventArgs.Handled = true;
19+
20+
if (GetActiveChild() == null)
3021
Hide();
3122

32-
base.OnLeftClick();
23+
base.OnLeftClick(inputEventArgs);
3324
}
34-
35-
3625
}
3726
}

0 commit comments

Comments
 (0)