Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
清理屎山 修复bug Fix#65
Browse files Browse the repository at this point in the history
  • Loading branch information
JWJUN233233 committed Apr 4, 2023
1 parent dbf1893 commit 953f62b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 36 deletions.
2 changes: 1 addition & 1 deletion WonderLab/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public async void AppRunAnimaction()
{
await Task.Run(() =>
{
UsersView.ViewModel.GetSaveUserInfo();
UsersView.ViewModel.GetSavedUserInfo();
});
await Task.Delay(2500);
cover.Opacity= 0;
Expand Down
4 changes: 2 additions & 2 deletions WonderLab/Modules/Models/UserViewDataModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public UserModels(UserDataModels user)
}

public UserModels Current => this;

public string Name { get; set; }
public string _Name;
public string Name { get => _Name; set => _Name = value; }

public string Jvm { get; set; }

Expand Down
27 changes: 11 additions & 16 deletions WonderLab/ViewModels/UsersViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DynamicData;
using FluentAvalonia.UI.Controls;
using MinecaftOAuth.Authenticator;
using System;
Expand All @@ -19,6 +20,7 @@ namespace WonderLab.ViewModels
//Binding
public partial class UsersViewModel : ViewModelBase
{
public string UserNameText { get => _UserNameText; set => RaiseAndSetIfChanged(ref _UserNameText, value); }
public string SelectedAuthenticator { get => _SelectedAuthenticator; set => RaiseAndSetIfChanged(ref _SelectedAuthenticator, value); }

public string UrlTextBoxText { get => _UrlTextBoxText; set => RaiseAndSetIfChanged(ref _UrlTextBoxText, value); }
Expand Down Expand Up @@ -57,10 +59,10 @@ public partial class UsersViewModel : ViewModelBase
//Methods
partial class UsersViewModel
{
//public UsersViewModel() => GetSaveUserInfo();

public async ValueTask AuthAsync()
{
TextBoxText = string.Empty;
FirstBoxVisibility = false;
PasswordBoxVisibility = false;
TextBoxVisibility = false;
Expand Down Expand Up @@ -174,10 +176,11 @@ public async void FindllyAuth()
UserType = "离线账户"
};
App.Data.UserList.Add(user);
Users.Add(new(user));
MainWindow.ShowInfoBarAsync("添加账户成功:", $"{user.UserType} {user.UserName} 欢迎回来,{user.UserName}", InfoBarSeverity.Success);
UsersView.CloseDialog();
}
GetSaveUserInfo();
JsonToolkit.JsonAllWrite();
StringsRefresh();
}

Expand All @@ -192,22 +195,13 @@ public void StringsRefresh()
DeviceTips = "";
}

public void GetSaveUserInfo()
public void GetSavedUserInfo()
{
BackgroundWorker worker = new();
worker.DoWork += (_, _) =>
JsonToolkit.JsonAllWrite();
App.Data.UserList.ForEach((x) =>
{
App.Data.UserList.ForEach(async x =>
{
await Task.Run(async () =>
{
Users.Add(new(x));
await Task.Delay(1000);
});
});
};

worker.RunWorkerAsync();
Users.Add(new(x));
});
//CurrentUser = Users.GetUserInIndex(App.Data.SelectedUser.UserName);
}

Expand All @@ -225,6 +219,7 @@ partial class UsersViewModel
public bool _PasswordBoxVisibility = false;
public bool _ProgressBarVisibility = false;
public bool _FirstBoxVisibility = false;
public string _UserNameText = string.Empty;
public string _SelectedAuthenticator = "微软验证";
public string _UrlTextBoxText = string.Empty;
public string _TextBoxText = string.Empty;
Expand Down
13 changes: 8 additions & 5 deletions WonderLab/Views/UsersView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
Command="{Binding CopyCodeAsync}"
Classes="accent" Content="将代码复制至剪贴板"/>
<Button Command="{Binding StringsRefresh}"
Width="75" Click="CancelButtonClick1"
Width="75" Click="CancelButtonClick2"
Margin="15,0,0,0">
<TextBlock Text="取消" />
</Button>
Expand All @@ -132,7 +132,7 @@
VerticalAlignment="Center"
FontSize="18"
FontWeight="Bold"
Text="Starcloudsea 的账户信息" />
x:Name="UserInfoTitle" />

<Grid HorizontalAlignment="Stretch" Margin="0 10 0 0" Grid.Row="1">
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -187,14 +187,14 @@
<Grid HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="2">

<StackPanel Margin="0 0 0 10" Spacing="10" Width="350">
<TextBox HorizontalAlignment="Stretch" Watermark="请输入您的游戏名"/>
<TextBox x:Name="NameInputTextBox" HorizontalAlignment="Stretch" Watermark="请输入您的游戏名"/>

<DockPanel Width="350">
<Button DockPanel.Dock="Right" Width="40" VerticalAlignment="Stretch" HorizontalAlignment="Left" Classes="accent">
<ui:SymbolIcon Symbol="Add"/>
</Button>

