Ticket #3911: visible_ai_setting.patch

File visible_ai_setting.patch, 4.3 KB (added by Imarok, 8 years ago)

Makes AI settings visible to all players but only let the controller change them

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

     
    11var g_PlayerSlot;
     2var g_IsController;
    23
    34const g_AIDescriptions = [{
    45    "id": "",
     
    1011
    1112function init(settings)
    1213{
     14    g_IsController = settings.callback != "";
    1315    // Remember the player ID that we change the AI settings for
    1416    g_PlayerSlot = settings.playerSlot;
    1517
     
    2022    var aiDiff = Engine.GetGUIObjectByName("aiDifficulty");
    2123    aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title;
    2224    aiDiff.selected = settings.difficulty;
     25
     26    Engine.GetGUIObjectByName("aiSelectionText").caption = aiSelection.list[aiSelection.selected];
     27    Engine.GetGUIObjectByName("aiDifficultyText").caption = aiDiff.list[aiDiff.selected];
     28
     29    aiSelection.hidden = !g_IsController;
     30    aiDiff.hidden = !g_IsController;
     31
     32    Engine.GetGUIObjectByName("aiSelectionText").hidden = g_IsController;
     33    Engine.GetGUIObjectByName("aiDifficultyText").hidden = g_IsController;
    2334}
    2435
    2536function selectAI(idx)
     
    3142{
    3243    var idx = Engine.GetGUIObjectByName("aiSelection").selected;
    3344
    34     // Pop the page before calling the callback, so the callback runs
    35     // in the parent GUI page's context
    36     Engine.PopGuiPageCB({
    37         "id": g_AIDescriptions[idx].id,
    38         "name": g_AIDescriptions[idx].data.name,
    39         "difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected,
    40         "playerSlot": g_PlayerSlot
    41     });
     45    if(g_IsController)
     46        // Pop the page before calling the callback, so the callback runs
     47        // in the parent GUI page's context
     48        Engine.PopGuiPageCB({
     49            "id": g_AIDescriptions[idx].id,
     50            "name": g_AIDescriptions[idx].data.name,
     51            "difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected,
     52            "playerSlot": g_PlayerSlot
     53        });
     54    else
     55        Engine.PopGuiPage();
    4256}
  • binaries/data/mods/public/gui/aiconfig/aiconfig.xml

     
    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>
     
    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"/>
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    14991499                selection = noAssignment;
    15001500
    15011501            // 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             }
     1502            configButton.hidden = false;
     1503            configButton.onpress = function() {
     1504                Engine.PushGuiPage("page_aiconfig.xml", {
     1505                    "id": g_GameAttributes.settings.PlayerData[playerSlot].AI,
     1506                    "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff,
     1507                    "callback": g_IsController ? "AIConfigCallback" : "",
     1508                    "playerSlot": playerSlot // required by the callback function
     1509                });
     1510            };
    15141511        }
    15151512        // There was a human, so make sure we don't have any AI left
    15161513        // over in their slot, if we're in charge of the attributes