Ticket #3806: 3806_player_gamesetup_v0.5.patch

File 3806_player_gamesetup_v0.5.patch, 16.8 KB (added by Imarok, 8 years ago)

WIP Patch: already implemented a test button to set the revealMap setting to false, that can be used by every player

  • binaries/data/mods/public/gui/common/settings.js

     
    3737        "MapTypes": loadMapTypes(),
    3838        "MapSizes": loadSettingValuesFile("map_sizes.json"),
    3939        "PlayerDefaults": loadPlayerDefaults(),
     40        "PlayersCanChange": loadSettingValuesFile("players_can_change.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_PlayersCanChange = prepareForDropdown(g_Settings && g_Settings.PlayersCanChange); //["None", "Color", "Civilization","Team", "All"];
    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);
     
    251252        initMapNameList();
    252253        initNumberOfPlayers();
    253254        initGameSpeed();
     255        initPlayersCanChange();
    254256        initPopulationCaps();
    255257        initStartingResources();
    256258        initCeasefire();
     
    319321        "optionPopulationCap",
    320322        "optionStartingResources",
    321323        "optionCeasefire",
     324        "optionPlayersCanChange",
    322325        "optionRevealMap",
    323326        "optionExploreMap",
    324327        "optionDisableTreasures",
     
    423426    };
    424427}
    425428
     429function initPlayersCanChange()
     430{
     431    let playersCanChange = Engine.GetGUIObjectByName("playersCanChange");
     432    playersCanChange.list = g_PlayersCanChange.Title;
     433    playersCanChange.list_data = g_PlayersCanChange.Data;
     434    playersCanChange.selected = g_PlayersCanChange.Default;
     435    playersCanChange.onSelectionChange = function() {
     436        if (this.selected != -1)
     437            g_GameAttributes.settings.PlayersCanChange = g_PlayersCanChange.Data[this.selected];
     438
     439        updateGameAttributes();
     440    };
     441}
     442
    426443function initVictoryConditions()
    427444{
    428445    let victoryConditions = Engine.GetGUIObjectByName("victoryCondition");
     
    13001317    let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default;
    13011318    let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
    13021319    let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers;
     1320    let playersCanChangeIdx = mapSettings.PlayersCanChange !== undefined ? g_PlayersCanChange.Data.indexOf(mapSettings.PlayersCanChange) : g_PlayersCanChange.Default;
    13031321
     1322
    13041323    if (g_IsController)
    13051324    {
    13061325        Engine.GetGUIObjectByName("mapTypeSelection").selected = mapTypeIdx;
     
    13101329        Engine.GetGUIObjectByName("numPlayersSelection").selected = numPlayers - 1;
    13111330        Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
    13121331        Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
     1332        Engine.GetGUIObjectByName("playersCanChange").selected = playersCanChangeIdx;
    13131333        Engine.GetGUIObjectByName("populationCap").selected = popIdx;
    13141334        Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
    13151335        Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
     
    13281348    Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers;
    13291349    Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx];
    13301350    Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx];
     1351    Engine.GetGUIObjectByName("playersCanChangeText").caption = g_PlayersCanChange.Title[playersCanChangeIdx];
    13311352    Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx];
    13321353    Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx];
    13331354    Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx];
     
    13671388    hideControl("disableTreasures", "disableTreasuresText", notScenario);
    13681389    hideControl("lockTeams", "lockTeamsText", notScenario);
    13691390
     1391    hideControl("playersCanChange", "playersCanChangeText");
     1392
    13701393    setMapDescription();
    13711394
    13721395    for (let i = 0; i < g_MaxPlayers; ++i)
     
    14791502 */
    14801503function updateGameAttributes()
    14811504{
    1482     if (g_IsInGuiUpdate || !g_IsController)
     1505    if (g_IsInGuiUpdate )//|| !g_IsController)TODO
    14831506        return;
    14841507
    14851508    if (g_IsNetworked)
    14861509    {
    1487         Engine.SetNetworkGameAttributes(g_GameAttributes);
     1510        Engine.NetworkChangeSettings(g_GameAttributes);
    14881511        if (g_LoadingState >= 2)
    14891512            sendRegisterGameStanza();
    14901513    }
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    250250                <translatableAttribute id="caption">Back</translatableAttribute>
    251251                <action on="Press">cancelSetup();</action>
    252252            </object>
     253           
     254            <object
     255                name="testButton"
     256                type="button"
     257                style="StoneButton"
     258                size="100%-500 100%-52 100%-400 100%-24"
     259                tooltip_style="onscreenToolTip"
     260            >
     261                <translatableAttribute id="caption">Test</translatableAttribute>
     262                <action on="Press">warn("test: " + g_GameAttributes.settings.RevealMap);
     263                g_GameAttributes.settings.RevealMap = false;
     264                updateGameAttributes();
     265                warn("after: " + g_GameAttributes.settings.RevealMap)
     266                </action>
     267            </object>
    253268
    254269            <!-- Options -->
    255270            <object name="gameOptionsBox" size="100%-425 529 100%-25 525">
     
    336351                    </object>
    337352                </object>
    338353
     354                <object name="optionPlayersCanChange" size="14 188 94% 206">
     355                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     356                        <translatableAttribute id="caption">Players can change:</translatableAttribute>
     357                    </object>
     358                    <object name="playersCanChangeText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     359                    <object name="playersCanChange" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
     360                        <translatableAttribute id="tooltip">Set which settings can be changed by every player.</translatableAttribute>
     361                    </object>
     362                </object>
     363
    339364                <object name="optionRevealMap" size="14 218 94% 246">
    340365                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    341366                        <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/players_can_change.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": "color",
     13            "Default": true
     14        },
     15        {
     16            "Title": "Color & Civilization",
     17            "Data": "civ"
     18        },
     19        {
     20            "Title": "Color & Civilization & Team",
     21            "Data": "team"
     22        },
     23        {
     24            "Title": "All",
     25            "Data": "all"
     26        }
     27    ]
     28}
  • source/gui/scripting/ScriptFunctions.cpp

     
    344344    g_NetServer->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface));
    345345}
    346346
     347void NetworkChangeSettings(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)
     348{
     349    ENSURE(g_NetClient);
     350    //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere
     351    // (with no obvious reason).
     352    JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
     353    JSAutoRequest rq(cx);
     354    JS::RootedValue attribs(cx, attribs1);
     355
     356    g_NetClient->SendChangeSettingsMessage(&attribs, *(pCxPrivate->pScriptInterface));
     357}
     358
    347359void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName)
    348360{
    349361    ENSURE(!g_NetClient);
     
    10431055    scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer");
    10441056    scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient");
    10451057    scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes");
     1058    scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkChangeSettings>("NetworkChangeSettings");
    10461059    scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer");
    10471060    scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus");
    10481061    scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady");
  • source/network/NetClient.cpp

     
    320320    SetCurrState(NCS_UNCONNECTED);
    321321}
    322322
     323void CNetClient::SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface)
     324{
     325    // Pass the attributes as JSON, since that's the easiest safe
     326    // cross-thread way of passing script data
     327    std::string attrsJSON = scriptInterface.StringifyJSON(attrs, false);
     328    CChangeSettingsMessage changeSetting;
     329    changeSetting.m_Settings = attrsJSON;
     330    SendMessage(&changeSetting);
     331   
     332    /*const CStr& setting, const CStr& value)
     333{
     334    CChangeSettingsMessage changeSetting;
     335    changeSetting.m_Setting = setting;
     336    changeSetting.m_Value = value;
     337    SendMessage(&changeSetting);*/
     338}
     339
    323340void CNetClient::SendChatMessage(const std::wstring& text)
    324341{
    325342    CChatMessage chat;
  • source/network/NetClient.h

     
    187187     */
    188188    void LoadFinished();
    189189
     190    void SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface);
     191
    190192    void SendChatMessage(const std::wstring& text);
    191193
    192194    void SendReadyMessage(const int status);
  • source/network/NetMessage.cpp

     
    198198    case NMT_SIMULATION_COMMAND:
    199199        pNewMessage = new CSimulationMessage(scriptInterface);
    200200        break;
     201    case NMT_CHANGE_SETTINGS:
     202        pNewMessage = new CChangeSettingsMessage;
     203        break;
    201204
    202205    default:
    203206        LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType());
  • 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
    7273    NMT_LAST                // Last message in the list
    7374};
    7475
     
    109110END_NMT_CLASS()
    110111
    111112START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE)
    112     NMT_FIELD(CStr8, m_GUID)
     113    NMT_FIELD(CStr, m_GUID)
    113114    NMT_FIELD(CStrW, m_Name)
    114115    NMT_FIELD(CStrW, m_Password)
    115116END_NMT_CLASS()
     
    121122END_NMT_CLASS()
    122123
    123124START_NMT_CLASS_(Chat, NMT_CHAT)
    124     NMT_FIELD(CStr8, m_GUID) // ignored when client->server, valid when server->client
     125    NMT_FIELD(CStr, m_GUID) // ignored when client->server, valid when server->client
    125126    NMT_FIELD(CStrW, m_Message)
    126127END_NMT_CLASS()
    127128
    128129START_NMT_CLASS_(Ready, NMT_READY)
    129     NMT_FIELD(CStr8, m_GUID)
     130    NMT_FIELD(CStr, m_GUID)
    130131    NMT_FIELD_INT(m_Status, u8, 1)
    131132END_NMT_CLASS()
    132133
    133134START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT)
    134135    NMT_START_ARRAY(m_Hosts)
    135         NMT_FIELD(CStr8, m_GUID)
     136        NMT_FIELD(CStr, m_GUID)
    136137        NMT_FIELD(CStrW, m_Name)
    137138        NMT_FIELD_INT(m_PlayerID, i8, 1)
    138139        NMT_FIELD_INT(m_Status, u8, 1)
     
    150151
    151152START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA)
    152153    NMT_FIELD_INT(m_RequestID, u32, 4)
    153     NMT_FIELD(CStr8, m_Data)
     154    NMT_FIELD(CStr, m_Data)
    154155END_NMT_CLASS()
    155156
    156157START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK)
     
    162163END_NMT_CLASS()
    163164
    164165START_NMT_CLASS_(Rejoined, NMT_REJOINED)
    165     NMT_FIELD(CStr8, m_GUID)
     166    NMT_FIELD(CStr, m_GUID)
    166167END_NMT_CLASS()
    167168
    168169START_NMT_CLASS_(Kicked, NMT_KICKED)
     
    171172END_NMT_CLASS()
    172173
    173174START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT)
    174     NMT_FIELD(CStr8, m_GUID)
     175    NMT_FIELD(CStr, m_GUID)
    175176    NMT_FIELD_INT(m_LastReceivedTime, u32, 4)
    176177END_NMT_CLASS()
    177178
    178179START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE)
    179180    NMT_START_ARRAY(m_Clients)
    180         NMT_FIELD(CStr8, m_GUID)
     181        NMT_FIELD(CStr, m_GUID)
    181182        NMT_FIELD_INT(m_MeanRTT, u32, 4)
    182183    NMT_END_ARRAY()
    183184END_NMT_CLASS()
     
    207208    NMT_END_ARRAY()
    208209END_NMT_CLASS()
    209210
     211START_NMT_CLASS_(ChangeSettings, NMT_CHANGE_SETTINGS)
     212    NMT_FIELD(CStr, m_GUID)
     213    NMT_FIELD(CStr, m_Settings)
     214END_NMT_CLASS()
     215
    210216END_NMTS()
    211217
    212218#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);
    652653    session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context);
    653654
    654655    session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
     
    11051106    return true;
    11061107}
    11071108
     1109bool CNetServerWorker::OnChangeSettings(void* context, CFsmEvent* event)
     1110{
     1111    ENSURE(event->GetType() == (uint)NMT_CHANGE_SETTINGS);
     1112    CNetServerSession* session = (CNetServerSession*)context;
     1113    CNetServerWorker& server = session->GetServer();
     1114
     1115    CChangeSettingsMessage* message = (CChangeSettingsMessage*)event->GetParamRef();
     1116    server.m_GameAttributesQueue.push_back(message->m_Settings);
     1117    return true;
     1118    /*JS::RootedValue gameAttributesVal(cx);
     1119    GetScriptInterface().ParseJSON(newGameAttributes.back(), &gameAttributesVal);
     1120    UpdateGameAttributes(&gameAttributesVal);*/
     1121
     1122    //UpdateGameAttributes(&(message->m_Settings));
     1123
     1124    /*
     1125    message->m_GUID = session->GetGUID();
     1126    PushGuiMessage??
     1127    server.SendMessage(m_Host, message);*/
     1128
     1129}
     1130
    11081131bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event)
    11091132{
    11101133    ENSURE(event->GetType() == (uint)NMT_LOADED_GAME);
  • source/network/NetServer.h

     
    188188    bool SendMessage(ENetPeer* peer, const CNetMessage* message);
    189189
    190190    /**
     191     * Send message to the host
     192    */
     193    bool SendMessageToHost(const CNetMessage* message);
     194
     195    /**
    191196     * Disconnects a player from gamesetup or session.
    192197     */
    193198    bool KickPlayer(const CStrW& playerName, const bool ban);
     
    270275    static bool OnInGame(void* context, CFsmEvent* event);
    271276    static bool OnChat(void* context, CFsmEvent* event);
    272277    static bool OnReady(void* context, CFsmEvent* event);
     278    static bool OnChangeSettings(void* context, CFsmEvent* event);
    273279    static bool OnLoadedGame(void* context, CFsmEvent* event);
    274280    static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event);
    275281    static bool OnRejoined(void* context, CFsmEvent* event);