Skip to content

Commit

Permalink
Add Play button to map editor
Browse files Browse the repository at this point in the history
  • Loading branch information
PunkPun committed Sep 9, 2022
1 parent 34d9cfc commit 9da7a88
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 3 deletions.
117 changes: 117 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 @@ -133,6 +135,30 @@ public class IngameMenuLogic : ChromeLogic
[TranslationReference]
static readonly string ExitMapEditorConfirm = "exit-map-editor-confirm";

[TranslationReference]
static readonly string PlayMapWarningTitle = "play-map-warning-title";

[TranslationReference]
static readonly string PlayMapWarningPrompt = "play-map-warning-prompt";

[TranslationReference]
static readonly string PlayMapWarningAccept = "play-map-warning-accept";

[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 @@ -145,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 All @@ -153,6 +180,7 @@ public class IngameMenuLogic : ChromeLogic
{ "SETTINGS", CreateSettingsButton },
{ "RESUME", CreateResumeButton },
{ "SAVE_MAP", CreateSaveMapButton },
{ "PLAY_MAP", CreatePlayMapButton },
{ "EXIT_EDITOR", CreateExitEditorButton }
};

Expand Down Expand Up @@ -237,6 +265,7 @@ void OnQuit()

Game.RunAfterDelay(exitDelay, () =>
{
lastGameEditor = false;
if (!Game.IsCurrentWorld(world))
return;
Expand Down Expand Up @@ -478,6 +507,94 @@ void CreateSaveMapButton()
};
}

void CreatePlayMapButton()
{
if (world.Type != WorldType.Editor)
return;

var actionManager = world.WorldActor.Trait<EditorActionManager>();
AddButton("PLAY_MAP", "Play Map")
.OnClick = () =>
{
hideMenu = true;
var uid = modData.MapCache.GetUpdatedMap(world.Map.Uid);
var map = uid == null ? null : modData.MapCache[uid];
if (map == null || (map.Visibility != MapVisibility.Lobby && map.Visibility != MapVisibility.MissionSelector))
{
ConfirmationDialogs.ButtonPrompt(modData,
title: PlayMapWarningTitle,
text: PlayMapWarningPrompt,
onConfirm: ShowMenu,
onCancel: ShowMenu,
confirmText: PlayMapWarningAccept,
cancelText: PlayMapWarningCancel);
return;
}
ExitEditor(actionManager, () =>
{
lastGameEditor = true;
Ui.CloseWindow();
Ui.ResetTooltips();
if (map.Visibility == MapVisibility.Lobby)
{
ConnectionLogic.Connect(Game.CreateLocalServer(uid),
"",
() => Game.OpenWindow("SERVER_LOBBY", new WidgetArgs
{
{ "onExit", onExit },
{ "onStart", () => { } },
{ "skirmishMode", true }
}),
() => { Game.CloseServer(); });
}
else if (map.Visibility == MapVisibility.MissionSelector)
{
Game.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs
{
{ "onExit", onExit },
{ "onStart", () => { } },
{ "initialMap", uid }
});
}
});
};
}

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, 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, 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
11 changes: 11 additions & 0 deletions mods/common/languages/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ exit-map-editor-prompt-deleted = The map may have been deleted outside the edito
exit-map-editor-confirm-anyway = Exit anyway
exit-map-editor-confirm = Exit
play-map-warning-title = Warning
play-map-warning-prompt = The map may have been deleted or has
errors preventing it from being loaded
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, 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 9da7a88

Please sign in to comment.