2017-02-03 23:19:25 +00:00
2017-03-05 13:03:27 +00:00
struct KeyBindings native version("2.4")
2017-02-10 23:36:53 +00:00
{
native static String NameKeys(int k1, int k2);
2020-10-04 17:28:20 +00:00
native static String NameAllKeys(array<int> list);
2017-02-10 23:36:53 +00:00
native int, int GetKeysForCommand(String cmd);
2020-10-04 17:28:20 +00:00
native void GetAllKeysForCommand(out array<int> list, String cmd);
2017-02-10 23:36:53 +00:00
native void SetBind(int key, String cmd);
native void UnbindACommand (String str);
}
2017-03-05 13:03:27 +00:00
struct OptionValues native version("2.4")
2017-02-10 23:36:53 +00:00
{
native static int GetCount(Name group);
native static String GetText(Name group, int index);
native static double GetValue(Name group, int index);
native static String GetTextValue(Name group, int index);
}
2017-03-05 13:03:27 +00:00
struct JoystickConfig native version("2.4")
2017-02-10 23:36:53 +00:00
{
enum EJoyAxis
{
JOYAXIS_None = -1,
JOYAXIS_Yaw,
JOYAXIS_Pitch,
JOYAXIS_Forward,
JOYAXIS_Side,
JOYAXIS_Up,
// JOYAXIS_Roll, // Ha ha. No roll for you.
NUM_JOYAXIS,
};
native float GetSensitivity();
native void SetSensitivity(float scale);
native float GetAxisScale(int axis);
native void SetAxisScale(int axis, float scale);
native float GetAxisDeadZone(int axis);
native void SetAxisDeadZone(int axis, float zone);
native int GetAxisMap(int axis);
native void SetAxisMap(int axis, int gameaxis);
2017-02-13 16:45:03 +00:00
native String GetName();
native int GetNumAxes();
native String GetAxisName(int axis);
2017-02-10 23:36:53 +00:00
}
2017-03-05 13:03:27 +00:00
class Menu : Object native ui version("2.4")
2017-02-03 23:19:25 +00:00
{
2017-02-10 10:44:46 +00:00
enum EMenuKey
{
MKEY_Up,
MKEY_Down,
MKEY_Left,
MKEY_Right,
MKEY_PageUp,
MKEY_PageDown,
MKEY_Enter,
MKEY_Back,
MKEY_Clear,
NUM_MKEYS,
// These are not buttons but events sent from other menus
MKEY_Input,
MKEY_Abort,
MKEY_MBYes,
MKEY_MBNo,
}
enum EMenuMouse
{
MOUSE_Click,
MOUSE_Move,
MOUSE_Release
};
2017-02-12 17:38:23 +00:00
enum EMenuState
{
Off, // Menu is closed
On, // Menu is opened
WaitKey, // Menu is opened and waiting for a key in the controls menu
OnNoPause, // Menu is opened but does not pause the game
};
native Menu mParentMenu;
2017-02-18 20:18:23 +00:00
native bool mMouseCapture;
native bool mBackbuttonSelected;
2017-02-19 12:07:49 +00:00
native bool DontDim;
2019-08-09 13:22:52 +00:00
native bool DontBlur;
2020-10-08 15:44:23 +00:00
native bool AnimatedTransition;
2020-10-09 20:44:34 +00:00
native bool Animated;
2017-02-12 17:38:23 +00:00
2017-02-11 15:11:48 +00:00
native static int MenuTime();
2017-02-10 23:36:53 +00:00
native static Menu GetCurrentMenu();
2017-03-28 20:51:37 +00:00
native static clearscope void SetMenu(Name mnu, int param = 0); // This is not 100% safe but needs to be available - but always make sure to check that only the desired player opens it!
2017-02-10 23:36:53 +00:00
native static void StartMessage(String msg, int mode = 0, Name command = 'none');
2017-02-19 14:23:33 +00:00
native static void SetMouseCapture(bool on);
native void Close();
native void ActivateMenu();
2017-02-10 23:36:53 +00:00
2017-02-19 14:23:33 +00:00
//=============================================================================
//
//
//
//=============================================================================
void Init(Menu parent)
{
mParentMenu = parent;
mMouseCapture = false;
mBackbuttonSelected = false;
DontDim = false;
2019-08-09 13:22:52 +00:00
DontBlur = false;
2020-10-08 15:44:23 +00:00
AnimatedTransition = false;
2020-10-09 20:44:34 +00:00
Animated = false;
2017-02-19 14:23:33 +00:00
}
//=============================================================================
//
//
//
//=============================================================================
virtual bool MenuEvent (int mkey, bool fromcontroller)
{
switch (mkey)
{
case MKEY_Back:
2020-10-07 16:29:34 +00:00
{
2017-02-19 14:23:33 +00:00
Close();
2020-10-07 16:29:34 +00:00
let m = GetCurrentMenu();
MenuSound(m != null ? "menu/backup" : "menu/clear");
if (!m) menuDelegate.MenuDismissed();
2017-02-19 14:23:33 +00:00
return true;
}
2020-10-07 16:29:34 +00:00
}
2017-02-19 14:23:33 +00:00
return false;
}
//=============================================================================
//
//
//
//=============================================================================
protected bool MouseEventBack(int type, int x, int y)
{
if (m_show_backbutton >= 0)
{
let tex = TexMan.CheckForTexture(gameinfo.mBackButton, TexMan.Type_MiscPatch);
if (tex.IsValid())
{
Vector2 v = TexMan.GetScaledSize(tex);
int w = int(v.X + 0.5) * CleanXfac;
int h = int(v.Y + 0.5) * CleanYfac;
if (m_show_backbutton&1) x -= screen.GetWidth() - w;
if (m_show_backbutton&2) y -= screen.GetHeight() - h;
mBackbuttonSelected = ( x >= 0 && x < w && y >= 0 && y < h);
if (mBackbuttonSelected && type == MOUSE_Release)
{
if (m_use_mouse == 2) mBackbuttonSelected = false;
MenuEvent(MKEY_Back, true);
}
return mBackbuttonSelected;
}
}
return false;
}
//=============================================================================
//
//
//
//=============================================================================
2017-03-06 21:27:51 +00:00
virtual bool OnUIEvent(UIEvent ev)
2017-02-19 14:23:33 +00:00
{
bool res = false;
2017-03-06 21:27:51 +00:00
int y = ev.MouseY;
if (ev.type == UIEvent.Type_LButtonDown)
2017-02-19 14:23:33 +00:00
{
2017-03-06 21:27:51 +00:00
res = MouseEventBack(MOUSE_Click, ev.MouseX, y);
// make the menu's mouse handler believe that the current coordinate is outside the valid range
if (res) y = -1;
res |= MouseEvent(MOUSE_Click, ev.MouseX, y);
if (res)
2017-02-19 14:23:33 +00:00
{
2017-03-06 21:27:51 +00:00
SetCapture(true);
2017-02-19 14:23:33 +00:00
}
2017-03-06 21:27:51 +00:00
}
else if (ev.type == UIEvent.Type_MouseMove)
{
2020-10-04 18:26:37 +00:00
BackbuttonTime = 4*GameTicRate;
2017-03-06 21:27:51 +00:00
if (mMouseCapture || m_use_mouse == 1)
2017-02-19 14:23:33 +00:00
{
2017-03-06 21:27:51 +00:00
res = MouseEventBack(MOUSE_Move, ev.MouseX, y);
if (res) y = -1;
res |= MouseEvent(MOUSE_Move, ev.MouseX, y);
2017-02-19 14:23:33 +00:00
}
2017-03-06 21:27:51 +00:00
}
else if (ev.type == UIEvent.Type_LButtonUp)
{
if (mMouseCapture)
2017-02-19 14:23:33 +00:00
{
2017-03-06 21:27:51 +00:00
SetCapture(false);
res = MouseEventBack(MOUSE_Release, ev.MouseX, y);
if (res) y = -1;
res |= MouseEvent(MOUSE_Release, ev.MouseX, y);
2017-02-19 14:23:33 +00:00
}
}
return false;
}
2017-03-06 21:27:51 +00:00
virtual bool OnInputEvent(InputEvent ev)
{
return false;
}
2017-02-19 14:23:33 +00:00
//=============================================================================
//
//
//
//=============================================================================
virtual void Drawer ()
{
if (self == GetCurrentMenu() && BackbuttonAlpha > 0 && m_show_backbutton >= 0 && m_use_mouse)
{
let tex = TexMan.CheckForTexture(gameinfo.mBackButton, TexMan.Type_MiscPatch);
if (tex.IsValid())
{
Vector2 v = TexMan.GetScaledSize(tex);
int w = int(v.X + 0.5) * CleanXfac;
int h = int(v.Y + 0.5) * CleanYfac;
int x = (!(m_show_backbutton&1))? 0:screen.GetWidth() - w;
int y = (!(m_show_backbutton&2))? 0:screen.GetHeight() - h;
if (mBackbuttonSelected && (mMouseCapture || m_use_mouse == 1))
{
2020-10-08 15:44:23 +00:00
screen.DrawTexture(tex, true, x, y, DTA_CleanNoMove, true, DTA_ColorOverlay, Color(40, 255,255,255), DTA_NOOFFSET, true);
2017-02-19 14:23:33 +00:00
}
else
{
2020-10-08 15:44:23 +00:00
screen.DrawTexture(tex, true, x, y, DTA_CleanNoMove, true, DTA_Alpha, BackbuttonAlpha, DTA_NOOFFSET, true);
2017-02-19 14:23:33 +00:00
}
}
}
}
2017-02-10 23:36:53 +00:00
2017-02-19 14:23:33 +00:00
//=============================================================================
//
//
//
//=============================================================================
void SetCapture(bool on)
{
if (mMouseCapture != on)
{
mMouseCapture = on;
SetMouseCapture(on);
}
}
//=============================================================================
//
//
//
//=============================================================================
2017-02-12 17:38:23 +00:00
virtual bool TranslateKeyboardEvents() { return true; }
2017-02-11 15:11:48 +00:00
virtual void SetFocus(MenuItemBase fc) {}
virtual bool CheckFocus(MenuItemBase fc) { return false; }
virtual void ReleaseFocus() {}
2017-02-12 19:20:47 +00:00
virtual void ResetColor() {}
2017-02-19 21:08:22 +00:00
virtual bool MouseEvent(int type, int mx, int my) { return true; }
2017-02-19 14:23:33 +00:00
virtual void Ticker() {}
2017-03-29 19:22:05 +00:00
virtual void OnReturn() {}
2017-02-19 14:23:33 +00:00
//=============================================================================
//
//
//
//=============================================================================
2017-02-12 17:38:23 +00:00
2020-10-07 16:29:34 +00:00
static void MenuSound(Name snd)
2017-02-09 19:18:53 +00:00
{
2020-10-07 16:29:34 +00:00
menuDelegate.PlaySound(snd);
2017-02-09 19:18:53 +00:00
}
2019-03-19 23:01:12 +00:00
deprecated("4.0") static void DrawConText (int color, int x, int y, String str)
2017-02-10 23:36:53 +00:00
{
2019-03-19 23:01:12 +00:00
screen.DrawText (ConFont, color, x, y, str, DTA_CellX, 8 * CleanXfac, DTA_CellY, 8 * CleanYfac);
2017-02-10 23:36:53 +00:00
}
2019-03-17 15:58:10 +00:00
static Font OptionFont()
{
return NewSmallFont;
}
static int OptionHeight()
{
return OptionFont().GetHeight();
}
static int OptionWidth(String s)
{
return OptionFont().StringWidth(s);
}
2019-03-17 17:14:12 +00:00
static void DrawOptionText(int x, int y, int color, String text, bool grayed = false)
{
String label = Stringtable.Localize(text);
int overlay = grayed? Color(96,48,0,0) : 0;
2019-04-21 08:49:27 +00:00
screen.DrawText (OptionFont(), color, x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
2019-03-17 17:14:12 +00:00
}
2017-02-10 23:36:53 +00:00
2017-02-09 19:18:53 +00:00
}
2017-03-05 13:03:27 +00:00
class MenuDescriptor : Object native ui version("2.4")
2017-02-09 19:18:53 +00:00
{
native Name mMenuName;
native String mNetgameMessage;
native Class<Menu> mClass;
2017-02-12 19:20:47 +00:00
native static MenuDescriptor GetDescriptor(Name n);
2017-02-09 19:18:53 +00:00
}
2017-02-19 14:35:28 +00:00
// This class is only needed to give it a virtual Init method that doesn't belong to Menu itself
class GenericMenu : Menu
{
virtual void Init(Menu parent)
{
Super.Init(parent);
}
}