diff --git a/project/scenes/components/result.tscn b/project/scenes/components/result.tscn new file mode 100644 index 0000000..20274b1 --- /dev/null +++ b/project/scenes/components/result.tscn @@ -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"] diff --git a/project/scenes/menu_body/search_results.tscn b/project/scenes/menu_body/search_results.tscn index bdb654b..f9fb49f 100644 --- a/project/scenes/menu_body/search_results.tscn +++ b/project/scenes/menu_body/search_results.tscn @@ -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 diff --git a/project/scripts/loading/gate_loader.gd b/project/scripts/loading/gate_loader.gd index 7b5a795..2d06f50 100644 --- a/project/scripts/loading/gate_loader.gd +++ b/project/scripts/loading/gate_loader.gd @@ -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) diff --git a/project/scripts/ui/menu/bookmark_ui.gd b/project/scripts/ui/menu/bookmark_ui.gd index 256dae2..5e9a5f1 100644 --- a/project/scripts/ui/menu/bookmark_ui.gd +++ b/project/scripts/ui/menu/bookmark_ui.gd @@ -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) diff --git a/project/scripts/ui/menu/history.gd b/project/scripts/ui/menu/history.gd index e6a5540..4ed0601 100644 --- a/project/scripts/ui/menu/history.gd +++ b/project/scripts/ui/menu/history.gd @@ -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 diff --git a/project/scripts/ui/menu/star.gd b/project/scripts/ui/menu/star.gd index 10b9c33..996c527 100644 --- a/project/scripts/ui/menu/star.gd +++ b/project/scripts/ui/menu/star.gd @@ -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) diff --git a/project/scripts/ui/search/one_line_text.gd b/project/scripts/ui/search/one_line_text.gd new file mode 100644 index 0000000..656e0ed --- /dev/null +++ b/project/scripts/ui/search/one_line_text.gd @@ -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 diff --git a/project/scripts/ui/search/result.gd b/project/scripts/ui/search/result.gd new file mode 100644 index 0000000..4ecab3d --- /dev/null +++ b/project/scripts/ui/search/result.gd @@ -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) diff --git a/project/scripts/ui/search/search_results.gd b/project/scripts/ui/search/search_results.gd index cc36fa0..9b40fbe 100644 --- a/project/scripts/ui/search/search_results.gd +++ b/project/scripts/ui/search/search_results.gd @@ -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)