2019-11-08 22:02:52 +00:00
|
|
|
/*
|
|
|
|
** optionmenuitems.h
|
|
|
|
** Control items for option menus
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2010 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
#include "v_text.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "gstrings.h"
|
2019-11-30 09:03:20 +00:00
|
|
|
#include "v_font.h"
|
2020-04-11 21:39:40 +00:00
|
|
|
#include "cmdlib.h"
|
2020-06-20 16:01:02 +00:00
|
|
|
#include "templates.h"
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
void M_DrawConText (int color, int x, int y, const char *str);
|
|
|
|
void M_SetVideoMode();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// opens a submenu, action is a submenu name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemSubmenu : public FOptionMenuItem
|
|
|
|
{
|
|
|
|
int mParam;
|
|
|
|
public:
|
|
|
|
FOptionMenuItemSubmenu(const char *label, const char *menu, int param = 0)
|
|
|
|
: FOptionMenuItem(label, menu)
|
|
|
|
{
|
|
|
|
mParam = param;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColorMore);
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool Activate(FName caller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
M_MenuSound(CursorSound);
|
2020-06-14 16:57:55 +00:00
|
|
|
M_SetMenu(mAction, mParam, static_cast<DOptionMenu*>(CurrentMenu)->GetDescriptor()->mMenuName);
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// opens a submenu, command is a submenu name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemLabeledSubmenu : public FOptionMenuItemSubmenu
|
|
|
|
{
|
|
|
|
FBaseCVar *mLabelCVar;
|
2019-12-05 18:00:40 +00:00
|
|
|
public:
|
2019-11-29 00:28:13 +00:00
|
|
|
FOptionMenuItemLabeledSubmenu(const char * label, FBaseCVar *labelcvar, FName command, int param = 0)
|
2020-04-11 21:50:43 +00:00
|
|
|
: FOptionMenuItemSubmenu(label, command.GetChars(), param)
|
2019-11-29 00:28:13 +00:00
|
|
|
{
|
|
|
|
mLabelCVar = labelcvar;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override
|
|
|
|
{
|
|
|
|
drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor);
|
|
|
|
|
2019-12-05 18:00:40 +00:00
|
|
|
auto text = mLabelCVar? mLabelCVar->GetHumanString() : "";
|
2019-11-29 00:28:13 +00:00
|
|
|
if (text[0] == 0) text = GStrings("notset");
|
|
|
|
drawValue(indent, y, OptionSettings.mFontColorValue, text);
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Executes a CCMD, action is a CCMD name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemCommand : public FOptionMenuItemSubmenu
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FOptionMenuItemCommand(const char *label, const char *menu)
|
|
|
|
: FOptionMenuItemSubmenu(label, menu)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool Activate(FName caller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
M_MenuSound(AdvanceSound);
|
2020-04-11 21:50:43 +00:00
|
|
|
C_DoCommand(mAction.GetChars());
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-04-11 21:50:43 +00:00
|
|
|
//=============================================================================*
|
2019-11-08 22:02:52 +00:00
|
|
|
//
|
|
|
|
// Executes a CCMD after confirmation, action is a CCMD name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemSafeCommand : public FOptionMenuItemCommand
|
|
|
|
{
|
|
|
|
// action is a CCMD
|
2019-11-29 00:28:13 +00:00
|
|
|
FString mPrompt;
|
|
|
|
int mScriptId; // shouldn't be used, but just in case.
|
2019-11-08 22:02:52 +00:00
|
|
|
public:
|
2019-11-29 00:28:13 +00:00
|
|
|
FOptionMenuItemSafeCommand(const char *label, const char *menu, const char *prompt = nullptr, int scriptid = INT_MAX)
|
2019-11-08 22:02:52 +00:00
|
|
|
: FOptionMenuItemCommand(label, menu)
|
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
mPrompt = prompt;
|
|
|
|
mScriptId = scriptid;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool MenuEvent (int mkey, bool fromcontroller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (mkey == MKEY_MBYes)
|
|
|
|
{
|
2020-04-11 21:50:43 +00:00
|
|
|
C_DoCommand(mAction.GetChars());
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return FOptionMenuItemCommand::MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool Activate(FName caller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-04-10 06:32:47 +00:00
|
|
|
FString msg;
|
|
|
|
msg << GStrings.localize(mPrompt.IsNotEmpty()? mPrompt.GetChars() : "$SAFEMESSAGE") << "\n\n" << GStrings.localize("$PRESSYN");
|
2019-12-01 14:31:08 +00:00
|
|
|
auto actionLabel = GStrings.localize(mLabel.GetChars());
|
2019-11-29 00:28:13 +00:00
|
|
|
|
2020-01-03 19:37:02 +00:00
|
|
|
//FStringf FullString("%s%s%s\n\n%s", TEXTCOLOR_WHITE, actionLabel, TEXTCOLOR_NORMAL, msg);
|
2020-04-10 06:32:47 +00:00
|
|
|
FStringf FullString("- %s -\n%s", actionLabel, msg.GetChars());
|
2019-11-29 00:28:13 +00:00
|
|
|
M_StartMessage(FullString, 0, mScriptId);
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Base class for option lists
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemOptionBase : public FOptionMenuItem
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
// action is a CVAR
|
|
|
|
FName mValues; // Entry in OptionValues table
|
|
|
|
FBaseCVar *mGrayCheck;
|
|
|
|
int mCenter;
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
OP_VALUES = 0x11001
|
|
|
|
};
|
|
|
|
|
|
|
|
FOptionMenuItemOptionBase(const char *label, const char *menu, const char *values, const char *graycheck, int center)
|
|
|
|
: FOptionMenuItem(label, menu)
|
|
|
|
{
|
|
|
|
mValues = values;
|
|
|
|
mGrayCheck = (FBoolCVar*)FindCVar(graycheck, NULL);
|
|
|
|
mCenter = center;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool SetString(int i, const char *newtext) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (i == OP_VALUES)
|
|
|
|
{
|
|
|
|
FOptionValues **opt = OptionValues.CheckKey(newtext);
|
|
|
|
mValues = newtext;
|
|
|
|
if (opt != NULL && *opt != NULL)
|
|
|
|
{
|
|
|
|
int s = GetSelection();
|
|
|
|
if (s >= (int)(*opt)->mValues.Size()) s = 0;
|
|
|
|
SetSelection(s); // readjust the CVAR if its value is outside the range now
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
virtual int GetSelection() = 0;
|
|
|
|
virtual void SetSelection(int Selection) = 0;
|
|
|
|
|
|
|
|
//=============================================================================
|
2019-11-29 00:28:13 +00:00
|
|
|
int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (mCenter)
|
|
|
|
{
|
2020-05-25 15:11:32 +00:00
|
|
|
indent = (twod->GetWidth() / 2);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 00:28:13 +00:00
|
|
|
drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, isGrayed());
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
int Selection = GetSelection();
|
2019-11-29 00:28:13 +00:00
|
|
|
const char *text;
|
2019-11-08 22:02:52 +00:00
|
|
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
|
|
|
if (Selection < 0 || opt == NULL || *opt == NULL)
|
|
|
|
{
|
|
|
|
text = "Unknown";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text = (*opt)->mValues[Selection].Text;
|
|
|
|
}
|
|
|
|
if (*text == '$') text = GStrings(text + 1);
|
2019-11-29 00:28:13 +00:00
|
|
|
|
|
|
|
drawValue(indent, y, OptionSettings.mFontColorValue, text, isGrayed());
|
2019-11-08 22:02:52 +00:00
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
2019-11-29 00:28:13 +00:00
|
|
|
bool MenuEvent (int mkey, bool fromcontroller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
|
|
|
if (opt != NULL && *opt != NULL && (*opt)->mValues.Size() > 0)
|
|
|
|
{
|
|
|
|
int Selection = GetSelection();
|
|
|
|
if (mkey == MKEY_Left)
|
|
|
|
{
|
|
|
|
if (Selection == -1) Selection = 0;
|
|
|
|
else if (--Selection < 0) Selection = (*opt)->mValues.Size()-1;
|
|
|
|
}
|
|
|
|
else if (mkey == MKEY_Right || mkey == MKEY_Enter)
|
|
|
|
{
|
|
|
|
if (++Selection >= (int)(*opt)->mValues.Size()) Selection = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FOptionMenuItem::MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
|
|
|
SetSelection(Selection);
|
2019-11-29 00:28:13 +00:00
|
|
|
M_MenuSound(ChangeSound);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
virtual bool isGrayed()
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
return mGrayCheck != NULL && !(mGrayCheck->GetGenericRep(CVAR_Bool).Bool);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Selectable() override
|
|
|
|
{
|
|
|
|
return !isGrayed();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Change a CVAR, action is the CVAR name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemOption : public FOptionMenuItemOptionBase
|
|
|
|
{
|
|
|
|
// action is a CVAR
|
|
|
|
FBaseCVar *mCVar;
|
|
|
|
public:
|
|
|
|
|
|
|
|
FOptionMenuItemOption(const char *label, const char *menu, const char *values, const char *graycheck, int center)
|
|
|
|
: FOptionMenuItemOptionBase(label, menu, values, graycheck, center)
|
|
|
|
{
|
2020-04-11 21:50:43 +00:00
|
|
|
mCVar = FindCVar(mAction.GetChars(), NULL);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
2019-11-29 00:28:13 +00:00
|
|
|
int GetSelection() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
int Selection = -1;
|
|
|
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
|
|
|
if (opt != NULL && *opt != NULL && mCVar != NULL && (*opt)->mValues.Size() > 0)
|
|
|
|
{
|
|
|
|
if ((*opt)->mValues[0].TextValue.IsEmpty())
|
|
|
|
{
|
|
|
|
UCVarValue cv = mCVar->GetGenericRep(CVAR_Float);
|
|
|
|
for(unsigned i = 0; i < (*opt)->mValues.Size(); i++)
|
|
|
|
{
|
|
|
|
if (fabs(cv.Float - (*opt)->mValues[i].Value) < FLT_EPSILON)
|
|
|
|
{
|
|
|
|
Selection = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UCVarValue cv = mCVar->GetGenericRep(CVAR_String);
|
|
|
|
for(unsigned i = 0; i < (*opt)->mValues.Size(); i++)
|
|
|
|
{
|
|
|
|
if ((*opt)->mValues[i].TextValue.CompareNoCase(cv.String) == 0)
|
|
|
|
{
|
|
|
|
Selection = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Selection;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
void SetSelection(int Selection) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
UCVarValue value;
|
|
|
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
|
|
|
if (opt != NULL && *opt != NULL && mCVar != NULL && (*opt)->mValues.Size() > 0)
|
|
|
|
{
|
|
|
|
if ((*opt)->mValues[0].TextValue.IsEmpty())
|
|
|
|
{
|
|
|
|
value.Float = (float)(*opt)->mValues[Selection].Value;
|
|
|
|
mCVar->SetGenericRep (value, CVAR_Float);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value.String = (*opt)->mValues[Selection].TextValue.LockBuffer();
|
|
|
|
mCVar->SetGenericRep (value, CVAR_String);
|
|
|
|
(*opt)->mValues[Selection].TextValue.UnlockBuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// This class is used to capture the key to be used as the new key binding
|
|
|
|
// for a control item
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class DEnterKey : public DMenu
|
|
|
|
{
|
|
|
|
int *pKey;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DEnterKey(DMenu *parent, int *keyptr)
|
|
|
|
: DMenu(parent)
|
|
|
|
{
|
|
|
|
pKey = keyptr;
|
|
|
|
SetMenuMessage(1);
|
|
|
|
menuactive = MENU_WaitKey; // There should be a better way to disable GUI capture...
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool TranslateKeyboardEvents() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMenuMessage(int which)
|
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
DOptionMenu *m = static_cast<DOptionMenu*>(mParentMenu);
|
|
|
|
if (m)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
FListMenuItem *it = m->GetItem(NAME_Controlmessage);
|
|
|
|
if (it != NULL)
|
|
|
|
{
|
|
|
|
it->SetValue(0, which);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool Responder(event_t *ev) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (ev->type == EV_KeyDown)
|
|
|
|
{
|
|
|
|
*pKey = ev->data1;
|
|
|
|
menuactive = MENU_On;
|
|
|
|
SetMenuMessage(0);
|
2019-12-05 20:39:02 +00:00
|
|
|
auto p = mParentMenu;
|
2019-11-08 22:02:52 +00:00
|
|
|
Close();
|
2019-12-05 20:39:02 +00:00
|
|
|
p->MenuEvent((ev->data1 == KEY_ESCAPE)? MKEY_Abort : MKEY_Input, 0);
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
void Drawer() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
mParentMenu->Drawer();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// // Edit a key binding, Action is the CCMD to bind
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemControl : public FOptionMenuItem
|
|
|
|
{
|
|
|
|
FKeyBindings *mBindings;
|
|
|
|
int mInput;
|
|
|
|
bool mWaiting;
|
|
|
|
public:
|
|
|
|
|
|
|
|
FOptionMenuItemControl(const char *label, const char *menu, FKeyBindings *bindings)
|
|
|
|
: FOptionMenuItem(label, menu)
|
|
|
|
{
|
|
|
|
mBindings = bindings;
|
|
|
|
mWaiting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
2019-11-29 00:28:13 +00:00
|
|
|
int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
drawLabel(indent, y, mWaiting? OptionSettings.mFontColorHighlight:
|
2019-11-08 22:02:52 +00:00
|
|
|
(selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor));
|
|
|
|
|
2020-04-11 21:50:43 +00:00
|
|
|
auto binds = mBindings->GetKeysForCommand(mAction.GetChars());
|
2019-11-29 00:28:13 +00:00
|
|
|
auto description = C_NameKeys(binds.Data(), binds.Size());
|
|
|
|
|
|
|
|
if (description.Len() > 0)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
drawValue(indent, y, CR_WHITE, description);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
drawValue(indent, y, CR_BLACK, "---");
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
2019-11-29 00:28:13 +00:00
|
|
|
bool MenuEvent(int mkey, bool fromcontroller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (mkey == MKEY_Input)
|
|
|
|
{
|
|
|
|
mWaiting = false;
|
2020-04-11 21:50:43 +00:00
|
|
|
mBindings->SetBind(mInput, mAction.GetChars());
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (mkey == MKEY_Clear)
|
|
|
|
{
|
2020-04-11 21:50:43 +00:00
|
|
|
mBindings->UnbindACommand(mAction.GetChars());
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (mkey == MKEY_Abort)
|
|
|
|
{
|
|
|
|
mWaiting = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool Activate(FName caller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
M_MenuSound(AdvanceSound);
|
2019-11-08 22:02:52 +00:00
|
|
|
mWaiting = true;
|
2020-06-14 16:57:55 +00:00
|
|
|
DMenu *input = new DEnterKey(CurrentMenu, &mInput);
|
2019-11-08 22:02:52 +00:00
|
|
|
M_ActivateMenu(input);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemStaticText : public FOptionMenuItem
|
|
|
|
{
|
|
|
|
EColorRange mColor;
|
|
|
|
public:
|
2019-11-29 00:28:13 +00:00
|
|
|
FOptionMenuItemStaticText(const char *label, EColorRange color = CR_UNDEFINED)
|
2019-11-08 22:02:52 +00:00
|
|
|
: FOptionMenuItem(label, NAME_None, true)
|
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
mColor = color == CR_UNDEFINED? (EColorRange)OptionSettings.mFontColor : color;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
drawLabel(indent, y, mColor);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool Selectable() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuItemStaticTextSwitchable : public FOptionMenuItem
|
|
|
|
{
|
|
|
|
EColorRange mColor;
|
|
|
|
FString mAltText;
|
|
|
|
int mCurrent;
|
|
|
|
|
|
|
|
public:
|
2019-11-29 00:28:13 +00:00
|
|
|
FOptionMenuItemStaticTextSwitchable(const char *label, const char *label2, FName action, EColorRange color = CR_UNDEFINED)
|
2019-11-08 22:02:52 +00:00
|
|
|
: FOptionMenuItem(label, action, true)
|
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
mColor = color == CR_UNDEFINED? (EColorRange)OptionSettings.mFontColor : color;
|
2019-11-08 22:02:52 +00:00
|
|
|
mAltText = label2;
|
|
|
|
mCurrent = 0;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-01 14:31:08 +00:00
|
|
|
const char *txt = GStrings.localize(mCurrent? mAltText.GetChars() : mLabel.GetChars());
|
2019-11-29 00:28:13 +00:00
|
|
|
int w = OptionWidth(txt) * CleanXfac_1;
|
2020-05-25 15:11:32 +00:00
|
|
|
int x = (twod->GetWidth() - w) / 2;
|
2019-11-29 00:28:13 +00:00
|
|
|
drawText(x, y, mColor, txt);
|
2019-11-08 22:02:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool SetValue(int i, int val) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
mCurrent = val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool SetString(int i, const char *newtext) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
mAltText = newtext;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool Selectable() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuSliderBase : public FOptionMenuItem
|
|
|
|
{
|
|
|
|
// action is a CVAR
|
|
|
|
double mMin, mMax, mStep;
|
|
|
|
int mShowValue;
|
|
|
|
int mDrawX;
|
|
|
|
int mSliderShort;
|
|
|
|
|
|
|
|
public:
|
2019-11-29 00:28:13 +00:00
|
|
|
FOptionMenuSliderBase(const char *label, double min, double max, double step, int showval, FName command = NAME_None)
|
|
|
|
: FOptionMenuItem(label, command)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
mMin = min;
|
|
|
|
mMax = max;
|
|
|
|
mStep = step;
|
|
|
|
mShowValue = showval;
|
|
|
|
mDrawX = 0;
|
|
|
|
mSliderShort = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual double GetSliderValue() = 0;
|
|
|
|
virtual void SetSliderValue(double val) = 0;
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Draw a slider. Set fracdigits negative to not display the current value numerically.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-29 00:28:13 +00:00
|
|
|
|
|
|
|
void DrawSliderElement (int color, int x, int y, const char * str)
|
|
|
|
{
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText (twod, ConFont, color, x, y, str, DTA_CellX, 16 * CleanXfac_1, DTA_CellY, 16 * CleanYfac_1, TAG_DONE);
|
2019-11-29 00:28:13 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
void DrawSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent)
|
|
|
|
{
|
|
|
|
char textbuf[16];
|
|
|
|
double range;
|
|
|
|
int maxlen = 0;
|
2019-12-03 19:32:35 +00:00
|
|
|
int right = x + (12*16 + 4) * CleanXfac_1;
|
|
|
|
int cy = y;// +(OptionSettings.mLinespacing - 8) * CleanYfac_1;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
range = max - min;
|
|
|
|
double ccur = clamp(cur, min, max) - min;
|
|
|
|
|
|
|
|
if (fracdigits >= 0)
|
|
|
|
{
|
|
|
|
snprintf(textbuf, countof(textbuf), "%.*f", fracdigits, max);
|
2019-12-03 19:32:35 +00:00
|
|
|
maxlen = NewSmallFont->StringWidth(textbuf) * CleanXfac_1;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 15:11:32 +00:00
|
|
|
mSliderShort = right + maxlen > twod->GetWidth();
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
if (!mSliderShort)
|
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
DrawSliderElement(CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12");
|
2020-01-03 19:40:56 +00:00
|
|
|
DrawSliderElement(CR_ORANGE, x + int((5 + ((ccur * 78) / range)) * 2*CleanXfac_1), cy, "\x13");
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// On 320x200 we need a shorter slider
|
2019-11-29 00:28:13 +00:00
|
|
|
DrawSliderElement(CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12");
|
2020-01-03 19:40:56 +00:00
|
|
|
DrawSliderElement(CR_ORANGE, x + int((5 + ((ccur * 38) / range)) * 2*CleanXfac_1), cy, "\x13");
|
2019-11-08 22:02:52 +00:00
|
|
|
right -= 5*8*CleanXfac_1;
|
|
|
|
}
|
|
|
|
|
2020-05-25 15:11:32 +00:00
|
|
|
if (fracdigits >= 0 && right + maxlen <= twod->GetWidth())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
snprintf(textbuf, countof(textbuf), "%.*f", fracdigits, cur);
|
2019-11-29 00:28:13 +00:00
|
|
|
drawText(right, y, CR_DARKGRAY, textbuf);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
2019-11-29 00:28:13 +00:00
|
|
|
int Draw(FOptionMenuDescriptor *desc, int y, int indent, bool selected) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
drawLabel(indent, y, selected? OptionSettings.mFontColorSelection : OptionSettings.mFontColor);
|
2019-11-29 00:28:13 +00:00
|
|
|
mDrawX = indent + CursorSpace();
|
2019-11-08 22:02:52 +00:00
|
|
|
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent);
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
2019-11-29 00:28:13 +00:00
|
|
|
bool MenuEvent (int mkey, bool fromcontroller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
double value = GetSliderValue();
|
|
|
|
|
|
|
|
if (mkey == MKEY_Left)
|
|
|
|
{
|
|
|
|
value -= mStep;
|
|
|
|
}
|
|
|
|
else if (mkey == MKEY_Right)
|
|
|
|
{
|
|
|
|
value += mStep;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FOptionMenuItem::MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
|
|
|
SetSliderValue(clamp(value, mMin, mMax));
|
2019-11-29 00:28:13 +00:00
|
|
|
M_MenuSound(ChangeSound);
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool MouseEvent(int type, int x, int y) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-06-14 16:57:55 +00:00
|
|
|
DOptionMenu *lm = static_cast<DOptionMenu*>(CurrentMenu);
|
2019-11-08 22:02:52 +00:00
|
|
|
if (type != DMenu::MOUSE_Click)
|
|
|
|
{
|
|
|
|
if (!lm->CheckFocus(this)) return false;
|
|
|
|
}
|
|
|
|
if (type == DMenu::MOUSE_Release)
|
|
|
|
{
|
|
|
|
lm->ReleaseFocus();
|
|
|
|
}
|
|
|
|
|
2020-02-18 20:05:46 +00:00
|
|
|
int slide_left = mDrawX+16*CleanXfac_1;
|
|
|
|
int slide_right = slide_left + (10*16*CleanXfac_1 >> mSliderShort); // 10 char cells with 8 pixels each.
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
if (type == DMenu::MOUSE_Click)
|
|
|
|
{
|
|
|
|
if (x < slide_left || x >= slide_right) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = clamp(x, slide_left, slide_right);
|
|
|
|
double v = mMin + ((x - slide_left) * (mMax - mMin)) / (slide_right - slide_left);
|
|
|
|
if (v != GetSliderValue())
|
|
|
|
{
|
|
|
|
SetSliderValue(v);
|
2019-11-29 00:28:13 +00:00
|
|
|
M_MenuSound(ChangeSound);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
if (type == DMenu::MOUSE_Click)
|
|
|
|
{
|
|
|
|
lm->SetFocus(this);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuSliderCVar : public FOptionMenuSliderBase
|
|
|
|
{
|
|
|
|
FBaseCVar *mCVar;
|
|
|
|
public:
|
|
|
|
FOptionMenuSliderCVar(const char *label, const char *menu, double min, double max, double step, int showval)
|
|
|
|
: FOptionMenuSliderBase(label, min, max, step, showval)
|
|
|
|
{
|
|
|
|
mCVar = FindCVar(menu, NULL);
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
double GetSliderValue() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (mCVar != NULL)
|
|
|
|
{
|
|
|
|
return mCVar->GetGenericRep(CVAR_Float).Float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
void SetSliderValue(double val) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (mCVar != NULL)
|
|
|
|
{
|
|
|
|
UCVarValue value;
|
|
|
|
value.Float = (float)val;
|
|
|
|
mCVar->SetGenericRep(value, CVAR_Float);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuSliderVar : public FOptionMenuSliderBase
|
|
|
|
{
|
|
|
|
float *mPVal;
|
|
|
|
public:
|
|
|
|
|
|
|
|
FOptionMenuSliderVar(const char *label, float *pVal, double min, double max, double step, int showval)
|
|
|
|
: FOptionMenuSliderBase(label, min, max, step, showval)
|
|
|
|
{
|
|
|
|
mPVal = pVal;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
double GetSliderValue() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
return *mPVal;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
void SetSliderValue(double val) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
*mPVal = (float)val;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// [TP] FOptionMenuFieldBase
|
|
|
|
//
|
|
|
|
// Base class for input fields
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuFieldBase : public FOptionMenuItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FOptionMenuFieldBase ( const char* label, const char* menu, const char* graycheck ) :
|
|
|
|
FOptionMenuItem ( label, menu ),
|
2020-04-11 21:50:43 +00:00
|
|
|
mCVar ( FindCVar( mAction.GetChars(), NULL )),
|
2019-11-08 22:02:52 +00:00
|
|
|
mGrayCheck (( graycheck && strlen( graycheck )) ? FindCVar( graycheck, NULL ) : NULL ) {}
|
|
|
|
|
|
|
|
const char* GetCVarString()
|
|
|
|
{
|
|
|
|
if ( mCVar == NULL )
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return mCVar->GetGenericRep( CVAR_String ).String;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual FString Represent()
|
|
|
|
{
|
|
|
|
return GetCVarString();
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
int Draw ( FOptionMenuDescriptor*, int y, int indent, bool selected ) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
bool grayed = mGrayCheck != NULL && !( mGrayCheck->GetGenericRep( CVAR_Bool ).Bool );
|
2019-11-29 00:28:13 +00:00
|
|
|
drawLabel(indent, y, selected ? OptionSettings.mFontColorSelection : OptionSettings.mFontColor, grayed);
|
|
|
|
drawValue(indent, y, OptionSettings.mFontColorValue, Represent(), grayed);
|
2019-11-08 22:02:52 +00:00
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool GetString ( int i, char* s, int len ) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if ( i == 0 )
|
|
|
|
{
|
|
|
|
strncpy( s, GetCVarString(), len );
|
|
|
|
s[len - 1] = '\0';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool SetString ( int i, const char* s ) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if ( i == 0 )
|
|
|
|
{
|
|
|
|
if ( mCVar )
|
|
|
|
{
|
|
|
|
UCVarValue vval;
|
|
|
|
vval.String = s;
|
|
|
|
mCVar->SetGenericRep( vval, CVAR_String );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Action is a CVar in this class and derivatives.
|
|
|
|
FBaseCVar* mCVar;
|
|
|
|
FBaseCVar* mGrayCheck;
|
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// [TP] FOptionMenuTextField
|
|
|
|
//
|
|
|
|
// A text input field widget, for use with string CVars.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuTextField : public FOptionMenuFieldBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FOptionMenuTextField ( const char *label, const char* menu, const char* graycheck ) :
|
|
|
|
FOptionMenuFieldBase ( label, menu, graycheck ),
|
|
|
|
mEntering ( false ) {}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
FString Represent() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2020-01-05 11:12:14 +00:00
|
|
|
if (mEntering)
|
|
|
|
{
|
|
|
|
FString text;
|
|
|
|
text = mInput->GetText();
|
2019-11-08 22:02:52 +00:00
|
|
|
text += '_';
|
2020-01-05 11:12:14 +00:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
else return FString(GetCVarString());
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
int Draw(FOptionMenuDescriptor*desc, int y, int indent, bool selected) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if (mEntering)
|
|
|
|
{
|
|
|
|
// reposition the text so that the cursor is visible when in entering mode.
|
|
|
|
FString text = Represent();
|
2019-12-03 19:32:35 +00:00
|
|
|
int tlen = NewSmallFont->StringWidth(text) * CleanXfac_1;
|
2020-05-25 15:11:32 +00:00
|
|
|
int newindent = twod->GetWidth() - tlen - CursorSpace();
|
2019-11-08 22:02:52 +00:00
|
|
|
if (newindent < indent) indent = newindent;
|
|
|
|
}
|
|
|
|
return FOptionMenuFieldBase::Draw(desc, y, indent, selected);
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool MenuEvent ( int mkey, bool fromcontroller ) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if ( mkey == MKEY_Enter )
|
|
|
|
{
|
2019-11-29 00:28:13 +00:00
|
|
|
M_MenuSound(AdvanceSound);
|
2019-11-08 22:02:52 +00:00
|
|
|
mEntering = true;
|
2020-06-14 16:57:55 +00:00
|
|
|
mInput = new DTextEnterMenu(CurrentMenu, NewSmallFont, GetCVarString(), 256, fromcontroller );
|
2020-01-05 11:12:14 +00:00
|
|
|
M_ActivateMenu( mInput );
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if ( mkey == MKEY_Input )
|
|
|
|
{
|
|
|
|
if ( mCVar )
|
|
|
|
{
|
|
|
|
UCVarValue vval;
|
2020-01-05 11:12:14 +00:00
|
|
|
vval.String = mInput->GetText();
|
2019-11-08 22:02:52 +00:00
|
|
|
mCVar->SetGenericRep( vval, CVAR_String );
|
|
|
|
}
|
|
|
|
|
|
|
|
mEntering = false;
|
2020-01-05 11:12:14 +00:00
|
|
|
mInput = nullptr;
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if ( mkey == MKEY_Abort )
|
|
|
|
{
|
|
|
|
mEntering = false;
|
2020-01-05 11:12:14 +00:00
|
|
|
mInput = nullptr;
|
2019-11-08 22:02:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FOptionMenuItem::MenuEvent( mkey, fromcontroller );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mEntering;
|
2020-01-05 11:12:14 +00:00
|
|
|
DTextEnterMenu* mInput;
|
2019-11-08 22:02:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// [TP] FOptionMenuNumberField
|
|
|
|
//
|
|
|
|
// A numeric input field widget, for use with number CVars where sliders are inappropriate (i.e.
|
|
|
|
// where the user is interested in the exact value specifically)
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class FOptionMenuNumberField : public FOptionMenuFieldBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FOptionMenuNumberField ( const char *label, const char* menu, float minimum, float maximum,
|
|
|
|
float step, const char* graycheck )
|
|
|
|
: FOptionMenuFieldBase ( label, menu, graycheck ),
|
|
|
|
mMinimum ( minimum ),
|
|
|
|
mMaximum ( maximum ),
|
|
|
|
mStep ( step )
|
|
|
|
{
|
|
|
|
if ( mMaximum <= mMinimum )
|
|
|
|
std::swap( mMinimum, mMaximum );
|
|
|
|
|
|
|
|
if ( mStep <= 0 )
|
|
|
|
mStep = 1;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:28:13 +00:00
|
|
|
bool MenuEvent ( int mkey, bool fromcontroller ) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
if ( mCVar )
|
|
|
|
{
|
|
|
|
float value = mCVar->GetGenericRep( CVAR_Float ).Float;
|
|
|
|
|
|
|
|
if ( mkey == MKEY_Left )
|
|
|
|
{
|
|
|
|
value -= mStep;
|
|
|
|
|
|
|
|
if ( value < mMinimum )
|
|
|
|
value = mMaximum;
|
|
|
|
}
|
|
|
|
else if ( mkey == MKEY_Right || mkey == MKEY_Enter )
|
|
|
|
{
|
|
|
|
value += mStep;
|
|
|
|
|
|
|
|
if ( value > mMaximum )
|
|
|
|
value = mMinimum;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FOptionMenuItem::MenuEvent( mkey, fromcontroller );
|
|
|
|
|
|
|
|
UCVarValue vval;
|
|
|
|
vval.Float = value;
|
|
|
|
mCVar->SetGenericRep( vval, CVAR_Float );
|
2019-11-29 00:28:13 +00:00
|
|
|
M_MenuSound(ChangeSound);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
float mMinimum;
|
|
|
|
float mMaximum;
|
|
|
|
float mStep;
|
|
|
|
};
|