From a441b81986daec608865d7d89d5a8a6881a8a073 Mon Sep 17 00:00:00 2001 From: Nordup Date: Mon, 25 Nov 2024 03:25:14 +0400 Subject: [PATCH] account home in history --- app/scenes/components/search_home.tscn | 2 +- app/scripts/ui/menu/history.gd | 6 +-- app/scripts/ui/menu/menu_navigation.gd | 53 +++++++++----------------- 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/app/scenes/components/search_home.tscn b/app/scenes/components/search_home.tscn index f6ec099..9e1ff07 100644 --- a/app/scenes/components/search_home.tscn +++ b/app/scenes/components/search_home.tscn @@ -89,7 +89,7 @@ theme_override_fonts/font = ExtResource("1_o2a5w") theme_override_font_sizes/font_size = 20 theme_override_styles/focus = SubResource("StyleBoxFlat_w0n18") theme_override_styles/normal = SubResource("StyleBoxFlat_w0n18") -placeholder_text = "Search or type URL" +placeholder_text = "What are you looking for today?" script = ExtResource("2_g181m") gate_events = ExtResource("3_bulmv") prompt_panel = NodePath("Prompt/Panel") diff --git a/app/scripts/ui/menu/history.gd b/app/scripts/ui/menu/history.gd index 4ed0601..f61646a 100644 --- a/app/scripts/ui/menu/history.gd +++ b/app/scripts/ui/menu/history.gd @@ -1,8 +1,8 @@ extends Resource class_name History -var history: Array[String] -var index := -1 +var history: Array[String] = [""] +var index := 0 func get_current() -> String: @@ -15,7 +15,7 @@ func can_forw() -> bool: func can_back() -> bool: - return index > -1 + return index > 0 func add(url: String) -> void: diff --git a/app/scripts/ui/menu/menu_navigation.gd b/app/scripts/ui/menu/menu_navigation.gd index a2c1c77..da52d74 100644 --- a/app/scripts/ui/menu/menu_navigation.gd +++ b/app/scripts/ui/menu/menu_navigation.gd @@ -12,65 +12,48 @@ extends Node func _ready() -> void: gate_events.open_gate.connect(on_new) gate_events.search.connect(on_new) + gate_events.exit_gate.connect(on_new.bind("")) go_back.pressed.connect(on_go_back) go_forw.pressed.connect(on_go_forw) reload.pressed.connect(on_reload) - home.pressed.connect(on_home) + home.pressed.connect(gate_events.exit_gate_emit) - disable([go_back, go_forw, reload, home]) + go_back.disable() + go_forw.disable() func on_new(location: String) -> void: history.add(location) - enable([go_back, reload, home]) - if not history.can_forw(): - disable([go_forw]) + update_buttons() func on_go_back() -> void: - var location = history.back() - - enable([go_forw]) - if history.can_back(): - open(location) - else: - disable([go_back, reload, home]) - gate_events.exit_gate_emit() + open(history.back()) + update_buttons() func on_go_forw() -> void: - var location = history.forw() - - enable([go_back]) - if not history.can_forw(): - disable([go_forw]) - - open(location) + open(history.forw()) + update_buttons() func on_reload() -> void: open(history.get_current()) -func on_home() -> void: - history.clear() - disable([go_back, go_forw, reload, home]) - gate_events.exit_gate_emit() - - func open(location: String) -> void: - if Url.is_valid(location): + if location == "": + gate_events.exit_gate_emit() + elif Url.is_valid(location): gate_events.open_gate_emit(location) else: gate_events.search_emit(location) -func disable(buttons: Array[RoundButton]) -> void: - for button in buttons: - button.disable() - - -func enable(buttons: Array[RoundButton]) -> void: - for button in buttons: - button.enable() +func update_buttons() -> void: + if history.can_back(): go_back.enable() + else: go_back.disable() + + if history.can_forw(): go_forw.enable() + else: go_forw.disable()