Skip to content

Commit

Permalink
Allow option to sort map list
Browse files Browse the repository at this point in the history
  • Loading branch information
devo1929 committed Apr 21, 2022
1 parent 9f7ee80 commit 0a9f9d0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ClientCore/Settings/UserINISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ protected UserINISettings(IniFile iniFile)
AllowPrivateMessagesFromState = new IntSetting(iniFile, MULTIPLAYER, "AllowPrivateMessagesFromState", (int)AllowPrivateMessagesFromEnum.All);
EnableMapSharing = new BoolSetting(iniFile, MULTIPLAYER, "EnableMapSharing", true);
AlwaysDisplayTunnelList = new BoolSetting(iniFile, MULTIPLAYER, "AlwaysDisplayTunnelList", false);
MapSortState = new IntSetting(iniFile, MULTIPLAYER, "MapSortState", (int)SortDirection.None);

CheckForUpdates = new BoolSetting(iniFile, OPTIONS, "CheckforUpdates", true);

Expand Down Expand Up @@ -208,6 +209,8 @@ protected UserINISettings(IniFile iniFile)
public BoolSetting EnableMapSharing { get; private set; }

public BoolSetting AlwaysDisplayTunnelList { get; private set; }

public IntSetting MapSortState { get; private set; }

/*********************/
/* GAME LIST FILTERS */
Expand Down
75 changes: 66 additions & 9 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ClientCore.Enums;
using DTAClient.DXGUI.Multiplayer.CnCNet;
using DTAClient.Online;
using DTAClient.Online.EventArguments;
Expand Down Expand Up @@ -128,6 +129,8 @@ protected GameModeMap GameModeMap
protected XNAContextMenu mapContextMenu;
private XNAContextMenuItem toggleFavoriteItem;

protected XNAClientStateButton<SortDirection> btnMapSortAlphabetically;

protected XNASuggestionTextBox tbMapSearch;

protected List<PlayerInfo> Players = new List<PlayerInfo>();
Expand Down Expand Up @@ -251,6 +254,8 @@ public override void Initialize()
ddGameModeMapFilter.AddItem(CreateGameFilterItem(gm.UIName, new GameModeMapFilter(GetGameModeMaps(gm))));

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

InitBtnMapSort();

tbMapSearch = FindChild<XNASuggestionTextBox>(nameof(tbMapSearch));
tbMapSearch.InputReceived += TbMapSearch_InputReceived;
Expand All @@ -264,8 +269,30 @@ public override void Initialize()
InitializeGameOptionPresetUI();
}

private void InitializeGameOptionPresetUI()
/// <summary>
/// Until the GUICreator can handle typed classes, this must remain manually done.
/// </summary>
private void InitBtnMapSort()
{
btnMapSortAlphabetically = new XNAClientStateButton<SortDirection>(WindowManager, new Dictionary<SortDirection, Texture2D>()
{
{ SortDirection.None, AssetLoader.LoadTexture("sortAlphaNone.png") },
{ SortDirection.Asc, AssetLoader.LoadTexture("sortAlphaAsc.png") },
{ SortDirection.Desc, AssetLoader.LoadTexture("sortAlphaDesc.png") },
});
btnMapSortAlphabetically.Name = nameof(btnMapSortAlphabetically);
btnMapSortAlphabetically.ClientRectangle = new Rectangle(
ddGameModeMapFilter.X + -ddGameModeMapFilter.Height - 4, ddGameModeMapFilter.Y,
ddGameModeMapFilter.Height, ddGameModeMapFilter.Height
);
btnMapSortAlphabetically.LeftClick += BtnMapSortAlphabetically_LeftClick;
btnMapSortAlphabetically.SetToolTipText("Sort Maps Alphabetically".L10N("UI:Main:MapSortAlphabeticallyToolTip"));
RefreshMapSortAlphabeticallyBtn();
AddChild(btnMapSortAlphabetically);
}

