fixes and adjustments
This commit is contained in:
parent
ec4fd39977
commit
2dbbdb3f0e
File diff suppressed because one or more lines are too long
@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Intrepid.GameManagers;
|
||||
using Intrepid.Gameplay.Entities.Player.ActionBelt.Events;
|
||||
using Intrepid.Gameplay.Entities.Player.ActionBelt.UI;
|
||||
using Intrepid.Gameplay.Entities.Player.Events;
|
||||
using Intrepid.Gameplay.Entities.Player.PDA.Events;
|
||||
using Intrepid.Gameplay.Entities.Player.PDA.UI;
|
||||
using Intrepid.Gameplay.Entities.Player.Sentinel.Cadence.UI;
|
||||
using Intrepid.Gameplay.Entities.Player.UI;
|
||||
@ -11,33 +12,68 @@ using Intrepid.SimpleEvents;
|
||||
using Intrepid.Utilities;
|
||||
using Intrepid.Window;
|
||||
using Intrepid.Window.Data;
|
||||
using Intrepid.Window.Events;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Intrepid.Gameplay.Codex.UI
|
||||
{
|
||||
public class CodexWindowManager : EventListener
|
||||
{
|
||||
[GroupConfigurations, SerializeField] private CodexCadenceUI codexCadenceUI;
|
||||
[GroupConfigurations, SerializeField] private CodexVitalityUI codexVitalityUI;
|
||||
[GroupConfigurations, SerializeField] private CodexGadgetsUI codexGadgetsUI;
|
||||
[GroupConfigurations, SerializeField] private CodexActionBeltUI codexActionBeltUI;
|
||||
[GroupConfigurations, SerializeField] private PDADeviceUI pdaDeviceUI;
|
||||
private enum CodexLayoutMode
|
||||
{
|
||||
None,
|
||||
Hud,
|
||||
ActionBelt,
|
||||
Pda
|
||||
}
|
||||
|
||||
[GroupConfigurations, SerializeField, Min(0f)] private float closeOpenSeparation = 0.1f;
|
||||
[GroupConfigurations, SerializeField, Min(0f)] private float transitionCooldown = 0.4f;
|
||||
|
||||
[GroupInjections, SerializeField] private CodexCadenceUI codexCadenceUI;
|
||||
[GroupInjections, SerializeField] private CodexVitalityUI codexVitalityUI;
|
||||
[GroupInjections, SerializeField] private CodexGadgetsUI codexGadgetsUI;
|
||||
[GroupInjections, SerializeField] private CodexActionBeltUI codexActionBeltUI;
|
||||
[GroupInjections, SerializeField] private PDADeviceUI pdaDeviceUI;
|
||||
|
||||
private Dictionary<WindowData, Window.Window> WindowsMap { get; } = new();
|
||||
private Stack<List<Window.Window>> StackWindows { get; } = new();
|
||||
|
||||
private void Add(ManagedWindowUI mwUI) => WindowsMap.Add(mwUI.WindowData, mwUI.ManagedWindow);
|
||||
private bool IsPlayerCommandGranted { get; set; }
|
||||
private bool IsActionBeltRequested { get; set; }
|
||||
private bool IsPdaRequested { get; set; }
|
||||
|
||||
private bool IsLayoutDirty { get; set; }
|
||||
private Coroutine LayoutRoutine { get; set; }
|
||||
private CodexLayoutMode CurrentLayout { get; set; } = CodexLayoutMode.None;
|
||||
|
||||
public bool IsTransitioning => LayoutRoutine is not null;
|
||||
|
||||
private void Add(ManagedWindowUI mwUI)
|
||||
{
|
||||
if (mwUI.IsNull()) return;
|
||||
if (mwUI.WindowData.IsNull()) return;
|
||||
if (mwUI.ManagedWindow.IsNull()) return;
|
||||
|
||||
WindowsMap[mwUI.WindowData] = mwUI.ManagedWindow;
|
||||
}
|
||||
|
||||
protected override void InitializeVariables()
|
||||
{
|
||||
StackWindows.Clear();
|
||||
WindowsMap.Clear();
|
||||
|
||||
Add(codexCadenceUI);
|
||||
Add(codexVitalityUI);
|
||||
Add(codexGadgetsUI);
|
||||
Add(codexActionBeltUI);
|
||||
Add(pdaDeviceUI);
|
||||
|
||||
IsPlayerCommandGranted = false;
|
||||
IsActionBeltRequested = false;
|
||||
IsPdaRequested = false;
|
||||
|
||||
IsLayoutDirty = false;
|
||||
LayoutRoutine = null;
|
||||
CurrentLayout = CodexLayoutMode.None;
|
||||
|
||||
DisableAllWindows();
|
||||
}
|
||||
|
||||
@ -47,95 +83,240 @@ namespace Intrepid.Gameplay.Codex.UI
|
||||
|
||||
protected override void Subscriptions()
|
||||
{
|
||||
Subscribe<WindowOpenEvent>(WhenWindowOpen);
|
||||
Subscribe<WindowCloseEvent>(WhenWindowClose);
|
||||
Subscribe<PlayerCommandGrantedEvent>(WhenPlayerCommandGranted);
|
||||
Subscribe<PlayerCommandRevokedEvent>(WhenPlayerCommandRevoked);
|
||||
|
||||
Subscribe<ActionBeltUIOpenEvent>(WhenActionBeltUIOpen);
|
||||
Subscribe<ActionBeltUICloseEvent>(WhenActionBeltUIClose);
|
||||
|
||||
Subscribe<PlayerCommandGrantedEvent>(_ =>
|
||||
{
|
||||
WindowsMap[codexCadenceUI.WindowData].Open();
|
||||
WindowsMap[codexVitalityUI.WindowData].Open();
|
||||
WindowsMap[codexGadgetsUI.WindowData].Open();
|
||||
});
|
||||
Subscribe<PlayerCommandRevokedEvent>(_ =>
|
||||
{
|
||||
WindowsMap[codexCadenceUI.WindowData].Close();
|
||||
WindowsMap[codexVitalityUI.WindowData].Close();
|
||||
WindowsMap[codexGadgetsUI.WindowData].Close();
|
||||
});
|
||||
Subscribe<PDAOpenRequestEvent>(WhenPDAOpenRequest);
|
||||
Subscribe<PDACloseRequestEvent>(WhenPDACloseRequest);
|
||||
}
|
||||
|
||||
private void WhenWindowOpen(WindowOpenEvent e)
|
||||
private void WhenPlayerCommandGranted(PlayerCommandGrantedEvent e)
|
||||
{
|
||||
if (e.ShouldStack)
|
||||
{
|
||||
var stackableWindows = WindowsMap
|
||||
.Values
|
||||
.Where(w => w.ConditionType is WindowConditionType.Opened)
|
||||
.ToList();
|
||||
StackWindows.Push(stackableWindows);
|
||||
stackableWindows.ForEach(window =>
|
||||
{
|
||||
window.Close();
|
||||
});
|
||||
}
|
||||
foreach (var windowData in e.WindowDataList)
|
||||
{
|
||||
if (WindowsMap.TryGetValue(windowData, out var window))
|
||||
{
|
||||
window.Open();
|
||||
}
|
||||
}
|
||||
if (IsPlayerCommandGranted) return;
|
||||
|
||||
IsPlayerCommandGranted = true;
|
||||
RequestRefreshLayout();
|
||||
}
|
||||
|
||||
private void WhenWindowClose(WindowCloseEvent e)
|
||||
private void WhenPlayerCommandRevoked(PlayerCommandRevokedEvent e)
|
||||
{
|
||||
foreach (var windowData in e.WindowDataList)
|
||||
{
|
||||
if (WindowsMap.TryGetValue(windowData, out var window))
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
if (!IsPlayerCommandGranted) return;
|
||||
|
||||
UnStackWindows();
|
||||
|
||||
return;
|
||||
|
||||
void UnStackWindows()
|
||||
{
|
||||
if (StackWindows.Count <= 0) return;
|
||||
var stackedWindows = StackWindows.Pop();
|
||||
foreach (var window in stackedWindows)
|
||||
{
|
||||
window.Open();
|
||||
}
|
||||
}
|
||||
IsPlayerCommandGranted = false;
|
||||
RequestRefreshLayout();
|
||||
}
|
||||
|
||||
private void WhenActionBeltUIOpen(ActionBeltUIOpenEvent e)
|
||||
{
|
||||
Proxy.Instance.EventBus.Raise(new WindowOpenEvent
|
||||
{
|
||||
ShouldStack = true,
|
||||
WindowDataList = new[] { codexActionBeltUI.WindowData },
|
||||
});
|
||||
if (IsActionBeltRequested) return;
|
||||
|
||||
IsActionBeltRequested = true;
|
||||
RequestRefreshLayout();
|
||||
}
|
||||
|
||||
private void WhenActionBeltUIClose(ActionBeltUICloseEvent e)
|
||||
{
|
||||
Proxy.Instance.EventBus.Raise(new WindowCloseEvent
|
||||
if (!IsActionBeltRequested) return;
|
||||
|
||||
IsActionBeltRequested = false;
|
||||
RequestRefreshLayout();
|
||||
}
|
||||
|
||||
private void WhenPDAOpenRequest(PDAOpenRequestEvent e)
|
||||
{
|
||||
if (IsPdaRequested) return;
|
||||
|
||||
IsPdaRequested = true;
|
||||
RequestRefreshLayout();
|
||||
}
|
||||
|
||||
private void WhenPDACloseRequest(PDACloseRequestEvent e)
|
||||
{
|
||||
if (!IsPdaRequested) return;
|
||||
|
||||
IsPdaRequested = false;
|
||||
RequestRefreshLayout();
|
||||
}
|
||||
|
||||
private void RequestRefreshLayout()
|
||||
{
|
||||
IsLayoutDirty = true;
|
||||
|
||||
if (LayoutRoutine is not null)
|
||||
{
|
||||
WindowDataList = new[] { codexActionBeltUI.WindowData },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
LayoutRoutine = StartCoroutine(RefreshLayoutRoutine());
|
||||
}
|
||||
|
||||
private IEnumerator RefreshLayoutRoutine()
|
||||
{
|
||||
while (IsLayoutDirty)
|
||||
{
|
||||
IsLayoutDirty = false;
|
||||
|
||||
var desiredLayout = ResolveDesiredLayout();
|
||||
|
||||
if (desiredLayout == CurrentLayout)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return TransitionTo(desiredLayout);
|
||||
}
|
||||
|
||||
LayoutRoutine = null;
|
||||
}
|
||||
|
||||
private CodexLayoutMode ResolveDesiredLayout()
|
||||
{
|
||||
if (IsPdaRequested)
|
||||
{
|
||||
return CodexLayoutMode.Pda;
|
||||
}
|
||||
|
||||
if (IsActionBeltRequested)
|
||||
{
|
||||
return CodexLayoutMode.ActionBelt;
|
||||
}
|
||||
|
||||
if (IsPlayerCommandGranted)
|
||||
{
|
||||
return CodexLayoutMode.Hud;
|
||||
}
|
||||
|
||||
return CodexLayoutMode.None;
|
||||
}
|
||||
|
||||
private IEnumerator TransitionTo(CodexLayoutMode targetLayout)
|
||||
{
|
||||
CloseAllLayouts();
|
||||
CurrentLayout = CodexLayoutMode.None;
|
||||
|
||||
yield return WaitUnscaled(closeOpenSeparation);
|
||||
|
||||
// Reavalia depois de fechar, porque outro evento pode ter chegado no meio da transição.
|
||||
targetLayout = ResolveDesiredLayout();
|
||||
|
||||
OpenLayout(targetLayout);
|
||||
CurrentLayout = targetLayout;
|
||||
|
||||
yield return WaitUnscaled(transitionCooldown);
|
||||
}
|
||||
|
||||
private IEnumerator WaitUnscaled(float duration)
|
||||
{
|
||||
if (duration <= 0f)
|
||||
{
|
||||
yield return null;
|
||||
yield break;
|
||||
}
|
||||
|
||||
var elapsed = 0f;
|
||||
|
||||
while (elapsed < duration)
|
||||
{
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenLayout(CodexLayoutMode layout)
|
||||
{
|
||||
switch (layout)
|
||||
{
|
||||
case CodexLayoutMode.None:
|
||||
break;
|
||||
|
||||
case CodexLayoutMode.Hud:
|
||||
OpenHud();
|
||||
break;
|
||||
|
||||
case CodexLayoutMode.ActionBelt:
|
||||
OpenActionBelt();
|
||||
break;
|
||||
|
||||
case CodexLayoutMode.Pda:
|
||||
OpenPda();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseAllLayouts()
|
||||
{
|
||||
CloseHud();
|
||||
CloseActionBelt();
|
||||
ClosePda();
|
||||
}
|
||||
|
||||
private void OpenHud()
|
||||
{
|
||||
Open(codexCadenceUI);
|
||||
Open(codexVitalityUI);
|
||||
Open(codexGadgetsUI);
|
||||
}
|
||||
|
||||
private void CloseHud()
|
||||
{
|
||||
Close(codexCadenceUI);
|
||||
Close(codexVitalityUI);
|
||||
Close(codexGadgetsUI);
|
||||
}
|
||||
|
||||
private void OpenActionBelt()
|
||||
{
|
||||
Open(codexActionBeltUI);
|
||||
}
|
||||
|
||||
private void CloseActionBelt()
|
||||
{
|
||||
Close(codexActionBeltUI);
|
||||
}
|
||||
|
||||
private void OpenPda()
|
||||
{
|
||||
Open(pdaDeviceUI);
|
||||
}
|
||||
|
||||
private void ClosePda()
|
||||
{
|
||||
Close(pdaDeviceUI);
|
||||
}
|
||||
|
||||
private void Open(ManagedWindowUI mwUI)
|
||||
{
|
||||
if (mwUI.IsNull()) return;
|
||||
|
||||
if (!WindowsMap.TryGetValue(mwUI.WindowData, out var window)) return;
|
||||
if (window.IsNull()) return;
|
||||
|
||||
if (window.ConditionType is WindowConditionType.Opened) return;
|
||||
|
||||
window.Open();
|
||||
}
|
||||
|
||||
private void Close(ManagedWindowUI mwUI)
|
||||
{
|
||||
if (mwUI.IsNull()) return;
|
||||
|
||||
if (!WindowsMap.TryGetValue(mwUI.WindowData, out var window)) return;
|
||||
if (window.IsNull()) return;
|
||||
|
||||
if (window.ConditionType is not WindowConditionType.Opened) return;
|
||||
|
||||
window.Close();
|
||||
}
|
||||
|
||||
private void DisableAllWindows()
|
||||
{
|
||||
foreach (var window in WindowsMap.Values)
|
||||
{
|
||||
if (window.IsNull()) continue;
|
||||
|
||||
if (window.WindowData.ShouldBeKeptAlwaysEnabled)
|
||||
{
|
||||
window.Close();
|
||||
|
||||
@ -89,9 +89,9 @@ namespace Intrepid.Gameplay.Entities.Player.ActionBelt.UI
|
||||
returnRoutine = null;
|
||||
}
|
||||
|
||||
public void UpdateContent(ActionEnvelope focus)
|
||||
public void UpdateContent(ActionEnvelope envelope)
|
||||
{
|
||||
if (focus.ActivationMode == ActionActivationMode.Instant)
|
||||
if (envelope.ActivationMode == ActionActivationMode.Instant)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
@ -79,9 +79,16 @@ namespace Intrepid.Gameplay.Entities.Player.ActionBelt.UI
|
||||
private IEnumerator UpdateContentNextFrame()
|
||||
{
|
||||
yield return null;
|
||||
var focus = GetFocus();
|
||||
activationProgress.UpdateContent(focus);
|
||||
center.UpdateContent(focus);
|
||||
var envelope = GetFocus();
|
||||
if (envelope.IsNotNull())
|
||||
{
|
||||
activationProgress.UpdateContent(envelope);
|
||||
center.UpdateContent(envelope);
|
||||
}
|
||||
else
|
||||
{
|
||||
DLogger.LogWarn("envelope is null, ui trying to show something is valid no more");
|
||||
}
|
||||
}
|
||||
|
||||
public override void BeforeOpen()
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
using Intrepid.SimpleEvents;
|
||||
|
||||
namespace Intrepid.Gameplay.Entities.Player.PDA.Events
|
||||
{
|
||||
public class PDACloseRequestEvent : IEventBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7699dc3e5b9d4ed39ba7411cd328325f
|
||||
timeCreated: 1783498179
|
||||
@ -0,0 +1,9 @@
|
||||
using Intrepid.SimpleEvents;
|
||||
|
||||
namespace Intrepid.Gameplay.Entities.Player.PDA.Events
|
||||
{
|
||||
public class PDAOpenRequestEvent : IEventBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4cb15e9263a54c6c93700bde22be1056
|
||||
timeCreated: 1783498152
|
||||
@ -1,11 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Intrepid.GameManagers;
|
||||
using Intrepid.Gameplay.Entities.Player.PDA.Events;
|
||||
using Intrepid.Integration.Input;
|
||||
using Intrepid.Structures;
|
||||
using Intrepid.Utilities;
|
||||
using Intrepid.Window.Data;
|
||||
using Intrepid.Window.Events;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Intrepid.Gameplay.Entities.Player.Sentinel.StateMachine.States
|
||||
@ -13,7 +10,6 @@ namespace Intrepid.Gameplay.Entities.Player.Sentinel.StateMachine.States
|
||||
public class SentinelStatePDA : SentinelState
|
||||
{
|
||||
[GroupConfigurations, SerializeField] private AnimationClip pda;
|
||||
[GroupConfigurations, SerializeField] private WindowData pdaWindowData;
|
||||
|
||||
public override SentinelStateType GetStateKey()
|
||||
{
|
||||
@ -31,14 +27,7 @@ namespace Intrepid.Gameplay.Entities.Player.Sentinel.StateMachine.States
|
||||
public override void RunOnFirstFrameOnly()
|
||||
{
|
||||
InputService.Instance.ChangeInputSchema(InputSchema.PDA);
|
||||
Proxy.Instance.EventBus.Raise(new WindowOpenEvent
|
||||
{
|
||||
ShouldStack = true,
|
||||
WindowDataList = new List<WindowData>
|
||||
{
|
||||
pdaWindowData
|
||||
},
|
||||
});
|
||||
Proxy.Instance.EventBus.Raise(new PDAOpenRequestEvent());
|
||||
}
|
||||
|
||||
protected override void RunOnEnter(ParameterStore ps)
|
||||
@ -51,13 +40,7 @@ namespace Intrepid.Gameplay.Entities.Player.Sentinel.StateMachine.States
|
||||
protected override void RunOnExit()
|
||||
{
|
||||
InputService.Instance.ChangeInputSchema(InputSchema.Sentinel);
|
||||
Proxy.Instance.EventBus.Raise(new WindowCloseEvent
|
||||
{
|
||||
WindowDataList = new List<WindowData>
|
||||
{
|
||||
pdaWindowData
|
||||
},
|
||||
});
|
||||
Proxy.Instance.EventBus.Raise(new PDACloseRequestEvent());
|
||||
}
|
||||
|
||||
public override void RunOnUpdate()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user