Ticket #3911: visible_ai_setting_v2.patch
File visible_ai_setting_v2.patch, 6.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/aiconfig/aiconfig.js
const g_AIDescriptions = [{ 11 11 function init(settings) 12 12 { 13 13 // Remember the player ID that we change the AI settings for 14 14 g_PlayerSlot = settings.playerSlot; 15 15 16 varaiSelection = Engine.GetGUIObjectByName("aiSelection");16 let aiSelection = Engine.GetGUIObjectByName("aiSelection"); 17 17 aiSelection.list = g_AIDescriptions.map(ai => ai.data.name); 18 18 aiSelection.selected = g_AIDescriptions.findIndex(ai => ai.id == settings.id); 19 aiSelection.hidden = !settings.isController; 19 20 20 var aiDiff = Engine.GetGUIObjectByName("aiDifficulty"); 21 let aiSelectionText = Engine.GetGUIObjectByName("aiSelectionText"); 22 aiSelectionText.caption = aiSelection.list[aiSelection.selected]; 23 aiSelectionText.hidden = settings.isController; 24 25 let aiDiff = Engine.GetGUIObjectByName("aiDifficulty"); 21 26 aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title; 22 27 aiDiff.selected = settings.difficulty; 28 aiDiff.hidden = !settings.isController; 29 30 let aiDiffText = Engine.GetGUIObjectByName("aiDifficultyText"); 31 aiDiffText.caption = aiDiff.list[aiDiff.selected]; 32 aiDiffText.hidden = settings.isController; 23 33 } 24 34 25 35 function selectAI(idx) 26 36 { 27 37 Engine.GetGUIObjectByName("aiDescription").caption = g_AIDescriptions[idx].data.description; 28 38 } 29 39 30 function returnAI( )40 function returnAI(save = true) 31 41 { 32 varidx = Engine.GetGUIObjectByName("aiSelection").selected;42 let idx = Engine.GetGUIObjectByName("aiSelection").selected; 33 43 34 44 // Pop the page before calling the callback, so the callback runs 35 45 // in the parent GUI page's context 36 46 Engine.PopGuiPageCB({ 47 "save": save, 37 48 "id": g_AIDescriptions[idx].id, 38 49 "name": g_AIDescriptions[idx].data.name, 39 50 "difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected, 40 51 "playerSlot": g_PlayerSlot 41 52 }); -
binaries/data/mods/public/gui/aiconfig/aiconfig.xml
22 22 </object> 23 23 24 24 <object name="aiSelection" type="dropdown" style="ModernDropDown" size="50%-24 0 50%+136 28"> 25 25 <action on="SelectionChange">selectAI(this.selected);</action> 26 26 </object> 27 <object name="aiSelectionText" type="text" style="ModernLeftLabelText" size="50%-24 0 50%+136 28"/> 27 28 28 29 <object type="text" style="ModernRightLabelText" size="-10 35 90 50%+35"> 29 30 <translatableAttribute id="caption">AI Difficulty:</translatableAttribute> 30 31 </object> 31 32 32 33 <object name="aiDifficulty" type="dropdown" style="ModernDropDown" size="50%-24 35 50%+136 63"> 33 34 </object> 35 <object name="aiDifficultyText" type="text" style="ModernLeftLabelText" size="50%-24 35 50%+136 63"/> 34 36 </object> 35 37 36 38 <object name="aiDescription" type="text" style="ModernLabelText" size="8% 90 92% 100%-60"/> 37 39 38 40 <object type="button" style="ModernButtonRed" size="18 100%-45 50%-5 100%-17" hotkey="cancel"> 39 41 <translatableAttribute id="caption">Cancel</translatableAttribute> 40 <action on="Press"> Engine.PopGuiPage();</action>42 <action on="Press">returnAI(false);</action> 41 43 </object> 42 44 43 45 <object type="button" style="ModernButtonRed" size="50%+5 100%-45 100%-18 100%-17"> 44 46 <translatableAttribute id="caption">OK</translatableAttribute> 45 <action on="Press">returnAI( );</action>47 <action on="Press">returnAI(true);</action> 46 48 </object> 47 49 </object> 48 50 </objects> -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
var g_LoadingState = 0; // 0 = not start 190 190 * Only send a lobby update if something actually changed. 191 191 */ 192 192 var g_LastGameStanza; 193 193 194 194 /** 195 * Remembers if the current player viewed the AI settings of some playerslot. 196 */ 197 var g_LastViewedAIPlayer = -1; 198 199 /** 195 200 * Initializes some globals without touching the GUI. 196 201 * 197 202 * @param {Object} attribs - context data sent by the lobby / mainmenu 198 203 */ 199 204 function init(attribs) … … function updateGUIObjects() 1361 1366 // Game attributes include AI settings, so update the player list 1362 1367 updatePlayerList(); 1363 1368 1364 1369 // We should have everyone confirm that the new settings are acceptable. 1365 1370 resetReadyData(); 1371 1372 // Refresh AI settings 1373 if (g_LastViewedAIPlayer != -1) 1374 { 1375 Engine.PopGuiPage(); 1376 openAIDialog(); 1377 } 1378 } 1379 1380 function openAIDialog() 1381 { 1382 Engine.PushGuiPage("page_aiconfig.xml", { 1383 "callback": "AIConfigCallback", 1384 "isController": g_IsController, 1385 "playerSlot": g_LastViewedAIPlayer, 1386 "id": g_GameAttributes.settings.PlayerData[g_LastViewedAIPlayer].AI, 1387 "difficulty": g_GameAttributes.settings.PlayerData[g_LastViewedAIPlayer].AIDiff 1388 }); 1366 1389 } 1367 1390 1368 1391 /** 1369 1392 * Sets an additional map label, map preview image and mapsettings description. 1370 1393 */ … … function updateGameAttributes() 1409 1432 updateGUIObjects(); 1410 1433 } 1411 1434 1412 1435 function AIConfigCallback(ai) 1413 1436 { 1437 g_LastViewedAIPlayer = -1; 1438 1439 if (!ai.save || !g_IsController) 1440 return; 1441 1414 1442 g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id; 1415 1443 g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty; 1416 1444 1417 1445 if (g_IsNetworked) 1418 1446 Engine.SetNetworkGameAttributes(g_GameAttributes); … … function updatePlayerList() 1497 1525 1498 1526 if (!selection) 1499 1527 selection = noAssignment; 1500 1528 1501 1529 // Since no human is assigned, show the AI config button 1502 if (g_IsController) 1503 { 1504 configButton.hidden = false; 1505 configButton.onpress = function() { 1506 Engine.PushGuiPage("page_aiconfig.xml", { 1507 "id": g_GameAttributes.settings.PlayerData[playerSlot].AI, 1508 "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff, 1509 "callback": "AIConfigCallback", 1510 "playerSlot": playerSlot // required by the callback function 1511 }); 1512 }; 1513 } 1530 configButton.hidden = false; 1531 configButton.onpress = function() { 1532 g_LastViewedAIPlayer = playerSlot; 1533 openAIDialog(); 1534 }; 1514 1535 } 1515 1536 // There was a human, so make sure we don't have any AI left 1516 1537 // over in their slot, if we're in charge of the attributes 1517 1538 else if (g_IsController && g_GameAttributes.settings.PlayerData[playerSlot].AI) 1518 1539 {