Skip to content

Commit

Permalink
Merge pull request misyltoad#20 from Blixibon/ez2/feature/generic-con…
Browse files Browse the repository at this point in the history
…firm-enhancement

Command-based confirm dialogs parent to current frame + support raw command strings (fixed)
  • Loading branch information
Blixibon authored Jul 17, 2023
2 parents 77647cf + 434b0fd commit d7da763
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions src/game/gamepadui/gamepadui_genericconfirmation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ CON_COMMAND( gamepadui_opengenerictextdialog, "Opens a generic text dialog.\nFor
return;
}

// TODO: Parent to current frame
new GamepadUIGenericConfirmationPanel( GamepadUI::GetInstance().GetBasePanel(), "GenericConfirmationPanel", args.Arg(1), args.Arg(2),
vgui::Panel *pParent = GamepadUI::GetInstance().GetCurrentFrame();
if (!pParent)
pParent = GamepadUI::GetInstance().GetBasePanel();

new GamepadUIGenericConfirmationPanel( pParent, "GenericConfirmationPanel", args.Arg(1), args.Arg(2),
[](){}, args.Arg(3)[0] != '0', false );
}

Expand All @@ -147,15 +150,35 @@ CON_COMMAND( gamepadui_opengenericconfirmdialog, "Opens a generic confirmation d
return;
}

// TODO: Parent to current frame
const char *pCmd = args.Arg( 4 );
new GamepadUIGenericConfirmationPanel( GamepadUI::GetInstance().GetBasePanel(), "GenericConfirmationPanel", args.Arg(1), args.Arg(2),
[pCmd]()
vgui::Panel *pParent = GamepadUI::GetInstance().GetCurrentFrame();
if (!pParent)
pParent = GamepadUI::GetInstance().GetBasePanel();

// To get the command, we just use the remaining string after the small font parameter
// This method is fairly dirty and relies a bit on guesswork, but it allows spaces and quotes to be used
// without having to worry about how the initial dialog command handles it
const char *pCmd = args.GetCommandString();
char *pSmallFont = V_strstr( pCmd, args.Arg( 3 )[0] != '0' ? " 1 " : " 0 " );
if (!pSmallFont)
{
// Look for quotes instead
pSmallFont = V_strstr( pCmd, args.Arg( 3 )[0] != '0' ? " \"1\" " : " \"0\" " );
if (pSmallFont)
pCmd += (pSmallFont - pCmd) + 5;
else
{
// Give up and use the 4th argument
pCmd = args.Arg( 4 );
}
}
else
{
// Replace '' with quotes
char szCmd[512];
V_StrSubst( pCmd, "''", "\"", szCmd, sizeof(szCmd) );
pCmd += (pSmallFont - pCmd) + 3;
}

GamepadUI::GetInstance().GetEngineClient()->ClientCmd_Unrestricted( szCmd );
new GamepadUIGenericConfirmationPanel( pParent, "GenericConfirmationPanel", args.Arg(1), args.Arg(2),
[pCmd]()
{
GamepadUI::GetInstance().GetEngineClient()->ClientCmd_Unrestricted( pCmd );
}, args.Arg(3)[0] != '0', true );
}

0 comments on commit d7da763

Please sign in to comment.