search done

This commit is contained in:
Nordup 2023-06-27 23:56:04 +04:00
parent da284d08c6
commit 8aa9c1cdc2
9 changed files with 181 additions and 22 deletions

View file

@ -0,0 +1,120 @@
[gd_scene load_steps=8 format=3 uid="uid://i3lgu2dyypcq"]
[ext_resource type="Script" path="res://scripts/ui/search/result.gd" id="1_b6nfm"]
[ext_resource type="Texture2D" uid="uid://cykx425p6ylwr" path="res://textures/background.png" id="1_cbuy3"]
[ext_resource type="Script" path="res://scripts/ui/search/one_line_text.gd" id="2_nxics"]
[ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_wgd6i"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_7mafe"]
bg_color = Color(0.25098, 0.25098, 0.25098, 0)
corner_radius_top_left = 16
corner_radius_top_right = 16
corner_radius_bottom_right = 16
corner_radius_bottom_left = 16
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_37xan"]
bg_color = Color(0.25098, 0.25098, 0.25098, 1)
corner_radius_top_left = 16
corner_radius_top_right = 16
corner_radius_bottom_right = 16
corner_radius_bottom_left = 16
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6os7t"]
corner_radius_top_left = 16
corner_radius_top_right = 16
corner_radius_bottom_right = 16
corner_radius_bottom_left = 16
[node name="result" type="Button" node_paths=PackedStringArray("url", "title", "description", "image")]
custom_minimum_size = Vector2(0, 132)
anchors_preset = 14
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/normal = SubResource("StyleBoxFlat_7mafe")
theme_override_styles/hover = SubResource("StyleBoxFlat_37xan")
theme_override_styles/pressed = SubResource("StyleBoxFlat_37xan")
script = ExtResource("1_b6nfm")
gate_events = ExtResource("2_wgd6i")
url = NodePath("HBoxContainer/VBoxContainer/HBoxContainer/Url")
title = NodePath("HBoxContainer/VBoxContainer/HBoxContainer/Title")
description = NodePath("HBoxContainer/VBoxContainer/Description")
image = NodePath("HBoxContainer/Mask/Image")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 16.0
offset_right = -16.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 16
[node name="Mask" type="Panel" parent="HBoxContainer"]
clip_children = 1
custom_minimum_size = Vector2(100, 100)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
mouse_filter = 1
theme_override_styles/panel = SubResource("StyleBoxFlat_6os7t")
[node name="Image" type="TextureRect" parent="HBoxContainer/Mask"]
custom_minimum_size = Vector2(87, 87)
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture = ExtResource("1_cbuy3")
expand_mode = 1
stretch_mode = 6
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
custom_minimum_size = Vector2(0, 80)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_constants/separation = 16
[node name="Title" type="Label" parent="HBoxContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 24
text = "Title"
[node name="Slash" type="Label" parent="HBoxContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 24
text = "/"
[node name="Url" type="Label" parent="HBoxContainer/VBoxContainer/HBoxContainer"]
self_modulate = Color(1, 1, 1, 0.8)
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 20
text = "http://localhost:8000"
[node name="Description" type="RichTextLabel" parent="HBoxContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
mouse_filter = 1
theme_override_font_sizes/normal_font_size = 20
bbcode_enabled = true
text = "Description alskdhflshdflkasldfkjslakdjflasdf
;alskdfaslkdhflaksjdfl;kasjdf
laskdf;laskhdflkasjdf;"
scroll_active = false
script = ExtResource("2_nxics")
[connection signal="pressed" from="." to="." method="_on_button_pressed"]

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=3 uid="uid://dh3owgirapji5"]
[gd_scene load_steps=5 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"]
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/api_settings.tres" id="3_263ma"]
[ext_resource type="PackedScene" uid="uid://i3lgu2dyypcq" path="res://scenes/components/result.tscn" id="4_yxn4t"]
[node name="search_results" type="Control"]
layout_mode = 3
@ -24,14 +25,19 @@ grow_vertical = 2
custom_minimum_size = Vector2(240, 0)
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
[node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
script = ExtResource("1_bycb5")
gate_events = ExtResource("2_2plpa")
api = ExtResource("3_263ma")
result_scene = ExtResource("4_yxn4t")
[node name="Label" type="Label" parent="HBoxContainer/VBoxContainer"]
[node name="Label" type="Label" parent="HBoxContainer/ScrollContainer/VBoxContainer"]
self_modulate = Color(1, 1, 1, 0.6)
custom_minimum_size = Vector2(0, 64)
layout_mode = 2

View file

@ -11,7 +11,7 @@ func _ready() -> void:
func load_gate(config_url: String) -> void:
Debug.logclr("======== " + config_url + " ========", Color.GREEN)
var config_path: String = await FileDownloader.download(config_url)
var config_path = await FileDownloader.download(config_url)
c_gate = ConfigGate.new(config_path, config_url)
gate_events.gate_config_loaded_emit(config_url, c_gate)

View file

@ -5,17 +5,17 @@ class_name BookmarkUI
@export var image: TextureRect
@export var title: Label
var gate: Gate
var url: String
func fill(_gate: Gate) -> void:
if _gate == null: return
gate = _gate
func fill(gate: Gate) -> void:
if gate == null: return
url = gate.url
title.text = "Unnamed" if gate.title.is_empty() else gate.title
image.texture = FileTools.load_external_tex(gate.image)
func _on_base_button_pressed() -> void:
if gate == null or gate.url.is_empty(): return
gate_events.open_gate_emit(gate.url)
if url.is_empty(): return
gate_events.open_gate_emit(url)

View file

@ -48,4 +48,5 @@ func clear() -> void:
func print_history() -> void:
Debug.logclr("History: " + str(history) + " Current: " + str(index), Color.DIM_GRAY)
# Debug.logclr("History: " + str(history) + " Current: " + str(index), Color.DIM_GRAY)
pass

View file

@ -15,6 +15,7 @@ func _ready() -> void:
unstar.visible = false
gate_events.open_gate.connect(show_buttons)
gate_events.search.connect(func(_query): hide_buttons())
gate_events.exit_gate.connect(hide_buttons)
gate_events.gate_info_loaded.connect(update_info)

View file

@ -0,0 +1,9 @@
extends RichTextLabel
func _ready() -> void:
finished.connect(to_line)
func to_line() -> void:
text = text.replace('\n', '\t') # TODO: Handle BBCode

View file

@ -0,0 +1,25 @@
extends Control
class_name SearchResult
@export var gate_events: GateEvents
@export var url: Label
@export var title: Label
@export var description: RichTextLabel
@export var image: TextureRect
func fill(gate: Dictionary) -> void:
if gate == null: return
url.text = gate["url"]
title.text = "Unnamed" if gate["title"].is_empty() else gate["title"]
description.text = gate["description"]
var image_path = await FileDownloader.download(gate["image"])
image.texture = FileTools.load_external_tex(image_path)
func _on_button_pressed() -> void:
if url.text.is_empty(): return
gate_events.open_gate_emit(url.text)

View file

@ -2,8 +2,9 @@ extends VBoxContainer
@export var gate_events: GateEvents
@export var api: ApiSettings
@export var result_scene: PackedScene
var result: String
var result_str: String
func _ready() -> void:
@ -14,27 +15,23 @@ func search(query: String) -> void:
Debug.logclr("======== " + query + " ========", Color.LIGHT_SEA_GREEN)
await search_request(query)
var gates = JSON.parse_string(result)
var gates = JSON.parse_string(result_str)
if gates == null or gates.is_empty():
Debug.logclr("No gates found", Color.YELLOW)
return
for gate in gates:
var url = gate["url"]
var title = gate["title"]
var image = gate["image"]
var description = gate["description"]
Debug.logr(gate)
#func add_result()
var result: SearchResult = result_scene.instantiate()
result.fill(gate)
add_child(result)
Debug.logr(gate["url"])
func search_request(query: String):
var url = api.search + query.uri_encode()
var callback = func(_result, code, _headers, body):
if code == 200:
result = body.get_string_from_utf8()
result_str = body.get_string_from_utf8()
else: Debug.logclr("Request search failed. Code " + str(code), Color.RED)
var err = await Backend.request(url, callback)