2017-02-10 23:36:53 +00:00
|
|
|
/*
|
|
|
|
** optionmenuitems.txt
|
|
|
|
** Control items for option menus
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2010-2017 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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2017-02-12 13:04:48 +00:00
|
|
|
class OptionMenuItem : MenuItemBase
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 13:04:48 +00:00
|
|
|
String mLabel;
|
|
|
|
bool mCentered;
|
2017-02-10 23:36:53 +00:00
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
protected void Init(String label, String command, bool center = false)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(0, 0, command);
|
|
|
|
mLabel = label;
|
|
|
|
mCentered = center;
|
|
|
|
}
|
|
|
|
|
2017-04-18 14:42:28 +00:00
|
|
|
protected int drawLabel(int indent, int y, int color, bool grayed = false)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
String label = Stringtable.Localize(mLabel);
|
2017-02-12 13:28:38 +00:00
|
|
|
|
2017-02-10 23:36:53 +00:00
|
|
|
int overlay = grayed? Color(96,48,0,0) : 0;
|
|
|
|
|
|
|
|
int x;
|
2019-03-17 15:22:38 +00:00
|
|
|
int w = NewSmallFont.StringWidth(label) * CleanXfac_1;
|
2017-02-10 23:36:53 +00:00
|
|
|
if (!mCentered) x = indent - w;
|
|
|
|
else x = (screen.GetWidth() - w) / 2;
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText (NewSmallFont, color, x, y, label, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
|
2017-04-18 14:42:28 +00:00
|
|
|
return x;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CursorSpace()
|
|
|
|
{
|
|
|
|
return (14 * CleanXfac_1);
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool Selectable()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-12 13:04:48 +00:00
|
|
|
override int GetIndent()
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
if (mCentered) return 0;
|
2019-03-17 15:22:38 +00:00
|
|
|
return NewSmallFont.StringWidth(Stringtable.Localize(mLabel));
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override bool MouseEvent(int type, int x, int y)
|
|
|
|
{
|
|
|
|
if (Selectable() && type == Menu.MOUSE_Release)
|
|
|
|
{
|
|
|
|
return Menu.GetCurrentMenu().MenuEvent(Menu.MKEY_Enter, true);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// opens a submenu, command is a submenu name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemSubmenu : OptionMenuItem
|
|
|
|
{
|
|
|
|
int mParam;
|
2017-04-18 14:42:28 +00:00
|
|
|
OptionMenuItemSubmenu Init(String label, Name command, int param = 0, bool centered = false)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-04-18 14:42:28 +00:00
|
|
|
Super.init(label, command, centered);
|
2017-02-10 23:36:53 +00:00
|
|
|
mParam = param;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
2017-04-18 14:42:28 +00:00
|
|
|
int x = drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColorMore);
|
|
|
|
if (mCentered)
|
|
|
|
{
|
|
|
|
return x - 16*CleanXfac_1;
|
|
|
|
}
|
2017-02-10 23:36:53 +00:00
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool Activate()
|
|
|
|
{
|
|
|
|
Menu.MenuSound("menu/choose");
|
|
|
|
Menu.SetMenu(mAction, mParam);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 07:52:40 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// opens a submenu, command is a submenu name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemLabeledSubmenu : OptionMenuItemSubmenu
|
|
|
|
{
|
|
|
|
CVar mLabelCVar;
|
|
|
|
OptionMenuItemSubmenu Init(String label, CVar labelcvar, Name command, int param = 0)
|
|
|
|
{
|
|
|
|
Super.init(label, command, false);
|
|
|
|
mLabelCVar = labelcvar;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
|
|
|
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor);
|
|
|
|
|
|
|
|
String text = mLabelCVar.GetString();
|
|
|
|
if (text.Length() == 0) text = Stringtable.Localize("$notset");
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, text, DTA_CleanNoMove_1, true);
|
2018-02-26 07:52:40 +00:00
|
|
|
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 23:36:53 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Executes a CCMD, command is a CCMD name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemCommand : OptionMenuItemSubmenu
|
|
|
|
{
|
2017-12-13 21:14:30 +00:00
|
|
|
private String ccmd; // do not allow access to this from the outside.
|
2017-11-25 21:03:18 +00:00
|
|
|
bool mCloseOnSelect;
|
2018-01-30 14:02:30 +00:00
|
|
|
private bool mUnsafe;
|
2017-11-25 21:03:18 +00:00
|
|
|
|
|
|
|
OptionMenuItemCommand Init(String label, Name command, bool centered = false, bool closeonselect = false)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-04-18 14:42:28 +00:00
|
|
|
Super.Init(label, command, 0, centered);
|
2017-12-13 21:14:30 +00:00
|
|
|
ccmd = command;
|
2017-11-25 21:03:18 +00:00
|
|
|
mCloseOnSelect = closeonselect;
|
2018-01-30 14:02:30 +00:00
|
|
|
mUnsafe = true;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 14:02:30 +00:00
|
|
|
private native static void DoCommand(String cmd, bool unsafe); // This is very intentionally limited to this menu item to prevent abuse.
|
2017-02-13 18:18:45 +00:00
|
|
|
|
2017-02-10 23:36:53 +00:00
|
|
|
override bool Activate()
|
|
|
|
{
|
2017-02-13 18:18:45 +00:00
|
|
|
// This needs to perform a few checks to prevent abuse by malicious modders.
|
2017-03-28 20:34:12 +00:00
|
|
|
if (GetClass() != "OptionMenuItemSafeCommand")
|
|
|
|
{
|
|
|
|
let m = OptionMenu(Menu.GetCurrentMenu());
|
|
|
|
// don't execute if no menu is active
|
|
|
|
if (m == null) return false;
|
|
|
|
// don't execute if this item cannot be found in the current menu.
|
|
|
|
if (m.GetItem(mAction) != self) return false;
|
|
|
|
}
|
2017-02-10 23:36:53 +00:00
|
|
|
Menu.MenuSound("menu/choose");
|
2018-01-30 14:02:30 +00:00
|
|
|
DoCommand(ccmd, mUnsafe);
|
2017-11-25 21:03:18 +00:00
|
|
|
if (mCloseOnSelect)
|
|
|
|
{
|
|
|
|
let curmenu = Menu.GetCurrentMenu();
|
|
|
|
if (curmenu != null) curmenu.Close();
|
|
|
|
}
|
2017-02-10 23:36:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Executes a CCMD after confirmation, command is a CCMD name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemSafeCommand : OptionMenuItemCommand
|
|
|
|
{
|
|
|
|
String mPrompt;
|
|
|
|
|
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemSafeCommand Init(String label, Name command, String prompt = "")
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command);
|
|
|
|
mPrompt = prompt;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override bool MenuEvent (int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
if (mkey == Menu.MKEY_MBYes)
|
|
|
|
{
|
2017-02-13 19:03:29 +00:00
|
|
|
Super.Activate();
|
2017-02-10 23:36:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return Super.MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool Activate()
|
|
|
|
{
|
|
|
|
String msg = mPrompt.Length() > 0 ? mPrompt : "$SAFEMESSAGE";
|
|
|
|
msg = StringTable.Localize(msg);
|
|
|
|
String actionLabel = StringTable.localize(mLabel);
|
|
|
|
|
|
|
|
String FullString;
|
2017-02-12 15:02:55 +00:00
|
|
|
FullString = String.Format("%s%s%s\n\n%s", TEXTCOLOR_WHITE, actionLabel, TEXTCOLOR_NORMAL, msg);
|
2017-02-10 23:36:53 +00:00
|
|
|
Menu.StartMessage(FullString, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Base class for option lists
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemOptionBase : OptionMenuItem
|
|
|
|
{
|
|
|
|
// command is a CVAR
|
|
|
|
Name mValues; // Entry in OptionValues table
|
|
|
|
CVar mGrayCheck;
|
|
|
|
int mCenter;
|
2017-02-12 15:02:55 +00:00
|
|
|
|
2017-02-10 23:36:53 +00:00
|
|
|
const OP_VALUES = 0x11001;
|
|
|
|
|
2017-02-11 20:28:48 +00:00
|
|
|
protected void Init(String label, Name command, Name values, CVar graycheck, int center)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command);
|
|
|
|
mValues = values;
|
|
|
|
mGrayCheck = graycheck;
|
|
|
|
mCenter = center;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool SetString(int i, String newtext)
|
|
|
|
{
|
|
|
|
if (i == OP_VALUES)
|
|
|
|
{
|
|
|
|
int cnt = OptionValues.GetCount(mValues);
|
|
|
|
if (cnt >= 0)
|
|
|
|
{
|
|
|
|
mValues = newtext;
|
|
|
|
int s = GetSelection();
|
|
|
|
if (s >= cnt) s = 0;
|
|
|
|
SetSelection(s); // readjust the CVAR if its value is outside the range now
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
virtual int GetSelection()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetSelection(int Selection)
|
|
|
|
{
|
|
|
|
}
|
2017-11-26 09:16:21 +00:00
|
|
|
|
2017-02-10 23:36:53 +00:00
|
|
|
//=============================================================================
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
2017-11-26 09:16:21 +00:00
|
|
|
bool grayed = isGrayed();
|
2017-02-10 23:36:53 +00:00
|
|
|
|
|
|
|
if (mCenter)
|
|
|
|
{
|
|
|
|
indent = (screen.GetWidth() / 2);
|
|
|
|
}
|
|
|
|
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, grayed);
|
|
|
|
|
|
|
|
int overlay = grayed? Color(96,48,0,0) : 0;
|
|
|
|
int Selection = GetSelection();
|
|
|
|
String text = StringTable.Localize(OptionValues.GetText(mValues, Selection));
|
|
|
|
if (text.Length() == 0) text = "Unknown";
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
|
2017-02-10 23:36:53 +00:00
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
override bool MenuEvent (int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
int cnt = OptionValues.GetCount(mValues);
|
|
|
|
if (cnt > 0)
|
|
|
|
{
|
|
|
|
int Selection = GetSelection();
|
|
|
|
if (mkey == Menu.MKEY_Left)
|
|
|
|
{
|
|
|
|
if (Selection == -1) Selection = 0;
|
|
|
|
else if (--Selection < 0) Selection = cnt - 1;
|
|
|
|
}
|
|
|
|
else if (mkey == Menu.MKEY_Right || mkey == Menu.MKEY_Enter)
|
|
|
|
{
|
|
|
|
if (++Selection >= cnt) Selection = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Super.MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
|
|
|
SetSelection(Selection);
|
|
|
|
Menu.MenuSound("menu/change");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Super.MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-26 09:16:21 +00:00
|
|
|
|
|
|
|
virtual bool isGrayed()
|
|
|
|
{
|
|
|
|
return mGrayCheck != null && !mGrayCheck.GetInt();
|
|
|
|
}
|
2017-02-10 23:36:53 +00:00
|
|
|
|
|
|
|
override bool Selectable()
|
|
|
|
{
|
2017-11-26 09:16:21 +00:00
|
|
|
return !isGrayed();
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Change a CVAR, command is the CVAR name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemOption : OptionMenuItemOptionBase
|
|
|
|
{
|
|
|
|
CVar mCVar;
|
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemOption Init(String label, Name command, Name values, CVar graycheck = null, int center = 0)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command, values, graycheck, center);
|
|
|
|
mCVar = CVar.FindCVar(mAction);
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
override int GetSelection()
|
|
|
|
{
|
|
|
|
int Selection = -1;
|
|
|
|
int cnt = OptionValues.GetCount(mValues);
|
|
|
|
if (cnt > 0 && mCVar != null)
|
|
|
|
{
|
2017-02-12 13:28:38 +00:00
|
|
|
if (OptionValues.GetTextValue(mValues, 0).Length() == 0)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
let f = mCVar.GetFloat();
|
|
|
|
for(int i = 0; i < cnt; i++)
|
|
|
|
{
|
|
|
|
if (f ~== OptionValues.GetValue(mValues, i))
|
|
|
|
{
|
|
|
|
Selection = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String cv = mCVar.GetString();
|
|
|
|
for(int i = 0; i < cnt; i++)
|
|
|
|
{
|
|
|
|
if (cv ~== OptionValues.GetTextValue(mValues, i))
|
|
|
|
{
|
|
|
|
Selection = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
override void SetSelection(int Selection)
|
|
|
|
{
|
|
|
|
int cnt = OptionValues.GetCount(mValues);
|
|
|
|
if (cnt > 0 && mCVar != null)
|
|
|
|
{
|
2017-02-12 13:28:38 +00:00
|
|
|
if (OptionValues.GetTextValue(mValues, 0).Length() == 0)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
mCVar.SetFloat(OptionValues.GetValue(mValues, Selection));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mCVar.SetString(OptionValues.GetTextValue(mValues, Selection));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// This class is used to capture the key to be used as the new key binding
|
|
|
|
// for a control item
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-02-12 17:38:23 +00:00
|
|
|
class EnterKey : Menu
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 17:38:23 +00:00
|
|
|
OptionMenuItemControlBase mOwner;
|
2017-02-10 23:36:53 +00:00
|
|
|
|
2017-02-12 17:38:23 +00:00
|
|
|
void Init(Menu parent, OptionMenuItemControlBase owner)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 17:38:23 +00:00
|
|
|
Super.Init(parent);
|
|
|
|
mOwner = owner;
|
2017-02-10 23:36:53 +00:00
|
|
|
SetMenuMessage(1);
|
2017-02-12 17:38:23 +00:00
|
|
|
menuactive = Menu.WaitKey; // There should be a better way to disable GUI capture...
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 17:38:23 +00:00
|
|
|
override bool TranslateKeyboardEvents()
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-12 17:38:23 +00:00
|
|
|
private void SetMenuMessage(int which)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 17:38:23 +00:00
|
|
|
let parent = OptionMenu(mParentMenu);
|
|
|
|
if (parent != null)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-18 18:11:53 +00:00
|
|
|
let it = parent.GetItem('Controlmessage');
|
2017-02-10 23:36:53 +00:00
|
|
|
if (it != null)
|
|
|
|
{
|
|
|
|
it.SetValue(0, which);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 21:27:51 +00:00
|
|
|
override bool OnInputEvent(InputEvent ev)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-03-06 21:27:51 +00:00
|
|
|
// This menu checks raw keys, not GUI keys because it needs the raw codes for binding.
|
|
|
|
if (ev.type == InputEvent.Type_KeyDown)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-03-06 21:27:51 +00:00
|
|
|
mOwner.SendKey(ev.KeyScan);
|
2017-02-12 17:38:23 +00:00
|
|
|
menuactive = Menu.On;
|
2017-02-10 23:36:53 +00:00
|
|
|
SetMenuMessage(0);
|
|
|
|
Close();
|
2017-03-06 21:27:51 +00:00
|
|
|
mParentMenu.MenuEvent((ev.KeyScan == InputEvent.KEY_ESCAPE)? Menu.MKEY_Abort : Menu.MKEY_Input, 0);
|
2017-02-10 23:36:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-12 17:38:23 +00:00
|
|
|
override void Drawer()
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 17:38:23 +00:00
|
|
|
mParentMenu.Drawer();
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
2017-02-12 17:38:23 +00:00
|
|
|
}
|
2017-02-10 23:36:53 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// // Edit a key binding, Action is the CCMD to bind
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-02-12 13:04:48 +00:00
|
|
|
class OptionMenuItemControlBase : OptionMenuItem
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
KeyBindings mBindings;
|
|
|
|
int mInput;
|
|
|
|
bool mWaiting;
|
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
protected void Init(String label, Name command, KeyBindings bindings)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.init(label, command);
|
|
|
|
mBindings = bindings;
|
|
|
|
mWaiting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
|
|
|
drawLabel(indent, y, mWaiting? OptionMenuSettings.mFontColorHighlight:
|
|
|
|
(selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor));
|
|
|
|
|
|
|
|
String description;
|
|
|
|
int Key1, Key2;
|
|
|
|
|
|
|
|
[Key1, Key2] = mBindings.GetKeysForCommand(mAction);
|
|
|
|
description = KeyBindings.NameKeys (Key1, Key2);
|
|
|
|
if (description.Length() > 0)
|
|
|
|
{
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText(NewSmallFont, Font.CR_WHITE, indent + CursorSpace(), y, description, DTA_CleanNoMove_1, true);
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText(NewSmallFont, Font.CR_BLACK, indent + CursorSpace(), y, "---", DTA_CleanNoMove_1, true);
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
override bool MenuEvent(int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
if (mkey == Menu.MKEY_Input)
|
|
|
|
{
|
|
|
|
mWaiting = false;
|
|
|
|
mBindings.SetBind(mInput, mAction);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (mkey == Menu.MKEY_Clear)
|
|
|
|
{
|
|
|
|
mBindings.UnbindACommand(mAction);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (mkey == Menu.MKEY_Abort)
|
|
|
|
{
|
|
|
|
mWaiting = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-12 17:38:23 +00:00
|
|
|
|
|
|
|
void SendKey(int key)
|
|
|
|
{
|
|
|
|
mInput = key;
|
|
|
|
}
|
2017-02-10 23:36:53 +00:00
|
|
|
|
|
|
|
override bool Activate()
|
|
|
|
{
|
|
|
|
Menu.MenuSound("menu/choose");
|
|
|
|
mWaiting = true;
|
2017-02-12 17:38:23 +00:00
|
|
|
let input = new("EnterKey");
|
|
|
|
input.Init(Menu.GetCurrentMenu(), self);
|
|
|
|
input.ActivateMenu();
|
2017-02-10 23:36:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-12 13:04:48 +00:00
|
|
|
class OptionMenuItemControl : OptionMenuItemControlBase
|
|
|
|
{
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemControl Init(String label, Name command)
|
2017-02-12 13:04:48 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command, Bindings);
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-12 13:04:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class OptionMenuItemMapControl : OptionMenuItemControlBase
|
|
|
|
{
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemMapControl Init(String label, Name command)
|
2017-02-12 13:04:48 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command, AutomapBindings);
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-12 13:04:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 23:36:53 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemStaticText : OptionMenuItem
|
|
|
|
{
|
|
|
|
int mColor;
|
|
|
|
|
2017-02-12 13:04:48 +00:00
|
|
|
// this function is only for use from MENUDEF, it needs to do some strange things with the color for backwards compatibility.
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemStaticText Init(String label, int cr = -1)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, 'None', true);
|
2017-02-12 13:04:48 +00:00
|
|
|
mColor = OptionMenuSettings.mFontColor;
|
|
|
|
if ((cr & 0xffff0000) == 0x12340000) mColor = cr & 0xffff;
|
|
|
|
else if (cr > 0) mColor = OptionMenuSettings.mFontColorHeader;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-12 13:04:48 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemStaticText InitDirect(String label, int cr)
|
2017-02-12 13:04:48 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, 'None', true);
|
|
|
|
mColor = cr;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
|
|
|
drawLabel(indent, y, mColor);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool Selectable()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemStaticTextSwitchable : OptionMenuItem
|
|
|
|
{
|
|
|
|
int mColor;
|
|
|
|
String mAltText;
|
|
|
|
int mCurrent;
|
|
|
|
|
2017-02-12 13:04:48 +00:00
|
|
|
// this function is only for use from MENUDEF, it needs to do some strange things with the color for backwards compatibility.
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemStaticTextSwitchable Init(String label, String label2, Name command, int cr = -1)
|
2017-02-12 13:04:48 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command, true);
|
|
|
|
mAltText = label2;
|
|
|
|
mCurrent = 0;
|
|
|
|
|
|
|
|
mColor = OptionMenuSettings.mFontColor;
|
|
|
|
if ((cr & 0xffff0000) == 0x12340000) mColor = cr & 0xffff;
|
|
|
|
else if (cr > 0) mColor = OptionMenuSettings.mFontColorHeader;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-12 13:04:48 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemStaticTextSwitchable InitDirect(String label, String label2, Name command, int cr)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command, true);
|
|
|
|
mColor = cr;
|
|
|
|
mAltText = label2;
|
|
|
|
mCurrent = 0;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
|
|
|
String txt = StringTable.Localize(mCurrent? mAltText : mLabel);
|
2019-03-17 15:22:38 +00:00
|
|
|
int w = NewSmallFont.StringWidth(txt) * CleanXfac_1;
|
2017-02-10 23:36:53 +00:00
|
|
|
int x = (screen.GetWidth() - w) / 2;
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText (NewSmallFont, mColor, x, y, txt, DTA_CleanNoMove_1, true);
|
2017-02-10 23:36:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool SetValue(int i, int val)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
mCurrent = val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool SetString(int i, String newtext)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
mAltText = newtext;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool Selectable()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuSliderBase : OptionMenuItem
|
|
|
|
{
|
|
|
|
// command is a CVAR
|
|
|
|
double mMin, mMax, mStep;
|
|
|
|
int mShowValue;
|
|
|
|
int mDrawX;
|
|
|
|
int mSliderShort;
|
|
|
|
|
2017-03-13 00:17:46 +00:00
|
|
|
protected void Init(String label, double min, double max, double step, int showval, Name command = 'none')
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-03-13 00:17:46 +00:00
|
|
|
Super.Init(label, command);
|
2017-02-10 23:36:53 +00:00
|
|
|
mMin = min;
|
|
|
|
mMax = max;
|
|
|
|
mStep = step;
|
|
|
|
mShowValue = showval;
|
|
|
|
mDrawX = 0;
|
|
|
|
mSliderShort = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual double GetSliderValue()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetSliderValue(double val)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Draw a slider. Set fracdigits negative to not display the current value numerically.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-03-30 09:30:09 +00:00
|
|
|
protected void DrawSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 15:02:55 +00:00
|
|
|
String formater = String.format("%%.%df", fracdigits); // The format function cannot do the '%.*f' syntax.
|
2017-02-10 23:36:53 +00:00
|
|
|
String textbuf;
|
|
|
|
double range;
|
|
|
|
int maxlen = 0;
|
|
|
|
int right = x + (12*8 + 4) * CleanXfac_1;
|
2019-03-17 15:22:38 +00:00
|
|
|
int cy = y;
|
2017-02-10 23:36:53 +00:00
|
|
|
|
|
|
|
range = max - min;
|
|
|
|
double ccur = clamp(cur, min, max) - min;
|
|
|
|
|
|
|
|
if (fracdigits >= 0)
|
|
|
|
{
|
|
|
|
textbuf = String.format(formater, max);
|
2019-03-17 15:22:38 +00:00
|
|
|
maxlen = NewSmallFont.StringWidth(textbuf) * CleanXfac_1;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mSliderShort = right + maxlen > screen.GetWidth();
|
|
|
|
|
|
|
|
if (!mSliderShort)
|
|
|
|
{
|
|
|
|
Menu.DrawConText(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12");
|
2017-10-14 17:05:15 +00:00
|
|
|
Menu.DrawConText(Font.FindFontColor(gameinfo.mSliderColor), x + int((5 + ((ccur * 78) / range)) * CleanXfac_1), cy, "\x13");
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// On 320x200 we need a shorter slider
|
|
|
|
Menu.DrawConText(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12");
|
2017-10-14 17:05:15 +00:00
|
|
|
Menu.DrawConText(Font.FindFontColor(gameinfo.mSliderColor), x + int((5 + ((ccur * 38) / range)) * CleanXfac_1), cy, "\x13");
|
2019-03-17 15:22:38 +00:00
|
|
|
right -= 5*8*CleanXfac;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fracdigits >= 0 && right + maxlen <= screen.GetWidth())
|
|
|
|
{
|
|
|
|
textbuf = String.format(formater, cur);
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText(NewSmallFont, Font.CR_DARKGRAY, right, y, textbuf, DTA_CleanNoMove_1, true);
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
|
|
|
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor);
|
|
|
|
mDrawX = indent + CursorSpace();
|
|
|
|
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent);
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
override bool MenuEvent (int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
double value = GetSliderValue();
|
|
|
|
|
|
|
|
if (mkey == Menu.MKEY_Left)
|
|
|
|
{
|
|
|
|
value -= mStep;
|
|
|
|
}
|
|
|
|
else if (mkey == Menu.MKEY_Right)
|
|
|
|
{
|
|
|
|
value += mStep;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return OptionMenuItem.MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
|
|
|
if (value ~== 0) value = 0; // This is to prevent formatting anomalies with very small values
|
|
|
|
SetSliderValue(clamp(value, mMin, mMax));
|
|
|
|
Menu.MenuSound("menu/change");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool MouseEvent(int type, int x, int y)
|
|
|
|
{
|
|
|
|
let lm = OptionMenu(Menu.GetCurrentMenu());
|
|
|
|
if (type != Menu.MOUSE_Click)
|
|
|
|
{
|
|
|
|
if (!lm.CheckFocus(self)) return false;
|
|
|
|
}
|
|
|
|
if (type == Menu.MOUSE_Release)
|
|
|
|
{
|
|
|
|
lm.ReleaseFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
int slide_left = mDrawX+8*CleanXfac_1;
|
|
|
|
int slide_right = slide_left + (10*8*CleanXfac_1 >> mSliderShort); // 12 char cells with 8 pixels each.
|
|
|
|
|
|
|
|
if (type == Menu.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);
|
|
|
|
//Menu.MenuSound("menu/change");
|
|
|
|
}
|
|
|
|
if (type == Menu.MOUSE_Click)
|
|
|
|
{
|
|
|
|
lm.SetFocus(self);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-02-11 20:28:48 +00:00
|
|
|
class OptionMenuItemSlider : OptionMenuSliderBase
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
CVar mCVar;
|
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemSlider Init(String label, Name command, double min, double max, double step, int showval = 1)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-03-13 00:17:46 +00:00
|
|
|
Super.Init(label, min, max, step, showval, command);
|
2017-02-10 23:36:53 +00:00
|
|
|
mCVar =CVar.FindCVar(command);
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override double GetSliderValue()
|
|
|
|
{
|
|
|
|
if (mCVar != null)
|
|
|
|
{
|
|
|
|
return mCVar.GetFloat();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override void SetSliderValue(double val)
|
|
|
|
{
|
|
|
|
if (mCVar != null)
|
|
|
|
{
|
|
|
|
mCVar.SetFloat(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// // Edit a key binding, Action is the CCMD to bind
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemColorPicker : OptionMenuItem
|
|
|
|
{
|
|
|
|
CVar mCVar;
|
|
|
|
|
|
|
|
const CPF_RESET = 0x20001;
|
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemColorPicker Init(String label, Name command)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command);
|
|
|
|
CVar cv = CVar.FindCVar(command);
|
2017-02-12 15:02:55 +00:00
|
|
|
if (cv != null && cv.GetRealType() != CVar.CVAR_Color) cv = null;
|
2017-02-10 23:36:53 +00:00
|
|
|
mCVar = cv;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
|
|
|
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor);
|
|
|
|
|
|
|
|
if (mCVar != null)
|
|
|
|
{
|
|
|
|
int box_x = indent + CursorSpace();
|
|
|
|
int box_y = y + CleanYfac_1;
|
2017-02-12 15:02:55 +00:00
|
|
|
screen.Clear (box_x, box_y, box_x + 32*CleanXfac_1, box_y + OptionMenuSettings.mLinespacing*CleanYfac_1, mCVar.GetInt() | 0xff000000);
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool SetValue(int i, int v)
|
|
|
|
{
|
|
|
|
if (i == CPF_RESET && mCVar != null)
|
|
|
|
{
|
|
|
|
mCVar.ResetToDefault();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool Activate()
|
|
|
|
{
|
|
|
|
if (mCVar != null)
|
|
|
|
{
|
|
|
|
Menu.MenuSound("menu/choose");
|
2017-02-12 20:56:01 +00:00
|
|
|
|
|
|
|
// This code is a bit complicated because it should allow subclassing the
|
|
|
|
// colorpicker menu.
|
2017-02-12 19:20:47 +00:00
|
|
|
// New color pickers must inherit from the internal one to work here.
|
2017-02-12 20:56:01 +00:00
|
|
|
|
|
|
|
let desc = MenuDescriptor.GetDescriptor('Colorpickermenu');
|
2017-02-12 19:20:47 +00:00
|
|
|
if (desc != NULL && (desc.mClass == null || desc.mClass is "ColorPickerMenu"))
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 19:20:47 +00:00
|
|
|
let odesc = OptionMenuDescriptor(desc);
|
|
|
|
if (odesc != null)
|
|
|
|
{
|
|
|
|
let cls = desc.mClass;
|
|
|
|
if (cls == null) cls = "ColorpickerMenu";
|
|
|
|
let picker = ColorpickerMenu(new(cls));
|
|
|
|
picker.Init(Menu.GetCurrentMenu(), mLabel, odesc, mCVar);
|
|
|
|
picker.ActivateMenu();
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// [TP] OptionMenuFieldBase
|
|
|
|
//
|
|
|
|
// Base class for input fields
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuFieldBase : OptionMenuItem
|
|
|
|
{
|
|
|
|
void Init (String label, Name command, CVar graycheck = null)
|
|
|
|
{
|
|
|
|
Super.Init(label, command);
|
|
|
|
mCVar = CVar.FindCVar(mAction);
|
|
|
|
mGrayCheck = graycheck;
|
|
|
|
}
|
|
|
|
|
|
|
|
String GetCVarString()
|
|
|
|
{
|
|
|
|
if (mCVar == null)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return mCVar.GetString();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual String Represent()
|
|
|
|
{
|
|
|
|
return GetCVarString();
|
|
|
|
}
|
|
|
|
|
|
|
|
override int Draw (OptionMenuDescriptor d, int y, int indent, bool selected)
|
|
|
|
{
|
|
|
|
bool grayed = mGrayCheck != null && !mGrayCheck.GetInt();
|
|
|
|
drawLabel(indent, y, selected ? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, grayed);
|
|
|
|
int overlay = grayed? Color(96, 48, 0, 0) : 0;
|
|
|
|
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText(NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, Represent(), DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
|
2017-02-10 23:36:53 +00:00
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool, String GetString (int i)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
return true, GetCVarString();
|
|
|
|
}
|
|
|
|
return false, "";
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool SetString (int i, String s)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
if (mCVar) mCVar.SetString(s);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CVar mCVar;
|
|
|
|
CVar mGrayCheck;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// [TP] OptionMenuTextField
|
|
|
|
//
|
|
|
|
// A text input field widget, for use with string CVars.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-02-11 20:28:48 +00:00
|
|
|
class OptionMenuItemTextField : OptionMenuFieldBase
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 20:45:37 +00:00
|
|
|
TextEnterMenu mEnter;
|
|
|
|
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemTextField Init (String label, Name command, CVar graycheck = null)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command, graycheck);
|
2017-02-12 20:45:37 +00:00
|
|
|
mEnter = null;
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override String Represent()
|
|
|
|
{
|
2019-03-17 15:22:38 +00:00
|
|
|
if (mEnter) return mEnter.GetText() .. NewSmallFont.GetCursor();
|
2017-02-10 23:36:53 +00:00
|
|
|
else return GetCVarString();
|
|
|
|
}
|
|
|
|
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
2017-02-12 20:45:37 +00:00
|
|
|
if (mEnter)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
// reposition the text so that the cursor is visible when in entering mode.
|
|
|
|
String text = Represent();
|
2019-03-17 15:22:38 +00:00
|
|
|
int tlen = NewSmallFont.StringWidth(text) * CleanXfac_1;
|
2017-02-10 23:36:53 +00:00
|
|
|
int newindent = screen.GetWidth() - tlen - CursorSpace();
|
|
|
|
if (newindent < indent) indent = newindent;
|
|
|
|
}
|
|
|
|
return Super.Draw(desc, y, indent, selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool MenuEvent (int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
if (mkey == Menu.MKEY_Enter)
|
|
|
|
{
|
|
|
|
Menu.MenuSound("menu/choose");
|
2019-03-17 15:22:38 +00:00
|
|
|
mEnter = TextEnterMenu.OpenTextEnter(Menu.GetCurrentMenu(), NewSmallFont, GetCVarString(), -1, fromcontroller);
|
2017-02-19 17:27:29 +00:00
|
|
|
mEnter.ActivateMenu();
|
2017-02-10 23:36:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (mkey == Menu.MKEY_Input)
|
|
|
|
{
|
2017-02-12 20:45:37 +00:00
|
|
|
if (mCVar) mCVar.SetString(mEnter.GetText());
|
|
|
|
mEnter = null;
|
2017-02-10 23:36:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (mkey == Menu.MKEY_Abort)
|
|
|
|
{
|
2017-02-12 20:45:37 +00:00
|
|
|
mEnter = null;
|
2017-02-10 23:36:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Super.MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// [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)
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2017-02-11 20:28:48 +00:00
|
|
|
class OptionMenuItemNumberField : OptionMenuFieldBase
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
2017-02-12 19:20:47 +00:00
|
|
|
OptionMenuItemNumberField Init (String label, Name command, float minimum = 0, float maximum = 100, float step = 1, CVar graycheck = null)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, command, graycheck);
|
|
|
|
mMinimum = min(minimum, maximum);
|
|
|
|
mMaximum = max(minimum, maximum);
|
|
|
|
mStep = max(1, step);
|
2017-02-12 19:20:47 +00:00
|
|
|
return self;
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override String Represent()
|
|
|
|
{
|
|
|
|
if (mCVar == null) return "";
|
|
|
|
return String.format("%.3f", mCVar.GetFloat());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override bool MenuEvent (int mkey, bool fromcontroller)
|
|
|
|
{
|
|
|
|
if (mCVar)
|
|
|
|
{
|
|
|
|
float value = mCVar.GetFloat();
|
|
|
|
|
|
|
|
if (mkey == Menu.MKEY_Left)
|
|
|
|
{
|
|
|
|
value -= mStep;
|
|
|
|
if (value < mMinimum) value = mMaximum;
|
|
|
|
}
|
|
|
|
else if (mkey == Menu.MKEY_Right || mkey == Menu.MKEY_Enter)
|
|
|
|
{
|
|
|
|
value += mStep;
|
|
|
|
if (value > mMaximum) value = mMinimum;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return Super.MenuEvent(mkey, fromcontroller);
|
|
|
|
|
|
|
|
mCVar.SetFloat(value);
|
|
|
|
Menu.MenuSound("menu/change");
|
|
|
|
}
|
2017-02-14 18:06:45 +00:00
|
|
|
else return Super.MenuEvent(mkey, fromcontroller);
|
2017-02-10 23:36:53 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
float mMinimum;
|
|
|
|
float mMaximum;
|
|
|
|
float mStep;
|
|
|
|
}
|
|
|
|
|
2017-03-30 09:30:09 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// A special slider that displays plain text for special settings related
|
|
|
|
// to scaling.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemScaleSlider : OptionMenuItemSlider
|
|
|
|
{
|
|
|
|
String TextZero;
|
|
|
|
String TextNegOne;
|
2017-03-30 18:12:39 +00:00
|
|
|
int mClickVal;
|
2017-03-30 09:30:09 +00:00
|
|
|
|
|
|
|
OptionMenuItemScaleSlider Init(String label, Name command, double min, double max, double step, String zero, String negone = "")
|
|
|
|
{
|
|
|
|
Super.Init(label, command, min, max, step, 0);
|
|
|
|
mCVar =CVar.FindCVar(command);
|
|
|
|
TextZero = zero;
|
|
|
|
TextNEgOne = negone;
|
2017-03-30 18:12:39 +00:00
|
|
|
mClickVal = -10;
|
2017-03-30 09:30:09 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
|
|
|
|
{
|
|
|
|
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor);
|
|
|
|
|
2017-04-27 08:23:31 +00:00
|
|
|
int Selection = int(GetSliderValue());
|
2017-03-30 18:12:39 +00:00
|
|
|
if ((Selection == 0 || Selection == -1) && mClickVal <= 0)
|
2017-03-30 09:30:09 +00:00
|
|
|
{
|
|
|
|
String text = Selection == 0? TextZero : Selection == -1? TextNegOne : "";
|
2019-03-17 15:22:38 +00:00
|
|
|
screen.DrawText (NewSmallFont, OptionMenuSettings.mFontColorValue, indent + CursorSpace(), y, text, DTA_CleanNoMove_1, true);
|
2017-03-30 09:30:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mDrawX = indent + CursorSpace();
|
|
|
|
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent);
|
|
|
|
}
|
|
|
|
return indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool MouseEvent(int type, int x, int y)
|
|
|
|
{
|
2017-04-27 08:23:31 +00:00
|
|
|
int value = int(GetSliderValue());
|
2017-03-30 18:12:39 +00:00
|
|
|
switch (type)
|
2017-03-30 09:30:09 +00:00
|
|
|
{
|
2017-03-30 18:12:39 +00:00
|
|
|
case Menu.MOUSE_Click:
|
|
|
|
mClickVal = value;
|
|
|
|
if (value <= 0) return false;
|
|
|
|
return Super.MouseEvent(type, x, y);
|
|
|
|
|
|
|
|
case Menu.MOUSE_Move:
|
|
|
|
if (mClickVal <= 0) return false;
|
|
|
|
return Super.MouseEvent(type, x, y);
|
|
|
|
|
|
|
|
case Menu.MOUSE_Release:
|
|
|
|
if (mClickVal <= 0)
|
|
|
|
{
|
|
|
|
mClickVal = -10;
|
|
|
|
SetSliderValue(value + 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
mClickVal = -10;
|
|
|
|
return Super.MouseEvent(type, x, y);
|
2017-03-30 09:30:09 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-16 14:15:41 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Placeholder classes for overhauled video mode menu. Do not use!
|
|
|
|
// Their sole purpose is to support mods with full copy of embedded MENUDEF
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemScreenResolution : OptionMenuItem
|
|
|
|
{
|
|
|
|
String mResTexts[3];
|
|
|
|
int mSelection;
|
|
|
|
int mHighlight;
|
|
|
|
int mMaxValid;
|
|
|
|
|
|
|
|
enum EValues
|
|
|
|
{
|
|
|
|
SRL_INDEX = 0x30000,
|
|
|
|
SRL_SELECTION = 0x30003,
|
|
|
|
SRL_HIGHLIGHT = 0x30004,
|
|
|
|
};
|
|
|
|
|
|
|
|
OptionMenuItemScreenResolution Init(String command)
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool Selectable()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class VideoModeMenu : OptionMenu
|
|
|
|
{
|
|
|
|
static bool SetSelectedSize()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|