Skip to content

Commit 59f8f57

Browse files
committed
MV Auth: Avoid creating multiple keys because it would be confusing / cvar multiaccount behavior properly
1 parent 8f9a69e commit 59f8f57

9 files changed

+160
-17
lines changed

SS14.Launcher/Models/Data/CVars.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ public static readonly CVarDef<bool> HasDismissedEarlyAccessWarning
7373

7474
/// <summary>
7575
/// Enable multi-account support on release builds.
76+
/// This works different from upstream, since SSMV supports multiple providers by default. But multiple accounts
77+
/// per-provider is a debug feature to help prevent new user confusion / mixing up keys.
7678
/// </summary>
77-
public static readonly CVarDef<bool> MultiAccounts = CVarDef.Create("MultiAccounts", false);
79+
public static readonly CVarDef<bool> MultiAccountsPerProvider = CVarDef.Create("MultiAccountsPerProvider", false);
7880

7981
/// <summary>
8082
/// Currently selected login in the drop down.

SS14.Launcher/Models/Data/DataManager.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,12 @@ public string? Locale
222222
public ICollection<ServerFilter> Filters { get; }
223223
public ICollection<Hub> Hubs { get; }
224224

225-
public bool ActuallyMultiAccounts => true;
225+
public bool MultiAccountsPerProvider => GetCVar(CVars.MultiAccountsPerProvider);
226226
/*
227-
I should probably change this to be a default on but cvar'able off, I guess.
228-
But just doing this quick for now.
229227
#if DEBUG
230228
true;
231229
#else
232-
GetCVar(CVars.MultiAccounts);
230+
GetCVar(CVars.MultiAccountsPerProvider);
233231
#endif
234232
*/
235233

SS14.Launcher/Models/Logins/LoginManager.cs

+11
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,15 @@ public void SetStatus(AccountLoginStatus status)
237237
Log.Debug("Setting status for login {account} to {status}", LoginInfo, status);
238238
}
239239
}
240+
241+
public bool HasAccountOfType(Type type)
242+
{
243+
foreach (var account in Logins.Items)
244+
{
245+
if (account != null && account.LoginInfo?.GetType() == type)
246+
return true;
247+
}
248+
249+
return false;
250+
}
240251
}

SS14.Launcher/ViewModels/AccountDropDownViewModel.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class AccountDropDownViewModel : ViewModelBase
3030

3131
public ReadOnlyObservableCollection<AvailableAccountViewModel> Accounts => _accounts;
3232

33-
public bool EnableMultiAccounts => _cfg.ActuallyMultiAccounts;
3433
public Control? Control { get; set; }
3534

3635
public AccountDropDownViewModel(MainWindowViewModel mainVm)
@@ -86,7 +85,7 @@ public string LoginText
8685
{
8786
return _loginMgr.ActiveAccount.Username + " [" + _loginMgr.ActiveAccount.LoginInfo.LoginTypeDisplaySuffix + "]";
8887
} else {
89-
return EnableMultiAccounts ? Loc.GetString("No account selected") : Loc.GetString("Not logged in");
88+
return Loc.GetString("No account selected");
9089
}
9190
}
9291
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using CodeHollow.FeedReader;
5+
using ReactiveUI;
6+
using SS14.Launcher.Localization;
7+
8+
namespace SS14.Launcher.ViewModels.IdentityTabs;
9+
10+
public class AlreadyMadeTabViewModel : IdentityTabViewModel
11+
{
12+
public AlreadyMadeTabViewModel(string name, IdentityTabViewModel replacementFor)
13+
{
14+
this._name = name;
15+
this.ReplacementFor = replacementFor;
16+
}
17+
18+
public override void Selected()
19+
{
20+
base.Selected();
21+
}
22+
23+
public override string Name
24+
{
25+
get
26+
{
27+
return _name;
28+
}
29+
}
30+
private string _name;
31+
32+
public string WelcomeText
33+
{
34+
get
35+
{
36+
return Loc.GetString(@"You've already made an account of this type. Select it at the top right.");
37+
}
38+
}
39+
40+
/// <summary>
41+
/// What normal tab is this stub tab replacing?
42+
/// </summary>
43+
public IdentityTabViewModel ReplacementFor { get; set; }
44+
45+
}

