- exported more parts of the joystick menus and also exported all strings for them to the string table.

- exported the skeleton definition for list menus.
This commit is contained in:
Christoph Oelckers 2017-02-13 17:45:03 +01:00
commit 7877bcbdcb
11 changed files with 347 additions and 327 deletions

View file

@ -40,19 +40,23 @@
class OptionMenuSliderJoySensitivity : OptionMenuSliderBase
{
void Init(String label, double min, double max, double step, int showval)
JoystickConfig mJoy;
OptionMenuSliderJoySensitivity Init(String label, double min, double max, double step, int showval, JoystickConfig joy)
{
Super.Init(label, min, max, step, showval);
mJoy = joy;
return self;
}
override double GetSliderValue()
{
return Menu.GetCurrentJoystickConfig().GetSensitivity();
return mJoy.GetSensitivity();
}
override void SetSliderValue(double val)
{
Menu.GetCurrentJoystickConfig().SetSensitivity(val);
mJoy.SetSensitivity(val);
}
}
@ -66,24 +70,27 @@ class OptionMenuSliderJoyScale : OptionMenuSliderBase
{
int mAxis;
int mNeg;
void Init(String label, int axis, double min, double max, double step, int showval)
JoystickConfig mJoy;
OptionMenuSliderJoyScale Init(String label, int axis, double min, double max, double step, int showval, JoystickConfig joy)
{
Super.Init(label, min, max, step, showval);
mAxis = axis;
mNeg = 1;
mJoy = joy;
return self;
}
override double GetSliderValue()
{
double d = Menu.GetCurrentJoystickConfig().GetAxisScale(mAxis);
double d = mJoy.GetAxisScale(mAxis);
mNeg = d < 0? -1:1;
return d;
}
override void SetSliderValue(double val)
{
Menu.GetCurrentJoystickConfig().SetAxisScale(mAxis, val * mNeg);
mJoy.SetAxisScale(mAxis, val * mNeg);
}
}
@ -97,25 +104,27 @@ class OptionMenuSliderJoyDeadZone : OptionMenuSliderBase
{
int mAxis;
int mNeg;
JoystickConfig mJoy;
void Init(String label, int axis, double min, double max, double step, int showval)
OptionMenuSliderJoyDeadZone Init(String label, int axis, double min, double max, double step, int showval, JoystickConfig joy)
{
Super.Init(label, min, max, step, showval);
mAxis = axis;
mNeg = 1;
mJoy = joy;
return self;
}
override double GetSliderValue()
{
double d = Menu.GetCurrentJoystickConfig().GetAxisDeadZone(mAxis);
double d = mJoy.GetAxisDeadZone(mAxis);
mNeg = d < 0? -1:1;
return d;
}
override void SetSliderValue(double val)
{
Menu.GetCurrentJoystickConfig().SetAxisDeadZone(mAxis, val * mNeg);
mJoy.SetAxisDeadZone(mAxis, val * mNeg);
}
}
@ -128,16 +137,19 @@ class OptionMenuSliderJoyDeadZone : OptionMenuSliderBase
class OptionMenuItemJoyMap : OptionMenuItemOptionBase
{
int mAxis;
void Init(String label, int axis, Name values, int center)
JoystickConfig mJoy;
OptionMenuItemJoyMap Init(String label, int axis, Name values, int center, JoystickConfig joy)
{
Super.Init(label, 'none', values, null, center);
mAxis = axis;
mJoy = joy;
return self;
}
override int GetSelection()
{
double f = Menu.GetCurrentJoystickConfig().GetAxisMap(mAxis);
double f = mJoy.GetAxisMap(mAxis);
let opt = OptionValues.GetCount(mValues);
if (opt > 0)
{
@ -165,7 +177,7 @@ class OptionMenuItemJoyMap : OptionMenuItemOptionBase
{
selection = int(OptionValues.GetValue(mValues, selection));
}
Menu.GetCurrentJoystickConfig().SetAxisMap(mAxis, selection);
mJoy.SetAxisMap(mAxis, selection);
}
}
@ -178,25 +190,27 @@ class OptionMenuItemJoyMap : OptionMenuItemOptionBase
class OptionMenuItemInverter : OptionMenuItemOptionBase
{
int mAxis;
void Init(String label, int axis, int center)
JoystickConfig mJoy;
OptionMenuItemInverter Init(String label, int axis, int center, JoystickConfig joy)
{
Super.Init(label, "none", "YesNo", NULL, center);
mAxis = axis;
mJoy = joy;
return self;
}
override int GetSelection()
{
float f = Menu.GetCurrentJoystickConfig().GetAxisScale(mAxis);
float f = mJoy.GetAxisScale(mAxis);
return f > 0? 0:1;
}
override void SetSelection(int Selection)
{
let f = abs(Menu.GetCurrentJoystickConfig().GetAxisScale(mAxis));
let f = abs(mJoy.GetAxisScale(mAxis));
if (Selection) f*=-1;
Menu.GetCurrentJoystickConfig().SetAxisScale(mAxis, f);
mJoy.SetAxisScale(mAxis, f);
}
}
@ -209,17 +223,90 @@ class OptionMenuItemInverter : OptionMenuItemOptionBase
class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu
{
JoystickConfig mJoy;
void Init(String label = "", JoystickConfig joy = null)
OptionMenuItemJoyConfigMenu Init(String label, JoystickConfig joy)
{
Super.Init(label, "JoystickConfigMenu");
mJoy = joy;
return self;
}
override bool Activate()
{
//UpdateJoystickConfigMenu(mJoy);
return Super.Activate();
let desc = OptionMenuDescriptor(MenuDescriptor.GetDescriptor('JoystickConfigMenu'));
if (desc != NULL)
{
SetController(OptionMenuDescriptor(desc), mJoy);
}
let res = Super.Activate();
let joymenu = JoystickConfigMenu(Menu.GetCurrentMenu());
if (res && joymenu != null) joymenu.mJoy = mJoy;
return res;
}
static void SetController(OptionMenuDescriptor opt, JoystickConfig joy)
{
OptionMenuItem it;
opt.mItems.Clear();
if (joy == NULL)
{
opt.mTitle = "$JOYMNU_CONFIG";
it = new("OptionMenuItemStaticText").Init("$JOYMNU_INVALID", false);
opt.mItems.Push(it);
}
else
{
it = new("OptionMenuItemStaticText").Init(joy.GetName(), false);
it = new("OptionMenuItemStaticText").Init("", false);
it = new("OptionMenuSliderJoySensitivity").Init("$JOYMNU_OVRSENS", 0, 2, 0.1, 3, joy);
opt.mItems.Push(it);
it = new("OptionMenuItemStaticText").Init(" ", false);
opt.mItems.Push(it);
if (joy.GetNumAxes() > 0)
{
it = new("OptionMenuItemStaticText").Init("$JOYMNU_AXIS", true);
opt.mItems.Push(it);
for (int i = 0; i < joy.GetNumAxes(); ++i)
{
it = new("OptionMenuItemStaticText").Init(" ", false);
opt.mItems.Push(it);
it = new("OptionMenuItemJoyMap").Init(joy.GetAxisName(i), i, "JoyAxisMapNames", false, joy);
opt.mItems.Push(it);
it = new("OptionMenuSliderJoyScale").Init("$JOYMNU_OVRSENS", i, 0, 4, 0.1, 3, joy);
opt.mItems.Push(it);
it = new("OptionMenuItemInverter").Init("$JOYMNU_INVERT", i, false, joy);
opt.mItems.Push(it);
it = new("OptionMenuSliderJoyDeadZone").Init("$JOYMNU_DEADZONE", i, 0, 0.9, 0.05, 3, joy);
opt.mItems.Push(it);
}
}
else
{
it = new("OptionMenuItemStaticText").Init("$JOYMNU_NOAXES", false);
opt.mItems.Push(it);
}
}
opt.mScrollPos = 0;
opt.mSelectedItem = -1;
opt.mIndent = 0;
opt.mPosition = -25;
opt.CalcIndent();
}
}
//=============================================================================
//
//
//
//=============================================================================
class JoystickConfigMenu : OptionMenu
{
JoystickConfig mJoy;
}

View file

@ -0,0 +1,108 @@
class ListMenuDescriptor : MenuDescriptor native
{
native Array<ListMenuItem> mItems;
native int mSelectedItem;
native int mSelectOfsX;
native int mSelectOfsY;
native TextureID mSelector;
native int mDisplayTop;
native int mXpos, mYpos;
native int mWLeft, mWRight;
native int mLinespacing; // needs to be stored for dynamically created menus
native int mAutoselect; // this can only be set by internal menu creation functions
native Font mFont;
native int mFontColor;
native int mFontColor2;
native bool mCenter;
void Reset()
{
// Reset the default settings (ignore all other values in the struct)
mSelectOfsX = 0;
mSelectOfsY = 0;
mSelector.SetInvalid();
mDisplayTop = 0;
mXpos = 0;
mYpos = 0;
mLinespacing = 0;
mNetgameMessage = "";
mFont = NULL;
mFontColor = Font.CR_UNTRANSLATED;
mFontColor2 = Font.CR_UNTRANSLATED;
}
}
//=============================================================================
//
// list menu class runs a menu described by a DListMenuDescriptor
//
//=============================================================================
class ListMenu : Menu native
{
native ListMenuDescriptor mDesc;
native MenuItemBase mFocusControl;
virtual void Init(Menu parent = NULL, ListMenuDescriptor desc = NULL)
{
mParentMenu = parent;
mDesc = desc;
if (desc.mCenter)
{
int center = 160;
for(int i=0; i < mDesc.mItems.Size(); i++)
{
int xpos = mDesc.mItems[i].GetX();
int width = mDesc.mItems[i].GetWidth();
int curx = mDesc.mSelectOfsX;
if (width > 0 && mDesc.mItems[i].Selectable())
{
int left = 160 - (width - curx) / 2 - curx;
if (left < center) center = left;
}
}
for(int i=0;i<mDesc.mItems.Size(); i++)
{
int width = mDesc.mItems[i].GetWidth();
if (width > 0)
{
mDesc.mItems[i].SetX(center);
}
}
}
}
MenuItemBase GetItem(Name name)
{
for(int i = 0; i < mDesc.mItems.Size(); i++)
{
Name nm = mDesc.mItems[i].GetAction();
if (nm == name) return mDesc.mItems[i];
}
return NULL;
}
//bool Responder (InputEvent ev);
//bool MenuEvent (int mkey, bool fromcontroller);
//bool MouseEvent(int type, int x, int y);
//void Ticker ();
//void Drawer ();
override void SetFocus(MenuItemBase fc)
{
mFocusControl = fc;
}
override bool CheckFocus(MenuItemBase fc)
{
return mFocusControl == fc;
}
override void ReleaseFocus()
{
mFocusControl = NULL;
}
}

View file

@ -41,6 +41,11 @@ struct JoystickConfig native
native int GetAxisMap(int axis);
native void SetAxisMap(int axis, int gameaxis);
native String GetName();
native int GetNumAxes();
native String GetAxisName(int axis);
}
class Menu : Object native
@ -91,7 +96,6 @@ class Menu : Object native
native static int MenuTime();
native static void SetVideoMode();
native static Menu GetCurrentMenu();
native static JoystickConfig GetCurrentJoystickConfig();
native static void SetMenu(Name mnu, int param = 0);
native static void StartMessage(String msg, int mode = 0, Name command = 'none');
@ -131,73 +135,3 @@ class MenuDescriptor : Object native
native static MenuDescriptor GetDescriptor(Name n);
}
class ListMenuDescriptor : MenuDescriptor native
{
native Array<ListMenuItem> mItems;
native int mSelectedItem;
native int mSelectOfsX;
native int mSelectOfsY;
native TextureID mSelector;
native int mDisplayTop;
native int mXpos, mYpos;
native int mWLeft, mWRight;
native int mLinespacing; // needs to be stored for dynamically created menus
native int mAutoselect; // this can only be set by internal menu creation functions
native Font mFont;
native int mFontColor;
native int mFontColor2;
native bool mCenter;
void Reset()
{
// Reset the default settings (ignore all other values in the struct)
mSelectOfsX = 0;
mSelectOfsY = 0;
mSelector.SetInvalid();
mDisplayTop = 0;
mXpos = 0;
mYpos = 0;
mLinespacing = 0;
mNetgameMessage = "";
mFont = NULL;
mFontColor = Font.CR_UNTRANSLATED;
mFontColor2 = Font.CR_UNTRANSLATED;
}
}
struct FOptionMenuSettings
{
int mTitleColor;
int mFontColor;
int mFontColorValue;
int mFontColorMore;
int mFontColorHeader;
int mFontColorHighlight;
int mFontColorSelection;
int mLinespacing;
}
class OptionMenuDescriptor : MenuDescriptor native
{
native Array<OptionMenuItem> mItems;
native String mTitle;
native int mSelectedItem;
native int mDrawTop;
native int mScrollTop;
native int mScrollPos;
native int mIndent;
native int mPosition;
native bool mDontDim;
native void CalcIndent();
//native OptionMenuItem GetItem(Name iname);
void Reset()
{
// Reset the default settings (ignore all other values in the struct)
mPosition = 0;
mScrollTop = 0;
mIndent = 0;
mDontDim = 0;
}
}

View file

@ -32,6 +32,43 @@
**
*/
struct FOptionMenuSettings
{
int mTitleColor;
int mFontColor;
int mFontColorValue;
int mFontColorMore;
int mFontColorHeader;
int mFontColorHighlight;
int mFontColorSelection;
int mLinespacing;
}
class OptionMenuDescriptor : MenuDescriptor native
{
native Array<OptionMenuItem> mItems;
native String mTitle;
native int mSelectedItem;
native int mDrawTop;
native int mScrollTop;
native int mScrollPos;
native int mIndent;
native int mPosition;
native bool mDontDim;
native void CalcIndent();
//native OptionMenuItem GetItem(Name iname);
void Reset()
{
// Reset the default settings (ignore all other values in the struct)
mPosition = 0;
mScrollTop = 0;
mIndent = 0;
mDontDim = 0;
}
}
class OptionMenu : Menu
{
OptionMenuDescriptor mDesc;
@ -461,9 +498,3 @@ class CompatibilityMenu : OptionMenu
DTA_CleanNoMove_1, true);
}
}
class JoystickConfigMenu : OptionMenu
{
// This is not really needed anymore but needs to be kept for old MENUDEFs that keep the entry
}