Skip to content

Commit

Permalink
Updated the title bar style
Browse files Browse the repository at this point in the history
  • Loading branch information
CriticalFlaw committed Sep 1, 2024
1 parent c35c8b4 commit 9d32807
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 36 deletions.
34 changes: 24 additions & 10 deletions src/TF2HUD.Editor/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
<Window x:Class="HUDEditor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
xmlns:views="clr-namespace:HUDEditor.Views"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="TF2HUD.Editor"
lex:ResxLocalizationProvider.DefaultDictionary="Resources"
mc:Ignorable="d"
Title="{lex:Loc ui_title}"
Width="1440"
Height="900"
WindowStartupLocation="CenterScreen"
FontFamily="../Resources/TF2Secondary.ttf #TF2 Secondary"
FontSize="20px"
Background="#2B2724">
<Grid>
<views:MainWindowView />
</Grid>
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
ResizeMode="NoResize"
FontFamily="../Resources/Fonts/TF2Secondary.ttf #TF2 Secondary"
FontSize="20px">

<Border BorderThickness="2" CornerRadius="10" Background="#2B2724">
<Grid>
<!-- Custom Title Bar -->
<Border Background="#211e1c" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Top" MouseDown="TitleBar_MouseDown">
<Grid>
<Image Source="../Resources/Images/favicon.ico" Height="20" HorizontalAlignment="Left" Margin="5"/>
<TextBlock Text="{lex:Loc ui_title}" VerticalAlignment="Center" Margin="30,0,0,0" Foreground="#EBE2CA" FontFamily="../Resources/Fonts/TF2Build.ttf #TF2 Build" FontSize="16px" />
<Button Content="X" HorizontalAlignment="Right" Width="30" Height="30" Click="CloseButton_Click" FontFamily="../Resources/Fonts/TF2Build.ttf #TF2 Build" />
</Grid>
</Border>

<!-- Main Content Area -->
<Grid Margin="0,30,0,0">
<views:MainWindowView />
</Grid>
</Grid>
</Border>
</Window>
24 changes: 19 additions & 5 deletions src/TF2HUD.Editor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using HUDEditor.Classes;
using HUDEditor.Models;
using HUDEditor.Properties;
Expand All @@ -31,18 +32,21 @@ public partial class MainWindow

public MainWindow()
{
// Initialize the logger, main window.
var repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
// Initialize the logger
XmlConfigurator.Configure(LogManager.GetRepository(Assembly.GetEntryAssembly()), new FileInfo("log4net.config"));
Logger.Info("=======================================================");
Logger.Info("Initializing.");
Logger.Info($"Starting {Assembly.GetExecutingAssembly().GetName().Name} {Assembly.GetExecutingAssembly().GetName().Version}");

// Initialize the main window
InitializeComponent();
var mainWindowViewModel = new MainWindowViewModel();
mainWindowViewModel.PropertyChanged += MainWindowViewModelPropertyChanged;
DataContext = mainWindowViewModel;

// Check for tf/custom directory
SetupDirectory();

// Check for updates.
// Check for updates
if (Settings.Default.app_update_auto == true) UpdateAppSchema();
}

Expand Down Expand Up @@ -214,5 +218,15 @@ public static async void UpdateAppVersion()
Console.WriteLine(e);
}
}

