From ae2e0af18a8e391c7b50dc04c862a9703eec04a1 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Tue, 29 Apr 2025 19:52:41 +0800 Subject: [PATCH] fix: Improve ongoing report round-robin period --- .../UI/EventOngoingListView.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs b/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs index 2fef491..97f59a8 100644 --- a/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs +++ b/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs @@ -23,6 +23,7 @@ namespace Cryville.EEW.Unity.UI { child.SetViewModel(e); child.transform.SetParent(m_listView, false); _displayingViews.Add(child); + OnDisplayingViewsChanged(); SwitchTo(_displayingReports.Count - 1); @@ -37,6 +38,7 @@ namespace Cryville.EEW.Unity.UI { child.SetParent(null, false); Destroy(child.gameObject); _displayingViews.RemoveAt(index); + OnDisplayingViewsChanged(); if (_displayingReports.Count == 0) { m_currentView.gameObject.SetActive(false); @@ -49,6 +51,14 @@ namespace Cryville.EEW.Unity.UI { if (_displayingReports.Count <= 1) m_listView.gameObject.SetActive(false); } + void OnDisplayingViewsChanged() { + _maxBaseDuration = 1; + foreach (var e in _displayingReports) { + float duration = GetBaseDuration(e); + if (duration > _maxBaseDuration) + _maxBaseDuration = duration; + } + } void Awake() { if (Instance != null) { @@ -63,6 +73,7 @@ namespace Cryville.EEW.Unity.UI { int _index = -1; float _tickDown; + float _maxBaseDuration; void Update() { if (_displayingReports.Count == 0) return; _tickDown -= Time.deltaTime; @@ -77,12 +88,15 @@ namespace Cryville.EEW.Unity.UI { _index = index; var e = _displayingReports[index]; m_currentView.SetViewModel(e, true); - var keyProp = e.Properties.FirstOrDefault(); _displayingViews[_index].SetCurrent(true); - _tickDown = MathF.Exp(Math.Max(-1f, keyProp?.Severity ?? -1f) + 1); + _tickDown = GetBaseDuration(e) / Math.Min(_maxBaseDuration, 4) * 4; m_currentView.gameObject.SetActive(true); Worker.Instance.SetCurrent(e); } + static float GetBaseDuration(ReportViewModel e) { + return MathF.Exp(Math.Max(-1f, e.Properties.FirstOrDefault()?.Severity ?? -1f) + 1); + } + public void OnItemClicked(ReportViewModel viewModel) { int index = _displayingReports.IndexOf(viewModel); if (index == -1) return;