From b52b9b9d7c6d88e317b85b445d733186861024a0 Mon Sep 17 00:00:00 2001 From: Paul Cento Date: Sun, 29 Sep 2024 16:43:25 -0400 Subject: [PATCH 1/3] prevent clicking other controls when popup is open --- C7/C7Game.tscn | 1 - C7/Credits.tscn | 6 +++--- C7/GlobalSingleton.cs | 6 +++--- C7/UIElements/Popups/PopupOverlay.cs | 12 ++++++++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/C7/C7Game.tscn b/C7/C7Game.tscn index c2e0d62c..69a7e9a8 100644 --- a/C7/C7Game.tscn +++ b/C7/C7Game.tscn @@ -180,7 +180,6 @@ anchors_preset = 11 anchor_left = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = -108.0 offset_top = 80.0 offset_right = -108.0 offset_bottom = -170.0 diff --git a/C7/Credits.tscn b/C7/Credits.tscn index 63cd3075..20fbeae4 100644 --- a/C7/Credits.tscn +++ b/C7/Credits.tscn @@ -1,6 +1,6 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=2 format=3 uid="uid://pfefjvwiljdp"] -[ext_resource path="res://Credits.cs" type="Script" id=1] +[ext_resource type="Script" path="res://Credits.cs" id="1"] [node name="Node2D" type="Node2D"] -script = ExtResource( 1 ) +script = ExtResource("1") diff --git a/C7/GlobalSingleton.cs b/C7/GlobalSingleton.cs index 75be8165..ff5ebb10 100644 --- a/C7/GlobalSingleton.cs +++ b/C7/GlobalSingleton.cs @@ -2,9 +2,9 @@ using QueryCiv3; /**** - Need to pass values from one scene to another, particularly when loading - a game in main menu. This script is set to auto load in project settings. - See https://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html + Need to pass values from one scene to another, particularly when loading + a game in main menu. This script is set to auto load in project settings. + See https://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html ****/ public partial class GlobalSingleton : Node { // Will have main menu file picker set this and Game.cs pass it to C7Engine.createGame diff --git a/C7/UIElements/Popups/PopupOverlay.cs b/C7/UIElements/Popups/PopupOverlay.cs index 6a673982..7408c14e 100644 --- a/C7/UIElements/Popups/PopupOverlay.cs +++ b/C7/UIElements/Popups/PopupOverlay.cs @@ -1,3 +1,4 @@ +using System.Net; using Godot; using Serilog; @@ -15,6 +16,8 @@ public partial class PopupOverlay : HBoxContainer public static readonly string NodePath = "/root/C7Game/CanvasLayer/PopupOverlay"; + private static readonly string ControlNodePath = "/root/C7Game/CanvasLayer/Control"; + public enum PopupCategory { Advisor, Console, @@ -26,6 +29,8 @@ public void OnHidePopup() RemoveChild(currentChild); currentChild = null; Hide(); + Control control = getControlNode(); + control.ProcessMode = ProcessModeEnum.Inherit; } public bool ShowingPopup => currentChild is not null; @@ -37,6 +42,10 @@ public void PlaySound(AudioStreamWav wav) player.Play(); } + private Control getControlNode() { + return GetNode(ControlNodePath); + } + public void ShowPopup(Popup child, PopupCategory category) { if (child is null) { @@ -64,6 +73,9 @@ public void ShowPopup(Popup child, PopupCategory category) log.Error("Invalid popup category"); } AudioStreamWav wav = Util.LoadWAVFromDisk(Util.Civ3MediaPath(soundFile)); + Control control = getControlNode(); + control.ProcessMode = ProcessModeEnum.Disabled; + Show(); PlaySound(wav); } From 75e0dfb05da19247b18d13f24fe771828838c540 Mon Sep 17 00:00:00 2001 From: Paul Cento Date: Sun, 29 Sep 2024 17:02:20 -0400 Subject: [PATCH 2/3] restore old UI behavior for popups --- C7/UIElements/GameStatus/LowerRightInfoBox.cs | 2 +- C7/UIElements/Popups/PopupOverlay.cs | 42 +++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/C7/UIElements/GameStatus/LowerRightInfoBox.cs b/C7/UIElements/GameStatus/LowerRightInfoBox.cs index 1042559d..8c1e38d3 100644 --- a/C7/UIElements/GameStatus/LowerRightInfoBox.cs +++ b/C7/UIElements/GameStatus/LowerRightInfoBox.cs @@ -19,7 +19,7 @@ public partial class LowerRightInfoBox : TextureRect Label yearAndGold = new Label(); Timer blinkingTimer = new Timer(); - Boolean timerStarted = false; //This "isStopped" returns false if it's never been started. So we need this to know if we've ever started it. + bool timerStarted = false; //This "isStopped" returns false if it's never been started. So we need this to know if we've ever started it. // Called when the node enters the scene tree for the first time. public override void _Ready() diff --git a/C7/UIElements/Popups/PopupOverlay.cs b/C7/UIElements/Popups/PopupOverlay.cs index 7408c14e..0ea17a7d 100644 --- a/C7/UIElements/Popups/PopupOverlay.cs +++ b/C7/UIElements/Popups/PopupOverlay.cs @@ -1,4 +1,3 @@ -using System.Net; using Godot; using Serilog; @@ -26,10 +25,17 @@ public enum PopupCategory { public void OnHidePopup() { + // 1. enable mouse interaction with non-UI nodes + MouseFilter = MouseFilterEnum.Pass; RemoveChild(currentChild); currentChild = null; Hide(); + Control control = getControlNode(); + // 2. enable mouse interactions with other UI elements + setMouseFilter(control, MouseFilterEnum.Pass); + + // 3. enable clicking other UI elements control.ProcessMode = ProcessModeEnum.Inherit; } @@ -46,6 +52,15 @@ private Control getControlNode() { return GetNode(ControlNodePath); } + private void setMouseFilter(Node n, MouseFilterEnum filter) { + foreach (Node child in n?.GetChildren()) { + setMouseFilter(child, filter); + } + if (n is Control control) { + control.MouseFilter = filter; + } + } + public void ShowPopup(Popup child, PopupCategory category) { if (child is null) { @@ -73,9 +88,18 @@ public void ShowPopup(Popup child, PopupCategory category) log.Error("Invalid popup category"); } AudioStreamWav wav = Util.LoadWAVFromDisk(Util.Civ3MediaPath(soundFile)); + + // 1. prevent mouse interaction with non-UI elements (ie. the map) + MouseFilter = MouseFilterEnum.Stop; + Control control = getControlNode(); + + // 2. prevent clicking other UI elements control.ProcessMode = ProcessModeEnum.Disabled; + // 3. ignore all mouse input on other UI elements (ie. button color changes on hover) + setMouseFilter(control, MouseFilterEnum.Ignore); + Show(); PlaySound(wav); } @@ -89,17 +113,11 @@ public void ShowPopup(Popup child, PopupCategory category) **/ public override void _UnhandledInput(InputEvent @event) { - if (this.Visible) { - if (@event is InputEventKey eventKey) - { - //As I've added more shortcuts, I've realized checking all of them here could be irksome. - //For now, I'm thinking it would make more sense to process or allow through the ones that should go through, - //as most of the global ones should *not* go through here. - if (eventKey.Pressed) - { - GetViewport().SetInputAsHandled(); - } - } + if (Visible && @event is InputEventKey eventKey && eventKey.Pressed) { + // As I've added more shortcuts, I've realized checking all of them here could be irksome. + // For now, I'm thinking it would make more sense to process or allow through the ones that should go through, + // as most of the global ones should *not* go through here. + GetViewport().SetInputAsHandled(); } } } From 844c54e5544d39054d85ad184d1b3f970d70bade Mon Sep 17 00:00:00 2001 From: Paul Cento Date: Sun, 29 Sep 2024 21:55:46 -0400 Subject: [PATCH 3/3] adjust spacing for ENTER or SPACEBAR... next turn message --- C7/UIElements/GameStatus/LowerRightInfoBox.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/C7/UIElements/GameStatus/LowerRightInfoBox.cs b/C7/UIElements/GameStatus/LowerRightInfoBox.cs index 8c1e38d3..13d4ca16 100644 --- a/C7/UIElements/GameStatus/LowerRightInfoBox.cs +++ b/C7/UIElements/GameStatus/LowerRightInfoBox.cs @@ -54,21 +54,21 @@ private void CreateUI() { lblUnitSelected.HorizontalAlignment = HorizontalAlignment.Right; lblUnitSelected.SetPosition(new Vector2(0, 20)); lblUnitSelected.AnchorRight = 1.0f; - lblUnitSelected.OffsetRight = -35; + lblUnitSelected.OffsetRight = -30; boxRightRectangle.AddChild(lblUnitSelected); attackDefenseMovement.Text = "0.0. 1/1"; attackDefenseMovement.HorizontalAlignment = HorizontalAlignment.Right; attackDefenseMovement.SetPosition(new Vector2(0, 35)); attackDefenseMovement.AnchorRight = 1.0f; - attackDefenseMovement.OffsetRight = -35; + attackDefenseMovement.OffsetRight = -30; boxRightRectangle.AddChild(attackDefenseMovement); terrainType.Text = "Grassland"; terrainType.HorizontalAlignment = HorizontalAlignment.Right; terrainType.SetPosition(new Vector2(0, 50)); terrainType.AnchorRight = 1.0f; - terrainType.OffsetRight = -35; + terrainType.OffsetRight = -30; boxRightRectangle.AddChild(terrainType); //For the centered labels, we anchor them center, with equal weight on each side.