Skip to content

Commit 07e46f3

Browse files
foglio1024alexrp
authored andcommitted
add logic for main content switching
1 parent 35ed793 commit 07e46f3

12 files changed

+165
-54
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Arise.Client.Launcher.Controllers;
2+
3+
public sealed class DefaultController : LauncherController
4+
{
5+
public DefaultController(IServiceProvider services)
6+
: base(services)
7+
{
8+
}
9+
}

src/client/Launcher/Controllers/MainController.cs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Arise.Client.Gateway;
33
using Arise.Client.Launcher.Media;
44
using Arise.Client.Launcher.Settings;
5-
using Avalonia.Data;
65

76
namespace Arise.Client.Launcher.Controllers;
87

@@ -16,7 +15,7 @@ public sealed class MainController : LauncherController
1615
private string _password = string.Empty;
1716
private bool _rememberMe;
1817
private bool _isModalVisible;
19-
private string _serverAddress;
18+
private ReactiveObject _currentContent;
2019

2120
public bool IsLoggedIn
2221
{
@@ -54,22 +53,10 @@ public bool IsModalVisible
5453
set => this.RaiseAndSetIfChanged(ref _isModalVisible, value);
5554
}
5655

57-
public string ServerAddress
56+
public ReactiveObject CurrentContent
5857
{
59-
get => _serverAddress;
60-
set
61-
{
62-
try
63-
{
64-
var svc = Services.GetService<GatewayClient>()!;
65-
svc.BaseAddress = new Uri(value);
66-
_ = this.RaiseAndSetIfChanged(ref _serverAddress, value);
67-
}
68-
catch (Exception ex)
69-
{
70-
throw new DataValidationException($"{ex.Message}");
71-
}
72-
}
58+
get => _currentContent;
59+
set => this.RaiseAndSetIfChanged(ref _currentContent, value);
7360
}
7461

7562
public ICommand LoginCommand { get; }
@@ -82,25 +69,31 @@ public string ServerAddress
8269

8370
public ICommand CloseModalCommand { get; }
8471

72+
public ICommand OpenSettingsCommand { get; }
73+
8574
private readonly MusicPlayer _musicPlayer;
8675

8776
public MainController(IServiceProvider services, MusicPlayer musicPlayer, LauncherSettingsManager launcherSettingsManager)
8877
: base(services)
8978
{
9079
_musicPlayer = musicPlayer;
91-
80+
_currentContent = new DefaultController(services);
9281
_launcherSettingsManager = launcherSettingsManager;
9382

9483
_gatewayClient = Services.GetService<GatewayClient>()!; // todo: inject this? it requires GatewayClient to be public tho
9584
_gatewayClient.BaseAddress = _launcherSettingsManager.Settings.ServerAddress;
9685

97-
_serverAddress = _launcherSettingsManager.Settings.ServerAddress?.ToString() ?? string.Empty;
98-
9986
LoginCommand = ReactiveCommand.Create(LoginAsync);
10087
RecoverPasswordCommand = ReactiveCommand.Create(RecoverPassword);
10188
RegisterCommand = ReactiveCommand.Create(Register);
10289
ShowAccountPopupCommand = ReactiveCommand.Create(ShowAccountPopup);
10390
CloseModalCommand = ReactiveCommand.Create(CloseModal);
91+
OpenSettingsCommand = ReactiveCommand.Create(OpenSettings);
92+
}
93+
94+
private void OpenSettings()
95+
{
96+
CurrentContent = new SettingsController(Services, _launcherSettingsManager);
10497
}
10598

10699
private void CloseModal()
@@ -151,11 +144,14 @@ private async Task LoginAsync()
151144

