Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 12 additions & 8 deletions Link/Lobby/LobbyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using PCL.Core.UI;
using static PCL.Core.Link.Lobby.LobbyInfoProvider;
using static PCL.Core.Link.Natayark.NatayarkProfileManager;
using LobbyType = PCL.Core.Link.Scaffolding.Client.Models.LobbyType;
Expand Down Expand Up @@ -44,7 +45,7 @@ public sealed class LobbyController
/// <summary>
/// Launch a Scaffolding Client.
/// </summary>
/// <param name="username">Join user name.</param>
/// <param name="username">Join username.</param>
/// <param name="code">Lobby share code.</param>
/// <returns>Created <see cref="ScaffoldingClientEntity"/>.</returns>
public async Task<ScaffoldingClientEntity?> LaunchClientAsync(string username, string code)
Expand Down Expand Up @@ -74,11 +75,10 @@ public sealed class LobbyController

foreach (var profile in scfEntity.Client.PlayerList)
{
if (profile.Kind == PlayerKind.HOST)
{
hostname = profile.Name;
LogWrapper.Debug($"大厅创建者的用户名: {hostname}");
}
if (profile.Kind != PlayerKind.HOST) continue;

hostname = profile.Name;
LogWrapper.Debug($"大厅创建者的用户名: {hostname}");
}

var localPort = await scfEntity.EasyTier.AddPortForwardAsync(scfEntity.HostInfo.Ip, port)
Expand All @@ -96,20 +96,24 @@ public sealed class LobbyController
catch (ArgumentNullException e)
{
LogWrapper.Error(e, "大厅创建者的用户名为空");
HintWrapper.Show("大厅创建者的用户名为空", HintType.Critical);
}
catch (ArgumentException e)
{
if (e.Message.Contains("lobby code"))
{
LogWrapper.Error(e, "大厅编号无效");
HintWrapper.Show("大厅编号无效", HintType.Critical);
}
else if (e.Message.Contains("hostname"))
{
LogWrapper.Error(e, "大厅创建者的用户名无效");
HintWrapper.Show("大厅创建者的用户名无效", HintType.Critical);
}
else
{
LogWrapper.Error(e, "在加入大厅时出现意外的无效参数");
HintWrapper.Show("在加入大厅时出现意外的无效参数", HintType.Critical);
}
}
catch (Exception e)
Expand All @@ -123,7 +127,7 @@ public sealed class LobbyController
/// <summary>
/// Launch a Scaffolding Server.
/// </summary>
/// <param name="username">Host user name.</param>
/// <param name="username">Host username.</param>
/// <param name="port">Minecraft port.</param>
/// <returns>Created <see cref="ScaffoldingServerEntity"/>.</returns>
/// <remarks>
Expand All @@ -147,7 +151,7 @@ public sealed class LobbyController
}
catch (Exception e)
{
LogWrapper.Error(e, "Occurred error when launching Scafolding Server.");
LogWrapper.Error(e, "Occurred error when launching Scaffolding Server.");
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion Link/Natayark/NatayarkProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static async Task GetNaidDataAsync(string token, bool isRefresh = false,
void WarnLog(string msg)
{
LogWrapper.Warn(ex, LogModule, msg);
HintWrapper.Show(msg, HintTheme.Error);
HintWrapper.Show(msg, HintType.Critical);
}
}
finally
Expand Down
2 changes: 1 addition & 1 deletion Logging/LogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static void _LogAction(ActionLevel level, string formatted, string plain
// hint
if (level is ActionLevel.Hint or ActionLevel.HintErr)
{
HintWrapper.Show(plain, (level == ActionLevel.Hint) ? HintTheme.Normal : HintTheme.Error);
HintWrapper.Show(plain, (level == ActionLevel.Hint) ? HintType.Info : HintType.Critical);
}

// message box
Expand Down
2 changes: 1 addition & 1 deletion Minecraft/Folder/FolderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task McFolderListLoadAsync() {

foreach (var folder in Config.Launch.Folders.Split('|', StringSplitOptions.RemoveEmptyEntries)) {
if (!folder.Contains('>') || !folder.EndsWith('\\')) {
HintWrapper.Show($"无效的 Minecraft 文件夹:{folder}", HintTheme.Error);
HintWrapper.Show($"无效的 Minecraft 文件夹:{folder}", HintType.Critical);
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion Minecraft/Launch/Services/Argument/LaunchArgBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void AddLegacyServerArguments(string server) {
_arguments.Add($"--server {host} --port {port}");

if (instance.InstanceInfo.HasPatch("optifine")) {
HintWrapper.Show("OptiFine 与自动进入服务器可能不兼容,有概率导致材质丢失甚至游戏崩溃!", HintTheme.Error);
HintWrapper.Show("OptiFine 与自动进入服务器可能不兼容,有概率导致材质丢失甚至游戏崩溃!", HintType.Critical);
}
}

Expand Down
26 changes: 19 additions & 7 deletions UI/HintWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
namespace PCL.Core.UI;

public enum HintTheme
/// <summary>
/// 提示信息的种类W
/// </summary>
public enum HintType
{
Normal,
Success,
Error
/// <summary>
/// 信息
/// </summary>
Info,
/// <summary>
/// 已完成
/// </summary>
Finish,
/// <summary>
/// 错误
/// </summary>
Critical
}

public delegate void HintHandler(
string message,
HintTheme theme
HintType type
);

public static class HintWrapper
{
public static event HintHandler? OnShow;

public static void Show(string message, HintTheme theme = HintTheme.Normal)
public static void Show(string message, HintType type = HintType.Info)
{
OnShow?.Invoke(message, theme);
OnShow?.Invoke(message, type);
}
}