Changeset View
Standalone View
binaries/data/mods/public/gui/campaign/simple_setup/campaignsetup.js
- This file was added.
var g_CampaignsAvailable = {}; // "name of JSON file/ID of campaign" : data as parsed JSON | |||||
elexis: /**
| |||||
var g_SelectedCampaign = null; | |||||
/* | |||||
* Initializes the campaign window. | |||||
* Loads all campaigns | |||||
* Allows you to start them. | |||||
*/ | |||||
// TODO: Should we support mods? | |||||
Not Done Inline Actions(How could we not) elexis: (How could we not) | |||||
Not Done Inline Actions-\n elexis: -\n | |||||
function init(data) | |||||
{ | |||||
g_CampaignsAvailable = LoadAvailableCampaigns(); | |||||
Engine.GetGUIObjectByName("CampaignImage").sprite = "cropped:" + 400/512 + "," + 300/512 + ":session/icons/mappreview/nopreview.png"; | |||||
Not Done Inline ActionsMind not copying this? elexis: Mind not copying this? | |||||
GenerateCampaignList(); | |||||
} | |||||
function GenerateCampaignList() | |||||
{ | |||||
Not Done Inline Actions(Nearly every GUI function starts lowercase) elexis: (Nearly every GUI function starts lowercase) | |||||
let selection = Engine.GetGUIObjectByName("campaignSelection"); | |||||
if (selection.selected !== -1) | |||||
displayCampaignDetails(); | |||||
let list = []; | |||||
Not Done Inline Actionscamp => elexis: camp => | |||||
for (let key in g_CampaignsAvailable) | |||||
list.push({ "directories" : key, "name" : g_CampaignsAvailable[key].Name }); | |||||
Not Done Inline Actionsclassic, due to the COList : CList inheritance. Notice COList doesnt even use list and list_data anywhere (only possibly JS using these CList properties. Would require lots of wasted braincells to fix) elexis: classic, due to the COList : CList inheritance. Notice COList doesnt even use list and… | |||||
// change array of object into object of array. | |||||
list = prepareForDropdown(list); | |||||
Done Inline Actions= Object.keys(g_CampaignsAvailable).map(directory =>g_CampaignsAvailable[key].Name ) elexis: `= Object.keys(g_CampaignsAvailable).map(directory =>g_CampaignsAvailable[key].Name )` | |||||
// Push to GUI | |||||
selection.selected = -1; | |||||
selection.list_name = list.name || []; | |||||
Done Inline Actions= Object.keys(g_CampaignsAvailable) g_CampaignsAvailable returning an array instead of object would remove the Object.keys in both places elexis: `= Object.keys(g_CampaignsAvailable)`
`g_CampaignsAvailable` returning an array instead of… | |||||
// Change these last, otherwise crash | |||||
// TODO: do we need both of those? I'm unsure. | |||||
selection.list = list.directories || []; | |||||
Not Done Inline ActionsOne avoids to refer to oneself in academic writing for the same reasons that apply here. State objective facts only. elexis: One avoids to refer to oneself in academic writing for the same reasons that apply here. State… | |||||
selection.list_data = list.directories || []; | |||||
// replaySelection.selected = replaySelection.list.findIndex(directory => directory == g_SelectedReplayDirectory); | |||||
// displayReplayDetails(); | |||||
} | |||||
Done Inline Actionsdelete commented out code or make it actual code elexis: delete commented out code or make it actual code | |||||
function displayCampaignDetails() | |||||
{ | |||||
let selection = Engine.GetGUIObjectByName("campaignSelection"); | |||||
Done Inline ActionsShould use lowerCamelCase or UpperCamelCase consistently, the same case that the majority of the GUI pages use elexis: Should use lowerCamelCase or UpperCamelCase consistently, the same case that the majority of… | |||||
Not Done Inline Actionsstill elexis: still | |||||
if (selection.selected === -1) | |||||
return; | |||||
g_SelectedCampaign = selection.list[selection.selected]; | |||||
Engine.GetGUIObjectByName("startCampButton").enabled = true; | |||||
Engine.GetGUIObjectByName("campaignOptionsButton").enabled = true; | |||||
Engine.GetGUIObjectByName("CampaignTitle").caption = translate(g_CampaignsAvailable[g_SelectedCampaign].Name); | |||||
Engine.GetGUIObjectByName("campaignDesc").caption = translate(g_CampaignsAvailable[g_SelectedCampaign].Description); | |||||
if (g_CampaignsAvailable[g_SelectedCampaign].Image) | |||||
Not Done Inline Actionssame elexis: same | |||||
Not Done Inline ActionsSee below:
wraitii: See below:
> Mh, I don't believe that's a good idea actually, because the image could/should… | |||||
Not Done Inline ActionsDon't see where that is an issue. The helper function receives a filename argument. I'm talking about setMapPreviewImage which removes the if and especially the image dimensions and fallback image. elexis: Don't see where that is an issue. The helper function receives a filename argument. I'm talking… | |||||
Not Done Inline ActionsThe point is that the image dimension could be different, mostly. But this should probably just be defined in the campaign JSON file. See the above open question for another issue. wraitii: The point is that the image dimension could be different, mostly. But this should probably just… | |||||
Engine.GetGUIObjectByName("CampaignImage").sprite = "stretched:" + g_CampaignsAvailable[g_SelectedCampaign].Image; | |||||
else | |||||
Engine.GetGUIObjectByName("CampaignImage").sprite = "cropped:" + 400/512 + "," + 300/512 + ":session/icons/mappreview/nopreview.png"; | |||||
Done Inline ActionssetMapPreviewImage, same for those other 300/512 occurances. extend the function if needed elexis: setMapPreviewImage, same for those other 300/512 occurances. extend the function if needed | |||||
Not Done Inline ActionsMh, I don't believe that's a good idea actually, because the image could/should be loaded from somewhere else maybe (we probably won't want to show the map itself). In fact that should be loaded from the campaign JSON file. wraitii: Mh, I don't believe that's a good idea actually, because the image could/should be loaded from… | |||||
Not Done Inline ActionsIf the JSON file should be able to specify custom image dimensions, how is that going to be implemented in the GUI? The object positions would have to shift depending on the image dimension specified by the user. elexis: If the JSON file should be able to specify custom image dimensions, how is that going to be… | |||||
Not Done Inline ActionsI suppose that's fair. wraitii: I suppose that's fair. | |||||
Not Done Inline ActionsAlso, if the campaign GUI should be able to use thumbnails of resolutions different from 400x300, then so should the gamesetup, lobby and replaymenu and that number could become an argument of the function. elexis: Also, if the campaign GUI should be able to use thumbnails of resolutions different from… | |||||
} | |||||
function startCampaign() | |||||
{ | |||||
Engine.PushGuiPage("page_newcampaign.xml", { "campaignID" : g_SelectedCampaign, "campaignData" : g_CampaignsAvailable[g_SelectedCampaign] }); | |||||
} |
/**