Refactor: reorganize scripts with domain-driven design structure
Move all C# scripts from flat structure to organized folders: - Core/ for game logic (Game, GameState, GameSettings) - UI/Menus/ and UI/Dialogs/ for user interface - Systems/ for reusable systems (Save, Localization) - Data/ for data models and configuration - Added framework for future: Gameplay/, Story/, Modding/ Update all .tscn scene files to reference new script paths. Fix timing issue in AdvancedSaveDialog focus handling.
This commit is contained in:
88
scripts/UI/Menus/MainMenu.cs
Normal file
88
scripts/UI/Menus/MainMenu.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user