mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Some checks failed
checkrefs / lfscheck (push) Has been cancelled
checkrefs / checkrefs (push) Has been cancelled
lint / cppcheck (push) Has been cancelled
lint / copyright (push) Has been cancelled
lint / jenkinsfiles (push) Has been cancelled
pre-commit / build (push) Has been cancelled
Add registerGlobalGuiPageHotkeys() to common/functions_utility.js to selectively register GUI page hotkeys Allow active GUI pages to close using their corresponding hotkey Move page_hotkeys.xml from gui/hotkeys/ to gui/ Update page_hotkeys.xml references in MainMenuItems and MenuButtons Add default tipScrolling fallback in TipsPage when no initData is provided
83 lines
3 KiB
JavaScript
83 lines
3 KiB
JavaScript
/**
|
|
* The campaign setup page shows you the list of available campaigns,
|
|
* some information about them, and lets you start a new one.
|
|
*/
|
|
class CampaignSetupPage extends AutoWatcher
|
|
{
|
|
constructor(closePageCallback)
|
|
{
|
|
super("render");
|
|
|
|
this.selectedIndex = -1;
|
|
this.templates = CampaignTemplate.getAvailableTemplates();
|
|
|
|
Engine.GetGUIObjectByName("mainMenuButton").onPress = closePageCallback.bind(undefined,
|
|
{ [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.onMouseLeftDoubleClickItem = () =>
|
|
{
|
|
if (this.selectedIndex === -1)
|
|
return;
|
|
Engine.OpenChildPage("campaigns/new_modal/page.xml", this.selectedTemplate);
|
|
};
|
|
this.campaignSelection.onSelectionChange = () =>
|
|
{
|
|
this.selectedIndex = this.campaignSelection.selected;
|
|
if (this.selectedIndex !== -1)
|
|
this.selectedTemplate = this.templates[this.selectedIndex];
|
|
else
|
|
this.selectedTemplate = null;
|
|
};
|
|
|
|
this._ready = true;
|
|
}
|
|
|
|
displayCampaignDetails()
|
|
{
|
|
Engine.GetGUIObjectByName("startCampButton").enabled = this.selectedIndex !== -1;
|
|
|
|
if (!this.selectedTemplate)
|
|
{
|
|
Engine.GetGUIObjectByName("campaignTitle").caption = translate("No campaign selected.");
|
|
Engine.GetGUIObjectByName("campaignDesc").caption = "";
|
|
Engine.GetGUIObjectByName("campaignImage").sprite = "cropped:" + 400/512 + "," + 300/512 + ":session/icons/mappreview/nopreview.png";
|
|
return;
|
|
}
|
|
|
|
Engine.GetGUIObjectByName("campaignTitle").caption = translateWithContext("Campaign Template", this.selectedTemplate.Name);
|
|
Engine.GetGUIObjectByName("campaignDesc").caption = translateWithContext("Campaign Template", this.selectedTemplate.Description);
|
|
if ('Image' in this.selectedTemplate)
|
|
Engine.GetGUIObjectByName("campaignImage").sprite = "stretched:" + this.selectedTemplate.Image;
|
|
else
|
|
Engine.GetGUIObjectByName("campaignImage").sprite = "cropped:" + 400/512 + "," + 300/512 + ":session/icons/mappreview/nopreview.png";
|
|
}
|
|
|
|
render()
|
|
{
|
|
this.displayCampaignDetails();
|
|
|
|
Engine.GetGUIObjectByName("campaignSelection").list_name = this.templates.map((camp) => translateWithContext("Campaign Template", camp.Name));
|
|
// COList needs these changed last or crashes.
|
|
Engine.GetGUIObjectByName("campaignSelection").list = this.templates.map((camp) => camp.identifier) || [];
|
|
Engine.GetGUIObjectByName("campaignSelection").list_data = this.templates.map((camp) => camp.identifier) || [];
|
|
}
|
|
}
|
|
|
|
|
|
var g_CampaignSetupPage;
|
|
|
|
function init()
|
|
{
|
|
registerGlobalGuiPageHotkeys(["options", "hotkeys", "civinfo", "structree", "catafalque", "manual", "tips", "mapbrowser"]);
|
|
return new Promise(closePageCallback =>
|
|
{
|
|
g_CampaignSetupPage = new CampaignSetupPage(closePageCallback);
|
|
});
|
|
}
|