sourcemod icon indicating copy to clipboard operation
sourcemod copied to clipboard

Implement reason for menu exit on non-existent item in L4D(2)

Open dragokas opened this issue 3 years ago • 8 comments

There are at least 2 cases when menu closed:

  • when "0: Exit" item pressed
  • when the non-existent item pressed.

Is it possible to provide different reason indeces in menu callback for above cases. At the moment they returns identical result:

MenuAction_Cancel. Reason: -3
MenuAction_End. Reason: -4
public void OnPluginStart()
{
	RegConsoleCmd("sm_gun", CmdGunMenu);
}

public Action CmdGunMenu(int client, int argc)
{
	Menu menu = new Menu(MenuHandler_MenuRoot, MENU_ACTIONS_DEFAULT);	
	menu.SetTitle("Weapon_choose");
	menu.AddItem("1", "Take_set");
	menu.Display(client, MENU_TIME_FOREVER);
	return Plugin_Handled;
}

public int MenuHandler_MenuRoot(Menu menu, MenuAction action, int param1, int param2)
{
	switch( action )
	{
		case MenuAction_End:
		{
			PrintToChatAll("MenuAction_End. Reason: %i", param1);
			delete menu;
		}
		
		case MenuAction_Cancel:
		{
			PrintToChatAll("MenuAction_Cancel. Reason: %i", param2);
		}
	}
}

dragokas avatar Nov 11 '21 00:11 dragokas

What game / SM version is this on?

(Please always use the template, that is why it is there.)

asherkin avatar Nov 11 '21 00:11 asherkin

Left 4 Dead 1 & 2 SM 1.11.0.6806

dragokas avatar Nov 11 '21 15:11 dragokas

I'm not a huge fan of implementing a new cancel reason that'll only ever be used on these two games (see #1543).

Why do you want to be able to distinguish between an invalid selection and exit?

asherkin avatar Nov 11 '21 15:11 asherkin

To be able to re-display menu in case player accidentally pressed the wrong button causing menu close. It is very important for a system with a lot of sub-menus, where player can easily misprint and will be forced to select all steps in each sub-menus again.

dragokas avatar Nov 11 '21 16:11 dragokas

That seems like something that could just be handled in SM instead - it'd at least be close to the other games behaviour of ignoring the selection that way, and we've got all the logic to re-display menus already.

asherkin avatar Nov 11 '21 16:11 asherkin

Personally, I would vote for your proposal. I can't find any good case where one intentionally may want to press the wrong (non-existent) button.

dragokas avatar Nov 11 '21 16:11 dragokas

Fancy taking a shot at implementing it? I think it should just be changing the behaviour of ItemSel_None.

asherkin avatar Nov 11 '21 16:11 asherkin

Maybe.

https://github.com/dragokas/sourcemod/blob/257535daf216704bbae7b30d104d4f76d50602d0/core/MenuStyle_Base.cpp#L371

Do you think I should just return from function when

type == ItemSel_None

No need to release some objects, like "Clear states" code a bit below?

dragokas avatar Nov 11 '21 16:11 dragokas