mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Remove Engine.SwitchGuiPage from campaigns
This commit is contained in:
parent
434a1a1905
commit
76b6725272
4 changed files with 86 additions and 54 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
class CampaignMenu extends AutoWatcher
|
class CampaignMenu extends AutoWatcher
|
||||||
{
|
{
|
||||||
constructor(campaignRun)
|
constructor(campaignRun, closePageCallback)
|
||||||
{
|
{
|
||||||
super("render");
|
super("render");
|
||||||
|
|
||||||
|
|
@ -16,17 +16,20 @@ class CampaignMenu extends AutoWatcher
|
||||||
this.levelSelection = Engine.GetGUIObjectByName("levelSelection");
|
this.levelSelection = Engine.GetGUIObjectByName("levelSelection");
|
||||||
this.levelSelection.onSelectionChange = () => { this.selectedLevel = this.levelSelection.selected; };
|
this.levelSelection.onSelectionChange = () => { this.selectedLevel = this.levelSelection.selected; };
|
||||||
|
|
||||||
this.levelSelection.onMouseLeftDoubleClickItem = () => this.startScenario();
|
const startScenarioCallback = this.startScenario.bind(this, closePageCallback);
|
||||||
Engine.GetGUIObjectByName('startButton').onPress = () => this.startScenario();
|
this.levelSelection.onMouseLeftDoubleClickItem = startScenarioCallback;
|
||||||
Engine.GetGUIObjectByName('backToMain').onPress = () => this.goBackToMainMenu();
|
Engine.GetGUIObjectByName('startButton').onPress = startScenarioCallback;
|
||||||
Engine.GetGUIObjectByName('savedGamesButton').onPress = this.loadSavegame.bind(this);
|
Engine.GetGUIObjectByName('backToMain').onPress =
|
||||||
|
this.goBackToMainMenu.bind(this, closePageCallback);
|
||||||
|
Engine.GetGUIObjectByName('savedGamesButton').onPress =
|
||||||
|
this.loadSavegame.bind(this, closePageCallback);
|
||||||
|
|
||||||
this.mapCache = new MapCache();
|
this.mapCache = new MapCache();
|
||||||
|
|
||||||
this._ready = true;
|
this._ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadSavegame()
|
async loadSavegame(closePageCallback)
|
||||||
{
|
{
|
||||||
const gameId = await Engine.OpenChildPage(
|
const gameId = await Engine.OpenChildPage(
|
||||||
'page_loadgame.xml',
|
'page_loadgame.xml',
|
||||||
|
|
@ -44,27 +47,29 @@ class CampaignMenu extends AutoWatcher
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine.SwitchGuiPage("page_loading.xml", {
|
closePageCallback({ [Engine.openRequest]: {
|
||||||
"attribs": metadata.initAttributes,
|
"page": "page_loading.xml",
|
||||||
"playerAssignments": {
|
"argument": {
|
||||||
"local": {
|
"attribs": metadata.initAttributes,
|
||||||
"name":
|
"playerAssignments": {
|
||||||
metadata.initAttributes.settings.PlayerData[metadata.playerID]?.Name ??
|
"local": {
|
||||||
singleplayerName(),
|
"name": metadata.initAttributes.settings.PlayerData[metadata.playerID]
|
||||||
"player": metadata.playerID
|
?.Name ?? singleplayerName(),
|
||||||
}
|
"player": metadata.playerID
|
||||||
},
|
}
|
||||||
"savedGUIData": metadata.gui
|
},
|
||||||
});
|
"savedGUIData": metadata.gui
|
||||||
|
}
|
||||||
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
goBackToMainMenu()
|
goBackToMainMenu(closePageCallback)
|
||||||
{
|
{
|
||||||
this.run.save();
|
this.run.save();
|
||||||
Engine.SwitchGuiPage("page_pregame.xml", {});
|
closePageCallback({ [Engine.openRequest]: { "page": "page_pregame.xml" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
startScenario()
|
startScenario(closePageCallback)
|
||||||
{
|
{
|
||||||
const level = this.getSelectedLevelData();
|
const level = this.getSelectedLevelData();
|
||||||
if (!meetsRequirements(this.run, level))
|
if (!meetsRequirements(this.run, level))
|
||||||
|
|
@ -113,23 +118,29 @@ class CampaignMenu extends AutoWatcher
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Engine.SwitchGuiPage("page_gamesetup.xml", {
|
closePageCallback({ [Engine.openRequest]: {
|
||||||
"backPage": {
|
"page": "page_gamesetup.xml",
|
||||||
"page": this.run.getMenuPath(),
|
"argument": {
|
||||||
"data": {
|
"backPage": {
|
||||||
"filename": this.run.filename
|
"page": this.run.getMenuPath(),
|
||||||
}
|
"data": {
|
||||||
},
|
"filename": this.run.filename
|
||||||
"gameSettings": attributes,
|
}
|
||||||
});
|
},
|
||||||
|
"gameSettings": attributes,
|
||||||
|
}
|
||||||
|
} });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameSettings.launchGame(assignments, true);
|
gameSettings.launchGame(assignments, true);
|
||||||
Engine.SwitchGuiPage("page_loading.xml", {
|
closePageCallback({ [Engine.openRequest]: {
|
||||||
"attribs": gameSettings.finalizedAttributes,
|
"page": "page_loading.xml",
|
||||||
"playerAssignments": assignments
|
"argument": {
|
||||||
});
|
"attribs": gameSettings.finalizedAttributes,
|
||||||
|
"playerAssignments": assignments
|
||||||
|
}
|
||||||
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
getSelectedLevelData()
|
getSelectedLevelData()
|
||||||
|
|
@ -234,7 +245,7 @@ class CampaignMenu extends AutoWatcher
|
||||||
|
|
||||||
var g_CampaignMenu;
|
var g_CampaignMenu;
|
||||||
|
|
||||||
function init(initData)
|
async function init(initData)
|
||||||
{
|
{
|
||||||
let run = initData?.filename || CampaignRun.getCurrentRunFilename();
|
let run = initData?.filename || CampaignRun.getCurrentRunFilename();
|
||||||
try
|
try
|
||||||
|
|
@ -242,11 +253,14 @@ function init(initData)
|
||||||
run = new CampaignRun(run).load();
|
run = new CampaignRun(run).load();
|
||||||
if (!run.isCurrent())
|
if (!run.isCurrent())
|
||||||
run.setCurrent();
|
run.setCurrent();
|
||||||
g_CampaignMenu = new CampaignMenu(run);
|
return new Promise(closePageCallback =>
|
||||||
|
{
|
||||||
|
g_CampaignMenu = new CampaignMenu(run, closePageCallback);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch(err)
|
catch(err)
|
||||||
{
|
{
|
||||||
error(sprintf("Error loading campaign run %s: %s.", CampaignRun.getCurrentRunFilename(), err));
|
error(sprintf("Error loading campaign run %s: %s.", CampaignRun.getCurrentRunFilename(), err));
|
||||||
Engine.SwitchGuiPage("page_pregame.xml", {});
|
return { [Engine.openRequest]: { "page": "page_pregame.xml" } };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,16 @@ class BrokenRun
|
||||||
*/
|
*/
|
||||||
class LoadModal extends AutoWatcher
|
class LoadModal extends AutoWatcher
|
||||||
{
|
{
|
||||||
constructor(campaignTemplate)
|
constructor(closePageCallback)
|
||||||
{
|
{
|
||||||
super("render");
|
super("render");
|
||||||
|
|
||||||
// _watch so render() is called anytime currentRuns are modified.
|
// _watch so render() is called anytime currentRuns are modified.
|
||||||
this.currentRuns = _watch(this.getRuns(), () => this.render());
|
this.currentRuns = _watch(this.getRuns(), () => this.render());
|
||||||
|
|
||||||
Engine.GetGUIObjectByName('cancelButton').onPress = () => Engine.SwitchGuiPage("page_pregame.xml", {});
|
Engine.GetGUIObjectByName('cancelButton').onPress = closePageCallback.bind(undefined, {
|
||||||
|
[Engine.openRequest]: { "page": "page_pregame.xml" }
|
||||||
|
});
|
||||||
Engine.GetGUIObjectByName('deleteGameButton').onPress = () => this.deleteSelectedRun();
|
Engine.GetGUIObjectByName('deleteGameButton').onPress = () => this.deleteSelectedRun();
|
||||||
Engine.GetGUIObjectByName('startButton').onPress = () => this.startSelectedRun();
|
Engine.GetGUIObjectByName('startButton').onPress = () => this.startSelectedRun();
|
||||||
|
|
||||||
|
|
@ -81,16 +83,19 @@ class LoadModal extends AutoWatcher
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCampaign()
|
loadCampaign(closePageCallback)
|
||||||
{
|
{
|
||||||
const filename = this.currentRuns[this.selectedRun].filename;
|
const filename = this.currentRuns[this.selectedRun].filename;
|
||||||
const run = new CampaignRun(filename)
|
const run = new CampaignRun(filename)
|
||||||
.load()
|
.load()
|
||||||
.setCurrent();
|
.setCurrent();
|
||||||
|
|
||||||
Engine.SwitchGuiPage(run.getMenuPath(), {
|
closePageCallback({ [Engine.openRequest]: {
|
||||||
"filename": run.filename
|
"page": run.getMenuPath(),
|
||||||
});
|
"argument": {
|
||||||
|
"filename": run.filename
|
||||||
|
}
|
||||||
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteSelectedRun()
|
async deleteSelectedRun()
|
||||||
|
|
@ -112,10 +117,10 @@ class LoadModal extends AutoWatcher
|
||||||
this.selectedRun = -1;
|
this.selectedRun = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
startSelectedRun()
|
startSelectedRun(closePageCallback)
|
||||||
{
|
{
|
||||||
if (this.currentRuns[this.selectedRun] instanceof CampaignRun)
|
if (this.currentRuns[this.selectedRun] instanceof CampaignRun)
|
||||||
this.loadCampaign();
|
this.loadCampaign(closePageCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayCurrentRuns()
|
displayCurrentRuns()
|
||||||
|
|
@ -138,5 +143,5 @@ var g_LoadModal;
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
g_LoadModal = new LoadModal();
|
return new Promise(closePageCallback => { g_LoadModal = new LoadModal(closePageCallback); });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ class NewCampaignModal
|
||||||
this.template = campaignTemplate;
|
this.template = campaignTemplate;
|
||||||
|
|
||||||
Engine.GetGUIObjectByName('cancelButton').onPress = closePageCallback;
|
Engine.GetGUIObjectByName('cancelButton').onPress = closePageCallback;
|
||||||
Engine.GetGUIObjectByName('startButton').onPress = () => this.createAndStartCampaign();
|
Engine.GetGUIObjectByName('startButton').onPress =
|
||||||
|
this.createAndStartCampaign.bind(this, closePageCallback);
|
||||||
Engine.GetGUIObjectByName('runDescription').caption = translateWithContext("Campaign Template", this.template.Name);
|
Engine.GetGUIObjectByName('runDescription').caption = translateWithContext("Campaign Template", this.template.Name);
|
||||||
Engine.GetGUIObjectByName('runDescription').onTextEdit = () =>
|
Engine.GetGUIObjectByName('runDescription').onTextEdit = () =>
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +20,7 @@ class NewCampaignModal
|
||||||
Engine.GetGUIObjectByName('runDescription').focus();
|
Engine.GetGUIObjectByName('runDescription').focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
createAndStartCampaign()
|
createAndStartCampaign(closePageCallback)
|
||||||
{
|
{
|
||||||
const filename = this.template.identifier + "_" + Date.now() + "_" + Math.floor(Math.random()*100000);
|
const filename = this.template.identifier + "_" + Date.now() + "_" + Math.floor(Math.random()*100000);
|
||||||
const run = new CampaignRun(filename)
|
const run = new CampaignRun(filename)
|
||||||
|
|
@ -28,8 +29,11 @@ class NewCampaignModal
|
||||||
.save()
|
.save()
|
||||||
.setCurrent();
|
.setCurrent();
|
||||||
|
|
||||||
Engine.SwitchGuiPage(run.getMenuPath(), {
|
closePageCallback({
|
||||||
"filename": run.filename
|
"page": run.getMenuPath(),
|
||||||
|
"argument": {
|
||||||
|
"filename": run.filename
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,21 @@
|
||||||
*/
|
*/
|
||||||
class CampaignSetupPage extends AutoWatcher
|
class CampaignSetupPage extends AutoWatcher
|
||||||
{
|
{
|
||||||
constructor()
|
constructor(closePageCallback)
|
||||||
{
|
{
|
||||||
super("render");
|
super("render");
|
||||||
|
|
||||||
this.selectedIndex = -1;
|
this.selectedIndex = -1;
|
||||||
this.templates = CampaignTemplate.getAvailableTemplates();
|
this.templates = CampaignTemplate.getAvailableTemplates();
|
||||||
|
|
||||||
Engine.GetGUIObjectByName("mainMenuButton").onPress = () => Engine.SwitchGuiPage("page_pregame.xml");
|
Engine.GetGUIObjectByName("mainMenuButton").onPress = closePageCallback.bind(undefined,
|
||||||
Engine.GetGUIObjectByName("startCampButton").onPress = () => Engine.OpenChildPage("campaigns/new_modal/page.xml", this.selectedTemplate);
|
{ [Engine.openRequest]: { "page": "page_pregame.xml" } });
|
||||||
|
Engine.GetGUIObjectByName("startCampButton").onPress = async() =>
|
||||||
|
{
|
||||||
|
const ret = await Engine.OpenChildPage("campaigns/new_modal/page.xml", this.selectedTemplate);
|
||||||
|
if (ret !== undefined)
|
||||||
|
closePageCallback({ [Engine.openRequest]: ret });
|
||||||
|
};
|
||||||
|
|
||||||
this.campaignSelection = Engine.GetGUIObjectByName("campaignSelection");
|
this.campaignSelection = Engine.GetGUIObjectByName("campaignSelection");
|
||||||
this.campaignSelection.onMouseLeftDoubleClickItem = () =>
|
this.campaignSelection.onMouseLeftDoubleClickItem = () =>
|
||||||
|
|
@ -69,5 +75,8 @@ var g_CampaignSetupPage;
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
g_CampaignSetupPage = new CampaignSetupPage();
|
return new Promise(closePageCallback =>
|
||||||
|
{
|
||||||
|
g_CampaignSetupPage = new CampaignSetupPage(closePageCallback);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue