Ticket #3806: 3806_player_gamesetup_v0.6.patch
File 3806_player_gamesetup_v0.6.patch, 17.8 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/common/settings.js
37 37 "MapTypes": loadMapTypes(), 38 38 "MapSizes": loadSettingValuesFile("map_sizes.json"), 39 39 "PlayerDefaults": loadPlayerDefaults(), 40 "GuestSettings": loadSettingValuesFile("guest_settings.json"), 40 41 "PopulationCapacities": loadPopulationCapacities(), 41 42 "StartingResources": loadSettingValuesFile("starting_resources.json"), 42 43 "VictoryConditions": loadVictoryConditions() -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
5 5 const g_GameSpeeds = prepareForDropdown(g_Settings && g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly)); 6 6 const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes); 7 7 const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes); 8 const g_GuestSettings = prepareForDropdown(g_Settings && g_Settings.GuestSettings); //["None", "Color", "Civilization","Team", "All"]; 8 9 const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities); 9 10 const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources); 10 11 const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions); … … 141 142 */ 142 143 const g_RandomCiv = '[color="' + g_ColorRandom + '"]' + translateWithContext("civilization", "Random") + '[/color]'; 143 144 144 // Is this isa networked game, or offline145 // Is this a networked game, or offline 145 146 var g_IsNetworked; 146 147 147 148 // Is this user in control of game settings (i.e. is a network server, or offline player) … … 251 252 initMapNameList(); 252 253 initNumberOfPlayers(); 253 254 initGameSpeed(); 255 initGuestSettings(); 254 256 initPopulationCaps(); 255 257 initStartingResources(); 256 258 initCeasefire(); … … 319 321 "optionPopulationCap", 320 322 "optionStartingResources", 321 323 "optionCeasefire", 324 "optionGuestSettings", 322 325 "optionRevealMap", 323 326 "optionExploreMap", 324 327 "optionDisableTreasures", … … 423 426 }; 424 427 } 425 428 429 function initGuestSettings() 430 { 431 let guestSettings = Engine.GetGUIObjectByName("guestSettings"); 432 guestSettings.list = g_GuestSettings.Title; 433 guestSettings.list_data = g_GuestSettings.Data; 434 guestSettings.selected = g_GuestSettings.Default; 435 guestSettings.onSelectionChange = function() { 436 if (this.selected != -1) 437 g_GameAttributes.settings.GuestSettings = g_GuestSettings.Data[this.selected]; 438 439 updateGameAttributes(); 440 }; 441 } 442 426 443 function initVictoryConditions() 427 444 { 428 445 let victoryConditions = Engine.GetGUIObjectByName("victoryCondition"); … … 547 564 } 548 565 549 566 /** 567 * Returns if the player is allowed to change this setting 568 * 569 */ 570 function canPlayerChange(setting) // TODO 571 { 572 if(true) 573 return true; 574 575 else 576 return g_IsController || 577 g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("all"); 578 } 579 /* 580 581 582 583 */ 584 585 586 /** 550 587 * Hide and set some elements depending on whether we play single- or multiplayer. 551 588 */ 552 589 function initMultiplayerSettings() … … 553 590 { 554 591 Engine.GetGUIObjectByName("chatPanel").hidden = !g_IsNetworked; 555 592 Engine.GetGUIObjectByName("optionCheats").hidden = !g_IsNetworked; 593 Engine.GetGUIObjectByName("optionGuestSettings").hidden = !g_IsNetworked; 556 594 Engine.GetGUIObjectByName("optionRating").hidden = !Engine.HasXmppClient(); 557 595 558 596 Engine.GetGUIObjectByName("enableCheats").enabled = !Engine.IsRankedGame(); … … 1301 1339 let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; 1302 1340 let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1303 1341 let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; 1342 let guestSettingsIdx = mapSettings.GuestSettings !== undefined ? g_GuestSettings.Data.indexOf(mapSettings.GuestSettings) : g_GuestSettings.Default; 1304 1343 1305 1344 if (g_IsController) 1306 1345 { … … 1311 1350 Engine.GetGUIObjectByName("numPlayersSelection").selected = numPlayers - 1; 1312 1351 Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; 1313 1352 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1353 Engine.GetGUIObjectByName("guestSettings").selected = guestSettingsIdx; 1314 1354 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1315 1355 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1316 1356 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; … … 1329 1369 Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; 1330 1370 Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; 1331 1371 Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; 1372 Engine.GetGUIObjectByName("guestSettingsText").caption = g_GuestSettings.Title[guestSettingsIdx]; 1332 1373 Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; 1333 1374 Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; 1334 1375 Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; … … 1368 1409 hideControl("disableTreasures", "disableTreasuresText", notScenario); 1369 1410 hideControl("lockTeams", "lockTeamsText", notScenario); 1370 1411 1412 hideControl("guestSettings", "guestSettingsText"); 1413 1371 1414 setMapDescription(); 1372 1415 1373 1416 for (let i = 0; i < g_MaxPlayers; ++i) … … 1480 1523 */ 1481 1524 function updateGameAttributes() 1482 1525 { 1483 if (g_IsInGuiUpdate || !g_IsController)1526 if (g_IsInGuiUpdate )//|| !g_IsController)TODO 1484 1527 return; 1485 1528 1486 1529 if (g_IsNetworked) 1487 1530 { 1488 Engine. SetNetworkGameAttributes(g_GameAttributes);1531 Engine.NetworkChangeSettings(g_GameAttributes); 1489 1532 if (g_LoadingState >= 2) 1490 1533 sendRegisterGameStanza(); 1491 1534 } -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
251 251 <action on="Press">cancelSetup();</action> 252 252 </object> 253 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> 268 254 269 <!-- Options --> 255 270 <object name="gameOptionsBox" size="100%-425 529 100%-25 525"> 256 271 <!-- More Options Button --> … … 336 351 </object> 337 352 </object> 338 353 354 <object name="optionGuestSettings" size="14 188 94% 206"> 355 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 356 <translatableAttribute id="caption">Guest Settings:</translatableAttribute> 357 </object> 358 <object name="guestSettingsText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/> 359 <object name="guestSettings" 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 339 364 <object name="optionRevealMap" size="14 218 94% 246"> 340 365 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 341 366 <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": "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
344 344 g_NetServer->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface)); 345 345 } 346 346 347 void 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 347 359 void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName) 348 360 { 349 361 ENSURE(!g_NetClient); … … 1043 1055 scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer"); 1044 1056 scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient"); 1045 1057 scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes"); 1058 scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkChangeSettings>("NetworkChangeSettings"); 1046 1059 scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer"); 1047 1060 scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus"); 1048 1061 scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady"); -
source/network/NetClient.cpp
321 321 SetCurrState(NCS_UNCONNECTED); 322 322 } 323 323 324 void 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 /*const CStr& setting, const CStr& value) 334 { 335 CChangeSettingsMessage changeSetting; 336 changeSetting.m_Setting = setting; 337 changeSetting.m_Value = value; 338 SendMessage(&changeSetting);*/ 339 } 340 324 341 void CNetClient::SendChatMessage(const std::wstring& text) 325 342 { 326 343 CChatMessage chat; -
source/network/NetClient.h
187 187 */ 188 188 void LoadFinished(); 189 189 190 void SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface); 191 190 192 void SendChatMessage(const std::wstring& text); 191 193 192 194 void SendReadyMessage(const int status); -
source/network/NetMessage.cpp
198 198 case NMT_SIMULATION_COMMAND: 199 199 pNewMessage = new CSimulationMessage(scriptInterface); 200 200 break; 201 case NMT_CHANGE_SETTINGS: 202 pNewMessage = new CChangeSettingsMessage; 203 break; 201 204 202 205 default: 203 206 LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType()); -
source/network/NetMessages.h
45 45 NMT_SERVER_HANDSHAKE_RESPONSE, 46 46 NMT_AUTHENTICATE, // Authentication stage 47 47 NMT_AUTHENTICATE_RESULT, 48 NMT_CHAT, // Common chat message48 NMT_CHAT, // Common chat message 49 49 NMT_READY, 50 50 NMT_GAME_SETUP, 51 51 NMT_PLAYER_ASSIGNMENT, … … 66 66 NMT_LOADED_GAME, 67 67 NMT_GAME_START, 68 68 NMT_END_COMMAND_BATCH, 69 NMT_SYNC_CHECK, // OOS-detection hash checking70 NMT_SYNC_ERROR, // OOS-detection error69 NMT_SYNC_CHECK, // OOS-detection hash checking 70 NMT_SYNC_ERROR, // OOS-detection error 71 71 NMT_SIMULATION_COMMAND, 72 NMT_CHANGE_SETTINGS, // User changes a setting in gamesetup 72 73 NMT_LAST // Last message in the list 73 74 }; 74 75 … … 109 110 END_NMT_CLASS() 110 111 111 112 START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE) 112 NMT_FIELD(CStr 8, m_GUID)113 NMT_FIELD(CStr, m_GUID) 113 114 NMT_FIELD(CStrW, m_Name) 114 115 NMT_FIELD(CStrW, m_Password) 115 116 NMT_FIELD_INT(m_IsLocalClient, u8, 1) … … 122 123 END_NMT_CLASS() 123 124 124 125 START_NMT_CLASS_(Chat, NMT_CHAT) 125 NMT_FIELD(CStr 8, m_GUID) // ignored when client->server, valid when server->client126 NMT_FIELD(CStr, m_GUID) // ignored when client->server, valid when server->client 126 127 NMT_FIELD(CStrW, m_Message) 127 128 END_NMT_CLASS() 128 129 129 130 START_NMT_CLASS_(Ready, NMT_READY) 130 NMT_FIELD(CStr 8, m_GUID)131 NMT_FIELD(CStr, m_GUID) 131 132 NMT_FIELD_INT(m_Status, u8, 1) 132 133 END_NMT_CLASS() 133 134 134 135 START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT) 135 136 NMT_START_ARRAY(m_Hosts) 136 NMT_FIELD(CStr 8, m_GUID)137 NMT_FIELD(CStr, m_GUID) 137 138 NMT_FIELD(CStrW, m_Name) 138 139 NMT_FIELD_INT(m_PlayerID, i8, 1) 139 140 NMT_FIELD_INT(m_Status, u8, 1) … … 151 152 152 153 START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA) 153 154 NMT_FIELD_INT(m_RequestID, u32, 4) 154 NMT_FIELD(CStr 8, m_Data)155 NMT_FIELD(CStr, m_Data) 155 156 END_NMT_CLASS() 156 157 157 158 START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK) … … 163 164 END_NMT_CLASS() 164 165 165 166 START_NMT_CLASS_(Rejoined, NMT_REJOINED) 166 NMT_FIELD(CStr 8, m_GUID)167 NMT_FIELD(CStr, m_GUID) 167 168 END_NMT_CLASS() 168 169 169 170 START_NMT_CLASS_(Kicked, NMT_KICKED) … … 172 173 END_NMT_CLASS() 173 174 174 175 START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT) 175 NMT_FIELD(CStr 8, m_GUID)176 NMT_FIELD(CStr, m_GUID) 176 177 NMT_FIELD_INT(m_LastReceivedTime, u32, 4) 177 178 END_NMT_CLASS() 178 179 179 180 START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE) 180 181 NMT_START_ARRAY(m_Clients) 181 NMT_FIELD(CStr 8, m_GUID)182 NMT_FIELD(CStr, m_GUID) 182 183 NMT_FIELD_INT(m_MeanRTT, u32, 4) 183 184 NMT_END_ARRAY() 184 185 END_NMT_CLASS() … … 208 209 NMT_END_ARRAY() 209 210 END_NMT_CLASS() 210 211 212 START_NMT_CLASS_(ChangeSettings, NMT_CHANGE_SETTINGS) 213 NMT_FIELD(CStr, m_GUID) 214 NMT_FIELD(CStr, m_Settings) 215 END_NMT_CLASS() 216 211 217 END_NMTS() 212 218 213 219 #else -
source/network/NetServer.cpp
649 649 session->AddTransition(NSS_PREGAME, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context); 650 650 session->AddTransition(NSS_PREGAME, (uint)NMT_CHAT, NSS_PREGAME, (void*)&OnChat, context); 651 651 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); 652 653 session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context); 653 654 654 655 session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context); … … 1106 1107 return true; 1107 1108 } 1108 1109 1110 bool CNetServerWorker::OnChangeSettings(void* context, CFsmEvent* event) 1111 { 1112 ENSURE(event->GetType() == (uint)NMT_CHANGE_SETTINGS); 1113 CNetServerSession* session = (CNetServerSession*)context; 1114 CNetServerWorker& server = session->GetServer(); 1115 1116 CChangeSettingsMessage* message = (CChangeSettingsMessage*)event->GetParamRef(); 1117 server.m_GameAttributesQueue.push_back(message->m_Settings); 1118 return true; 1119 /*JS::RootedValue gameAttributesVal(cx); 1120 GetScriptInterface().ParseJSON(newGameAttributes.back(), &gameAttributesVal); 1121 UpdateGameAttributes(&gameAttributesVal);*/ 1122 1123 //UpdateGameAttributes(&(message->m_Settings)); 1124 1125 /* 1126 message->m_GUID = session->GetGUID(); 1127 PushGuiMessage?? 1128 server.SendMessage(m_Host, message);*/ 1129 1130 } 1131 1109 1132 bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event) 1110 1133 { 1111 1134 ENSURE(event->GetType() == (uint)NMT_LOADED_GAME); -
source/network/NetServer.h
188 188 bool SendMessage(ENetPeer* peer, const CNetMessage* message); 189 189 190 190 /** 191 * Send message to the host 192 */ 193 bool SendMessageToHost(const CNetMessage* message); 194 195 /** 191 196 * Disconnects a player from gamesetup or session. 192 197 */ 193 198 bool KickPlayer(const CStrW& playerName, const bool ban); … … 270 275 static bool OnInGame(void* context, CFsmEvent* event); 271 276 static bool OnChat(void* context, CFsmEvent* event); 272 277 static bool OnReady(void* context, CFsmEvent* event); 278 static bool OnChangeSettings(void* context, CFsmEvent* event); 273 279 static bool OnLoadedGame(void* context, CFsmEvent* event); 274 280 static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event); 275 281 static bool OnRejoined(void* context, CFsmEvent* event);