program settings added with some new bugs

This commit is contained in:
Timerix22 2022-03-17 23:41:37 +03:00
parent c5815c17e0
commit 93847820ce
10 changed files with 156 additions and 111 deletions

View File

@ -5,12 +5,11 @@
<SolidColorBrush x:Key="MyDarkTr" <SolidColorBrush x:Key="MyDarkTr"
Opacity="0.8" Opacity="0.8"
Color="#141419" /> Color="#141419" />
<SolidColorBrush x:Key="MyGray" Color="#4B4B50" /> <SolidColorBrush x:Key="MyGray" Color="#46464B" />
<SolidColorBrush x:Key="MyWhite" Color="#F0F0F0" /> <SolidColorBrush x:Key="MyWhite" Color="#F0F0F0" />
<SolidColorBrush x:Key="MyGreen" Color="#2CDA11" /> <SolidColorBrush x:Key="MyGreen" Color="#28C311" />
<SolidColorBrush x:Key="MyOrange" Color="#D09524" />
<SolidColorBrush x:Key="MyRed" Color="#E5160A" /> <SolidColorBrush x:Key="MyRed" Color="#E5160A" />
<SolidColorBrush x:Key="MySelectionColor" Color="#3768A4" /> <SolidColorBrush x:Key="MySelectionColor" Color="#B7800A" />
<ControlTemplate x:Key="myScrollBar" TargetType="{x:Type ScrollBar}"> <ControlTemplate x:Key="myScrollBar" TargetType="{x:Type ScrollBar}">
@ -105,6 +104,15 @@
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
<Style x:Key="MyTextBoxStyle" TargetType="TextBox">
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="Background" Value="{DynamicResource MyDarkTr}" />
<Setter Property="FontSize" Value="16" />
<Setter Property="Foreground" Value="{DynamicResource MyWhite}" />
<Setter Property="SelectionBrush" Value="{DynamicResource MySelectionColor}" />
<Setter Property="Template" Value="{DynamicResource myTextBox}" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
<ControlTemplate x:Key="myTextBox" TargetType="{x:Type TextBoxBase}"> <ControlTemplate x:Key="myTextBox" TargetType="{x:Type TextBoxBase}">
<Border Name="Border" <Border Name="Border"
Padding="0" Padding="0"
@ -139,18 +147,28 @@
Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
BorderBrush="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"> BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}">
<ContentPresenter Margin="2" <Grid>
HorizontalAlignment="Center" <Border x:Name="Border_fade"
VerticalAlignment="Center" Background="{DynamicResource MyWhite}"
RecognizesAccessKey="True" /> Opacity="0.2"
Visibility="Hidden" />
<Border x:Name="Border_fade2"
Background="{DynamicResource MyGray}"
Opacity="0.4"
Visibility="Hidden" />
<ContentPresenter Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True" />
</Grid>
</Border> </Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true"> <Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Background" Value="#FF4E4E59" /> <Setter TargetName="Border_fade" Property="Visibility" Value="Visible" />
</Trigger> </Trigger>
<Trigger Property="IsPressed" Value="true"> <Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border" Property="Background" Value="#FF38384F" /> <Setter TargetName="Border_fade" Property="Visibility" Value="Hidden" />
<Setter TargetName="Border_fade2" Property="Visibility" Value="Visible" />
</Trigger> </Trigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
@ -186,7 +204,7 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Data="M 0 0 L 4 4 L 8 0 Z" Data="M 0 0 L 4 4 L 8 0 Z"
Fill="{DynamicResource MyOrange}" /> Fill="{DynamicResource MySelectionColor}" />
</Grid> </Grid>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="ToggleButton.IsMouseOver" Value="true"> <Trigger Property="ToggleButton.IsMouseOver" Value="true">

View File

