From ef9d268dae24cb9bb5c665fcfbb30263065efa8b Mon Sep 17 00:00:00 2001 From: Nordup Date: Sun, 2 Jul 2023 22:40:04 +0400 Subject: [PATCH] search status --- project/scenes/components/search.tscn | 60 +++++++++++++++++++++- project/scenes/menu.tscn | 26 +++++----- project/scripts/resources/gate_events.gd | 6 +-- project/scripts/ui/search/search_status.gd | 31 +++++++++++ 4 files changed, 105 insertions(+), 18 deletions(-) create mode 100644 project/scripts/ui/search/search_status.gd diff --git a/project/scenes/components/search.tscn b/project/scenes/components/search.tscn index 3092c9a..9dd5854 100644 --- a/project/scenes/components/search.tscn +++ b/project/scenes/components/search.tscn @@ -1,12 +1,15 @@ -[gd_scene load_steps=11 format=3 uid="uid://ctam0fxigbefk"] +[gd_scene load_steps=14 format=3 uid="uid://ctam0fxigbefk"] [ext_resource type="Script" path="res://scripts/ui/search.gd" id="1_7ivk2"] [ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_13io8"] [ext_resource type="Texture2D" uid="uid://c28surtqjf4st" path="res://textures/search.svg" id="3_1rllf"] +[ext_resource type="Script" path="res://scripts/ui/search/search_status.gd" id="3_3p1re"] [ext_resource type="Script" path="res://scripts/ui/search_go.gd" id="3_eayvw"] [ext_resource type="Texture2D" uid="uid://byvigfpu44dnu" path="res://textures/arrow.svg" id="5_dqxpp"] +[ext_resource type="Texture2D" uid="uid://8wvea7j0v0rx" path="res://textures/Reload.svg" id="5_yhqf5"] [ext_resource type="Script" path="res://scripts/ui/menu/star.gd" id="6_iyikx"] [ext_resource type="Resource" uid="uid://bewhdj6jugt6q" path="res://resources/bookmarks.tres" id="7_2mijb"] +[ext_resource type="Texture2D" uid="uid://dystd8vvbqwo2" path="res://textures/exit.svg" id="7_jllve"] [ext_resource type="Texture2D" uid="uid://btn6ytky782a2" path="res://textures/star.svg" id="8_b00p6"] [ext_resource type="Texture2D" uid="uid://lxx36xkotvh1" path="res://textures/star_filled.svg" id="9_2en0l"] @@ -50,7 +53,7 @@ placeholder_text = "Search or enter address" script = ExtResource("1_7ivk2") gate_events = ExtResource("2_13io8") -[node name="SearchTexture" type="TextureRect" parent="."] +[node name="SearchStatus" type="Control" parent="." node_paths=PackedStringArray("search_line_edit", "search", "downloading", "success", "error")] self_modulate = Color(1, 1, 1, 0.8) layout_mode = 1 anchors_preset = 4 @@ -61,9 +64,62 @@ offset_top = -10.0 offset_right = 30.0 offset_bottom = 10.0 grow_vertical = 2 +mouse_filter = 1 +script = ExtResource("3_3p1re") +gate_events = ExtResource("2_13io8") +search_line_edit = NodePath("..") +search = NodePath("Search") +downloading = NodePath("Downloading") +success = NodePath("Success") +error = NodePath("Error") + +[node name="Search" type="TextureRect" parent="SearchStatus"] +self_modulate = Color(1, 1, 1, 0.8) +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 texture = ExtResource("3_1rllf") expand_mode = 1 +[node name="Downloading" type="TextureRect" parent="SearchStatus"] +visible = false +self_modulate = Color(1, 1, 1, 0.8) +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("5_yhqf5") +expand_mode = 1 + +[node name="Success" type="TextureRect" parent="SearchStatus"] +visible = false +self_modulate = Color(1, 1, 1, 0.8) +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("5_dqxpp") +expand_mode = 1 + +[node name="Error" type="TextureRect" parent="SearchStatus"] +visible = false +self_modulate = Color(1, 1, 1, 0.8) +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("7_jllve") +expand_mode = 1 + [node name="Go" type="BaseButton" parent="."] _import_path = NodePath("") unique_name_in_owner = false diff --git a/project/scenes/menu.tscn b/project/scenes/menu.tscn index 3c93b4f..727feea 100644 --- a/project/scenes/menu.tscn +++ b/project/scenes/menu.tscn @@ -35,7 +35,7 @@ tracks/0/keys = { tracks/1/type = "value" tracks/1/imported = false tracks/1/enabled = true -tracks/1/path = NodePath("VBoxContainer/Top/HBoxContainer:modulate") +tracks/1/path = NodePath("VBoxContainer/Top/MenuNavigation:modulate") tracks/1/interp = 1 tracks/1/loop_wrap = true tracks/1/keys = { @@ -76,7 +76,7 @@ tracks/0/keys = { tracks/1/type = "value" tracks/1/imported = false tracks/1/enabled = true -tracks/1/path = NodePath("VBoxContainer/Top/HBoxContainer:modulate") +tracks/1/path = NodePath("VBoxContainer/Top/MenuNavigation:modulate") tracks/1/interp = 1 tracks/1/loop_wrap = true tracks/1/keys = { @@ -117,7 +117,7 @@ tracks/0/keys = { tracks/1/type = "value" tracks/1/imported = false tracks/1/enabled = true -tracks/1/path = NodePath("VBoxContainer/Top/HBoxContainer:modulate") +tracks/1/path = NodePath("VBoxContainer/Top/MenuNavigation:modulate") tracks/1/interp = 1 tracks/1/loop_wrap = true tracks/1/keys = { @@ -184,7 +184,7 @@ grow_horizontal = 2 grow_vertical = 2 theme_override_styles/panel = SubResource("StyleBoxFlat_re7ca") -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Top" node_paths=PackedStringArray("go_back", "go_forw", "reload", "home")] +[node name="MenuNavigation" type="HBoxContainer" parent="VBoxContainer/Top" node_paths=PackedStringArray("go_back", "go_forw", "reload", "home")] layout_mode = 1 anchors_preset = 13 anchor_left = 0.5 @@ -204,7 +204,7 @@ go_forw = NodePath("GoForward") reload = NodePath("Reload") home = NodePath("Home") -[node name="GoBack" type="BaseButton" parent="VBoxContainer/Top/HBoxContainer"] +[node name="GoBack" type="BaseButton" parent="VBoxContainer/Top/MenuNavigation"] _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 @@ -259,7 +259,7 @@ shortcut_feedback = true shortcut_in_tooltip = true script = null -[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/HBoxContainer/GoBack"] +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/MenuNavigation/GoBack"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -273,7 +273,7 @@ size_flags_vertical = 4 texture = ExtResource("1_wkgtd") expand_mode = 1 -[node name="GoForward" type="BaseButton" parent="VBoxContainer/Top/HBoxContainer"] +[node name="GoForward" type="BaseButton" parent="VBoxContainer/Top/MenuNavigation"] _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 @@ -328,7 +328,7 @@ shortcut_feedback = true shortcut_in_tooltip = true script = null -[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/HBoxContainer/GoForward"] +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/MenuNavigation/GoForward"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -340,7 +340,7 @@ size_flags_vertical = 4 texture = ExtResource("1_wkgtd") expand_mode = 1 -[node name="Reload" type="BaseButton" parent="VBoxContainer/Top/HBoxContainer"] +[node name="Reload" type="BaseButton" parent="VBoxContainer/Top/MenuNavigation"] _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 @@ -395,7 +395,7 @@ shortcut_feedback = true shortcut_in_tooltip = true script = null -[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/HBoxContainer/Reload"] +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/MenuNavigation/Reload"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -407,12 +407,12 @@ size_flags_vertical = 4 texture = ExtResource("1_d6dhb") expand_mode = 1 -[node name="Search" parent="VBoxContainer/Top/HBoxContainer" instance=ExtResource("5_li2do")] +[node name="Search" parent="VBoxContainer/Top/MenuNavigation" instance=ExtResource("5_li2do")] layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 -[node name="Home" type="BaseButton" parent="VBoxContainer/Top/HBoxContainer"] +[node name="Home" type="BaseButton" parent="VBoxContainer/Top/MenuNavigation"] _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 @@ -467,7 +467,7 @@ shortcut_feedback = true shortcut_in_tooltip = true script = null -[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/HBoxContainer/Home"] +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/MenuNavigation/Home"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 diff --git a/project/scripts/resources/gate_events.gd b/project/scripts/resources/gate_events.gd index 52889e5..45da0d0 100644 --- a/project/scripts/resources/gate_events.gd +++ b/project/scripts/resources/gate_events.gd @@ -10,7 +10,7 @@ signal gate_entered signal exit_gate signal download_progress(url: String, body_size: int, downloaded_bytes: int) -signal gate_error(type: GateError) +signal gate_error(code: GateError) enum GateError { @@ -68,5 +68,5 @@ func download_progress_emit(url: String, body_size: int, downloaded_bytes: int) download_progress.emit(url, body_size, downloaded_bytes) -func gate_error_emit(type: GateError) -> void: - gate_error.emit(type) +func gate_error_emit(code: GateError) -> void: + gate_error.emit(code) diff --git a/project/scripts/ui/search/search_status.gd b/project/scripts/ui/search/search_status.gd new file mode 100644 index 0000000..6d4b0cd --- /dev/null +++ b/project/scripts/ui/search/search_status.gd @@ -0,0 +1,31 @@ +extends Control + +@export var gate_events: GateEvents +@export var search_line_edit: LineEdit + +@export var search: Control +@export var downloading: Control +@export var success: Control +@export var error: Control + + +func _ready() -> void: + search_line_edit.text_changed.connect(func(_text): switch_to(search)) + gate_events.exit_gate.connect(func(): switch_to(search)) + gate_events.open_gate.connect(func(_url): switch_to(downloading)) + gate_events.gate_entered.connect(func(): switch_to(success)) + gate_events.gate_error.connect(func(_code): switch_to(error)) + + switch_to(search) + + +func switch_to(_state: Control) -> void: + disable([search, downloading, success, error]) + _state.visible = true + _state.process_mode = Node.PROCESS_MODE_INHERIT + + +func disable(states: Array[Control]) -> void: + for state in states: + state.visible = false + state.process_mode = Node.PROCESS_MODE_DISABLED