mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Add bulk font replacement, Win32 for file picker
This commit is contained in:
parent
41ca47ad0b
commit
63ef907246
@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
@ -1035,6 +1036,44 @@ namespace Bloxstrap
|
||||
await response.Content.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
// check custom font mod
|
||||
// instead of replacing the fonts themselves, we'll just alter the font family manifests
|
||||
|
||||
string modFontFamiliesFolder = Path.Combine(Directories.Modifications, "content\\fonts\\families");
|
||||
string customFontLocation = Path.Combine(Directories.Modifications, "content\\fonts\\CustomFont.ttf");
|
||||
|
||||
if (File.Exists(customFontLocation))
|
||||
{
|
||||
App.Logger.WriteLine("[Bootstrapper::ApplyModifications] Begin font check");
|
||||
|
||||
Directory.CreateDirectory(modFontFamiliesFolder);
|
||||
|
||||
foreach (string jsonFilePath in Directory.GetFiles(Path.Combine(_versionFolder, "content\\fonts\\families")))
|
||||
{
|
||||
string jsonFilename = Path.GetFileName(jsonFilePath);
|
||||
string modFilepath = Path.Combine(modFontFamiliesFolder, jsonFilename);
|
||||
|
||||
if (File.Exists(modFilepath))
|
||||
continue;
|
||||
|
||||
FontFamily? fontFamilyData = JsonSerializer.Deserialize<FontFamily>(File.ReadAllText(jsonFilePath));
|
||||
|
||||
if (fontFamilyData is null)
|
||||
continue;
|
||||
|
||||
foreach (FontFace fontFace in fontFamilyData.Faces)
|
||||
fontFace.AssetId = "rbxasset://fonts/CustomFont.ttf";
|
||||
|
||||
File.WriteAllText(modFilepath, JsonSerializer.Serialize(fontFamilyData, new JsonSerializerOptions { WriteIndented = true }));
|
||||
}
|
||||
|
||||
App.Logger.WriteLine("[Bootstrapper::ApplyModifications] End font check");
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.Delete(modFontFamiliesFolder, true);
|
||||
}
|
||||
|
||||
foreach (string file in Directory.GetFiles(modFolder, "*.*", SearchOption.AllDirectories))
|
||||
{
|
||||
// get relative directory path
|
||||
|
20
Bloxstrap/Models/FontFace.cs
Normal file
20
Bloxstrap/Models/FontFace.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Bloxstrap.Models
|
||||
{
|
||||
public class FontFace
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("weight")]
|
||||
public int Weight { get; set; }
|
||||
|
||||
[JsonPropertyName("style")]
|
||||
public string Style { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("assetId")]
|
||||
public string AssetId { get; set; } = null!;
|
||||
}
|
||||
}
|
14
Bloxstrap/Models/FontFamily.cs
Normal file
14
Bloxstrap/Models/FontFamily.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Bloxstrap.Models
|
||||
{
|
||||
public class FontFamily
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("faces")]
|
||||
public IEnumerable<FontFace> Faces { get; set; } = null!;
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Column="0" Margin="0,0,4,0" Text="{Binding InstallLocation, Mode=TwoWay}" />
|
||||
<ui:Button Grid.Column="1" Margin="4,0,4,0" Height="35" Icon="Folder24" Content="Browse" Command="{Binding BrowseInstallLocationCommand}" />
|
||||
<ui:Button Grid.Column="2" Margin="4,0,0,0" Height="35" Icon="ArrowUndo24" Content="Reset" Command="{Binding ResetInstallLocationCommand}" />
|
||||
<ui:Button Grid.Column="2" Margin="4,0,0,0" Height="35" Icon="ArrowCounterclockwise24" Content="Reset" Command="{Binding ResetInstallLocationCommand}" />
|
||||
</Grid>
|
||||
</ui:CardExpander>
|
||||
|
||||
|
@ -113,6 +113,20 @@
|
||||
|
||||
<StackPanel x:Name="MiscellaneousOptions">
|
||||
<TextBlock Text="Miscellaneous" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
|
||||
<ui:CardControl Margin="0,8,0,0">
|
||||
<ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
<TextBlock FontSize="14" Text="Apply custom font" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Foreground="{DynamicResource TextFillColorTertiaryBrush}">
|
||||
Forces every in-game font to be a font that you choose.
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
<ui:Button Icon="DocumentAdd16" Content="Choose font..." Appearance="Primary" Command="{Binding ManageCustomFontCommand}" Visibility="{Binding ChooseCustomFontVisibility, Mode=OneWay}" />
|
||||
<ui:Button Icon="Delete16" Content="Remove applied font" Appearance="Danger" Command="{Binding ManageCustomFontCommand}" Visibility="{Binding DeleteCustomFontVisibility, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
</ui:CardControl>
|
||||
<ui:CardControl Margin="0,8,0,0">
|
||||
<ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
@ -122,7 +136,7 @@
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch IsChecked="{Binding DisableFullscreenOptimizationsEnabled, Mode=TwoWay}" />
|
||||
<ui:ToggleSwitch IsChecked="{Binding DisableFullscreenOptimizations, Mode=TwoWay}" />
|
||||
</ui:CardControl>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
@ -3,7 +3,7 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
@ -40,14 +40,16 @@ namespace Bloxstrap.UI.ViewModels.Menu
|
||||
|
||||
private void BrowseCustomIconLocation()
|
||||
{
|
||||
using var dialog = new OpenFileDialog();
|
||||
dialog.Filter = "Icon files (*.ico)|*.ico|All files (*.*)|*.*";
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
CustomIconLocation = dialog.FileName;
|
||||
OnPropertyChanged(nameof(CustomIconLocation));
|
||||
}
|
||||
Filter = "Icon files|*.ico|All files|*.*"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() != true)
|
||||
return;
|
||||
|
||||
CustomIconLocation = dialog.FileName;
|
||||
OnPropertyChanged(nameof(CustomIconLocation));
|
||||
}
|
||||
|
||||
public AppearanceViewModel(Page page)
|
||||
|
@ -1,21 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
using Bloxstrap.Enums;
|
||||
using Bloxstrap.Extensions;
|
||||
|
||||
using Microsoft.Win32;
|
||||
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Bloxstrap.UI.ViewModels.Menu
|
||||
{
|
||||
public class ModsViewModel
|
||||
public class ModsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public ICommand OpenModsFolderCommand => new RelayCommand(OpenModsFolder);
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
|
||||
private void OpenModsFolder() => Process.Start("explorer.exe", Directories.Modifications);
|
||||
|
||||
private string _customFontLocation = Path.Combine(Directories.Modifications, "content\\fonts\\CustomFont.ttf");
|
||||
private bool _usingCustomFont => File.Exists(_customFontLocation);
|
||||
|
||||
private void ManageCustomFont()
|
||||
{
|
||||
if (_usingCustomFont)
|
||||
{
|
||||
File.Delete(_customFontLocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
Filter = "Font files|*.ttf;*.otf|All files|*.*"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() != true)
|
||||
return;
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(_customFontLocation)!);
|
||||
File.Copy(dialog.FileName, _customFontLocation);
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(ChooseCustomFontVisibility));
|
||||
OnPropertyChanged(nameof(DeleteCustomFontVisibility));
|
||||
}
|
||||
|
||||
public ICommand OpenModsFolderCommand => new RelayCommand(OpenModsFolder);
|
||||
|
||||
public bool OldDeathSoundEnabled
|
||||
{
|
||||
get => App.Settings.Prop.UseOldDeathSound;
|
||||
@ -50,7 +85,12 @@ namespace Bloxstrap.UI.ViewModels.Menu
|
||||
set => App.Settings.Prop.EmojiType = EmojiTypes[value];
|
||||
}
|
||||
|
||||
public bool DisableFullscreenOptimizationsEnabled
|
||||
public Visibility ChooseCustomFontVisibility => _usingCustomFont ? Visibility.Collapsed : Visibility.Visible;
|
||||
public Visibility DeleteCustomFontVisibility => _usingCustomFont ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public ICommand ManageCustomFontCommand => new RelayCommand(ManageCustomFont);
|
||||
|
||||
public bool DisableFullscreenOptimizations
|
||||
{
|
||||
get => App.Settings.Prop.DisableFullscreenOptimizations;
|
||||
set => App.Settings.Prop.DisableFullscreenOptimizations = value;
|
||||
|
Loading…
Reference in New Issue
Block a user