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.
106 lines
3.2 KiB
C#
106 lines
3.2 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
namespace TheGame
|
|
{
|
|
public partial class ExitConfirmationDialog : AcceptDialog
|
|
{
|
|
private Action _onConfirm;
|
|
private Button _yesButton;
|
|
private Button _noButton;
|
|
private Label _messageLabel;
|
|
|
|
public override void _Ready()
|
|
{
|
|
// Lägg till i localized_ui gruppen
|
|
AddToGroup("localized_ui");
|
|
|
|
// Skapa dialog layout
|
|
SetupDialog();
|
|
UpdateLocalization();
|
|
}
|
|
|
|
private void SetupDialog()
|
|
{
|
|
// Sätt dialog egenskaper
|
|
Title = "";
|
|
Unresizable = false;
|
|
ProcessMode = ProcessModeEnum.WhenPaused;
|
|
|
|
// Ta bort standard OK knapp
|
|
GetOkButton().QueueFree();
|
|
|
|
// Skapa innehåll
|
|
var vbox = new VBoxContainer();
|
|
AddChild(vbox);
|
|
|
|
_messageLabel = new Label();
|
|
_messageLabel.HorizontalAlignment = HorizontalAlignment.Center;
|
|
_messageLabel.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
|
vbox.AddChild(_messageLabel);
|
|
|
|
// Lägg till mellanrum
|
|
var spacer = new Control();
|
|
spacer.CustomMinimumSize = new Vector2(0, 20);
|
|
vbox.AddChild(spacer);
|
|
|
|
// Skapa knappar
|
|
var buttonContainer = new HBoxContainer();
|
|
buttonContainer.Alignment = BoxContainer.AlignmentMode.Center;
|
|
vbox.AddChild(buttonContainer);
|
|
|
|
_yesButton = new Button();
|
|
_yesButton.Pressed += OnYesPressed;
|
|
buttonContainer.AddChild(_yesButton);
|
|
|
|
// Lägg till mellanrum mellan knappar
|
|
var buttonSpacer = new Control();
|
|
buttonSpacer.CustomMinimumSize = new Vector2(20, 0);
|
|
buttonContainer.AddChild(buttonSpacer);
|
|
|
|
_noButton = new Button();
|
|
_noButton.Pressed += OnNoPressed;
|
|
buttonContainer.AddChild(_noButton);
|
|
|
|
// Sätt minimum storlek för dialog
|
|
Size = new Vector2I(400, 200);
|
|
}
|
|
|
|
public void UpdateLocalization()
|
|
{
|
|
var loc = LocalizationManager.Instance;
|
|
Title = loc.GetText("exit_warning_title");
|
|
_messageLabel.Text = loc.GetText("exit_warning_message");
|
|
_yesButton.Text = loc.GetText("yes");
|
|
_noButton.Text = loc.GetText("no");
|
|
}
|
|
|
|
public void ShowDialog(Action onConfirm)
|
|
{
|
|
_onConfirm = onConfirm;
|
|
PopupCentered();
|
|
_noButton.GrabFocus(); // Fokusera på "Nej" som säkrare alternativ
|
|
}
|
|
|
|
private void OnYesPressed()
|
|
{
|
|
Hide();
|
|
_onConfirm?.Invoke();
|
|
}
|
|
|
|
private void OnNoPressed()
|
|
{
|
|
Hide();
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
// Hantera ESC för att stänga dialog (samma som "Nej")
|
|
if (@event.IsActionPressed("ui_cancel") && Visible)
|
|
{
|
|
OnNoPressed();
|
|
GetViewport().SetInputAsHandled();
|
|
}
|
|
}
|
|
}
|
|
} |