- Implemented LocalizationManager for handling multiple languages. - Updated LoadGameMenu, MainMenu, PauseMenu, and SettingsMenu to support localization. - Added InstanceSelectionMenu for selecting game instances. - Refactored SaveManager to handle new SaveInstance structure. - Created SaveDialog for saving games with user-defined names. - Enhanced SaveData to manage multiple save instances. - Added error handling and logging for save/load operations. - Updated UI elements to reflect localized text.
88 lines
2.9 KiB
C#
88 lines
2.9 KiB
C#
using Godot;
|
|
|
|
namespace TheGame
|
|
{
|
|
public partial class MainMenu : Control
|
|
{
|
|
private Button _loadButton;
|
|
private Label _titleLabel;
|
|
private Button _startButton;
|
|
private Button _settingsButton;
|
|
private Button _exitButton;
|
|
|
|
public override void _Ready()
|
|
{
|
|
// Lägg till i localized_ui gruppen
|
|
AddToGroup("localized_ui");
|
|
|
|
_loadButton = GetNode<Button>("VBoxContainer/LoadButton");
|
|
_titleLabel = GetNode<Label>("VBoxContainer/TitleLabel");
|
|
_startButton = GetNode<Button>("VBoxContainer/StartButton");
|
|
_settingsButton = GetNode<Button>("VBoxContainer/SettingsButton");
|
|
_exitButton = GetNode<Button>("VBoxContainer/ExitButton");
|
|
|
|
// Initiera inställningar och språk
|
|
GameSettings.Instance.ApplyAllSettings();
|
|
|
|
UpdateLoadButtonState();
|
|
UpdateLocalization();
|
|
}
|
|
|
|
public void UpdateLocalization()
|
|
{
|
|
var loc = LocalizationManager.Instance;
|
|
_titleLabel.Text = loc.GetText("main_menu_title");
|
|
_startButton.Text = loc.GetText("main_menu_start");
|
|
_loadButton.Text = loc.GetText("main_menu_load");
|
|
_settingsButton.Text = loc.GetText("main_menu_settings");
|
|
_exitButton.Text = loc.GetText("main_menu_exit");
|
|
}
|
|
|
|
private void UpdateLoadButtonState()
|
|
{
|
|
// Kontrollera om det finns sparade spel
|
|
var saveManager = new SaveManager();
|
|
var savedGames = saveManager.GetSavedGames();
|
|
_loadButton.Disabled = savedGames.Count == 0;
|
|
}
|
|
|
|
private void _on_start_button_pressed()
|
|
{
|
|
// Rensa befintligt game state för att starta nytt spel
|
|
GameState.ResetGameState();
|
|
|
|
GetTree().ChangeSceneToFile("res://scenes/Game.tscn");
|
|
}
|
|
|
|
public override void _Notification(int what)
|
|
{
|
|
if (what == NotificationWMCloseRequest)
|
|
{
|
|
// I huvudmenyn kan vi avsluta direkt
|
|
GetTree().Quit();
|
|
}
|
|
}
|
|
|
|
private void _on_load_button_pressed()
|
|
{
|
|
GetTree().ChangeSceneToFile("res://scenes/LoadGameMenu.tscn");
|
|
}
|
|
|
|
private void _on_settings_button_pressed()
|
|
{
|
|
// Skapa settings menu som popup
|
|
var settingsScene = GD.Load<PackedScene>("res://scenes/SettingsMenu.tscn");
|
|
var settingsMenu = settingsScene.Instantiate<SettingsMenu>();
|
|
|
|
// Sätt process mode för main menu context
|
|
settingsMenu.ProcessMode = ProcessModeEnum.Always;
|
|
|
|
GetTree().Root.AddChild(settingsMenu);
|
|
}
|
|
|
|
private void _on_exit_button_pressed()
|
|
{
|
|
GetTree().Quit();
|
|
}
|
|
}
|
|
} |