162 lines
5.4 KiB
GDScript3
162 lines
5.4 KiB
GDScript3
|
|
extends CanvasLayer
|
||
|
|
## Global UI: pause, inventory, shop, settings, toast, dialog, burger-cham.
|
||
|
|
|
||
|
|
@onready var pause_panel: PanelContainer = $PausePanel
|
||
|
|
@onready var dialog_panel: PanelContainer = $DialogPanel
|
||
|
|
@onready var dialog_label: Label = $DialogPanel/Margin/DialogLabel
|
||
|
|
@onready var toast_label: Label = $ToastLabel
|
||
|
|
@onready var burger_overlay: ColorRect = $BurgerOverlay
|
||
|
|
@onready var burger_label: Label = $BurgerOverlay/BurgerLabel
|
||
|
|
@onready var points_label: Label = $PausePanel/Margin/VBox/PointsLabel
|
||
|
|
@onready var inventory_list: ItemList = $PausePanel/Margin/VBox/InventoryList
|
||
|
|
@onready var sfx_slider: HSlider = $PausePanel/Margin/VBox/SfxSlider
|
||
|
|
@onready var music_slider: HSlider = $PausePanel/Margin/VBox/MusicSlider
|
||
|
|
@onready var lang_option: OptionButton = $PausePanel/Margin/VBox/LangOption
|
||
|
|
@onready var hp_label: Label = $HUD/HpLabel
|
||
|
|
|
||
|
|
var _dialog_timer: float = 0.0
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
||
|
|
layer = 100
|
||
|
|
pause_panel.visible = false
|
||
|
|
dialog_panel.visible = false
|
||
|
|
burger_overlay.visible = false
|
||
|
|
toast_label.visible = false
|
||
|
|
_setup_lang_option()
|
||
|
|
_refresh_texts()
|
||
|
|
sfx_slider.value = Settings.sfx_volume
|
||
|
|
music_slider.value = 1.0
|
||
|
|
music_slider.editable = false
|
||
|
|
Achievements.unlocked.connect(_on_achievement)
|
||
|
|
AudioDirector.burger_cham_triggered.connect(_on_burger_cham)
|
||
|
|
Settings.settings_changed.connect(_refresh_texts)
|
||
|
|
Locale.locale_changed.connect(_refresh_texts)
|
||
|
|
Inventory.inventory_changed.connect(_refresh_inventory)
|
||
|
|
Shop.points_changed.connect(_refresh_points)
|
||
|
|
GameState.hp_changed.connect(_on_hp)
|
||
|
|
_on_hp(GameState.hp, GameState.max_hp)
|
||
|
|
_refresh_inventory()
|
||
|
|
_refresh_points(Shop.dressler_points)
|
||
|
|
|
||
|
|
func _process(delta: float) -> void:
|
||
|
|
if _dialog_timer > 0.0:
|
||
|
|
_dialog_timer -= delta
|
||
|
|
if _dialog_timer <= 0.0:
|
||
|
|
dialog_panel.visible = false
|
||
|
|
|
||
|
|
func _unhandled_input(event: InputEvent) -> void:
|
||
|
|
if event.is_action_pressed("pause_menu"):
|
||
|
|
toggle_pause()
|
||
|
|
get_viewport().set_input_as_handled()
|
||
|
|
|
||
|
|
func toggle_pause() -> void:
|
||
|
|
if GameState.current_scene_id in ["title_screen", "death_screen", "intro_cutscene"]:
|
||
|
|
return
|
||
|
|
pause_panel.visible = not pause_panel.visible
|
||
|
|
get_tree().paused = pause_panel.visible
|
||
|
|
if pause_panel.visible:
|
||
|
|
_refresh_texts()
|
||
|
|
_refresh_inventory()
|
||
|
|
|
||
|
|
func show_dialog(text: String, duration: float = 3.5) -> void:
|
||
|
|
dialog_label.text = text
|
||
|
|
dialog_panel.visible = true
|
||
|
|
_dialog_timer = duration
|
||
|
|
|
||
|
|
func _setup_lang_option() -> void:
|
||
|
|
lang_option.clear()
|
||
|
|
lang_option.add_item("Deutsch", 0)
|
||
|
|
lang_option.add_item("English", 1)
|
||
|
|
lang_option.add_item("Bayerisch", 2)
|
||
|
|
match Settings.language:
|
||
|
|
"en":
|
||
|
|
lang_option.select(1)
|
||
|
|
"by":
|
||
|
|
lang_option.select(2)
|
||
|
|
_:
|
||
|
|
lang_option.select(0)
|
||
|
|
|
||
|
|
func _refresh_texts() -> void:
|
||
|
|
$PausePanel/Margin/VBox/TitleLabel.text = Locale.tr_key("menu_settings")
|
||
|
|
$PausePanel/Margin/VBox/ResumeButton.text = Locale.tr_key("menu_resume")
|
||
|
|
$PausePanel/Margin/VBox/ShopTitle.text = Locale.tr_key("menu_shop")
|
||
|
|
$PausePanel/Margin/VBox/BuyPointButton.text = Locale.tr_key("menu_buy_point")
|
||
|
|
$PausePanel/Margin/VBox/BuySunglassesButton.text = Locale.tr_key("shop_sunglasses")
|
||
|
|
$PausePanel/Margin/VBox/BuyTicketButton.text = Locale.tr_key("shop_ticket")
|
||
|
|
$PausePanel/Margin/VBox/BuyMilkButton.text = Locale.tr_key("shop_milk")
|
||
|
|
$PausePanel/Margin/VBox/BuyTiramisuButton.text = Locale.tr_key("shop_tiramisu")
|
||
|
|
$PausePanel/Margin/VBox/SfxLabel.text = Locale.tr_key("menu_sfx")
|
||
|
|
$PausePanel/Margin/VBox/MusicLabel.text = Locale.tr_key("menu_music")
|
||
|
|
$PausePanel/Margin/VBox/LangLabel.text = Locale.tr_key("menu_language")
|
||
|
|
$PausePanel/Margin/VBox/InventoryLabel.text = Locale.tr_key("menu_inventory")
|
||
|
|
_refresh_points(Shop.dressler_points)
|
||
|
|
|
||
|
|
func _refresh_points(points: int) -> void:
|
||
|
|
points_label.text = Locale.tr_key("menu_points", [str(points)])
|
||
|
|
|
||
|
|
func _refresh_inventory() -> void:
|
||
|
|
inventory_list.clear()
|
||
|
|
var items := Inventory.get_all()
|
||
|
|
for id in items.keys():
|
||
|
|
var count: int = int(items[id])
|
||
|
|
var item_name: String = Locale.tr_key("item_" + str(id))
|
||
|
|
inventory_list.add_item("%s x%d" % [item_name, count])
|
||
|
|
inventory_list.set_item_metadata(inventory_list.item_count - 1, id)
|
||
|
|
|
||
|
|
func _on_hp(hp: int, max_hp: int) -> void:
|
||
|
|
hp_label.text = "HP %d/%d" % [hp, max_hp]
|
||
|
|
|
||
|
|
func _on_achievement(_id: String, title: String) -> void:
|
||
|
|
toast_label.text = Locale.tr_key("toast_achievement", [title])
|
||
|
|
toast_label.visible = true
|
||
|
|
await get_tree().create_timer(3.0).timeout
|
||
|
|
toast_label.visible = false
|
||
|
|
|
||
|
|
func _on_burger_cham() -> void:
|
||
|
|
burger_label.text = Locale.tr_key("burger_cham")
|
||
|
|
burger_overlay.visible = true
|
||
|
|
await get_tree().create_timer(2.5).timeout
|
||
|
|
burger_overlay.visible = false
|
||
|
|
|
||
|
|
func _on_resume_pressed() -> void:
|
||
|
|
pause_panel.visible = false
|
||
|
|
get_tree().paused = false
|
||
|
|
|
||
|
|
func _on_buy_point() -> void:
|
||
|
|
Shop.purchase("buy_point")
|
||
|
|
|
||
|
|
func _on_buy_sunglasses() -> void:
|
||
|
|
Shop.purchase("sunglasses")
|
||
|
|
|
||
|
|
func _on_buy_ticket() -> void:
|
||
|
|
Shop.purchase("death_ticket")
|
||
|
|
|
||
|
|
func _on_buy_milk() -> void:
|
||
|
|
Shop.purchase("milk")
|
||
|
|
|
||
|
|
func _on_buy_tiramisu() -> void:
|
||
|
|
Shop.purchase("tiramisu")
|
||
|
|
|
||
|
|
func _on_sfx_changed(value: float) -> void:
|
||
|
|
Settings.set_sfx_volume(value)
|
||
|
|
|
||
|
|
func _on_music_changed(_value: float) -> void:
|
||
|
|
Settings.set_music_volume(1.0)
|
||
|
|
music_slider.value = 1.0
|
||
|
|
|
||
|
|
func _on_lang_selected(index: int) -> void:
|
||
|
|
match index:
|
||
|
|
1:
|
||
|
|
Settings.set_language("en")
|
||
|
|
2:
|
||
|
|
Settings.set_language("by")
|
||
|
|
_:
|
||
|
|
Settings.set_language("de")
|
||
|
|
|
||
|
|
func _on_inventory_activated(index: int) -> void:
|
||
|
|
var id: Variant = inventory_list.get_item_metadata(index)
|
||
|
|
if typeof(id) == TYPE_STRING:
|
||
|
|
Inventory.use_item(str(id))
|
||
|
|
_refresh_inventory()
|