From 2cf1eb61df2f7801eaf877ae944b386643f79fd1 Mon Sep 17 00:00:00 2001 From: Nordup Date: Thu, 22 Jun 2023 00:07:10 +0400 Subject: [PATCH] search results --- project/scenes/app.tscn | 4 +- project/scenes/menu_body/search_results.tscn | 43 +++++++++++++++++++ project/scripts/analytics/analytics_events.gd | 6 +-- .../analytics/analytics_sender_gate.gd | 6 +-- project/scripts/app.gd | 4 +- project/scripts/resources/gate_events.gd | 14 ++++-- project/scripts/ui/menu/menu_navigation.gd | 15 ++++--- project/scripts/ui/search.gd | 19 +------- project/scripts/ui/search/search_results.gd | 11 +++++ 9 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 project/scenes/menu_body/search_results.tscn create mode 100644 project/scripts/ui/search/search_results.gd diff --git a/project/scenes/app.tscn b/project/scenes/app.tscn index 83de4cc..6b9ef3e 100644 --- a/project/scenes/app.tscn +++ b/project/scenes/app.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=14 format=3 uid="uid://ct8gsph3wnepl"] +[gd_scene load_steps=15 format=3 uid="uid://ct8gsph3wnepl"] [ext_resource type="Script" path="res://scripts/app.gd" id="1_skc7d"] [ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_cdryv"] [ext_resource type="PackedScene" uid="uid://pgl3w7q5w84m" path="res://scenes/menu_body/bookmarks.tscn" id="3_l8glb"] [ext_resource type="PackedScene" uid="uid://5btb7nvgmfhl" path="res://scenes/menu.tscn" id="3_o1f7b"] [ext_resource type="PackedScene" uid="uid://kywrsqro3d5i" path="res://scenes/menu_body/world.tscn" id="4_p75rl"] +[ext_resource type="PackedScene" uid="uid://dh3owgirapji5" path="res://scenes/menu_body/search_results.tscn" id="4_phjpd"] [ext_resource type="Script" path="res://scripts/bookmark_saver.gd" id="5_ev0ch"] [ext_resource type="Script" path="res://scripts/analytics/analytics.gd" id="6_25d48"] [ext_resource type="Resource" uid="uid://bewhdj6jugt6q" path="res://resources/bookmarks.tres" id="6_rupvx"] @@ -18,6 +19,7 @@ script = ExtResource("1_skc7d") gate_events = ExtResource("2_cdryv") bookmarks = ExtResource("3_l8glb") +search_results = ExtResource("4_phjpd") world_scene = ExtResource("4_p75rl") scenes_root = NodePath("Menu/VBoxContainer/Body") diff --git a/project/scenes/menu_body/search_results.tscn b/project/scenes/menu_body/search_results.tscn new file mode 100644 index 0000000..9145bdc --- /dev/null +++ b/project/scenes/menu_body/search_results.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=3 format=3 uid="uid://dh3owgirapji5"] + +[ext_resource type="Script" path="res://scripts/ui/search/search_results.gd" id="1_bycb5"] +[ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_2plpa"] + +[node name="search_results" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Space" type="Control" parent="HBoxContainer"] +custom_minimum_size = Vector2(240, 0) +layout_mode = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +script = ExtResource("1_bycb5") +gate_events = ExtResource("2_2plpa") + +[node name="Label" type="Label" parent="HBoxContainer/VBoxContainer"] +self_modulate = Color(1, 1, 1, 0.6) +custom_minimum_size = Vector2(0, 64) +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "-------------------------------------------------------------------------------------------------- Search results -------------------------------------------------------------------------------------------------" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Space2" type="Control" parent="HBoxContainer"] +custom_minimum_size = Vector2(240, 0) +layout_mode = 2 diff --git a/project/scripts/analytics/analytics_events.gd b/project/scripts/analytics/analytics_events.gd index 82c7d3b..2360430 100644 --- a/project/scripts/analytics/analytics_events.gd +++ b/project/scripts/analytics/analytics_events.gd @@ -31,9 +31,9 @@ func app_exit(time_spend: int) -> Dictionary: # GATE -func search_press(url: String) -> Dictionary: - var event = base("search_press") - event.gate_url = url +func search(query: String) -> Dictionary: + var event = base("search") + event.query = query return event diff --git a/project/scripts/analytics/analytics_sender_gate.gd b/project/scripts/analytics/analytics_sender_gate.gd index aaf71ca..f7d73e2 100644 --- a/project/scripts/analytics/analytics_sender_gate.gd +++ b/project/scripts/analytics/analytics_sender_gate.gd @@ -10,7 +10,7 @@ var gate_url: String func start() -> void: super.start() - gate_events.search_pressed.connect(send_search_press) + gate_events.search.connect(send_search) gate_events.open_gate.connect(send_gate_open) gate_events.gate_entered.connect(send_gate_enter) gate_events.exit_gate.connect(send_gate_exit) @@ -22,8 +22,8 @@ func start() -> void: analytics.send_event(JSON.parse_string(json)) -func send_search_press(url: String) -> void: - analytics.send_event(AnalyticsEvents.search_press(url)) +func send_search(query: String) -> void: + analytics.send_event(AnalyticsEvents.search(query)) func send_gate_open(url: String) -> void: diff --git a/project/scripts/app.gd b/project/scripts/app.gd index db31a79..6b2f714 100644 --- a/project/scripts/app.gd +++ b/project/scripts/app.gd @@ -2,15 +2,17 @@ extends Node @export var gate_events: GateEvents @export var bookmarks: PackedScene +@export var search_results: PackedScene @export var world_scene: PackedScene @export var scenes_root: Node func _ready() -> void: + gate_events.search.connect(func(_query): switch_scene(search_results)) gate_events.open_gate.connect(func(_url): switch_scene(world_scene)) gate_events.exit_gate.connect(func(): switch_scene(bookmarks)) - scenes_root.add_child(bookmarks.instantiate()) + switch_scene(bookmarks) func switch_scene(scene: PackedScene) -> void: diff --git a/project/scripts/resources/gate_events.gd b/project/scripts/resources/gate_events.gd index 4bae62f..d5810da 100644 --- a/project/scripts/resources/gate_events.gd +++ b/project/scripts/resources/gate_events.gd @@ -1,24 +1,30 @@ extends Resource class_name GateEvents -signal search_pressed(url: String) +signal search(query: String) signal open_gate(url: String) signal gate_info_loaded(gate: Gate) signal gate_loaded(gate: Gate) signal gate_entered signal exit_gate +var current_search_query: String var current_gate_url: String var current_gate: Gate func open_gate_emit(url: String) -> void: current_gate_url = Url.fix_gate_url(url) + current_search_query = "" + open_gate.emit(current_gate_url) -func search_pressed_emit(url: String) -> void: - search_pressed.emit(url) +func search_emit(query: String) -> void: + current_search_query = query + current_gate_url = "" + + search.emit(query) func gate_info_loaded_emit(gate: Gate) -> void: @@ -36,6 +42,8 @@ func gate_entered_emit() -> void: func exit_gate_emit() -> void: + current_search_query = "" current_gate_url = "" current_gate = null + exit_gate.emit() diff --git a/project/scripts/ui/menu/menu_navigation.gd b/project/scripts/ui/menu/menu_navigation.gd index 0e1430c..e5ec027 100644 --- a/project/scripts/ui/menu/menu_navigation.gd +++ b/project/scripts/ui/menu/menu_navigation.gd @@ -10,7 +10,8 @@ extends Node func _ready() -> void: - gate_events.open_gate.connect(on_open_gate) + gate_events.open_gate.connect(on_new) + gate_events.search.connect(on_new) go_back.pressed.connect(on_go_back) go_forw.pressed.connect(on_go_forw) @@ -20,32 +21,32 @@ func _ready() -> void: disable([go_back, go_forw, reload, home]) -func on_open_gate(url: String) -> void: - history.add(url) +func on_new(location: String) -> void: + history.add(location) enable([go_back, reload, home]) if not history.can_forw(): disable([go_forw]) func on_go_back() -> void: - var url = history.back() + var location = history.back() enable([go_forw]) if history.can_back(): - gate_events.open_gate_emit(url) + gate_events.open_gate_emit(location) else: disable([go_back, reload, home]) gate_events.exit_gate_emit() func on_go_forw() -> void: - var url = history.forw() + var location = history.forw() enable([go_back]) if not history.can_forw(): disable([go_forw]) - gate_events.open_gate_emit(url) + gate_events.open_gate_emit(location) func on_reload() -> void: diff --git a/project/scripts/ui/search.gd b/project/scripts/ui/search.gd index 4455412..796473f 100644 --- a/project/scripts/ui/search.gd +++ b/project/scripts/ui/search.gd @@ -35,25 +35,8 @@ func _on_go_pressed() -> void: func open_gate() -> void: - gate_events.search_pressed_emit(url) if Url.is_valid(url): - release_focus() gate_events.open_gate_emit(url) else: - shake() - - -func shake() -> void: + gate_events.search_emit(url) release_focus() - var tween = get_tree().create_tween() - var pos = position - const delta = Vector2(0, 5) - const duration = 0.07 - tween.tween_property(self, "position", pos + delta, duration) - tween.tween_property(self, "position", pos - delta, duration) - tween.tween_property(self, "position", pos + delta, duration) - tween.tween_property(self, "position", pos - delta, duration) - tween.tween_property(self, "position", pos, duration) - await tween.finished - grab_focus() - diff --git a/project/scripts/ui/search/search_results.gd b/project/scripts/ui/search/search_results.gd new file mode 100644 index 0000000..db6369b --- /dev/null +++ b/project/scripts/ui/search/search_results.gd @@ -0,0 +1,11 @@ +extends VBoxContainer + +@export var gate_events: GateEvents + + +func _ready() -> void: + search(gate_events.current_search_query) + + +func search(query: String) -> void: + Debug.logclr("======== " + query + " ========", Color.LIGHT_SEA_GREEN)