Ticket #3806: 3806_player_gamesetup_v1.2.patch

File 3806_player_gamesetup_v1.2.patch, 32.4 KB (added by Imarok, 8 years ago)

Removed SetNetworkGameAttributes as it is unneeded now, removed the TODO mentioned in the ticket description, extended initDropdowns and some cleanup

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

     
    1616    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;
     19    aiSelection.hidden = !settings.canBeChanged;
    2020
    2121    let aiSelectionText = Engine.GetGUIObjectByName("aiSelectionText");
    2222    aiSelectionText.caption = aiSelection.list[aiSelection.selected];
    23     aiSelectionText.hidden = settings.isController;
     23    aiSelectionText.hidden = settings.canBeChanged;
    2424
    2525    let aiDiff = Engine.GetGUIObjectByName("aiDifficulty");
    2626    aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title;
    2727    aiDiff.selected = settings.difficulty;
    28     aiDiff.hidden = !settings.isController;
     28    aiDiff.hidden = !settings.canBeChanged;
    2929
    3030    let aiDiffText = Engine.GetGUIObjectByName("aiDifficultyText");
    3131    aiDiffText.caption = aiDiff.list[aiDiff.selected];
    32     aiDiffText.hidden = settings.isController;
     32    aiDiffText.hidden = settings.canBeChanged;
    3333}
    3434
    3535function selectAI(idx)
  • binaries/data/mods/public/gui/common/settings.js

     
    3737        "MapTypes": loadMapTypes(),
    3838        "MapSizes": loadSettingValuesFile("map_sizes.json"),
    3939        "PlayerDefaults": loadPlayerDefaults(),
     40        "GuestSettings": loadSettingValuesFile("guest_settings.json"),
    4041        "PopulationCapacities": loadPopulationCapacities(),
    4142        "StartingResources": loadSettingValuesFile("starting_resources.json"),
    4243        "VictoryConditions": loadVictoryConditions()
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    55const g_GameSpeeds = prepareForDropdown(g_Settings && g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly));
    66const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes);
    77const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes);
     8const g_GuestSettings = prepareForDropdown(g_Settings && g_Settings.GuestSettings);
    89const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities);
    910const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources);
    1011const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions);
     
    146147 */
    147148const g_RandomCiv = '[color="' + g_ColorRandom + '"]' + translateWithContext("civilization", "Random") + '[/color]';
    148149
    149 // Is this is a networked game, or offline
     150// Is this a networked game, or offline
    150151var g_IsNetworked;
    151152
    152153// Is this user in control of game settings (i.e. is a network server, or offline player)
     
    249250{
    250251    Engine.GetGUIObjectByName("cancelGame").tooltip = Engine.HasXmppClient() ? translate("Return to the lobby.") : translate("Return to the main menu.");
    251252
    252     initCivNameList();
    253     initMapTypes();
    254     initMapFilters();
    255 
    256253    if (g_IsController)
    257254    {
    258255        // Unique ID to be used for identifying the same game reports for the lobby
     
    260257        g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked;
    261258        g_GameAttributes.settings.RatingEnabled = Engine.IsRankedGame() || undefined;
    262259
    263         initMapNameList();
    264         initNumberOfPlayers();
    265         initGameSpeed();
    266         initPopulationCaps();
    267         initStartingResources();
    268         initCeasefire();
    269         initWonderDurations();
    270         initVictoryConditions();
    271         initMapSizes();
    272         initRadioButtons();
     260        initDropdowns();
    273261    }
    274     else
    275         hideControls();
    276262
    277263    initMultiplayerSettings();
    278264    initPlayerAssignments();
     
    291277    }
    292278}
    293279
     280function initDropdowns()
     281{
     282    initCivNameList();
     283    initMapTypes();
     284    initMapFilters();
     285    initMapNameList();
     286    initNumberOfPlayers();
     287    initGameSpeed();
     288    initGuestSettings();
     289    initPopulationCaps();
     290    initStartingResources();
     291    initCeasefire();
     292    initWonderDurations();
     293    initVictoryConditions();
     294    initMapSizes();
     295    initRadioButtons();
     296}
     297
    294298function initMapTypes()
    295299{
    296300    let mapTypes = Engine.GetGUIObjectByName("mapType");
     
    331335        "optionPopulationCap",
    332336        "optionStartingResources",
    333337        "optionCeasefire",
     338        "optionGuestSettings",
    334339        "optionRevealMap",
    335340        "optionExploreMap",
    336341        "optionDisableTreasures",
     
    380385function initGameSpeed()
    381386{
    382387    let gameSpeed = Engine.GetGUIObjectByName("gameSpeed");
    383     gameSpeed.hidden = false;
    384     Engine.GetGUIObjectByName("gameSpeedText").hidden = true;
     388    gameSpeed.hidden = !canPlayerChange("gameSpeed");
     389    Engine.GetGUIObjectByName("gameSpeedText").hidden = canPlayerChange("gameSpeed");
    385390    gameSpeed.list = g_GameSpeeds.Title;
    386391    gameSpeed.list_data = g_GameSpeeds.Speed;
    387392    gameSpeed.onSelectionChange = function() {
     
    435440    };
    436441}
    437442
     443function initGuestSettings()
     444{
     445    let guestSettings = Engine.GetGUIObjectByName("guestSettings");
     446    guestSettings.list = g_GuestSettings.Title;
     447    guestSettings.list_data = g_GuestSettings.Data;
     448    if (guestSettings.selected == -1)
     449        guestSettings.selected = g_GuestSettings.Default;
     450    guestSettings.onSelectionChange = function() {
     451        if (this.selected != -1)
     452            g_GameAttributes.GuestSettings = g_GuestSettings.Data[this.selected];
     453
     454        updateGameAttributes();
     455    };
     456}
     457
    438458function initVictoryConditions()
    439459{
    440460    let victoryConditions = Engine.GetGUIObjectByName("victoryCondition");
     
    515535function hideControls()
    516536{
    517537    for (let ctrl of ["mapType", "mapFilter", "mapSelection", "victoryCondition", "gameSpeed", "numPlayers"])
    518         hideControl(ctrl, ctrl + "Text");
     538        hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl));
    519539
    520     // TODO: Shouldn't players be able to choose their own assignment?
    521540    for (let i = 0; i < g_MaxPlayers; ++i)
    522541    {
    523542        Engine.GetGUIObjectByName("playerAssignment["+i+"]").hidden = true;
     
    555574}
    556575
    557576/**
     577 * Returns if the player is allowed to change this setting
     578 */
     579function canPlayerChange(setting)
     580{
     581    if (g_GameAttributes.mapType == "scenario" &&
     582         ["victoryCondition", "wonderDuration", "populationCap",
     583         "startingResources", "ceasefire", "revealMap", "exploreMap",
     584         "disableTreasures", "lockTeams", "playerCiv", "playerTeam", "playerColor"].indexOf(setting) >= 0)
     585        return false;
     586
     587    if (g_GameAttributes.mapType != "random" && setting == "numPlayers")
     588        return false;
     589
     590    if (g_IsController)
     591        return true;
     592 
     593     if (setting == "guestSettings")
     594        return false;
     595
     596    if (g_GuestSettings.Data.indexOf(setting) == -1)
     597        return g_GameAttributes.GuestSettings == "all";
     598
     599    return g_GuestSettings.Data.indexOf(g_GameAttributes.GuestSettings) >= g_GuestSettings.Data.indexOf(setting);
     600}
     601
     602/**
    558603 * Hide and set some elements depending on whether we play single- or multiplayer.
    559604 */
    560605function initMultiplayerSettings()
     
    561606{
    562607    Engine.GetGUIObjectByName("chatPanel").hidden = !g_IsNetworked;
    563608    Engine.GetGUIObjectByName("optionCheats").hidden = !g_IsNetworked;
     609    Engine.GetGUIObjectByName("optionGuestSettings").hidden = !g_IsNetworked;
    564610    Engine.GetGUIObjectByName("optionRating").hidden = !Engine.HasXmppClient();
    565611
    566612    Engine.GetGUIObjectByName("enableCheats").enabled = !Engine.IsRankedGame();
     
    677723}
    678724
    679725/**
    680  * Called whenever the host changed any setting.
     726 * Called whenever someone changed any setting.
    681727 * @param {Object} message
    682728 */
    683729function handleGamesetupMessage(message)
     
    694740    }
    695741
    696742    Engine.SetRankedGame(!!g_GameAttributes.settings.RatingEnabled);
    697 
    698743    updateGUIObjects();
    699744}
    700745
     
    9951040        initGUIObjects();
    9961041        ++g_LoadingState;
    9971042    }
    998     else if (g_LoadingState == 2)
     1043    else if (g_LoadingState == 2 || g_LoadingState == 3)
    9991044    {
    10001045        while (true)
    10011046        {
     
    10061051            log("Net message: " + uneval(message));
    10071052
    10081053            if (g_NetMessageTypes[message.type])
     1054            {
    10091055                g_NetMessageTypes[message.type](message);
     1056                if (g_LoadingState == 2 && message.type == "gamesetup")
     1057                {
     1058                    ++g_LoadingState;
     1059                    initDropdowns();
     1060                    hideControls();
     1061                }
     1062            }
    10101063            else
    10111064                error("Unrecognised net message type " + message.type);
    10121065        }
     
    10221075function selectNumPlayers(num)
    10231076{
    10241077    // Avoid recursion
    1025     if (g_IsInGuiUpdate || !g_IsController || g_GameAttributes.mapType != "random")
     1078    if (g_IsInGuiUpdate || !canPlayerChange("numPlayers") || g_GameAttributes.mapType != "random")
    10261079        return;
    1027 
    10281080    // Unassign players from nonexistent slots
    10291081    if (g_IsNetworked)
    10301082    {
     
    10861138function selectMapType(type)
    10871139{
    10881140    // Avoid recursion
    1089     if (g_IsInGuiUpdate || !g_IsController)
     1141    if (g_IsInGuiUpdate)
    10901142        return;
    10911143
    10921144    if (!g_MapPath[type])
     
    11161168function selectMapFilter(id)
    11171169{
    11181170    // Avoid recursion
    1119     if (g_IsInGuiUpdate || !g_IsController)
     1171    if (g_IsInGuiUpdate)
    11201172        return;
    11211173
    11221174    g_GameAttributes.mapFilter = id;
     
    11301182function selectMap(name)
    11311183{
    11321184    // Avoid recursion
    1133     if (g_IsInGuiUpdate || !g_IsController || !name)
     1185    if (g_IsInGuiUpdate || !name)
    11341186        return;
    11351187
    11361188    // Reset some map specific properties which are not necessarily redefined on each map
     
    12621314
    12631315    if (g_IsNetworked)
    12641316    {
    1265         Engine.SetNetworkGameAttributes(g_GameAttributes);
     1317        Engine.NetworkChangeSettings(g_GameAttributes);
    12661318        Engine.StartNetworkGame();
    12671319    }
    12681320    else
     
    13011353    let mapFilterIdx = g_MapFilters.findIndex(mapFilter => mapFilter.id == (g_GameAttributes.mapFilter || "default"));
    13021354    let mapTypeIdx = g_GameAttributes.mapType !== undefined ? g_MapTypes.Name.indexOf(g_GameAttributes.mapType) : g_MapTypes.Default;
    13031355    let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default;
     1356    let guestSettingsIdx = g_GameAttributes.GuestSettings !== undefined ? g_GuestSettings.Data.indexOf(g_GameAttributes.GuestSettings) : g_GuestSettings.Default;
    13041357
    13051358    // These dropdowns might set the default (as they ignore g_IsInGuiUpdate)
    13061359    let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default;
     
    13111364    let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
    13121365    let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers;
    13131366
    1314     if (g_IsController)
    1315     {
    1316         Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx;
    1317         Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx;
    1318         Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName);
    1319         Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx;
    1320         Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1;
    1321         Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
    1322         Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
    1323         Engine.GetGUIObjectByName("populationCap").selected = popIdx;
    1324         Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
    1325         Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
    1326         Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
    1327     }
    1328     else
    1329     {
    1330         Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx];
    1331         Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name;
    1332         Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName));
    1333         initMapNameList();
    1334     }
     1367    Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx;
     1368    Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx;
     1369    Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName);
     1370    Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx;
     1371    Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1;
     1372    Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
     1373    Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
     1374    Engine.GetGUIObjectByName("populationCap").selected = popIdx;
     1375    Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
     1376    Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
     1377    Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
     1378    Engine.GetGUIObjectByName("guestSettings").selected = guestSettingsIdx;
    13351379
     1380
     1381    initMapNameList();
     1382
    13361383    // Can be visible to both host and clients
    13371384    Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default");
    13381385    Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers;
    13391386    Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx];
    13401387    Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx];
     1388    Engine.GetGUIObjectByName("guestSettingsText").caption = g_GuestSettings.Title[guestSettingsIdx];
    13411389    Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx];
    13421390    Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx];
    13431391    Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx];
    13441392    Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx];
     1393    Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx];
     1394    Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name;
     1395    Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName));
    13451396
    13461397    setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled);
    13471398    setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures);
     
    13641415    Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom;
    13651416    Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController;
    13661417    Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController;
    1367     hideControl("numPlayers", "numPlayersText", isRandom && g_IsController);
    13681418
    1369     let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
    1370 
    13711419    for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap",
    13721420                      "startingResources", "ceasefire", "revealMap",
    1373                       "exploreMap", "disableTreasures", "lockTeams"])
    1374         hideControl(ctrl, ctrl + "Text", notScenario);
     1421                      "exploreMap", "disableTreasures", "lockTeams",
     1422                      "gameSpeed", "guestSettings", "enableCheats",
     1423                      "mapSelection", "numPlayers", "mapType", "mapFilter"])
     1424        hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl));
    13751425
     1426    let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
     1427
    13761428    setMapDescription();
    13771429
    13781430    for (let i = 0; i < g_MaxPlayers; ++i)
     
    14081460        pCiv.selected = civ ? pCiv.list_data.indexOf(civ) : 0;
    14091461        pTeam.selected = team !== undefined && team >= 0 ? team+1 : 0;
    14101462
    1411         hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", g_IsController);
    1412         hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", notScenario);
    1413         hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", notScenario);
     1463        hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", canPlayerChange("playerAssignment"));
     1464        hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", canPlayerChange("playerCiv"));
     1465        hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", canPlayerChange("playerTeam"));
    14141466
    14151467        // Allow host to chose player colors on non-scenario maps
    14161468        let pColorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]");
    14171469        let pColorPickerHeading = Engine.GetGUIObjectByName("playerColorHeading");
    1418         let canChangeColors = g_IsController && g_GameAttributes.mapType != "scenario";
    1419         pColorPicker.hidden = !canChangeColors;
    1420         pColorPickerHeading.hidden = !canChangeColors;
    1421         if (canChangeColors)
     1470        pColorPicker.hidden = !canPlayerChange("playerColor");
     1471        pColorPickerHeading.hidden = !canPlayerChange("playerColor");
     1472        if (canPlayerChange("playerColor"))
    14221473            pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color));
    14231474    }
    14241475
     
    14851536 */
    14861537function updateGameAttributes()
    14871538{
    1488     if (g_IsInGuiUpdate || !g_IsController)
     1539    if (g_IsInGuiUpdate)
    14891540        return;
    14901541
    14911542    if (g_IsNetworked)
    14921543    {
    1493         Engine.SetNetworkGameAttributes(g_GameAttributes);
     1544        Engine.NetworkChangeSettings(g_GameAttributes);
    14941545        if (g_LoadingState >= 2)
    14951546            sendRegisterGameStanza();
    14961547    }
     
    15041555
    15051556    Engine.PushGuiPage("page_aiconfig.xml", {
    15061557        "callback": "AIConfigCallback",
    1507         "isController": g_IsController,
     1558        "canBeChanged": canPlayerChange("playerConfig"),
    15081559        "playerSlot": playerSlot,
    15091560        "id": g_GameAttributes.settings.PlayerData[playerSlot].AI,
    15101561        "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff
     
    15181569{
    15191570    g_LastViewedAIPlayer = -1;
    15201571
    1521     if (!ai.save || !g_IsController)
     1572    if (!ai.save)
    15221573        return;
    15231574
    15241575    g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id;
     
    15251576    g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty;
    15261577
    15271578    if (g_IsNetworked)
    1528         Engine.SetNetworkGameAttributes(g_GameAttributes);
     1579        Engine.NetworkChangeSettings(g_GameAttributes);
    15291580    else
    15301581        updatePlayerList();
    15311582}
     
    16211672        {
    16221673            g_GameAttributes.settings.PlayerData[playerSlot].AI = "";
    16231674            if (g_IsNetworked)
    1624                 Engine.SetNetworkGameAttributes(g_GameAttributes);
     1675                Engine.NetworkChangeSettings(g_GameAttributes);
    16251676        }
    16261677
    16271678        let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]");
     
    16321683            assignBox.selected = selection;
    16331684        assignBoxText.caption = hostNameList[selection];
    16341685
    1635         if (g_IsController)
    1636             assignBox.onselectionchange = function() {
    1637                 if (g_IsInGuiUpdate)
    1638                     return;
     1686        assignBox.onSelectionChange = function() {
     1687            if (g_IsInGuiUpdate)
     1688                return;
    16391689
    1640                 let guid = hostGuidList[this.selected];
    1641                 if (!guid)
    1642                 {
    1643                     if (g_IsNetworked)
    1644                         // Unassign any host from this player slot
    1645                         Engine.AssignNetworkPlayer(playerID, "");
    1646                     // Remove AI from this player slot
    1647                     g_GameAttributes.settings.PlayerData[playerSlot].AI = "";
    1648                 }
    1649                 else if (guid.substr(0, 3) == "ai:")
    1650                 {
    1651                     if (g_IsNetworked)
    1652                         // Unassign any host from this player slot
    1653                         Engine.AssignNetworkPlayer(playerID, "");
    1654                     // Set the AI for this player slot
    1655                     g_GameAttributes.settings.PlayerData[playerSlot].AI = guid.substr(3);
    1656                 }
    1657                 else
    1658                     swapPlayers(guid, playerSlot);
     1690            let guid = hostGuidList[this.selected];
     1691            if (!guid)
     1692            {
     1693                if (g_IsNetworked)
     1694                    // Unassign any host from this player slot
     1695                    Engine.AssignNetworkPlayer(playerID, "");
     1696                // Remove AI from this player slot
     1697                g_GameAttributes.settings.PlayerData[playerSlot].AI = "";
     1698            }
     1699            else if (guid.substr(0, 3) == "ai:")
     1700            {
     1701                if (g_IsNetworked)
     1702                    // Unassign any host from this player slot
     1703                    Engine.AssignNetworkPlayer(playerID, "");
     1704                // Set the AI for this player slot
     1705                g_GameAttributes.settings.PlayerData[playerSlot].AI = guid.substr(3);
     1706            }
     1707            else
     1708                swapPlayers(guid, playerSlot);
    16591709
    1660                 if (g_IsNetworked)
    1661                     Engine.SetNetworkGameAttributes(g_GameAttributes);
    1662                 else
    1663                     updatePlayerList();
    1664                 updateReadyUI();
    1665             };
     1710            if (g_IsNetworked)
     1711                Engine.NetworkChangeSettings(g_GameAttributes);
     1712            else
     1713                updatePlayerList();
     1714            updateReadyUI();
     1715        };
    16661716    }
    16671717
    16681718    g_IsInGuiUpdate = false;
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    8080                            <object name="playerAssignment[n]" type="dropdown" style="ModernDropDown" size="22%+37 2 50%+35 30" tooltip_style="onscreenToolTip">
    8181                                <translatableAttribute id="tooltip">Select player.</translatableAttribute>
    8282                            </object>
    83                             <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+5 0 50%+35 30"/>
     83                            <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+33 0 50%+35 30"/>
    8484                            <object name="playerConfig[n]" type="button" style="StoneButton" size="50%+40 4 50%+64 28"
    8585                                tooltip_style="onscreenToolTip"
    8686                                font="sans-bold-stroke-12"
     
    250250                <translatableAttribute id="caption">Back</translatableAttribute>
    251251                <action on="Press">cancelSetup();</action>
    252252            </object>
    253 
     253 
    254254            <!-- Options -->
    255255            <object name="gameOptionsBox" size="100%-425 529 100%-25 525">
    256256                <!-- More Options Button -->
     
    336336                    </object>
    337337                </object>
    338338
     339                <object name="optionGuestSettings" size="14 188 94% 206">
     340                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     341                        <translatableAttribute id="caption">Guest Settings:</translatableAttribute>
     342                    </object>
     343                    <object name="guestSettingsText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     344                    <object name="guestSettings" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
     345                        <translatableAttribute id="tooltip">Set which settings can be changed by every player.</translatableAttribute>
     346                    </object>
     347                </object>
     348
    339349                <object name="optionRevealMap" size="14 218 94% 246">
    340350                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    341351                        <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute>
  • binaries/data/mods/public/simulation/data/settings/guest_settings.json

     
     1{
     2    "TranslatedKeys": ["Title"],
     3    "TranslationContext": "players can change",
     4    "Data":
     5    [
     6        {
     7            "Title": "None",
     8            "Data": "none"
     9        },
     10        {
     11            "Title": "Color",
     12            "Data": "playerColor",
     13            "Default": true
     14        },
     15        {
     16            "Title": "Color & Civilization",
     17            "Data": "playerCiv"
     18        },
     19        {
     20            "Title": "Color, Civilization & Team",
     21            "Data": "playerTeam"
     22        },
     23        {
     24            "Title": "All",
     25            "Data": "all"
     26        }
     27    ]
     28}
  • source/gui/scripting/ScriptFunctions.cpp

     
    332332        LOGERROR("Failed to save game");
    333333}
    334334
    335 void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)
     335void NetworkChangeSettings(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)
    336336{
    337     ENSURE(g_NetServer);
     337    ENSURE(g_NetClient);
    338338    //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere
    339339    // (with no obvious reason).
    340340    JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
     
    341341    JSAutoRequest rq(cx);
    342342    JS::RootedValue attribs(cx, attribs1);
    343343
    344     g_NetServer->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface));
     344    g_NetClient->SendChangeSettingsMessage(&attribs, *(pCxPrivate->pScriptInterface));
    345345}
    346346
    347347void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName)
     
    427427
    428428void AssignNetworkPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int playerID, const std::string& guid)
    429429{
    430     ENSURE(g_NetServer);
     430    ENSURE(g_NetClient);
    431431
    432     g_NetServer->AssignPlayer(playerID, guid);
     432    g_NetClient->SendAssignPlayerMessage(playerID, guid);
    433433}
    434434
    435435void SetNetworkPlayerStatus(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& guid, int ready)
     
    10481048    scriptInterface.RegisterFunction<std::string, &GetPlayerGUID>("GetPlayerGUID");
    10491049    scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer");
    10501050    scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient");
    1051     scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes");
     1051    scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkChangeSettings>("NetworkChangeSettings");
    10521052    scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer");
    10531053    scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus");
    10541054    scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady");
  • source/network/NetClient.cpp

     
    321321    SetCurrState(NCS_UNCONNECTED);
    322322}
    323323
     324void CNetClient::SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface)
     325{
     326    // Pass the attributes as JSON, since that's the easiest safe
     327    // cross-thread way of passing script data
     328    std::string attrsJSON = scriptInterface.StringifyJSON(attrs, false);
     329    CChangeSettingsMessage changeSetting;
     330    changeSetting.m_Settings = attrsJSON;
     331    SendMessage(&changeSetting);
     332}
     333
     334void CNetClient::SendAssignPlayerMessage(const int playerID, const std::string guid)
     335{
     336    CAssignPlayerMessage assignPlayer;
     337    assignPlayer.m_PlayerID = playerID;
     338    assignPlayer.m_GUIDToAssign = guid;
     339    SendMessage(&assignPlayer);
     340}
     341
    324342void CNetClient::SendChatMessage(const std::wstring& text)
    325343{
    326344    CChatMessage chat;
  • source/network/NetClient.h

     
    187187     */
    188188    void LoadFinished();
    189189
     190    void SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface);
     191
     192    void SendAssignPlayerMessage(const int playerID, const std::string guid);
     193
    190194    void SendChatMessage(const std::wstring& text);
    191195
    192196    void SendReadyMessage(const int status);
  • source/network/NetMessage.cpp

     
    199199        pNewMessage = new CSimulationMessage(scriptInterface);
    200200        break;
    201201
     202    case NMT_CHANGE_SETTINGS:
     203        pNewMessage = new CChangeSettingsMessage;
     204        break;
     205    case NMT_ASSIGN_PLAYER:
     206        pNewMessage = new CAssignPlayerMessage;
     207        break;
     208
    202209    default:
    203210        LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType());
    204211        break;
  • source/network/NetMessages.h

     
    4545    NMT_SERVER_HANDSHAKE_RESPONSE,
    4646    NMT_AUTHENTICATE,       // Authentication stage
    4747    NMT_AUTHENTICATE_RESULT,
    48     NMT_CHAT,       // Common chat message
     48    NMT_CHAT,               // Common chat message
    4949    NMT_READY,
    5050    NMT_GAME_SETUP,
    5151    NMT_PLAYER_ASSIGNMENT,
     
    6666    NMT_LOADED_GAME,
    6767    NMT_GAME_START,
    6868    NMT_END_COMMAND_BATCH,
    69     NMT_SYNC_CHECK, // OOS-detection hash checking
    70     NMT_SYNC_ERROR, // OOS-detection error
     69    NMT_SYNC_CHECK,         // OOS-detection hash checking
     70    NMT_SYNC_ERROR,         // OOS-detection error
    7171    NMT_SIMULATION_COMMAND,
     72    NMT_CHANGE_SETTINGS,    // User changes a setting in gamesetup
     73    NMT_ASSIGN_PLAYER,
    7274    NMT_LAST                // Last message in the list
    7375};
    7476
     
    109111END_NMT_CLASS()
    110112
    111113START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE)
    112     NMT_FIELD(CStr8, m_GUID)
     114    NMT_FIELD(CStr, m_GUID)
    113115    NMT_FIELD(CStrW, m_Name)
    114116    NMT_FIELD(CStrW, m_Password)
    115117    NMT_FIELD_INT(m_IsLocalClient, u8, 1)
     
    122124END_NMT_CLASS()
    123125
    124126START_NMT_CLASS_(Chat, NMT_CHAT)
    125     NMT_FIELD(CStr8, m_GUID) // ignored when client->server, valid when server->client
     127    NMT_FIELD(CStr, m_GUID) // ignored when client->server, valid when server->client
    126128    NMT_FIELD(CStrW, m_Message)
    127129END_NMT_CLASS()
    128130
    129131START_NMT_CLASS_(Ready, NMT_READY)
    130     NMT_FIELD(CStr8, m_GUID)
     132    NMT_FIELD(CStr, m_GUID)
    131133    NMT_FIELD_INT(m_Status, u8, 1)
    132134END_NMT_CLASS()
    133135
    134136START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT)
    135137    NMT_START_ARRAY(m_Hosts)
    136         NMT_FIELD(CStr8, m_GUID)
     138        NMT_FIELD(CStr, m_GUID)
    137139        NMT_FIELD(CStrW, m_Name)
    138140        NMT_FIELD_INT(m_PlayerID, i8, 1)
    139141        NMT_FIELD_INT(m_Status, u8, 1)
     
    151153
    152154START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA)
    153155    NMT_FIELD_INT(m_RequestID, u32, 4)
    154     NMT_FIELD(CStr8, m_Data)
     156    NMT_FIELD(CStr, m_Data)
    155157END_NMT_CLASS()
    156158
    157159START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK)
     
    163165END_NMT_CLASS()
    164166
    165167START_NMT_CLASS_(Rejoined, NMT_REJOINED)
    166     NMT_FIELD(CStr8, m_GUID)
     168    NMT_FIELD(CStr, m_GUID)
    167169END_NMT_CLASS()
    168170
    169171START_NMT_CLASS_(Kicked, NMT_KICKED)
     
    172174END_NMT_CLASS()
    173175
    174176START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT)
    175     NMT_FIELD(CStr8, m_GUID)
     177    NMT_FIELD(CStr, m_GUID)
    176178    NMT_FIELD_INT(m_LastReceivedTime, u32, 4)
    177179END_NMT_CLASS()
    178180
    179181START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE)
    180182    NMT_START_ARRAY(m_Clients)
    181         NMT_FIELD(CStr8, m_GUID)
     183        NMT_FIELD(CStr, m_GUID)
    182184        NMT_FIELD_INT(m_MeanRTT, u32, 4)
    183185    NMT_END_ARRAY()
    184186END_NMT_CLASS()
     
    208210    NMT_END_ARRAY()
    209211END_NMT_CLASS()
    210212
     213START_NMT_CLASS_(ChangeSettings, NMT_CHANGE_SETTINGS)
     214    NMT_FIELD(CStr, m_GUID)
     215    NMT_FIELD(CStr, m_Settings)
     216END_NMT_CLASS()
     217
     218START_NMT_CLASS_(AssignPlayer, NMT_ASSIGN_PLAYER)
     219    NMT_FIELD_INT(m_PlayerID, i8, 1)
     220    NMT_FIELD(CStr, m_GUIDToAssign)
     221END_NMT_CLASS()
     222
    211223END_NMTS()
    212224
    213225#else
  • source/network/NetServer.cpp

     
    649649    session->AddTransition(NSS_PREGAME, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
    650650    session->AddTransition(NSS_PREGAME, (uint)NMT_CHAT, NSS_PREGAME, (void*)&OnChat, context);
    651651    session->AddTransition(NSS_PREGAME, (uint)NMT_READY, NSS_PREGAME, (void*)&OnReady, context);
     652    session->AddTransition(NSS_PREGAME, (uint)NMT_CHANGE_SETTINGS, NSS_PREGAME, (void*)&OnChangeSettings, context);
     653    session->AddTransition(NSS_PREGAME, (uint)NMT_ASSIGN_PLAYER, NSS_PREGAME, (void*)&OnAssignPlayer, context);
    652654    session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context);
    653655
    654656    session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
     
    11061108    return true;
    11071109}
    11081110
     1111bool CNetServerWorker::OnChangeSettings(void* context, CFsmEvent* event)
     1112{
     1113    ENSURE(event->GetType() == (uint)NMT_CHANGE_SETTINGS);
     1114    CNetServerSession* session = (CNetServerSession*)context;
     1115    CNetServerWorker& server = session->GetServer();
     1116
     1117    CChangeSettingsMessage* message = (CChangeSettingsMessage*)event->GetParamRef();
     1118    server.m_GameAttributesQueue.push_back(message->m_Settings);
     1119    return true;
     1120}
     1121
     1122bool CNetServerWorker::OnAssignPlayer(void* context, CFsmEvent* event)
     1123{
     1124    ENSURE(event->GetType() == (uint)NMT_ASSIGN_PLAYER);
     1125    CNetServerSession* session = (CNetServerSession*)context;
     1126    CNetServerWorker& server = session->GetServer();
     1127
     1128    CAssignPlayerMessage* message = (CAssignPlayerMessage*)event->GetParamRef();
     1129    server.m_AssignPlayerQueue.emplace_back(message->m_PlayerID, message->m_GUIDToAssign);
     1130    return true;
     1131}
     1132
    11091133bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event)
    11101134{
    11111135    ENSURE(event->GetType() == (uint)NMT_LOADED_GAME);
  • source/network/NetServer.h

     
    270270    static bool OnInGame(void* context, CFsmEvent* event);
    271271    static bool OnChat(void* context, CFsmEvent* event);
    272272    static bool OnReady(void* context, CFsmEvent* event);
     273    static bool OnChangeSettings(void* context, CFsmEvent* event);
     274    static bool OnAssignPlayer(void* context, CFsmEvent* event);
    273275    static bool OnLoadedGame(void* context, CFsmEvent* event);
    274276    static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event);
    275277    static bool OnRejoined(void* context, CFsmEvent* event);