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 Jun 11, 2023
1 parent 47c02ed commit 9a890fe
Show file tree
Hide file tree
Showing 5 changed files with 59 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 @@ -126,6 +126,18 @@ public class IngameMenuLogic : ChromeLogic
[TranslationReference]
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 buttonContainer;
readonly ButtonWidget buttonTemplate;
Expand All @@ -142,6 +154,8 @@ public class IngameMenuLogic : ChromeLogic
bool leaving;
bool hideMenu;

static bool lastGameEditor = false;

[ObjectCreator.UseCtor]
public IngameMenuLogic(Widget widget, ModData modData, World world, Action onExit, WorldRenderer worldRenderer,
IngameInfoPanel initialPanel, Dictionary<string, MiniYaml> logicArgs)
Expand All @@ -154,6 +168,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 @@ -244,6 +259,7 @@ public static void OnQuit(World world)
exitDelay += 40 * mpe.Info.FadeLength;
}

lastGameEditor = false;
Game.RunAfterDelay(exitDelay, () =>
{
if (!Game.IsCurrentWorld(world))
Expand Down Expand Up @@ -513,6 +529,8 @@ void CreatePlayMapButton()
ExitEditor(actionManager, () =>
{
lastGameEditor = true;
Ui.CloseWindow();
Ui.ResetTooltips();
void CloseMenu()
Expand Down Expand Up @@ -546,6 +564,38 @@ void CloseMenu()
};
}

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()
{
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
6 changes: 6 additions & 0 deletions mods/common/languages/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ dialog-play-map-warning =
errors preventing it from being loaded.
.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
## IngamePowerCounterLogic
label-power-usage = Power Usage: { $usage }/{ $capacity }
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 9a890fe

Please sign in to comment.