SS14.Launcher/ViewModels/MainWindowIdentityViewModel.cs

+65-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
using System.Collections.Generic;
22
using ReactiveUI;
3+
using ReactiveUI.Fody.Helpers;
34
using Splat;
45
using SS14.Launcher.Api;
56
using SS14.Launcher.Models.Data;
67
using SS14.Launcher.Models.Logins;
78
using SS14.Launcher.Utility;
89
using SS14.Launcher.ViewModels.IdentityTabs;
910
using SS14.Launcher.ViewModels.Login;
11+
using System;
12+
using System.Collections.ObjectModel;
13+
using System.Diagnostics.CodeAnalysis;
14+
using System.Reactive.Linq;
15+
using Avalonia.Controls;
16+
using Avalonia.VisualTree;
17+
using DynamicData;
18+
using JetBrains.Annotations;
19+
using SS14.Launcher.Localization;
20+
using SS14.Launcher.Views;
1021

1122
namespace SS14.Launcher.ViewModels;
1223

1324
public class MainWindowIdentityViewModel : ViewModelBase
1425
{
1526
private readonly DataManager _cfg;
27+
private readonly LoginManager _loginManager;
1628

1729
// Identity Tabs
1830
public InformationTabViewModel InformationTab { get; }
@@ -21,13 +33,14 @@ public class MainWindowIdentityViewModel : ViewModelBase
2133
public GuestTabViewModel GuestTab { get; }
2234
public LoginTabViewModel WizardsDenLoginTab { get; }
2335

24-
public IReadOnlyList<IdentityTabViewModel> IdentityTabs { get; }
36+
public ObservableCollection<IdentityTabViewModel> IdentityTabs { get; set; } = new ObservableCollection<IdentityTabViewModel>();
2537

2638
public LanguageDropDownViewModel LanguageDropDown { get; }
2739

2840
public MainWindowIdentityViewModel()
2941
{
3042
_cfg = Locator.Current.GetRequiredService<DataManager>();
43+
_loginManager = Locator.Current.GetRequiredService<LoginManager>();
3144

3245
// Identity Tabs
3346

@@ -37,16 +50,59 @@ public MainWindowIdentityViewModel()
3750
GuestTab = new GuestTabViewModel();
3851
WizardsDenLoginTab = new LoginTabViewModel();
3952

40-
IdentityTabs = new IdentityTabViewModel[]
41-
{
42-
InformationTab,
43-
KeyNewTab,
44-
KeyImportTab,
45-
GuestTab,
46-
WizardsDenLoginTab
47-
};
53+
IdentityTabs.Add(InformationTab);
54+
IdentityTabs.Add(KeyNewTab);
55+
IdentityTabs.Add(KeyImportTab);
56+
IdentityTabs.Add(GuestTab);
57+
IdentityTabs.Add(WizardsDenLoginTab);
4858

4959
LanguageDropDown = new LanguageDropDownViewModel();
60+
61+
_loginManager.Logins.Connect()
62+
.DistinctUntilChanged()
63+
.ObserveOn(RxApp.MainThreadScheduler)
64+
.Subscribe(
65+
_ => // Check the data after list modification actions are completed
66+
{
67+
if (!_cfg.MultiAccountsPerProvider) // Respect multi-account setting
68+
{
69+
// Replace tabs as needed
70+
ReplaceOrUnreplaceTabInListBasedOnAccountExisting(KeyNewTab, typeof(LoginInfoKey));
71+
ReplaceOrUnreplaceTabInListBasedOnAccountExisting(WizardsDenLoginTab, typeof(LoginInfoAccount)); // TODO: Properly support one account PER provider, instead of globally
72+
}
73+
});
74+
}
75+
76+
private void ReplaceOrUnreplaceTabInListBasedOnAccountExisting(IdentityTabViewModel identityTabViewModel, Type accountType)
77+
{
78+
if (_loginManager.HasAccountOfType(accountType))
79+
{
80+
// Already has it, so remove from list if it is in there
81+
for (int i=0; i<IdentityTabs.Count; i++)
82+
{
83+
if (IdentityTabs[i] == identityTabViewModel)
84+
{
85+
// IdentityTabs[i] = new AlreadyMadeTabViewModel(IdentityTabs[i].Name);
86+
// (^ This syntax won't update UI)
87+
IdentityTabs.Replace(IdentityTabs[i],
88+
new AlreadyMadeTabViewModel(IdentityTabs[i].Name, IdentityTabs[i]));
89+
return;
90+
}
91+
}
92+
} else {
93+
// Doesn't already have, so revert the replacement if necessary
94+
for (int i=0; i<IdentityTabs.Count; i++)
95+
{
96+
if (IdentityTabs[i] is AlreadyMadeTabViewModel alreadyMadeTabViewModel &&
97+
alreadyMadeTabViewModel.ReplacementFor == identityTabViewModel)
98+
{
99+
//IdentityTabs[i] = identityTabViewModel;
100+
// (^ This syntax won't update UI)
101+
IdentityTabs.Replace(IdentityTabs[i], identityTabViewModel);
102+
return;
103+
}
104+
}
105+
}
50106
}
51107

52108
public string Version => $"v{LauncherVersion.Version}";

SS14.Launcher/Views/AccountDropDown.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<StackPanel Orientation="Vertical" IsVisible="{Binding AccountControlsVisible}">
2020
<Button Content="{Binding ConfigureText}" Command="{Binding ConfigurePressed}" Margin="4" IsVisible="{Binding ConfigureButtonVisible}" />
2121
<Button Content="{Binding LogoutText}" Command="{Binding LogoutPressed}" Margin="4" IsVisible="{Binding LogoutButtonVisible}" />
22-
<Button Content="{loc:Get Add account}" IsVisible="{Binding EnableMultiAccounts}" Command="{Binding AddAccountPressed}" Margin="4" />
22+
<Button Content="{loc:Get Add account}" Command="{Binding AddAccountPressed}" Margin="4" />
2323
</StackPanel>
2424

2525
<StackPanel Orientation="Vertical" IsVisible="{Binding AccountSwitchVisible}">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Avalonia.Controls;
2+
using Avalonia.Markup.Xaml;
3+
4+
namespace SS14.Launcher.Views.IdentityTabs;
5+
6+
public partial class AlreadyMadeTabView : UserControl
7+
{
8+
public AlreadyMadeTabView()
9+
{
10+
InitializeComponent();
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
xmlns:vm="clr-namespace:SS14.Launcher.ViewModels;assembly=SS14.Launcher"
6+
xmlns:identityTabs="clr-namespace:SS14.Launcher.ViewModels.IdentityTabs"
7+
xmlns:loc="clr-namespace:SS14.Launcher.Localization.Xaml"
8+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
9+
x:Class="SS14.Launcher.Views.IdentityTabs.AlreadyMadeTabView"
10+
Name="AlreadyMadeTab">
11+
<Design.DataContext>
12+
<identityTabs:AlreadyMadeTabViewModel />
13+
</Design.DataContext>
14+
15+
<DockPanel>
16+
<Panel Background="{DynamicResource StripeBackBrush}">
17+
<TextBlock TextWrapping="Wrap" Margin="4, 4" Text="{Binding WelcomeText}"></TextBlock>
18+
</Panel>
19+
</DockPanel>
20+
</UserControl>

0 commit comments

Comments
 (0)