Ticket #1580: 1580.7.diff

File 1580.7.diff, 7.0 KB (added by elexis, 9 years ago)
  • binaries/data/mods/public/gui/common/functions_utility.js

     
    146146    return ret;
    147147}
    148148
    149149// ====================================================================
    150150
     151function sameColor(color1, color2)
     152{
     153    return color1.r === color2.r && color1.g === color2.g && color1.b === color2.b;
     154}
     155
     156// ====================================================================
     157
    151158/**
    152159 * Convert time in milliseconds to [hh:]mm:ss string representation.
    153160 * @param time Time period in milliseconds (integer)
    154161 * @return String representing time period
    155162 */
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    88const g_Ceasefire = prepareForDropdown(g_Settings ? g_Settings.Ceasefire : undefined);
    99const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly) : undefined);
    1010const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined);
    1111const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined);
    1212
     13const g_PlayerColors = initPlayerDefaults().slice(1).map(playerData => playerData.Color);
     14
    1315////////////////////////////////////////////////////////////////////////////////////////////////
    1416
    1517// Is this is a networked game, or offline
    1618var g_IsNetworked;
    1719
     
    378380                g_GameAttributes.settings.PlayerData[playerSlot].Team = this.selected - 1;
    379381
    380382            updateGameAttributes();
    381383        };
    382384
     385        // Populate color drop-down lists.
     386        var colorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]");
     387        colorPicker.list = g_PlayerColors.map(color => '[color="' + color.r + ' ' + color.g + ' ' + color.b + '"]■[/color]' );
     388        colorPicker.list_data = g_PlayerColors.map((color, index) => index);
     389        colorPicker.selected = -1;
     390
     391        // Update color
     392        colorPicker.onSelectionChange = function()
     393        {
     394            if (this.selected == -1)
     395                return;
     396
     397            // Add missing properties
     398            g_GameAttributes.settings.PlayerData.forEach((pData, index) => {
     399                if (!pData.Color)
     400                    pData.Color = g_PlayerColors[index];
     401            });
     402
     403            // Apply color if noone else has it
     404            if (g_GameAttributes.settings.PlayerData.every(pData => !sameColor(g_PlayerColors[this.selected], pData.Color)))
     405                g_GameAttributes.settings.PlayerData[playerSlot].Color = g_PlayerColors[this.selected];
     406
     407            if (!g_IsInGuiUpdate)
     408                updateGameAttributes();
     409        }
     410
    383411        // Set events
    384412        var civ = Engine.GetGUIObjectByName("playerCiv["+i+"]");
    385413        civ.onSelectionChange = function() {
    386414            if ((this.selected != -1)&&(g_GameAttributes.mapType !== "scenario"))
    387415                g_GameAttributes.settings.PlayerData[playerSlot].Civ = this.list_data[this.selected];
     
    14201448        var pCiv = Engine.GetGUIObjectByName("playerCiv["+i+"]");
    14211449        var pCivText = Engine.GetGUIObjectByName("playerCivText["+i+"]");
    14221450        var pTeam = Engine.GetGUIObjectByName("playerTeam["+i+"]");
    14231451        var pTeamText = Engine.GetGUIObjectByName("playerTeamText["+i+"]");
    14241452        var pColor = Engine.GetGUIObjectByName("playerColor["+i+"]");
     1453        var pColorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]")
    14251454
    14261455        // Player data / defaults
    14271456        var pData = mapSettings.PlayerData ? mapSettings.PlayerData[i] : {};
    14281457        var pDefs = g_DefaultPlayerData ? g_DefaultPlayerData[i] : {};
    14291458
     
    14471476        // TODO: Allow clients to choose their own civ and team
    14481477        if (!g_IsController || g_GameAttributes.mapType == "scenario")
    14491478        {
    14501479            pCivText.hidden = false;
    14511480            pCiv.hidden = true;
     1481            pColorPicker.hidden = true;
    14521482            pTeamText.hidden = false;
    14531483            pTeam.hidden = true;
    14541484            // Set text values
    14551485            if (civ == "random")
    14561486                pCivText.caption = "[color=\"orange\"]" + translateWithContext("civilization", "Random");
     
    14621492        {
    14631493            pCivText.hidden = true;
    14641494            pCiv.hidden = false;
    14651495            pTeamText.hidden = true;
    14661496            pTeam.hidden = false;
     1497            pColorPicker.hidden = false;
    14671498            // Set dropdown values
    14681499            pCiv.selected = (civ ? pCiv.list_data.indexOf(civ) : 0);
    14691500            pTeam.selected = (team !== undefined && team >= 0) ? team+1 : 0;
     1501            pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color));
    14701502        }
    14711503    }
    14721504
    14731505    Engine.GetGUIObjectByName("mapInfoDescription").caption = playerString;
    14741506
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    4040            </action>
    4141
    4242            <!-- Player assignments -->
    4343            <object size="24 49 100%-440 345" type="image" sprite="ModernDarkBoxGold" name="playerAssignmentsPanel">
    4444                <object size="0 6 100% 30">
    45                     <object name="playerNameHeading" type="text" style="ModernLabelText" size="0 0 22% 100%">
     45                    <object name="playerNameHeading" type="text" style="ModernLabelText" size="0 0 16% 100%">
    4646                        <translatableAttribute id="caption">Player Name</translatableAttribute>
    4747                    </object>
     48                    <object name="playerColorHeading" type="text" style="ModernLabelText" size="-3% 0 40% 100%">
     49                        <translatableAttribute id="caption">Color</translatableAttribute>
     50                    </object>
    4851                    <object name="playerPlacementHeading" type="text" style="ModernLabelText" size="22%+5 0 50%+35 100%">
    4952                        <translatableAttribute id="caption">Player Placement</translatableAttribute>
    5053                    </object>
    5154                    <object name="playerCivHeading" type="text" style="ModernLabelText" size="50%+65 0 85%-26 100%">
    5255                        <translatableAttribute id="caption">Civilization</translatableAttribute>
     
    6972                </object>
    7073                <object size="1 36 100%-1 100%">
    7174                    <repeat count="8">
    7275                        <object name="playerBox[n]" size="0 0 100% 32" hidden="true">
    7376                            <object name="playerColor[n]" type="image" size="0 0 100% 100%"/>
    74                             <object name="playerName[n]" type="text" style="ModernLabelText" size="0 2 22% 30"/>
     77                            <object name="playerName[n]" type="text" style="ModernLabelText" size="0 0 16% 100%"/>
     78                            <object name="playerColorPicker[n]" type="dropdown" style="ModernDropDown" size="15%+5 2 20%+5 30" tooltip_style="onscreenToolTip">
     79                                <translatableAttribute id="tooltip">Pick a color.</translatableAttribute>
     80                            </object>
    7581                            <object name="playerAssignment[n]" type="dropdown" style="ModernDropDown" size="22%+5 2 50%+35 30" tooltip_style="onscreenToolTip">
    7682                                <translatableAttribute id="tooltip">Select player.</translatableAttribute>
    7783                            </object>
    7884                            <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+5 0 50%+35 30"/>
    7985                            <object name="playerConfig[n]" type="button" style="StoneButton" size="50%+40 4 50%+64 28"