From 15f2fe6f57158c9f6d5084bde4306609e2451e9a Mon Sep 17 00:00:00 2001 From: akanyan Date: Fri, 3 Jan 2025 17:39:16 +0000 Subject: [PATCH] fix(MoreProfileOptions): a better way --- .../MU3.CustomUI/patch_MU3UICounter.cs | 31 ++++---------- .../MU3.Data/patch_GameData.cs | 15 ------- .../MU3.Mod/CustomRating.cs | 40 +++++++++---------- .../MU3.SceneObject/patch_ANM_CMN_User.cs | 15 ++++++- .../patch_ANM_SWH_LocalMatching_User.cs | 30 ++++++++++++++ .../MU3.Sequence/patch_Play.cs | 9 +++++ .../MU3/patch_UIResultBattlePoint.cs | 3 +- 7 files changed, 80 insertions(+), 63 deletions(-) delete mode 100644 Extras/MoreProfileOptions/MU3.Data/patch_GameData.cs create mode 100644 Extras/MoreProfileOptions/MU3.SceneObject/patch_ANM_SWH_LocalMatching_User.cs create mode 100644 Extras/MoreProfileOptions/MU3.Sequence/patch_Play.cs diff --git a/Extras/MoreProfileOptions/MU3.CustomUI/patch_MU3UICounter.cs b/Extras/MoreProfileOptions/MU3.CustomUI/patch_MU3UICounter.cs index 1ed6ec5..28780fb 100644 --- a/Extras/MoreProfileOptions/MU3.CustomUI/patch_MU3UICounter.cs +++ b/Extras/MoreProfileOptions/MU3.CustomUI/patch_MU3UICounter.cs @@ -1,36 +1,19 @@ -using MU3.Mod; -using MU3.User; +using MU3.User; namespace MU3.CustomUI; class patch_MU3UICounter: MU3UICounter { - public bool isRatingDisplay { get; set; } - - protected extern void orig_calcNumFiguresFloat(double value); - protected new void calcNumFiguresFloat(double value) { - orig_calcNumFiguresFloat(value); - - if(isRatingDisplay) { - var b = CustomRating.GetSuffix(); - if(b != 0) { - pushFigureFront(b); - } - } + public void SetRating(int value, byte suffix) { + Counter = UserUtil.toRatingFloat(value); + AddSuffix(suffix); } - protected void pushFigureFront(byte c) { + + public void AddSuffix(byte c) { for(int i = numFigures_; i > 0; --i) { figures_[i] = figures_[i - 1]; } figures_[0] = c; numFigures_ += 1; - } - - public extern void orig_set_Counter(double value); - public void set_Counter(double value) { - if(isRatingDisplay && CustomRating.IsEnabled()) { - orig_set_Counter(UserUtil.toRatingFloat(CustomRating.Get())); - } else { - orig_set_Counter(value); - } + SetVerticesDirty(); } } diff --git a/Extras/MoreProfileOptions/MU3.Data/patch_GameData.cs b/Extras/MoreProfileOptions/MU3.Data/patch_GameData.cs deleted file mode 100644 index 5ba1ef7..0000000 --- a/Extras/MoreProfileOptions/MU3.Data/patch_GameData.cs +++ /dev/null @@ -1,15 +0,0 @@ -using MU3.DB; -using MU3.Mod; - -namespace MU3.Data; - -class patch_GameData: GameData { - public extern static RatingColorID orig_getRatingColorIDFromRating100(int rating100); - public static new RatingColorID getRatingColorIDFromRating100(int rating100) { - if(CustomRating.IsEnabled()) { - return orig_getRatingColorIDFromRating100(CustomRating.Get()); - } else { - return orig_getRatingColorIDFromRating100(rating100); - } - } -} \ No newline at end of file diff --git a/Extras/MoreProfileOptions/MU3.Mod/CustomRating.cs b/Extras/MoreProfileOptions/MU3.Mod/CustomRating.cs index d483f12..fc8c638 100644 --- a/Extras/MoreProfileOptions/MU3.Mod/CustomRating.cs +++ b/Extras/MoreProfileOptions/MU3.Mod/CustomRating.cs @@ -68,29 +68,29 @@ public static class CustomRating { } public static int Get() { - switch(eRating) { - case patch_UserOption.eRating.Naive: - return GetNaive(); - case patch_UserOption.eRating.Reachable: - return GetReachable(); - case patch_UserOption.eRating.Recent: - return GetRecent(); - default: - return 0; - } + return eRating switch { + patch_UserOption.eRating.Naive => GetNaive(), + patch_UserOption.eRating.Reachable => GetReachable(), + patch_UserOption.eRating.Recent => GetRecent(), + _ => 0, + }; } public static byte GetSuffix() { - switch(eRating) { - case patch_UserOption.eRating.Naive: - return MU3CounterBase.FigurePlus; - case patch_UserOption.eRating.Reachable: - return MU3CounterBase.FigureMinus; - case patch_UserOption.eRating.Recent: - return MU3CounterBase.FigureComma; - default: - return 0; - } + return eRating switch { + patch_UserOption.eRating.Naive => GetSuffix(0), + patch_UserOption.eRating.Reachable => GetSuffix(1), + patch_UserOption.eRating.Recent => GetSuffix(2), + _ => 0, + }; + } + public static byte GetSuffix(int idx) { + return idx switch { + 0 => MU3CounterBase.FigurePlus, + 1 => MU3CounterBase.FigureMinus, + 2 => MU3CounterBase.FigureComma, + _ => 0, + }; } // Adapted from MU3.User.UserRating.calcBest() diff --git a/Extras/MoreProfileOptions/MU3.SceneObject/patch_ANM_CMN_User.cs b/Extras/MoreProfileOptions/MU3.SceneObject/patch_ANM_CMN_User.cs index ab0ee52..36b27f5 100644 --- a/Extras/MoreProfileOptions/MU3.SceneObject/patch_ANM_CMN_User.cs +++ b/Extras/MoreProfileOptions/MU3.SceneObject/patch_ANM_CMN_User.cs @@ -1,4 +1,8 @@ using MU3.CustomUI; +using MU3.Data; +using MU3.DB; +using MU3.Mod; +using MU3.User; namespace MU3.SceneObject; @@ -7,8 +11,15 @@ class patch_ANM_CMN_UserDeta_01: ANM_CMN_UserDeta_01 { public extern void orig_setUserDetail(); public new void setUserDetail() { - rating.isRatingDisplay = true; orig_setUserDetail(); - rating.setForceDirty(); + + if(CustomRating.IsEnabled()) { + var r = CustomRating.Get(); + rating.Counter = UserUtil.toRatingFloat(r); + rating.AddSuffix(CustomRating.GetSuffix()); + RatingColorID ratingColorIDFromRating = GameData.getRatingColorIDFromRating100(r); + transform.Find("NUM_CMN_UserData_01/NUM_Rating").GetComponent().SpriteIndex = (int)ratingColorIDFromRating; + transform.Find("NUM_CMN_UserData_01/NUM_Rating/PAT_Header").GetComponent().patternNumber = (float)ratingColorIDFromRating; + } } } diff --git a/Extras/MoreProfileOptions/MU3.SceneObject/patch_ANM_SWH_LocalMatching_User.cs b/Extras/MoreProfileOptions/MU3.SceneObject/patch_ANM_SWH_LocalMatching_User.cs new file mode 100644 index 0000000..30c987d --- /dev/null +++ b/Extras/MoreProfileOptions/MU3.SceneObject/patch_ANM_SWH_LocalMatching_User.cs @@ -0,0 +1,30 @@ +using MU3.Collab; +using MU3.CustomUI; +using MU3.Mod; +using UnityEngine; + +namespace MU3.SceneObject; + +class patch_ANM_SWH_LocalMatching_User: ANM_SWH_LocalMatching_User { + private GameObject _objRatingNum; + private patch_MU3UICounter _counterRating; + private GameObject _objRatingMask; + + private extern void orig_set_sub(Party.UserInfo userInfo, bool isHost, bool isWaitPlay, bool forRecruit); + private void set_sub(Party.UserInfo userInfo, bool isHost, bool isWaitPlay, bool forRecruit) { + orig_set_sub(userInfo, isHost, isWaitPlay, forRecruit); + + var flag = userInfo._optRatingID >= 1; + _objRatingNum.SetActive(flag); + if(userInfo._optRatingID > 1) { + _counterRating.AddSuffix(userInfo._optRatingID switch { + 2 => CustomRating.GetSuffix(0), + 3 => CustomRating.GetSuffix(1), + 4 => CustomRating.GetSuffix(2), + _ => 0 + }); + } + + _objRatingMask.SetActive(!flag); + } +} diff --git a/Extras/MoreProfileOptions/MU3.Sequence/patch_Play.cs b/Extras/MoreProfileOptions/MU3.Sequence/patch_Play.cs new file mode 100644 index 0000000..8317d7b --- /dev/null +++ b/Extras/MoreProfileOptions/MU3.Sequence/patch_Play.cs @@ -0,0 +1,9 @@ +using MU3.Util; + +namespace MU3.Sequence; + +class patch_Play: Play { + private void Leave_Login() { + SingletonMonoBehaviour.instance.userData.setUserDetail(); + } +} diff --git a/Extras/MoreProfileOptions/MU3/patch_UIResultBattlePoint.cs b/Extras/MoreProfileOptions/MU3/patch_UIResultBattlePoint.cs index c2578c8..c8e0a92 100644 --- a/Extras/MoreProfileOptions/MU3/patch_UIResultBattlePoint.cs +++ b/Extras/MoreProfileOptions/MU3/patch_UIResultBattlePoint.cs @@ -21,8 +21,6 @@ class patch_UIResultBattlePoint: UIResultBattlePoint { public extern void orig_initTechRating(PlayInfo playInfo); public new void initTechRating(PlayInfo playInfo) { - counterScore_.isRatingDisplay = true; - if(!CustomRating.IsEnabled()) { orig_initTechRating(playInfo); return; @@ -36,6 +34,7 @@ class patch_UIResultBattlePoint: UIResultBattlePoint { int ratingPatternNo = UserUtil.toRatingPatternNo(rating1); counterScore_.SpriteIndex = ratingPatternNo; imageHeader_.patternNumber = ratingPatternNo; + counterScore_.AddSuffix(CustomRating.GetSuffix()); int rating2 = rating1 - prevRating; if(rating2 == 0) { disable(counterScorePlus_);