@ -1,5 +1,4 @@
using System.Windows.Input; using System.Windows.Media;
using System.Windows.Media;
namespace launcher_client_win.GUI; namespace launcher_client_win.GUI;
@ -17,7 +16,7 @@ public partial class App : Application
MySoftDark = (SolidColorBrush)Resources["MyGray"]; MySoftDark = (SolidColorBrush)Resources["MyGray"];
MyWhite = (SolidColorBrush)Resources["MyWhite"]; MyWhite = (SolidColorBrush)Resources["MyWhite"];
MyGreen = (SolidColorBrush)Resources["MyGreen"]; MyGreen = (SolidColorBrush)Resources["MyGreen"];
MyOrange = (SolidColorBrush)Resources["MyOrange"]; MyOrange = (SolidColorBrush)Resources["MySelectionColor"];
MySelectionColor = (SolidColorBrush)Resources["MySelectionColor"]; MySelectionColor = (SolidColorBrush)Resources["MySelectionColor"];
_Main(e.Args); _Main(e.Args);
} }

View File

@ -44,7 +44,6 @@
Grid.Column="0" Grid.Column="0"
Content="Library" Content="Library"
FontSize="18" FontSize="18"
Foreground="{DynamicResource MyGreen}"
Style="{DynamicResource MyButtonStyle}" /> Style="{DynamicResource MyButtonStyle}" />
<local:TabButton x:Name="DownloadsButton" <local:TabButton x:Name="DownloadsButton"
Grid.Column="2" Grid.Column="2"
@ -105,52 +104,38 @@
<Button x:Name="RemoveButton" <Button x:Name="RemoveButton"
Width="100" Width="100"
Margin="2,0" Margin="2,0"
Background="{DynamicResource MyRed}"
Content="Remove" Content="Remove"
Foreground="{DynamicResource MyRed}"
Style="{DynamicResource MyButtonStyle}" /> Style="{DynamicResource MyButtonStyle}" />
<Button x:Name="InstallButton" <Button x:Name="InstallButton"
Width="100" Width="100"
Margin="2,0" Margin="2,0"
Content="Install" Content="Install"
Foreground="{DynamicResource MyOrange}"
Style="{DynamicResource MyButtonStyle}" /> Style="{DynamicResource MyButtonStyle}" />
<Button x:Name="UpdateButton" <Button x:Name="UpdateButton"
Width="100" Width="100"
Margin="2,0" Margin="2,0"
Content="Update" Content="Update"
Foreground="{DynamicResource MyOrange}"
Style="{DynamicResource MyButtonStyle}" /> Style="{DynamicResource MyButtonStyle}" />
<Button x:Name="LaunchButton" <Button x:Name="LaunchButton"
Width="100" Width="100"
Margin="2,0" Margin="2,0"
Background="{DynamicResource MyGreen}"
Content="Launch" Content="Launch"
Foreground="{DynamicResource MyGreen}"
Style="{DynamicResource MyButtonStyle}" /> Style="{DynamicResource MyButtonStyle}" />
</StackPanel> </StackPanel>
<TextBox x:Name="DescriptionBox" <TextBox x:Name="DescriptionBox"
Grid.Row="4" Grid.Row="4"
Background="{DynamicResource MyDarkTr}" Style="{DynamicResource MyTextBoxStyle}"
FontSize="16"
Foreground="{DynamicResource MyWhite}"
IsReadOnly="True"
SelectionBrush="{DynamicResource MySelectionColor}"
Template="{DynamicResource myTextBox}"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" /> VerticalScrollBarVisibility="Auto" />
<TextBox x:Name="ProgramLogBox" <TextBox x:Name="ProgramLogBox"
Grid.Row="6" Grid.Row="6"
Background="{DynamicResource MyDarkTr}" Style="{DynamicResource MyTextBoxStyle}"
FontSize="16"
Foreground="{DynamicResource MyWhite}"
IsReadOnly="True"
SelectionBrush="{DynamicResource MySelectionColor}"
Template="{DynamicResource myTextBox}"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" /> VerticalScrollBarVisibility="Auto" />
</Grid> </Grid>
<Grid Grid.Row="0" Grid.Column="4"> <Grid Grid.Row="0" Grid.Column="4">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="90" /> <RowDefinition Height="95" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Row="0"> <Grid Grid.Row="0">
@ -197,13 +182,12 @@
Content="0" Content="0"
Style="{DynamicResource MyLabelStyle}" /> Style="{DynamicResource MyLabelStyle}" />
</Grid> </Grid>
<ScrollViewer Grid.Row="1" <ScrollViewer Name="ProgramSettingsViever"
Grid.Row="1"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
VerticalContentAlignment="Top" VerticalContentAlignment="Top"
Template="{DynamicResource myScrollViewer}"> Template="{DynamicResource myScrollViewer}" />
<StackPanel x:Name="ProgramSettings" />
</ScrollViewer>
</Grid> </Grid>
</Grid> </Grid>
@ -230,14 +214,7 @@
<TextBox x:Name="LogBox" <TextBox x:Name="LogBox"
Grid.Row="1" Grid.Row="1"
Grid.Column="0" Grid.Column="0"
Background="{DynamicResource MyDarkTr}" Style="{DynamicResource MyTextBoxStyle}"
BorderThickness="0"
FontSize="16"
Foreground="{DynamicResource MyWhite}"
IsReadOnly="True"
SelectionBrush="{DynamicResource MySelectionColor}"
Template="{DynamicResource myTextBox}"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" /> VerticalScrollBarVisibility="Auto" />
</Grid> </Grid>

