Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#368 show colors in color drop down #369

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public override void Initialize()
ddGameModeMapFilter.AddItem(CreateGameFilterItem(gm.UIName, new GameModeMapFilter(GetGameModeMaps(gm))));

lblGameModeSelect = FindChild<XNALabel>(nameof(lblGameModeSelect));

InitBtnMapSort();

tbMapSearch = FindChild<XNASuggestionTextBox>(nameof(tbMapSearch));
Expand Down Expand Up @@ -784,9 +784,14 @@ protected void InitPlayerOptionDropdowns()
ddPlayerColor.ClientRectangle = new Rectangle(
ddPlayerSide.Right + playerOptionHorizontalMargin,
ddPlayerName.Y, colorWidth, DROP_DOWN_HEIGHT);
ddPlayerColor.AddItem("Random".L10N("UI:Main:RandomColor"), AssetLoader.GetColorFromString(randomColor));
ddPlayerColor.AddItem(MultiplayerColor.GetRandomColorLabel(), AssetLoader.GetColorFromString(randomColor));
foreach (MultiplayerColor mpColor in MPColors)
ddPlayerColor.AddItem(mpColor.Name, mpColor.XnaColor);
{
if(mpColor.Name.StartsWith("$"))
ddPlayerColor.AddItem(string.Empty, AssetLoader.CreateTexture(mpColor.XnaColor, ddPlayerColor.Width - 2, ddPlayerColor.ItemHeight + 2));
Comment on lines +790 to +791
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(mpColor.Name.StartsWith("$"))
ddPlayerColor.AddItem(string.Empty, AssetLoader.CreateTexture(mpColor.XnaColor, ddPlayerColor.Width - 2, ddPlayerColor.ItemHeight + 2));
if (mpColor.Name.StartsWith("$"))
ddPlayerColor.AddItem(string.Empty, AssetLoader.CreateTexture(mpColor.XnaColor, ddPlayerColor.Width - 2, ddPlayerColor.ItemHeight));

Otherwise, some items will be partially outside the box.

A screenshot. The width of the color has been decreased to show which color is being highlighted. This is the client (bae3855) with built-in resources:

items-in-color-drop-down-are-partially-outside-the-box

Seeing the gap between the dropdown border and the color, ...

Yes, the additional 2 pixels look like a workaround for the gap, but we didn't fully succeed.

else
ddPlayerColor.AddItem(mpColor.Name, mpColor.XnaColor);
}
ddPlayerColor.AllowDropDown = false;
ddPlayerColor.SelectedIndexChanged += CopyPlayerDataFromUI;
ddPlayerColor.Tag = false;
Expand Down
12 changes: 12 additions & 0 deletions DXMainClient/Domain/Multiplayer/MultiplayerColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Rampastring.Tools;
using System;
using System.Collections.Generic;
using Localization;

namespace DTAClient.Domain.Multiplayer
{
Expand All @@ -17,6 +18,10 @@ public class MultiplayerColor

private static List<MultiplayerColor> colorList;

private static string randomColorLabel;

private static string RandomColorDefaultLabel => "Random".L10N("UI:Main:RandomColor");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static string RandomColorDefaultLabel => "Random".L10N("UI:Main:RandomColor");
private static string RandomColorDefaultLabel => "Random".L10N("Client:Main:RandomColor");

Before we merge the code into the current "develop" branch.


/// <summary>
/// Creates a new multiplayer color from data in a string array.
/// </summary>
Expand Down Expand Up @@ -68,8 +73,15 @@ public static List<MultiplayerColor> LoadColors()
}
}

var randomColorSection = gameOptionsIni.GetSection("MPColorsRandomLabel");
if (randomColorSection != null)
randomColorLabel = randomColorSection.GetStringValue("Text", null);

colorList = mpColors;
return new List<MultiplayerColor>(colorList);
}

public static string GetRandomColorLabel()
=> string.IsNullOrEmpty(randomColorLabel) ? RandomColorDefaultLabel : randomColorLabel;
}
}
6 changes: 6 additions & 0 deletions DXMainClient/Resources/DTA/GameOptions.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ReservedStartingLocationAngularVelocity=0.01
RandomColor=136,121,114 ;189,166,111 matches civilian color

; The multiplayer colors. Syntax: <Name>=R,G,B,<in-game color ID>
; To show actual colors instead of color names/labels, prefix each key with "$"

[MPColors]
Gold=255,227,140,0
Red=222,77,49,1
Expand All @@ -24,6 +26,10 @@ White=255,255,255,15
Pink=255,20,169,35
Cyan=132,239,255,59 ;,53

[MPColorsRandomLabel]
; This is the text that will appear for the "Random" option in the color drop down
Text=Random

[MultiplayerGameLobby]
; Defines if a side or multiple sides need specific DropDown values to be usable.
; Each side needs 3 entries: side name, DropDown name, and DropDown value index.
Expand Down