account home in history

This commit is contained in:
Nordup 2024-11-25 03:25:14 +04:00
parent ca4cb615b0
commit a441b81986
3 changed files with 22 additions and 39 deletions

View file

@ -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")

View file

@ -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:

View file

@ -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()