Ticket #3911: visible_ai_setting_v1.1.patch

File visible_ai_setting_v1.1.patch, 4.7 KB (added by Imarok, 8 years ago)

cleanup

  • 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
    16     var aiSelection = Engine.GetGUIObjectByName("aiSelection");
     18    let aiSelection = Engine.GetGUIObjectByName("aiSelection");
    1719    aiSelection.list = g_AIDescriptions.map(ai => ai.data.name);
    1820    aiSelection.selected = g_AIDescriptions.findIndex(ai => ai.id == settings.id);
     21    aiSelection.hidden = !g_IsController;
    1922
    20     var aiDiff = Engine.GetGUIObjectByName("aiDifficulty");
     23    let aiSelectionText = Engine.GetGUIObjectByName("aiSelectionText");
     24    aiSelectionText.caption = aiSelection.list[aiSelection.selected];
     25    aiSelectionText.hidden = g_IsController;
     26
     27    let aiDiff = Engine.GetGUIObjectByName("aiDifficulty");
    2128    aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title;
    2229    aiDiff.selected = settings.difficulty;
     30    aiDiff.hidden = !g_IsController;
     31
     32    let aiDiffText = Engine.GetGUIObjectByName("aiDifficultyText");
     33    aiDiffText.caption = aiDiff.list[aiDiff.selected];
     34    aiDiffText.hidden = g_IsController;
    2335}
    2436
    2537function selectAI(idx)
     
    2941
    3042function returnAI()
    3143{
    32     var idx = Engine.GetGUIObjectByName("aiSelection").selected;
     44    let idx = Engine.GetGUIObjectByName("aiSelection").selected;
    3345
    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     });
     46    if (g_IsController)
     47        // Pop the page before calling the callback, so the callback runs
     48        // in the parent GUI page's context
     49        Engine.PopGuiPageCB({
     50            "id": g_AIDescriptions[idx].id,
     51            "name": g_AIDescriptions[idx].data.name,
     52            "difficulty": Engine.GetGUIObjectByName("aiDifficulty").selected,
     53            "playerSlot": g_PlayerSlot
     54        });
     55    else
     56        Engine.PopGuiPage();
    4257}
  • 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