2026-06-21 09:37:54 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2020-12-22 03:13:43 +00:00
|
|
|
* 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;
|
2020-12-14 02:56:35 +00:00
|
|
|
using System.Collections.Generic;
|
2026-06-16 21:29:12 +01:00
|
|
|
using System.Linq;
|
2026-06-21 09:37:54 +01:00
|
|
|
using GameCult.Aetheria.EveRuntime;
|
2026-06-21 09:54:15 +01:00
|
|
|
using GameCult.Aetheria.State.Verse;
|
2026-06-16 21:29:12 +01:00
|
|
|
using GameCult.Eve.Surface;
|
2020-12-14 02:56:35 +00:00
|
|
|
using UnityEngine;
|
2026-06-16 21:29:12 +01:00
|
|
|
using UnityEngine.UIElements;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
|
|
|
|
public class MenuPanel : MonoBehaviour
|
|
|
|
|
{
|
2026-06-17 00:43:42 +01:00
|
|
|
[Serializable]
|
|
|
|
|
private sealed class MenuTabBinding
|
|
|
|
|
{
|
|
|
|
|
public MenuTab Tab;
|
|
|
|
|
public GameObject TabContents;
|
|
|
|
|
public string Label;
|
|
|
|
|
public bool RequireDock;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 02:56:35 +00:00
|
|
|
public RectTransform TabButtons;
|
2026-06-17 00:43:42 +01:00
|
|
|
[SerializeField] private MenuTabBinding[] TabBindings = Array.Empty<MenuTabBinding>();
|
2020-12-14 02:56:35 +00:00
|
|
|
|
|
|
|
|
public event Action<MenuTab> TabChanged;
|
|
|
|
|
|
2026-06-17 00:43:42 +01:00
|
|
|
private readonly Dictionary<MenuTab, MenuTabBinding> _tabs = new Dictionary<MenuTab, MenuTabBinding>();
|
|
|
|
|
private MenuTabBinding _current;
|
2026-06-16 21:29:12 +01:00
|
|
|
private UIDocument _tabSurfaceDocument;
|
2026-06-21 09:37:54 +01:00
|
|
|
private readonly AetheriaEveUnitySurfaceChrome _tabSurfaceChrome = new AetheriaEveUnitySurfaceChrome();
|
2026-06-29 09:33:22 +01:00
|
|
|
private AetheriaUnityObservedEntityIndex _observedEntityIndex;
|
|
|
|
|
private AetheriaUnityObservedDockingIndex _observedDockingIndex;
|
2020-12-18 13:48:03 +00:00
|
|
|
|
|
|
|
|
public MenuTab CurrentTab { get; private set; }
|
2020-12-14 02:56:35 +00:00
|
|
|
|
2026-06-28 12:34:47 +01:00
|
|
|
public void SetObservedEntityIndex(AetheriaUnityObservedEntityIndex observedEntityIndex)
|
|
|
|
|
{
|
2026-06-29 09:33:22 +01:00
|
|
|
if (!ReferenceEquals(_observedEntityIndex, observedEntityIndex))
|
|
|
|
|
{
|
|
|
|
|
_observedDockingIndex = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_observedEntityIndex = observedEntityIndex;
|
2026-06-28 12:34:47 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-14 02:56:35 +00:00
|
|
|
public void ShowTab(MenuTab tab)
|
|
|
|
|
{
|
|
|
|
|
gameObject.SetActive(true);
|
2026-06-16 21:29:12 +01:00
|
|
|
|
|
|
|
|
if (!_tabs.TryGetValue(tab, out var next))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_current == next)
|
|
|
|
|
{
|
|
|
|
|
RenderTabSurface();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-14 02:56:35 +00:00
|
|
|
|
|
|
|
|
if(_current != null)
|
|
|
|
|
{
|
|
|
|
|
_current.TabContents.SetActive(false);
|
|
|
|
|
}
|
2020-12-18 13:48:03 +00:00
|
|
|
|
|
|
|
|
CurrentTab = tab;
|
2026-06-16 21:29:12 +01:00
|
|
|
_current = next;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
|
|
|
|
_current.TabContents.SetActive(true);
|
2026-06-16 21:29:12 +01:00
|
|
|
RenderTabSurface();
|
2020-12-14 02:56:35 +00:00
|
|
|
|
|
|
|
|
TabChanged?.Invoke(tab);
|
|
|
|
|
}
|
2021-01-14 03:20:27 +00:00
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
2026-06-16 21:29:12 +01:00
|
|
|
if (TabButtons != null)
|
|
|
|
|
TabButtons.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
RenderTabSurface();
|
2021-01-14 03:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-17 02:45:52 +00:00
|
|
|
private void Awake()
|
2020-12-14 02:56:35 +00:00
|
|
|
{
|
2026-06-17 00:43:42 +01:00
|
|
|
foreach (var tabBinding in TabBindings)
|
2020-12-14 02:56:35 +00:00
|
|
|
{
|
2026-06-17 00:43:42 +01:00
|
|
|
if (tabBinding?.TabContents == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
tabBinding.TabContents.SetActive(false);
|
|
|
|
|
_tabs[tabBinding.Tab] = tabBinding;
|
2020-12-14 02:56:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-01-17 02:45:52 +00:00
|
|
|
|
2026-06-16 21:29:12 +01:00
|
|
|
private void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
HideTabSurface();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
if (_tabSurfaceDocument != null)
|
|
|
|
|
{
|
2026-06-21 09:37:54 +01:00
|
|
|
AetheriaEveUnitySurfaceHost.DestroyDocument(_tabSurfaceDocument);
|
2026-06-16 21:29:12 +01:00
|
|
|
_tabSurfaceDocument = null;
|
|
|
|
|
}
|
2026-06-29 02:08:46 +01:00
|
|
|
|
2026-06-29 09:33:22 +01:00
|
|
|
_observedDockingIndex = null;
|
2026-06-16 21:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RenderTabSurface()
|
|
|
|
|
{
|
|
|
|
|
if (_tabs.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (TabButtons != null)
|
|
|
|
|
TabButtons.gameObject.SetActive(false);
|
|
|
|
|
|
2026-06-21 09:37:54 +01:00
|
|
|
_tabSurfaceDocument = AetheriaEveUnitySurfaceHost.RenderRuntime(
|
|
|
|
|
transform,
|
|
|
|
|
_tabSurfaceDocument,
|
|
|
|
|
"Aetheria Runtime Menu Tabs Surface",
|
2026-06-29 05:27:10 +01:00
|
|
|
AetheriaRuntimeMenuTabsSurfaceBuilder.Build(
|
|
|
|
|
ToRuntimeTabKey(CurrentTab),
|
|
|
|
|
ResolveVisibleTabs()
|
|
|
|
|
.Select(tabBinding => new AetheriaRuntimeMenuTabModelOption(
|
|
|
|
|
ToRuntimeTabKey(tabBinding.Tab),
|
|
|
|
|
GetTabLabel(tabBinding),
|
|
|
|
|
(int)tabBinding.Tab)),
|
|
|
|
|
DateTime.UtcNow.ToString("O")),
|
2026-06-21 09:37:54 +01:00
|
|
|
HandleTabSurfaceCommand,
|
|
|
|
|
_tabSurfaceChrome);
|
2026-06-16 21:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleTabSurfaceCommand(EveSurfaceCommandRequest request)
|
|
|
|
|
{
|
2026-06-21 09:37:54 +01:00
|
|
|
if (!AetheriaRuntimeMenuTabsSurfaceCommands.TryRead(request, out var command))
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning($"Unknown runtime menu tab command: {request?.Command}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-16 21:29:12 +01:00
|
|
|
foreach (var tab in _tabs.Keys)
|
|
|
|
|
{
|
2026-06-21 09:37:54 +01:00
|
|
|
if (command.Kind == AetheriaRuntimeMenuTabCommandKind.SelectTab &&
|
2026-06-21 21:42:06 +01:00
|
|
|
string.Equals(command.TabKey, ToRuntimeTabKey(tab), StringComparison.Ordinal))
|
2026-06-16 21:29:12 +01:00
|
|
|
{
|
|
|
|
|
ShowTab(tab);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-21 09:37:54 +01:00
|
|
|
Debug.LogWarning($"Unknown runtime menu tab command: {request?.Command}");
|
2026-06-16 21:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideTabSurface()
|
|
|
|
|
{
|
|
|
|
|
if (_tabSurfaceDocument == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2026-06-21 09:37:54 +01:00
|
|
|
AetheriaEveUnitySurfaceHost.Hide(_tabSurfaceDocument);
|
2026-06-16 21:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-17 00:43:42 +01:00
|
|
|
private MenuTabBinding[] ResolveVisibleTabs()
|
2026-06-16 21:29:12 +01:00
|
|
|
{
|
2026-06-29 09:33:22 +01:00
|
|
|
var isDocked = TryResolveObservedDockingIndex(out var dockingIndex) &&
|
|
|
|
|
dockingIndex.TryResolveCurrentDocking(out var docking) &&
|
|
|
|
|
docking.IsDocked;
|
2026-06-16 21:29:12 +01:00
|
|
|
return _tabs.Values
|
2026-06-25 18:09:33 +01:00
|
|
|
.Where(tabBinding => !tabBinding.RequireDock || isDocked)
|
|
|
|
|
.Where(tabBinding => tabBinding.Tab != MenuTab.Local || isDocked)
|
2026-06-17 00:43:42 +01:00
|
|
|
.OrderBy(tabBinding => (int)tabBinding.Tab)
|
2026-06-16 21:29:12 +01:00
|
|
|
.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-29 09:33:22 +01:00
|
|
|
private bool TryResolveObservedDockingIndex(out AetheriaUnityObservedDockingIndex dockingIndex)
|
2026-06-25 18:09:33 +01:00
|
|
|
{
|
2026-06-29 09:33:22 +01:00
|
|
|
dockingIndex = null;
|
|
|
|
|
if (_observedEntityIndex == null)
|
2026-06-28 12:34:47 +01:00
|
|
|
return false;
|
2026-06-29 09:33:22 +01:00
|
|
|
|
|
|
|
|
dockingIndex = _observedDockingIndex ??= new AetheriaUnityObservedDockingIndex(_observedEntityIndex);
|
|
|
|
|
return true;
|
2026-06-25 18:09:33 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-17 00:43:42 +01:00
|
|
|
private static string GetTabLabel(MenuTabBinding tabBinding)
|
|
|
|
|
{
|
|
|
|
|
return string.IsNullOrWhiteSpace(tabBinding.Label)
|
|
|
|
|
? tabBinding.Tab.ToString()
|
|
|
|
|
: tabBinding.Label;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-21 21:42:06 +01:00
|
|
|
private static string ToRuntimeTabKey(MenuTab tab)
|
2026-06-16 21:29:12 +01:00
|
|
|
{
|
2026-06-21 21:42:06 +01:00
|
|
|
return AetheriaRuntimeMenuTabsSurfaceBuilder.NormalizeTabKey(tab.ToString());
|
2026-06-16 21:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-21 09:37:54 +01:00
|
|
|
// void Start()
|
2021-01-17 02:45:52 +00:00
|
|
|
// {
|
|
|
|
|
// ShowTab(MenuTab.Inventory);
|
|
|
|
|
// }
|
2020-12-14 02:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum MenuTab
|
|
|
|
|
{
|
|
|
|
|
Map,
|
2021-01-14 03:20:27 +00:00
|
|
|
Inventory,
|
2021-03-15 11:40:46 +00:00
|
|
|
Trade,
|
2021-04-19 04:35:46 +01:00
|
|
|
Galaxy,
|
|
|
|
|
Local
|
2026-06-16 21:29:12 +01:00
|
|
|
}
|