diff --git a/project/resources/history.tres b/project/resources/history.tres new file mode 100644 index 0000000..af6c282 --- /dev/null +++ b/project/resources/history.tres @@ -0,0 +1,6 @@ +[gd_resource type="Resource" script_class="History" load_steps=2 format=3 uid="uid://bqgikyax6jfqa"] + +[ext_resource type="Script" path="res://scripts/ui/menu/history.gd" id="1_oh8jq"] + +[resource] +script = ExtResource("1_oh8jq") diff --git a/project/scenes/menu.tscn b/project/scenes/menu.tscn index 62ffb23..c229559 100644 --- a/project/scenes/menu.tscn +++ b/project/scenes/menu.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=17 format=3 uid="uid://5btb7nvgmfhl"] +[gd_scene load_steps=18 format=3 uid="uid://5btb7nvgmfhl"] +[ext_resource type="Script" path="res://scripts/ui/menu/menu_navigation.gd" id="1_7anvm"] [ext_resource type="Texture2D" uid="uid://8wvea7j0v0rx" path="res://textures/Reload.svg" id="1_d6dhb"] [ext_resource type="Texture2D" uid="uid://byvigfpu44dnu" path="res://textures/arrow.svg" id="1_wkgtd"] -[ext_resource type="Script" path="res://scripts/ui/world/home.gd" id="2_l5iu6"] [ext_resource type="Texture2D" uid="uid://dystd8vvbqwo2" path="res://textures/exit.svg" id="3_1a6fk"] [ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="3_m632k"] +[ext_resource type="Resource" uid="uid://bqgikyax6jfqa" path="res://resources/history.tres" id="3_wi554"] [ext_resource type="Texture2D" uid="uid://bmju020v33vrv" path="res://textures/home.svg" id="4_5npup"] [ext_resource type="Script" path="res://scripts/ui/menu/exit_app.gd" id="4_2065t"] [ext_resource type="PackedScene" uid="uid://ctam0fxigbefk" path="res://scenes/components/search.tscn" id="5_li2do"] @@ -183,7 +184,7 @@ grow_horizontal = 2 grow_vertical = 2 theme_override_styles/panel = SubResource("StyleBoxFlat_re7ca") -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Top"] +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Top" node_paths=PackedStringArray("go_back", "go_forw", "reload", "home")] layout_mode = 1 anchors_preset = 13 anchor_left = 0.5 @@ -195,6 +196,13 @@ grow_horizontal = 2 grow_vertical = 2 theme_override_constants/separation = 20 alignment = 1 +script = ExtResource("1_7anvm") +gate_events = ExtResource("3_m632k") +history = ExtResource("3_wi554") +go_back = NodePath("GoBack") +go_forw = NodePath("GoForward") +reload = NodePath("Reload") +home = NodePath("Home") [node name="GoBack" type="BaseButton" parent="VBoxContainer/Top/HBoxContainer"] _import_path = NodePath("") @@ -457,8 +465,7 @@ button_group = null shortcut = null shortcut_feedback = true shortcut_in_tooltip = true -script = ExtResource("2_l5iu6") -gate_events = ExtResource("3_m632k") +script = null [node name="TextureRect" type="TextureRect" parent="VBoxContainer/Top/HBoxContainer/Home"] layout_mode = 1 @@ -565,5 +572,4 @@ script = ExtResource("7_1hi62") ui_events = ExtResource("8_8dnbq") gate_events = ExtResource("3_m632k") -[connection signal="pressed" from="VBoxContainer/Top/HBoxContainer/Home" to="VBoxContainer/Top/HBoxContainer/Home" method="_on_pressed"] [connection signal="pressed" from="VBoxContainer/Top/Exit" to="VBoxContainer/Top/Exit" method="_on_pressed"] diff --git a/project/scripts/ui/menu/history.gd b/project/scripts/ui/menu/history.gd new file mode 100644 index 0000000..09db7c2 --- /dev/null +++ b/project/scripts/ui/menu/history.gd @@ -0,0 +1,47 @@ +extends Resource +class_name History + +var history: Array[String] +var index := -1 + + +func get_current() -> String: + if index == -1: return "" + return history[index] + + +func can_forw() -> bool: + return index + 1 < history.size() + + +func can_back() -> bool: + return index > -1 + + +func add(url: String) -> void: + if url == get_current(): return + + index += 1 + history.resize(index) + history.push_back(url) + print(str(history) + " " + str(index)) + + +func forw() -> String: + index += 1 + print(str(history) + " " + str(index)) + return history[index] + + +func back() -> String: + index -= 1 + print(str(history) + " " + str(index)) + if index == -1: + return "" + return history[index] + + +func clear() -> void: + index = -1 + history.clear() + print(str(history) + " " + str(index)) diff --git a/project/scripts/ui/menu/menu_navigation.gd b/project/scripts/ui/menu/menu_navigation.gd new file mode 100644 index 0000000..1c554a5 --- /dev/null +++ b/project/scripts/ui/menu/menu_navigation.gd @@ -0,0 +1,67 @@ +extends Node + +@export var gate_events: GateEvents +@export var history: History + +@export var go_back: BaseButton +@export var go_forw: BaseButton +@export var reload: BaseButton +@export var home: BaseButton + + +func _ready() -> void: + gate_events.open_gate.connect(on_open_gate) + + go_back.pressed.connect(on_go_back) + go_forw.pressed.connect(on_go_forw) + reload.pressed.connect(on_reload) + home.pressed.connect(on_home) + + disable([go_back, go_forw, reload, home]) + + +func on_open_gate(url: String) -> void: + history.add(url) + enable([go_back, reload, home]) + + +func on_go_back() -> void: + var url = history.back() + if url == "": + on_home() + else: + gate_events.open_gate_emit(url) + enable([go_forw]) + + +func on_go_forw() -> void: + var url = history.forw() + + enable([go_back]) + if not history.can_forw(): + disable([go_forw]) + + gate_events.open_gate_emit(url) + + +func on_reload() -> void: + gate_events.open_gate_emit(history.get_current()) + + +func on_home() -> void: + disable([go_back, go_forw, reload, home]) + gate_events.exit_gate_emit() + + +func disable(buttons: Array[BaseButton]) -> void: + for button in buttons: + button.disabled = true + button.modulate.a = 0.5 + button.mouse_default_cursor_shape = Control.CURSOR_ARROW + + +func enable(buttons: Array[BaseButton]) -> void: + for button in buttons: + button.disabled = false + button.modulate.a = 1 + button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND diff --git a/project/scripts/ui/world/home.gd b/project/scripts/ui/world/home.gd deleted file mode 100644 index 631a330..0000000 --- a/project/scripts/ui/world/home.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends BaseButton - -@export var gate_events: GateEvents - - -func _on_pressed() -> void: - gate_events.exit_gate_emit()