Sync daemon authority migration
This commit is contained in:
parent
030b4b5d74
commit
39a0dc8737
295 changed files with 25121 additions and 7360 deletions
|
|
@ -1,12 +1,13 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.EveRuntime;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using GameCult.Eve.Surface;
|
||||
using GameCult.Eve.UnityUIToolkit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
|
@ -21,12 +22,6 @@ public class MenuPanel : MonoBehaviour
|
|||
public bool RequireDock;
|
||||
}
|
||||
|
||||
private const string MenuTabsSurfaceType = "surface-state";
|
||||
private const string MenuTabsSurfaceSchema = "gamecult.eve.surface.v1";
|
||||
private const string MenuTabsSurfaceProviderId = "aetheria";
|
||||
private const string MenuTabsSurfaceProviderKind = "runtime.menu";
|
||||
private const string MenuTabsSurfaceId = "aetheria.runtime_menu.tabs";
|
||||
|
||||
public ActionGameManager GameManager;
|
||||
public RectTransform TabButtons;
|
||||
[SerializeField] private MenuTabBinding[] TabBindings = Array.Empty<MenuTabBinding>();
|
||||
|
|
@ -36,6 +31,7 @@ public class MenuPanel : MonoBehaviour
|
|||
private readonly Dictionary<MenuTab, MenuTabBinding> _tabs = new Dictionary<MenuTab, MenuTabBinding>();
|
||||
private MenuTabBinding _current;
|
||||
private UIDocument _tabSurfaceDocument;
|
||||
private readonly AetheriaEveUnitySurfaceChrome _tabSurfaceChrome = new AetheriaEveUnitySurfaceChrome();
|
||||
|
||||
public MenuTab CurrentTab { get; private set; }
|
||||
|
||||
|
|
@ -95,7 +91,7 @@ public class MenuPanel : MonoBehaviour
|
|||
{
|
||||
if (_tabSurfaceDocument != null)
|
||||
{
|
||||
Destroy(_tabSurfaceDocument.gameObject);
|
||||
AetheriaEveUnitySurfaceHost.DestroyDocument(_tabSurfaceDocument);
|
||||
_tabSurfaceDocument = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -108,61 +104,34 @@ public class MenuPanel : MonoBehaviour
|
|||
if (TabButtons != null)
|
||||
TabButtons.gameObject.SetActive(false);
|
||||
|
||||
var document = ResolveTabSurfaceDocument();
|
||||
document.gameObject.SetActive(true);
|
||||
|
||||
var root = document.rootVisualElement;
|
||||
root.Clear();
|
||||
root.style.flexGrow = 1;
|
||||
root.style.position = Position.Absolute;
|
||||
root.style.left = 0;
|
||||
root.style.top = 0;
|
||||
root.style.right = 0;
|
||||
root.style.bottom = 0;
|
||||
root.style.alignItems = Align.Center;
|
||||
root.style.justifyContent = Justify.FlexStart;
|
||||
root.style.paddingTop = 16;
|
||||
root.pickingMode = PickingMode.Ignore;
|
||||
|
||||
var shell = new VisualElement();
|
||||
shell.style.minWidth = 420;
|
||||
shell.style.maxWidth = 760;
|
||||
shell.style.backgroundColor = new Color(0.08f, 0.1f, 0.14f, 0.94f);
|
||||
shell.style.borderTopLeftRadius = 8;
|
||||
shell.style.borderTopRightRadius = 8;
|
||||
shell.style.borderBottomLeftRadius = 8;
|
||||
shell.style.borderBottomRightRadius = 8;
|
||||
shell.style.paddingLeft = 16;
|
||||
shell.style.paddingRight = 16;
|
||||
shell.style.paddingTop = 12;
|
||||
shell.style.paddingBottom = 12;
|
||||
shell.style.borderLeftWidth = 1;
|
||||
shell.style.borderRightWidth = 1;
|
||||
shell.style.borderTopWidth = 1;
|
||||
shell.style.borderBottomWidth = 1;
|
||||
shell.style.borderLeftColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
shell.style.borderRightColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
shell.style.borderTopColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
shell.style.borderBottomColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
shell.pickingMode = PickingMode.Position;
|
||||
root.Add(shell);
|
||||
|
||||
var lowerer = new EveUiToolkitSurfaceLowerer();
|
||||
shell.Add(lowerer.Lower(BuildTabSurfaceDefinition(), HandleTabSurfaceCommand));
|
||||
_tabSurfaceDocument = AetheriaEveUnitySurfaceHost.RenderRuntime(
|
||||
transform,
|
||||
_tabSurfaceDocument,
|
||||
"Aetheria Runtime Menu Tabs Surface",
|
||||
AetheriaRuntimeMenuTabsSurfaceBuilder.Build(ProjectTabSurfaceState()),
|
||||
HandleTabSurfaceCommand,
|
||||
_tabSurfaceChrome);
|
||||
}
|
||||
|
||||
private void HandleTabSurfaceCommand(EveSurfaceCommandRequest request)
|
||||
{
|
||||
if (!AetheriaRuntimeMenuTabsSurfaceCommands.TryRead(request, out var command))
|
||||
{
|
||||
Debug.LogWarning($"Unknown runtime menu tab command: {request?.Command}");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var tab in _tabs.Keys)
|
||||
{
|
||||
if (string.Equals(request.Command, GetTabCommand(tab), StringComparison.Ordinal))
|
||||
if (command.Kind == AetheriaRuntimeMenuTabCommandKind.SelectTab &&
|
||||
string.Equals(command.TabKey, TabKey(tab), StringComparison.Ordinal))
|
||||
{
|
||||
ShowTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.LogWarning($"Unknown runtime menu tab command: {request.Command}");
|
||||
Debug.LogWarning($"Unknown runtime menu tab command: {request?.Command}");
|
||||
}
|
||||
|
||||
private void HideTabSurface()
|
||||
|
|
@ -170,68 +139,21 @@ public class MenuPanel : MonoBehaviour
|
|||
if (_tabSurfaceDocument == null)
|
||||
return;
|
||||
|
||||
_tabSurfaceDocument.rootVisualElement.Clear();
|
||||
_tabSurfaceDocument.gameObject.SetActive(false);
|
||||
AetheriaEveUnitySurfaceHost.Hide(_tabSurfaceDocument);
|
||||
}
|
||||
|
||||
private UIDocument ResolveTabSurfaceDocument()
|
||||
{
|
||||
if (_tabSurfaceDocument != null)
|
||||
return _tabSurfaceDocument;
|
||||
|
||||
var host = new GameObject("Aetheria Runtime Menu Tabs Surface");
|
||||
host.transform.SetParent(transform, false);
|
||||
var document = host.AddComponent<UIDocument>();
|
||||
document.sortingOrder = 1000;
|
||||
host.SetActive(false);
|
||||
_tabSurfaceDocument = document;
|
||||
return document;
|
||||
}
|
||||
|
||||
private EveSurfaceDocument BuildTabSurfaceDefinition()
|
||||
private AetheriaRuntimeMenuTabsSurfaceState ProjectTabSurfaceState()
|
||||
{
|
||||
var visibleTabs = ResolveVisibleTabs();
|
||||
var commands = visibleTabs
|
||||
.Select(tabBinding => new EveCommandTemplate(
|
||||
GetTabCommand(tabBinding.Tab),
|
||||
GetTabLabel(tabBinding),
|
||||
"unity-uitoolkit"))
|
||||
.ToArray();
|
||||
|
||||
var buttons = visibleTabs
|
||||
.Select(tabBinding =>
|
||||
{
|
||||
var label = GetTabLabel(tabBinding);
|
||||
if (tabBinding.Tab == CurrentTab)
|
||||
label = $"{label} *";
|
||||
|
||||
return Button(
|
||||
$"{MenuTabsSurfaceId}.{tabBinding.Tab.ToString().ToLowerInvariant()}",
|
||||
label,
|
||||
GetTabCommand(tabBinding.Tab));
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return new EveSurfaceDocument(
|
||||
MenuTabsSurfaceType,
|
||||
MenuTabsSurfaceSchema,
|
||||
MenuTabsSurfaceProviderId,
|
||||
MenuTabsSurfaceProviderKind,
|
||||
"Runtime Menu Tabs",
|
||||
version: 1,
|
||||
DateTime.UtcNow.ToString("O"),
|
||||
new EveSurfaceTree(
|
||||
MenuTabsSurfaceId,
|
||||
Node(
|
||||
$"{MenuTabsSurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
Text(
|
||||
$"{MenuTabsSurfaceId}.current",
|
||||
$"Current: {CurrentTab}"),
|
||||
ButtonRow($"{MenuTabsSurfaceId}.tabs", buttons)),
|
||||
Array.Empty<EveStyleToken>()),
|
||||
commands);
|
||||
return new AetheriaRuntimeMenuTabsSurfaceState(
|
||||
TabKey(CurrentTab),
|
||||
visibleTabs
|
||||
.Select(tabBinding => new AetheriaRuntimeMenuTabSurfaceEntry(
|
||||
TabKey(tabBinding.Tab),
|
||||
GetTabLabel(tabBinding),
|
||||
tabBinding.Tab == CurrentTab))
|
||||
.ToArray(),
|
||||
DateTime.UtcNow.ToString("O"));
|
||||
}
|
||||
|
||||
private MenuTabBinding[] ResolveVisibleTabs()
|
||||
|
|
@ -250,42 +172,12 @@ public class MenuPanel : MonoBehaviour
|
|||
: tabBinding.Label;
|
||||
}
|
||||
|
||||
private static string GetTabCommand(MenuTab tab)
|
||||
private static string TabKey(MenuTab tab)
|
||||
{
|
||||
return $"aetheria.runtime_menu.tab.{tab.ToString().ToLowerInvariant()}";
|
||||
return tab.ToString().ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value) });
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label), ("command", command) });
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params EveSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params EveSurfaceComponent[] children)
|
||||
{
|
||||
return new EveSurfaceComponent(
|
||||
id,
|
||||
kind,
|
||||
props.ToDictionary(prop => prop.Key, prop => prop.Value, StringComparer.Ordinal),
|
||||
children ?? Array.Empty<EveSurfaceComponent>());
|
||||
}
|
||||
|
||||
// void Start()
|
||||
// void Start()
|
||||
// {
|
||||
// ShowTab(MenuTab.Inventory);
|
||||
// }
|
||||
|
|
|
|||
Loading…
Reference in a new issue