fix: Fix ongoing event cycling logic
This commit is contained in:
@@ -22,6 +22,8 @@ namespace Cryville.EEW.Unity.Map {
|
||||
readonly List<ReportViewModel> _displayingReports = new();
|
||||
readonly List<int> _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);
|
||||
|
@@ -16,8 +16,6 @@ namespace Cryville.EEW.Unity.UI {
|
||||
readonly List<ReportViewModel> _displayingReports = new();
|
||||
readonly List<EventOngoingView> _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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user