Skip to content

Commit

Permalink
Merge pull request #155 from ONLOX/dev
Browse files Browse the repository at this point in the history
A Simple Launcher
  • Loading branch information
DreamEnderKing authored Mar 29, 2024
2 parents 632dd5f + 708af45 commit b240dde
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 15 deletions.
2 changes: 1 addition & 1 deletion installer/Model/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class UserInfo

public HttpClient Client = new HttpClient();
public EEsast Web; // EEsast服务器
public Logger Log; // 日志管理器
public Logger Log; // 日志管理器
public Logger LogError;
public enum UpdateStatus
{
Expand Down
2 changes: 1 addition & 1 deletion installer/Model/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public override void Dispose()
public class ExceptionStack
{
public Logger logger;
public ConcurrentStack<Exception> Exceptions;
protected ConcurrentStack<Exception> Exceptions;
protected object? Source;
public event EventHandler? OnFailed;
public event EventHandler? OnFailProcessed;
Expand Down
104 changes: 99 additions & 5 deletions installer/Page/LaunchPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,106 @@
x:Class="installer.Page.LaunchPage"
Title="Launcher">

<VerticalStackLayout>
<VerticalStackLayout
HorizontalOptions="Center">

<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="IP"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Entry
WidthRequest="400"
Placeholder=""
Text="{Binding IP}"
FontSize="16"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="Port"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Entry
WidthRequest="400"
Placeholder=""
Text="{Binding Port}"
FontSize="16"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="Player ID"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Entry
WidthRequest="400"
Placeholder=""
Text="{Binding PlayerID}"
FontSize="16"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="Team ID"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Entry
WidthRequest="400"
Placeholder=""
Text="{Binding TeamID}"
FontSize="16"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="Sweeper Type"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Entry
WidthRequest="400"
Placeholder=""
Text="{Binding SweeperType}"
FontSize="16"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="Playback File"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Entry
WidthRequest="400"
Placeholder=""
Text="{Binding PlaybackFile}"
FontSize="16"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label
WidthRequest="170"
Text="Playback Speed"
VerticalOptions="Center"
FontSize="{Binding ConstFontSize}"/>
<Entry
WidthRequest="400"
Placeholder=""
Text="{Binding PlaybackSpeed}"
FontSize="16"/>
</HorizontalStackLayout>

<Label
Text="敬请期待"
VerticalOptions="Center"
HorizontalOptions="Center"
FontSize="24"/>
Text="{Binding DebugAlert}"/>

<Button
WidthRequest="400"
Text="启动"
Command="{Binding StartBtnClickedCommand}"
IsEnabled="{Binding StartEnabled}"
BackgroundColor="{Binding ConstBackgroundColor}"
FontSize="{Binding ConstFontSize}"
TextColor="{Binding ConstTextColor}"/>

</VerticalStackLayout>

</ContentPage>
7 changes: 2 additions & 5 deletions installer/ViewModel/InstallViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace installer.ViewModel
{
public class InstallViewModel : BaseViewModel
{
private readonly Model.Downloader Downloader;
private readonly Downloader Downloader;
private readonly IFolderPicker FolderPicker;
public ObservableCollection<Exception> Exceptions { get; private set; }

public InstallViewModel(IFolderPicker folderPicker, Model.Downloader downloader)
public InstallViewModel(IFolderPicker folderPicker, Downloader downloader)
{
Downloader = downloader;
FolderPicker = folderPicker;
Expand Down Expand Up @@ -132,7 +132,6 @@ public bool UpdateEnabled
}
}

// private int cnt = 1;
public void UpdateExceptions()
{
while (Downloader.Exceptions.Count > 0)
Expand All @@ -143,8 +142,6 @@ public void UpdateExceptions()
Exceptions.Add(exception);
}
}
// Exceptions.Add(new Exception($"exp {cnt}"));
// cnt ++;
}

public ICommand BrowseBtnClickedCommand { get; }
Expand Down
137 changes: 136 additions & 1 deletion installer/ViewModel/LaunchViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,150 @@
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using installer.Model;

namespace installer.ViewModel
{
public class LaunchViewModel : BaseViewModel
{
private readonly Downloader Downloader;
public LaunchViewModel(Downloader downloader)
{
Downloader = downloader;

PlaybackSpeed = Downloader.Data.Config.Commands.PlaybackSpeed.ToString();
StartEnabled = true;

StartBtnClickedCommand = new AsyncRelayCommand(StartBtnClicked);
}

private string? debugAlert;
public string? DebugAlert
{
get => debugAlert;
set
{
debugAlert = value;
OnPropertyChanged();
}
}


public string IP
{
get => Downloader.Data.Config.Commands.IP;
set
{
Downloader.Data.Config.Commands.IP = value;
OnPropertyChanged();
}
}

public string Port
{
get => Downloader.Data.Config.Commands.Port;
set
{
Downloader.Data.Config.Commands.Port = value;
OnPropertyChanged();
}
}

public string TeamID
{
get => Downloader.Data.Config.Commands.TeamID;
set
{
Downloader.Data.Config.Commands.TeamID = value;
OnPropertyChanged();
}
}

public string PlayerID
{
get => Downloader.Data.Config.Commands.PlayerID;
set
{
Downloader.Data.Config.Commands.PlayerID = value;
OnPropertyChanged();
}
}

public string SweeperType
{
get => Downloader.Data.Config.Commands.SweeperType;
set
{
Downloader.Data.Config.Commands.SweeperType = value;
OnPropertyChanged();
}
}

public string PlaybackFile
{
get => Downloader.Data.Config.Commands.PlaybackFile;
set
{
Downloader.Data.Config.Commands.PlaybackFile = value;
OnPropertyChanged();
}
}

public string? playbackSpeed;
public string? PlaybackSpeed
{
get => playbackSpeed;
set
{
playbackSpeed = value;
try
{
Downloader.Data.Config.Commands.PlaybackSpeed = Convert.ToDouble(value);
DebugAlert = null;
StartEnabled = true;
}
catch (Exception e)
{
DebugAlert = e.ToString();
StartEnabled = false;
}
OnPropertyChanged();
}
}

private bool startEnabled;
public bool StartEnabled
{
get => startEnabled;
set
{
startEnabled = value;
OnPropertyChanged();
}
}


public ICommand StartBtnClickedCommand { get; }
private async Task StartBtnClicked()
{
await Task.Run(() => Start());
}

private void Start()
{
DebugAlert = IP + " "
+ Port + " "
+ TeamID + " "
+ PlayerID + " "
+ SweeperType + " "
+ PlaybackFile + " "
+ PlaybackSpeed;
}
}
}
}
6 changes: 4 additions & 2 deletions installer/ViewModel/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using installer.Model;

namespace installer.ViewModel
{
public class LoginViewModel : BaseViewModel
{
private readonly Model.Downloader Downloader;
private readonly Downloader Downloader;

public LoginViewModel(Model.Downloader downloader)
public LoginViewModel(Downloader downloader)
{
Downloader = downloader;

LoginBtnClickedCommand = new RelayCommand(LoginBtnClicked);
}

Expand Down

0 comments on commit b240dde

Please sign in to comment.