переименовал всякое

This commit is contained in:
Timerix 2024-09-01 15:41:01 +05:00
parent 15361151d9
commit 6a087767a1
12 changed files with 113 additions and 80 deletions

View File

@ -1,46 +0,0 @@
using Newtonsoft.Json;
namespace Млаумчерб.Клиент;
public class Config
{
public string username { get; set; } = "";
public int memory { get; set; } = 4096;
public bool fullscreen { get; set; }
[JsonIgnore] public static Config Instance { get; private set; } = new();
public const string FileName = "млаумчерб.конфиг";
public const string BackupFileName = "млаумчерб.конфиг.старый";
public static readonly Encoding UTF8WithoutBom = new UTF8Encoding(false);
public static void LoadFromFile()
{
//TODO: log
if(!File.Exists(FileName))
{
SaveToFile();
return;
}
string text = File.ReadAllText(FileName);
Config? c = JsonConvert.DeserializeObject<Config>(text);
if (c is not null)
Instance = c;
else
{
File.Move(FileName, BackupFileName, true);
SaveToFile();
Errors.ShowMessageBox($"Не удалось прочитать конфиг.\n" +
$"Сломанный конфиг переименован в '{BackupFileName}'.\n" +
$"Создан новый файл '{FileName}'.");
}
}
public static void SaveToFile()
{
//TODO: log
var text = JsonConvert.SerializeObject(Instance, Formatting.Indented);
File.WriteAllText(FileName, text, UTF8WithoutBom);
}
}

View File

