Skip to content

Commit

Permalink
Add back to editor button
Browse files Browse the repository at this point in the history
  • Loading branch information
PunkPun committed Sep 9, 2022
1 parent 45835e4 commit b4e39cd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
50 changes: 50 additions & 0 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class IngameMenuLogic : ChromeLogic
bool leaving;
bool hideMenu;

static bool lastGameEditor = false;

[TranslationReference]
static readonly string Leave = "leave";

Expand Down Expand Up @@ -145,6 +147,18 @@ public class IngameMenuLogic : ChromeLogic
[TranslationReference]
static readonly string PlayMapWarningCancel = "play-map-warning-cancel";

[TranslationReference]
static readonly string ExitToMapEditorTitle = "exit-to-map-editor-title";

[TranslationReference]
static readonly string ExitToMapEditorPrompt = "exit-to-map-editor-prompt";

[TranslationReference]
static readonly string ExitToMapEditorAccept = "exit-to-map-editor-accept";

[TranslationReference]
static readonly string ExitToMapEditorCancel = "exit-to-map-editor-cancel";

[ObjectCreator.UseCtor]
public IngameMenuLogic(Widget widget, ModData modData, World world, Action onExit, WorldRenderer worldRenderer,
IngameInfoPanel initialPanel, Dictionary<string, MiniYaml> logicArgs)
Expand All @@ -157,6 +171,7 @@ public class IngameMenuLogic : ChromeLogic
var buttonHandlers = new Dictionary<string, Action>
{
{ "ABORT_MISSION", CreateAbortMissionButton },
{ "BACK_TO_EDITOR", CreateBackToEditorButton },
{ "RESTART", CreateRestartButton },
{ "SURRENDER", CreateSurrenderButton },
{ "LOAD_GAME", CreateLoadGameButton },
Expand Down Expand Up @@ -248,6 +263,7 @@ void OnQuit()
exitDelay += 40 * mpe.Info.FadeLength;
}

lastGameEditor = false;
Game.RunAfterDelay(exitDelay, () =>
{
if (!Game.IsCurrentWorld(world))
Expand Down Expand Up @@ -518,6 +534,8 @@ void CreatePlayMapButton()
ExitEditor(actionManager, () =>
{
lastGameEditor = true;
Ui.CloseWindow();
Ui.ResetTooltips();
if (map.Visibility == MapVisibility.Lobby)
Expand Down Expand Up @@ -545,6 +563,38 @@ void CreatePlayMapButton()
};
}

void CreateBackToEditorButton()
{
if (world.Type != WorldType.Regular || !lastGameEditor)
return;

AddButton("BACK_TO_EDITOR", "Back To Editor")
.OnClick = () =>
{
hideMenu = true;
Action 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: ExitToMapEditorAccept,
cancelText: ExitToMapEditorCancel);
};
}

void CreateExitEditorButton()
{
if (world.Type != WorldType.Editor)
Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/chrome/ingame-menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
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
Children:
Image@EVA:
Expand Down
2 changes: 1 addition & 1 deletion mods/common/chrome/ingame-menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
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
Children:
Background@BORDER:
Expand Down
5 changes: 5 additions & 0 deletions mods/common/languages/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ play-map-warning-prompt = The map may have been deleted or has
play-map-warning-accept = Okay
play-map-warning-cancel = Okay
exit-to-map-editor-title = Leave Mission
exit-to-map-editor-prompt = Leave this game and return to the editor?
exit-to-map-editor-accept = Back To Editor
exit-to-map-editor-cancel = Stay
## IngamePowerBarLogic
## IngamePowerCounterLogic
power-usage = Power Usage
Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/chrome/ingame-menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
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
Children:
Label@VERSION_LABEL:
Expand Down

0 comments on commit b4e39cd

Please sign in to comment.