Ticket #3806: 3806_player_gamesetup_v0.9.patch
File 3806_player_gamesetup_v0.9.patch, 31.7 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); … … 146 147 */ 147 148 const g_RandomCiv = '[color="' + g_ColorRandom + '"]' + translateWithContext("civilization", "Random") + '[/color]'; 148 149 149 // Is this isa networked game, or offline150 // Is this a networked game, or offline 150 151 var g_IsNetworked; 151 152 152 153 // Is this user in control of game settings (i.e. is a network server, or offline player) … … 260 261 g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked; 261 262 g_GameAttributes.settings.RatingEnabled = Engine.IsRankedGame() || undefined; 262 263 263 initMapNameList(); 264 initNumberOfPlayers(); 265 initGameSpeed(); 266 initPopulationCaps(); 267 initStartingResources(); 268 initCeasefire(); 269 initWonderDurations(); 270 initVictoryConditions(); 271 initMapSizes(); 272 initRadioButtons(); 264 initDropdowns(); 273 265 } 274 else275 hideControls();276 266 277 267 initMultiplayerSettings(); 278 268 initPlayerAssignments(); … … 291 281 } 292 282 } 293 283 284 function initDropdowns() 285 { 286 initMapNameList(); 287 initNumberOfPlayers(); 288 initGameSpeed(); 289 initGuestSettings(); 290 initPopulationCaps(); 291 initStartingResources(); 292 initCeasefire(); 293 initWonderDurations(); 294 initVictoryConditions(); 295 initMapSizes(); 296 initRadioButtons(); 297 } 298 294 299 function initMapTypes() 295 300 { 296 301 let mapTypes = Engine.GetGUIObjectByName("mapType"); … … 331 336 "optionPopulationCap", 332 337 "optionStartingResources", 333 338 "optionCeasefire", 339 "optionGuestSettings", 334 340 "optionRevealMap", 335 341 "optionExploreMap", 336 342 "optionDisableTreasures", … … 380 386 function initGameSpeed() 381 387 { 382 388 let gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 383 gameSpeed.hidden = false;384 Engine.GetGUIObjectByName("gameSpeedText").hidden = true;389 gameSpeed.hidden = !canPlayerChange("gameSpeed"); 390 Engine.GetGUIObjectByName("gameSpeedText").hidden = canPlayerChange("gameSpeed"); 385 391 gameSpeed.list = g_GameSpeeds.Title; 386 392 gameSpeed.list_data = g_GameSpeeds.Speed; 387 393 gameSpeed.onSelectionChange = function() { … … 435 441 }; 436 442 } 437 443 444 function initGuestSettings() 445 { 446 let guestSettings = Engine.GetGUIObjectByName("guestSettings"); 447 guestSettings.list = g_GuestSettings.Title; 448 guestSettings.list_data = g_GuestSettings.Data; 449 guestSettings.selected = g_GuestSettings.Default; 450 guestSettings.onSelectionChange = function() { 451 if (this.selected != -1) 452 g_GameAttributes.settings.GuestSettings = g_GuestSettings.Data[this.selected]; 453 454 updateGameAttributes(); 455 }; 456 } 457 438 458 function initVictoryConditions() 439 459 { 440 460 let victoryConditions = Engine.GetGUIObjectByName("victoryCondition"); … … 515 535 function hideControls() 516 536 { 517 537 for (let ctrl of ["mapType", "mapFilter", "mapSelection", "victoryCondition", "gameSpeed", "numPlayers"]) 518 hideControl(ctrl, ctrl + "Text" );538 hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl)); 519 539 520 540 // TODO: Shouldn't players be able to choose their own assignment? 521 541 for (let i = 0; i < g_MaxPlayers; ++i) … … 555 575 } 556 576 557 577 /** 578 * Returns if the player is allowed to change this setting 579 */ 580 function canPlayerChange(setting) // TODO 581 { 582 if (setting == "") 583 if (g_GameAttributes.mapType == "scenario" && 584 ["victoryCondition", "wonderDuration", "populationCap", 585 "startingResources", "ceasefire", "revealMap", "exploreMap", 586 "disableTreasures", "lockTeams", "playerCiv", "playerTeam", "playerColor"].indexOf(setting) >= 0) 587 return false; 588 if (g_GameAttributes.mapType != "random" && setting == "numPlayers") 589 return false; 590 //TODO scenario etc.? 591 if (g_IsController) 592 return true; 593 594 switch (setting) 595 { 596 case "guestSettings": return false; 597 case "playerColor": return g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("color"); 598 case "playerCiv": return g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("civ"); 599 case "playerTeam": return g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("team"); 600 default: return g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("all"); 601 } 602 } 603 604 /** 558 605 * Hide and set some elements depending on whether we play single- or multiplayer. 559 606 */ 560 607 function initMultiplayerSettings() … … 561 608 { 562 609 Engine.GetGUIObjectByName("chatPanel").hidden = !g_IsNetworked; 563 610 Engine.GetGUIObjectByName("optionCheats").hidden = !g_IsNetworked; 611 Engine.GetGUIObjectByName("optionGuestSettings").hidden = !g_IsNetworked; 564 612 Engine.GetGUIObjectByName("optionRating").hidden = !Engine.HasXmppClient(); 565 613 566 614 Engine.GetGUIObjectByName("enableCheats").enabled = !Engine.IsRankedGame(); … … 607 655 colorPicker.list_data = g_PlayerColors.map((color, index) => index); 608 656 colorPicker.selected = -1; 609 657 colorPicker.onSelectionChange = function() { selectPlayerColor(playerSlot, this.selected); }; 610 658 warn("color: " + colorPicker.list); 611 659 Engine.GetGUIObjectByName("playerCiv["+i+"]").onSelectionChange = function() { 612 660 if ((this.selected != -1)&&(g_GameAttributes.mapType !== "scenario")) 613 661 g_GameAttributes.settings.PlayerData[playerSlot].Civ = this.list_data[this.selected]; … … 677 725 } 678 726 679 727 /** 680 * Called whenever the hostchanged any setting.728 * Called whenever someone changed any setting. 681 729 * @param {Object} message 682 730 */ 683 731 function handleGamesetupMessage(message) … … 695 743 696 744 Engine.SetRankedGame(!!g_GameAttributes.settings.RatingEnabled); 697 745 746 747 //initMapNameList(); 748 698 749 updateGUIObjects(); 699 750 } 700 751 … … 871 922 /** 872 923 * Sets the gameattributes the way they were the last time the user left the gamesetup. 873 924 */ 874 function loadPersistMatchSettings() 925 function loadPersistMatchSettings() //TODO is the guestSettings setting getting restored? 875 926 { 876 927 if (Engine.ConfigDB_GetValue("user", "persistmatchsettings") != "true") 877 928 return; … … 995 1046 initGUIObjects(); 996 1047 ++g_LoadingState; 997 1048 } 998 else if (g_LoadingState == 2 )1049 else if (g_LoadingState == 2 || g_LoadingState == 3) 999 1050 { 1000 1051 while (true) 1001 1052 { … … 1006 1057 log("Net message: " + uneval(message)); 1007 1058 1008 1059 if (g_NetMessageTypes[message.type]) 1060 { 1009 1061 g_NetMessageTypes[message.type](message); 1062 if (g_LoadingState == 2 && message.type == "gamesetup") 1063 { 1064 ++g_LoadingState; 1065 initDropdowns(); 1066 hideControls(); 1067 } 1068 } 1010 1069 else 1011 1070 error("Unrecognised net message type " + message.type); 1012 1071 } … … 1022 1081 function selectNumPlayers(num) 1023 1082 { 1024 1083 // Avoid recursion 1025 if (g_IsInGuiUpdate || ! g_IsController|| g_GameAttributes.mapType != "random")1084 if (g_IsInGuiUpdate || !canPlayerChange("numPlayers") || g_GameAttributes.mapType != "random") 1026 1085 return; 1027 1028 1086 // Unassign players from nonexistent slots 1029 1087 if (g_IsNetworked) 1030 1088 { 1031 1089 for (let i = g_MaxPlayers; i > num; --i) 1032 Engine.AssignNetworkPlayer(i, ""); 1090 Engine.AssignNetworkPlayer(i, ""); //TODO: AssignNetworkPlayer only works for host 1033 1091 } 1034 1092 else if (g_PlayerAssignments.local.player > num) 1035 1093 g_PlayerAssignments.local.player = 1; … … 1086 1144 function selectMapType(type) 1087 1145 { 1088 1146 // Avoid recursion 1089 if (g_IsInGuiUpdate || !g_IsController)1147 if (g_IsInGuiUpdate )//|| !g_IsController) 1090 1148 return; 1091 1149 1092 1150 if (!g_MapPath[type]) … … 1116 1174 function selectMapFilter(id) 1117 1175 { 1118 1176 // Avoid recursion 1119 if (g_IsInGuiUpdate || !g_IsController)1177 if (g_IsInGuiUpdate) 1120 1178 return; 1121 1179 1122 1180 g_GameAttributes.mapFilter = id; … … 1130 1188 function selectMap(name) 1131 1189 { 1132 1190 // Avoid recursion 1133 if (g_IsInGuiUpdate || ! g_IsController || !name)1191 if (g_IsInGuiUpdate || !name) 1134 1192 return; 1135 1193 1136 1194 // Reset some map specific properties which are not necessarily redefined on each map … … 1182 1240 { // Unassign extra players 1183 1241 let player = g_PlayerAssignments[guid].player; 1184 1242 if (player <= g_MaxPlayers && player > numPlayers) 1185 Engine.AssignNetworkPlayer(player, ""); 1243 Engine.AssignNetworkPlayer(player, ""); //TODO: make usable for everyone 1186 1244 } 1187 1245 } 1188 1246 … … 1262 1320 1263 1321 if (g_IsNetworked) 1264 1322 { 1265 Engine. SetNetworkGameAttributes(g_GameAttributes);1323 Engine.NetworkChangeSettings(g_GameAttributes); 1266 1324 Engine.StartNetworkGame(); 1267 1325 } 1268 1326 else … … 1310 1368 let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; 1311 1369 let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1312 1370 let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; 1371 let guestSettingsIdx = mapSettings.GuestSettings !== undefined ? g_GuestSettings.Data.indexOf(mapSettings.GuestSettings) : g_GuestSettings.Default; 1313 1372 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)); 1373 Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx; 1374 Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx; 1375 Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName); 1376 Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx; 1377 Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1; 1378 Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; 1379 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1380 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1381 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1382 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; 1383 Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; 1384 1385 //if (g_IsController) 1333 1386 initMapNameList(); 1334 }1335 1387 1336 1388 // Can be visible to both host and clients 1337 1389 Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default"); … … 1338 1390 Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; 1339 1391 Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; 1340 1392 Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; 1393 Engine.GetGUIObjectByName("guestSettingsText").caption = g_GuestSettings.Title[guestSettingsIdx]; 1341 1394 Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; 1342 1395 Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; 1343 1396 Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; 1344 1397 Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx]; 1398 Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; 1399 Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name; 1400 Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName)); 1345 1401 1346 1402 setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled); 1347 1403 setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures); … … 1364 1420 Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom; 1365 1421 Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController; 1366 1422 Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController; 1367 hideControl("numPlayers", "numPlayersText", isRandom && g_IsController);1368 1423 1369 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;1370 1371 1424 for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap", 1372 1425 "startingResources", "ceasefire", "revealMap", 1373 "exploreMap", "disableTreasures", "lockTeams"]) 1374 hideControl(ctrl, ctrl + "Text", notScenario); 1426 "exploreMap", "disableTreasures", "lockTeams", 1427 "gameSpeed", "guestSettings", "enableCheats", 1428 "mapSelection", "numPlayers", "mapType", "mapFilter"]) 1429 hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl)); 1375 1430 1431 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; 1432 1376 1433 setMapDescription(); 1377 1434 1378 1435 for (let i = 0; i < g_MaxPlayers; ++i) … … 1408 1465 pCiv.selected = civ ? pCiv.list_data.indexOf(civ) : 0; 1409 1466 pTeam.selected = team !== undefined && team >= 0 ? team+1 : 0; 1410 1467 1411 hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", g_IsController);1412 hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", notScenario);1413 hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", notScenario);1468 hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", canPlayerChange("playerAssignment")); 1469 hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", canPlayerChange("playerCiv")); 1470 hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", canPlayerChange("playerTeam")); 1414 1471 1415 1472 // Allow host to chose player colors on non-scenario maps 1416 1473 let pColorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]"); 1417 1474 let pColorPickerHeading = Engine.GetGUIObjectByName("playerColorHeading"); 1418 let canChangeColors = g_IsController && g_GameAttributes.mapType != "scenario";1419 pColorPicker.hidden = !can ChangeColors;1420 pColorPickerHeading.hidden = !can ChangeColors;1421 if (can ChangeColors)1475 //let canChangeColors = g_IsController && g_GameAttributes.mapType != "scenario"; 1476 pColorPicker.hidden = !canPlayerChange("playerColor"); 1477 pColorPickerHeading.hidden = !canPlayerChange("playerColor"); 1478 if (canPlayerChange("playerColor")) 1422 1479 pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color)); 1423 1480 } 1424 1481 … … 1485 1542 */ 1486 1543 function updateGameAttributes() 1487 1544 { 1488 if (g_IsInGuiUpdate || !g_IsController)1545 if (g_IsInGuiUpdate )//|| !g_IsController)TODO 1489 1546 return; 1490 1547 1491 1548 if (g_IsNetworked) 1492 1549 { 1493 Engine. SetNetworkGameAttributes(g_GameAttributes);1550 Engine.NetworkChangeSettings(g_GameAttributes); 1494 1551 if (g_LoadingState >= 2) 1495 1552 sendRegisterGameStanza(); 1496 1553 } … … 1504 1561 1505 1562 Engine.PushGuiPage("page_aiconfig.xml", { 1506 1563 "callback": "AIConfigCallback", 1507 "isController": g_IsController,1564 "isController": canPlayerChange("playerConfig"), 1508 1565 "playerSlot": playerSlot, 1509 1566 "id": g_GameAttributes.settings.PlayerData[playerSlot].AI, 1510 1567 "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff … … 1518 1575 { 1519 1576 g_LastViewedAIPlayer = -1; 1520 1577 1521 if (!ai.save || !g_IsController)1578 if (!ai.save)// || !g_IsController) 1522 1579 return; 1523 1580 1524 1581 g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id; … … 1525 1582 g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty; 1526 1583 1527 1584 if (g_IsNetworked) 1528 Engine. SetNetworkGameAttributes(g_GameAttributes);1585 Engine.NetworkChangeSettings(g_GameAttributes); 1529 1586 else 1530 1587 updatePlayerList(); 1531 1588 } … … 1621 1678 { 1622 1679 g_GameAttributes.settings.PlayerData[playerSlot].AI = ""; 1623 1680 if (g_IsNetworked) 1624 Engine. SetNetworkGameAttributes(g_GameAttributes);1681 Engine.NetworkChangeSettings(g_GameAttributes); 1625 1682 } 1626 1683 1627 1684 let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); … … 1632 1689 assignBox.selected = selection; 1633 1690 assignBoxText.caption = hostNameList[selection]; 1634 1691 1635 if (g_IsController)1692 //if (g_IsController) 1636 1693 assignBox.onselectionchange = function() { 1637 1694 if (g_IsInGuiUpdate) 1638 1695 return; … … 1658 1715 swapPlayers(guid, playerSlot); 1659 1716 1660 1717 if (g_IsNetworked) 1661 Engine. SetNetworkGameAttributes(g_GameAttributes);1718 Engine.NetworkChangeSettings(g_GameAttributes); 1662 1719 else 1663 1720 updatePlayerList(); 1664 1721 updateReadyUI(); -
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" … … 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); … … 427 439 428 440 void AssignNetworkPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int playerID, const std::string& guid) 429 441 { 430 ENSURE(g_Net Server);442 ENSURE(g_NetClient); 431 443 432 g_Net Server->AssignPlayer(playerID, guid);444 g_NetClient->SendAssignPlayerMessage(playerID, guid); 433 445 } 434 446 435 447 void SetNetworkPlayerStatus(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& guid, int ready) … … 1049 1061 scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer"); 1050 1062 scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient"); 1051 1063 scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes"); 1064 scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkChangeSettings>("NetworkChangeSettings"); 1052 1065 scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer"); 1053 1066 scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus"); 1054 1067 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 341 void CNetClient::SendAssignPlayerMessage(const int playerID, const std::string guid) 342 { 343 CAssignPlayerMessage assignPlayer; 344 assignPlayer.m_PlayerID = playerID; 345 assignPlayer.m_GUIDToAssign = guid; 346 SendMessage(&assignPlayer); 347 } 348 324 349 void CNetClient::SendChatMessage(const std::wstring& text) 325 350 { 326 351 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
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 73 NMT_ASSIGN_PLAYER, 72 74 NMT_LAST // Last message in the list 73 75 }; 74 76 … … 109 111 END_NMT_CLASS() 110 112 111 113 START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE) 112 NMT_FIELD(CStr 8, m_GUID)114 NMT_FIELD(CStr, m_GUID) 113 115 NMT_FIELD(CStrW, m_Name) 114 116 NMT_FIELD(CStrW, m_Password) 115 117 NMT_FIELD_INT(m_IsLocalClient, u8, 1) … … 122 124 END_NMT_CLASS() 123 125 124 126 START_NMT_CLASS_(Chat, NMT_CHAT) 125 NMT_FIELD(CStr 8, m_GUID) // ignored when client->server, valid when server->client127 NMT_FIELD(CStr, m_GUID) // ignored when client->server, valid when server->client 126 128 NMT_FIELD(CStrW, m_Message) 127 129 END_NMT_CLASS() 128 130 129 131 START_NMT_CLASS_(Ready, NMT_READY) 130 NMT_FIELD(CStr 8, m_GUID)132 NMT_FIELD(CStr, m_GUID) 131 133 NMT_FIELD_INT(m_Status, u8, 1) 132 134 END_NMT_CLASS() 133 135 134 136 START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT) 135 137 NMT_START_ARRAY(m_Hosts) 136 NMT_FIELD(CStr 8, m_GUID)138 NMT_FIELD(CStr, m_GUID) 137 139 NMT_FIELD(CStrW, m_Name) 138 140 NMT_FIELD_INT(m_PlayerID, i8, 1) 139 141 NMT_FIELD_INT(m_Status, u8, 1) … … 151 153 152 154 START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA) 153 155 NMT_FIELD_INT(m_RequestID, u32, 4) 154 NMT_FIELD(CStr 8, m_Data)156 NMT_FIELD(CStr, m_Data) 155 157 END_NMT_CLASS() 156 158 157 159 START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK) … … 163 165 END_NMT_CLASS() 164 166 165 167 START_NMT_CLASS_(Rejoined, NMT_REJOINED) 166 NMT_FIELD(CStr 8, m_GUID)168 NMT_FIELD(CStr, m_GUID) 167 169 END_NMT_CLASS() 168 170 169 171 START_NMT_CLASS_(Kicked, NMT_KICKED) … … 172 174 END_NMT_CLASS() 173 175 174 176 START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT) 175 NMT_FIELD(CStr 8, m_GUID)177 NMT_FIELD(CStr, m_GUID) 176 178 NMT_FIELD_INT(m_LastReceivedTime, u32, 4) 177 179 END_NMT_CLASS() 178 180 179 181 START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE) 180 182 NMT_START_ARRAY(m_Clients) 181 NMT_FIELD(CStr 8, m_GUID)183 NMT_FIELD(CStr, m_GUID) 182 184 NMT_FIELD_INT(m_MeanRTT, u32, 4) 183 185 NMT_END_ARRAY() 184 186 END_NMT_CLASS() … … 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 /*JS::RootedValue gameAttributesVal(cx); 1121 GetScriptInterface().ParseJSON(newGameAttributes.back(), &gameAttributesVal); 1122 UpdateGameAttributes(&gameAttributesVal);*/ 1123 1124 //UpdateGameAttributes(&(message->m_Settings)); 1125 1126 /* 1127 message->m_GUID = session->GetGUID(); 1128 PushGuiMessage?? 1129 server.SendMessage(m_Host, message);*/ 1130 1131 } 1132 1133 bool CNetServerWorker::OnAssignPlayer(void* context, CFsmEvent* event) 1134 { 1135 ENSURE(event->GetType() == (uint)NMT_ASSIGN_PLAYER); 1136 CNetServerSession* session = (CNetServerSession*)context; 1137 CNetServerWorker& server = session->GetServer(); 1138 1139 CAssignPlayerMessage* message = (CAssignPlayerMessage*)event->GetParamRef(); 1140 server.m_AssignPlayerQueue.emplace_back(message->m_PlayerID, message->m_GUIDToAssign); 1141 return true; 1142 } 1143 1109 1144 bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event) 1110 1145 { 1111 1146 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); 279 static bool OnAssignPlayer(void* context, CFsmEvent* event); 273 280 static bool OnLoadedGame(void* context, CFsmEvent* event); 274 281 static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event); 275 282 static bool OnRejoined(void* context, CFsmEvent* event);