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<ReportViewModel> _displayingReports = new();
|
||||||
readonly List<int> _displayingOrder = new();
|
readonly List<int> _displayingOrder = new();
|
||||||
|
|
||||||
|
public int Count => _displayingReports.Count;
|
||||||
|
|
||||||
[SerializeField] MapElementManager m_subManager;
|
[SerializeField] MapElementManager m_subManager;
|
||||||
|
|
||||||
public RectangleF? AABB {
|
public RectangleF? AABB {
|
||||||
@@ -37,8 +39,6 @@ namespace Cryville.EEW.Unity.Map {
|
|||||||
return _displayingElements[index].AABB;
|
return _displayingElements[index].AABB;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddOngoing(ReportViewModel e) => Add(e);
|
|
||||||
public void RemoveOngoing(ReportViewModel e) => Remove(e);
|
|
||||||
public void SetSelected(ReportViewModel e) {
|
public void SetSelected(ReportViewModel e) {
|
||||||
if (_selected is not null)
|
if (_selected is not null)
|
||||||
Remove(_selected);
|
Remove(_selected);
|
||||||
@@ -46,16 +46,17 @@ namespace Cryville.EEW.Unity.Map {
|
|||||||
_selected = null;
|
_selected = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Add(e);
|
if (!Add(e))
|
||||||
|
return;
|
||||||
_selected = e;
|
_selected = e;
|
||||||
}
|
}
|
||||||
public void SetCurrent(ReportViewModel e) {
|
public void SetCurrent(ReportViewModel e) {
|
||||||
_current = e;
|
_current = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Add(ReportViewModel e) {
|
public bool Add(ReportViewModel e) {
|
||||||
var element = Build(e.Model, out _, out int order);
|
var element = Build(e.Model, out _, out int order);
|
||||||
if (element == null) return;
|
if (element == null) return false;
|
||||||
var pos = element.transform.localPosition;
|
var pos = element.transform.localPosition;
|
||||||
pos.z = OrderToZ(_displayingOrder.Sum());
|
pos.z = OrderToZ(_displayingOrder.Sum());
|
||||||
element.transform.localPosition = pos;
|
element.transform.localPosition = pos;
|
||||||
@@ -64,8 +65,9 @@ namespace Cryville.EEW.Unity.Map {
|
|||||||
_displayingOrder.Add(order);
|
_displayingOrder.Add(order);
|
||||||
element.transform.SetParent(transform, false);
|
element.transform.SetParent(transform, false);
|
||||||
if (m_subManager != null) m_subManager.Add(e);
|
if (m_subManager != null) m_subManager.Add(e);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
void Remove(ReportViewModel e) {
|
public void Remove(ReportViewModel e) {
|
||||||
int index = _displayingReports.IndexOf(e);
|
int index = _displayingReports.IndexOf(e);
|
||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
_displayingElements.RemoveAt(index);
|
_displayingElements.RemoveAt(index);
|
||||||
|
@@ -16,8 +16,6 @@ namespace Cryville.EEW.Unity.UI {
|
|||||||
readonly List<ReportViewModel> _displayingReports = new();
|
readonly List<ReportViewModel> _displayingReports = new();
|
||||||
readonly List<EventOngoingView> _displayingViews = new();
|
readonly List<EventOngoingView> _displayingViews = new();
|
||||||
|
|
||||||
public int Count => _displayingReports.Count;
|
|
||||||
|
|
||||||
public void Add(ReportViewModel e) {
|
public void Add(ReportViewModel e) {
|
||||||
_displayingReports.Add(e);
|
_displayingReports.Add(e);
|
||||||
|
|
||||||
@@ -89,6 +87,7 @@ namespace Cryville.EEW.Unity.UI {
|
|||||||
int index = _displayingReports.IndexOf(viewModel);
|
int index = _displayingReports.IndexOf(viewModel);
|
||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
SwitchTo(index);
|
SwitchTo(index);
|
||||||
|
Worker.Instance.SetSelected(viewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -176,16 +176,18 @@ namespace Cryville.EEW.Unity {
|
|||||||
void OnOngoingReported(ReportViewModel item, CollectionChangeAction action) {
|
void OnOngoingReported(ReportViewModel item, CollectionChangeAction action) {
|
||||||
if (action == CollectionChangeAction.Add) {
|
if (action == CollectionChangeAction.Add) {
|
||||||
_uiActionQueue.Enqueue(() => {
|
_uiActionQueue.Enqueue(() => {
|
||||||
m_mapElementManager.AddOngoing(item);
|
|
||||||
m_ongoingEventList.Add(item);
|
m_ongoingEventList.Add(item);
|
||||||
|
if (m_mapElementManager.Add(item)) {
|
||||||
|
m_mapElementManager.SetSelected(null);
|
||||||
|
}
|
||||||
m_cameraController.OnMapElementUpdated();
|
m_cameraController.OnMapElementUpdated();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (action == CollectionChangeAction.Remove) {
|
else if (action == CollectionChangeAction.Remove) {
|
||||||
_uiActionQueue.Enqueue(() => {
|
_uiActionQueue.Enqueue(() => {
|
||||||
m_mapElementManager.RemoveOngoing(item);
|
|
||||||
m_ongoingEventList.Remove(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_mapElementManager.SetSelected(_latestHistoryReport);
|
||||||
}
|
}
|
||||||
m_cameraController.OnMapElementUpdated();
|
m_cameraController.OnMapElementUpdated();
|
||||||
|
Reference in New Issue
Block a user