Skip to main content

Overview

The main_menu.gd script controls Nyuron’s main menu scene. It handles:
  • Minigame launching with proper screen orientation
  • Character skin updates based on equipped items
  • Progress panel and store navigation
  • Coin display formatting
  • Decorative seagull spawning
  • UI fade-in animations
Scene Path: res://scenes/main_menu.tscn

Key Methods

update_menu_skin()

Updates the character’s visual appearance based on equipped items from ScoreManager.
return
void
No return value
How it works:
  1. Fetches equipped shell and accessory from ScoreManager
  2. Maps item names to file suffixes using lookup dictionaries
  3. Constructs texture path: res://Accesorios/global/spr_rest{color}{accessory}.png
  4. Applies texture to AnimatedSprite2D frames
Example texture paths:
  • Default: spr_rest.png
  • Blue shell: spr_rest_blue.png
  • Blue shell + crown: spr_rest_blue_corona.png
Called:
  • During _ready() (main_menu.gd:58)
  • After skin changes via ScoreManager signal
Example Usage:
# From main_menu.gd:98-115
func update_menu_skin():
    var id_cuerpo = ScoreManager.get_equipped_item("caparazon")
    var id_accesorio = ScoreManager.get_equipped_item("accesorio")
    
    var color_suffix = menu_color_codes.get(id_cuerpo, "")
    var acc_suffix = menu_accessory_codes.get(id_accesorio, "")
    
    var final_path = "res://Accesorios/global/spr_rest" + color_suffix + acc_suffix + ".png"
    
    if ResourceLoader.exists(final_path):
        var new_texture = load(final_path)
        _apply_texture_to_menu_anim(new_texture)

fade_in_ui()

Animates UI elements from transparent to opaque after scene loads.
duration
float
default:"0.45"
Duration of fade animation in seconds
return
void
No return value
Implementation:
  • Targets all nodes in the "ui" group
  • Tweens modulate.a from 0.0 to 1.0
  • Re-enables mouse interaction after fade completes
Example Usage:
# From main_menu.gd:69-72
if TransitionBlocks.visible:
    TransitionBlocks.transition_finished.connect(func(): fade_in_ui())
else:
    fade_in_ui()

# Manual call with custom duration
fade_in_ui(0.3)  # Faster fade

load_and_update_coins()

Fetches coin count from ScoreManager and updates the UI label with formatted display.
return
void
No return value
Uses: format_number() to abbreviate large values (K/M suffixes) Example Usage:
# From main_menu.gd:276-278
func load_and_update_coins():
    var current_coins = ScoreManager.get_coins()
    coin_label.text = format_number(current_coins)

format_number()

Formats large numbers with K/M suffixes for compact display.
number
int
required
Number to format
return
String
Formatted string with K/M suffix if applicable
Formatting rules:
  • < 1,000: No suffix (e.g., “523”)
  • ≥ 1,000: K suffix (e.g., “1.5K”, “42.3K”)
  • ≥ 1,000,000: M suffix (e.g., “2.1M”)
Example Usage:
format_number(150)        # "150"
format_number(1500)       # "1.5K"
format_number(42_300)     # "42.3K"
format_number(2_100_000)  # "2.1M"

has_seen_intro()

Checks if player has completed the intro sequence.
return
bool
true if intro was seen, false otherwise
Implementation:
  • Reads from user://player_data.cfg
  • Checks player.intro_seen value
  • Returns false if file doesn’t exist
Example Usage:
# From main_menu.gd:51-55
if not has_seen_intro():
    # Redirect to intro scene
    get_tree().change_scene_to_file("res://scenes/intro.tscn")
    return

Minigame Launchers

Each minigame has a dedicated launcher method that:
  1. Sets appropriate screen orientation
  2. Configures viewport resolution
  3. Changes to the minigame scene

_on_turtle_pressed()

Launches Turtle Runner minigame. Configuration:
  • Orientation: Landscape
  • Resolution: 480×270
  • Scene: res://minigames/turtle_run/scenes/main.tscn
func _on_turtle_pressed():
    DisplayServer.screen_set_orientation(DisplayServer.SCREEN_LANDSCAPE)
    get_tree().root.set_content_scale_size(Vector2i(480, 270))
    get_tree().change_scene_to_file("res://minigames/turtle_run/scenes/main.tscn")

_on_worm_pressed()

Launches Worm Catch minigame. Configuration:
  • Orientation: Portrait
  • Resolution: 270×480
  • Scene: res://minigames/worm_bucket/Scenes/main.tscn

_on_food_pressed()

Launches Food Catch minigame. Configuration:
  • Orientation: Portrait
  • Resolution: 270×480
  • Scene: res://minigames/food_catch/scenes/Main.tscn

_on_memorice_pressed()

Launches Memorice matching game. Configuration:
  • Orientation: Portrait
  • Resolution: 270×480
  • Scene: res://minigames/memorice/scenes/minijuego_memorice.tscn

_on_counting_pressed()

Launches Counting Animals minigame. Configuration:
  • Orientation: Landscape
  • Resolution: 480×270
  • Scene: res://minigames/counting_animals/scenes/Main.tscn

_on_color_pressed()

Launches Nyuron Color minigame. Configuration:
  • Orientation: Portrait
  • Resolution: 270×480
  • Scene: res://minigames/nyuron_color/scenes/Main.tscn

