Skip to content

Commit

Permalink
Support for HUDs without customization (#61)
Browse files Browse the repository at this point in the history
- HUDs found in shared.json will display basic information, media links and the option to either install or uninstall the selected HUD. No customizations are included.
- Fixed missing images in rayshud and zeeshud schemas.
  • Loading branch information
CriticalFlaw committed Aug 5, 2021
1 parent eae9656 commit 4032c3d
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 32 deletions.
13 changes: 9 additions & 4 deletions src/TF2HUD.Editor/Classes/HUD/HUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ public partial class HUD
private HUDBackground hudBackground;
private bool isRendered;
private string[][] layout;
public bool Maximize;
public bool Maximize, Customizable;

public string Name, UpdateUrl, GitHubUrl, IssueUrl, HudsTfUrl, SteamUrl, DiscordUrl;
public string Name, Description, Author, UpdateUrl, GitHubUrl, HudsTfUrl, SteamUrl, DiscordUrl;
public double Opacity;
public HUDSettings Settings;
public string Thumbnail, Background, CustomizationsFolder, EnabledFolder;
public string[] Screenshots;

/// <summary>
/// Initialize the HUD object with values from the JSON schema.
/// </summary>
/// <param name="name">Name of the HUD object.</param>
/// <param name="schema">Contents of the HUD's schema file.</param>
public HUD(string name, HudJson schema)
public HUD(string name, HudJson schema, bool isCustomizable = true)
{
// Basic Schema Properties.
Name = name;
Name = schema.Name ?? name;
Settings = new HUDSettings(Name);
Opacity = schema.Opacity;
Maximize = schema.Maximize;
Expand All @@ -44,6 +45,10 @@ public HUD(string name, HudJson schema)
DirtyControls = new List<string>();
Thumbnail = schema.Thumbnail;
Background = schema.Background;
Description = schema.Description;
Author = schema.Author;
Customizable = isCustomizable;
Screenshots = schema.Screenshots;

// Download and Media Links.
if (schema.Links is not null)
Expand Down
7 changes: 6 additions & 1 deletion src/TF2HUD.Editor/Classes/Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using HUDEditor.Models;
using HUDEditor.Properties;
using Newtonsoft.Json;
Expand All @@ -31,7 +32,10 @@ public Json()
var json = new StreamReader(File.OpenRead(jsonFile), new UTF8Encoding(false)).ReadToEnd();

// Add the HUD object to the list.
hudList.Add(new HUD(hudName, JsonConvert.DeserializeObject<HudJson>(json)));
if (hudName.Equals("shared"))
hudList.AddRange(JsonConvert.DeserializeObject<List<HudJson>>(json).Select(hud => new HUD(hudName, hud, false)));
else
hudList.Add(new HUD(hudName, JsonConvert.DeserializeObject<HudJson>(json)));
}

HUDList = hudList.ToArray();
Expand All @@ -50,6 +54,7 @@ public void SetHUDByName(string name)
/// <param name="name">Name of the HUD the user wants to view.</param>
public HUD GetHUDByName(string name)
{
if (name.Equals("shared")) return HUDList[0];
foreach (var hud in HUDList)
if (string.Equals(hud.Name, name, StringComparison.InvariantCultureIgnoreCase))
return hud;
Expand Down
4 changes: 2 additions & 2 deletions src/TF2HUD.Editor/JSON/rayshud.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/CriticalFlaw/TF2HUD.Editor/master/src/TF2HUD.Editor/JSON/Schema/schema.json",
"Thumbnail": "https://huds.tf/site/xthreads_attach.php/572_1486499416_dd57b51a/8daf74d7f23cd9e2dd4abd849b3f0644/directory.jpg",
"Background": "https://imgur.com/UIHWxBv.png",
"Thumbnail": "https://huds.tf/site/xthreads_attach.php/572_1625449753_caa6f785/5f18a61726cef2bcddd21c3a5043be3e/rayshud-new2.png",
"Background": "https://i.imgur.com/vC7qekD.png",
"Layout": [
"0 0 1 1 6 6",
"2 2 3 3 6 6",
Expand Down
2 changes: 1 addition & 1 deletion src/TF2HUD.Editor/JSON/zeeshud.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/CriticalFlaw/TF2HUD.Editor/master/src/TF2HUD.Editor/JSON/Schema/schema.json",
"Thumbnail": "https://huds.tf/site/xthreads_attach.php/3403_1622089359_0ae9f236/6bdb991d2d780d34bd92ccafeb0ba092/zeeshudlogo_card.jpg",
"Thumbnail": "https://huds.tf/site/xthreads_attach.php/3403_1627843846_e18896e8/26d23f685f415d0fa5181c80aba3fdc6/zeeshudlogo_card.jpg",
"Background": "https://i.imgur.com/U4m1mOx.png",
"Layout": [
"0 0 4 4 1 1",
Expand Down
24 changes: 22 additions & 2 deletions src/TF2HUD.Editor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
<TextBox Name="SearchBox" TextChanged="TbSearchBox_TextChanged" Foreground="WhiteSmoke"
Background="#2B2724" BorderThickness="1" VerticalContentAlignment="Center"
Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="1" Grid.RowSpan="1" />
<ScrollViewer Background="#2B2724" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Grid.RowSpan="1" Margin="0,10,0,0">
<ScrollViewer Background="Transparent" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Grid.RowSpan="1" Margin="0,10,0,0">
<WrapPanel x:Name="GridSelectHud" HorizontalAlignment="Center" />
</ScrollViewer>
</Grid>
<!-- App Info and Changelog -->
<ScrollViewer VerticalScrollBarVisibility="Hidden" Grid.Column="1" Grid.Row="0">
<ScrollViewer x:Name="AppInfo" VerticalScrollBarVisibility="Hidden" Grid.Column="1" Grid.Row="0" Visibility="Hidden">
<StackPanel Margin="20">
<Image Source="Resources/banner.png" Height="142" Width="621" Margin="0,0,0,15" />
<TextBlock Style="{StaticResource BodyText}" FontSize="21" TextAlignment="Center">
Expand Down Expand Up @@ -101,6 +101,26 @@
</TextBlock>
</StackPanel>
</ScrollViewer>
<!-- HUD Info and Download -->
<ScrollViewer x:Name="HudInfo" VerticalScrollBarVisibility="Hidden" Grid.Column="1" Grid.Row="0" Visibility="Visible">
<StackPanel Margin="20">
<Label x:Name="HudName" Content="HUD" Style="{StaticResource HeaderText}"/>
<TextBlock x:Name="HudAuthor" Style="{StaticResource BodyText}" FontSize="20" TextAlignment="Center">HUD Developer</TextBlock>
<TextBlock x:Name="HudDesc" Style="{StaticResource BodyText}" FontSize="20" TextAlignment="Center" Margin="0,15,0,0" >HUD Description</TextBlock>
<Border Background="#A49E9E" HorizontalAlignment="Stretch" Height="1" Margin="0,15,0,10" />
<Grid x:Name="HudScreenshots">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5*" />
<RowDefinition Height="5*" />
</Grid.RowDefinitions>
</Grid>
<Label x:Name="HudStatus" Content="HUD" Style="{StaticResource HeaderText}" FontSize="20px" Margin="0,10,0,0"/>
</StackPanel>
</ScrollViewer>
</Grid>
</GroupBox>
<!-- Editor Controls -->
Expand Down
86 changes: 64 additions & 22 deletions src/TF2HUD.Editor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void SetPageControls()
File.Delete(Directory.GetCurrentDirectory() + "\\temp.zip");

// If the HUD Selection is visible, disable most control buttons.
if (GbSelectHud.IsVisible)
if (AppInfo.IsVisible)
{
LblStatus.Content = string.Empty;
BtnInstall.IsEnabled = false;
Expand All @@ -176,12 +176,14 @@ public void SetPageControls()
BtnInstall.IsEnabled = true;
BtnInstall.Content = Utilities.GetLocalizedString(isInstalled ? "ui_reinstall" : "ui_install");
BtnUninstall.IsEnabled = isInstalled;
BtnSave.IsEnabled = isInstalled;
BtnReset.IsEnabled = isInstalled;
BtnSwitch.IsEnabled = true;
BtnSave.IsEnabled = isInstalled && !HudInfo.IsVisible;
BtnReset.IsEnabled = isInstalled && !HudInfo.IsVisible;
BtnSwitch.IsEnabled = !HudInfo.IsVisible;
LblStatus.Content = string.Format(isInstalled
? Properties.Resources.status_installed
: Properties.Resources.status_installed_not, HudSelection);
HudStatus.Content = LblStatus.Content;
HudStatus.Foreground = isInstalled ? new SolidColorBrush(Colors.GreenYellow) : new SolidColorBrush(Colors.Red);
}
else
{
Expand All @@ -191,7 +193,7 @@ public void SetPageControls()
BtnUninstall.IsEnabled = false;
BtnSave.IsEnabled = false;
BtnReset.IsEnabled = false;
BtnSwitch.IsEnabled = true;
BtnSwitch.IsEnabled = !HudInfo.IsVisible;
LblStatus.Content = Properties.Resources.status_pathNotSet;
}

Expand Down Expand Up @@ -223,24 +225,66 @@ private void SetPageView()
var selection = Json.GetHUDByName(Settings.Default.hud_selected);

// Display a list of available HUDs if a HUD selection has not been set.
GbSelectHud.Visibility = selection is null ? Visibility.Visible : Visibility.Hidden;
MainToolbar.Visibility = selection is null ? Visibility.Hidden : Visibility.Visible;
GbSelectHud.Visibility = Visibility.Visible;
MainToolbar.Visibility = Visibility.Hidden;
EditorContainer.Children.Clear();

// If there's a HUD selection, generate the controls for that HUD's page.
if (selection is null) return;
Logger.Info($"Changing page view to: {selection.Name}.");
EditorContainer.Children.Add(selection.GetControls());

selection.PresetChanged += (sender, Preset) =>
if (selection.Customizable)
{
EditorContainer.Children.Clear();
GbSelectHud.Visibility = Visibility.Hidden;
MainToolbar.Visibility = Visibility.Visible;

EditorContainer.Children.Add(selection.GetControls());
};

// Maximize the application window if a given HUD schema requests it.
Application.Current.MainWindow.WindowState =
selection.Maximize ? WindowState.Maximized : WindowState.Normal;
selection.PresetChanged += (_, _) =>
{
EditorContainer.Children.Clear();
EditorContainer.Children.Add(selection.GetControls());
};

// Maximize the application window if a given HUD schema requests it.
Application.Current.MainWindow.WindowState = selection.Maximize ? WindowState.Maximized : WindowState.Normal;
}
else
{
AppInfo.Visibility = Visibility.Hidden;
HudInfo.Visibility = Visibility.Visible;

HudName.Content = selection.Name;
HudAuthor.Text = string.Format(Properties.Resources.ui_author, selection.Author);
HudDesc.Text = selection.Description;

int rowIndex = 0, columnIndex = 0;
HudScreenshots.Children.Clear();
foreach (var x in selection.Screenshots)
{
var screenshot = new Image
{
Source = new BitmapImage(new Uri(x))
};

if (columnIndex > 1)
{
rowIndex++;
columnIndex = 0;
}

Grid.SetRow(screenshot, rowIndex);
Grid.SetColumn(screenshot, columnIndex);

columnIndex++;
HudScreenshots.Children.Add(screenshot);
}

BtnGitHub.IsEnabled = !string.IsNullOrWhiteSpace(selection.GitHubUrl);
BtnHuds.IsEnabled = !string.IsNullOrWhiteSpace(selection.HudsTfUrl);
BtnDiscord.IsEnabled = !string.IsNullOrWhiteSpace(selection.DiscordUrl);
BtnSteam.IsEnabled = !string.IsNullOrWhiteSpace(selection.SteamUrl);
}

// Disable the social media buttons if they don't have a link.
BtnGitHub.IsEnabled = !string.IsNullOrWhiteSpace(selection.GitHubUrl);
Expand All @@ -260,15 +304,11 @@ private void SetPageView()
private void SetPageBackground()
{
// Reset the application to the default background color.
if (GbSelectHud.IsVisible)
{
MainGrid.Background = (Brush) new BrushConverter().ConvertFromString("#2B2724");
return;
}
MainGrid.Background = (Brush)new BrushConverter().ConvertFromString("#2B2724");

// If a HUD is selected, retrieve the set Background value if available.
var selection = Json.GetHUDByName(Settings.Default.hud_selected);
if (selection?.Background == null) return;
if (selection?.Background == null || AppInfo.IsVisible) return;

Logger.Info($"Changing background to: {selection.Background}");
if (selection.Background.StartsWith("http"))
Expand Down Expand Up @@ -377,15 +417,15 @@ private void BtnInstall_OnClick(object sender, RoutedEventArgs e)
if (string.IsNullOrWhiteSpace(HudSelection)) return;
var selection = Json.GetHUDByName(Settings.Default.hud_selected);
selection.Settings.SaveSettings();
if (!selection.Customizable) return;
EditorContainer.Children.Clear();
EditorContainer.Children.Add(selection.GetControls());
selection.ApplyCustomizations();
});
};
worker.RunWorkerCompleted += (_, _) =>
{
LblStatus.Content = string.Format(Properties.Resources.status_installed_now, Settings.Default.hud_selected, DateTime.Now);
Json.GetHUDByName(Settings.Default.hud_selected).ApplyCustomizations();
LblStatus.Content = string.Format(Properties.Resources.status_applied, Settings.Default.hud_selected, DateTime.Now);
SetPageControls();
};
worker.RunWorkerAsync();
Expand Down Expand Up @@ -478,6 +518,8 @@ private void BtnSwitch_OnClick(object sender, RoutedEventArgs e)
{
Logger.Info("Changing page view to: main menu.");
GbSelectHud.Visibility = Visibility.Visible;
AppInfo.Visibility = Visibility.Visible;
HudInfo.Visibility = Visibility.Hidden;
EditorContainer.Children.Clear();
SetPageControls();
SetPageBackground();
Expand Down
4 changes: 4 additions & 0 deletions src/TF2HUD.Editor/Models/HudJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class HudJson
[JsonPropertyName("Maximize")] public bool Maximize;
[JsonPropertyName("Opacity")] public double Opacity = 0.5;
[JsonPropertyName("Thumbnail")] public string Thumbnail;
[JsonPropertyName("Name")] public string Name;
[JsonPropertyName("Description")] public string Description;
[JsonPropertyName("Author")] public string Author;
[JsonPropertyName("Screenshots")] public string[] Screenshots;
}

public class Links
Expand Down
18 changes: 18 additions & 0 deletions src/TF2HUD.Editor/Properties/Resources.Designer.cs

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

6 changes: 6 additions & 0 deletions src/TF2HUD.Editor/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
<data name="ui_apply" xml:space="preserve">
<value>Apply Changes</value>
</data>
<data name="ui_author" xml:space="preserve">
<value>Created by: {0}</value>
</data>
<data name="ui_back" xml:space="preserve">
<value>Back</value>
</data>
<data name="ui_directory" xml:space="preserve">
<value>Set Directory</value>
</data>
Expand Down

0 comments on commit 4032c3d

Please sign in to comment.