From 3985aece5001e9fba96f3b35f575e120bdb185af Mon Sep 17 00:00:00 2001 From: Nordup Date: Sun, 13 Aug 2023 15:54:20 +0400 Subject: [PATCH] prompt focus --- project/scenes/components/prompt.tscn | 2 ++ project/scenes/components/search.tscn | 18 ++++++++++---- project/scenes/menu.tscn | 10 ++++++++ project/scripts/string_tools.gd | 20 ++++++++-------- project/scripts/ui/search.gd | 15 +++++++++--- .../scripts/ui/search/prompt_navigation.gd | 17 +++++++++++++ project/scripts/ui/search/prompt_results.gd | 24 +++++++++++++++---- 7 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 project/scripts/ui/search/prompt_navigation.gd diff --git a/project/scenes/components/prompt.tscn b/project/scenes/components/prompt.tscn index cc1607e..3defe50 100644 --- a/project/scenes/components/prompt.tscn +++ b/project/scenes/components/prompt.tscn @@ -41,6 +41,7 @@ grow_vertical = 2 theme_override_styles/normal = SubResource("StyleBoxFlat_wbjg7") theme_override_styles/hover = SubResource("StyleBoxFlat_srt8r") theme_override_styles/pressed = SubResource("StyleBoxFlat_awixv") +theme_override_styles/focus = SubResource("StyleBoxFlat_srt8r") script = ExtResource("1_7xv44") gate_events = ExtResource("2_33m26") prompt_text = NodePath("Label") @@ -56,6 +57,7 @@ theme_override_font_sizes/font_size = 20 theme_override_styles/normal = SubResource("StyleBoxEmpty_6fg0o") text = "prompt" vertical_alignment = 1 +text_overrun_behavior = 3 [node name="SearchStatus" type="Control" parent="."] self_modulate = Color(1, 1, 1, 0.8) diff --git a/project/scenes/components/search.tscn b/project/scenes/components/search.tscn index b6e5767..90b6a52 100644 --- a/project/scenes/components/search.tscn +++ b/project/scenes/components/search.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=20 format=3 uid="uid://ctam0fxigbefk"] +[gd_scene load_steps=21 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"] @@ -15,6 +15,7 @@ [ext_resource type="Texture2D" uid="uid://lxx36xkotvh1" path="res://textures/star_filled.svg" id="9_2en0l"] [ext_resource type="Script" path="res://scripts/ui/search/prompt_results.gd" id="14_0lofv"] [ext_resource type="Script" path="res://scripts/ui/top_level.gd" id="14_5k27g"] +[ext_resource type="Script" path="res://scripts/ui/search/prompt_navigation.gd" id="14_h86vl"] [ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/api_settings.tres" id="15_uafyh"] [ext_resource type="PackedScene" uid="uid://b57n6cvtqn5b7" path="res://scenes/components/prompt.tscn" id="16_lbcsd"] @@ -48,7 +49,7 @@ corner_radius_bottom_right = 6 corner_radius_bottom_left = 6 corner_detail = 10 -[node name="Search" type="LineEdit"] +[node name="Search" type="LineEdit" node_paths=PackedStringArray("prompt_panel")] custom_minimum_size = Vector2(1000, 40) anchors_preset = 8 anchor_left = 0.5 @@ -73,6 +74,7 @@ theme_override_styles/focus = SubResource("StyleBoxFlat_hyysn") placeholder_text = "Search or enter address" script = ExtResource("1_7ivk2") gate_events = ExtResource("2_13io8") +prompt_panel = NodePath("Prompt/Panel") [node name="SearchStatus" type="Control" parent="." node_paths=PackedStringArray("search_line_edit", "search", "downloading", "success", "error")] self_modulate = Color(1, 1, 1, 0.8) @@ -409,14 +411,18 @@ grow_vertical = 2 texture = ExtResource("9_2en0l") expand_mode = 1 -[node name="Prompt" type="Control" parent="."] +[node name="Prompt" type="Control" parent="." node_paths=PackedStringArray("search", "prompt_results")] layout_mode = 1 anchors_preset = 2 anchor_top = 1.0 anchor_bottom = 1.0 grow_vertical = 0 +script = ExtResource("14_h86vl") +search = NodePath("..") +prompt_results = NodePath("Panel/VBoxContainer") [node name="Panel" type="Panel" parent="Prompt"] +visible = false top_level = true layout_mode = 1 anchors_preset = 5 @@ -425,22 +431,24 @@ anchor_right = 0.5 offset_left = -500.0 offset_top = 560.0 offset_right = 500.0 -offset_bottom = 1060.0 +offset_bottom = 860.0 grow_horizontal = 2 theme_override_styles/panel = SubResource("StyleBoxFlat_mh73y") script = ExtResource("14_5k27g") -[node name="VBoxContainer" type="VBoxContainer" parent="Prompt/Panel"] +[node name="VBoxContainer" type="VBoxContainer" parent="Prompt/Panel" node_paths=PackedStringArray("panel")] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +theme_override_constants/separation = 0 script = ExtResource("14_0lofv") gate_events = ExtResource("2_13io8") api = ExtResource("15_uafyh") result_scene = ExtResource("16_lbcsd") +panel = NodePath("..") [connection signal="text_changed" from="." to="." method="_on_text_changed"] [connection signal="text_changed" from="." to="Go" method="_on_search_text_changed"] diff --git a/project/scenes/menu.tscn b/project/scenes/menu.tscn index 727feea..27fdb49 100644 --- a/project/scenes/menu.tscn +++ b/project/scenes/menu.tscn @@ -209,6 +209,8 @@ _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 process_priority = 0 +process_physics_priority = 0 +process_thread_group = 0 editor_description = "" visible = true modulate = Color(1, 1, 1, 1) @@ -278,6 +280,8 @@ _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 process_priority = 0 +process_physics_priority = 0 +process_thread_group = 0 editor_description = "" visible = true modulate = Color(1, 1, 1, 1) @@ -345,6 +349,8 @@ _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 process_priority = 0 +process_physics_priority = 0 +process_thread_group = 0 editor_description = "" visible = true modulate = Color(1, 1, 1, 1) @@ -417,6 +423,8 @@ _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 process_priority = 0 +process_physics_priority = 0 +process_thread_group = 0 editor_description = "" visible = true modulate = Color(1, 1, 1, 1) @@ -484,6 +492,8 @@ _import_path = NodePath("") unique_name_in_owner = false process_mode = 0 process_priority = 0 +process_physics_priority = 0 +process_thread_group = 0 editor_description = "" visible = true modulate = Color(1, 1, 1, 1) diff --git a/project/scripts/string_tools.gd b/project/scripts/string_tools.gd index f4d4240..76612ac 100644 --- a/project/scripts/string_tools.gd +++ b/project/scripts/string_tools.gd @@ -3,15 +3,15 @@ class_name StringTools static func to_alpha(text: String) -> String: - var clean_text = "" - var last_is_char = false + var last_is_alpha = false + var result = "" - for char in text: - if (char >= 'a' and char <= 'z') or (char >= 'A' and char <= 'Z'): - clean_text += char - last_is_char = true - elif last_is_char: - clean_text += " " - last_is_char = false + for symbol in text: + if (symbol >= 'a' and symbol <= 'z') or (symbol >= 'A' and symbol <= 'Z'): + result += symbol + last_is_alpha = true + elif last_is_alpha: + result += " " + last_is_alpha = false - return clean_text + return result diff --git a/project/scripts/ui/search.gd b/project/scripts/ui/search.gd index 4e7d35f..716065c 100644 --- a/project/scripts/ui/search.gd +++ b/project/scripts/ui/search.gd @@ -1,6 +1,10 @@ extends LineEdit +class_name Search + +signal on_release_focus @export var gate_events: GateEvents +@export var prompt_panel: Control var url: String @@ -14,13 +18,16 @@ func _ready() -> void: func set_current_url(_url: String) -> void: url = _url text = url + + on_release_focus.emit() func _input(event: InputEvent) -> void: - if (has_focus() - and event is InputEventMouseButton - and not get_global_rect().has_point(event.position)): + if (has_focus() and event is InputEventMouseButton + and not get_global_rect().has_point(event.position) + and not prompt_panel.get_global_rect().has_point(event.position)): release_focus() + on_release_focus.emit() func _on_text_changed(_url: String) -> void: @@ -42,4 +49,6 @@ func open_gate() -> void: gate_events.open_gate_emit(url) else: gate_events.search_emit(url) + release_focus() + on_release_focus.emit() diff --git a/project/scripts/ui/search/prompt_navigation.gd b/project/scripts/ui/search/prompt_navigation.gd new file mode 100644 index 0000000..2e3fa99 --- /dev/null +++ b/project/scripts/ui/search/prompt_navigation.gd @@ -0,0 +1,17 @@ +extends Node + +@export var search: Search +@export var prompt_results: PromptResults + + +func _ready() -> void: + search.focus_entered.connect(_on_focus_entered) + search.on_release_focus.connect(_on_release_focus) + + +func _on_focus_entered() -> void: + prompt_results._on_search_text_changed(search.text) + + +func _on_release_focus() -> void: + prompt_results.clear() diff --git a/project/scripts/ui/search/prompt_results.gd b/project/scripts/ui/search/prompt_results.gd index eee9fea..c4485e6 100644 --- a/project/scripts/ui/search/prompt_results.gd +++ b/project/scripts/ui/search/prompt_results.gd @@ -1,23 +1,32 @@ extends VBoxContainer +class_name PromptResults @export var gate_events: GateEvents @export var api: ApiSettings @export var result_scene: PackedScene +@export var panel: Control + +var prompt_size: float var result_str: String func _ready() -> void: - pass + var prompt: Control = result_scene.instantiate() + prompt_size = prompt.size.y + prompt.queue_free() + + panel.visible = true + clear() func _on_search_text_changed(query: String) -> void: - clear() - if query.is_empty(): return + if query.is_empty(): clear(); return await prompt_request(query) + clear() - var prompts = JSON.parse_string(result_str) + var prompts: Array = JSON.parse_string(result_str) if prompts == null or prompts.is_empty(): return @@ -25,6 +34,8 @@ func _on_search_text_changed(query: String) -> void: var result: PromptResult = result_scene.instantiate() result.fill(prompt) add_child(result) + + change_size(prompts.size()) func prompt_request(query: String) -> void: @@ -42,3 +53,8 @@ func clear() -> void: for child in get_children(): child.queue_free() remove_child(child) + change_size(0) + + +func change_size(promt_count: int) -> void: + panel.size = Vector2(panel.size.x, promt_count * prompt_size)