_toggle_menu()

Toggles the slide-out minigame selection panel. Behavior:
  • Shows/hides menu_panel
  • Dims background with overlay when open
  • Hides other UI elements for focus
  • Auto-closes progress panel if open
func _toggle_menu() -> void:
    menu_panel.visible = not menu_panel.visible
    
    if menu_panel.visible:
        main_ui_buttons.visible = false
        progress_button.visible = false
        dim_overlay.visible = true
        create_tween().tween_property(dim_overlay, "color:a", 0.6, 0.25)

_on_tienda_pressed()

Navigates to the store/shop scene.
func _on_tienda_pressed():
    get_tree().change_scene_to_file("res://tienda/scenes/StoreMenu.tscn")

_on_progress_button_pressed()

Opens the progress/achievements panel. Actions:
  1. Closes minigame menu if open
  2. Updates progress info and achievements
  3. Shows progress panel
  4. Hides main UI buttons
  5. Shows dim overlay
func _on_progress_button_pressed():
    if panel_progreso.has_method("update_info"):
        panel_progreso.update_info()
    if panel_progreso.has_method("update_logros"):
        panel_progreso.update_logros()
    
    panel_progreso.visible = true
    main_ui_buttons.visible = false
    progress_button.visible = false

_on_progress_hud_closed()

Closes the progress panel and restores main UI.
func _on_progress_hud_closed():
    panel_progreso.visible = false
    main_ui_buttons.visible = true
    progress_button.visible = true
    
    if not menu_panel.visible:
        var tween = create_tween()
        tween.tween_property(dim_overlay, "color:a", 0.0, 0.25)
        tween.tween_callback(func(): dim_overlay.visible = false)

Cosmetic System Lookups

Maps shell item names to texture file suffixes:
var menu_color_codes = {
    "default": "",
    "caparazon": "",
    "Caparazón Azul": "_blue",
    "Caparazón Verde": "_green",
    "Caparazón Purpura": "_purple",
    "Caparazón Gris": "_gray"
}
Maps accessory item names to texture file suffixes:
var menu_accessory_codes = {
    "none": "",
    "ninguno": "",
    "Corona": "_corona",
    "Gafas": "_lentes",
    "Gorro": "_gorro",
    "Cadena": "_cadena"
}

Seagull Spawning

_spawn_gaviota()

Spawns decorative seagulls that fly across the screen. Configuration:
  • Triggered by spawn_timer timeout signal
  • Random direction (left-to-right or right-to-left)
  • Random Y position between altura_min and altura_max
  • Spawns offscreen, flies across viewport
func _spawn_gaviota():
    if gaviota_scene == null:
        return
    
    var gaviota = gaviota_scene.instantiate()
    var izquierda_a_derecha = randi() % 2 == 0
    var y := randf_range(altura_min, altura_max)
    
    gaviota.position = Vector2(
        -100 if izquierda_a_derecha else viewport_size.x + 100,
        y
    )
    
    gaviota.direction.x = 1 if izquierda_a_derecha else -1
    if not izquierda_a_derecha:
        gaviota.scale.x = -1
    
    add_child(gaviota)

Complete Usage Example

# Typical main menu flow
func _ready() -> void:
    # 1. Check if intro needed
    if not has_seen_intro():
        get_tree().change_scene_to_file("res://scenes/intro.tscn")
        return
    
    # 2. Load and display player data
    load_and_update_coins()
    update_menu_skin()
    
    # 3. Setup UI fade-in
    if TransitionBlocks.visible:
        TransitionBlocks.transition_finished.connect(func(): fade_in_ui())
    else:
        fade_in_ui()
    
    # 4. Connect button signals
    turtle_button.pressed.connect(_on_turtle_pressed)
    tienda_button.pressed.connect(_on_tienda_pressed)
    progress_button.pressed.connect(_on_progress_button_pressed)

Node References

UI Elements

@onready var menu_panel := $CanvasLayer/MenuSlidePanel
@onready var coin_label: Label = $CanvasLayer/CoinDisplay/HBoxContainer/CoinLabel
@onready var panel_progreso: Control = $CanvasLayer/PanelProgreso
@onready var dim_overlay: ColorRect = $CanvasLayer/FondoOscuro
@onready var nyuron_visual: AnimatedSprite2D = $NyuronVisual

Button References

@onready var turtle_button := $CanvasLayer/.../TurtleButton
@onready var worm_button := $CanvasLayer/.../WormButton
@onready var food_button := $CanvasLayer/.../FoodButton
@onready var memorice_button := $CanvasLayer/.../MemoriceButton
@onready var counting_button := $CanvasLayer/.../CountingButton
@onready var color_button := $CanvasLayer/.../ColorButton
@onready var tienda_button := $CanvasLayer/HBoxContainer/Tienda

Architecture Notes

  • Screen Orientation: Portrait by default (270×480), switches to landscape for certain minigames
  • Intro Guard: Redirects to intro scene on first launch
  • Transition Integration: Waits for TransitionBlocks to complete before fading in UI
  • Cosmetic System: Dynamically loads character textures based on ScoreManager state
  • Progress Panel: Two-way communication via signals (back_pressed, play_game_pressed)

Build docs developers (and LLMs) love