diff --git a/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerColor.js b/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerColor.js index 9eeb8c1bd0..a0b4e8fd5f 100644 --- a/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerColor.js +++ b/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerColor.js @@ -20,17 +20,21 @@ PlayerSettingControls.PlayerColor = class PlayerColor extends GameSettingControl if (g_GameSettings.playerCount.nbPlayers < this.playerIndex + 1) return; - let hidden = !g_IsController || g_GameSettings.map.type == "scenario"; + const hidden = !g_IsController || g_GameSettings.map.type == "scenario"; this.dropdown.hidden = hidden; this.playerColorHeading.hidden = hidden; - let value = g_GameSettings.playerColor.get(this.playerIndex); - this.setSelectedValue(value); + const value = g_GameSettings.playerColor.get(this.playerIndex); this.playerBackgroundColor.sprite = "color:" + rgbToGuiColor(value, 100); this.values = g_GameSettings.playerColor.available; this.dropdown.list = this.values.map(color => coloredText(this.ColorIcon, rgbToGuiColor(color))); this.dropdown.list_data = this.values.map((color, i) => i); + this.setSelectedValue(this.values.map((color, i) => { + if (color.r === value.r && color.g === value.g && color.b === value.b) + return i; + return undefined; + }).filter(x => x !== undefined)?.[0] ?? -1); } onSelectionChange(itemIdx) diff --git a/source/gui/ObjectTypes/CDropDown.cpp b/source/gui/ObjectTypes/CDropDown.cpp index 1e3317c6e0..3388733fd9 100644 --- a/source/gui/ObjectTypes/CDropDown.cpp +++ b/source/gui/ObjectTypes/CDropDown.cpp @@ -169,7 +169,10 @@ void CDropDown::HandleMessage(SGUIMessage& Message) m_ElementHighlight = m_Selected; // Start at the position of the selected item, if possible. - GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60); + if (m_ItemsYPositions.empty() || m_ElementHighlight < 0 || static_cast(m_ElementHighlight) >= m_ItemsYPositions.size()) + GetScrollBar(0).SetPos(0); + else + GetScrollBar(0).SetPos(m_ItemsYPositions[m_ElementHighlight] - 60); PlaySound(m_SoundOpened); return; // overshadow