private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left) DragMove();
}

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}
12 changes: 11 additions & 1 deletion src/TF2HUD.Editor/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/TF2HUD.Editor/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@
<data name="ui_install" xml:space="preserve">
<value>Install</value>
</data>
<data name="ui_options" xml:space="preserve">
<value>Options</value>
<data name="ui_settings" xml:space="preserve">
<value>Settings</value>
</data>
<data name="ui_persist_xhair" xml:space="preserve">
<value>Remember crosshair selection</value>
Expand Down Expand Up @@ -276,4 +276,7 @@
<data name="ui_uninstall" xml:space="preserve">
<value>Uninstall</value>
</data>
<data name="ui_options" xml:space="preserve">
<value>Options</value>
</data>
</root>
43 changes: 25 additions & 18 deletions src/TF2HUD.Editor/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Windows;
using System.Windows.Forms;
using CommunityToolkit.Mvvm.Input;
using Crews.Utility.TgaSharp;
using HUDEditor.Classes;
using HUDEditor.Models;
using HUDEditor.Properties;
Expand Down Expand Up @@ -89,29 +90,35 @@ public bool Installing
public MainWindowViewModel()
{
_hudList = new List<HUD>();
var sharedControlsJson = new StreamReader(File.OpenRead("JSON\\shared-hud.json"), new UTF8Encoding(false)).ReadToEnd();

foreach (var jsonFile in Directory.EnumerateFiles("JSON"))
{
// Extract HUD information from the file path and add it to the object list.
var fileInfo = jsonFile.Split("\\")[^1].Split(".");
if (fileInfo[^1] != "json") continue;
_hudList.Add(new HUD(fileInfo[0], JsonConvert.DeserializeObject<HudJson>(new StreamReader(File.OpenRead(jsonFile), new UTF8Encoding(false)).ReadToEnd()), true));
}
if (fileInfo[^1] != "json" || fileInfo[0] == "shared-hud") continue;

// Load all shared huds from JSON/Shared/shared.json, and shared controls from JSON/Shared/controls.json
// For each hud, assign unique ids for the controls based on the hud name and add to HUDs list.
var sharedHuds = JsonConvert.DeserializeObject<List<HudJson>>(new StreamReader(File.OpenRead("JSON\\Shared\\shared.json"), new UTF8Encoding(false)).ReadToEnd());
var sharedControlsJson = new StreamReader(File.OpenRead("JSON\\Shared\\controls.json"), new UTF8Encoding(false)).ReadToEnd();
if (fileInfo[0].Equals("common"))
{
// Load all common HUDS from `JSON/common.json` and shared controls from `JSON/shared-hud.json`
// For each hud, assign unique ids for the controls based on the hud name and add to HUDs list.
var sharedHuds = JsonConvert.DeserializeObject<List<HudJson>>(new StreamReader(File.OpenRead("JSON\\common.json"), new UTF8Encoding(false)).ReadToEnd());

foreach (var sharedHud in sharedHuds)
{
var hudControls = JsonConvert.DeserializeObject<HudJson>(sharedControlsJson);
foreach (var control in hudControls.Controls.SelectMany(group => hudControls.Controls[group.Key]))
control.Name = $"{Utilities.EncodeId(sharedHud.Name)}_{Utilities.EncodeId(control.Name)}";
sharedHud.Layout = hudControls.Layout;
sharedHud.Controls = hudControls.Controls;
foreach (var sharedHud in sharedHuds)
{
var hudControls = JsonConvert.DeserializeObject<HudJson>(sharedControlsJson);
foreach (var control in hudControls.Controls.SelectMany(group => hudControls.Controls[group.Key]))
control.Name = $"{Utilities.EncodeId(sharedHud.Name)}_{Utilities.EncodeId(control.Name)}";
sharedHud.Layout = hudControls.Layout;
sharedHud.Controls = hudControls.Controls;

_hudList.Add(new HUD(sharedHud.Name, sharedHud, false));
_hudList.Add(new HUD(sharedHud.Name, sharedHud, false));
}
}
else
{
_hudList.Add(new HUD(fileInfo[0], JsonConvert.DeserializeObject<HudJson>(new StreamReader(File.OpenRead(jsonFile), new UTF8Encoding(false)).ReadToEnd()), true));
}
}

// Local Shared HUDs
Expand All @@ -133,7 +140,7 @@ public MainWindowViewModel()
Layout = sharedProperties.Layout,
Links = new Links
{
Download = new[] { new Download() { Source = "GitHub", Link = $"file://{sharedHud}\\{hudName}.zip" } }
Download = [new Download() { Source = "GitHub", Link = $"file://{sharedHud}\\{hudName}.zip" }]
},
Controls = sharedProperties.Controls
}, false));
Expand Down Expand Up @@ -387,7 +394,7 @@ public void BtnSwitch_Click()
[RelayCommand]
public void BtnSettings_Click()
{
var settings = new Options();
var settings = new SettingsWindow();
settings.Owner = System.Windows.Application.Current.MainWindow;
settings.Show();
}
Expand Down Expand Up @@ -555,7 +562,7 @@ public async Task Add(string folderPath)
// TF2 HUD Crosshairs
await Utilities.InstallCrosshairs(folderPath);

var sharedControlsJson = new StreamReader(File.OpenRead("JSON\\Shared\\controls.json"), new UTF8Encoding(false)).ReadToEnd();
var sharedControlsJson = new StreamReader(File.OpenRead("JSON\\shared-hud.json"), new UTF8Encoding(false)).ReadToEnd();
var hudControls = JsonConvert.DeserializeObject<HudJson>(sharedControlsJson);
foreach (var group in hudControls.Controls)
foreach (var control in hudControls.Controls[group.Key])
Expand Down

0 comments on commit 9d32807

Please sign in to comment.