forked from mirrors/0ad
Reveal AI settings in the gamesetup to all players. Based on patch by Imarok, fixes #3911.
This was SVN commit r18078.
This commit is contained in:
@@ -13,13 +13,23 @@ function init(settings)
|
||||
// Remember the player ID that we change the AI settings for
|
||||
g_PlayerSlot = settings.playerSlot;
|
||||
|
||||
var aiSelection = Engine.GetGUIObjectByName("aiSelection");
|
||||
let aiSelection = Engine.GetGUIObjectByName("aiSelection");
|
||||
aiSelection.list = g_AIDescriptions.map(ai => ai.data.name);
|
||||
aiSelection.selected = g_AIDescriptions.findIndex(ai => ai.id == settings.id);
|
||||
aiSelection.hidden = !settings.isController;
|
||||
|
||||
var aiDiff = Engine.GetGUIObjectByName("aiDifficulty");
|
||||
let aiSelectionText = Engine.GetGUIObjectByName("aiSelectionText");
|
||||
aiSelectionText.caption = aiSelection.list[aiSelection.selected];
|
||||
aiSelectionText.hidden = settings.isController;
|
||||
|
||||
let aiDiff = Engine.GetGUIObjectByName("aiDifficulty");
|
||||
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)
|
||||
@@ -27,13 +37,14 @@ function selectAI(idx)
|
||||
Engine.GetGUIObjectByName("aiDescription").caption = g_AIDescriptions[idx].data.description;
|
||||
}
|
||||
|
||||
function returnAI()
|
||||
function returnAI(save = true)
|
||||
{
|
||||
var idx = Engine.GetGUIObjectByName("aiSelection").selected;
|
||||
let idx = Engine.GetGUIObjectByName("aiSelection").selected;
|
||||
|
||||
// Pop the page before calling the callback, so the callback runs
|
||||
// in the parent GUI page's context
|
||||
Engine.PopGuiPageCB({
|
||||
"save": save,
|
||||
"id": g_AIDescriptions[idx].id,
|
||||
"name": g_AIDescriptions[idx].data.name,
|
||||
"difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<object name="aiSelection" type="dropdown" style="ModernDropDown" size="50%-24 0 50%+136 28">
|
||||
<action on="SelectionChange">selectAI(this.selected);</action>
|
||||
</object>
|
||||
<object name="aiSelectionText" type="text" style="ModernLeftLabelText" size="50%-24 0 50%+136 28"/>
|
||||
|
||||
<object type="text" style="ModernRightLabelText" size="-10 35 90 50%+35">
|
||||
<translatableAttribute id="caption">AI Difficulty:</translatableAttribute>
|
||||
@@ -31,18 +32,19 @@
|
||||
|
||||
<object name="aiDifficulty" type="dropdown" style="ModernDropDown" size="50%-24 35 50%+136 63">
|
||||
</object>
|
||||
<object name="aiDifficultyText" type="text" style="ModernLeftLabelText" size="50%-24 35 50%+136 63"/>
|
||||
</object>
|
||||
|
||||
<object name="aiDescription" type="text" style="ModernLabelText" size="8% 90 92% 100%-60"/>
|
||||
|
||||
<object type="button" style="ModernButtonRed" size="18 100%-45 50%-5 100%-17" hotkey="cancel">
|
||||
<translatableAttribute id="caption">Cancel</translatableAttribute>
|
||||
<action on="Press">Engine.PopGuiPage();</action>
|
||||
<action on="Press">returnAI(false);</action>
|
||||
</object>
|
||||
|
||||
<object type="button" style="ModernButtonRed" size="50%+5 100%-45 100%-18 100%-17">
|
||||
<translatableAttribute id="caption">OK</translatableAttribute>
|
||||
<action on="Press">returnAI();</action>
|
||||
<action on="Press">returnAI(true);</action>
|
||||
</object>
|
||||
</object>
|
||||
</objects>
|
||||
|
||||
@@ -192,6 +192,11 @@ var g_LoadingState = 0; // 0 = not started, 1 = loading, 2 = loaded
|
||||
*/
|
||||
var g_LastGameStanza;
|
||||
|
||||
/**
|
||||
* Remembers if the current player viewed the AI settings of some playerslot.
|
||||
*/
|
||||
var g_LastViewedAIPlayer = -1;
|
||||
|
||||
/**
|
||||
* Initializes some globals without touching the GUI.
|
||||
*
|
||||
@@ -1420,6 +1425,13 @@ function updateGUIObjects()
|
||||
|
||||
// We should have everyone confirm that the new settings are acceptable.
|
||||
resetReadyData();
|
||||
|
||||
// Refresh AI config page
|
||||
if (g_LastViewedAIPlayer != -1)
|
||||
{
|
||||
Engine.PopGuiPage();
|
||||
openAIConfig(g_LastViewedAIPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1480,8 +1492,29 @@ function updateGameAttributes()
|
||||
updateGUIObjects();
|
||||
}
|
||||
|
||||
function openAIConfig(playerSlot)
|
||||
{
|
||||
g_LastViewedAIPlayer = playerSlot;
|
||||
|
||||
Engine.PushGuiPage("page_aiconfig.xml", {
|
||||
"callback": "AIConfigCallback",
|
||||
"isController": g_IsController,
|
||||
"playerSlot": playerSlot,
|
||||
"id": g_GameAttributes.settings.PlayerData[playerSlot].AI,
|
||||
"difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after closing the dialog.
|
||||
*/
|
||||
function AIConfigCallback(ai)
|
||||
{
|
||||
g_LastViewedAIPlayer = -1;
|
||||
|
||||
if (!ai.save || !g_IsController)
|
||||
return;
|
||||
|
||||
g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id;
|
||||
g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty;
|
||||
|
||||
@@ -1570,18 +1603,10 @@ function updatePlayerList()
|
||||
selection = noAssignment;
|
||||
|
||||
// Since no human is assigned, show the AI config button
|
||||
if (g_IsController)
|
||||
{
|
||||
configButton.hidden = false;
|
||||
configButton.onpress = function() {
|
||||
Engine.PushGuiPage("page_aiconfig.xml", {
|
||||
"id": g_GameAttributes.settings.PlayerData[playerSlot].AI,
|
||||
"difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff,
|
||||
"callback": "AIConfigCallback",
|
||||
"playerSlot": playerSlot // required by the callback function
|
||||
});
|
||||
};
|
||||
}
|
||||
configButton.hidden = false;
|
||||
configButton.onpress = function() {
|
||||
openAIConfig(playerSlot);
|
||||
};
|
||||
}
|
||||
// There was a human, so make sure we don't have any AI left
|
||||
// over in their slot, if we're in charge of the attributes
|
||||
|
||||
Reference in New Issue
Block a user