View File

@ -1,5 +1,4 @@
using System.Windows.Controls; using System.Windows.Media.Imaging;
using System.Windows.Media.Imaging;
namespace launcher_client_win.GUI; namespace launcher_client_win.GUI;
@ -42,41 +41,14 @@ public partial class LauncherWindow : Window
{ {
if(CurrentTab!=null) if(CurrentTab!=null)
{ {
CurrentTab.Foreground = App.MyWhite; CurrentTab.Background = App.MyDark;
CurrentTab.TabGrid.Visibility = Visibility.Collapsed; CurrentTab.TabGrid.Visibility = Visibility.Collapsed;
} }
var selected = (TabButton)sender; var selected = (TabButton)sender;
selected.Foreground = App.MyGreen; selected.Background = App.MySelectionColor;
selected.TabGrid.Visibility = Visibility.Visible; selected.TabGrid.Visibility = Visibility.Visible;
CurrentTab = selected; CurrentTab = selected;
} }
void LibraryTab_activate(object sender, RoutedEventArgs eventArgs)
{
LibraryButton.Foreground = App.MyGreen;
LogButton.Foreground = App.MyWhite;
SettingsButton.Foreground = App.MyWhite;
LibraryGrid.Visibility = Visibility.Visible;
LogGrid.Visibility = Visibility.Hidden;
SettingsGrid.Visibility = Visibility.Hidden;
}
void LogTab_activate(object sender, RoutedEventArgs eventArgs)
{
LibraryButton.Foreground = App.MyWhite;
LogButton.Foreground = App.MyGreen;
SettingsButton.Foreground = App.MyWhite;
LibraryGrid.Visibility = Visibility.Hidden;
LogGrid.Visibility = Visibility.Visible;
SettingsGrid.Visibility = Visibility.Hidden;
}
void SettingsTab_activate(object sender, RoutedEventArgs eventArgs)
{
LibraryButton.Foreground = App.MyWhite;
LogButton.Foreground = App.MyWhite;
SettingsButton.Foreground = App.MyGreen;
LibraryGrid.Visibility = Visibility.Hidden;
LogGrid.Visibility = Visibility.Hidden;
SettingsGrid.Visibility = Visibility.Visible;
}
public Program[] Programs; public Program[] Programs;
@ -99,7 +71,7 @@ public partial class LauncherWindow : Window
} }
public Program DisplayingProgram; public Program DisplayingProgram;
public void SelectProgram(Program selectedP) public void SelectProgram(Program selectedProg)
{ {
try try
{ {
@ -110,16 +82,17 @@ public partial class LauncherWindow : Window
} }
else ProgramGrid.Visibility = Visibility.Visible; else ProgramGrid.Visibility = Visibility.Visible;
selectedP.ProgramLabel.Foreground = App.MyGreen; selectedProg.ProgramLabel.Foreground = App.MySelectionColor;
selectedP.ProgramLabel.FontWeight = FontWeights.Bold; selectedProg.ProgramLabel.FontWeight = FontWeights.Bold;
NameLabel.Content = selectedP.Name; NameLabel.Content = selectedProg.Name;
DescriptionBox.Text = selectedP.Description; DescriptionBox.Text = selectedProg.Description;
BackgroundImage.Source = BackgroundImage.Source =
new BitmapImage(new Uri( new BitmapImage(new Uri(
$"{Directory.GetCurrent()}{Path.Sep}backgrounds{Path.Sep}{selectedP.BackgroundFile}", $"{Directory.GetCurrent()}{Path.Sep}backgrounds{Path.Sep}{selectedProg.BackgroundFile}",
UriKind.Absolute)); UriKind.Absolute));
DisplayingProgram = selectedP; ProgramSettingsViever.Content = selectedProg.SettingsPanel;
DisplayingProgram = selectedProg;
} }
catch(Exception ex) catch(Exception ex)
{ LogError("SelectProgram()",ex); } { LogError("SelectProgram()",ex); }