private void InitializeGameOptionPresetUI()
{
BtnSaveLoadGameOptions = FindChild<XNAClientButton>(nameof(BtnSaveLoadGameOptions), true);

if (BtnSaveLoadGameOptions != null)
Expand Down Expand Up @@ -297,7 +324,22 @@ private void InitializeGameOptionPresetUI()

AddChild(loadSaveGameOptionsMenu);
AddChild(loadOrSaveGameOptionPresetWindow);
}
}
}

private void BtnMapSortAlphabetically_LeftClick(object sender, EventArgs e)
{
UserINISettings.Instance.MapSortState.Value = (int)btnMapSortAlphabetically.GetState();

RefreshMapSortAlphabeticallyBtn();
UserINISettings.Instance.SaveSettings();
ListMaps();
}

private void RefreshMapSortAlphabeticallyBtn()
{
if (Enum.IsDefined(typeof(SortDirection), UserINISettings.Instance.MapSortState.Value))
btnMapSortAlphabetically.SetState((SortDirection)UserINISettings.Instance.MapSortState.Value);
}

private static XNADropDownItem CreateGameFilterItem(string text, GameModeMapFilter filter)
Expand All @@ -321,10 +363,10 @@ private void RefreshBthPlayerExtraOptionsOpenTexture()
{
if (btnPlayerExtraOptionsOpen != null)
{
var texture = GetPlayerExtraOptions().IsDefault() ? "comboBoxArrow.png" : "comboBoxArrow-highlight.png";
btnPlayerExtraOptionsOpen.IdleTexture = AssetLoader.LoadTexture(texture);
btnPlayerExtraOptionsOpen.HoverTexture = AssetLoader.LoadTexture(texture);
}
var texture = GetPlayerExtraOptions().IsDefault() ? "comboBoxArrow.png" : "comboBoxArrow-highlight.png";
btnPlayerExtraOptionsOpen.IdleTexture = AssetLoader.LoadTexture(texture);
btnPlayerExtraOptionsOpen.HoverTexture = AssetLoader.LoadTexture(texture);
}
}

protected void HandleGameOptionPresetSaveCommand(GameOptionPresetEventArgs e) => HandleGameOptionPresetSaveCommand(e.PresetName);
Expand Down Expand Up @@ -432,6 +474,22 @@ private void AddPlayerExtraOptionForcedNotice(bool disabled, string type)
string.Format("The game host has disabled {0}".L10N("UI:Main:HostDisableSection"), type) :
string.Format("The game host has enabled {0}".L10N("UI:Main:HostEnableSection"), type));

private List<GameModeMap> GetSortedGameModeMaps()
{
var gameModeMaps = gameModeMapFilter.GetGameModeMaps();
switch ((SortDirection)UserINISettings.Instance.MapSortState.Value)
{
case SortDirection.Asc:
gameModeMaps = gameModeMaps.OrderBy(gmm => gmm.Map.Name).ToList();
break;
case SortDirection.Desc:
gameModeMaps = gameModeMaps.OrderByDescending(gmm => gmm.Map.Name).ToList();
break;
}

return gameModeMaps;
}

protected void ListMaps()
{
lbGameModeMapList.SelectedIndexChanged -= LbGameModeMapList_SelectedIndexChanged;
Expand All @@ -444,9 +502,8 @@ protected void ListMaps()
int mapIndex = -1;
int skippedMapsCount = 0;

var gameModeMaps = gameModeMapFilter.GetGameModeMaps();
var isFavoriteMapsSelected = IsFavoriteMapsSelected();
var maps = gameModeMaps.OrderBy(gmm => gmm.Map.Name).ToList();
var maps = GetSortedGameModeMaps();

for (int i = 0; i < maps.Count; i++)
{
Expand Down Expand Up @@ -2016,7 +2073,7 @@ private void ApplyForcedDropDownOptions(List<GameLobbyDropDown> optionList,
protected string AILevelToName(int aiLevel)
{
return ProgramConstants.GetAILevelName(aiLevel);
}
}

protected GameType GetGameType()
{
Expand Down

0 comments on commit 0a9f9d0

Please sign in to comment.