mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-02-17 17:41:23 +00:00
- Don't record pointers to OptionValues outside of the OptionValues table, so that they can be redefined.
SVN r3675 (trunk)
This commit is contained in:
parent
9e31ff0799
commit
36d348dba6
3 changed files with 39 additions and 38 deletions
|
@ -169,12 +169,16 @@ public:
|
||||||
int GetSelection()
|
int GetSelection()
|
||||||
{
|
{
|
||||||
double f = SELECTED_JOYSTICK->GetAxisMap(mAxis);
|
double f = SELECTED_JOYSTICK->GetAxisMap(mAxis);
|
||||||
// Map from joystick axis to menu selection.
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
||||||
for(unsigned i=0;i<mValues->mValues.Size(); i++)
|
if (opt != NULL && *opt != NULL)
|
||||||
{
|
{
|
||||||
if (fabs(f - mValues->mValues[i].Value) < FLT_EPSILON)
|
// Map from joystick axis to menu selection.
|
||||||
|
for(unsigned i = 0; i < (*opt)->mValues.Size(); i++)
|
||||||
{
|
{
|
||||||
return i;
|
if (fabs(f - (*opt)->mValues[i].Value) < FLT_EPSILON)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -182,14 +186,15 @@ public:
|
||||||
|
|
||||||
void SetSelection(int selection)
|
void SetSelection(int selection)
|
||||||
{
|
{
|
||||||
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
||||||
// Map from menu selection to joystick axis.
|
// Map from menu selection to joystick axis.
|
||||||
if ((unsigned)selection >= mValues->mValues.Size())
|
if (opt == NULL || *opt == NULL || (unsigned)selection >= (*opt)->mValues.Size())
|
||||||
{
|
{
|
||||||
selection = JOYAXIS_None;
|
selection = JOYAXIS_None;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
selection = (int)mValues->mValues[selection].Value;
|
selection = (int)(*opt)->mValues[selection].Value;
|
||||||
}
|
}
|
||||||
SELECTED_JOYSTICK->SetAxisMap(mAxis, (EJoyAxis)selection);
|
SELECTED_JOYSTICK->SetAxisMap(mAxis, (EJoyAxis)selection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,7 +509,7 @@ static void ParseOptionValue(FScanner &sc)
|
||||||
FOptionValues **pOld = OptionValues.CheckKey(optname);
|
FOptionValues **pOld = OptionValues.CheckKey(optname);
|
||||||
if (pOld != NULL && *pOld != NULL)
|
if (pOld != NULL && *pOld != NULL)
|
||||||
{
|
{
|
||||||
sc.ScriptError("Redefinition of option value set '%s'", optname.GetChars());
|
delete *pOld;
|
||||||
}
|
}
|
||||||
OptionValues[optname] = val;
|
OptionValues[optname] = val;
|
||||||
}
|
}
|
||||||
|
@ -542,7 +542,7 @@ static void ParseOptionString(FScanner &sc)
|
||||||
FOptionValues **pOld = OptionValues.CheckKey(optname);
|
FOptionValues **pOld = OptionValues.CheckKey(optname);
|
||||||
if (pOld != NULL && *pOld != NULL)
|
if (pOld != NULL && *pOld != NULL)
|
||||||
{
|
{
|
||||||
sc.ScriptError("Redefinition of option value set '%s'", optname.GetChars());
|
delete *pOld;
|
||||||
}
|
}
|
||||||
OptionValues[optname] = val;
|
OptionValues[optname] = val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ class FOptionMenuItemOptionBase : public FOptionMenuItem
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
// action is a CVAR
|
// action is a CVAR
|
||||||
FOptionValues *mValues;
|
FName mValues; // Entry in OptionValues table
|
||||||
FBaseCVar *mGrayCheck;
|
FBaseCVar *mGrayCheck;
|
||||||
int mCenter;
|
int mCenter;
|
||||||
public:
|
public:
|
||||||
|
@ -147,15 +147,7 @@ public:
|
||||||
FOptionMenuItemOptionBase(const char *label, const char *menu, const char *values, const char *graycheck, int center)
|
FOptionMenuItemOptionBase(const char *label, const char *menu, const char *values, const char *graycheck, int center)
|
||||||
: FOptionMenuItem(label, menu)
|
: FOptionMenuItem(label, menu)
|
||||||
{
|
{
|
||||||
FOptionValues **opt = OptionValues.CheckKey(values);
|
mValues = values;
|
||||||
if (opt != NULL)
|
|
||||||
{
|
|
||||||
mValues = *opt;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mValues = NULL;
|
|
||||||
}
|
|
||||||
mGrayCheck = (FBoolCVar*)FindCVar(graycheck, NULL);
|
mGrayCheck = (FBoolCVar*)FindCVar(graycheck, NULL);
|
||||||
mCenter = center;
|
mCenter = center;
|
||||||
}
|
}
|
||||||
|
@ -165,11 +157,11 @@ public:
|
||||||
if (i == OP_VALUES)
|
if (i == OP_VALUES)
|
||||||
{
|
{
|
||||||
FOptionValues **opt = OptionValues.CheckKey(newtext);
|
FOptionValues **opt = OptionValues.CheckKey(newtext);
|
||||||
if (opt != NULL)
|
mValues = newtext;
|
||||||
|
if (opt != NULL && *opt != NULL)
|
||||||
{
|
{
|
||||||
mValues = *opt;
|
|
||||||
int s = GetSelection();
|
int s = GetSelection();
|
||||||
if (s >= (int)mValues->mValues.Size()) s = 0;
|
if (s >= (int)(*opt)->mValues.Size()) s = 0;
|
||||||
SetSelection(s); // readjust the CVAR if its value is outside the range now
|
SetSelection(s); // readjust the CVAR if its value is outside the range now
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -197,13 +189,14 @@ public:
|
||||||
int overlay = grayed? MAKEARGB(96,48,0,0) : 0;
|
int overlay = grayed? MAKEARGB(96,48,0,0) : 0;
|
||||||
const char *text;
|
const char *text;
|
||||||
int Selection = GetSelection();
|
int Selection = GetSelection();
|
||||||
if (Selection < 0)
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
||||||
|
if (Selection < 0 || opt == NULL || *opt == NULL)
|
||||||
{
|
{
|
||||||
text = "Unknown";
|
text = "Unknown";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
text = mValues->mValues[Selection].Text;
|
text = (*opt)->mValues[Selection].Text;
|
||||||
}
|
}
|
||||||
screen->DrawText (SmallFont, OptionSettings.mFontColorValue, indent + CURSORSPACE, y,
|
screen->DrawText (SmallFont, OptionSettings.mFontColorValue, indent + CURSORSPACE, y,
|
||||||
text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay, TAG_DONE);
|
text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay, TAG_DONE);
|
||||||
|
@ -213,17 +206,18 @@ public:
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
bool MenuEvent (int mkey, bool fromcontroller)
|
bool MenuEvent (int mkey, bool fromcontroller)
|
||||||
{
|
{
|
||||||
if (mValues->mValues.Size() > 0)
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
||||||
|
if (opt != NULL && *opt != NULL && (*opt)->mValues.Size() > 0)
|
||||||
{
|
{
|
||||||
int Selection = GetSelection();
|
int Selection = GetSelection();
|
||||||
if (mkey == MKEY_Left)
|
if (mkey == MKEY_Left)
|
||||||
{
|
{
|
||||||
if (Selection == -1) Selection = 0;
|
if (Selection == -1) Selection = 0;
|
||||||
else if (--Selection < 0) Selection = mValues->mValues.Size()-1;
|
else if (--Selection < 0) Selection = (*opt)->mValues.Size()-1;
|
||||||
}
|
}
|
||||||
else if (mkey == MKEY_Right || mkey == MKEY_Enter)
|
else if (mkey == MKEY_Right || mkey == MKEY_Enter)
|
||||||
{
|
{
|
||||||
if (++Selection >= (int)mValues->mValues.Size()) Selection = 0;
|
if (++Selection >= (int)(*opt)->mValues.Size()) Selection = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -263,14 +257,15 @@ public:
|
||||||
int GetSelection()
|
int GetSelection()
|
||||||
{
|
{
|
||||||
int Selection = -1;
|
int Selection = -1;
|
||||||
if (mValues != NULL && mCVar != NULL && mValues->mValues.Size() > 0)
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
||||||
|
if (opt != NULL && *opt != NULL && mCVar != NULL && (*opt)->mValues.Size() > 0)
|
||||||
{
|
{
|
||||||
if (mValues->mValues[0].TextValue.IsEmpty())
|
if ((*opt)->mValues[0].TextValue.IsEmpty())
|
||||||
{
|
{
|
||||||
UCVarValue cv = mCVar->GetGenericRep(CVAR_Float);
|
UCVarValue cv = mCVar->GetGenericRep(CVAR_Float);
|
||||||
for(unsigned i=0;i<mValues->mValues.Size(); i++)
|
for(unsigned i = 0; i < (*opt)->mValues.Size(); i++)
|
||||||
{
|
{
|
||||||
if (fabs(cv.Float - mValues->mValues[i].Value) < FLT_EPSILON)
|
if (fabs(cv.Float - (*opt)->mValues[i].Value) < FLT_EPSILON)
|
||||||
{
|
{
|
||||||
Selection = i;
|
Selection = i;
|
||||||
break;
|
break;
|
||||||
|
@ -280,9 +275,9 @@ public:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UCVarValue cv = mCVar->GetGenericRep(CVAR_String);
|
UCVarValue cv = mCVar->GetGenericRep(CVAR_String);
|
||||||
for(unsigned i=0;i<mValues->mValues.Size(); i++)
|
for(unsigned i = 0; i < (*opt)->mValues.Size(); i++)
|
||||||
{
|
{
|
||||||
if (mValues->mValues[i].TextValue.CompareNoCase(cv.String) == 0)
|
if ((*opt)->mValues[i].TextValue.CompareNoCase(cv.String) == 0)
|
||||||
{
|
{
|
||||||
Selection = i;
|
Selection = i;
|
||||||
break;
|
break;
|
||||||
|
@ -296,18 +291,19 @@ public:
|
||||||
void SetSelection(int Selection)
|
void SetSelection(int Selection)
|
||||||
{
|
{
|
||||||
UCVarValue value;
|
UCVarValue value;
|
||||||
if (mValues != NULL && mCVar != NULL && mValues->mValues.Size() > 0)
|
FOptionValues **opt = OptionValues.CheckKey(mValues);
|
||||||
|
if (opt != NULL && *opt != NULL && mCVar != NULL && (*opt)->mValues.Size() > 0)
|
||||||
{
|
{
|
||||||
if (mValues->mValues[0].TextValue.IsEmpty())
|
if ((*opt)->mValues[0].TextValue.IsEmpty())
|
||||||
{
|
{
|
||||||
value.Float = (float)mValues->mValues[Selection].Value;
|
value.Float = (float)(*opt)->mValues[Selection].Value;
|
||||||
mCVar->SetGenericRep (value, CVAR_Float);
|
mCVar->SetGenericRep (value, CVAR_Float);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value.String = mValues->mValues[Selection].TextValue.LockBuffer();
|
value.String = (*opt)->mValues[Selection].TextValue.LockBuffer();
|
||||||
mCVar->SetGenericRep (value, CVAR_String);
|
mCVar->SetGenericRep (value, CVAR_String);
|
||||||
mValues->mValues[Selection].TextValue.UnlockBuffer();
|
(*opt)->mValues[Selection].TextValue.UnlockBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue