prompt focus

This commit is contained in:
Nordup 2023-08-13 15:54:20 +04:00
parent bffe8a330f
commit 3985aece50
7 changed files with 84 additions and 22 deletions

View file

@ -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)

View file

@ -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"]

View file

@ -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)

View file

@ -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

View file

@ -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()

View file

@ -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()

View file

@ -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)