diff --git a/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs b/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs index 24d3027..f4f27d0 100644 --- a/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs +++ b/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs @@ -22,6 +22,8 @@ namespace Cryville.EEW.Unity.Map { readonly List _displayingReports = new(); readonly List _displayingOrder = new(); + public int Count => _displayingReports.Count; + [SerializeField] MapElementManager m_subManager; public RectangleF? AABB { @@ -37,8 +39,6 @@ namespace Cryville.EEW.Unity.Map { 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); @@ -46,16 +46,17 @@ namespace Cryville.EEW.Unity.Map { _selected = null; return; } - Add(e); + if (!Add(e)) + return; _selected = e; } public void SetCurrent(ReportViewModel e) { _current = e; } - void Add(ReportViewModel e) { + public bool Add(ReportViewModel e) { var element = Build(e.Model, out _, out int order); - if (element == null) return; + if (element == null) return false; var pos = element.transform.localPosition; pos.z = OrderToZ(_displayingOrder.Sum()); element.transform.localPosition = pos; @@ -64,8 +65,9 @@ namespace Cryville.EEW.Unity.Map { _displayingOrder.Add(order); element.transform.SetParent(transform, false); if (m_subManager != null) m_subManager.Add(e); + return true; } - void Remove(ReportViewModel e) { + public void Remove(ReportViewModel e) { int index = _displayingReports.IndexOf(e); if (index == -1) return; _displayingElements.RemoveAt(index); diff --git a/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs b/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs index 5e037cf..9e32c4c 100644 --- a/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs +++ b/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs @@ -16,8 +16,6 @@ namespace Cryville.EEW.Unity.UI { readonly List _displayingReports = new(); readonly List _displayingViews = new(); - public int Count => _displayingReports.Count; - public void Add(ReportViewModel e) { _displayingReports.Add(e); @@ -89,6 +87,7 @@ namespace Cryville.EEW.Unity.UI { int index = _displayingReports.IndexOf(viewModel); if (index == -1) return; SwitchTo(index); + Worker.Instance.SetSelected(viewModel); } } } diff --git a/Assets/Cryville.EEW.Unity/Worker.cs b/Assets/Cryville.EEW.Unity/Worker.cs index 04d0eaa..fb54147 100644 --- a/Assets/Cryville.EEW.Unity/Worker.cs +++ b/Assets/Cryville.EEW.Unity/Worker.cs @@ -176,16 +176,18 @@ namespace Cryville.EEW.Unity { void OnOngoingReported(ReportViewModel item, CollectionChangeAction action) { if (action == CollectionChangeAction.Add) { _uiActionQueue.Enqueue(() => { - m_mapElementManager.AddOngoing(item); m_ongoingEventList.Add(item); + if (m_mapElementManager.Add(item)) { + m_mapElementManager.SetSelected(null); + } m_cameraController.OnMapElementUpdated(); }); } else if (action == CollectionChangeAction.Remove) { _uiActionQueue.Enqueue(() => { - m_mapElementManager.RemoveOngoing(item); m_ongoingEventList.Remove(item); - if (m_ongoingEventList.Count == 0 && SharedSettings.Instance.DoSwitchBackToHistory && _latestHistoryReport is not null) { + m_mapElementManager.Remove(item); + if (m_mapElementManager.Count == 0 && SharedSettings.Instance.DoSwitchBackToHistory && _latestHistoryReport is not null) { m_mapElementManager.SetSelected(_latestHistoryReport); } m_cameraController.OnMapElementUpdated();