Skip to content

Commit

Permalink
Allow Clients To Sort Map List
Browse files Browse the repository at this point in the history
  • Loading branch information
Deaod committed Dec 27, 2023
1 parent 8fd1b3a commit 921c632
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Classes/VS_ClientSettings.uc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ enum ETheme {
TH_Black
};

enum EMapListSort {
MLS_Name,
MLS_Recency,
MLS_PlayCount
};

var config ETheme Theme;
var config EMapListSort MapListSort;

var config float MenuX;
var config float MenuY;
Expand All @@ -25,8 +32,18 @@ static final function ETheme IntToTheme(int A) {
return default.Theme;
}

static final function EMapListSort IntToMapListSort(int A) {
switch(A) {
case 0: return MLS_Name;
case 1: return MLS_Recency;
case 2: return MLS_PlayCount;
}
return default.MapListSort;
}

defaultproperties {
Theme=TH_Bright
MapListSort=MLS_Name;

MenuX=-1.0
MenuY=-1.0
Expand Down
21 changes: 21 additions & 0 deletions Classes/VS_UI_ClientSettingsPage.uc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ var localized string ThemeBright;
var localized string ThemeDark;
var localized string ThemeBlack;

var VS_UI_ComboControl Cmb_MapListSort;
var localized string MapListSortText;
var localized string MapListSortName;
var localized string MapListSortRecency;
var localized string MapListSortPlayCount;

function Created() {
super.Created();

Expand All @@ -17,6 +23,13 @@ function Created() {
Cmb_Theme.AddItem(ThemeDark);
Cmb_Theme.AddItem(ThemeBlack);
Cmb_Theme.SetEditable(false);

Cmb_MapListSort = VS_UI_ComboControl(CreateControl(class'VS_UI_ComboControl', 8, 28, 188, 16));
Cmb_MapListSort.SetText(MapListSortText);
Cmb_MapListSort.AddItem(MapListSortName);
Cmb_MapListSort.AddItem(MapListSortRecency);
Cmb_MapListSort.AddItem(MapListSortPlayCount);
Cmb_MapListSort.SetEditable(false);
}

function LoadSettings(VS_PlayerChannel C) {
Expand All @@ -25,21 +38,29 @@ function LoadSettings(VS_PlayerChannel C) {
Settings = C.Settings;

Cmb_Theme.SetSelectedIndex(Settings.Theme);
Cmb_MapListSort.SetSelectedIndex(Settings.MapListSort);
}

function SaveSettings() {
Settings.Theme = Settings.IntToTheme(Cmb_Theme.GetSelectedIndex());
Settings.MapListSort = Settings.IntToMapListSort(Cmb_MapListSort.GetSelectedIndex());

Settings.SaveConfig();
}

function ApplyTheme() {
Cmb_Theme.Theme = Theme;
Cmb_MapListSort.Theme = Theme;
}

defaultproperties {
ThemeText="Theme"
ThemeBright="Bright"
ThemeDark="Dark"
ThemeBlack="Black"

MapListSortText="Sort Map List By"
MapListSortName="Name"
MapListSortRecency="Recency"
MapListSortPlayCount="Play Count"
}
26 changes: 25 additions & 1 deletion Classes/VS_UI_MapListItem.uc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,32 @@ class VS_UI_MapListItem extends VS_UI_ListItem;
var VS_Map MapRef;
var bool bFilteredOut;

// Sentinel Only
var byte SortMode;

function int Compare(UWindowList T, UWindowList B) {
if (Caps(VS_UI_MapListItem(T).MapRef.MapName) < Caps(VS_UI_MapListItem(B).MapRef.MapName))
local VS_Map M1, M2;

M1 = VS_UI_MapListItem(T).MapRef;
M2 = VS_UI_MapListItem(B).MapRef;

switch(VS_UI_MapListItem(Sentinel).SortMode) {
case 1:
if (M1.Sequence > M2.Sequence)
return -1;
else if (M1.Sequence < M2.Sequence)
return 1;
break;

case 2:
if (M1.PlayCount > M2.PlayCount)
return -1;
else if (M1.PlayCount < M2.PlayCount)
return 1;
break;
}

if (Caps(M1.MapName) < Caps(M2.MapName))
return -1;

return 1;
Expand Down
12 changes: 11 additions & 1 deletion Classes/VS_UI_VoteClientWindow.uc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class VS_UI_VoteClientWindow extends UWindowDialogClientWindow;
var VS_PlayerChannel Channel;
var VS_ClientSettings Settings;
var int ActiveTheme;
var byte PreviousMapListSort;

var VS_UI_CategoryTabItem ActiveCategory;
var VS_Preset ActivePreset;
Expand Down Expand Up @@ -112,6 +113,8 @@ function BeforePaint(Canvas C, float MouseX, float MouseY) {
UpdateCandidateList(Info);
UpdatePlayerList(Info);

PreviousMapListSort = Settings.MapListSort;

CategoryTabs.WinWidth = WinWidth;

if (ChatEdit.EditBox.bControlDown)
Expand Down Expand Up @@ -231,7 +234,11 @@ function UpdateActivePreset(VS_Info Info) {
local VS_Map M;
local bool bEnable;

if (Presets.SelectedPreset != ActivePreset || bWasAdmin != bAdmin || NumPlayers != PreviousNumPlayers) {
if (Presets.SelectedPreset != ActivePreset ||
bWasAdmin != bAdmin ||
PreviousNumPlayers != NumPlayers ||
PreviousMapListSort != Settings.MapListSort
) {
ActivePreset = Presets.SelectedPreset;
MapListBox.Items.Clear();

Expand All @@ -246,6 +253,9 @@ function UpdateActivePreset(VS_Info Info) {
bEnable = true;
MapListBox.AppendMap(M, bEnable);
}

VS_UI_MapListItem(MapListBox.Items).SortMode = Settings.MapListSort;
MapListBox.Items.Sort();
}
}

Expand Down
Binary file modified Docs/ClientSettings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions System/VoteSys.int
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ ThemeText="Theme"
ThemeBright="Bright"
ThemeDark="Dark"
ThemeBlack="Black"
MapListSortText="Sort Map List By"
MapListSortName="Name"
MapListSortRecency="Recency"
MapListSortPlayCount="Play Count"

[VS_UI_SettingsWindow]
WindowTitle="VoteSys Settings"
Expand Down

0 comments on commit 921c632

Please sign in to comment.