Add Play button to map editor

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

View File

@@ -117,6 +117,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[TranslationReference]
const string ExitMapEditorConfirm = "dialog-exit-map-editor.confirm";
[TranslationReference]
const string PlayMapWarningTitle = "dialog-play-map-warning.title";
[TranslationReference]
const string PlayMapWarningPrompt = "dialog-play-map-warning.prompt";
[TranslationReference]
const string PlayMapWarningCancel = "dialog-play-map-warning.cancel";
readonly Widget menu;
readonly Widget buttonContainer;
readonly ButtonWidget buttonTemplate;
@@ -153,6 +162,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "SETTINGS", CreateSettingsButton },
{ "RESUME", CreateResumeButton },
{ "SAVE_MAP", CreateSaveMapButton },
{ "PLAY_MAP", CreatePlayMapButton },
{ "EXIT_EDITOR", CreateExitEditorButton }
};
@@ -478,6 +488,64 @@ namespace OpenRA.Mods.Common.Widgets.Logic
};
}
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,
onCancel: ShowMenu,
cancelText: PlayMapWarningCancel);
return;
}
ExitEditor(actionManager, () =>
{
Ui.CloseWindow();
Ui.ResetTooltips();
void CloseMenu()
{
mpe?.Fade(MenuPaletteEffect.EffectType.None);
onExit();
}
if (map.Visibility == MapVisibility.Lobby)
{
ConnectionLogic.Connect(Game.CreateLocalServer(uid),
"",
() => Game.OpenWindow("SERVER_LOBBY", new WidgetArgs
{
{ "onExit", CloseMenu },
{ "onStart", () => { } },
{ "skirmishMode", true }
}),
() => Game.CloseServer());
}
else if (map.Visibility == MapVisibility.MissionSelector)
{
Game.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs
{
{ "onExit", CloseMenu },
{ "onStart", () => { } },
{ "initialMap", uid }
});
}
});
};
}
void CreateExitEditorButton()
{
if (world.Type != WorldType.Editor)

View File

@@ -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, SURRENDER, RESTART, LOAD_GAME, SAVE_GAME, MUSIC, SETTINGS, RESUME
ButtonStride: 130, 0
Children:
Image@EVA:

View File

@@ -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, ABORT_MISSION, SAVE_MAP, PLAY_MAP, EXIT_EDITOR
ButtonStride: 0, 40
Children:
Background@BORDER:

View File

@@ -222,6 +222,12 @@ dialog-exit-map-editor =
.confirm-anyway = Exit anyway
.confirm = Exit
dialog-play-map-warning =
.title = Warning
.prompt = The map may have been deleted or has
errors preventing it from being loaded.
.cancel = Okay
## IngamePowerBarLogic
## IngamePowerCounterLogic
label-power-usage = Power Usage: { $usage }/{ $capacity }

View File

@@ -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, ABORT_MISSION, SAVE_MAP, PLAY_MAP, EXIT_EDITOR
ButtonStride: 0, 40
Children:
Label@VERSION_LABEL: