Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a logout button so that a "saved profile" can be forgotten. #286

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SIT.Manager/Localization/en-US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@
<!-- CharacterSummaryView -->
<system:String x:Key="CharacterSummaryViewPlayButtonText">Play</system:String>
<system:String x:Key="CharacterSummaryViewLoginButtonText">Login</system:String>
<system:String x:Key="CharacterSummaryViewLogoutButtonText">Logout</system:String>

<!-- CreateServerDialogView -->
<system:String x:Key="CreateServerDialogViewAddTitle">Add Server</system:String>
Expand Down
1 change: 1 addition & 0 deletions SIT.Manager/Localization/ru-RU.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
<!-- CharacterSummaryView -->
<system:String x:Key="CharacterSummaryViewPlayButtonText">Играть</system:String>
<system:String x:Key="CharacterSummaryViewLoginButtonText">Войти</system:String>
<system:String x:Key="CharacterSummaryViewLogoutButtonText">Выход</system:String>

<!-- CreateServerDialogView -->
<system:String x:Key="CreateServerDialogViewAddTitle">Добавить сервер</system:String>
Expand Down
1 change: 1 addition & 0 deletions SIT.Manager/Localization/uk-UA.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@
<!-- CharacterSummaryView -->
<system:String x:Key="CharacterSummaryViewPlayButtonText">Грати</system:String>
<system:String x:Key="CharacterSummaryViewLoginButtonText">Ввійти</system:String>
<system:String x:Key="CharacterSummaryViewLogoutButtonText">Вихід</system:String>

<!-- CreateServerDialogView -->
<system:String x:Key="CreateServerDialogViewAddTitle">Додати сервер</system:String>
Expand Down
1 change: 1 addition & 0 deletions SIT.Manager/Localization/zh-CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@
<!-- CharacterSummaryView -->
<system:String x:Key="CharacterSummaryViewPlayButtonText">玩</system:String>
<system:String x:Key="CharacterSummaryViewLoginButtonText">登录</system:String>
<system:String x:Key="CharacterSummaryViewLogoutButtonText">注销</system:String>

<!-- CreateServerDialogView -->
<system:String x:Key="CreateServerDialogViewAddTitle">添加服务器</system:String>
Expand Down
1 change: 1 addition & 0 deletions SIT.Manager/Localization/zh-HK.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
<!-- CharacterSummaryView -->
<system:String x:Key="CharacterSummaryViewPlayButtonText">玩</system:String>
<system:String x:Key="CharacterSummaryViewLoginButtonText">登錄</system:String>
<system:String x:Key="CharacterSummaryViewLogoutButtonText">注销</system:String>

<!-- CreateServerDialogView -->
<system:String x:Key="CreateServerDialogViewAddTitle">添加伺服器</system:String>
Expand Down
1 change: 1 addition & 0 deletions SIT.Manager/Localization/zh-TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@
<!-- CharacterSummaryView -->
<system:String x:Key="CharacterSummaryViewPlayButtonText">玩</system:String>
<system:String x:Key="CharacterSummaryViewLoginButtonText">登入</system:String>
<system:String x:Key="CharacterSummaryViewLogoutButtonText">注销</system:String>

<!-- CreateServerDialogView -->
<system:String x:Key="CreateServerDialogViewAddTitle">添加伺服器</system:String>
Expand Down
27 changes: 27 additions & 0 deletions SIT.Manager/ViewModels/Play/CharacterSummaryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using SIT.Manager.Services.Caching;
using SIT.Manager.Views.Play;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -43,6 +45,8 @@ public partial class CharacterSummaryViewModel : ObservableRecipient

public IAsyncRelayCommand PlayCommand { get; }

public IAsyncRelayCommand LogoutCommand { get; }

public CharacterSummaryViewModel(AkiServer server,
AkiMiniProfile profile,
ILocalizationService localizationService,
Expand Down Expand Up @@ -86,6 +90,7 @@ public CharacterSummaryViewModel(AkiServer server,
Task.Run(SetSideImage);

PlayCommand = new AsyncRelayCommand(Play);
LogoutCommand = new AsyncRelayCommand(Logout);
}

private async Task SetSideImage()
Expand Down Expand Up @@ -140,11 +145,14 @@ private async Task Play()
if (success && rememberLogin)
{
_connectedServer.Characters.Add(character);

int index = _configService.Config.BookmarkedServers.FindIndex(x => x.Address == _connectedServer.Address);

if (index != -1 && !_configService.Config.BookmarkedServers[index].Characters.Any(x => x.Username == character.Username))
{
_configService.Config.BookmarkedServers[index].Characters.Add(character);
}

_configService.UpdateConfig(_configService.Config);
RequireLogin = false;
}
Expand All @@ -161,4 +169,23 @@ private async Task Play()
await errorDialog.ShowAsync();
}
}

private async Task Logout()
{
AkiCharacter? character = _connectedServer.Characters.FirstOrDefault(x => x.Username == Profile.Username);
Plootie marked this conversation as resolved.
Show resolved Hide resolved

if (character != null)
{
_connectedServer.Characters.Remove(character);

int index = _configService.Config.BookmarkedServers.FindIndex(x => x.Address == _connectedServer.Address);

if (index != -1 && !_configService.Config.BookmarkedServers[index].Characters.Any(x => x.Username == character.Username))
{
_configService.Config.BookmarkedServers[index].Characters.Remove(character);
}
Plootie marked this conversation as resolved.
Show resolved Hide resolved
_configService.UpdateConfig(_configService.Config);
RequireLogin = true;
}
}
}
11 changes: 10 additions & 1 deletion SIT.Manager/Views/Play/CharacterSummaryView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
x:Class="SIT.Manager.Views.Play.CharacterSummaryView"
x:DataType="vm:CharacterSummaryViewModel">
<controls:Card Margin="8">
<Grid ColumnDefinitions="Auto, *, Auto">
<Grid ColumnDefinitions="Auto, *, Auto, Auto">
<StackPanel Grid.Column="0">
<Image Grid.Column="0"
VerticalAlignment="Center"
Expand Down Expand Up @@ -61,6 +61,15 @@
Text="{DynamicResource CharacterSummaryViewLoginButtonText}"/>
</Panel>
</Button>

<Button Grid.Column="3"
Margin="14,0"
Command="{Binding LogoutCommand}"
IsVisible="{Binding !RequireLogin}">
<Panel>
<TextBlock Text="{DynamicResource CharacterSummaryViewLogoutButtonText}"/>
</Panel>
</Button>
</Grid>
</controls:Card>
</UserControl>