<TextBox DockPanel.Dock="Left" Margin="0 0 10 0" Width="300" Watermark="请输入您的角色皮肤路径"/>
<TextBox x:Name="SkinFilePath" DockPanel.Dock="Left" Margin="0 0 10 0" Width="300" Watermark="请输入您的角色皮肤路径"/>
</DockPanel>

</StackPanel>
Expand All @@ -206,12 +206,15 @@
Orientation="Horizontal">

<Button
Width="100" Click="CancelButtonClick1"
x:Name="DeleteButton"
Width="100" Click="DeleteButtonClick"
Margin="0,0,15,0" Background="Red">
<TextBlock Text="删除此档案" />
</Button>

<Button Width="75"
x:Name="SaveButton"
Click="SaveButtonClick"
Classes="accent" IsVisible="{Binding TextBoxVisibility}"
Foreground="White">
<TextBlock Text="确定" />
Expand Down
45 changes: 33 additions & 12 deletions WonderLab/Views/UsersView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Threading;
using FluentAvalonia.UI.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -56,7 +57,10 @@ public static void CloseDialog()
private async void ShowUserInfoDialogClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e) {
var Skin = ((sender as Button)!.DataContext as UserModels)!.SkinBytes;
var Data = ((sender as Button)!.DataContext as UserModels)!;

ViewModel.UserNameText = string.Format("{0} 的账户信息", Data.Name);
UserInfoTitle.Text = ViewModel.UserNameText;
DeleteButton.DataContext = Data;
SaveButton.DataContext = Data;
try
{
if (Data.Type.Contains("微软"))
Expand Down Expand Up @@ -99,26 +103,43 @@ private async void ShowUserInfoDialogClick(object? sender, Avalonia.Interactivit

private void CancelButtonClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e) => AuthenticatorTypeDialog.Hide();

private void CancelButtonClick1(object? sender, Avalonia.Interactivity.RoutedEventArgs e) => LoginDialog.Hide();
private void CancelButtonClick1(object? sender, Avalonia.Interactivity.RoutedEventArgs e) => UserInfoDialog.Hide();
private void CancelButtonClick2(object? sender, Avalonia.Interactivity.RoutedEventArgs e) => LoginDialog.Hide();

private void DeleteButtonClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var user = (UserModels)(sender as Button).DataContext!;

App.Data.UserList.RemoveAll((x) => x.UserUuid == user.Uuid && x.UserName == user.Name && x.UserType == user.Type);

List<UserModels> tmp = new(ViewModel.Users);
tmp.RemoveAll((x) => x.Uuid == user.Uuid && x.Name == user.Name && x.Type == user.Type);
ViewModel.Users = new(tmp);
if (App.Data.SelectedUser is not null && App.Data.SelectedUser.UserName.Equals(user.Name) && App.Data.SelectedUser.UserUuid.Equals(user.Uuid))
App.Data.SelectedUser = null;
JsonToolkit.JsonAllWrite();
UserInfoDialog.Hide();
MainWindow.ShowInfoBarAsync("成功:",$"账户 {user.Name} 已成功被移除!", InfoBarSeverity.Success);
}
private void SaveButtonClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var user = (UserModels)(sender as Button).DataContext!;

for (int i = 0; i < App.Data.UserList.Count; i++)
List<UserModels> tmp = new(ViewModel.Users);
tmp.RemoveAll((x) => x.Uuid == user.Uuid && x.Name == user.Name && x.Type == user.Type);
ViewModel.Users = new(tmp);
if (NameInputTextBox.Text != null)
{
if (ViewModel.Users[i].Name == App.Data.UserList[i].UserName && ViewModel.Users[i].Uuid == App.Data.UserList[i].UserUuid)
App.Data.UserList.Remove(App.Data.UserList[i]);
user.Name = NameInputTextBox.Text;
}
ViewModel.Users.Add(user);
App.Data.UserList.Find((x)=> {
return x.UserName == user.Name && x.UserUuid == user.Uuid && x.UserType == user.Type;

ViewModel.Users.Remove(user.Current);
var temp = ViewModel.Users;
ViewModel.Users = null;
ViewModel.Users = new(temp);
if (App.Data.SelectedUser is not null && App.Data.SelectedUser.UserName.Equals(user.Name) && App.Data.SelectedUser.UserUuid.Equals(user.Uuid))
App.Data.SelectedUser = null;
}).UserName = user.Name;

MainWindow.ShowInfoBarAsync("成功:",$"账户 {user.Name} 已成功被移除!", InfoBarSeverity.Success);
JsonToolkit.JsonAllWrite();
UserInfoDialog.Hide();
}

private async void UserSettingOpenPointerPressed(object? sender, Avalonia.Input.PointerPressedEventArgs e)
Expand Down

0 comments on commit 953f62b

Please sign in to comment.