@ -7,7 +7,7 @@ using Avalonia;
namespace Млаумчерб.Клиент; namespace Млаумчерб.Клиент;
class Главне public class Главне
{ {
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)

View File

@ -8,7 +8,7 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport> <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>гойда.manifest</ApplicationManifest> <ApplicationManifest>гойда.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault> <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationIcon>капитал\icon.ico</ApplicationIcon> <ApplicationIcon>капитал\кубе.ico</ApplicationIcon>
<AssemblyName>млаумчерб</AssemblyName> <AssemblyName>млаумчерб</AssemblyName>
</PropertyGroup> </PropertyGroup>
@ -17,7 +17,9 @@
<PackageReference Include="Avalonia.Desktop" Version="11.1.3" /> <PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
<PackageReference Include="Avalonia.Themes.Simple" Version="11.1.3" /> <PackageReference Include="Avalonia.Themes.Simple" Version="11.1.3" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" /> <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
<PackageReference Include="DTLib" Version="1.3.4" />
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.6" /> <PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.6" />
<PackageReference Include="DTLib.Logging" Version="1.3.5" />
<PackageReference Include="MessageBox.Avalonia" Version="3.1.6" /> <PackageReference Include="MessageBox.Avalonia" Version="3.1.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,42 @@
using Newtonsoft.Json;
namespace Млаумчерб.Клиент;
public class Настройки
{
public string имя_пользователя { get; set; } = "";
public int выделенная_память_мб { get; set; } = 4096;
public bool открыватьаесь_экран { get; set; }
public static readonly Encoding UTF8WithoutBom = new UTF8Encoding(false);
public static Настройки ЗагрузитьИзФайла(string имяайла = "млаумчерб.настройки")
{
//TODO: лог
if(!File.Exists(имяайла))
{
return new Настройки();
}
string текст = File.ReadAllText(имяайла);
Настройки? н = JsonConvert.DeserializeObject<Настройки>(текст);
if (н == null)
{
File.Move(имяайла, имяайла + ".старые", true);
н = new Настройки();
н.СохранитьВФайл();
Ошибки.ПоказатьСообщение($"Не удалось прочитать настройки.\n" +
$"Сломанный файл настроек переименован в '{имя_файла}.старые'.\n" +
$"Создан новый файл '{имя_файла}'.");
}
return н;
}
public void СохранитьВФайл(string имяайла = "млаумчерб.настройки")
{
//TODO: log
var текст = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(имяайла, текст, UTF8WithoutBom);
}
}

View File

@ -1,22 +1,32 @@
<Window xmlns="https://github.com/avaloniaui" <Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Млаумчерб.Клиент.Окне" x:Class="Млаумчерб.Клиент.Окне"
Name="window"
Title="млаумчерб" Title="млаумчерб"
FontFamily="{StaticResource PlexMono}" FontSize="24" Icon="avares://млаумчерб/капитал/кубе.ico"
Icon="avares://млаумчерб/капитал/icon.ico" FontFamily="{StaticResource PlexMono}" FontSize="18"
Width="600" Height="500" MinWidth="800" MinHeight="500"
Name="window"> Width="800" Height="500"
WindowStartupLocation="CenterScreen">
<Grid> <Grid>
<Grid.RowDefinitions>40 *</Grid.RowDefinitions> <Grid.RowDefinitions>30 * 30</Grid.RowDefinitions>
<Image Grid.RowSpan="2" Stretch="UniformToFill" <Image Grid.RowSpan="3" Stretch="UniformToFill"
Source="avares://млаумчерб/капитал/background.png"></Image> Source="avares://млаумчерб/капитал/фоне.png"></Image>
<!-- <Border Grid.Row="0" Background="#7000b0"></Border> --> <!-- <Border Grid.Row="0" Background="#7000b0"></Border> -->
<Grid Grid.Row="1" Margin="0 60"> <Grid Grid.Row="1">
<Grid.ColumnDefinitions>* 400 *</Grid.ColumnDefinitions> <Grid.ColumnDefinitions>* 300 *</Grid.ColumnDefinitions>
<Border Grid.Column="0"
Classes="dark_box white_border"
Margin="10 5 ">
<Grid>
<Grid.RowDefinitions>30 *</Grid.RowDefinitions>
<Grid.ColumnDefinitions>30</Grid.ColumnDefinitions>
<Button></Button>
</Grid>
</Border>
<Border Grid.Column="1" <Border Grid.Column="1"
Height="400" Classes="dark_box white_border"
BorderThickness="1" BorderBrush="White" Margin="5 5">
Background="#b7303040">
<Grid> <Grid>
<Grid.RowDefinitions>* 60</Grid.RowDefinitions> <Grid.RowDefinitions>* 60</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Margin="10" Spacing="10"> <StackPanel Orientation="Vertical" Margin="10" Spacing="10">
@ -35,17 +45,27 @@
Foreground="Blue" Foreground="Blue"
Value="{Binding #window.MemoryLimit}"> Value="{Binding #window.MemoryLimit}">
</Slider> </Slider>
<CheckBox IsChecked="{Binding #window.Fullscreen}">Fullscreen</CheckBox> <CheckBox IsChecked="{Binding #window.Fullscreen}">
<CheckBox IsChecked="{Binding #window.UpdateGameFiles}">Update game files</CheckBox> Fullscreen
</CheckBox>
<CheckBox IsChecked="{Binding #window.UpdateGameFiles}">
Update game files
</CheckBox>
</StackPanel> </StackPanel>
<Button Grid.Row="1" Margin="10" <Button Grid.Row="1" Margin="10" Padding="0 0 0 5"
BorderThickness="1" BorderBrush="Gray" BorderThickness="2" BorderBrush="Transparent"
Background="#BBFF4000" Background="#BBFF5900"
Click="LaunchButtonHandler"> Click="LaunchButtonHandler">
Launch Launch
</Button> </Button>
</Grid> </Grid>
</Border> </Border>
<Border Grid.Column="2"
Classes="dark_box white_border"
Margin="10 5">
</Border>
</Grid> </Grid>
</Grid> </Grid>
</Window> </Window>

View File

@ -1,3 +1,4 @@
using System.ComponentModel.DataAnnotations;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Data; using Avalonia.Data;
@ -52,14 +53,14 @@ public partial class Окне : Window
{ {
try try
{ {
Config.LoadFromFile(); Приложение.Настройки = Настройки.ЗагрузитьИзФайла();
Username = Config.Instance.username; Username = Приложение.Настройки.имя_пользователя;
MemoryLimit = Config.Instance.memory; MemoryLimit = Приложение.Настройки.выделенная_память_мб;
Fullscreen = Config.Instance.fullscreen; Fullscreen = Приложение.Настройки.открыватьаесь_экран;
} }
catch (Exception ex) catch (Exception ex)
{ {
Errors.ShowMessageBox(ex); Ошибки.ПоказатьСообщение(ex);
} }
} }
@ -67,16 +68,15 @@ public partial class Окне : Window
{ {
try try
{ {
Config.Instance.username = Username; Приложение.Настройки.имя_пользователя = Username;
Config.Instance.memory = MemoryLimit; Приложение.Настройки.выделенная_память_мб = MemoryLimit;
Config.Instance.fullscreen = Fullscreen; Приложение.Настройки.открыватьаесь_экран = Fullscreen;
Config.SaveToFile(); Приложение.Настройки.СохранитьВФайл();
} }
catch (Exception ex) catch (Exception ex)
{ {
Errors.ShowMessageBox(ex); Ошибки.ПоказатьСообщение(ex);
} }
} }
} }

View File

@ -6,12 +6,12 @@ using MsBox.Avalonia.Models;
namespace Млаумчерб.Клиент; namespace Млаумчерб.Клиент;
public static class Errors public static class Ошибки
{ {
internal static void ShowMessageBox(Exception err) internal static void ПоказатьСообщение(Exception err)
=> ShowMessageBox(err.ToStringDemystified()); => ПоказатьСообщение(err.ToStringDemystified());
internal static async void ShowMessageBox(string err) internal static async void ПоказатьСообщение(string err)
{ {
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
{ {

View File

@ -4,6 +4,19 @@
RequestedThemeVariant="Dark"> RequestedThemeVariant="Dark">
<Application.Styles> <Application.Styles>
<SimpleTheme /> <SimpleTheme />
<Style Selector="Control.center">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style Selector="Border.dark_box">
<Setter Property="Background" Value="#b7303040"/>
</Style>
<Style Selector="Control.white_border">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="White"/>
</Style>
</Application.Styles> </Application.Styles>
<Application.Resources> <Application.Resources>

View File

@ -20,4 +20,6 @@ public partial class Приложение : Application
base.OnFrameworkInitializationCompleted(); base.OnFrameworkInitializationCompleted();
} }
public static Настройки Настройки = new();
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB