Added optional prompt argument to MENUDEF's SafeCommand

This commit is contained in:
yqco 2016-07-27 15:52:33 -06:00 committed by Christoph Oelckers
parent 3d9591229e
commit 58a6d7df1f
2 changed files with 28 additions and 3 deletions

View file

@ -781,7 +781,15 @@ static void ParseOptionMenuBody(FScanner &sc, FOptionMenuDescriptor *desc)
FString label = sc.String;
sc.MustGetStringName(",");
sc.MustGetString();
FOptionMenuItem *it = new FOptionMenuItemSafeCommand(label, sc.String);
FString command = sc.String;
FString prompt;
// Check for optional custom prompt
if (sc.CheckString(","))
{
sc.MustGetString();
prompt = sc.String;
}
FOptionMenuItem *it = new FOptionMenuItemSafeCommand(label, command, prompt);
desc->mItems.Push(it);
}
else if (sc.Compare("Control") || sc.Compare("MapControl"))

View file

@ -103,10 +103,23 @@ public:
class FOptionMenuItemSafeCommand : public FOptionMenuItemCommand
{
// action is a CCMD
protected:
char *mPrompt;
public:
FOptionMenuItemSafeCommand(const char *label, const char *menu)
FOptionMenuItemSafeCommand(const char *label, const char *menu, const char *prompt)
: FOptionMenuItemCommand(label, menu)
, mPrompt(nullptr)
{
if (prompt && *prompt)
{
mPrompt = copystring(prompt);
}
}
~FOptionMenuItemSafeCommand()
{
if (mPrompt != NULL) delete[] mPrompt;
}
bool MenuEvent (int mkey, bool fromcontroller)
@ -121,7 +134,11 @@ public:
bool Activate()
{
const char *msg = GStrings("SAFEMESSAGE");
const char *msg = mPrompt ? mPrompt : "$SAFEMESSAGE";
if (*msg == '$')
{
msg = GStrings(msg + 1);
}
const char *actionLabel = mLabel;
if (actionLabel != NULL)