From bcf5249067b076e988628471f19d6ee45cf036f9 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 9 Jan 2026 20:52:47 -0600 Subject: [PATCH] Begin UI refactor --- cutscene/conversation/ConversationElement.gd | 2 +- overworld/OverworldScene.gd | 2 +- overworld/entity/EntityMovement.gd | 2 + project.godot | 1 + scene/InitialScene.tscn | 2 + scene/RootScene.gd | 19 +++++---- scene/RootScene.tscn | 10 ++++- singleton/Pause.gd | 42 ++++++++++---------- ui/RootUI.gd | 11 +++++ ui/{UI.gd.uid => RootUI.gd.uid} | 0 ui/{UI.tscn => RootUI.tscn} | 12 +++--- ui/UI.gd | 10 ----- ui/UISingleton.gd | 15 +++++++ ui/UISingleton.gd.uid | 1 + ui/debugmenu/DebugMenu.gd | 2 +- ui/debugmenu/DebugMenu.tscn | 11 +++++ 16 files changed, 92 insertions(+), 50 deletions(-) create mode 100644 ui/RootUI.gd rename ui/{UI.gd.uid => RootUI.gd.uid} (100%) rename ui/{UI.tscn => RootUI.tscn} (78%) delete mode 100644 ui/UI.gd create mode 100644 ui/UISingleton.gd create mode 100644 ui/UISingleton.gd.uid diff --git a/cutscene/conversation/ConversationElement.gd b/cutscene/conversation/ConversationElement.gd index 6f00811..812ff65 100644 --- a/cutscene/conversation/ConversationElement.gd +++ b/cutscene/conversation/ConversationElement.gd @@ -5,5 +5,5 @@ class_name ConversationElement @export_multiline var label: String func sceneItem() -> int: - # await UI.TEXTBOX.setTextAndWait(label) + await UI.TEXTBOX.setTextAndWait(label) return CutsceneSingleton.CUTSCENE_CONTINUE diff --git a/overworld/OverworldScene.gd b/overworld/OverworldScene.gd index ac704ef..323cbdd 100644 --- a/overworld/OverworldScene.gd +++ b/overworld/OverworldScene.gd @@ -11,7 +11,7 @@ func _ready() -> void: func _exit_tree() -> void: OVERWORLD.mapChanged.disconnect(onMapChanged) -func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void: +func onMapChanged(newMap:PackedScene, _playerDestinationNodeName:String) -> void: print("New map time.", newMap) for childScene in map.get_children(): map.remove_child(childScene) diff --git a/overworld/entity/EntityMovement.gd b/overworld/entity/EntityMovement.gd index 9850658..37db895 100644 --- a/overworld/entity/EntityMovement.gd +++ b/overworld/entity/EntityMovement.gd @@ -62,6 +62,8 @@ func _applyFriction(delta:float) -> void: entity.velocity.z *= delta * FRICTION func _canMove() -> bool: + if !UI.TEXTBOX.isClosed: + return false return true # diff --git a/project.godot b/project.godot index f015cf6..45b80fd 100644 --- a/project.godot +++ b/project.godot @@ -28,6 +28,7 @@ PARTY="*res://party/Party.gd" COOKING="*res://cooking/Cooking.gd" SAVE="*res://save/Save.gd" ControllerIcons="*res://addons/controller_icons/ControllerIcons.gd" +UI="*res://ui/UISingleton.gd" [debug] diff --git a/scene/InitialScene.tscn b/scene/InitialScene.tscn index 6f7c561..8bc9ce6 100644 --- a/scene/InitialScene.tscn +++ b/scene/InitialScene.tscn @@ -5,3 +5,5 @@ [node name="InitialScene" type="Node3D"] [node name="MainMenu" parent="." instance=ExtResource("1_hu3pf")] +z_as_relative = false +mouse_filter = 2 diff --git a/scene/RootScene.gd b/scene/RootScene.gd index 96ec9cf..61de209 100644 --- a/scene/RootScene.gd +++ b/scene/RootScene.gd @@ -4,6 +4,7 @@ class_name RootScene extends Node3D @export var initial:Node3D = null @export var battle:Node3D = null @export var cooking:Node3D = null +@export var currentScene:Node = null func _enter_tree() -> void: SCENE.sceneChanged.connect(onSceneChange) @@ -13,13 +14,15 @@ func _exit_tree() -> void: push_error("RootScene should not be removed from the scene tree. This is a bug.") func removeAndHide(node:Node3D) -> void: - if node && node.get_parent() == self: - remove_child(node) + if node && node.get_parent(): + node.get_parent().remove_child(node) node.visible = false func addAndShow(node:Node3D) -> void: - if node && node.get_parent() != self: - add_child(node) + if node && currentScene: + if node.get_parent() && node.get_parent() != currentScene: + node.get_parent().remove_child(node) + currentScene.add_child(node) node.visible = true func onSceneChange(newScene:SceneSingleton.SceneType) -> void: @@ -48,8 +51,8 @@ func onSceneChange(newScene:SceneSingleton.SceneType) -> void: removeAndHide(battle) addAndShow(cooking) - SceneSingleton.SceneType.UNSET: - pass - _: - pass + removeAndHide(initial) + removeAndHide(overworld) + removeAndHide(battle) + removeAndHide(cooking) diff --git a/scene/RootScene.tscn b/scene/RootScene.tscn index d890ec4..02280a8 100644 --- a/scene/RootScene.tscn +++ b/scene/RootScene.tscn @@ -1,17 +1,19 @@ -[gd_scene load_steps=6 format=3 uid="uid://ckkewlcugc8ro"] +[gd_scene load_steps=7 format=3 uid="uid://ckkewlcugc8ro"] [ext_resource type="Script" uid="uid://ml70iui7qpo4" path="res://scene/RootScene.gd" id="1_nky1x"] [ext_resource type="PackedScene" uid="uid://dy54m7dvjgqta" path="res://battle/BattleScene.tscn" id="2_0idls"] [ext_resource type="PackedScene" uid="uid://bs41nqi3ocih3" path="res://scene/InitialScene.tscn" id="2_hkmoa"] [ext_resource type="PackedScene" uid="uid://c0k1t3tyiaojl" path="res://overworld/OverworldScene.tscn" id="2_o1wvd"] [ext_resource type="PackedScene" uid="uid://cxkd4frxvt873" path="res://cooking/CookingScene.tscn" id="5_aj1eq"] +[ext_resource type="PackedScene" uid="uid://baos0arpiskbp" path="res://ui/RootUI.tscn" id="6_ajii0"] -[node name="RootScene" type="Node3D" node_paths=PackedStringArray("overworld", "initial", "battle", "cooking")] +[node name="RootScene" type="Node3D" node_paths=PackedStringArray("overworld", "initial", "battle", "cooking", "currentScene")] script = ExtResource("1_nky1x") overworld = NodePath("OverworldScene") initial = NodePath("InitialScene") battle = NodePath("BattleScene") cooking = NodePath("CookingScene") +currentScene = NodePath("CurrentScene") metadata/_custom_type_script = "uid://ml70iui7qpo4" [node name="InitialScene" parent="." instance=ExtResource("2_hkmoa")] @@ -25,3 +27,7 @@ visible = false [node name="CookingScene" parent="." instance=ExtResource("5_aj1eq")] visible = false + +[node name="CurrentScene" type="Node" parent="."] + +[node name="RootUI" parent="." instance=ExtResource("6_ajii0")] diff --git a/singleton/Pause.gd b/singleton/Pause.gd index bf95a40..21bd97d 100644 --- a/singleton/Pause.gd +++ b/singleton/Pause.gd @@ -1,31 +1,31 @@ class_name PauseSingleton extends Node -var cutscenePaused:bool = false +# var cutscenePaused:bool = false -func cutscenePause() -> void: - cutscenePaused = true +# func cutscenePause() -> void: +# cutscenePaused = true -func cutsceneResume() -> void: - cutscenePaused = false +# func cutsceneResume() -> void: +# cutscenePaused = false -func isMovementPaused() -> bool: - if cutscenePaused: - return true +# func isMovementPaused() -> bool: +# if cutscenePaused: +# return true - # if !UI.TEXTBOX.isClosed: - # return true +# if !UI.TEXTBOX.isClosed: +# return true - # if UI.PAUSE.isOpen(): - # return true +# if UI.PAUSE.isOpen(): +# return true - if OVERWORLD.isMapChanging(): - return true +# if OVERWORLD.isMapChanging(): +# return true - return false +# return false -func menuPause() -> void: - # if UI.PAUSE.isOpen(): - # UI.PAUSE.close() - # else: - # UI.PAUSE.open() - pass \ No newline at end of file +# func menuPause() -> void: +# # if UI.PAUSE.isOpen(): +# # UI.PAUSE.close() +# # else: +# # UI.PAUSE.open() +# pass \ No newline at end of file diff --git a/ui/RootUI.gd b/ui/RootUI.gd new file mode 100644 index 0000000..976064e --- /dev/null +++ b/ui/RootUI.gd @@ -0,0 +1,11 @@ +class_name RootUI extends Control + +@export var debugMenu:DebugMenu +@export var textBox:VNTextbox + +func _enter_tree() -> void: + UI.rootUi = self + +func _exit_tree() -> void: + if UI.rootUi == self: + UI.rootUi = null diff --git a/ui/UI.gd.uid b/ui/RootUI.gd.uid similarity index 100% rename from ui/UI.gd.uid rename to ui/RootUI.gd.uid diff --git a/ui/UI.tscn b/ui/RootUI.tscn similarity index 78% rename from ui/UI.tscn rename to ui/RootUI.tscn index 164767d..307176f 100644 --- a/ui/UI.tscn +++ b/ui/RootUI.tscn @@ -1,22 +1,22 @@ [gd_scene load_steps=5 format=3 uid="uid://baos0arpiskbp"] [ext_resource type="PackedScene" uid="uid://bkx3l0kckf4a8" path="res://ui/component/VNTextbox.tscn" id="1_1mtk3"] -[ext_resource type="Script" uid="uid://dq3qyyayugt5l" path="res://ui/UI.gd" id="1_son71"] +[ext_resource type="Script" uid="uid://dq3qyyayugt5l" path="res://ui/RootUI.gd" id="1_son71"] [ext_resource type="PackedScene" uid="uid://c0i5e2dj11d8c" path="res://ui/pause/PauseMenu.tscn" id="2_atyu8"] [ext_resource type="PackedScene" uid="uid://b38dr0wkix76t" path="res://ui/debugmenu/DebugMenu.tscn" id="4_u132g"] -[node name="UI" type="Control" node_paths=PackedStringArray("TEXTBOX", "PAUSE", "DEBUG")] +[node name="RootUI" type="Control" node_paths=PackedStringArray("debugMenu", "textBox")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -mouse_filter = 1 +mouse_filter = 2 script = ExtResource("1_son71") -TEXTBOX = NodePath("VNTextbox") -PAUSE = NodePath("PauseMenu") -DEBUG = NodePath("DebugMenu") +debugMenu = NodePath("DebugMenu") +textBox = NodePath("VNTextbox") +metadata/_custom_type_script = "uid://dq3qyyayugt5l" [node name="DebugMenu" parent="." instance=ExtResource("4_u132g")] visible = false diff --git a/ui/UI.gd b/ui/UI.gd deleted file mode 100644 index affc7c0..0000000 --- a/ui/UI.gd +++ /dev/null @@ -1,10 +0,0 @@ -class_name UISingleton extends Control - -# @deprecated -@export var TEXTBOX: VNTextbox - -# @deprecated -@export var PAUSE: PauseMenu - -# @deprecated -@export var DEBUG: DebugMenu diff --git a/ui/UISingleton.gd b/ui/UISingleton.gd new file mode 100644 index 0000000..35a7429 --- /dev/null +++ b/ui/UISingleton.gd @@ -0,0 +1,15 @@ +extends Node + +var rootUi:RootUI = null + +var DEBUG_MENU: + get(): + if rootUi && rootUi.debugMenu: + return rootUi.debugMenu + return null + +var TEXTBOX: + get(): + if rootUi && rootUi.textBox: + return rootUi.textBox + return null \ No newline at end of file diff --git a/ui/UISingleton.gd.uid b/ui/UISingleton.gd.uid new file mode 100644 index 0000000..ba3720e --- /dev/null +++ b/ui/UISingleton.gd.uid @@ -0,0 +1 @@ +uid://c0m8hvpqj3xcb diff --git a/ui/debugmenu/DebugMenu.gd b/ui/debugmenu/DebugMenu.gd index e15520f..c0d9b33 100644 --- a/ui/debugmenu/DebugMenu.gd +++ b/ui/debugmenu/DebugMenu.gd @@ -20,7 +20,7 @@ func _enter_tree() -> void: btnBattle.pressed.connect(onBattlePressed) if btnCooking: btnCooking.pressed.connect(onCookingPressed) - isClosed = false + isClosed = true func _exit_tree() -> void: if btnInitial: diff --git a/ui/debugmenu/DebugMenu.tscn b/ui/debugmenu/DebugMenu.tscn index c8d5752..4ad8235 100644 --- a/ui/debugmenu/DebugMenu.tscn +++ b/ui/debugmenu/DebugMenu.tscn @@ -9,6 +9,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 script = ExtResource("1_c1p3i") btnInitial = NodePath("HBoxContainer/InitialScene") btnOverworld = NodePath("HBoxContainer/OverworldScene") @@ -16,6 +17,16 @@ btnBattle = NodePath("HBoxContainer/BattleScene") btnCooking = NodePath("HBoxContainer/CookingScene") metadata/_custom_type_script = "uid://bekdew700opvq" +[node name="ColorRect" type="ColorRect" parent="."] +visible = false +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(1, 1, 1, 0.619608) + [node name="HBoxContainer" type="HBoxContainer" parent="."] layout_mode = 0 offset_right = 40.0