diff --git a/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs b/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs index f4f27d0..f3cd37e 100644 --- a/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs +++ b/Assets/Cryville.EEW.Unity/Map/MapElementManager.cs @@ -39,19 +39,39 @@ namespace Cryville.EEW.Unity.Map { return _displayingElements[index].AABB; } - public void SetSelected(ReportViewModel e) { - if (_selected is not null) + public void SetSelected(ReportViewModel e, bool forced = false) { + if (e == null) { Remove(_selected); - if (e == null || _displayingReports.Contains(e)) { _selected = null; return; } + if (_displayingReports.Contains(e)) { + if (forced) return; + Remove(_selected); + _selected = null; + return; + } + if (e.IsExcludedFromHistory) + return; if (!Add(e)) return; + if (_selected is not null) + Remove(_selected); _selected = e; } - public void SetCurrent(ReportViewModel e) { + public bool SetCurrent(ReportViewModel e) { + if (e == null) { + _current = null; + return true; + } + if (!_displayingReports.Contains(e)) { + _current = null; + return false; + } + if (_current == e) + return false; _current = e; + return true; } public bool Add(ReportViewModel e) { @@ -68,6 +88,7 @@ namespace Cryville.EEW.Unity.Map { return true; } public void Remove(ReportViewModel e) { + if (_current == e) _current = null; 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 9e32c4c..6cfcc98 100644 --- a/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs +++ b/Assets/Cryville.EEW.Unity/UI/EventOngoingListView.cs @@ -87,7 +87,7 @@ namespace Cryville.EEW.Unity.UI { int index = _displayingReports.IndexOf(viewModel); if (index == -1) return; SwitchTo(index); - Worker.Instance.SetSelected(viewModel); + Worker.Instance.SetSelected(null); } } } diff --git a/Assets/Cryville.EEW.Unity/Worker.cs b/Assets/Cryville.EEW.Unity/Worker.cs index 9ad14c0..a52cfc2 100644 --- a/Assets/Cryville.EEW.Unity/Worker.cs +++ b/Assets/Cryville.EEW.Unity/Worker.cs @@ -176,20 +176,20 @@ namespace Cryville.EEW.Unity { void OnOngoingReported(ReportViewModel item, CollectionChangeAction action) { if (action == CollectionChangeAction.Add) { _uiActionQueue.Enqueue(() => { - m_ongoingEventList.Add(item); if (m_mapElementManager.Add(item)) { m_mapElementManager.SetSelected(null); } + m_ongoingEventList.Add(item); m_cameraController.OnMapElementUpdated(); }); } else if (action == CollectionChangeAction.Remove) { _uiActionQueue.Enqueue(() => { - m_ongoingEventList.Remove(item); m_mapElementManager.Remove(item); if (m_mapElementManager.Count == 0 && SharedSettings.Instance.DoSwitchBackToHistory && _latestHistoryReport is not null) { - m_mapElementManager.SetSelected(_latestHistoryReport); + m_mapElementManager.SetSelected(_latestHistoryReport, true); } + m_ongoingEventList.Remove(item); m_cameraController.OnMapElementUpdated(); }); }