Fixed Theme's not being applied correctly

Sometimes when switching themes it wouldn't apply the theme correctly.
This commit is contained in:
Heavy Bob 2025-04-07 09:20:13 +10:00
parent 5fc670b652
commit f116793591

View file

@ -18,17 +18,17 @@ public partial class HomePage : UserControl
private LogHandler? _logHandler; private LogHandler? _logHandler;
private KillHistoryManager _killHistoryManager; private KillHistoryManager _killHistoryManager;
private bool _UIEventsRegistered = false; private bool _UIEventsRegistered = false;
public HomePage() public HomePage()
{ {
InitializeComponent(); InitializeComponent();
_killHistoryManager = new KillHistoryManager(ConfigManager.KillHistoryFile); _killHistoryManager = new KillHistoryManager(ConfigManager.KillHistoryFile);
// Set the TextBlock text // Set the TextBlock text
KillTallyTitle.Text = $"Kill Tally - {_killHistoryManager.GetKillsInCurrentMonth().Count}"; KillTallyTitle.Text = $"Kill Tally - {_killHistoryManager.GetKillsInCurrentMonth().Count}";
AddKillHistoryKillsToUI(); AddKillHistoryKillsToUI();
} }
// //
public void UpdateButtonState(bool isRunning) public void UpdateButtonState(bool isRunning)
@ -68,7 +68,7 @@ public partial class HomePage : UserControl
StartButton.Style = (Style)FindResource("ButtonStyle"); StartButton.Style = (Style)FindResource("ButtonStyle");
StopButton.IsEnabled = false; // Disable Stop button StopButton.IsEnabled = false; // Disable Stop button
} }
RegisterUIEventHandlers(); RegisterUIEventHandlers();
} }
@ -77,13 +77,13 @@ public partial class HomePage : UserControl
UpdateButtonState(true); UpdateButtonState(true);
//string scriptPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "KillTrackR_MainScript.ps1"); //string scriptPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "KillTrackR_MainScript.ps1");
// TailFileAsync(scriptPath); // TailFileAsync(scriptPath);
// _logHandler = new LogHandler(@"U:\\StarCitizen\\StarCitizen\\LIVE\\Game.log"); // _logHandler = new LogHandler(@"U:\\StarCitizen\\StarCitizen\\LIVE\\Game.log");
_logHandler = new LogHandler(ConfigManager.LogFile); _logHandler = new LogHandler(ConfigManager.LogFile);
_logHandler.Initialize(); _logHandler.Initialize();
} }
private void AddKillHistoryKillsToUI() private void AddKillHistoryKillsToUI()
{ {
var kills = _killHistoryManager.GetKills(); var kills = _killHistoryManager.GetKills();
@ -97,9 +97,10 @@ public partial class HomePage : UserControl
{ {
if (_UIEventsRegistered) if (_UIEventsRegistered)
return; return;
// Username // Username
TrackREventDispatcher.PlayerLoginEvent += (username) => { TrackREventDispatcher.PlayerLoginEvent += (username) =>
{
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
PilotNameTextBox.Text = username; PilotNameTextBox.Text = username;
@ -107,19 +108,21 @@ public partial class HomePage : UserControl
LocalPlayerData.Username = username; LocalPlayerData.Username = username;
}); });
}; };
// Ship // Ship
TrackREventDispatcher.JumpDriveStateChangedEvent += (shipName) => { TrackREventDispatcher.JumpDriveStateChangedEvent += (shipName) =>
Dispatcher.Invoke(() => {
{ Dispatcher.Invoke(() =>
PlayerShipTextBox.Text = shipName; {
AdjustFontSize(PlayerShipTextBox); PlayerShipTextBox.Text = shipName;
LocalPlayerData.PlayerShip = shipName; AdjustFontSize(PlayerShipTextBox);
}); LocalPlayerData.PlayerShip = shipName;
});
}; };
// Game Mode // Game Mode
TrackREventDispatcher.PlayerChangedGameModeEvent += (mode) => { TrackREventDispatcher.PlayerChangedGameModeEvent += (mode) =>
{
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
GameModeTextBox.Text = mode.ToString(); GameModeTextBox.Text = mode.ToString();
@ -127,14 +130,16 @@ public partial class HomePage : UserControl
LocalPlayerData.CurrentGameMode = mode; LocalPlayerData.CurrentGameMode = mode;
}); });
}; };
// Game Version // Game Version
TrackREventDispatcher.GameVersionEvent += (version) => { TrackREventDispatcher.GameVersionEvent += (version) =>
LocalPlayerData.GameVersion = version; {
LocalPlayerData.GameVersion = version;
}; };
// Actor Death // Actor Death
TrackREventDispatcher.ActorDeathEvent += async (actorDeathData) => { TrackREventDispatcher.ActorDeathEvent += async (actorDeathData) =>
{
if (actorDeathData.VictimPilot != LocalPlayerData.Username) if (actorDeathData.VictimPilot != LocalPlayerData.Username)
{ {
var playerData = await WebHandler.GetPlayerData(actorDeathData.VictimPilot); var playerData = await WebHandler.GetPlayerData(actorDeathData.VictimPilot);
@ -156,7 +161,7 @@ public partial class HomePage : UserControl
KillTime = DateTime.UtcNow.ToString("dd MMM yyyy HH:mm"), KillTime = DateTime.UtcNow.ToString("dd MMM yyyy HH:mm"),
PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg" PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg"
}; };
switch (LocalPlayerData.CurrentGameMode) switch (LocalPlayerData.CurrentGameMode)
{ {
case GameMode.PersistentUniverse: case GameMode.PersistentUniverse:
@ -166,13 +171,13 @@ public partial class HomePage : UserControl
killData.Mode = "ac"; killData.Mode = "ac";
break; break;
} }
// Add kill to UI // Add kill to UI
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
AddKillToScreen(killData); AddKillToScreen(killData);
}); });
// Only submit kill data if not in offline mode // Only submit kill data if not in offline mode
if (ConfigManager.OfflineMode == 0) if (ConfigManager.OfflineMode == 0)
{ {
@ -185,17 +190,18 @@ public partial class HomePage : UserControl
} }
} }
}; };
// Vehicle Destruction // Vehicle Destruction
TrackREventDispatcher.VehicleDestructionEvent += (data) => { TrackREventDispatcher.VehicleDestructionEvent += (data) =>
{
LocalPlayerData.LastSeenVehicleLocation = data.VehicleZone; LocalPlayerData.LastSeenVehicleLocation = data.VehicleZone;
}; };
_UIEventsRegistered = true; _UIEventsRegistered = true;
} }
private void AddKillToScreen(KillData killData) private void AddKillToScreen(KillData killData)
{ {
// Fetch the dynamic resource for AltTextColor // Fetch the dynamic resource for AltTextColor
var altTextColorBrush = new SolidColorBrush((Color)Application.Current.Resources["AltTextColor"]); var altTextColorBrush = new SolidColorBrush((Color)Application.Current.Resources["AltTextColor"]);
var accentColorBrush = new SolidColorBrush((Color)Application.Current.Resources["AccentColor"]); var accentColorBrush = new SolidColorBrush((Color)Application.Current.Resources["AccentColor"]);
@ -236,22 +242,22 @@ public partial class HomePage : UserControl
FontFamily = orbitronFontFamily, FontFamily = orbitronFontFamily,
}); });
killTextBlock.Inlines.Add(new Run($"{killData.OrgAffiliation}\n")); killTextBlock.Inlines.Add(new Run($"{killData.OrgAffiliation}\n"));
killTextBlock.Inlines.Add(new Run("Join Date: ") killTextBlock.Inlines.Add(new Run("Join Date: ")
{ {
Foreground = altTextColorBrush, Foreground = altTextColorBrush,
FontFamily = orbitronFontFamily, FontFamily = orbitronFontFamily,
}); });
killTextBlock.Inlines.Add(new Run($"{killData.Enlisted}\n")); killTextBlock.Inlines.Add(new Run($"{killData.Enlisted}\n"));
killTextBlock.Inlines.Add(new Run("UEE Record: ") killTextBlock.Inlines.Add(new Run("UEE Record: ")
{ {
Foreground = altTextColorBrush, Foreground = altTextColorBrush,
FontFamily = orbitronFontFamily, FontFamily = orbitronFontFamily,
}); });
killTextBlock.Inlines.Add(new Run($"{killData.RecordNumber}\n")); killTextBlock.Inlines.Add(new Run($"{killData.RecordNumber}\n"));
killTextBlock.Inlines.Add(new Run("Kill Time: ") killTextBlock.Inlines.Add(new Run("Kill Time: ")
{ {
Foreground = altTextColorBrush, Foreground = altTextColorBrush,
@ -284,7 +290,7 @@ public partial class HomePage : UserControl
{ {
killData.PFP = "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg"; killData.PFP = "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg";
} }
// Create the Image for the profile // Create the Image for the profile
var profileImage = new Image var profileImage = new Image
{ {
@ -295,15 +301,13 @@ public partial class HomePage : UserControl
}; };
// Create a Border around the Image // Create a Border around the Image
var imageBorder = new Border var imageBorder = new Border();
{ imageBorder.SetResourceReference(Border.BorderBrushProperty, "AccentBrush");
BorderBrush = accentColorBrush, // Set the border color imageBorder.BorderThickness = new Thickness(2);
BorderThickness = new Thickness(2), // Set the border thickness imageBorder.Padding = new Thickness(0);
Padding = new Thickness(0), // Optional padding inside the border imageBorder.CornerRadius = new CornerRadius(5);
CornerRadius = new CornerRadius(5), imageBorder.Margin = new Thickness(10, 18, 15, 18);
Margin = new Thickness(10,18,15,18), imageBorder.Child = profileImage;
Child = profileImage // Set the Image as the content of the Border
};
// Add the Border (with the image inside) to the Grid // Add the Border (with the image inside) to the Grid
Grid.SetColumn(imageBorder, 1); Grid.SetColumn(imageBorder, 1);
@ -370,19 +374,19 @@ public partial class HomePage : UserControl
// Apply the adjusted font size // Apply the adjusted font size
textBlock.FontSize = fontSize; textBlock.FontSize = fontSize;
} }
public static void RunAHKScript(string path) public static void RunAHKScript(string path)
{ {
string scriptPath = Path.Combine(ConfigManager.AHKScriptFolder, path); string scriptPath = Path.Combine(ConfigManager.AHKScriptFolder, path);
if (!File.Exists(scriptPath)) if (!File.Exists(scriptPath))
{ {
return; return;
} }
// Run the script using powershell // Run the script using powershell
using var ahkProcess = new Process(); using var ahkProcess = new Process();
// Runs the script via Explorer, ensuring it uses whatever the // Runs the script via Explorer, ensuring it uses whatever the
// default binary for AHK is. Skips having to find a specific path to AHK // default binary for AHK is. Skips having to find a specific path to AHK
ahkProcess.StartInfo.FileName = "explorer"; ahkProcess.StartInfo.FileName = "explorer";
@ -397,7 +401,7 @@ public partial class HomePage : UserControl
RunAHKScript(ConfigManager.VisorWipeScript); RunAHKScript(ConfigManager.VisorWipeScript);
} }
} }
private void VideoRecord() private void VideoRecord()
{ {
if (ConfigManager.VideoRecord == 1) if (ConfigManager.VideoRecord == 1)