Add back to editor button

This commit is contained in:
Gustas
2022-09-09 21:15:40 +03:00
committed by Matthias Mailänder
parent 4fc4fb2fb3
commit 085a4c421b
5 changed files with 59 additions and 3 deletions

View File

@@ -126,6 +126,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[TranslationReference] [TranslationReference]
const string PlayMapWarningCancel = "dialog-play-map-warning.cancel"; const string PlayMapWarningCancel = "dialog-play-map-warning.cancel";
[TranslationReference]
const string ExitToMapEditorTitle = "dialog-exit-to-map-editor.title";
[TranslationReference]
const string ExitToMapEditorPrompt = "dialog-exit-to-map-editor.prompt";
[TranslationReference]
const string ExitToMapEditorConfirm = "dialog-exit-to-map-editor.confirm";
[TranslationReference]
const string ExitToMapEditorCancel = "dialog-exit-to-map-editor.cancel";
readonly Widget menu; readonly Widget menu;
readonly Widget buttonContainer; readonly Widget buttonContainer;
readonly ButtonWidget buttonTemplate; readonly ButtonWidget buttonTemplate;
@@ -142,6 +154,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
bool leaving; bool leaving;
bool hideMenu; bool hideMenu;
static bool lastGameEditor = false;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public IngameMenuLogic(Widget widget, ModData modData, World world, Action onExit, WorldRenderer worldRenderer, public IngameMenuLogic(Widget widget, ModData modData, World world, Action onExit, WorldRenderer worldRenderer,
IngameInfoPanel initialPanel, Dictionary<string, MiniYaml> logicArgs) IngameInfoPanel initialPanel, Dictionary<string, MiniYaml> logicArgs)
@@ -154,6 +168,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var buttonHandlers = new Dictionary<string, Action> var buttonHandlers = new Dictionary<string, Action>
{ {
{ "ABORT_MISSION", CreateAbortMissionButton }, { "ABORT_MISSION", CreateAbortMissionButton },
{ "BACK_TO_EDITOR", CreateBackToEditorButton },
{ "RESTART", CreateRestartButton }, { "RESTART", CreateRestartButton },
{ "SURRENDER", CreateSurrenderButton }, { "SURRENDER", CreateSurrenderButton },
{ "LOAD_GAME", CreateLoadGameButton }, { "LOAD_GAME", CreateLoadGameButton },
@@ -244,6 +259,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
exitDelay += 40 * mpe.Info.FadeLength; exitDelay += 40 * mpe.Info.FadeLength;
} }
lastGameEditor = false;
Game.RunAfterDelay(exitDelay, () => Game.RunAfterDelay(exitDelay, () =>
{ {
if (!Game.IsCurrentWorld(world)) if (!Game.IsCurrentWorld(world))
@@ -513,6 +529,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
ExitEditor(actionManager, () => ExitEditor(actionManager, () =>
{ {
lastGameEditor = true;
Ui.CloseWindow(); Ui.CloseWindow();
Ui.ResetTooltips(); Ui.ResetTooltips();
void CloseMenu() void CloseMenu()
@@ -546,6 +564,38 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}; };
} }
void CreateBackToEditorButton()
{
if (world.Type != WorldType.Regular || !lastGameEditor)
return;
AddButton("BACK_TO_EDITOR", "Back To Editor")
.OnClick = () =>
{
hideMenu = true;
void OnConfirm()
{
lastGameEditor = false;
var map = modData.MapCache.GetUpdatedMap(world.Map.Uid);
if (map == null)
Game.LoadShellMap();
else
{
DiscordService.UpdateStatus(DiscordState.InMapEditor);
Game.LoadEditor(map);
}
}
ConfirmationDialogs.ButtonPrompt(modData,
title: ExitToMapEditorTitle,
text: ExitToMapEditorPrompt,
onConfirm: OnConfirm,
onCancel: ShowMenu,
confirmText: ExitToMapEditorConfirm,
cancelText: ExitToMapEditorCancel);
};
}
void CreateExitEditorButton() void CreateExitEditorButton()
{ {
if (world.Type != WorldType.Editor) if (world.Type != WorldType.Editor)

View File

@@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM Height: WINDOW_BOTTOM
Logic: IngameMenuLogic Logic: IngameMenuLogic
Buttons: EXIT_EDITOR, PLAY_MAP, SAVE_MAP, ABORT_MISSION, SURRENDER, RESTART, LOAD_GAME, SAVE_GAME, MUSIC, SETTINGS, RESUME Buttons: EXIT_EDITOR, PLAY_MAP, SAVE_MAP, ABORT_MISSION, BACK_TO_EDITOR, SURRENDER, RESTART, LOAD_GAME, SAVE_GAME, MUSIC, SETTINGS, RESUME
ButtonStride: 130, 0 ButtonStride: 130, 0
Children: Children:
Image@EVA: Image@EVA:

View File

@@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM Height: WINDOW_BOTTOM
Logic: IngameMenuLogic Logic: IngameMenuLogic
Buttons: RESUME, LOAD_GAME, SAVE_GAME, SETTINGS, MUSIC, SURRENDER, RESTART, ABORT_MISSION, SAVE_MAP, PLAY_MAP, EXIT_EDITOR Buttons: RESUME, LOAD_GAME, SAVE_GAME, SETTINGS, MUSIC, SURRENDER, RESTART, BACK_TO_EDITOR, ABORT_MISSION, SAVE_MAP, PLAY_MAP, EXIT_EDITOR
ButtonStride: 0, 40 ButtonStride: 0, 40
Children: Children:
Background@BORDER: Background@BORDER:

View File

@@ -228,6 +228,12 @@ dialog-play-map-warning =
errors preventing it from being loaded. errors preventing it from being loaded.
.cancel = Okay .cancel = Okay
dialog-exit-to-map-editor =
.title = Leave Mission
.prompt = Leave this game and return to the editor?
.confirm = Back To Editor
.cancel = Stay
## IngamePowerBarLogic ## IngamePowerBarLogic
## IngamePowerCounterLogic ## IngamePowerCounterLogic
label-power-usage = Power Usage: { $usage }/{ $capacity } label-power-usage = Power Usage: { $usage }/{ $capacity }

View File

@@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM Height: WINDOW_BOTTOM
Logic: IngameMenuLogic Logic: IngameMenuLogic
Buttons: RESUME, LOAD_GAME, SAVE_GAME, SETTINGS, MUSIC, SURRENDER, RESTART, ABORT_MISSION, SAVE_MAP, PLAY_MAP, EXIT_EDITOR Buttons: RESUME, LOAD_GAME, SAVE_GAME, SETTINGS, MUSIC, SURRENDER, RESTART, BACK_TO_EDITOR, ABORT_MISSION, SAVE_MAP, PLAY_MAP, EXIT_EDITOR
ButtonStride: 0, 40 ButtonStride: 0, 40
Children: Children:
Label@VERSION_LABEL: Label@VERSION_LABEL: