fixt pop up box about unsaved porgrass
This commit is contained in:
@@ -100,6 +100,9 @@ namespace TheGame
|
|||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
|
if (!IsInsideTree())
|
||||||
|
return;
|
||||||
|
|
||||||
if (@event.IsActionPressed("ui_cancel")) // ESC key
|
if (@event.IsActionPressed("ui_cancel")) // ESC key
|
||||||
{
|
{
|
||||||
TogglePause();
|
TogglePause();
|
||||||
|
|||||||
@@ -225,16 +225,24 @@ namespace TheGame
|
|||||||
|
|
||||||
public string GetText(string key)
|
public string GetText(string key)
|
||||||
{
|
{
|
||||||
|
string text = null;
|
||||||
|
|
||||||
// Försök hämta från nuvarande språk
|
// Försök hämta från nuvarande språk
|
||||||
if (_currentTranslations != null && _currentTranslations.ContainsKey(key))
|
if (_currentTranslations != null && _currentTranslations.ContainsKey(key))
|
||||||
{
|
{
|
||||||
return _currentTranslations[key];
|
text = _currentTranslations[key];
|
||||||
|
}
|
||||||
|
// Fallback till engelska
|
||||||
|
else if (_fallbackTranslations != null && _fallbackTranslations.ContainsKey(key))
|
||||||
|
{
|
||||||
|
text = _fallbackTranslations[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback till engelska
|
// Konvertera escape-sekvenser om vi hittade text
|
||||||
if (_fallbackTranslations != null && _fallbackTranslations.ContainsKey(key))
|
if (text != null)
|
||||||
{
|
{
|
||||||
return _fallbackTranslations[key];
|
text = text.Replace("\\n", "\n").Replace("\\t", "\t");
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Om inte ens engelska finns, returnera nyckeln
|
// Om inte ens engelska finns, returnera nyckeln
|
||||||
|
|||||||
@@ -271,6 +271,9 @@ namespace TheGame
|
|||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
|
if (!IsInsideTree())
|
||||||
|
return;
|
||||||
|
|
||||||
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
||||||
{
|
{
|
||||||
if (keyEvent.Keycode == Key.Enter || keyEvent.Keycode == Key.KpEnter)
|
if (keyEvent.Keycode == Key.Enter || keyEvent.Keycode == Key.KpEnter)
|
||||||
@@ -287,13 +290,19 @@ namespace TheGame
|
|||||||
OnSaveConfirmed();
|
OnSaveConfirmed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GetViewport().SetInputAsHandled();
|
if (IsInsideTree())
|
||||||
|
{
|
||||||
|
GetViewport().SetInputAsHandled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (keyEvent.Keycode == Key.Escape)
|
else if (keyEvent.Keycode == Key.Escape)
|
||||||
{
|
{
|
||||||
Hide();
|
Hide();
|
||||||
QueueFree();
|
QueueFree();
|
||||||
GetViewport().SetInputAsHandled();
|
if (IsInsideTree())
|
||||||
|
{
|
||||||
|
GetViewport().SetInputAsHandled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System;
|
|||||||
|
|
||||||
namespace TheGame
|
namespace TheGame
|
||||||
{
|
{
|
||||||
public partial class ExitConfirmationDialog : AcceptDialog
|
public partial class ExitConfirmationDialog : Window
|
||||||
{
|
{
|
||||||
private Action _onConfirm;
|
private Action _onConfirm;
|
||||||
private Button _yesButton;
|
private Button _yesButton;
|
||||||
@@ -15,6 +15,9 @@ namespace TheGame
|
|||||||
// Lägg till i localized_ui gruppen
|
// Lägg till i localized_ui gruppen
|
||||||
AddToGroup("localized_ui");
|
AddToGroup("localized_ui");
|
||||||
|
|
||||||
|
// Dölj dialogen initialt
|
||||||
|
Hide();
|
||||||
|
|
||||||
// Skapa dialog layout
|
// Skapa dialog layout
|
||||||
SetupDialog();
|
SetupDialog();
|
||||||
UpdateLocalization();
|
UpdateLocalization();
|
||||||
@@ -27,29 +30,46 @@ namespace TheGame
|
|||||||
Unresizable = false;
|
Unresizable = false;
|
||||||
ProcessMode = ProcessModeEnum.WhenPaused;
|
ProcessMode = ProcessModeEnum.WhenPaused;
|
||||||
|
|
||||||
// Ta bort standard OK knapp
|
// Konfigurera window egenskaper
|
||||||
GetOkButton().QueueFree();
|
Mode = ModeEnum.Windowed;
|
||||||
|
SetFlag(Flags.Popup, true);
|
||||||
|
|
||||||
// Skapa innehåll
|
// Skapa innehåll
|
||||||
var vbox = new VBoxContainer();
|
var vbox = new VBoxContainer();
|
||||||
|
vbox.AddThemeConstantOverride("separation", 10);
|
||||||
AddChild(vbox);
|
AddChild(vbox);
|
||||||
|
|
||||||
|
// Lägg till padding
|
||||||
|
var margin = new MarginContainer();
|
||||||
|
margin.AddThemeConstantOverride("margin_left", 25);
|
||||||
|
margin.AddThemeConstantOverride("margin_right", 25);
|
||||||
|
margin.AddThemeConstantOverride("margin_top", 25);
|
||||||
|
margin.AddThemeConstantOverride("margin_bottom", 25);
|
||||||
|
vbox.AddChild(margin);
|
||||||
|
|
||||||
|
var content = new VBoxContainer();
|
||||||
|
margin.AddChild(content);
|
||||||
|
|
||||||
_messageLabel = new Label();
|
_messageLabel = new Label();
|
||||||
_messageLabel.HorizontalAlignment = HorizontalAlignment.Center;
|
_messageLabel.HorizontalAlignment = HorizontalAlignment.Center;
|
||||||
|
_messageLabel.VerticalAlignment = VerticalAlignment.Center;
|
||||||
_messageLabel.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
_messageLabel.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||||
vbox.AddChild(_messageLabel);
|
_messageLabel.CustomMinimumSize = new Vector2(300, 80); // Säkerställ tillräcklig höjd för text
|
||||||
|
content.AddChild(_messageLabel);
|
||||||
|
|
||||||
// Lägg till mellanrum
|
// Lägg till mellanrum
|
||||||
var spacer = new Control();
|
var spacer = new Control();
|
||||||
spacer.CustomMinimumSize = new Vector2(0, 20);
|
spacer.CustomMinimumSize = new Vector2(0, 20);
|
||||||
vbox.AddChild(spacer);
|
content.AddChild(spacer);
|
||||||
|
|
||||||
// Skapa knappar
|
// Skapa knappar
|
||||||
var buttonContainer = new HBoxContainer();
|
var buttonContainer = new HBoxContainer();
|
||||||
buttonContainer.Alignment = BoxContainer.AlignmentMode.Center;
|
buttonContainer.Alignment = BoxContainer.AlignmentMode.Center;
|
||||||
vbox.AddChild(buttonContainer);
|
content.AddChild(buttonContainer);
|
||||||
|
|
||||||
_yesButton = new Button();
|
_yesButton = new Button();
|
||||||
|
_yesButton.FocusMode = Control.FocusModeEnum.All;
|
||||||
|
_yesButton.CustomMinimumSize = new Vector2(80, 35);
|
||||||
_yesButton.Pressed += OnYesPressed;
|
_yesButton.Pressed += OnYesPressed;
|
||||||
buttonContainer.AddChild(_yesButton);
|
buttonContainer.AddChild(_yesButton);
|
||||||
|
|
||||||
@@ -59,11 +79,14 @@ namespace TheGame
|
|||||||
buttonContainer.AddChild(buttonSpacer);
|
buttonContainer.AddChild(buttonSpacer);
|
||||||
|
|
||||||
_noButton = new Button();
|
_noButton = new Button();
|
||||||
|
_noButton.FocusMode = Control.FocusModeEnum.All;
|
||||||
|
_noButton.CustomMinimumSize = new Vector2(80, 35);
|
||||||
_noButton.Pressed += OnNoPressed;
|
_noButton.Pressed += OnNoPressed;
|
||||||
buttonContainer.AddChild(_noButton);
|
buttonContainer.AddChild(_noButton);
|
||||||
|
|
||||||
// Sätt minimum storlek för dialog
|
// Sätt lämplig storlek för dialog
|
||||||
Size = new Vector2I(400, 200);
|
MinSize = new Vector2I(380, 200);
|
||||||
|
Size = new Vector2I(420, 220);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateLocalization()
|
public void UpdateLocalization()
|
||||||
@@ -78,28 +101,51 @@ namespace TheGame
|
|||||||
public void ShowDialog(Action onConfirm)
|
public void ShowDialog(Action onConfirm)
|
||||||
{
|
{
|
||||||
_onConfirm = onConfirm;
|
_onConfirm = onConfirm;
|
||||||
PopupCentered();
|
// Använd PopupCentered med explicit storlek
|
||||||
_noButton.GrabFocus(); // Fokusera på "Nej" som säkrare alternativ
|
PopupCentered(new Vector2I(420, 220));
|
||||||
|
// Skjut upp fokusanropet till nästa frame
|
||||||
|
CallDeferred(nameof(FocusNoButton));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FocusNoButton()
|
||||||
|
{
|
||||||
|
// Sätt fokus på "Nej"-knappen
|
||||||
|
if (_noButton != null && IsInsideTree() && _noButton.IsInsideTree())
|
||||||
|
{
|
||||||
|
_noButton.GrabFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void OnYesPressed()
|
private void OnYesPressed()
|
||||||
{
|
{
|
||||||
Hide();
|
Hide();
|
||||||
_onConfirm?.Invoke();
|
_onConfirm?.Invoke();
|
||||||
|
// Återställ onConfirm för nästa användning
|
||||||
|
_onConfirm = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnNoPressed()
|
private void OnNoPressed()
|
||||||
{
|
{
|
||||||
Hide();
|
Hide();
|
||||||
|
// Återställ onConfirm för nästa användning
|
||||||
|
_onConfirm = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
|
if (!IsInsideTree())
|
||||||
|
return;
|
||||||
|
|
||||||
// Hantera ESC för att stänga dialog (samma som "Nej")
|
// Hantera ESC för att stänga dialog (samma som "Nej")
|
||||||
if (@event.IsActionPressed("ui_cancel") && Visible)
|
if (@event.IsActionPressed("ui_cancel") && Visible)
|
||||||
{
|
{
|
||||||
OnNoPressed();
|
OnNoPressed();
|
||||||
GetViewport().SetInputAsHandled();
|
if (IsInsideTree())
|
||||||
|
{
|
||||||
|
GetViewport().SetInputAsHandled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,19 +81,28 @@ namespace TheGame
|
|||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
|
if (!IsInsideTree())
|
||||||
|
return;
|
||||||
|
|
||||||
// Se till att input fungerar när spelet är pausat
|
// Se till att input fungerar när spelet är pausat
|
||||||
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
||||||
{
|
{
|
||||||
if (keyEvent.Keycode == Key.Enter || keyEvent.Keycode == Key.KpEnter)
|
if (keyEvent.Keycode == Key.Enter || keyEvent.Keycode == Key.KpEnter)
|
||||||
{
|
{
|
||||||
OnSaveConfirmed();
|
OnSaveConfirmed();
|
||||||
GetViewport().SetInputAsHandled();
|
if (IsInsideTree())
|
||||||
|
{
|
||||||
|
GetViewport().SetInputAsHandled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (keyEvent.Keycode == Key.Escape)
|
else if (keyEvent.Keycode == Key.Escape)
|
||||||
{
|
{
|
||||||
Hide();
|
Hide();
|
||||||
QueueFree();
|
QueueFree();
|
||||||
GetViewport().SetInputAsHandled();
|
if (IsInsideTree())
|
||||||
|
{
|
||||||
|
GetViewport().SetInputAsHandled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,12 +108,18 @@ namespace TheGame
|
|||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
|
if (!IsInsideTree())
|
||||||
|
return;
|
||||||
|
|
||||||
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
||||||
{
|
{
|
||||||
if (keyEvent.Keycode == Key.Escape)
|
if (keyEvent.Keycode == Key.Escape)
|
||||||
{
|
{
|
||||||
OnCancelPressed();
|
OnCancelPressed();
|
||||||
GetViewport().SetInputAsHandled();
|
if (IsInsideTree())
|
||||||
|
{
|
||||||
|
GetViewport().SetInputAsHandled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user