From e4b5ce7e1bb793dc42674dc90fd41919c0141e2b Mon Sep 17 00:00:00 2001 From: NguyenVanDat Date: Wed, 6 May 2026 11:16:52 +0700 Subject: [PATCH] fix show progress bar --- .../Scripts/MainFiles/EC_Game.Time.cs | 10 +- .../Scripts/UI/Dialogs/DlgHost.cs | 112 +--------------- .../Scripts/UI/HUDMainGamePlay.cs | 126 +++++++++++++++++- Assets/Scripts/CECHostPlayer.cs | 2 +- 4 files changed, 130 insertions(+), 120 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.Time.cs b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.Time.cs index cce14ba1ff..f434bd3933 100644 --- a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.Time.cs +++ b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.Time.cs @@ -14,6 +14,7 @@ namespace BrewMonster.Network private static bool m_bServerTimeInited; private static float m_dwTickTime; // Logic time of current tick private static float m_dwRealTickTime; // Real tick time + public static int GetTimeZoneBias() { return m_iTimeZoneBias; } // 设置时间误差 // Set time error public static void SetServerTime(int iSevTime, int iTimeZoneBias) @@ -71,14 +72,13 @@ namespace BrewMonster.Network return m_AbsTimeStart + (int)sec; } } - + // Get real tick time of current frame public static float GetRealTickTime() { - // return m_dwRealTickTime; + return (uint)(Time.deltaTime * 1000f); + return Mathf.Abs(m_dwRealTickTime); // return Time.realtimeSinceStartup; - // 0.018f is value to make mining process run fit with player animation. if have any issue => discussing with Mr. Drimdar - return Mathf.Abs(Time.unscaledDeltaTime - 0.018f) * 1000f;//-0.001f } } -} \ No newline at end of file +} diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgHost.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgHost.cs index 9bff76d233..c47a44e00d 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgHost.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgHost.cs @@ -5,10 +5,6 @@ namespace BrewMonster.UI //Win_Hpmpxp public class DlgHost : AUIDialog { - public const int AUIPROGRESS_MAX = 100; - private DlgWinPrgs2 _dlgWinPrgs; - private CECHostPlayer _pHost; - public override bool Render() { // if( m_szName == "Win_Hpmpxp" ) @@ -16,114 +12,10 @@ namespace BrewMonster.UI // else if (m_szName == "Win_HideHP") // { // a_LogOutput(1,"[Dat Mine] Win_HideHP"); - RefreshStatusBar(); + // RefreshStatusBar(); // } - + return base.Render(); } - - public void RefreshStatusBar() - { - bool bActive = true; - // if( GetGameUIMan()->GetActiveDialog() && - // GetGameUIMan()->GetActiveDialog()->GetFocus() && - // GetGameUIMan()->GetActiveDialog()->GetFocus()->GetType() == AUIOBJECT_TYPE_EDITBOX ) - // bActive = false; - // - // // Flight bar. - // RefreshFlightBar(bActive); - // - // // Oxigen bar. - // RefreshOxigenBar(bActive); - - // Gather bar. - RefreshGatherBar(bActive); - - // // group these bars, show only one at one time - // bool bShow = false; - // // Power bar. - // bShow |= RefreshPowerBar(bShow, bActive); - // // Array bar. - // bShow |= RefreshArrayBar(bShow, bActive); - // // Incant bar. - // bShow |= RefreshIncantBar(bShow, bActive); - // - // if (GetHostPlayer()->GetCurSkill() && !bShow) - // { - // // ´«Ë͵ȷ½Ê½µ¼ÖÂλÖÃÇл»¡¢¼¼ÄÜ£¨Õó¼¼ÄÜ£©ÈÔÈ»ÔÚÊÍ·Å״̬ - // // - // GetGameSession()->c2s_CmdCancelAction(); - // } - // - // // AutoHP bar. - // RefreshAutoHPBar(bActive); - // - // // AutoMP bar. - // RefreshAutoMPBar(bActive); - // - // // pet status - // RefreshPetStatus(); - // - // //ELF status - // RefreshElfStatus(); - } - - private bool RefreshGatherBar(bool bActive) - { - if (_dlgWinPrgs == null) - { - var pDlg = GetGameUIMan().GetDialog("Win_Prgs2"); - if (pDlg == null) - { - BMLogger.LogError("Null Win_Prgs2"); - return false; - } - - if (pDlg is not DlgWinPrgs2 dlgWinPrgs) - { - BMLogger.LogError("Can not cast Win_Prgs2"); - return false; - } - _dlgWinPrgs = dlgWinPrgs; - } - - if (_pHost == null) - { - _pHost = GetHostPlayer(); - if (_pHost == null) return false; - } - - CECCounter counter = _pHost.GetGatherCnt(); - if (_pHost.IsGathering()) - { - int nCur = (int)counter.GetCounter(); - int nMax = Mathf.Max((int)counter.GetPeriod(), 1); - - if (!_dlgWinPrgs.IsShow()) - _dlgWinPrgs.Show(bActive);//true, false, bActive - - // PAUIPROGRESS pProgress = (PAUIPROGRESS)pDlg.GetDlgItem("Prgs"); - // PAUILABEL pLabel = (PAUILABEL)pDlg.GetDlgItem("1"); - - var percent = AUIPROGRESS_MAX * nCur / nMax; - _dlgWinPrgs.SetProgressAndText(percent*1.0f/100.0f,$"{percent}%"); - // pLabel.SetText(percent); - // pProgress.SetProgress(AUIPROGRESS_MAX * nCur / nMax); - if (percent < 100) - { - _dlgWinPrgs.SetActiveProgress(true); - } - } - else - { - if (_dlgWinPrgs.IsShow()) - { - _dlgWinPrgs.Show(false); - _dlgWinPrgs.SetActiveProgress(false); - } - } - - return _dlgWinPrgs.IsShow(); - } } } diff --git a/Assets/PerfectWorld/Scripts/UI/HUDMainGamePlay.cs b/Assets/PerfectWorld/Scripts/UI/HUDMainGamePlay.cs index db70214c2d..4d323a8fb3 100644 --- a/Assets/PerfectWorld/Scripts/UI/HUDMainGamePlay.cs +++ b/Assets/PerfectWorld/Scripts/UI/HUDMainGamePlay.cs @@ -1,5 +1,6 @@ using System; using BrewMonster.Network; +using BrewMonster.UI; using UnityEngine; using UnityEngine.UI; @@ -17,6 +18,10 @@ namespace BrewMonster [SerializeField]private Transform _taskTraceParent; [SerializeField]private Button _btnTeamList; + public const int AUIPROGRESS_MAX = 100; + private DlgWinPrgs2 _dlgWinPrgs; + private CECHostPlayer _pHost; + #endregion private void OnEnable() @@ -27,8 +32,8 @@ namespace BrewMonster _btnTeam.onValueChanged.AddListener(OnTeamClicked); _btnTaskTrace.onValueChanged.AddListener(OnTaskTraceClicked); _btnTeamList.onClick.AddListener(OnTeamListClicked); - EventBus.Unsubscribe(OnUIEvent); - EventBus.Subscribe(OnUIEvent); + EventBus.Unsubscribe(OnUIEvent); + EventBus.Subscribe(OnUIEvent); } private void OnDisable() @@ -42,6 +47,11 @@ namespace BrewMonster EventBus.Unsubscribe(OnUIEvent); } + private void Update() + { + RefreshStatusBar(); + } + private void OnUIEvent(UIEvent uiEvent) { switch(uiEvent.EventType) @@ -127,13 +137,121 @@ namespace BrewMonster private void OnEscapeClicked() { // Open the exit dialog , not directly exit the game - + // return; if(EC_Game.GetGameRun()?.GetHostPlayer() != null) { EC_Game.GetGameRun()?.GetHostPlayer().OnClickBtnEscape(); } } + + #region Progress Bar + + public void RefreshStatusBar() + { + bool bActive = true; + // if( GetGameUIMan()->GetActiveDialog() && + // GetGameUIMan()->GetActiveDialog()->GetFocus() && + // GetGameUIMan()->GetActiveDialog()->GetFocus()->GetType() == AUIOBJECT_TYPE_EDITBOX ) + // bActive = false; + // + // // Flight bar. + // RefreshFlightBar(bActive); + // + // // Oxigen bar. + // RefreshOxigenBar(bActive); + + // Gather bar. + RefreshGatherBar(bActive); + + // // group these bars, show only one at one time + // bool bShow = false; + // // Power bar. + // bShow |= RefreshPowerBar(bShow, bActive); + // // Array bar. + // bShow |= RefreshArrayBar(bShow, bActive); + // // Incant bar. + // bShow |= RefreshIncantBar(bShow, bActive); + // + // if (GetHostPlayer()->GetCurSkill() && !bShow) + // { + // // ´«Ë͵ȷ½Ê½µ¼ÖÂλÖÃÇл»¡¢¼¼ÄÜ£¨Õó¼¼ÄÜ£©ÈÔÈ»ÔÚÊÍ·Å״̬ + // // + // GetGameSession()->c2s_CmdCancelAction(); + // } + // + // // AutoHP bar. + // RefreshAutoHPBar(bActive); + // + // // AutoMP bar. + // RefreshAutoMPBar(bActive); + // + // // pet status + // RefreshPetStatus(); + // + // //ELF status + // RefreshElfStatus(); + } + + private bool RefreshGatherBar(bool bActive) + { + if (_dlgWinPrgs == null) + { + var pDlg = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan().GetDialog("Win_Prgs2"); + if (pDlg == null) + { + BMLogger.LogError("Null Win_Prgs2"); + return false; + } + + if (pDlg is not DlgWinPrgs2 dlgWinPrgs) + { + BMLogger.LogError("Can not cast Win_Prgs2"); + return false; + } + _dlgWinPrgs = dlgWinPrgs; + } + + if (_pHost == null) + { + _pHost = EC_Game.GetGameRun().GetHostPlayer(); + if (_pHost == null) return false; + } + + CECCounter counter = _pHost.GetGatherCnt(); + if (_pHost.IsGathering()) + { + int nCur = (int)counter.GetCounter(); + int nMax = Mathf.Max((int)counter.GetPeriod(), 1); + + if (!_dlgWinPrgs.IsShow()) + _dlgWinPrgs.Show(bActive);//true, false, bActive + + // PAUIPROGRESS pProgress = (PAUIPROGRESS)pDlg.GetDlgItem("Prgs"); + // PAUILABEL pLabel = (PAUILABEL)pDlg.GetDlgItem("1"); + + var percent = AUIPROGRESS_MAX * nCur / nMax; + _dlgWinPrgs.SetProgressAndText(percent*1.0f/100.0f,$"{percent}%"); + // pLabel.SetText(percent); + // pProgress.SetProgress(AUIPROGRESS_MAX * nCur / nMax); + if (percent < 100) + { + _dlgWinPrgs.SetActiveProgress(true); + } + } + else + { + if (_dlgWinPrgs.IsShow()) + { + _dlgWinPrgs.Show(false); + _dlgWinPrgs.SetActiveProgress(false); + } + } + + return _dlgWinPrgs.IsShow(); + } + + #endregion } public enum UIEventType { @@ -144,7 +262,7 @@ namespace BrewMonster } public struct UIEvent { - + public UIEventType EventType; public UIEvent(UIEventType eventType) { diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 99129348fd..80085e3add 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -3641,7 +3641,7 @@ namespace BrewMonster } // Gather time counter - if (m_GatherCnt.IncCounter(iRealTime * 1000)) + if (m_GatherCnt.IncCounter(iRealTime)) m_GatherCnt.Reset(true); // Incant time counter