View File

@ -1,5 +1,4 @@
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
namespace launcher_client_win.GUI; namespace launcher_client_win.GUI;

View File

@ -0,0 +1,26 @@
<UserControl x:Class="launcher_client_win.GUI.ProgramSettingsPanelItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:launcher_client_win.GUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Height="30"
d:DesignWidth="100"
mc:Ignorable="d"
Background="Transparent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Name="KeyLabel" Grid.Column="0"
Content="{Binding SettingKey, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProgramSettingsPanelItem}}"
Style="{DynamicResource MyLabelStyle}" />
<TextBox Name="ValueBox" Grid.Column="1"
HorizontalScrollBarVisibility="Auto"
Style="{DynamicResource MyTextBoxStyle}"
VerticalScrollBarVisibility="Disabled"
IsReadOnly="False"
Text="{Binding SettingValue, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProgramSettingsPanelItem}}"/>
</Grid>
</UserControl>

View File

@ -0,0 +1,36 @@
using System.Windows.Controls;
namespace launcher_client_win.GUI;
public partial class ProgramSettingsPanelItem : UserControl
{
public static readonly DependencyProperty SettingKeyProp = DependencyProperty.Register(
"SettingKey",
typeof(string),
typeof(TabButton));
public string SettingKey
{
get => (string)GetValue(SettingKeyProp);
set => SetValue(SettingKeyProp, value);
}
public static readonly DependencyProperty SettingValueProp = DependencyProperty.Register(
"SettingValue",
typeof(string),
typeof(TabButton));
public string SettingValue
{
get => (string)GetValue(SettingValueProp);
set => SetValue(SettingValueProp, value);
}
public ProgramSettingsPanelItem(string key, string value)
{
InitializeComponent();
SettingKey = key;
SettingValue = value;
ValueBox.TextChanged += (_,_)=> UpdatedEvent?.Invoke(this);
}
public event Action<ProgramSettingsPanelItem> UpdatedEvent;
}

View File

@ -32,6 +32,7 @@ public static class Launcher
Directory.Create("icons"); Directory.Create("icons");
Directory.Create("backgrounds"); Directory.Create("backgrounds");
Directory.Create("installed"); Directory.Create("installed");
Directory.Create("settings");
File.WriteAllText($"descriptors{Path.Sep}default.descriptor.template", File.WriteAllText($"descriptors{Path.Sep}default.descriptor.template",
ReadResource("launcher_client_win.Resources.default.descriptor.template")); ReadResource("launcher_client_win.Resources.default.descriptor.template"));
CurrentLauncherWindow = new(); CurrentLauncherWindow = new();

View File

