GlowPuff / ImperialCommander2

A companion app for the Imperial Assault board game.
MIT License
88 stars 12 forks source link

Feature Request: Show tile count when more than one tile is needed in mission setup (TileInfoPopup.cs?) #55

Closed MrRosendahl closed 9 months ago

MrRosendahl commented 10 months ago

My feature request is simply to add a count when a tile is needed more than once i the mission setup to make it easier to read.

This will:

The tile examples below are not from a specific setup and may not be the correct number of tiles, they are used as an example.

Instead of showing the tiles as they are displayed now.

Core 7     Core 10      Core 18         Core 22     Core 22     Core 22
Core 25    Core 25      Core 26         Core 26     Core 32     Core 35
Core 36    Core 36      Core 38

Add a tile count, but only when a specific tile is needed more than once to make it/them stand outand:

Core 7          Core 10     Core 18     Core 22 x 3     Core 25 x 2
Core 26 x 2     Core 32     Core 35     Core 36 x 2     Core 38

I believe this is done in the TileInfoPopup.cs and can be done with the following code:

//sort tiles by number
tiles = tiles.OrderBy(x => int.Parse(x.Split(' ')[1])).ToArray();

// Group tiles by name
var groupedTiles = tiles.GroupBy(x => x);

foreach (var group in groupedTiles)
{
        GameObject go = new GameObject("content item");
        go.layer = 5;
        go.transform.SetParent(container);
        go.transform.localPosition = Vector2.zero;
        go.transform.localScale = Vector3.one;
        go.transform.localEulerAngles = Vector3.zero;

        TextMeshProUGUI nt = go.AddComponent<TextMeshProUGUI>();
        nt.color = Color.white;
        nt.fontSize = 25;
        nt.alignment = TextAlignmentOptions.Center;
        nt.horizontalAlignment = HorizontalAlignmentOptions.Left;

        // Display a count when more than one tile is needed
        if (group.Count() > 1)
        {
                nt.text = $"{group.Key} x {group.Count()}";
        }
        else
        {
                nt.text = group.Key;
        }
}
MrRosendahl commented 10 months ago

I've created a pull request #56 for this feature request.

GlowPuff commented 9 months ago

Merged this in a week or so ago, thank you for your contribution!