program settings added with some new bugs
This commit is contained in:
parent
c5815c17e0
commit
93847820ce
@ -5,12 +5,11 @@
|
||||
<SolidColorBrush x:Key="MyDarkTr"
|
||||
Opacity="0.8"
|
||||
Color="#141419" />
|
||||
<SolidColorBrush x:Key="MyGray" Color="#4B4B50" />
|
||||
<SolidColorBrush x:Key="MyGray" Color="#46464B" />
|
||||
<SolidColorBrush x:Key="MyWhite" Color="#F0F0F0" />
|
||||
<SolidColorBrush x:Key="MyGreen" Color="#2CDA11" />
|
||||
<SolidColorBrush x:Key="MyOrange" Color="#D09524" />
|
||||
<SolidColorBrush x:Key="MyGreen" Color="#28C311" />
|
||||
<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}">
|
||||
@ -105,6 +104,15 @@
|
||||
</Grid>
|
||||
</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}">
|
||||
<Border Name="Border"
|
||||
Padding="0"
|
||||
@ -139,18 +147,28 @@
|
||||
Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
BorderBrush="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<Grid>
|
||||
<Border x:Name="Border_fade"
|
||||
Background="{DynamicResource MyWhite}"
|
||||
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>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter TargetName="Border" Property="Background" Value="#FF4E4E59" />
|
||||
<Setter TargetName="Border_fade" Property="Visibility" Value="Visible" />
|
||||
</Trigger>
|
||||
<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>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
@ -186,7 +204,7 @@
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Data="M 0 0 L 4 4 L 8 0 Z"
|
||||
Fill="{DynamicResource MyOrange}" />
|
||||
Fill="{DynamicResource MySelectionColor}" />
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="ToggleButton.IsMouseOver" Value="true">
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace launcher_client_win.GUI;
|
||||
|
||||
@ -17,7 +16,7 @@ public partial class App : Application
|
||||
MySoftDark = (SolidColorBrush)Resources["MyGray"];
|
||||
MyWhite = (SolidColorBrush)Resources["MyWhite"];
|
||||
MyGreen = (SolidColorBrush)Resources["MyGreen"];
|
||||
MyOrange = (SolidColorBrush)Resources["MyOrange"];
|
||||
MyOrange = (SolidColorBrush)Resources["MySelectionColor"];
|
||||
MySelectionColor = (SolidColorBrush)Resources["MySelectionColor"];
|
||||
_Main(e.Args);
|
||||
}
|
||||
|
||||
@ -44,7 +44,6 @@
|
||||
Grid.Column="0"
|
||||
Content="Library"
|
||||
FontSize="18"
|
||||
Foreground="{DynamicResource MyGreen}"
|
||||
Style="{DynamicResource MyButtonStyle}" />
|
||||
<local:TabButton x:Name="DownloadsButton"
|
||||
Grid.Column="2"
|
||||
@ -105,52 +104,38 @@
|
||||
<Button x:Name="RemoveButton"
|
||||
Width="100"
|
||||
Margin="2,0"
|
||||
Background="{DynamicResource MyRed}"
|
||||
Content="Remove"
|
||||
Foreground="{DynamicResource MyRed}"
|
||||
Style="{DynamicResource MyButtonStyle}" />
|
||||
<Button x:Name="InstallButton"
|
||||
Width="100"
|
||||
Margin="2,0"
|
||||
Content="Install"
|
||||
Foreground="{DynamicResource MyOrange}"
|
||||
Style="{DynamicResource MyButtonStyle}" />
|
||||
<Button x:Name="UpdateButton"
|
||||
Width="100"
|
||||
Margin="2,0"
|
||||
Content="Update"
|
||||
Foreground="{DynamicResource MyOrange}"
|
||||
Style="{DynamicResource MyButtonStyle}" />
|
||||
<Button x:Name="LaunchButton"
|
||||
Width="100"
|
||||
Margin="2,0"
|
||||
Background="{DynamicResource MyGreen}"
|
||||
Content="Launch"
|
||||
Foreground="{DynamicResource MyGreen}"
|
||||
Style="{DynamicResource MyButtonStyle}" />
|
||||
</StackPanel>
|
||||
<TextBox x:Name="DescriptionBox"
|
||||
Grid.Row="4"
|
||||
Background="{DynamicResource MyDarkTr}"
|
||||
FontSize="16"
|
||||
Foreground="{DynamicResource MyWhite}"
|
||||
IsReadOnly="True"
|
||||
SelectionBrush="{DynamicResource MySelectionColor}"
|
||||
Template="{DynamicResource myTextBox}"
|
||||
TextWrapping="Wrap"
|
||||
Style="{DynamicResource MyTextBoxStyle}"
|
||||
VerticalScrollBarVisibility="Auto" />
|
||||
<TextBox x:Name="ProgramLogBox"
|
||||
Grid.Row="6"
|
||||
Background="{DynamicResource MyDarkTr}"
|
||||
FontSize="16"
|
||||
Foreground="{DynamicResource MyWhite}"
|
||||
IsReadOnly="True"
|
||||
SelectionBrush="{DynamicResource MySelectionColor}"
|
||||
Template="{DynamicResource myTextBox}"
|
||||
TextWrapping="Wrap"
|
||||
Style="{DynamicResource MyTextBoxStyle}"
|
||||
VerticalScrollBarVisibility="Auto" />
|
||||
</Grid>
|
||||
<Grid Grid.Row="0" Grid.Column="4">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="90" />
|
||||
<RowDefinition Height="95" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="0">
|
||||
@ -197,13 +182,12 @@
|
||||
Content="0"
|
||||
Style="{DynamicResource MyLabelStyle}" />
|
||||
</Grid>
|
||||
<ScrollViewer Grid.Row="1"
|
||||
<ScrollViewer Name="ProgramSettingsViever"
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
VerticalContentAlignment="Top"
|
||||
Template="{DynamicResource myScrollViewer}">
|
||||
<StackPanel x:Name="ProgramSettings" />
|
||||
</ScrollViewer>
|
||||
Template="{DynamicResource myScrollViewer}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@ -230,14 +214,7 @@
|
||||
<TextBox x:Name="LogBox"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Background="{DynamicResource MyDarkTr}"
|
||||
BorderThickness="0"
|
||||
FontSize="16"
|
||||
Foreground="{DynamicResource MyWhite}"
|
||||
IsReadOnly="True"
|
||||
SelectionBrush="{DynamicResource MySelectionColor}"
|
||||
Template="{DynamicResource myTextBox}"
|
||||
TextWrapping="Wrap"
|
||||
Style="{DynamicResource MyTextBoxStyle}"
|
||||
VerticalScrollBarVisibility="Auto" />
|
||||
</Grid>
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace launcher_client_win.GUI;
|
||||
|
||||
@ -42,41 +41,14 @@ public partial class LauncherWindow : Window
|
||||
{
|
||||
if(CurrentTab!=null)
|
||||
{
|
||||
CurrentTab.Foreground = App.MyWhite;
|
||||
CurrentTab.Background = App.MyDark;
|
||||
CurrentTab.TabGrid.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
var selected = (TabButton)sender;
|
||||
selected.Foreground = App.MyGreen;
|
||||
selected.Background = App.MySelectionColor;
|
||||
selected.TabGrid.Visibility = Visibility.Visible;
|
||||
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;
|
||||
|
||||
@ -99,7 +71,7 @@ public partial class LauncherWindow : Window
|
||||
}
|
||||
|
||||
public Program DisplayingProgram;
|
||||
public void SelectProgram(Program selectedP)
|
||||
public void SelectProgram(Program selectedProg)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -110,16 +82,17 @@ public partial class LauncherWindow : Window
|
||||
}
|
||||
else ProgramGrid.Visibility = Visibility.Visible;
|
||||
|
||||
selectedP.ProgramLabel.Foreground = App.MyGreen;
|
||||
selectedP.ProgramLabel.FontWeight = FontWeights.Bold;
|
||||
selectedProg.ProgramLabel.Foreground = App.MySelectionColor;
|
||||
selectedProg.ProgramLabel.FontWeight = FontWeights.Bold;
|
||||
|
||||
NameLabel.Content = selectedP.Name;
|
||||
DescriptionBox.Text = selectedP.Description;
|
||||
NameLabel.Content = selectedProg.Name;
|
||||
DescriptionBox.Text = selectedProg.Description;
|
||||
BackgroundImage.Source =
|
||||
new BitmapImage(new Uri(
|
||||
$"{Directory.GetCurrent()}{Path.Sep}backgrounds{Path.Sep}{selectedP.BackgroundFile}",
|
||||
$"{Directory.GetCurrent()}{Path.Sep}backgrounds{Path.Sep}{selectedProg.BackgroundFile}",
|
||||
UriKind.Absolute));
|
||||
DisplayingProgram = selectedP;
|
||||
ProgramSettingsViever.Content = selectedProg.SettingsPanel;
|
||||
DisplayingProgram = selectedProg;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{ LogError("SelectProgram()",ex); }
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace launcher_client_win.GUI;
|
||||
|
||||
26
launcher-client-win/GUI/ProgramSettingsPanelItem.xaml
Normal file
26
launcher-client-win/GUI/ProgramSettingsPanelItem.xaml
Normal 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>
|
||||
36
launcher-client-win/GUI/ProgramSettingsPanelItem.xaml.cs
Normal file
36
launcher-client-win/GUI/ProgramSettingsPanelItem.xaml.cs
Normal 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;
|
||||
}
|
||||
@ -32,6 +32,7 @@ public static class Launcher
|
||||
Directory.Create("icons");
|
||||
Directory.Create("backgrounds");
|
||||
Directory.Create("installed");
|
||||
Directory.Create("settings");
|
||||
File.WriteAllText($"descriptors{Path.Sep}default.descriptor.template",
|
||||
ReadResource("launcher_client_win.Resources.default.descriptor.template"));
|
||||
CurrentLauncherWindow = new();
|
||||
|
||||
@ -20,30 +20,18 @@ public class 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))
|
||||
{
|
||||
DtsodV23 dtsod = new(File.ReadAllText(configFile));
|
||||
// заменяет дефолтные значения на пользовательские
|
||||
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();
|
||||
DtsodV23 oldConfig = new(File.ReadAllText(configFile));
|
||||
updatedConfig = DtsodFunctions.UpdateByDefault(oldConfig, updatedDefault);
|
||||
}
|
||||
else updatedConfig = updatedDefault;
|
||||
|
||||
// парсит парсит полученный дтсод в LauncherConfig
|
||||
List<object> serversD = updatedDtsod["server"];
|
||||
List<object> serversD = updatedConfig["server"];
|
||||
ServerAddresses = new Server[serversD.Count];
|
||||
ushort i = 0;
|
||||
foreach (DtsodV23 serverD in serversD)
|
||||
@ -54,8 +42,11 @@ public class LauncherConfig
|
||||
? new Server(dom, port)
|
||||
: new Server(IPAddress.Parse(serverD["ip"]), port);
|
||||
}
|
||||
|
||||
WriteToFile();
|
||||
}
|
||||
|
||||
// записывает обновлённый конфиг в файл
|
||||
public void WriteToFile()
|
||||
{
|
||||
StringBuilder b = new();
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Imaging;
|
||||
using launcher_client_win.GUI;
|
||||
using Path = DTLib.Filesystem.Path;
|
||||
|
||||
namespace launcher_client_win;
|
||||
|
||||
@ -15,9 +14,17 @@ public class Program
|
||||
public readonly string LaunchFile;
|
||||
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;
|
||||
|
||||
public event Action<Program> ProgramSelectedEvent;
|
||||
|
||||
public Program(string descriptorFile)
|
||||
{
|
||||
DtsodV23 descriptor= new(File.ReadAllText(descriptorFile));
|
||||
@ -29,13 +36,31 @@ public class Program
|
||||
string startcommand = descriptor["launchcommand"];
|
||||
LaunchFile = startcommand.Remove(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 ProgramLabel_ClickHandler(object s, MouseButtonEventArgs e) => ProgramSelectedEvent?.Invoke(this);
|
||||
void UpdateSetting(ProgramSettingsPanelItem uiElem)
|
||||
{
|
||||
Settings[uiElem.SettingKey] = uiElem.SettingValue;
|
||||
File.WriteAllText(SettingsFile, Settings.ToString());
|
||||
}
|
||||
|
||||
public void Launch()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user