152145
if (!IsLoggedIn)
153146
{
147+
var client = Services.GetService<GatewayClient>()
148+
?? throw new InvalidOperationException("GatewayClient service not found"); // todo: idk how we should handle this case, if even possible
149+
154150
// todo: catch something?
155151

156152
try
157153
{
158-
var resp = await _gatewayClient.Rest.AuthenticateAccountAsync(Username, Password).ConfigureAwait(true);
154+
var resp = await client.Rest.AuthenticateAccountAsync(Username, Password).ConfigureAwait(true);
159155

160156
if (resp.IsSuccessStatusCode)
161157
{
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Windows.Input;
2+
using Arise.Client.Launcher.Settings;
3+
using Avalonia.Data;
4+
5+
namespace Arise.Client.Launcher.Controllers;
6+
7+
public sealed class SettingsController : LauncherController
8+
{
9+
private readonly LauncherSettingsManager _settingsManager;
10+
private string _serverAddress = string.Empty;
11+
12+
public ICommand ApplyCommand { get; }
13+
14+
public ICommand CancelCommand { get; }
15+
16+
public string ServerAddress
17+
{
18+
get => _serverAddress;
19+
set
20+
{
21+
try
22+
{
23+
using var mockClient = new HttpClient();
24+
mockClient.BaseAddress = new Uri(value);
25+
_ = this.RaiseAndSetIfChanged(ref _serverAddress, value);
26+
}
27+
catch (Exception ex)
28+
{
29+
throw new DataValidationException($"{ex.Message}");
30+
}
31+
}
32+
}
33+
34+
public SettingsController(IServiceProvider services, LauncherSettingsManager launcherSettingsManager)
35+
: base(services)
36+
{
37+
_settingsManager = launcherSettingsManager;
38+
_serverAddress = _settingsManager.Settings.ServerAddress?.ToString() ?? string.Empty;
39+
40+
ApplyCommand = ReactiveCommand.Create(Apply);
41+
CancelCommand = ReactiveCommand.Create(Cancel);
42+
}
43+
44+
private void Cancel()
45+
{
46+
// todo: return without updating the settings
47+
}
48+
49+
private void Apply()
50+
{
51+
// todo: commit changes to the manager
52+
53+
_settingsManager.Save();
54+
}
55+
}

src/client/Launcher/LauncherApplication.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</ResourceDictionary.ThemeDictionaries>
3030
</ResourceDictionary>
3131
<!--9A2B70,76024F,6E014B,D764A1,412831 palette from arise logo-->
32-
<SolidColorBrush x:Key="AccentBrush" Color="#9A2B70"/>
32+
<SolidColorBrush x:Key="AccentBrush" Color="#CC3391"/>
3333

3434
<!--not working; figure it out later-->
3535
<!--<FontFamily x:Key="Quicksand">avares://Fonts#Quicksand Light</FontFamily>-->

src/client/Launcher/LauncherApplication.axaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public override void OnFrameworkInitializationCompleted()
3030
return;
3131

3232
DataTemplates.Add(new WindowLocatorDataTemplate(_services));
33+
DataTemplates.Add(new MainContentLocator());
3334

3435
var hostLifetime = _services.GetRequiredService<IHostApplicationLifetime>();
3536
var avaloniaLifetime = Unsafe.As<IClassicDesktopStyleApplicationLifetime>(ApplicationLifetime!);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Arise.Client.Launcher.Controllers;
2+
3+
namespace Arise.Client.Launcher.Templates;
4+
5+
internal sealed class MainContentLocator : IDataTemplate
6+
{
7+
public Control? Build(object? data)
8+
{
9+
if (data == null)
10+
return null;
11+
12+
var name = data.GetType().FullName!.Replace("Controller", "View", StringComparison.Ordinal);
13+
var type = Type.GetType(name);
14+
15+
return type != null
16+
? (Control)Activator.CreateInstance(type)!
17+
: new TextBlock { Text = "Not Found: " + name };
18+
}
19+
20+
public bool Match(object? data)
21+
{
22+
return data is LauncherController;
23+
}
24+
}

src/client/Launcher/Templates/WindowLocatorDataTemplate.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public WindowLocatorDataTemplate(IServiceProvider services)
1818

1919
public bool Match(object? data)
2020
{
21-
return data is LauncherController;
21+
return data is LauncherController
22+
&& data!.GetType().FullName!.Contains("Window", StringComparison.Ordinal);
2223
}
2324

2425
public Control Build(object? param)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
6+
x:Class="Arise.Client.Launcher.Views.DefaultView">
7+
main content goes here
8+
</UserControl>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Arise.Client.Launcher.Views;
2+
3+
public partial class DefaultView : UserControl
4+
{
5+
public DefaultView()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
6+
x:Class="Arise.Client.Launcher.Views.SettingsView"
7+
xmlns:controllers="using:Arise.Client.Launcher.Controllers"
8+
x:DataType="controllers:SettingsController">
9+
<!--this should only be visible in dev builds-->
10+
<TextBox Text="{Binding ServerAddress, Mode=TwoWay}"
11+
Grid.Row="1"
12+
VerticalAlignment="Top"
13+
Watermark="Server address"
14+
/>
15+
</UserControl>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Arise.Client.Launcher.Views;
2+
3+
public partial class SettingsView : UserControl
4+
{
5+
public SettingsView()
6+
{
7+
InitializeComponent();
8+
}
9+
}

src/client/Launcher/Windows/MainWindow.axaml

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Style Selector="#CloseButton:pressed /template/ ContentPresenter">
1818
<Setter Property="Background" Value="{DynamicResource CloseButtonPressedBackground}" />
1919
</Style>
20-
<!--this is slow on first display (even without transition)
20+
<!--todo: this is slow on first display (even without transition)
2121
need to figure out a way to fix it; maybe render
2222
the form outside of the window (or under the background image)
2323
as soon as the window is loaded, then hide it and bring it
@@ -45,6 +45,7 @@
4545
<Setter Property="Background" Value="{DynamicResource DefaultButtonBackground}" />
4646
<Setter Property="CornerRadius" Value="8" />
4747
<Setter Property="Height" Value="24" />
48+
<Setter Property="Width" Value="24" />
4849
</Style>
4950
</Grid.Styles>
5051

@@ -68,13 +69,14 @@
6869

6970
<StackPanel Orientation="Horizontal"
7071
Grid.Column="1"
71-
HorizontalAlignment="Right">
72+
HorizontalAlignment="Right"
73+
Spacing="6">
7274

7375
<Button x:Name="AccountButton"
7476
FontSize="10"
75-
Margin="0 0 6 0"
7677
Padding="6 0"
7778
Command="{Binding ShowAccountPopupCommand}"
79+
Width="NaN"
7880
>
7981
<StackPanel Orientation="Horizontal">
8082
<avalonia:MaterialIcon Kind="Account"
@@ -85,16 +87,15 @@
8587
</StackPanel>
8688
</Button>
8789

88-
<Button x:Name="MinimizeButton"
89-
Width="24"
90-
Click="OnMinimizeClick">
90+
<Button x:Name="SettingsButton" Command="{Binding OpenSettingsCommand}">
91+
<avalonia:MaterialIcon Kind="Settings" />
92+
</Button>
93+
94+
<Button x:Name="MinimizeButton" Click="OnMinimizeClick">
9195
<avalonia:MaterialIcon Kind="WindowMinimize" />
9296
</Button>
9397

94-
<Button x:Name="CloseButton"
95-
Width="24"
96-
Margin="6 0 0 0"
97-
Click="OnCloseClick">
98+
<Button x:Name="CloseButton" Click="OnCloseClick">
9899
<avalonia:MaterialIcon Kind="Close" />
99100
</Button>
100101

@@ -105,33 +106,16 @@
105106
IsHitTestVisible="False"
106107
Grid.Row="1" />
107108

108-
<controls:AcrylicBorder
109-
Width="300"
110-
Height="200"
111-
Grid.Row="1"
112-
BoxShadow="0 10 15 0 #6000"
113-
>
114-
<controls:AcrylicBorder.Transitions>
115-
<Transitions>
116-
<CornerRadiusTransition Property="CornerRadius" Duration="0:0:0.50"/>
117-
</Transitions>
118-
</controls:AcrylicBorder.Transitions>
119-
</controls:AcrylicBorder>
120-
121109
<!--<Image Source="../../image_logo.webp"
122110
IsHitTestVisible="False"
123111
Stretch="Uniform"
124112
Width="280"
125113
Grid.Row="1" />-->
126114

127-
<!--this should only be visible in dev builds
128-
(also move it to settings later)-->
129-
<TextBox Text="{Binding ServerAddress, Mode=TwoWay}"
130-
Grid.Row="1"
131-
VerticalAlignment="Top"
132-
Watermark="Server address"
133-
/>
134-
115+
<ContentControl
116+
Content="{Binding CurrentContent}"
117+
Grid.Row="1"/>
118+
135119
<Border x:Name="ModalDarkening"
136120
Background="#5000"
137121
Grid.RowSpan="2"

0 commit comments

Comments
 (0)