Skip to content

Commit

Permalink
[+] Network error reason
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Sep 30, 2024
1 parent e39f013 commit e65d67f
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 9 deletions.
1 change: 1 addition & 0 deletions AquaMai/AquaMai.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ DEBUG</DefineConstants>
<Compile Include="Utils\PractiseMode.cs" />
<Compile Include="Utils\PractiseModeUI.cs" />
<Compile Include="Utils\SelectionDetail.cs" />
<Compile Include="Utils\ShowNetErrorDetail.cs" />
<Compile Include="Utils\WindowState.cs" />
<Compile Include="UX\CustomPlaceName.cs" />
<Compile Include="UX\CustomVersionString.cs" />
Expand Down
2 changes: 2 additions & 0 deletions AquaMai/AquaMai.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ IWontTapOrSlideVigorously=true
SkipGameOverScreen=true
# Skip TrackStart screen
SkipTrackStart=true
# Show reason when net icon is gray
ShowNetErrorDetail=true

[TouchSensitivity]
# Enable custom sensitivity
Expand Down
2 changes: 2 additions & 0 deletions AquaMai/AquaMai.zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Width=0
Height=0
# 选歌界面显示选择的歌曲的详情
SelectionDetail=true
# 出现灰网时显示原因
ShowNetErrorDetail=true

# ===================================
# 节省一些不知道有用没用的时间
Expand Down
1 change: 1 addition & 0 deletions AquaMai/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class UtilsConfig
public int Height { get; set; }
public bool PractiseMode { get; set; }
public bool SelectionDetail { get; set; }
public bool ShowNetErrorDetail { get; set; }
}

public class TimeSavingConfig
Expand Down
3 changes: 1 addition & 2 deletions AquaMai/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ public override void OnInitializeMelon()

if (_hasErrors)
{
MelonLogger.Warning("========================================================================!!!");
MelonLogger.Warning(Locale.LoadError);
MelonLogger.Warning("========================================================================!!!\n" + Locale.LoadError);
MelonLogger.Warning("===========================================================================");
}

Expand Down
36 changes: 36 additions & 0 deletions AquaMai/Resources/Locale.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions AquaMai/Resources/Locale.resx
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,16 @@
<data name="Loaded" xml:space="preserve">
<value>Loaded!</value>
</data>
<data name="NetErrIsAliveServer" xml:space="preserve">
<value>Server communication error</value>
</data>
<data name="NetErrIsAliveAimeReader" xml:space="preserve">
<value>Aime reader error</value>
</data>
<data name="NetErrIsAliveAimeServer" xml:space="preserve">
<value>Aime server error</value>
</data>
<data name="NetErrWasDownloadSuccessOnce" xml:space="preserve">
<value>Data download not success</value>
</data>
</root>
12 changes: 12 additions & 0 deletions AquaMai/Resources/Locale.zh.resx
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,16 @@
<data name="Loaded" xml:space="preserve">
<value>加载完成!</value>
</data>
<data name="NetErrIsAliveServer" xml:space="preserve">
<value>主服务器通信错误</value>
</data>
<data name="NetErrIsAliveAimeReader" xml:space="preserve">
<value>Aime 读卡器错误</value>
</data>
<data name="NetErrIsAliveAimeServer" xml:space="preserve">
<value>AimeDB 通信错误</value>
</data>
<data name="NetErrWasDownloadSuccessOnce" xml:space="preserve">
<value>数据下载不成功</value>
</data>
</root>
11 changes: 4 additions & 7 deletions AquaMai/UX/ImmediateSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ public static void ResultProcessOnStart()
void CheckSaveDone()
{
doneCount++;
if (doneCount == 4)
{
if (ui != null)
{
UnityEngine.Object.Destroy(ui);
}
}
if (doneCount != 4) return;
if (ui == null) return;
UnityEngine.Object.Destroy(ui);
ui = null;
}

for (int i = 0; i < 2; i++)
Expand Down
69 changes: 69 additions & 0 deletions AquaMai/Utils/ShowNetErrorDetail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Collections.Generic;
using AquaMai.Helpers;
using AquaMai.Resources;
using HarmonyLib;
using MAI2.Util;
using Manager;
using MelonLoader;
using Monitor;
using Process;
using UnityEngine;

namespace AquaMai.Utils;

public class ShowNetErrorDetail
{
[HarmonyPatch(typeof(CommonProcess), "OnStart")]
[HarmonyPostfix]
public static void SetIconStatus(CommonMonitor[] ____monitors)
{
____monitors[0].gameObject.AddComponent<DetailUi>();
}

private class DetailUi : MonoBehaviour
{
public void OnGUI()
{
var errors = new List<string>();
if (!Singleton<OperationManager>.Instance.IsAliveServer)
{
errors.Add(Locale.NetErrIsAliveServer);
}

if (!Singleton<OperationManager>.Instance.IsAliveAimeReader)
{
errors.Add(Locale.NetErrIsAliveAimeReader);
}

if (!Singleton<OperationManager>.Instance.IsAliveAimeServer)
{
errors.Add(Locale.NetErrIsAliveAimeServer);
}

if (!Singleton<OperationManager>.Instance.WasDownloadSuccessOnce)
{
errors.Add(Locale.NetErrWasDownloadSuccessOnce);
}

if (errors.Count == 0)
{
return;
}

var labelStyle = GUI.skin.GetStyle("label");
labelStyle.fontSize = GuiSizes.FontSize;
labelStyle.alignment = TextAnchor.MiddleCenter;

var x = GuiSizes.PlayerCenter + GuiSizes.PlayerWidth * .2f;
var y = Screen.height * .01f;
var width = GuiSizes.FontSize * 15f;
var height = GuiSizes.LabelHeight * errors.Count + GuiSizes.Margin * 2;

GUI.Box(new Rect(x, y, width, height), "");
for (var i = 0; i < errors.Count; i++)
{
GUI.Label(new Rect(x, y + GuiSizes.Margin + GuiSizes.LabelHeight * i, width, GuiSizes.LabelHeight), errors[i]);
}
}
}
}

0 comments on commit e65d67f

Please sign in to comment.