переименовал всякое
This commit is contained in:
parent
15361151d9
commit
6a087767a1
@ -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);
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@ using Avalonia;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
class Главне
|
||||
public class Главне
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>гойда.manifest</ApplicationManifest>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
<ApplicationIcon>капитал\icon.ico</ApplicationIcon>
|
||||
<ApplicationIcon>капитал\кубе.ico</ApplicationIcon>
|
||||
<AssemblyName>млаумчерб</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
@ -17,7 +17,9 @@
|
||||
<PackageReference Include="Avalonia.Desktop" 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 Include="DTLib" Version="1.3.4" />
|
||||
<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="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
42
Млаумчерб.Клиент/Настройки.cs
Normal file
42
Млаумчерб.Клиент/Настройки.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@ -1,22 +1,32 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Млаумчерб.Клиент.Окне"
|
||||
Name="window"
|
||||
Title="млаумчерб"
|
||||
FontFamily="{StaticResource PlexMono}" FontSize="24"
|
||||
Icon="avares://млаумчерб/капитал/icon.ico"
|
||||
Width="600" Height="500"
|
||||
Name="window">
|
||||
Icon="avares://млаумчерб/капитал/кубе.ico"
|
||||
FontFamily="{StaticResource PlexMono}" FontSize="18"
|
||||
MinWidth="800" MinHeight="500"
|
||||
Width="800" Height="500"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>40 *</Grid.RowDefinitions>
|
||||
<Image Grid.RowSpan="2" Stretch="UniformToFill"
|
||||
Source="avares://млаумчерб/капитал/background.png"></Image>
|
||||
<Grid.RowDefinitions>30 * 30</Grid.RowDefinitions>
|
||||
<Image Grid.RowSpan="3" Stretch="UniformToFill"
|
||||
Source="avares://млаумчерб/капитал/фоне.png"></Image>
|
||||
<!-- <Border Grid.Row="0" Background="#7000b0"></Border> -->
|
||||
<Grid Grid.Row="1" Margin="0 60">
|
||||
<Grid.ColumnDefinitions>* 400 *</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Row="1">
|
||||
<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"
|
||||
Height="400"
|
||||
BorderThickness="1" BorderBrush="White"
|
||||
Background="#b7303040">
|
||||
Classes="dark_box white_border"
|
||||
Margin="5 5">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>* 60</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Vertical" Margin="10" Spacing="10">
|
||||
@ -35,17 +45,27 @@
|
||||
Foreground="Blue"
|
||||
Value="{Binding #window.MemoryLimit}">
|
||||
</Slider>
|
||||
<CheckBox IsChecked="{Binding #window.Fullscreen}">Fullscreen</CheckBox>
|
||||
<CheckBox IsChecked="{Binding #window.UpdateGameFiles}">Update game files</CheckBox>
|
||||
<CheckBox IsChecked="{Binding #window.Fullscreen}">
|
||||
Fullscreen
|
||||
</CheckBox>
|
||||
<CheckBox IsChecked="{Binding #window.UpdateGameFiles}">
|
||||
Update game files
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
<Button Grid.Row="1" Margin="10"
|
||||
BorderThickness="1" BorderBrush="Gray"
|
||||
Background="#BBFF4000"
|
||||
<Button Grid.Row="1" Margin="10" Padding="0 0 0 5"
|
||||
BorderThickness="2" BorderBrush="Transparent"
|
||||
Background="#BBFF5900"
|
||||
Click="LaunchButtonHandler">
|
||||
Launch
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border Grid.Column="2"
|
||||
Classes="dark_box white_border"
|
||||
Margin="10 5">
|
||||
|
||||
</Border>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
@ -52,14 +53,14 @@ public partial class Окне : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
Config.LoadFromFile();
|
||||
Username = Config.Instance.username;
|
||||
MemoryLimit = Config.Instance.memory;
|
||||
Fullscreen = Config.Instance.fullscreen;
|
||||
Приложение.Настройки = Настройки.ЗагрузитьИзФайла();
|
||||
Username = Приложение.Настройки.имя_пользователя;
|
||||
MemoryLimit = Приложение.Настройки.выделенная_память_мб;
|
||||
Fullscreen = Приложение.Настройки.открывать_на_весь_экран;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Errors.ShowMessageBox(ex);
|
||||
Ошибки.ПоказатьСообщение(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,16 +68,15 @@ public partial class Окне : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
Config.Instance.username = Username;
|
||||
Config.Instance.memory = MemoryLimit;
|
||||
Config.Instance.fullscreen = Fullscreen;
|
||||
Config.SaveToFile();
|
||||
|
||||
Приложение.Настройки.имя_пользователя = Username;
|
||||
Приложение.Настройки.выделенная_память_мб = MemoryLimit;
|
||||
Приложение.Настройки.открывать_на_весь_экран = Fullscreen;
|
||||
Приложение.Настройки.СохранитьВФайл();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Errors.ShowMessageBox(ex);
|
||||
Ошибки.ПоказатьСообщение(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,12 +6,12 @@ using MsBox.Avalonia.Models;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
public static class Errors
|
||||
public static class Ошибки
|
||||
{
|
||||
internal static void ShowMessageBox(Exception err)
|
||||
=> ShowMessageBox(err.ToStringDemystified());
|
||||
internal static void ПоказатьСообщение(Exception err)
|
||||
=> ПоказатьСообщение(err.ToStringDemystified());
|
||||
|
||||
internal static async void ShowMessageBox(string err)
|
||||
internal static async void ПоказатьСообщение(string err)
|
||||
{
|
||||
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
|
||||
{
|
||||
@ -4,6 +4,19 @@
|
||||
RequestedThemeVariant="Dark">
|
||||
<Application.Styles>
|
||||
<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.Resources>
|
||||
|
||||
@ -20,4 +20,6 @@ public partial class Приложение : Application
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
public static Настройки Настройки = new();
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Loading…
Reference in New Issue
Block a user