Cozy Wather + buld systeme
This commit is contained in:
@@ -39,13 +39,25 @@ namespace Ashwild.UI
|
||||
private UIPanel inventoryPanel;
|
||||
|
||||
/// <summary>
|
||||
/// True while a non-inventory panel is open — i.e. the game is paused.
|
||||
/// The registered construction menu panel (resolved by its kind), toggled by the build
|
||||
/// hammer's right-click through <see cref="PlayerEvents.BuildMenuToggleRequested"/>.
|
||||
/// </summary>
|
||||
public bool IsPaused => Current != null && Current.Kind != PanelKind.Inventory;
|
||||
private UIPanel buildPanel;
|
||||
|
||||
/// <summary>
|
||||
/// True while a panel that pauses the world is open — i.e. anything but the inventory, the
|
||||
/// construction menu or the chest, all local windows the world keeps running under.
|
||||
/// </summary>
|
||||
public bool IsPaused => Current != null
|
||||
&& Current.Kind != PanelKind.Inventory
|
||||
&& Current.Kind != PanelKind.Build
|
||||
&& Current.Kind != PanelKind.Chest;
|
||||
|
||||
// Last bus values pushed, so we only fire on real transitions.
|
||||
private bool lastPaused;
|
||||
private bool lastInventoryOpen;
|
||||
private bool lastChestOpen;
|
||||
private bool lastBuildOpen;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -58,6 +70,7 @@ namespace Ashwild.UI
|
||||
{
|
||||
base.OnEnable();
|
||||
PlayerEvents.InventoryTogglePressed += HandleInventoryToggle;
|
||||
PlayerEvents.BuildMenuToggleRequested += HandleBuildMenuToggle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,6 +80,7 @@ namespace Ashwild.UI
|
||||
{
|
||||
base.OnDisable();
|
||||
PlayerEvents.InventoryTogglePressed -= HandleInventoryToggle;
|
||||
PlayerEvents.BuildMenuToggleRequested -= HandleBuildMenuToggle;
|
||||
|
||||
if (lastPaused)
|
||||
{
|
||||
@@ -78,6 +92,16 @@ namespace Ashwild.UI
|
||||
lastInventoryOpen = false;
|
||||
PlayerEvents.RaiseInventoryOpenChanged(false);
|
||||
}
|
||||
if (lastChestOpen)
|
||||
{
|
||||
lastChestOpen = false;
|
||||
PlayerEvents.RaiseChestOpenChanged(false);
|
||||
}
|
||||
if (lastBuildOpen)
|
||||
{
|
||||
lastBuildOpen = false;
|
||||
PlayerEvents.RaiseBuildMenuOpenChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,7 +110,7 @@ namespace Ashwild.UI
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
ResolveInventoryPanel();
|
||||
ResolvePanelsByKind();
|
||||
ApplyUIState(force: true);
|
||||
}
|
||||
|
||||
@@ -180,26 +204,48 @@ namespace Ashwild.UI
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't open the inventory on top of the pause menu.
|
||||
// Don't open the inventory on top of the pause menu, the construction menu or a chest.
|
||||
if (IsPaused) return;
|
||||
if (Current != null && (Current.Kind == PanelKind.Build || Current.Kind == PanelKind.Chest)) return;
|
||||
|
||||
if (inventoryPanel != null)
|
||||
OpenPanel(inventoryPanel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the registered panel flagged as the inventory.
|
||||
/// Build hammer right-click: close the construction menu if it is open, otherwise open it
|
||||
/// (never over the pause menu or the inventory). Mirrors the inventory toggle so the two
|
||||
/// windows can never fight for the stack.
|
||||
/// </summary>
|
||||
private void ResolveInventoryPanel()
|
||||
private void HandleBuildMenuToggle()
|
||||
{
|
||||
if (PlayerEvents.IsDead) return;
|
||||
|
||||
if (Current != null && Current.Kind == PanelKind.Build)
|
||||
{
|
||||
CloseAll();
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsPaused) return;
|
||||
if (Current != null && (Current.Kind == PanelKind.Inventory || Current.Kind == PanelKind.Chest)) return;
|
||||
|
||||
if (buildPanel != null)
|
||||
OpenPanel(buildPanel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Caches the registered inventory and construction-menu panels by their kind, so the
|
||||
/// toggle handlers can open them without a hard type reference.
|
||||
/// </summary>
|
||||
private void ResolvePanelsByKind()
|
||||
{
|
||||
if (panels == null) return;
|
||||
foreach (UIPanel p in panels)
|
||||
{
|
||||
if (p != null && p.Kind == PanelKind.Inventory)
|
||||
{
|
||||
inventoryPanel = p;
|
||||
return;
|
||||
}
|
||||
if (p == null) continue;
|
||||
if (p.Kind == PanelKind.Inventory) inventoryPanel = p;
|
||||
else if (p.Kind == PanelKind.Build) buildPanel = p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,15 +260,19 @@ namespace Ashwild.UI
|
||||
|
||||
/// <summary>
|
||||
/// Drives the side effects of the open panel: cursor for any panel, world freeze + GamePaused
|
||||
/// for non-inventory panels, and InventoryOpenChanged for the inventory. Both bus states feed
|
||||
/// PlayerEvents.InputLocked, so player control is cut whenever a panel is open.
|
||||
/// for pausing panels, and the InventoryOpenChanged / ChestOpenChanged / BuildMenuOpenChanged
|
||||
/// bus states for the three local windows. The inventory, the chest and the construction menu
|
||||
/// are windows the world keeps running under, so only "real" menus pause. All four bus states
|
||||
/// feed PlayerEvents.InputLocked, so player control is cut whenever a panel is open.
|
||||
/// </summary>
|
||||
private void ApplyUIState(bool force = false)
|
||||
{
|
||||
UIPanel cur = Current;
|
||||
bool anyOpen = cur != null;
|
||||
bool inventory = anyOpen && cur.Kind == PanelKind.Inventory;
|
||||
bool paused = anyOpen && !inventory;
|
||||
bool chest = anyOpen && cur.Kind == PanelKind.Chest;
|
||||
bool build = anyOpen && cur.Kind == PanelKind.Build;
|
||||
bool paused = anyOpen && !inventory && !chest && !build;
|
||||
|
||||
Cursor.lockState = anyOpen ? CursorLockMode.None : CursorLockMode.Locked;
|
||||
Cursor.visible = anyOpen;
|
||||
@@ -237,6 +287,16 @@ namespace Ashwild.UI
|
||||
lastInventoryOpen = inventory;
|
||||
PlayerEvents.RaiseInventoryOpenChanged(inventory);
|
||||
}
|
||||
if (force || chest != lastChestOpen)
|
||||
{
|
||||
lastChestOpen = chest;
|
||||
PlayerEvents.RaiseChestOpenChanged(chest);
|
||||
}
|
||||
if (force || build != lastBuildOpen)
|
||||
{
|
||||
lastBuildOpen = build;
|
||||
PlayerEvents.RaiseBuildMenuOpenChanged(build);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user