Ticket #3806: 3806_player_gamesetup_v1.4_rebased.patch
File 3806_player_gamesetup_v1.4_rebased.patch, 29.3 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/aiconfig/aiconfig.js
16 16 let aiSelection = Engine.GetGUIObjectByName("aiSelection"); 17 17 aiSelection.list = g_AIDescriptions.map(ai => ai.data.name); 18 18 aiSelection.selected = g_AIDescriptions.findIndex(ai => ai.id == settings.id); 19 aiSelection.hidden = !settings. isController;19 aiSelection.hidden = !settings.canBeChanged; 20 20 21 21 let aiSelectionText = Engine.GetGUIObjectByName("aiSelectionText"); 22 22 aiSelectionText.caption = aiSelection.list[aiSelection.selected]; 23 aiSelectionText.hidden = settings. isController;23 aiSelectionText.hidden = settings.canBeChanged; 24 24 25 25 let aiDiff = Engine.GetGUIObjectByName("aiDifficulty"); 26 26 aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title; 27 27 aiDiff.selected = settings.difficulty; 28 aiDiff.hidden = !settings. isController;28 aiDiff.hidden = !settings.canBeChanged; 29 29 30 30 let aiDiffText = Engine.GetGUIObjectByName("aiDifficultyText"); 31 31 aiDiffText.caption = aiDiff.list[aiDiff.selected]; 32 aiDiffText.hidden = settings. isController;32 aiDiffText.hidden = settings.canBeChanged; 33 33 } 34 34 35 35 function selectAI(idx) -
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); 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); … … 270 271 initCivNameList(); 271 272 initMapTypes(); 272 273 initMapFilters(); 274 initDropdowns(); 273 275 274 276 if (g_IsController) 275 277 { … … 277 279 g_GameAttributes.matchID = Engine.GetMatchID(); 278 280 g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked; 279 281 g_GameAttributes.settings.RatingEnabled = Engine.IsRankedGame() || undefined; 280 281 initMapNameList();282 initNumberOfPlayers();283 initGameSpeed();284 initPopulationCaps();285 initStartingResources();286 initCeasefire();287 initWonderDurations();288 initVictoryConditions();289 initMapSizes();290 initRadioButtons();291 282 } 292 283 else 293 284 hideControls(); … … 309 300 } 310 301 } 311 302 303 function initDropdowns() 304 { 305 initMapNameList(); 306 initNumberOfPlayers(); 307 initGameSpeed(); 308 initGuestSettings(); 309 initPopulationCaps(); 310 initStartingResources(); 311 initCeasefire(); 312 initWonderDurations(); 313 initVictoryConditions(); 314 initMapSizes(); 315 initRadioButtons(); 316 } 317 312 318 function initMapTypes() 313 319 { 314 320 let mapTypes = Engine.GetGUIObjectByName("mapType"); … … 318 324 if (this.selected != -1) 319 325 selectMapType(this.list_data[this.selected]); 320 326 }; 321 if (g_IsController) 322 mapTypes.selected = g_MapTypes.Default; 327 mapTypes.selected = g_MapTypes.Default; 323 328 } 324 329 325 330 function initMapFilters() … … 331 336 if (this.selected != -1) 332 337 selectMapFilter(this.list_data[this.selected]); 333 338 }; 334 if (g_IsController) 335 mapFilters.selected = 0; 339 mapFilters.selected = 0; 336 340 g_GameAttributes.mapFilter = "default"; 337 341 } 338 342 … … 349 353 "optionPopulationCap", 350 354 "optionStartingResources", 351 355 "optionCeasefire", 356 "optionGuestSettings", 352 357 "optionRevealMap", 353 358 "optionExploreMap", 354 359 "optionDisableTreasures", … … 398 403 function initGameSpeed() 399 404 { 400 405 let gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 401 gameSpeed.hidden = false;402 Engine.GetGUIObjectByName("gameSpeedText").hidden = true;403 406 gameSpeed.list = g_GameSpeeds.Title; 404 407 gameSpeed.list_data = g_GameSpeeds.Speed; 405 408 gameSpeed.onSelectionChange = function() { … … 453 456 }; 454 457 } 455 458 459 function initGuestSettings() 460 { 461 let guestSettings = Engine.GetGUIObjectByName("guestSettings"); 462 guestSettings.list = g_GuestSettings.Title; 463 guestSettings.list_data = g_GuestSettings.Data; 464 guestSettings.onSelectionChange = function() { 465 if (this.selected != -1) 466 g_GameAttributes.GuestSettings = g_GuestSettings.Data[this.selected]; 467 468 updateGameAttributes(); 469 }; 470 if (guestSettings.selected == -1) 471 guestSettings.selected = g_GuestSettings.Default; 472 } 473 456 474 function initVictoryConditions() 457 475 { 458 476 let victoryConditions = Engine.GetGUIObjectByName("victoryCondition"); … … 533 551 function hideControls() 534 552 { 535 553 for (let ctrl of ["mapType", "mapFilter", "mapSelection", "victoryCondition", "gameSpeed", "numPlayers"]) 536 hideControl(ctrl, ctrl + "Text" );554 hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl)); 537 555 538 // TODO: Shouldn't players be able to choose their own assignment?539 556 for (let i = 0; i < g_MaxPlayers; ++i) 540 557 { 541 558 Engine.GetGUIObjectByName("playerAssignment["+i+"]").hidden = true; … … 573 590 } 574 591 575 592 /** 593 * Returns if the player is allowed to change this setting 594 */ 595 function canPlayerChange(setting) 596 { 597 if (g_GameAttributes.mapType == "scenario" && 598 ["victoryCondition", "wonderDuration", "populationCap", 599 "startingResources", "ceasefire", "revealMap", "exploreMap", 600 "disableTreasures", "lockTeams", "playerCiv", "playerTeam", "playerColor"].indexOf(setting) >= 0) 601 return false; 602 603 if (g_GameAttributes.mapType != "random" && setting == "numPlayers") 604 return false; 605 606 if (g_IsController) 607 return true; 608 609 if (setting == "guestSettings") 610 return false; 611 612 if (g_GuestSettings.Data.indexOf(setting) == -1) 613 return g_GameAttributes.GuestSettings == "all"; 614 615 return g_GuestSettings.Data.indexOf(g_GameAttributes.GuestSettings) >= g_GuestSettings.Data.indexOf(setting); 616 } 617 618 /** 576 619 * Hide and set some elements depending on whether we play single- or multiplayer. 577 620 */ 578 621 function initMultiplayerSettings() … … 579 622 { 580 623 Engine.GetGUIObjectByName("chatPanel").hidden = !g_IsNetworked; 581 624 Engine.GetGUIObjectByName("optionCheats").hidden = !g_IsNetworked; 625 Engine.GetGUIObjectByName("optionGuestSettings").hidden = !g_IsNetworked; 582 626 Engine.GetGUIObjectByName("optionRating").hidden = !Engine.HasXmppClient(); 583 627 584 628 Engine.GetGUIObjectByName("enableCheats").enabled = !Engine.IsRankedGame(); … … 695 739 } 696 740 697 741 /** 698 * Called whenever the hostchanged any setting.742 * Called whenever someone changed any setting. 699 743 * @param {Object} message 700 744 */ 701 745 function handleGamesetupMessage(message) … … 1046 1090 function selectNumPlayers(num) 1047 1091 { 1048 1092 // Avoid recursion 1049 if (g_IsInGuiUpdate || ! g_IsController|| g_GameAttributes.mapType != "random")1093 if (g_IsInGuiUpdate || !canPlayerChange("numPlayers") || g_GameAttributes.mapType != "random") 1050 1094 return; 1051 1095 1052 1096 // Unassign players from nonexistent slots … … 1110 1154 function selectMapType(type) 1111 1155 { 1112 1156 // Avoid recursion 1113 if (g_IsInGuiUpdate || !g_IsController)1157 if (g_IsInGuiUpdate) 1114 1158 return; 1115 1159 1116 1160 if (!g_MapPath[type]) … … 1140 1184 function selectMapFilter(id) 1141 1185 { 1142 1186 // Avoid recursion 1143 if (g_IsInGuiUpdate || !g_IsController)1187 if (g_IsInGuiUpdate) 1144 1188 return; 1145 1189 1146 1190 g_GameAttributes.mapFilter = id; … … 1153 1197 function selectMap(name) 1154 1198 { 1155 1199 // Avoid recursion 1156 if (g_IsInGuiUpdate || ! g_IsController || !name)1200 if (g_IsInGuiUpdate || !name) 1157 1201 return; 1158 1202 1159 1203 // Reset some map specific properties which are not necessarily redefined on each map … … 1285 1329 1286 1330 if (g_IsNetworked) 1287 1331 { 1288 Engine. SetNetworkGameAttributes(g_GameAttributes);1332 Engine.NetworkChangeSettings(g_GameAttributes); 1289 1333 Engine.StartNetworkGame(); 1290 1334 } 1291 1335 else … … 1324 1368 let mapFilterIdx = g_MapFilters.findIndex(mapFilter => mapFilter.id == (g_GameAttributes.mapFilter || "default")); 1325 1369 let mapTypeIdx = g_GameAttributes.mapType !== undefined ? g_MapTypes.Name.indexOf(g_GameAttributes.mapType) : g_MapTypes.Default; 1326 1370 let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; 1371 let guestSettingsIdx = g_GameAttributes.GuestSettings !== undefined ? g_GuestSettings.Data.indexOf(g_GameAttributes.GuestSettings) : g_GuestSettings.Default; 1327 1372 1328 1373 // These dropdowns might set the default (as they ignore g_IsInGuiUpdate) 1329 1374 let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default; … … 1334 1379 let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1335 1380 let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; 1336 1381 1337 if (g_IsController) 1338 { 1339 Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx; 1340 Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx; 1341 Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName); 1342 Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx; 1343 Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1; 1344 Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; 1345 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1346 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1347 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1348 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; 1349 Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; 1350 } 1351 else 1352 { 1353 Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; 1354 Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name; 1355 Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName)); 1356 initMapNameList(); 1357 } 1382 Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx; 1383 Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx; 1384 Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName); 1385 Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx; 1386 Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1; 1387 Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; 1388 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1389 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1390 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1391 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; 1392 Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; 1393 Engine.GetGUIObjectByName("guestSettings").selected = guestSettingsIdx; 1358 1394 1395 1396 initMapNameList(); 1397 1359 1398 // Can be visible to both host and clients 1360 1399 Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default"); 1361 1400 Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; 1362 1401 Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; 1363 1402 Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; 1403 Engine.GetGUIObjectByName("guestSettingsText").caption = g_GuestSettings.Title[guestSettingsIdx]; 1364 1404 Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; 1365 1405 Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; 1366 1406 Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; 1367 1407 Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx]; 1408 Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; 1409 Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name; 1410 Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName)); 1368 1411 1369 1412 setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled); 1370 1413 setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures); … … 1387 1430 Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom; 1388 1431 Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController; 1389 1432 Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController; 1390 hideControl("numPlayers", "numPlayersText", isRandom && g_IsController);1391 1433 1392 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;1393 1394 1434 for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap", 1395 1435 "startingResources", "ceasefire", "revealMap", 1396 "exploreMap", "disableTreasures", "lockTeams"]) 1397 hideControl(ctrl, ctrl + "Text", notScenario); 1436 "exploreMap", "disableTreasures", "lockTeams", 1437 "gameSpeed", "guestSettings", "enableCheats", 1438 "mapSelection", "numPlayers", "mapType", "mapFilter"]) 1439 hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl)); 1398 1440 1441 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; 1442 1399 1443 setMapDescription(); 1400 1444 1401 1445 for (let i = 0; i < g_MaxPlayers; ++i) … … 1431 1475 pCiv.selected = civ ? pCiv.list_data.indexOf(civ) : 0; 1432 1476 pTeam.selected = team !== undefined && team >= 0 ? team+1 : 0; 1433 1477 1434 hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", g_IsController);1435 hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", notScenario);1436 hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", notScenario);1478 hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", canPlayerChange("playerAssignment")); 1479 hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", canPlayerChange("playerCiv")); 1480 hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", canPlayerChange("playerTeam")); 1437 1481 1438 1482 // Allow host to chose player colors on non-scenario maps 1439 1483 let pColorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]"); 1440 1484 let pColorPickerHeading = Engine.GetGUIObjectByName("playerColorHeading"); 1441 let canChangeColors = g_IsController && g_GameAttributes.mapType != "scenario"; 1442 pColorPicker.hidden = !canChangeColors; 1443 pColorPickerHeading.hidden = !canChangeColors; 1444 if (canChangeColors) 1485 pColorPicker.hidden = !canPlayerChange("playerColor"); 1486 pColorPickerHeading.hidden = !canPlayerChange("playerColor"); 1487 if (canPlayerChange("playerColor")) 1445 1488 pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color)); 1446 1489 } 1447 1490 … … 1508 1551 */ 1509 1552 function updateGameAttributes() 1510 1553 { 1511 if (g_IsInGuiUpdate || !g_IsController)1554 if (g_IsInGuiUpdate) 1512 1555 return; 1513 1556 1514 1557 if (g_IsNetworked) 1515 1558 { 1516 Engine. SetNetworkGameAttributes(g_GameAttributes);1559 Engine.NetworkChangeSettings(g_GameAttributes); 1517 1560 if (g_LoadingState >= 2) 1518 1561 sendRegisterGameStanza(); 1519 1562 } … … 1527 1570 1528 1571 Engine.PushGuiPage("page_aiconfig.xml", { 1529 1572 "callback": "AIConfigCallback", 1530 " isController": g_IsController,1573 "canBeChanged": canPlayerChange("playerConfig"), 1531 1574 "playerSlot": playerSlot, 1532 1575 "id": g_GameAttributes.settings.PlayerData[playerSlot].AI, 1533 1576 "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff … … 1541 1584 { 1542 1585 g_LastViewedAIPlayer = -1; 1543 1586 1544 if (!ai.save || !g_IsController)1587 if (!ai.save) 1545 1588 return; 1546 1589 1547 1590 g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id; … … 1548 1591 g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty; 1549 1592 1550 1593 if (g_IsNetworked) 1551 Engine. SetNetworkGameAttributes(g_GameAttributes);1594 Engine.NetworkChangeSettings(g_GameAttributes); 1552 1595 else 1553 1596 updatePlayerList(); 1554 1597 } … … 1644 1687 { 1645 1688 g_GameAttributes.settings.PlayerData[playerSlot].AI = ""; 1646 1689 if (g_IsNetworked) 1647 Engine. SetNetworkGameAttributes(g_GameAttributes);1690 Engine.NetworkChangeSettings(g_GameAttributes); 1648 1691 } 1649 1692 1650 1693 let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); … … 1655 1698 assignBox.selected = selection; 1656 1699 assignBoxText.caption = hostNameList[selection]; 1657 1700 1658 if (g_IsController) 1659 assignBox.onselectionchange = function() { 1660 if (g_IsInGuiUpdate) 1661 return; 1701 assignBox.onSelectionChange = function() { 1702 if (g_IsInGuiUpdate) 1703 return; 1662 1704 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1705 let guid = hostGuidList[this.selected]; 1706 if (!guid) 1707 { 1708 if (g_IsNetworked) 1709 // Unassign any host from this player slot 1710 Engine.AssignNetworkPlayer(playerID, ""); 1711 // Remove AI from this player slot 1712 g_GameAttributes.settings.PlayerData[playerSlot].AI = ""; 1713 } 1714 else if (guid.substr(0, 3) == "ai:") 1715 { 1716 if (g_IsNetworked) 1717 // Unassign any host from this player slot 1718 Engine.AssignNetworkPlayer(playerID, ""); 1719 // Set the AI for this player slot 1720 g_GameAttributes.settings.PlayerData[playerSlot].AI = guid.substr(3); 1721 } 1722 else 1723 swapPlayers(guid, playerSlot); 1682 1724 1683 1684 Engine.SetNetworkGameAttributes(g_GameAttributes);1685 1686 1687 1688 1725 if (g_IsNetworked) 1726 Engine.NetworkChangeSettings(g_GameAttributes); 1727 else 1728 updatePlayerList(); 1729 updateReadyUI(); 1730 }; 1689 1731 } 1690 1732 1691 1733 g_IsInGuiUpdate = false; -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
80 80 <object name="playerAssignment[n]" type="dropdown" style="ModernDropDown" size="22%+37 2 50%+35 30" tooltip_style="onscreenToolTip"> 81 81 <translatableAttribute id="tooltip">Select player.</translatableAttribute> 82 82 </object> 83 <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+ 50 50%+35 30"/>83 <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+33 0 50%+35 30"/> 84 84 <object name="playerConfig[n]" type="button" style="StoneButton" size="50%+40 4 50%+64 28" 85 85 tooltip_style="onscreenToolTip" 86 86 font="sans-bold-stroke-12" … … 336 336 </object> 337 337 </object> 338 338 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 339 349 <object name="optionRevealMap" size="14 218 94% 246"> 340 350 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 341 351 <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute> -
source/gui/scripting/ScriptFunctions.cpp
332 332 LOGERROR("Failed to save game"); 333 333 } 334 334 335 void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)335 void NetworkChangeSettings(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1) 336 336 { 337 ENSURE(g_Net Server);337 ENSURE(g_NetClient); 338 338 //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere 339 339 // (with no obvious reason). 340 340 JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); … … 341 341 JSAutoRequest rq(cx); 342 342 JS::RootedValue attribs(cx, attribs1); 343 343 344 g_Net Server->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface));344 g_NetClient->SendChangeSettingsMessage(&attribs, *(pCxPrivate->pScriptInterface)); 345 345 } 346 346 347 347 void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName) … … 427 427 428 428 void AssignNetworkPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int playerID, const std::string& guid) 429 429 { 430 ENSURE(g_Net Server);430 ENSURE(g_NetClient); 431 431 432 g_Net Server->AssignPlayer(playerID, guid);432 g_NetClient->SendAssignPlayerMessage(playerID, guid); 433 433 } 434 434 435 435 void SetNetworkPlayerStatus(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& guid, int ready) … … 1048 1048 scriptInterface.RegisterFunction<std::string, &GetPlayerGUID>("GetPlayerGUID"); 1049 1049 scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer"); 1050 1050 scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient"); 1051 scriptInterface.RegisterFunction<void, JS::HandleValue, & SetNetworkGameAttributes>("SetNetworkGameAttributes");1051 scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkChangeSettings>("NetworkChangeSettings"); 1052 1052 scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer"); 1053 1053 scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus"); 1054 1054 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 334 void 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 324 342 void CNetClient::SendChatMessage(const std::wstring& text) 325 343 { 326 344 CChatMessage chat; -
source/network/NetClient.h
187 187 */ 188 188 void LoadFinished(); 189 189 190 void SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface); 191 192 void SendAssignPlayerMessage(const int playerID, const std::string guid); 193 190 194 void SendChatMessage(const std::wstring& text); 191 195 192 196 void SendReadyMessage(const int status); -
source/network/NetMessage.cpp
199 199 pNewMessage = new CSimulationMessage(scriptInterface); 200 200 break; 201 201 202 case NMT_CHANGE_SETTINGS: 203 pNewMessage = new CChangeSettingsMessage; 204 break; 205 case NMT_ASSIGN_PLAYER: 206 pNewMessage = new CAssignPlayerMessage; 207 break; 208 202 209 default: 203 210 LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType()); 204 211 break; -
source/network/NetMessages.h
28 28 29 29 #define PS_PROTOCOL_MAGIC 0x5073013f // 'P', 's', 0x01, '?' 30 30 #define PS_PROTOCOL_MAGIC_RESPONSE 0x50630121 // 'P', 'c', 0x01, '!' 31 #define PS_PROTOCOL_VERSION 0x0101001 2// Arbitrary protocol31 #define PS_PROTOCOL_VERSION 0x01010013 // Arbitrary protocol 32 32 #define PS_DEFAULT_PORT 0x5073 // 'P', 's' 33 33 34 34 // Defines the list of message types. The order of the list must not change. … … 37 37 // positive values. 38 38 enum NetMessageType 39 39 { 40 NMT_CONNECT_COMPLETE = -256, // Connection is complete40 NMT_CONNECT_COMPLETE = -256, 41 41 NMT_CONNECTION_LOST, 42 NMT_INVALID = 0, // Invalid message43 NMT_SERVER_HANDSHAKE, // Handshake stage42 NMT_INVALID = 0, 43 NMT_SERVER_HANDSHAKE, 44 44 NMT_CLIENT_HANDSHAKE, 45 45 NMT_SERVER_HANDSHAKE_RESPONSE, 46 NMT_AUTHENTICATE, // Authentication stage46 NMT_AUTHENTICATE, 47 47 NMT_AUTHENTICATE_RESULT, 48 NMT_CHAT, // Common chat message48 NMT_CHAT, 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, 70 NMT_SYNC_ERROR, 71 71 NMT_SIMULATION_COMMAND, 72 NMT_LAST // Last message in the list 72 NMT_CHANGE_SETTINGS, 73 NMT_ASSIGN_PLAYER, 74 NMT_LAST // Last message in the list 73 75 }; 74 76 75 77 // Authentication result codes … … 208 210 NMT_END_ARRAY() 209 211 END_NMT_CLASS() 210 212 213 START_NMT_CLASS_(ChangeSettings, NMT_CHANGE_SETTINGS) 214 NMT_FIELD(CStr, m_GUID) 215 NMT_FIELD(CStr, m_Settings) 216 END_NMT_CLASS() 217 218 START_NMT_CLASS_(AssignPlayer, NMT_ASSIGN_PLAYER) 219 NMT_FIELD_INT(m_PlayerID, i8, 1) 220 NMT_FIELD(CStr, m_GUIDToAssign) 221 END_NMT_CLASS() 222 211 223 END_NMTS() 212 224 213 225 #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); 653 session->AddTransition(NSS_PREGAME, (uint)NMT_ASSIGN_PLAYER, NSS_PREGAME, (void*)&OnAssignPlayer, context); 652 654 session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context); 653 655 654 656 session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context); … … 1106 1108 return true; 1107 1109 } 1108 1110 1111 bool 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 1122 bool 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 1109 1133 bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event) 1110 1134 { 1111 1135 ENSURE(event->GetType() == (uint)NMT_LOADED_GAME); -
source/network/NetServer.h
270 270 static bool OnInGame(void* context, CFsmEvent* event); 271 271 static bool OnChat(void* context, CFsmEvent* event); 272 272 static bool OnReady(void* context, CFsmEvent* event); 273 static bool OnChangeSettings(void* context, CFsmEvent* event); 274 static bool OnAssignPlayer(void* context, CFsmEvent* event); 273 275 static bool OnLoadedGame(void* context, CFsmEvent* event); 274 276 static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event); 275 277 static bool OnRejoined(void* context, CFsmEvent* event);