@ -20,30 +20,18 @@ public class LauncherConfig
public LauncherConfig() public LauncherConfig()
{ {
// читает дефолтный конфиг из ресурсов // читает дефолтный конфиг из ресурсов
DtsodV23 updatedDtsod = new(ReadResource("launcher_client_win.Resources.launcher.dtsod")); DtsodV23 updatedConfig;
DtsodV23 updatedDefault = new(ReadResource("launcher_client_win.Resources.launcher.dtsod"));
// проверка и обновление конфига // проверка и обновление конфига
if (File.Exists(configFile)) if (File.Exists(configFile))
{ {
DtsodV23 dtsod = new(File.ReadAllText(configFile)); DtsodV23 oldConfig = new(File.ReadAllText(configFile));
// заменяет дефолтные значения на пользовательские updatedConfig = DtsodFunctions.UpdateByDefault(oldConfig, updatedDefault);
foreach (var p in dtsod)
{
if (updatedDtsod.TryGetValue(p.Key, out dynamic def))
{
if (def.GetType() != p.Value.GetType())
throw new Exception(
"uncompatible config value type\n " +
$"launcher.dtsod: {p.Key}:{p.Value} is {p.Value.GetType().Name}, " +
$"must be {def.GetType().Name}");
updatedDtsod[p.Key] = p.Value;
}
}
// записывает обновлённый конфиг в файл
WriteToFile();
} }
else updatedConfig = updatedDefault;
// парсит парсит полученный дтсод в LauncherConfig // парсит парсит полученный дтсод в LauncherConfig
List<object> serversD = updatedDtsod["server"]; List<object> serversD = updatedConfig["server"];
ServerAddresses = new Server[serversD.Count]; ServerAddresses = new Server[serversD.Count];
ushort i = 0; ushort i = 0;
foreach (DtsodV23 serverD in serversD) foreach (DtsodV23 serverD in serversD)
@ -54,8 +42,11 @@ public class LauncherConfig
? new Server(dom, port) ? new Server(dom, port)
: new Server(IPAddress.Parse(serverD["ip"]), port); : new Server(IPAddress.Parse(serverD["ip"]), port);
} }
WriteToFile();
} }
// записывает обновлённый конфиг в файл
public void WriteToFile() public void WriteToFile()
{ {
StringBuilder b = new(); StringBuilder b = new();

View File

@ -1,7 +1,6 @@
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using launcher_client_win.GUI; using launcher_client_win.GUI;
using Path = DTLib.Filesystem.Path;
namespace launcher_client_win; namespace launcher_client_win;
@ -15,9 +14,17 @@ public class Program
public readonly string LaunchFile; public readonly string LaunchFile;
public readonly string LaunchArgs; public readonly string LaunchArgs;
public ProgramLabel ProgramLabel; public readonly ProgramLabel ProgramLabel;
public readonly string SettingsFile;
public readonly DtsodV23 Settings;
public readonly StackPanel SettingsPanel;
private Process ProgramProcess; private Process ProgramProcess;
public event Action<Program> ProgramSelectedEvent;
public Program(string descriptorFile) public Program(string descriptorFile)
{ {
DtsodV23 descriptor= new(File.ReadAllText(descriptorFile)); DtsodV23 descriptor= new(File.ReadAllText(descriptorFile));
@ -29,13 +36,31 @@ public class Program
string startcommand = descriptor["launchcommand"]; string startcommand = descriptor["launchcommand"];
LaunchFile = startcommand.Remove(startcommand.IndexOf(' ')); LaunchFile = startcommand.Remove(startcommand.IndexOf(' '));
LaunchArgs = startcommand.Remove(0,startcommand.IndexOf(' ')); LaunchArgs = startcommand.Remove(0,startcommand.IndexOf(' '));
ProgramLabel = new ProgramLabel(Name, IconFile);
ProgramLabel.MouseLeftButtonDown += ProgramLabel_ClickHandler; ProgramLabel = new ProgramLabel(Name, IconFile);
ProgramLabel.MouseLeftButtonDown += (_, _) => ProgramSelectedEvent?.Invoke(this);
SettingsFile = $"settings{Path.Sep}{Directory}.settings";
Settings = File.Exists(SettingsFile)
? DtsodFunctions.UpdateByDefault(
new DtsodV23(File.ReadAllText(SettingsFile)),
descriptor["default_settings"])
: descriptor["default_settings"];
File.WriteAllText(SettingsFile, Settings.ToString());
SettingsPanel = new StackPanel();
foreach (var setting in Settings)
{
ProgramSettingsPanelItem settingUi = new(setting.Key, setting.Value);
settingUi.UpdatedEvent += UpdateSetting;
SettingsPanel.Children.Add(settingUi);
}
} }
public event Action<Program> ProgramSelectedEvent; void UpdateSetting(ProgramSettingsPanelItem uiElem)
void ProgramLabel_ClickHandler(object s, MouseButtonEventArgs e) => ProgramSelectedEvent?.Invoke(this); {
Settings[uiElem.SettingKey] = uiElem.SettingValue;
File.WriteAllText(SettingsFile, Settings.ToString());
}
public void Launch() public void Launch()
{ {