Ticket #3911: visible_ai_setting_v2.patch

File visible_ai_setting_v2.patch, 6.4 KB (added by elexis, 8 years ago)

Update the window when settings were changed.

  • binaries/data/mods/public/gui/aiconfig/aiconfig.js

    const g_AIDescriptions = [{  
    1111function init(settings)
    1212{
    1313    // Remember the player ID that we change the AI settings for
    1414    g_PlayerSlot = settings.playerSlot;
    1515
    16     var aiSelection = Engine.GetGUIObjectByName("aiSelection");
     16    let aiSelection = Engine.GetGUIObjectByName("aiSelection");
    1717    aiSelection.list = g_AIDescriptions.map(ai => ai.data.name);
    1818    aiSelection.selected = g_AIDescriptions.findIndex(ai => ai.id == settings.id);
     19    aiSelection.hidden = !settings.isController;
    1920
    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");
    2126    aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title;
    2227    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;
    2333}
    2434
    2535function selectAI(idx)
    2636{
    2737    Engine.GetGUIObjectByName("aiDescription").caption = g_AIDescriptions[idx].data.description;
    2838}
    2939
    30 function returnAI()
     40function returnAI(save = true)
    3141{
    32     var idx = Engine.GetGUIObjectByName("aiSelection").selected;
     42    let idx = Engine.GetGUIObjectByName("aiSelection").selected;
    3343
    3444    // Pop the page before calling the callback, so the callback runs
    3545    // in the parent GUI page's context
    3646    Engine.PopGuiPageCB({
     47        "save": save,
    3748        "id": g_AIDescriptions[idx].id,
    3849        "name": g_AIDescriptions[idx].data.name,
    3950        "difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected,
    4051        "playerSlot": g_PlayerSlot
    4152    });
  • binaries/data/mods/public/gui/aiconfig/aiconfig.xml

     
    2222            </object>
    2323
    2424            <object name="aiSelection" type="dropdown" style="ModernDropDown" size="50%-24 0 50%+136 28">
    2525                <action on="SelectionChange">selectAI(this.selected);</action>
    2626            </object>
     27            <object name="aiSelectionText" type="text" style="ModernLeftLabelText" size="50%-24 0 50%+136 28"/>
    2728
    2829            <object type="text" style="ModernRightLabelText" size="-10 35 90 50%+35">
    2930                <translatableAttribute id="caption">AI Difficulty:</translatableAttribute>
    3031            </object>
    3132           
    3233            <object name="aiDifficulty" type="dropdown" style="ModernDropDown" size="50%-24 35 50%+136 63">
    3334            </object>
     35            <object name="aiDifficultyText" type="text" style="ModernLeftLabelText" size="50%-24 35 50%+136 63"/>
    3436        </object>
    3537
    3638        <object name="aiDescription" type="text" style="ModernLabelText" size="8% 90 92% 100%-60"/>
    3739
    3840        <object type="button" style="ModernButtonRed" size="18 100%-45 50%-5 100%-17" hotkey="cancel">
    3941            <translatableAttribute id="caption">Cancel</translatableAttribute>
    40             <action on="Press">Engine.PopGuiPage();</action>
     42            <action on="Press">returnAI(false);</action>
    4143        </object>
    4244
    4345        <object type="button" style="ModernButtonRed" size="50%+5 100%-45 100%-18 100%-17">
    4446            <translatableAttribute id="caption">OK</translatableAttribute>
    45             <action on="Press">returnAI();</action>
     47            <action on="Press">returnAI(true);</action>
    4648        </object>
    4749    </object>
    4850</objects>
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

    var g_LoadingState = 0; // 0 = not start  
    190190 * Only send a lobby update if something actually changed.
    191191 */
    192192var g_LastGameStanza;
    193193
    194194/**
     195 * Remembers if the current player viewed the AI settings of some playerslot.
     196 */
     197var g_LastViewedAIPlayer = -1;
     198
     199/**
    195200 * Initializes some globals without touching the GUI.
    196201 *
    197202 * @param {Object} attribs - context data sent by the lobby / mainmenu
    198203 */
    199204function init(attribs)
    function updateGUIObjects()  
    13611366    // Game attributes include AI settings, so update the player list
    13621367    updatePlayerList();
    13631368
    13641369    // We should have everyone confirm that the new settings are acceptable.
    13651370    resetReadyData();
     1371
     1372    // Refresh AI settings
     1373    if (g_LastViewedAIPlayer != -1)
     1374    {
     1375        Engine.PopGuiPage();
     1376        openAIDialog();
     1377    }
     1378}
     1379
     1380function 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    });
    13661389}
    13671390
    13681391/**
    13691392 * Sets an additional map label, map preview image and mapsettings description.
    13701393 */
    function updateGameAttributes()  
    14091432        updateGUIObjects();
    14101433}
    14111434
    14121435function AIConfigCallback(ai)
    14131436{
     1437    g_LastViewedAIPlayer = -1;
     1438
     1439    if (!ai.save || !g_IsController)
     1440        return;
     1441
    14141442    g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id;
    14151443    g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty;
    14161444
    14171445    if (g_IsNetworked)
    14181446        Engine.SetNetworkGameAttributes(g_GameAttributes);
    function updatePlayerList()  
    14971525
    14981526            if (!selection)
    14991527                selection = noAssignment;
    15001528
    15011529            // 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            };
    15141535        }
    15151536        // There was a human, so make sure we don't have any AI left
    15161537        // over in their slot, if we're in charge of the attributes
    15171538        else if (g_IsController && g_GameAttributes.settings.PlayerData[playerSlot].AI)
    15181539        {