Read menu docking through current typed state
This commit is contained in:
parent
2a03386ddd
commit
ca8b5858a2
4 changed files with 68 additions and 72 deletions
|
|
@ -34,21 +34,9 @@ public class MenuPanel : MonoBehaviour
|
|||
private MenuTabBinding _current;
|
||||
private UIDocument _tabSurfaceDocument;
|
||||
private readonly AetheriaEveUnitySurfaceChrome _tabSurfaceChrome = new AetheriaEveUnitySurfaceChrome();
|
||||
private AetheriaUnityObservedEntityIndex _observedEntityIndex;
|
||||
private AetheriaUnityObservedDockingIndex _observedDockingIndex;
|
||||
|
||||
public MenuTab CurrentTab { get; private set; }
|
||||
|
||||
public void SetObservedEntityIndex(AetheriaUnityObservedEntityIndex observedEntityIndex)
|
||||
{
|
||||
if (!ReferenceEquals(_observedEntityIndex, observedEntityIndex))
|
||||
{
|
||||
_observedDockingIndex = null;
|
||||
}
|
||||
|
||||
_observedEntityIndex = observedEntityIndex;
|
||||
}
|
||||
|
||||
public void ShowTab(MenuTab tab)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
|
@ -108,8 +96,6 @@ public class MenuPanel : MonoBehaviour
|
|||
AetheriaEveUnitySurfaceHost.DestroyDocument(_tabSurfaceDocument);
|
||||
_tabSurfaceDocument = null;
|
||||
}
|
||||
|
||||
_observedDockingIndex = null;
|
||||
}
|
||||
|
||||
private void RenderTabSurface()
|
||||
|
|
@ -162,8 +148,7 @@ public class MenuPanel : MonoBehaviour
|
|||
|
||||
private MenuTabBinding[] ResolveVisibleTabs()
|
||||
{
|
||||
var isDocked = TryResolveObservedDockingIndex(out var dockingIndex) &&
|
||||
dockingIndex.TryResolveCurrentDocking(out var docking) &&
|
||||
var isDocked = TryResolveCurrentDocking(out var docking) &&
|
||||
docking.IsDocked;
|
||||
return _tabs.Values
|
||||
.Where(tabBinding => !tabBinding.RequireDock || isDocked)
|
||||
|
|
@ -172,14 +157,21 @@ public class MenuPanel : MonoBehaviour
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
private bool TryResolveObservedDockingIndex(out AetheriaUnityObservedDockingIndex dockingIndex)
|
||||
private static bool TryResolveCurrentDocking(out AetheriaRuntimeCurrentDockingDocument docking)
|
||||
{
|
||||
dockingIndex = null;
|
||||
if (_observedEntityIndex == null)
|
||||
docking = null;
|
||||
try
|
||||
{
|
||||
docking = AetheriaUnityRuntimeClientProvider
|
||||
.RuntimeState("unity-runtime-menu-tabs")
|
||||
.CurrentDockingState();
|
||||
return docking != null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to read Aetheria runtime docking for menu tabs: {ex.Message}");
|
||||
return false;
|
||||
|
||||
dockingIndex = _observedDockingIndex ??= new AetheriaUnityObservedDockingIndex(_observedEntityIndex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetTabLabel(MenuTabBinding tabBinding)
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ public class TradeMenu : MonoBehaviour
|
|||
private UIDocument _filterSurfaceDocument;
|
||||
private UIDocument _rowActionSurfaceDocument;
|
||||
private UIDocument _tradeItemSurfaceDocument;
|
||||
private AetheriaUnityObservedEntityIndex _observedEntityIndex;
|
||||
private AetheriaUnityObservedDockingIndex _observedDockingIndex;
|
||||
private readonly AetheriaEveUnitySurfaceChrome _cargoSelectorSurfaceChrome = PanelChrome(360f, 420f, Align.FlexEnd);
|
||||
private readonly AetheriaEveUnitySurfaceChrome _filterSurfaceChrome = PanelChrome(420f, 520f, Align.FlexStart);
|
||||
private readonly AetheriaEveUnitySurfaceChrome _rowActionSurfaceChrome = PanelChrome(320f, 360f, Align.FlexStart);
|
||||
|
|
@ -51,16 +49,6 @@ public class TradeMenu : MonoBehaviour
|
|||
|
||||
public EquippedCargoBay Inventory { get; set; }
|
||||
|
||||
public void SetObservedEntityIndex(AetheriaUnityObservedEntityIndex observedEntityIndex)
|
||||
{
|
||||
if (!ReferenceEquals(_observedEntityIndex, observedEntityIndex))
|
||||
{
|
||||
_observedDockingIndex = null;
|
||||
}
|
||||
|
||||
_observedEntityIndex = observedEntityIndex;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (!TryResolveCurrentDocking(out var docking) ||
|
||||
|
|
@ -514,26 +502,34 @@ public class TradeMenu : MonoBehaviour
|
|||
|
||||
private AetheriaRuntimeStationRefitDocument StationRefitSnapshot()
|
||||
{
|
||||
return TryResolveObservedDockingIndex(out var dockingIndex)
|
||||
? dockingIndex.StationRefitSnapshot()
|
||||
: null;
|
||||
try
|
||||
{
|
||||
return AetheriaUnityRuntimeClientProvider
|
||||
.RuntimeState("unity-trade")
|
||||
.CurrentStationRefit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to read Aetheria station refit for trade menu: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryResolveCurrentDocking(out AetheriaRuntimeCurrentDockingDocument docking)
|
||||
{
|
||||
docking = null;
|
||||
return TryResolveObservedDockingIndex(out var dockingIndex) &&
|
||||
dockingIndex.TryResolveCurrentDocking(out docking);
|
||||
}
|
||||
|
||||
private bool TryResolveObservedDockingIndex(out AetheriaUnityObservedDockingIndex dockingIndex)
|
||||
{
|
||||
dockingIndex = null;
|
||||
if (_observedEntityIndex == null)
|
||||
try
|
||||
{
|
||||
docking = AetheriaUnityRuntimeClientProvider
|
||||
.RuntimeState("unity-trade")
|
||||
.CurrentDockingState();
|
||||
return docking != null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to read Aetheria runtime docking for trade menu: {ex.Message}");
|
||||
return false;
|
||||
|
||||
dockingIndex = _observedDockingIndex ??= new AetheriaUnityObservedDockingIndex(_observedEntityIndex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryResolveStationRefitCargoTarget(
|
||||
|
|
@ -581,11 +577,6 @@ public class TradeMenu : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private void ClearClientCaches()
|
||||
{
|
||||
_observedDockingIndex = null;
|
||||
}
|
||||
|
||||
private AetheriaRuntimeCatalogSnapshot CatalogSnapshot()
|
||||
{
|
||||
try
|
||||
|
|
@ -1258,8 +1249,6 @@ public class TradeMenu : MonoBehaviour
|
|||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ClearClientCaches();
|
||||
|
||||
if (_cargoSelectorSurfaceDocument != null)
|
||||
{
|
||||
AetheriaEveUnitySurfaceHost.DestroyDocument(_cargoSelectorSurfaceDocument);
|
||||
|
|
|
|||
Loading…
Reference in a new issue