- Android back: application/config/quit_on_go_back=false; Main.go_back() (from NOTIFICATION_WM_GO_BACK_REQUEST, phones only) closes the shop or pouch panel or leaves build mode, else pauses; paused it closes the question, then settings, then resumes (shared with the pause action); at the main menu it closes the question or settings, else quits. - Phones hide the main menu's Quit and the pause menu's Quit the game. - ScreenLabels.ensure() makes the one ScreenLabels (ToonLook's on desktop; Main's on phones, which watch()es the tree for Label3Ds). Label sizes grow with the window's content_scale_factor (1 on desktop). - FollowCamera starts at PHONE_DISTANCE (12 m) on phones. - MobilePort.forced for tests; game/tests/mobile/platform_test.gd. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
4.6 KiB
GDScript
116 lines
4.6 KiB
GDScript
class_name MainMenu
|
|
extends Control
|
|
## The title screen over the farm (Main slowly circles a camera around it): the title, then
|
|
## Continue (with which morning it resumes at, or why the save can't be continued), New
|
|
## vacation, Play with a friend (co-op, CoopMenu; not on phones), Settings, and Quit (not on
|
|
## phones either), and a notice line (e.g.
|
|
## why a co-op game ended). Mouse, keyboard, and gamepad work through focus.
|
|
|
|
signal continue_requested
|
|
signal new_requested
|
|
signal settings_requested
|
|
signal coop_requested
|
|
signal quit_requested
|
|
|
|
var continue_button: Button
|
|
var new_button: Button
|
|
var settings_button: Button
|
|
var coop_button: Button
|
|
var notice: Label
|
|
var quit_button: Button
|
|
var save_note: Label
|
|
|
|
|
|
func _ready() -> void:
|
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
var shade := ColorRect.new() # darkens the left side behind the buttons
|
|
shade.color = Color(0.03, 0.04, 0.03, 0.62)
|
|
shade.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(shade)
|
|
shade.set_anchors_and_offsets_preset(Control.PRESET_LEFT_WIDE)
|
|
shade.offset_right = 700.0
|
|
var box := VBoxContainer.new()
|
|
box.position = Vector2(110.0, 150.0)
|
|
box.add_theme_constant_override("separation", 16)
|
|
add_child(box)
|
|
var title := Label.new()
|
|
title.text = "Harvest Season"
|
|
title.add_theme_font_size_override("font_size", 92)
|
|
title.add_theme_color_override("font_color", UiTheme.GOLD)
|
|
title.add_theme_color_override("font_outline_color", Color(0.15, 0.1, 0.05))
|
|
title.add_theme_constant_override("outline_size", 14)
|
|
box.add_child(title)
|
|
var sub := Label.new()
|
|
sub.text = "The farmers are away. You're the scarecrow."
|
|
sub.add_theme_font_size_override("font_size", 28)
|
|
sub.add_theme_color_override("font_color", UiTheme.TEXT)
|
|
box.add_child(sub)
|
|
var gap := Control.new()
|
|
gap.custom_minimum_size = Vector2(0.0, 50.0)
|
|
box.add_child(gap)
|
|
continue_button = _button(box, "Continue")
|
|
continue_button.pressed.connect(func() -> void: continue_requested.emit())
|
|
save_note = Label.new()
|
|
save_note.add_theme_font_size_override("font_size", 19)
|
|
save_note.add_theme_color_override("font_color", Color(0.75, 0.77, 0.7))
|
|
box.add_child(save_note)
|
|
new_button = _button(box, "New vacation")
|
|
new_button.pressed.connect(func() -> void: new_requested.emit())
|
|
coop_button = _button(box, "Play with a friend")
|
|
coop_button.pressed.connect(func() -> void: coop_requested.emit())
|
|
coop_button.visible = not MobilePort.active() # no co-op on phones
|
|
settings_button = _button(box, "Settings")
|
|
settings_button.pressed.connect(func() -> void: settings_requested.emit())
|
|
quit_button = _button(box, "Quit")
|
|
quit_button.pressed.connect(func() -> void: quit_requested.emit())
|
|
quit_button.visible = not MobilePort.active() # phones: the system closes apps (Android's back here, Main)
|
|
notice = Label.new()
|
|
notice.add_theme_font_size_override("font_size", 22)
|
|
notice.add_theme_color_override("font_color", Color(1.0, 0.75, 0.5))
|
|
box.add_child(notice)
|
|
var credits := Label.new()
|
|
credits.text = "Art: KayKit and ithappy · Sounds: Kenney (CC0) · Music: \"On the Farm\"; DavidKBD, Purgatory · Co-op: GD-Sync · Made with Godot"
|
|
credits.add_theme_font_size_override("font_size", 16)
|
|
credits.add_theme_color_override("font_color", Color(0.6, 0.62, 0.56))
|
|
add_child(credits)
|
|
credits.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_LEFT)
|
|
credits.offset_top = -60.0
|
|
credits.offset_left = 110.0
|
|
visible = false
|
|
|
|
|
|
## Shows the menu for the save as read (SaveGame.read): Continue says where it resumes, or is
|
|
## off with the reason.
|
|
func open(saved: SaveGame.Loaded, nights: int) -> void:
|
|
visible = true
|
|
var ok := saved != null and saved.status == SaveGame.Status.OK
|
|
continue_button.disabled = not ok
|
|
continue_button.focus_mode = Control.FOCUS_ALL if ok else Control.FOCUS_NONE
|
|
if ok:
|
|
save_note.text = "Morning of day %d of %d%s" % [saved.state.night, nights,
|
|
(" · saved " + saved.saved_at.replace("T", " ").left(16)) if saved.saved_at != "" else ""]
|
|
else:
|
|
save_note.text = saved.message if saved != null else "No saved vacation"
|
|
_focus_first.call_deferred()
|
|
|
|
|
|
func close() -> void:
|
|
visible = false
|
|
|
|
|
|
## Continue when it can be used, else New vacation (checked when it runs: open() may have been
|
|
## called again since).
|
|
func _focus_first() -> void:
|
|
if visible:
|
|
(new_button if continue_button.disabled else continue_button).grab_focus()
|
|
|
|
|
|
func _button(parent: Control, text: String) -> Button:
|
|
var b := Button.new()
|
|
b.text = text
|
|
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
b.custom_minimum_size = Vector2(380.0, 62.0)
|
|
b.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
|
|
b.add_theme_font_size_override("font_size", 28)
|
|
parent.add_child(b)
|
|
return b
|