Skip to content

Commit

Permalink
Fix veto menu pagination (splewis#121)
Browse files Browse the repository at this point in the history
Fix map pick and veto pagination on <=7 maps.

Turns out that setting menu.Pagination = 7 won't work, since 7 is
apparently too high a number (i think there might be a miscalculation in
sourcemod on this). This can be seen by checking the return value
of calling SetMenuPagination (which will be false).

This is fixed by turning off pagination entirely if we have 7 maps or
less. I haven't added this logic to the side pick handler, as there
are never more than 2 options.

Offending code is either here:
https://github.com/alliedmodders/sourcemod/blob/237db0504c7a59e394828446af3e8ca3d53ef647/core/MenuStyle_Valve.cpp#L367
or here:
https://github.com/alliedmodders/sourcemod/blob/237db0504c7a59e394828446af3e8ca3d53ef647/core/MenuStyle_Radio.cpp#L598

* Rename functions to increase consistency

Renames some functions to increase consistency. Functions that present
menus are now:
 - GiveSidePickMenu
 - GiveMapPickMenu
 - GiveMapVetoMenu

And their handlers are:
 - SidePickMenuHandler
 - MapPickMenuHandler
 - MapVetoMenuHandler

* Rename main veto controller for clarity

Renames the main veto controller from MapVetoController to just
VetoController, for consistency with VetoFinished and AbortVeto.

Reasoning is that anything related to specific maps (veto or pick) is
now named with a "Map" prefix, while the process as a whole is just
named "Veto"

* Reorganize and introduce sections

Add a header to each section of code, and move them around, so that
they are more in line with how the usual veto process happens (i.e.
ban -> pick -> side)
  • Loading branch information
miped authored and splewis committed Mar 18, 2017
1 parent 34081e1 commit a8ce001
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 57 deletions.
2 changes: 1 addition & 1 deletion scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public Action Timer_CheckReady(Handle timer) {
if (g_GameState == GameState_PreVeto) {
if (AllTeamsReady(false)) {
ChangeState(GameState_Veto);
CreateMapVeto();
CreateVeto();
} else {
CheckReadyWaitingTimes();
}
Expand Down
137 changes: 81 additions & 56 deletions scripting/get5/mapveto.sp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Map vetoing functions
*/
public void CreateMapVeto() {
public void CreateVeto() {
if (g_MapPoolList.Length % 2 == 0) {
LogError(
"Warning, the maplist is odd number sized (%d maps), vetos may not function correctly!",
Expand All @@ -12,7 +12,13 @@ public void CreateMapVeto() {
g_VetoCaptains[MatchTeam_Team2] = GetTeamCaptain(MatchTeam_Team2);
ResetReadyStatus();
MatchTeam startingTeam = OtherMatchTeam(g_LastVetoTeam);
MapVetoController(g_VetoCaptains[startingTeam]);
VetoController(g_VetoCaptains[startingTeam]);
}

static void AbortVeto() {
Get5_MessageToAll("%t", "CaptainLeftOnVetoInfoMessage");
Get5_MessageToAll("%t", "ReadyToResumeVetoInfoMessage");
ChangeState(GameState_PreVeto);
}

public void VetoFinished() {
Expand All @@ -28,7 +34,10 @@ public void VetoFinished() {
CreateTimer(10.0, Timer_NextMatchMap);
}

public void MapVetoController(int client) {

// Main Veto Controller

public void VetoController(int client) {
if (!IsPlayer(client) || GetClientMatchTeam(client) == MatchTeam_TeamSpec) {
AbortVeto();
}
Expand Down Expand Up @@ -63,11 +72,11 @@ public void MapVetoController(int client) {

} else if (g_MatchSideType == MatchSideType_AlwaysKnife) {
g_MapSides.Push(SideChoice_KnifeRound);
MapVetoController(client);
VetoController(client);

} else if (g_MatchSideType == MatchSideType_NeverKnife) {
g_MapSides.Push(SideChoice_Team1CT);
MapVetoController(client);
VetoController(client);
}

} else if (mapsLeft == 1) {
Expand Down Expand Up @@ -101,15 +110,71 @@ public void MapVetoController(int client) {
} else if (mapsLeft + mapsPicked <= maxMaps || bo3_hack || bo2_hack) {
GiveMapPickMenu(client);
} else {
GiveVetoMenu(client);
GiveMapVetoMenu(client);
}
}

public void GiveMapPickMenu(int client) {
Menu menu = new Menu(MapPickHandler);

// Map Vetos

public void GiveMapVetoMenu(int client) {
Menu menu = new Menu(MapVetoMenuHandler);
menu.SetTitle("%T", "MapVetoBanMenuText", client);
menu.ExitButton = false;
// Don't paginate the menu if we have 7 maps or less, as they will fit
// on one page when we don't add the pagination options
if (g_MapsLeftInVetoPool.Length <= 7) {
menu.Pagination = MENU_NO_PAGINATION;
}

char mapName[PLATFORM_MAX_PATH];
for (int i = 0; i < g_MapsLeftInVetoPool.Length; i++) {
g_MapsLeftInVetoPool.GetString(i, mapName, sizeof(mapName));
menu.AddItem(mapName, mapName);
}
menu.Display(client, MENU_TIME_FOREVER);
}

public int MapVetoMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
if (action == MenuAction_Select) {
int client = param1;
char mapName[PLATFORM_MAX_PATH];
menu.GetItem(param2, mapName, sizeof(mapName));
RemoveStringFromArray(g_MapsLeftInVetoPool, mapName);

MatchTeam team = GetClientMatchTeam(client);
Get5_MessageToAll("%t", "TeamVetoedMapInfoMessage", g_FormattedTeamNames[team], mapName);

EventLogger_MapVetoed(team, mapName);

Call_StartForward(g_OnMapVetoed);
Call_PushCell(team);
Call_PushString(mapName);
Call_Finish();

VetoController(GetNextTeamCaptain(client));
g_LastVetoTeam = team;

} else if (action == MenuAction_Cancel) {
AbortVeto();

} else if (action == MenuAction_End) {
delete menu;
}
}


// Map Picks

public void GiveMapPickMenu(int client) {
Menu menu = new Menu(MapPickMenuHandler);
menu.SetTitle("%T", "MapVetoPickMenuText", client);
menu.Pagination = 7;
menu.ExitButton = false;
// Don't paginate the menu if we have 7 maps or less, as they will fit
// on one page when we don't add the pagination options
if (g_MapsLeftInVetoPool.Length <= 7) {
menu.Pagination = MENU_NO_PAGINATION;
}

char mapName[PLATFORM_MAX_PATH];
for (int i = 0; i < g_MapsLeftInVetoPool.Length; i++) {
Expand All @@ -119,7 +184,7 @@ public void GiveMapPickMenu(int client) {
menu.Display(client, MENU_TIME_FOREVER);
}

public int MapPickHandler(Menu menu, MenuAction action, int param1, int param2) {
public int MapPickMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
if (action == MenuAction_Select) {
int client = param1;
MatchTeam team = GetClientMatchTeam(client);
Expand All @@ -140,7 +205,7 @@ public int MapPickHandler(Menu menu, MenuAction action, int param1, int param2)
Call_PushString(mapName);
Call_Finish();

MapVetoController(GetNextTeamCaptain(client));
VetoController(GetNextTeamCaptain(client));

} else if (action == MenuAction_Cancel) {
AbortVeto();
Expand All @@ -150,6 +215,9 @@ public int MapPickHandler(Menu menu, MenuAction action, int param1, int param2)
}
}


// Side Picks

public void GiveSidePickMenu(int client) {
Menu menu = new Menu(SidePickMenuHandler);
menu.ExitButton = false;
Expand Down Expand Up @@ -191,7 +259,7 @@ public int SidePickMenuHandler(Menu menu, MenuAction action, int param1, int par
Get5_MessageToAll("%t", "TeamSelectSideInfoMessage", g_FormattedTeamNames[team], choice,
mapName);

MapVetoController(client);
VetoController(client);

} else if (action == MenuAction_Cancel) {
AbortVeto();
Expand All @@ -201,51 +269,8 @@ public int SidePickMenuHandler(Menu menu, MenuAction action, int param1, int par
}
}

public void GiveVetoMenu(int client) {
Menu menu = new Menu(VetoHandler);
menu.ExitButton = false;
menu.SetTitle("%T", "MapVetoBanMenuText", client);
char mapName[PLATFORM_MAX_PATH];
for (int i = 0; i < g_MapsLeftInVetoPool.Length; i++) {
g_MapsLeftInVetoPool.GetString(i, mapName, sizeof(mapName));
menu.AddItem(mapName, mapName);
}
menu.Display(client, MENU_TIME_FOREVER);
}

public int VetoHandler(Menu menu, MenuAction action, int param1, int param2) {
if (action == MenuAction_Select) {
int client = param1;
char mapName[PLATFORM_MAX_PATH];
menu.GetItem(param2, mapName, sizeof(mapName));
RemoveStringFromArray(g_MapsLeftInVetoPool, mapName);

MatchTeam team = GetClientMatchTeam(client);
Get5_MessageToAll("%t", "TeamVetoedMapInfoMessage", g_FormattedTeamNames[team], mapName);

EventLogger_MapVetoed(team, mapName);

Call_StartForward(g_OnMapVetoed);
Call_PushCell(team);
Call_PushString(mapName);
Call_Finish();

MapVetoController(GetNextTeamCaptain(client));
g_LastVetoTeam = team;

} else if (action == MenuAction_Cancel) {
AbortVeto();

} else if (action == MenuAction_End) {
delete menu;
}
}

static void AbortVeto() {
Get5_MessageToAll("%t", "CaptainLeftOnVetoInfoMessage");
Get5_MessageToAll("%t", "ReadyToResumeVetoInfoMessage");
ChangeState(GameState_PreVeto);
}
// Helpers

static int GetNumMapsLeft() {
return g_MapsLeftInVetoPool.Length;
Expand Down

0 comments on commit a8ce001

Please sign in to comment.