Ticket #1580: 1580.11.diff
File 1580.11.diff, 8.7 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_utility.js
146 146 return ret; 147 147 } 148 148 149 149 // ==================================================================== 150 150 151 function sameColor(color1, color2) 152 { 153 return color1.r === color2.r && color1.g === color2.g && color1.b === color2.b; 154 } 155 156 // ==================================================================== 157 151 158 /** 152 159 * Convert time in milliseconds to [hh:]mm:ss string representation. 153 160 * @param time Time period in milliseconds (integer) 154 161 * @return String representing time period 155 162 */ -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
7 7 const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly) : undefined); 8 8 const g_VictoryConditions = prepareForDropdown(g_Settings ? g_Settings.VictoryConditions : undefined); 9 9 const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined); 10 10 const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined); 11 11 12 // All colors except gaia 13 const g_PlayerColors = initPlayerDefaults().slice(1).map(playerData => playerData.Color); 14 12 15 //////////////////////////////////////////////////////////////////////////////////////////////// 13 16 14 17 // Is this is a networked game, or offline 15 18 var g_IsNetworked; 16 19 … … 373 376 g_GameAttributes.settings.PlayerData[playerSlot].Team = this.selected - 1; 374 377 375 378 updateGameAttributes(); 376 379 }; 377 380 381 // Populate color drop-down lists. 382 var colorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]"); 383 colorPicker.list = g_PlayerColors.map(color => '[font="sans-stroke-14"][color="' + color.r + ' ' + color.g + ' ' + color.b + '"] ■[/color][/font]'); 384 colorPicker.list_data = g_PlayerColors.map((color, index) => index); 385 colorPicker.onSelectionChange = function() { selectPlayerColor(playerSlot, colorPicker.selected); }; 386 colorPicker.selected = -1; 387 378 388 // Set events 379 389 var civ = Engine.GetGUIObjectByName("playerCiv["+i+"]"); 380 390 civ.onSelectionChange = function() { 381 391 if ((this.selected != -1)&&(g_GameAttributes.mapType !== "scenario")) 382 392 g_GameAttributes.settings.PlayerData[playerSlot].Civ = this.list_data[this.selected]; … … 886 896 } 887 897 888 898 updateGameAttributes(); 889 899 } 890 900 901 function selectPlayerColor(playerSlot, selectedColorIdx) 902 { 903 if (selectedColorIdx == -1) 904 return; 905 906 // Add missing properties 907 g_GameAttributes.settings.PlayerData.forEach((pData, index) => { 908 if (!pData.Color) 909 pData.Color = g_PlayerColors[index]; 910 }); 911 912 // If someone else has that color, give him/her the old one 913 var playerID = g_GameAttributes.settings.PlayerData.findIndex(pData => sameColor(g_PlayerColors[selectedColorIdx], pData.Color)); 914 if (playerID != -1) 915 g_GameAttributes.settings.PlayerData[playerID].Color = g_GameAttributes.settings.PlayerData[playerSlot].Color; 916 917 // Assign the new player color 918 g_GameAttributes.settings.PlayerData[playerSlot].Color = g_PlayerColors[selectedColorIdx]; 919 920 // Ensure colors are not used twice (would be possible by selecting any unused color and then increasing the number of players) 921 do 922 { 923 // Find a player with a color that is used twice 924 playerID = g_GameAttributes.settings.PlayerData.findIndex((pData, index) => 925 g_GameAttributes.settings.PlayerData.some((pData2, index2) => index != index2 && sameColor(pData.Color, pData2.Color))); 926 927 // Assign an unused color 928 if (playerID != -1) 929 g_GameAttributes.settings.PlayerData[playerID].Color = 930 g_PlayerColors.find(color => g_GameAttributes.settings.PlayerData.every(pData => !sameColor(color, pData.Color))); 931 932 } while (playerID != -1); 933 934 if (!g_IsInGuiUpdate) 935 updateGameAttributes(); 936 } 937 891 938 // Called when the user selects a map type from the list 892 939 function selectMapType(type) 893 940 { 894 941 // Avoid recursion 895 942 if (g_IsInGuiUpdate) … … 1422 1469 var pCiv = Engine.GetGUIObjectByName("playerCiv["+i+"]"); 1423 1470 var pCivText = Engine.GetGUIObjectByName("playerCivText["+i+"]"); 1424 1471 var pTeam = Engine.GetGUIObjectByName("playerTeam["+i+"]"); 1425 1472 var pTeamText = Engine.GetGUIObjectByName("playerTeamText["+i+"]"); 1426 1473 var pColor = Engine.GetGUIObjectByName("playerColor["+i+"]"); 1474 var pColorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]"); 1475 var pColorPickerHeading = Engine.GetGUIObjectByName("playerColorHeading"); 1427 1476 1428 1477 // Player data / defaults 1429 1478 var pData = mapSettings.PlayerData ? mapSettings.PlayerData[i] : {}; 1430 1479 var pDefs = g_DefaultPlayerData ? g_DefaultPlayerData[i] : {}; 1431 1480 1432 1481 // Common to all game types 1433 var color = rgbToGuiColor(getSetting(pData, pDefs, "Color"));1434 pColor.sprite = "color:" + color+ " 100";1482 var color = getSetting(pData, pDefs, "Color"); 1483 pColor.sprite = "color:" + rgbToGuiColor(color) + " 100"; 1435 1484 pName.caption = translate(getSetting(pData, pDefs, "Name")); 1436 1485 1437 1486 var team = getSetting(pData, pDefs, "Team"); 1438 1487 var civ = getSetting(pData, pDefs, "Civ"); 1439 1488 … … 1449 1498 // TODO: Allow clients to choose their own civ and team 1450 1499 if (!g_IsController || g_GameAttributes.mapType == "scenario") 1451 1500 { 1452 1501 pCivText.hidden = false; 1453 1502 pCiv.hidden = true; 1503 pColorPicker.hidden = true; 1504 pColorPickerHeading.hidden = true; 1454 1505 pTeamText.hidden = false; 1455 1506 pTeam.hidden = true; 1456 1507 // Set text values 1457 1508 if (civ == "random") 1458 1509 pCivText.caption = "[color=\"orange\"]" + translateWithContext("civilization", "Random"); … … 1464 1515 { 1465 1516 pCivText.hidden = true; 1466 1517 pCiv.hidden = false; 1467 1518 pTeamText.hidden = true; 1468 1519 pTeam.hidden = false; 1520 pColorPicker.hidden = false; 1521 pColorPickerHeading.hidden = false; 1522 pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color)); 1469 1523 // Set dropdown values 1470 1524 pCiv.selected = (civ ? pCiv.list_data.indexOf(civ) : 0); 1471 1525 pTeam.selected = (team !== undefined && team >= 0) ? team+1 : 0; 1472 1526 } 1473 1527 } -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
40 40 <object size="24 49 100%-440 345" type="image" sprite="ModernDarkBoxGold" name="playerAssignmentsPanel"> 41 41 <object size="0 6 100% 30"> 42 42 <object name="playerNameHeading" type="text" style="ModernLabelText" size="0 0 22% 100%"> 43 43 <translatableAttribute id="caption">Player Name</translatableAttribute> 44 44 </object> 45 <object name="playerPlacementHeading" type="text" style="ModernLabelText" size="22%+5 0 50%+35 100%"> 45 <object name="playerColorHeading" type="text" style="ModernLabelText" size="22%+5 0 22%+40 100%"> 46 <translatableAttribute id="caption">Color</translatableAttribute> 47 </object> 48 <object name="playerPlacementHeading" type="text" style="ModernLabelText" size="22%+45 0 50%+35 100%"> 46 49 <translatableAttribute id="caption">Player Placement</translatableAttribute> 47 50 </object> 48 51 <object name="playerCivHeading" type="text" style="ModernLabelText" size="50%+65 0 85%-26 100%"> 49 52 <translatableAttribute id="caption">Civilization</translatableAttribute> 50 53 </object> … … 67 70 <object size="1 36 100%-1 100%"> 68 71 <repeat count="8"> 69 72 <object name="playerBox[n]" size="0 0 100% 32" hidden="true"> 70 73 <object name="playerColor[n]" type="image" size="0 0 100% 100%"/> 71 74 <object name="playerName[n]" type="text" style="ModernLabelText" size="0 2 22% 30"/> 72 <object name="playerAssignment[n]" type="dropdown" style="ModernDropDown" size="22%+5 2 50%+35 30" tooltip_style="onscreenToolTip"> 75 <object name="playerColorPicker[n]" type="dropdown" style="ModernDropDown" size="22%+5 2 22%+40 30" scrollbar="false" tooltip_style="onscreenToolTip"> 76 <translatableAttribute id="tooltip">Pick a color.</translatableAttribute> 77 </object> 78 <object name="playerAssignment[n]" type="dropdown" style="ModernDropDown" size="22%+45 2 50%+35 30" tooltip_style="onscreenToolTip"> 73 79 <translatableAttribute id="tooltip">Select player.</translatableAttribute> 74 80 </object> 75 81 <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+5 0 50%+35 30"/> 76 82 <object name="playerConfig[n]" type="button" style="StoneButton" size="50%+40 4 50%+64 28" 77 83 tooltip_style="onscreenToolTip"