From eeb7042d11019f1aa63c9b55be859d65ed5b4cef Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Sat, 23 Apr 2022 16:25:16 -0400 Subject: [PATCH] fix: adds control node to ESCGame for UI that must be populated, along with Escoria-only UI methods; this helps to avoid display issues on startup --- .../game/core-scripts/esc/esc_room_manager.gd | 1 - .../game/core-scripts/esc_game.gd | 26 +++++++++++++++++++ addons/escoria-core/game/escoria.gd | 3 +++ addons/escoria-ui-9verbs/game.tscn | 10 +------ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd index 557ca1c8..2c61fa99 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd @@ -113,7 +113,6 @@ func change_scene(room_path: String, enable_automatic_transitions: bool) -> void var game_parent = escoria.game_scene.get_parent() game_parent.remove_child(escoria.game_scene) - #escoria.game_scene.hide_ui() room_scene.add_child(escoria.game_scene) room_scene.move_child(escoria.game_scene, 0) room_scene.game = escoria.game_scene diff --git a/addons/escoria-core/game/core-scripts/esc_game.gd b/addons/escoria-core/game/core-scripts/esc_game.gd index 801993fa..4cd88fcb 100644 --- a/addons/escoria-core/game/core-scripts/esc_game.gd +++ b/addons/escoria-core/game/core-scripts/esc_game.gd @@ -31,6 +31,9 @@ export(float) var mouse_tooltip_margin = 50.0 export(EDITOR_GAME_DEBUG_DISPLAY) var editor_debug_mode = \ EDITOR_GAME_DEBUG_DISPLAY.NONE setget _set_editor_debug_mode +# The Control node underneath which all UI must be placed. +# This should be a Control node and NOT a CanvasLayer (or any other type of) node. +export(NodePath) var ui_parent_control_node # A reference to the node handling tooltips var tooltip_node: Object @@ -421,3 +424,26 @@ func show_crash_popup(files: Array = []) -> void: yield(crash_popup, "confirmed") emit_signal("crash_popup_confirmed") + +# *** FOR USE BY ESCORIA CORE ONLY *** +# Hides everything under the UI Control node. +func escoria_hide_ui(): + if ui_parent_control_node != null and not ui_parent_control_node.is_empty(): + (get_node(ui_parent_control_node) as Control).visible = false + else: + escoria.logger.report_warnings( + "esc_game.gd#escoria_hide_ui", + ["UI parent Control node not defined!"] + ) + + +# *** FOR USE BY ESCORIA CORE ONLY *** +# Show everything under the UI Control node. +func escoria_show_ui(): + if ui_parent_control_node != null and not ui_parent_control_node.is_empty(): + (get_node(ui_parent_control_node) as Control).visible = true + else: + escoria.logger.report_warnings( + "esc_game.gd#escoria_show_ui", + ["UI parent Control node not defined!"] + ) diff --git a/addons/escoria-core/game/escoria.gd b/addons/escoria-core/game/escoria.gd index a7f1b1fe..642ec1f9 100644 --- a/addons/escoria-core/game/escoria.gd +++ b/addons/escoria-core/game/escoria.gd @@ -172,6 +172,9 @@ func _notification(what): # Usually you'll want to show some logos animations before spawning the main # menu in the escoria/main/game_start_script 's :init event func init(): + # Don't show the UI until we're ready in order to avoid a sometimes-noticeable + # blink. The UI will be "shown" later via a visibility update to the first room. + escoria.game_scene.escoria_hide_ui() run_event_from_script(start_script, self.event_manager.EVENT_INIT) diff --git a/addons/escoria-ui-9verbs/game.tscn b/addons/escoria-ui-9verbs/game.tscn index 77dd7535..8c5e9538 100644 --- a/addons/escoria-ui-9verbs/game.tscn +++ b/addons/escoria-ui-9verbs/game.tscn @@ -16,6 +16,7 @@ bg_color = Color( 0.6, 0.6, 0.6, 0.5 ) script = ExtResource( 5 ) main_menu = NodePath("ui/main_menu") pause_menu = NodePath("ui/pause_menu") +ui_parent_control_node = NodePath("ui/Control") [node name="dialog_layer" type="CanvasLayer" parent="."] @@ -143,15 +144,6 @@ margin_bottom = 200.0 size_flags_horizontal = 3 size_flags_vertical = 3 -[node name="hover_stack" type="Label" parent="ui"] -margin_left = 1085.0 -margin_top = 2.81912 -margin_right = 1283.0 -margin_bottom = 107.819 -__meta__ = { -"_edit_use_anchors_": false -} - [node name="main_menu" parent="ui" instance=ExtResource( 7 )] visible = false