Game version management
This commit is contained in:
@@ -7,53 +7,93 @@
|
||||
Title="млаумчерб"
|
||||
Icon="avares://млаумчерб/капитал/кубе.ico"
|
||||
FontFamily="{StaticResource MonospaceFont}" FontSize="18"
|
||||
MinWidth="1200" MinHeight="700"
|
||||
Width="800" Height="500"
|
||||
MinWidth="800" MinHeight="400"
|
||||
Width="800" Height="600"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>* 30</Grid.RowDefinitions>
|
||||
<Grid RowDefinitions="* 30">
|
||||
<Image Grid.RowSpan="2" Stretch="UniformToFill"
|
||||
Source="avares://млаумчерб/капитал/фоне.png"/>
|
||||
|
||||
<Grid Grid.Row="0" Margin="10">
|
||||
<Grid.ColumnDefinitions>* 300 *</Grid.ColumnDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="150"/>
|
||||
<ColumnDefinition Width="2" />
|
||||
<ColumnDefinition MinWidth="300"/>
|
||||
<ColumnDefinition Width="2" />
|
||||
<ColumnDefinition MinWidth="150"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<GridSplitter Grid.Column="1" Background="Transparent" ResizeDirection="Columns" />
|
||||
<GridSplitter Grid.Column="3" Background="Transparent" ResizeDirection="Columns"/>
|
||||
|
||||
<!-- Central panel -->
|
||||
<Border Grid.Column="1"
|
||||
Classes="dark_tr_bg white_border"
|
||||
Margin="10 0">
|
||||
<Border Grid.Column="2"
|
||||
Classes="dark_tr_bg white_border">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>* 60</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Vertical" Margin="10" Spacing="10">
|
||||
<TextBlock>Версия:</TextBlock>
|
||||
<ComboBox Name="VersionComboBox"/>
|
||||
|
||||
<TextBlock>Ник:</TextBlock>
|
||||
<TextBox Background="Transparent"
|
||||
Text="{Binding #window.PlayerName}"/>
|
||||
|
||||
<TextBlock>
|
||||
<Run>Выделенная память:</Run>
|
||||
<TextBox Background="Transparent" Padding="0"
|
||||
BorderThickness="1"
|
||||
BorderBrush="#777777"
|
||||
Text="{Binding #window.MemoryLimit}">
|
||||
</TextBox>
|
||||
<Run>Мб</Run>
|
||||
</TextBlock>
|
||||
<Slider Minimum="2048" Maximum="8192"
|
||||
Value="{Binding #window.MemoryLimit}">
|
||||
</Slider>
|
||||
|
||||
<CheckBox IsChecked="{Binding #window.CheckGameFiles}">
|
||||
Проверять файлы игры
|
||||
</CheckBox>
|
||||
<CheckBox IsChecked="{Binding #window.EnableJavaDownload}">
|
||||
Скачивать джаву
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
<ScrollViewer Grid.Row="0"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Margin="10" Spacing="10">
|
||||
<TextBlock>Версия:</TextBlock>
|
||||
<ComboBox Name="InstalledVersionComboBox"/>
|
||||
<Button Name="DeleteVersionButton"
|
||||
Click="DeleteVersionButton_OnClick">
|
||||
Удалить версию
|
||||
</Button>
|
||||
|
||||
<Expander Header="Добавление версий"
|
||||
BorderThickness="1" BorderBrush="Gray"
|
||||
Padding="4">
|
||||
<StackPanel>
|
||||
<TextBlock>Источник:</TextBlock>
|
||||
<ComboBox Name="VersionCatalogComboBox"/>
|
||||
<WrapPanel>
|
||||
<CheckBox Name="ReleaseVersionTypeCheckBox" IsChecked="True">релиз</CheckBox>
|
||||
<CheckBox Name="SnapshotVersionTypeCheckBox">снапшот</CheckBox>
|
||||
<CheckBox Name="OldVersionTypeCheckBox">старое</CheckBox>
|
||||
<CheckBox Name="OtherVersionTypeAlphaCheckBox">другое</CheckBox>
|
||||
</WrapPanel>
|
||||
<Button Name="SearchVersionsButton"
|
||||
Click="SearchVersionsButton_OnClick">
|
||||
Поиск
|
||||
</Button>
|
||||
<TextBlock>Доступные версии:</TextBlock>
|
||||
<ComboBox Name="VersionCatalogItemsComboBox"/>
|
||||
<Button Name="AddVersionButton" IsEnabled="False"
|
||||
Click="AddVersionButton_OnClick">
|
||||
Добавить
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
|
||||
<TextBlock>Ник:</TextBlock>
|
||||
<TextBox Background="Transparent"
|
||||
Text="{Binding #window.PlayerName}"/>
|
||||
|
||||
<TextBlock>
|
||||
<Run>Выделенная память:</Run>
|
||||
<TextBox Background="Transparent" Padding="0"
|
||||
BorderThickness="1"
|
||||
BorderBrush="#777777"
|
||||
Text="{Binding #window.MemoryLimit}">
|
||||
</TextBox>
|
||||
<Run>Мб</Run>
|
||||
</TextBlock>
|
||||
<Slider Minimum="2048" Maximum="8192"
|
||||
Value="{Binding #window.MemoryLimit}">
|
||||
</Slider>
|
||||
|
||||
<CheckBox IsChecked="{Binding #window.CheckGameFiles}">
|
||||
Проверять файлы игры
|
||||
</CheckBox>
|
||||
<CheckBox IsChecked="{Binding #window.EnableJavaDownload}">
|
||||
Скачивать джаву
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<Button Name="LaunchButton" Grid.Row="1"
|
||||
Margin="10" Padding="0 0 0 4"
|
||||
Margin="10" Padding="4"
|
||||
Classes="button_no_border"
|
||||
Background="#BBfd7300"
|
||||
Click="Запуск">
|
||||
@@ -63,10 +103,9 @@
|
||||
</Border>
|
||||
|
||||
<!-- Left panel -->
|
||||
<Border Grid.Column="0"
|
||||
<Border Grid.Column="0"
|
||||
Classes="dark_tr_bg white_border">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>36 *</Grid.RowDefinitions>
|
||||
<Grid RowDefinitions="36 *">
|
||||
<Border Classes="white_border" Margin="-1" Padding="4">
|
||||
<DockPanel>
|
||||
<TextBlock FontWeight="Bold"
|
||||
@@ -92,9 +131,9 @@
|
||||
</Border>
|
||||
|
||||
<!-- Right panel -->
|
||||
<Border Grid.Column="2" Classes="dark_tr_bg white_border">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>36 *</Grid.RowDefinitions>
|
||||
<Border Grid.Column="4"
|
||||
Classes="dark_tr_bg white_border">
|
||||
<Grid RowDefinitions="36 *">
|
||||
<Border Classes="white_border" Margin="-1" Padding="4">
|
||||
<DockPanel>
|
||||
<TextBlock FontWeight="Bold"
|
||||
|
||||
@@ -6,6 +6,9 @@ using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Dto;
|
||||
using MsBox.Avalonia.Models;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.зримое;
|
||||
|
||||
@@ -63,19 +66,26 @@ public partial class MainWindow : Window
|
||||
MemoryLimit = LauncherApp.Config.max_memory;
|
||||
EnableJavaDownload = LauncherApp.Config.download_java;
|
||||
|
||||
VersionComboBox.SelectedIndex = 0;
|
||||
VersionComboBox.IsEnabled = false;
|
||||
InstalledVersionComboBox.SelectedIndex = 0;
|
||||
InstalledVersionComboBox.IsEnabled = false;
|
||||
var versions = await GameVersion.GetAllVersionsAsync();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
foreach (var p in versions)
|
||||
{
|
||||
VersionComboBox.Items.Add(new VersionItemView(p));
|
||||
InstalledVersionComboBox.Items.Add(new VersionItemView(p));
|
||||
// select last played version
|
||||
if (LauncherApp.Config.last_launched_version != null &&
|
||||
p.Name == LauncherApp.Config.last_launched_version)
|
||||
VersionComboBox.SelectedIndex = VersionComboBox.Items.Count - 1;
|
||||
InstalledVersionComboBox.SelectedIndex = InstalledVersionComboBox.Items.Count - 1;
|
||||
}
|
||||
VersionComboBox.IsEnabled = true;
|
||||
InstalledVersionComboBox.IsEnabled = true;
|
||||
|
||||
foreach (var vc in LauncherApp.Config.version_catalogs)
|
||||
{
|
||||
VersionCatalogComboBox.Items.Add(vc);
|
||||
}
|
||||
VersionCatalogComboBox.SelectedIndex = 0;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -103,7 +113,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() => LaunchButton.IsEnabled = false);
|
||||
|
||||
var selectedVersionView = (VersionItemView?)VersionComboBox.SelectedItem;
|
||||
var selectedVersionView = (VersionItemView?)InstalledVersionComboBox.SelectedItem;
|
||||
var selectedVersion = selectedVersionView?.Props;
|
||||
LauncherApp.Config.last_launched_version = selectedVersion?.Name;
|
||||
LauncherApp.Config.player_name = PlayerName;
|
||||
@@ -196,4 +206,94 @@ public partial class MainWindow : Window
|
||||
}
|
||||
DownloadsPanel.Children.Clear();
|
||||
}
|
||||
|
||||
private async void DeleteVersionButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
VersionItemView? sel = InstalledVersionComboBox.SelectedItem as VersionItemView;
|
||||
if(sel is null)
|
||||
return;
|
||||
|
||||
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
|
||||
{
|
||||
ButtonDefinitions = new List<ButtonDefinition> { new() { Name = "Да" }, new() { Name = "Нет" } },
|
||||
ContentTitle = $"Удаление версии {sel.Props.Name}",
|
||||
ContentMessage = $"Вы уверены, что хотите удалить версию {sel.Props.Name}? Все файлы, включая сохранения, будут удалены!",
|
||||
Icon = MsBox.Avalonia.Enums.Icon.Question,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||
SizeToContent = SizeToContent.WidthAndHeight,
|
||||
ShowInCenter = true,
|
||||
Topmost = true
|
||||
}
|
||||
);
|
||||
var result = await box.ShowAsync().ConfigureAwait(false);
|
||||
if (result != "Да")
|
||||
return;
|
||||
|
||||
sel.Props.DeleteFiles();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
InstalledVersionComboBox.Items.Remove(sel);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private async void SearchVersionsButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var catalogProps = VersionCatalogComboBox.SelectedItem as VersionCatalogProps;
|
||||
if(catalogProps is null)
|
||||
return;
|
||||
|
||||
var catalog = await catalogProps.GetVersionCatalogAsync();
|
||||
var searchParams = new VersionSearchParams();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
searchParams.ReleaseTypeAllowed = ReleaseVersionTypeCheckBox.IsChecked ?? false;
|
||||
searchParams.SnapshotTypeAllowed = SnapshotVersionTypeCheckBox.IsChecked ?? false;
|
||||
searchParams.OldTypeAllowed = OldVersionTypeCheckBox.IsChecked ?? false;
|
||||
searchParams.OtherTypeAllowed = OtherVersionTypeAlphaCheckBox.IsChecked ?? false;
|
||||
});
|
||||
var versions = catalog.GetDownloadableVersions(searchParams);
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
VersionCatalogItemsComboBox.IsEnabled = false;
|
||||
VersionCatalogItemsComboBox.Items.Clear();
|
||||
foreach (var p in versions)
|
||||
{
|
||||
VersionCatalogItemsComboBox.Items.Add(new VersionItemView(p));
|
||||
}
|
||||
VersionCatalogItemsComboBox.IsEnabled = true;
|
||||
AddVersionButton.IsEnabled = versions.Count > 0;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddVersionButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var selectedVersionView = VersionCatalogItemsComboBox.SelectedItem as VersionItemView;
|
||||
if(selectedVersionView is null)
|
||||
return;
|
||||
|
||||
InstalledVersionComboBox.Items.Insert(0, new VersionItemView(selectedVersionView.Props));
|
||||
InstalledVersionComboBox.SelectedIndex = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Mlaumcherb.Client.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Mlaumcherb.Client.Avalonia.зримое.VersionItemView">
|
||||
x:Class="Mlaumcherb.Client.Avalonia.зримое.VersionItemView"
|
||||
Padding="2">
|
||||
<TextBlock Name="text" Background="Transparent"/>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.зримое;
|
||||
@@ -20,12 +21,14 @@ public partial class VersionItemView : ListBoxItem
|
||||
Props = props;
|
||||
InitializeComponent();
|
||||
text.Text = props.Name;
|
||||
props.OnDownloadCompleted += UpdateBackground;
|
||||
UpdateBackground();
|
||||
props.StatusChanged += UpdateBackground;
|
||||
UpdateBackground(props.IsDownloaded);
|
||||
}
|
||||
|
||||
private void UpdateBackground()
|
||||
private void UpdateBackground(bool isDownloaded)
|
||||
{
|
||||
Background = Props.IsDownloaded ? _avaliableColor : _unavaliableColor;
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
Background = isDownloaded ? _avaliableColor : _unavaliableColor
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user