Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/aiconfig/aiconfig.js
var g_AIBehaviorList = [{ | |||||
"Name": "random", | |||||
"Title": translateWithContext("AI Behavior", "Random") | |||||
}].concat(g_Settings.AIBehaviors); | |||||
var g_PlayerSlot; | var g_PlayerSlot; | ||||
const g_AIDescriptions = [{ | var g_AIDescriptions = [{ | ||||
"id": "", | "id": "", | ||||
"data": { | "data": { | ||||
"name": translateWithContext("ai", "None"), | "name": translateWithContext("ai", "None"), | ||||
"description": translate("AI will be disabled for this player.") | "description": translate("AI will be disabled for this player.") | ||||
} | } | ||||
}].concat(g_Settings.AIDescriptions); | }].concat(g_Settings.AIDescriptions); | ||||
var g_AIControls = { | |||||
"aiSelection": { | |||||
"labels": g_AIDescriptions.map(ai => ai.data.name), | |||||
"selected": settings => g_AIDescriptions.findIndex(ai => ai.id == settings.id) | |||||
}, | |||||
"aiDifficulty": { | |||||
"labels": prepareForDropdown(g_Settings.AIDifficulties).Title, | |||||
"selected": settings => settings.difficulty | |||||
}, | |||||
"aiBehavior": { | |||||
"labels": prepareForDropdown(g_AIBehaviorList).Title, | |||||
"selected": settings => g_AIBehaviorList.findIndex(b => b.Name == settings.behavior) | |||||
} | |||||
}; | |||||
function init(settings) | function init(settings) | ||||
{ | { | ||||
// Remember the player ID that we change the AI settings for | // Remember the player ID that we change the AI settings for | ||||
g_PlayerSlot = settings.playerSlot; | g_PlayerSlot = settings.playerSlot; | ||||
let aiSelection = Engine.GetGUIObjectByName("aiSelection"); | for (let name in g_AIControls) | ||||
aiSelection.list = g_AIDescriptions.map(ai => ai.data.name); | { | ||||
aiSelection.selected = g_AIDescriptions.findIndex(ai => ai.id == settings.id); | let control = Engine.GetGUIObjectByName(name); | ||||
aiSelection.hidden = !settings.isController; | control.list = g_AIControls[name].labels; | ||||
control.selected = g_AIControls[name].selected(settings); | |||||
let aiSelectionText = Engine.GetGUIObjectByName("aiSelectionText"); | control.hidden = !settings.isController; | ||||
aiSelectionText.caption = aiSelection.list[aiSelection.selected]; | |||||
aiSelectionText.hidden = settings.isController; | let label = Engine.GetGUIObjectByName(name + "Text"); | ||||
label.caption = control.list[control.selected]; | |||||
let aiDiff = Engine.GetGUIObjectByName("aiDifficulty"); | label.hidden = settings.isController; | ||||
aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title; | } | ||||
aiDiff.selected = settings.difficulty; | |||||
aiDiff.hidden = !settings.isController; | |||||
let aiDiffText = Engine.GetGUIObjectByName("aiDifficultyText"); | |||||
aiDiffText.caption = aiDiff.list[aiDiff.selected]; | |||||
aiDiffText.hidden = settings.isController; | |||||
} | } | ||||
function selectAI(idx) | function selectAI(idx) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("aiDescription").caption = g_AIDescriptions[idx].data.description; | Engine.GetGUIObjectByName("aiDescription").caption = g_AIDescriptions[idx].data.description; | ||||
} | } | ||||
function returnAI(save = true) | function returnAI(save = true) | ||||
{ | { | ||||
let idx = Engine.GetGUIObjectByName("aiSelection").selected; | let idx = Engine.GetGUIObjectByName("aiSelection").selected; | ||||
// Pop the page before calling the callback, so the callback runs | // Pop the page before calling the callback, so the callback runs | ||||
// in the parent GUI page's context | // in the parent GUI page's context | ||||
Engine.PopGuiPageCB({ | Engine.PopGuiPageCB({ | ||||
"save": save, | "save": save, | ||||
"id": g_AIDescriptions[idx].id, | "id": g_AIDescriptions[idx].id, | ||||
"name": g_AIDescriptions[idx].data.name, | "name": g_AIDescriptions[idx].data.name, | ||||
"difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected, | "difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected, | ||||
"behavior": g_AIBehaviorList[Engine.GetGUIObjectByName("aiBehavior").selected].Name, | |||||
"playerSlot": g_PlayerSlot | "playerSlot": g_PlayerSlot | ||||
}); | }); | ||||
} | } |
Wildfire Games · Phabricator