Add quit button to connection lost panel

This commit is contained in:
Gustas
2023-03-16 23:02:43 +02:00
committed by Matthias Mailänder
parent 482f2fc335
commit c4bd9fb7aa
6 changed files with 35 additions and 8 deletions

View File

@@ -42,6 +42,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "connection", connection },
{ "password", password },
{ "onAbort", onAbort },
{ "onQuit", null },
{ "onRetry", onRetry }
});
}
@@ -102,16 +103,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic
bool passwordOffsetAdjusted;
[ObjectCreator.UseCtor]
public ConnectionFailedLogic(Widget widget, ModData modData, OrderManager orderManager, NetworkConnection connection, string password, Action onAbort, Action<string> onRetry)
public ConnectionFailedLogic(Widget widget, ModData modData, OrderManager orderManager, NetworkConnection connection, string password, Action onAbort, Action onQuit, Action<string> onRetry)
{
var panel = widget;
var abortButton = panel.Get<ButtonWidget>("ABORT_BUTTON");
var quitButton = panel.Get<ButtonWidget>("QUIT_BUTTON");
var retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON");
var leaving = false;
abortButton.Visible = onAbort != null;
abortButton.IsDisabled = () => leaving;
abortButton.OnClick = () => { Ui.CloseWindow(); onAbort(); };
quitButton.Visible = onQuit != null;
quitButton.IsDisabled = () => leaving;
quitButton.OnClick = () => { onQuit(); leaving = true; };
retryButton.Visible = onRetry != null;
retryButton.IsDisabled = () => leaving;
retryButton.OnClick = () =>
{
var pass = passwordField != null && passwordField.IsVisible() ? passwordField.Text : password;

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public class DisconnectWatcherLogic : ChromeLogic
{
[ObjectCreator.UseCtor]
public DisconnectWatcherLogic(Widget widget, OrderManager orderManager)
public DisconnectWatcherLogic(Widget widget, World world, OrderManager orderManager)
{
var disconnected = false;
widget.Get<LogicTickerWidget>("DISCONNECT_WATCHER").OnTick = () =>
@@ -34,6 +34,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "password", CurrentServerSettings.Password },
{ "connection", connection },
{ "onAbort", null },
{ "onQuit", () => IngameMenuLogic.OnQuit(world) },
{ "onRetry", null }
}));

View File

@@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
void OnQuit()
public static void OnQuit(World world)
{
// TODO: Create a mechanism to do things like this cleaner. Also needed for scripted missions
if (world.Type == WorldType.Regular)
@@ -221,10 +221,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
leaving = true;
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var exitDelay = iop?.ExitDelay ?? 0;
var mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
if (mpe != null)
{
Game.RunAfterDelay(exitDelay, () =>
@@ -295,7 +294,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
ConfirmationDialogs.ButtonPrompt(modData,
title: LeaveMissionTitle,
text: LeaveMissionPrompt,
onConfirm: OnQuit,
onConfirm: () => { OnQuit(world); leaving = true; },
onCancel: ShowMenu,
confirmText: LeaveMissionAccept,
cancelText: LeaveMissionCancel);
@@ -499,11 +498,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
title: ExitMapEditorTitle,
text: deletedOrUnavailable ? ExitMapEditorPromptDeleted : ExitMapEditorPromptUnsaved,
confirmText: deletedOrUnavailable ? ExitMapEditorAnywayConfirm : ExitMapEditorConfirm,
onConfirm: OnQuit,
onConfirm: () => { OnQuit(world); leaving = true; },
onCancel: ShowMenu);
}
else
OnQuit();
{
OnQuit(world);
leaving = true;
}
};
}
}

View File

@@ -136,6 +136,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "connection", connection },
{ "password", password },
{ "onAbort", onExit },
{ "onQuit", null },
{ "onRetry", onRetry }
});
}

View File

@@ -83,6 +83,12 @@ Container@CONNECTIONFAILED_PANEL:
Width: 140
Height: 35
Text: Abort
Button@QUIT_BUTTON:
Key: escape
Y: 84
Width: 140
Height: 35
Text: Quit
Button@RETRY_BUTTON:
Key: return
X: 230

View File

@@ -57,6 +57,14 @@ Background@CONNECTIONFAILED_PANEL:
Text: Abort
Font: Bold
Key: escape
Button@QUIT_BUTTON:
X: PARENT_RIGHT - 180
Y: PARENT_BOTTOM - 45
Width: 160
Height: 25
Text: Quit
Font: Bold
Key: escape
Background@CONNECTING_PANEL:
Logic: ConnectionLogic