From a3c4bd08ee2a4168c470596775e7059c714affa5 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Sun, 16 Feb 2025 13:12:08 +0800 Subject: [PATCH] feat: Sync map to current ongoing event --- .../Map/MapElementManager.cs | 30 ++++++++++--------- .../UI/EventOngoingListView.cs | 1 + .../Cryville.EEW.Unity/UI/EventOngoingView.cs | 2 -- Assets/Cryville.EEW.Unity/Worker.cs | 4 +++ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs b/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs index 6ef14d5..24d3027 100644 --- a/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs +++ b/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs @@ -1,5 +1,4 @@ using Cryville.EEW.Core; -using Cryville.EEW.Core.Map; using Cryville.EEW.CWAOpenData.Map; using Cryville.EEW.GlobalQuake.Map; using Cryville.EEW.JMAAtom.Map; @@ -18,6 +17,7 @@ using UnityMapElement = Cryville.EEW.Unity.Map.Element.MapElement; namespace Cryville.EEW.Unity.Map { sealed class MapElementManager : MonoBehaviour { ReportViewModel _selected; + ReportViewModel _current; readonly List _displayingElements = new(); readonly List _displayingReports = new(); readonly List _displayingOrder = new(); @@ -26,29 +26,31 @@ namespace Cryville.EEW.Unity.Map { public RectangleF? AABB { get { - RectangleF? ret = null; - foreach (var element in _displayingElements) { - if (element == null) continue; - if (element.AABB is not RectangleF aabb) continue; - if (ret == null) ret = aabb; // TODO dynamic - else ret = MapTileUtils.UnionTileAABBs(ret.Value, aabb); - } - return ret; + if (_selected != null) return AABBOf(_selected); + if (_current != null) return AABBOf(_current); + return null; } } + RectangleF? AABBOf(ReportViewModel e) { + int index = _displayingReports.IndexOf(e); + if (index == -1) return null; + return _displayingElements[index].AABB; + } public void AddOngoing(ReportViewModel e) => Add(e); public void RemoveOngoing(ReportViewModel e) => Remove(e); public void SetSelected(ReportViewModel e) { if (_selected is not null) Remove(_selected); - if (_displayingReports.Contains(e)) { + if (e == null || _displayingReports.Contains(e)) { _selected = null; + return; } - else { - Add(e); - _selected = e; - } + Add(e); + _selected = e; + } + public void SetCurrent(ReportViewModel e) { + _current = e; } void Add(ReportViewModel e) { diff --git a/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs b/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs index 50b6d5d..4e623ae 100644 --- a/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs +++ b/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs @@ -79,6 +79,7 @@ namespace Cryville.EEW.Unity.UI { _displayingViews[_index].SetCurrent(true); _tickDown = Math.Max(0, keyProp?.Severity ?? 0) * 4 + 4; m_currentView.gameObject.SetActive(true); + Worker.Instance.SetCurrent(e); } public void SetCurrent(ReportViewModel viewModel) { int index = _displayingReports.IndexOf(viewModel); diff --git a/Assets/Cryville.EEW.Unity/UI/EventOngoingView.cs b/Assets/Cryville.EEW.Unity/UI/EventOngoingView.cs index 7c8ad77..2846e76 100644 --- a/Assets/Cryville.EEW.Unity/UI/EventOngoingView.cs +++ b/Assets/Cryville.EEW.Unity/UI/EventOngoingView.cs @@ -1,12 +1,10 @@ using Cryville.Common.Unity.UI; using Cryville.EEW.Report; -using System; using System.Globalization; using System.Linq; using UnityEngine; using UnityEngine.UI; using Utils; -using static UnityEditor.Profiling.HierarchyFrameDataView; namespace Cryville.EEW.Unity.UI { class EventOngoingView : MonoBehaviour { diff --git a/Assets/Cryville.EEW.Unity/Worker.cs b/Assets/Cryville.EEW.Unity/Worker.cs index edaed5e..b3370b6 100644 --- a/Assets/Cryville.EEW.Unity/Worker.cs +++ b/Assets/Cryville.EEW.Unity/Worker.cs @@ -147,6 +147,10 @@ namespace Cryville.EEW.Unity { m_mapElementManager.SetSelected(e); m_cameraController.OnMapElementUpdated(); } + public void SetCurrent(ReportViewModel e) { + m_mapElementManager.SetCurrent(e); + m_cameraController.OnMapElementUpdated(); + } void Update() { while (_uiActionQueue.TryDequeue(out var action)) {