8 Commits

11 changed files with 79 additions and 29 deletions

View File

@@ -0,0 +1,3 @@
using System.Reflection;
[assembly: AssemblyVersion("0.0.1")]

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c468580e7742d414e96822c2dfe6e4b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Cryville.EEW.Unity { namespace Cryville.EEW.Unity {
record Config( record Config(
string SeverityScheme, string SeverityScheme,
string SeverityColorMapping,
float SeverityColorMappingLuminanceMultiplier, float SeverityColorMappingLuminanceMultiplier,
bool UseContinuousColor, bool UseContinuousColor,
string ColorScheme, string ColorScheme,
@@ -16,7 +16,6 @@ namespace Cryville.EEW.Unity {
IReadOnlyCollection<EventSourceConfig> EventSources IReadOnlyCollection<EventSourceConfig> EventSources
) { ) {
public static Config Default => new( public static Config Default => new(
"Default",
"Default", "Default",
1f, 1f,
false, false,
@@ -27,9 +26,9 @@ namespace Cryville.EEW.Unity {
true, true,
new List<EventSourceConfig> { new List<EventSourceConfig> {
new JMAAtomEventSourceConfig(), new JMAAtomEventSourceConfig(Array.Empty<string>()),
new UpdateCheckerEventSourceConfig(), new UpdateCheckerEventSourceConfig(),
new WolfxEventSourceConfig(), new WolfxEventSourceConfig(Array.Empty<string>()),
} }
); );
} }

View File

@@ -26,7 +26,7 @@ namespace Cryville.EEW.Unity.Map {
_tiles.CacheDir = Application.temporaryCachePath; _tiles.CacheDir = Application.temporaryCachePath;
_camera.orthographicSize = 0.5f / MathF.Max(1, (float)_camera.pixelWidth / _camera.pixelHeight); _camera.orthographicSize = 0.5f / MathF.Max(1, (float)_camera.pixelWidth / _camera.pixelHeight);
_elementLayerZ = m_layerElement.transform.position.z; _elementLayerZ = m_layerElement.transform.position.z;
UpdateTransform(); _mapElementUpdated = true;
} }
void OnDestroy() { void OnDestroy() {
_tiles.Dispose(); _tiles.Dispose();
@@ -39,7 +39,9 @@ namespace Cryville.EEW.Unity.Map {
static readonly Rect _viewportRect = new(0, 0, 1, 1); static readonly Rect _viewportRect = new(0, 0, 1, 1);
Vector3? ppos; Vector3? ppos;
bool _mapElementUpdated;
void Update() { void Update() {
bool flag = false;
var cpos = Input.mousePosition; var cpos = Input.mousePosition;
bool isMouseInViewport = _viewportRect.Contains(_camera.ScreenToViewportPoint(Input.mousePosition)); bool isMouseInViewport = _viewportRect.Contains(_camera.ScreenToViewportPoint(Input.mousePosition));
if (Input.GetMouseButtonDown(0) && isMouseInViewport) { if (Input.GetMouseButtonDown(0) && isMouseInViewport) {
@@ -49,18 +51,25 @@ namespace Cryville.EEW.Unity.Map {
var delta = _camera.ScreenToWorldPoint(pos0) - _camera.ScreenToWorldPoint(cpos); var delta = _camera.ScreenToWorldPoint(pos0) - _camera.ScreenToWorldPoint(cpos);
transform.position += delta; transform.position += delta;
ppos = cpos; ppos = cpos;
UpdateTransform(); flag = true;
} }
if (Input.GetMouseButtonUp(0)) { if (Input.GetMouseButtonUp(0)) {
ppos = null; ppos = null;
} }
if (Input.mouseScrollDelta.y != 0 && isMouseInViewport) { if (Input.mouseScrollDelta.y != 0 && isMouseInViewport) {
Scale *= Mathf.Pow(2, -Input.mouseScrollDelta.y / 8); Scale *= Mathf.Pow(2, -Input.mouseScrollDelta.y / 8);
UpdateTransform(); flag = true;
}
if (_mapElementUpdated) {
_mapElementUpdated = false;
ZoomToMapElement();
flag = true;
}
if (flag) {
UpdateTransform(); // Ensure UpdateTransform is called at most once per frame for tiles to unload correctly
} }
} }
void ZoomToMapElement() {
public void OnMapElementUpdated() {
var aabb = m_layerElement.AABB; var aabb = m_layerElement.AABB;
if (aabb is not RectangleF b) return; if (aabb is not RectangleF b) return;
if (b.Width * _camera.pixelHeight < _camera.pixelWidth * b.Height) if (b.Width * _camera.pixelHeight < _camera.pixelWidth * b.Height)
@@ -70,7 +79,9 @@ namespace Cryville.EEW.Unity.Map {
Scale *= 0.6f; Scale *= 0.6f;
if (Scale < 0.01f) Scale = 0.01f; if (Scale < 0.01f) Scale = 0.01f;
transform.localPosition = new PointF(b.X + b.Width / 2, b.Y + b.Height / 2).ToVector2(); transform.localPosition = new PointF(b.X + b.Width / 2, b.Y + b.Height / 2).ToVector2();
UpdateTransform(); }
public void OnMapElementUpdated() {
_mapElementUpdated = true;
} }
void UpdateTransform() { void UpdateTransform() {

View File

@@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 5
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:

View File

@@ -39,19 +39,39 @@ namespace Cryville.EEW.Unity.Map {
return _displayingElements[index].AABB; return _displayingElements[index].AABB;
} }
public void SetSelected(ReportViewModel e) { public void SetSelected(ReportViewModel e, bool forced = false) {
if (_selected is not null) if (e == null) {
Remove(_selected); Remove(_selected);
if (e == null || _displayingReports.Contains(e)) {
_selected = null; _selected = null;
return; return;
} }
if (_displayingReports.Contains(e)) {
if (forced) return;
Remove(_selected);
_selected = null;
return;
}
if (e.IsExcludedFromHistory)
return;
if (!Add(e)) if (!Add(e))
return; return;
if (_selected is not null)
Remove(_selected);
_selected = e; _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; _current = e;
return true;
} }
public bool Add(ReportViewModel e) { public bool Add(ReportViewModel e) {
@@ -68,6 +88,7 @@ namespace Cryville.EEW.Unity.Map {
return true; return true;
} }
public void Remove(ReportViewModel e) { public void Remove(ReportViewModel e) {
if (_current == e) _current = null;
int index = _displayingReports.IndexOf(e); int index = _displayingReports.IndexOf(e);
if (index == -1) return; if (index == -1) return;
_displayingElements.RemoveAt(index); _displayingElements.RemoveAt(index);

View File

@@ -69,11 +69,14 @@ namespace Cryville.EEW.Unity {
"Legacy" => new LegacySeverityScheme(), "Legacy" => new LegacySeverityScheme(),
_ => throw new InvalidOperationException("Unknown severity scheme."), _ => throw new InvalidOperationException("Unknown severity scheme."),
}; };
SeverityColorMapping = config.SeverityColorMapping switch { SeverityColorMapping = config.ColorScheme switch {
"Default" => new DefaultSeverityColorMapping(config.SeverityColorMappingLuminanceMultiplier), "Default" => new DefaultSeverityColorMapping(config.SeverityColorMappingLuminanceMultiplier),
"SREV" => new SREVSeverityColorMapping(config.SeverityColorMappingLuminanceMultiplier), "SREV" => new SREVSeverityColorMapping(config.SeverityColorMappingLuminanceMultiplier),
"SREVBorder" => new SREVBorderSeverityColorMapping(config.SeverityColorMappingLuminanceMultiplier), "DichromaticYB" => new DichromaticSeverityColorMapping(0.62f, 0.20f, 90, config.SeverityColorMappingLuminanceMultiplier),
_ => throw new InvalidOperationException("Unknown severity color mapping."), "DichromaticRC" => new DichromaticSeverityColorMapping(0.62f, 0.25f, 30, config.SeverityColorMappingLuminanceMultiplier),
"DichromaticPG" => new DichromaticSeverityColorMapping(0.62f, 0.30f, -30, config.SeverityColorMappingLuminanceMultiplier),
"Monochromatic" => new MonochromaticSeverityColorMapping(config.SeverityColorMappingLuminanceMultiplier),
_ => throw new InvalidOperationException("Unknown color scheme."),
}; };
UseContinuousColor = config.UseContinuousColor; UseContinuousColor = config.UseContinuousColor;
ColorScheme = config.ColorScheme switch { ColorScheme = config.ColorScheme switch {

View File

@@ -79,15 +79,15 @@ namespace Cryville.EEW.Unity.UI {
m_currentView.SetViewModel(e, true); m_currentView.SetViewModel(e, true);
var keyProp = e.Properties.FirstOrDefault(); var keyProp = e.Properties.FirstOrDefault();
_displayingViews[_index].SetCurrent(true); _displayingViews[_index].SetCurrent(true);
_tickDown = Math.Max(0, keyProp?.Severity ?? 0) * 4 + 4; _tickDown = MathF.Exp(Math.Max(-1f, keyProp?.Severity ?? -1f) + 1);
m_currentView.gameObject.SetActive(true); m_currentView.gameObject.SetActive(true);
Worker.Instance.SetCurrent(e); Worker.Instance.SetCurrent(e);
} }
public void SetCurrent(ReportViewModel viewModel) { public void OnItemClicked(ReportViewModel viewModel) {
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); Worker.Instance.SetSelected(null);
} }
} }
} }

View File

@@ -51,7 +51,7 @@ namespace Cryville.EEW.Unity.UI {
m_button.onClick.AddListener(OnViewClicked); m_button.onClick.AddListener(OnViewClicked);
} }
void OnViewClicked() { void OnViewClicked() {
EventOngoingListView.Instance.SetCurrent(_viewModel); EventOngoingListView.Instance.OnItemClicked(_viewModel);
} }
void Update() { void Update() {
_dockRatioTweener.Advance(Time.deltaTime); _dockRatioTweener.Advance(Time.deltaTime);

View File

@@ -163,7 +163,8 @@ namespace Cryville.EEW.Unity {
readonly ConcurrentQueue<Action> _uiActionQueue = new(); readonly ConcurrentQueue<Action> _uiActionQueue = new();
ReportViewModel _latestHistoryReport; ReportViewModel _latestHistoryReport;
void OnReported(object sender, ReportViewModel e) { void OnReported(object sender, ReportViewModel e) {
Debug.Log(e); if (e.Model is Exception && e.Model is not SourceWorkerNetworkException)
Debug.LogError(e);
_ongoingReportManager.Report(e); _ongoingReportManager.Report(e);
_uiActionQueue.Enqueue(() => { _uiActionQueue.Enqueue(() => {
m_mapElementManager.SetSelected(e); m_mapElementManager.SetSelected(e);
@@ -176,20 +177,20 @@ 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_ongoingEventList.Add(item);
if (m_mapElementManager.Add(item)) { if (m_mapElementManager.Add(item)) {
m_mapElementManager.SetSelected(null); m_mapElementManager.SetSelected(null);
} }
m_ongoingEventList.Add(item);
m_cameraController.OnMapElementUpdated(); m_cameraController.OnMapElementUpdated();
}); });
} }
else if (action == CollectionChangeAction.Remove) { else if (action == CollectionChangeAction.Remove) {
_uiActionQueue.Enqueue(() => { _uiActionQueue.Enqueue(() => {
m_ongoingEventList.Remove(item);
m_mapElementManager.Remove(item); m_mapElementManager.Remove(item);
if (m_mapElementManager.Count == 0 && SharedSettings.Instance.DoSwitchBackToHistory && _latestHistoryReport is not null) { 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(); m_cameraController.OnMapElementUpdated();
}); });
} }
@@ -205,8 +206,9 @@ namespace Cryville.EEW.Unity {
m_cameraController.OnMapElementUpdated(); m_cameraController.OnMapElementUpdated();
} }
public void SetCurrent(ReportViewModel e) { public void SetCurrent(ReportViewModel e) {
m_mapElementManager.SetCurrent(e); if (m_mapElementManager.SetCurrent(e)) {
m_cameraController.OnMapElementUpdated(); m_cameraController.OnMapElementUpdated();
}
} }
void Update() { void Update() {

View File

@@ -1368,7 +1368,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 1180, y: 620} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1925427753 --- !u!114 &1925427753
MonoBehaviour: MonoBehaviour: