mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-27 06:12:19 +00:00
- the first menu function has been scriptified.
This commit is contained in:
parent
7efa9cd70d
commit
07ba75762b
12 changed files with 176 additions and 100 deletions
|
@ -55,6 +55,8 @@ class DColorPickerMenu : public DOptionMenu
|
||||||
{
|
{
|
||||||
DECLARE_CLASS(DColorPickerMenu, DOptionMenu)
|
DECLARE_CLASS(DColorPickerMenu, DOptionMenu)
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
float mRed;
|
float mRed;
|
||||||
float mGreen;
|
float mGreen;
|
||||||
float mBlue;
|
float mBlue;
|
||||||
|
@ -66,8 +68,6 @@ class DColorPickerMenu : public DOptionMenu
|
||||||
|
|
||||||
FColorCVar *mCVar;
|
FColorCVar *mCVar;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
DColorPickerMenu(DMenu *parent, const char *name, DOptionMenuDescriptor *desc, FColorCVar *cvar)
|
DColorPickerMenu(DMenu *parent, const char *name, DOptionMenuDescriptor *desc, FColorCVar *cvar)
|
||||||
{
|
{
|
||||||
mStartItem = desc->mItems.Size();
|
mStartItem = desc->mItems.Size();
|
||||||
|
@ -124,93 +124,6 @@ public:
|
||||||
//
|
//
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
||||||
bool MenuEvent (int mkey, bool fromcontroller)
|
|
||||||
{
|
|
||||||
int &mSelectedItem = mDesc->mSelectedItem;
|
|
||||||
|
|
||||||
switch (mkey)
|
|
||||||
{
|
|
||||||
case MKEY_Down:
|
|
||||||
if (mSelectedItem == mStartItem+6) // last valid item
|
|
||||||
{
|
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE);
|
|
||||||
mGridPosY = 0;
|
|
||||||
// let it point to the last static item so that the super class code still has a valid item
|
|
||||||
mSelectedItem = mStartItem+7;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (mSelectedItem == mStartItem+7)
|
|
||||||
{
|
|
||||||
if (mGridPosY < 15)
|
|
||||||
{
|
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE);
|
|
||||||
mGridPosY++;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MKEY_Up:
|
|
||||||
if (mSelectedItem == mStartItem+7)
|
|
||||||
{
|
|
||||||
if (mGridPosY > 0)
|
|
||||||
{
|
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE);
|
|
||||||
mGridPosY--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE);
|
|
||||||
mSelectedItem = mStartItem+6;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MKEY_Left:
|
|
||||||
if (mSelectedItem == mStartItem+7)
|
|
||||||
{
|
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE);
|
|
||||||
if (--mGridPosX < 0) mGridPosX = 15;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MKEY_Right:
|
|
||||||
if (mSelectedItem == mStartItem+7)
|
|
||||||
{
|
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE);
|
|
||||||
if (++mGridPosX > 15) mGridPosX = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MKEY_Enter:
|
|
||||||
if (mSelectedItem == mStartItem+7)
|
|
||||||
{
|
|
||||||
// Choose selected palette entry
|
|
||||||
int index = mGridPosX + mGridPosY * 16;
|
|
||||||
mRed = GPalette.BaseColors[index].r;
|
|
||||||
mGreen = GPalette.BaseColors[index].g;
|
|
||||||
mBlue = GPalette.BaseColors[index].b;
|
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (mSelectedItem >= 0 && mSelectedItem < mStartItem+7)
|
|
||||||
{
|
|
||||||
if (mDesc->mItems[mDesc->mSelectedItem]->MenuEvent(mkey, fromcontroller)) return true;
|
|
||||||
}
|
|
||||||
return Super::MenuEvent(mkey, fromcontroller);
|
|
||||||
}
|
|
||||||
|
|
||||||
//=============================================================================
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//=============================================================================
|
|
||||||
|
|
||||||
bool MouseEvent(int type, int mx, int my)
|
bool MouseEvent(int type, int mx, int my)
|
||||||
{
|
{
|
||||||
int olditem = mDesc->mSelectedItem;
|
int olditem = mDesc->mSelectedItem;
|
||||||
|
@ -355,3 +268,11 @@ DMenu *StartPickerMenu(DMenu *parent, const char *name, FColorCVar *cvar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DEFINE_FIELD(DColorPickerMenu, mRed);
|
||||||
|
DEFINE_FIELD(DColorPickerMenu, mGreen);
|
||||||
|
DEFINE_FIELD(DColorPickerMenu, mBlue);
|
||||||
|
DEFINE_FIELD(DColorPickerMenu, mGridPosX);
|
||||||
|
DEFINE_FIELD(DColorPickerMenu, mGridPosY);
|
||||||
|
DEFINE_FIELD(DColorPickerMenu, mStartItem);
|
||||||
|
DEFINE_FIELD(DColorPickerMenu, mCVar);
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
#include "r_utility.h"
|
#include "r_utility.h"
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
#include "textures/textures.h"
|
#include "textures/textures.h"
|
||||||
|
#include "virtual.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Todo: Move these elsewhere
|
// Todo: Move these elsewhere
|
||||||
|
@ -208,6 +209,18 @@ DEFINE_ACTION_FUNCTION(DMenu, MenuEvent)
|
||||||
ACTION_RETURN_BOOL(self->MenuEvent(key, fromcontroller));
|
ACTION_RETURN_BOOL(self->MenuEvent(key, fromcontroller));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DMenu::CallMenuEvent(int mkey, bool fromcontroller)
|
||||||
|
{
|
||||||
|
IFVIRTUAL(DMenu, MenuEvent)
|
||||||
|
{
|
||||||
|
VMValue params[] = { (DObject*)this, mkey, fromcontroller };
|
||||||
|
int retval;
|
||||||
|
VMReturn ret(&retval);
|
||||||
|
GlobalVMStack.Call(func, params, 3, &ret, 1, nullptr);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
else return MenuEvent(mkey, fromcontroller);
|
||||||
|
}
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -260,7 +273,7 @@ bool DMenu::MouseEventBack(int type, int x, int y)
|
||||||
if (mBackbuttonSelected && type == MOUSE_Release)
|
if (mBackbuttonSelected && type == MOUSE_Release)
|
||||||
{
|
{
|
||||||
if (m_use_mouse == 2) mBackbuttonSelected = false;
|
if (m_use_mouse == 2) mBackbuttonSelected = false;
|
||||||
MenuEvent(MKEY_Back, true);
|
CallMenuEvent(MKEY_Back, true);
|
||||||
}
|
}
|
||||||
return mBackbuttonSelected;
|
return mBackbuttonSelected;
|
||||||
}
|
}
|
||||||
|
@ -661,7 +674,7 @@ bool M_Responder (event_t *ev)
|
||||||
{
|
{
|
||||||
MenuButtonTickers[mkey] = KEY_REPEAT_DELAY;
|
MenuButtonTickers[mkey] = KEY_REPEAT_DELAY;
|
||||||
}
|
}
|
||||||
DMenu::CurrentMenu->MenuEvent(mkey, fromcontroller);
|
DMenu::CurrentMenu->CallMenuEvent(mkey, fromcontroller);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,6 +242,9 @@ public:
|
||||||
virtual bool TranslateKeyboardEvents();
|
virtual bool TranslateKeyboardEvents();
|
||||||
virtual void Close();
|
virtual void Close();
|
||||||
virtual bool MouseEvent(int type, int x, int y);
|
virtual bool MouseEvent(int type, int x, int y);
|
||||||
|
|
||||||
|
bool CallMenuEvent(int mkey, bool fromcontroller);
|
||||||
|
|
||||||
bool MouseEventBack(int type, int x, int y);
|
bool MouseEventBack(int type, int x, int y);
|
||||||
void SetCapture();
|
void SetCapture();
|
||||||
void ReleaseCapture();
|
void ReleaseCapture();
|
||||||
|
|
|
@ -138,7 +138,7 @@ bool DTextEnterMenu::Responder(event_t *ev)
|
||||||
{
|
{
|
||||||
DMenu *parent = mParentMenu;
|
DMenu *parent = mParentMenu;
|
||||||
Close();
|
Close();
|
||||||
parent->MenuEvent(MKEY_Abort, false);
|
parent->CallMenuEvent(MKEY_Abort, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (ch == '\r')
|
else if (ch == '\r')
|
||||||
|
@ -151,7 +151,7 @@ bool DTextEnterMenu::Responder(event_t *ev)
|
||||||
|
|
||||||
DMenu *parent = mParentMenu;
|
DMenu *parent = mParentMenu;
|
||||||
Close();
|
Close();
|
||||||
parent->MenuEvent(MKEY_Input, false);
|
parent->CallMenuEvent(MKEY_Input, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ bool DTextEnterMenu::MouseEvent(int type, int x, int y)
|
||||||
InputGridY = (y - screen_y) / cell_height;
|
InputGridY = (y - screen_y) / cell_height;
|
||||||
if (type == DMenu::MOUSE_Release)
|
if (type == DMenu::MOUSE_Release)
|
||||||
{
|
{
|
||||||
if (MenuEvent(MKEY_Enter, true))
|
if (CallMenuEvent(MKEY_Enter, true))
|
||||||
{
|
{
|
||||||
S_Sound (CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE);
|
S_Sound (CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE);
|
||||||
if (m_use_mouse == 2) InputGridX = InputGridY = -1;
|
if (m_use_mouse == 2) InputGridX = InputGridY = -1;
|
||||||
|
@ -210,7 +210,7 @@ bool DTextEnterMenu::MenuEvent (int key, bool fromcontroller)
|
||||||
{
|
{
|
||||||
if (key == MKEY_Back)
|
if (key == MKEY_Back)
|
||||||
{
|
{
|
||||||
mParentMenu->MenuEvent(MKEY_Abort, false);
|
mParentMenu->CallMenuEvent(MKEY_Abort, false);
|
||||||
return Super::MenuEvent(key, fromcontroller);
|
return Super::MenuEvent(key, fromcontroller);
|
||||||
}
|
}
|
||||||
if (fromcontroller)
|
if (fromcontroller)
|
||||||
|
@ -262,7 +262,7 @@ bool DTextEnterMenu::MenuEvent (int key, bool fromcontroller)
|
||||||
{
|
{
|
||||||
DMenu *parent = mParentMenu;
|
DMenu *parent = mParentMenu;
|
||||||
Close();
|
Close();
|
||||||
parent->MenuEvent(MKEY_Input, false);
|
parent->CallMenuEvent(MKEY_Input, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ void DMessageBoxMenu::HandleResult(bool res)
|
||||||
{
|
{
|
||||||
if (mAction == NAME_None)
|
if (mAction == NAME_None)
|
||||||
{
|
{
|
||||||
mParentMenu->MenuEvent(res? MKEY_MBYes : MKEY_MBNo, false);
|
mParentMenu->CallMenuEvent(res? MKEY_MBYes : MKEY_MBNo, false);
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -496,7 +496,7 @@ bool DOptionMenuItem::MouseEvent(int type, int x, int y)
|
||||||
{
|
{
|
||||||
if (Selectable() && type == DMenu::MOUSE_Release)
|
if (Selectable() && type == DMenu::MOUSE_Release)
|
||||||
{
|
{
|
||||||
return DMenu::CurrentMenu->MenuEvent(MKEY_Enter, true);
|
return DMenu::CurrentMenu->CallMenuEvent(MKEY_Enter, true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,7 +418,7 @@ public:
|
||||||
menuactive = MENU_On;
|
menuactive = MENU_On;
|
||||||
SetMenuMessage(0);
|
SetMenuMessage(0);
|
||||||
Close();
|
Close();
|
||||||
mParentMenu->MenuEvent((ev->data1 == KEY_ESCAPE)? MKEY_Abort : MKEY_Input, 0);
|
mParentMenu->CallMenuEvent((ev->data1 == KEY_ESCAPE)? MKEY_Abort : MKEY_Input, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -103,6 +103,15 @@ DEFINE_ACTION_FUNCTION(_Screen, GetHeight)
|
||||||
ACTION_RETURN_INT(screen->GetHeight());
|
ACTION_RETURN_INT(screen->GetHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(_Screen, PaletteColor)
|
||||||
|
{
|
||||||
|
PARAM_PROLOGUE;
|
||||||
|
PARAM_INT(index);
|
||||||
|
if (index < 0 || index > 255) index = 0;
|
||||||
|
else index = GPalette.BaseColors[index];
|
||||||
|
ACTION_RETURN_INT(index);
|
||||||
|
}
|
||||||
|
|
||||||
static int PalFromRGB(uint32 rgb)
|
static int PalFromRGB(uint32 rgb)
|
||||||
{
|
{
|
||||||
if (LastPal >= 0 && LastRGB == rgb)
|
if (LastPal >= 0 && LastRGB == rgb)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "zscript/menu/menu.txt"
|
#include "zscript/menu/menu.txt"
|
||||||
//#include "zscript/menu/menuitembase.txt"
|
//#include "zscript/menu/menuitembase.txt"
|
||||||
|
#include "zscript/menu/colorpickermenu.txt"
|
||||||
|
|
||||||
#include "zscript/inventory/inventory.txt"
|
#include "zscript/inventory/inventory.txt"
|
||||||
#include "zscript/inventory/inv_misc.txt"
|
#include "zscript/inventory/inv_misc.txt"
|
||||||
|
|
|
@ -133,6 +133,7 @@ struct Screen native
|
||||||
NUM_TEXT_COLORS
|
NUM_TEXT_COLORS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
native static Color PaletteColor(int index);
|
||||||
native static int GetWidth();
|
native static int GetWidth();
|
||||||
native static int GetHeight();
|
native static int GetHeight();
|
||||||
native static void DrawHUDTexture(TextureID tex, double x, double y);
|
native static void DrawHUDTexture(TextureID tex, double x, double y);
|
||||||
|
@ -170,6 +171,10 @@ struct DamageTypeDefinition native
|
||||||
native static bool IgnoreArmor(Name type);
|
native static bool IgnoreArmor(Name type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CVar native
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
struct GameInfoStruct native
|
struct GameInfoStruct native
|
||||||
{
|
{
|
||||||
// will be extended as needed.
|
// will be extended as needed.
|
||||||
|
|
102
wadsrc/static/zscript/menu/colorpickermenu.txt
Normal file
102
wadsrc/static/zscript/menu/colorpickermenu.txt
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
|
||||||
|
class ColorpickerMenu : Menu native
|
||||||
|
{
|
||||||
|
native float mRed;
|
||||||
|
native float mGreen;
|
||||||
|
native float mBlue;
|
||||||
|
|
||||||
|
native int mGridPosX;
|
||||||
|
native int mGridPosY;
|
||||||
|
|
||||||
|
native int mStartItem;
|
||||||
|
|
||||||
|
native CVar mCVar;
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//=============================================================================
|
||||||
|
|
||||||
|
override bool MenuEvent (int mkey, bool fromcontroller)
|
||||||
|
{
|
||||||
|
switch (mkey)
|
||||||
|
{
|
||||||
|
case MKEY_Down:
|
||||||
|
if (mDesc.mSelectedItem == mStartItem+6) // last valid item
|
||||||
|
{
|
||||||
|
MenuSound ("menu/cursor");
|
||||||
|
mGridPosY = 0;
|
||||||
|
// let it point to the last static item so that the super class code still has a valid item
|
||||||
|
mDesc.mSelectedItem = mStartItem+7;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (mDesc.mSelectedItem == mStartItem+7)
|
||||||
|
{
|
||||||
|
if (mGridPosY < 15)
|
||||||
|
{
|
||||||
|
MenuSound ("menu/cursor");
|
||||||
|
mGridPosY++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MKEY_Up:
|
||||||
|
if (mDesc.mSelectedItem == mStartItem+7)
|
||||||
|
{
|
||||||
|
if (mGridPosY > 0)
|
||||||
|
{
|
||||||
|
MenuSound ("menu/cursor");
|
||||||
|
mGridPosY--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MenuSound ("menu/cursor");
|
||||||
|
mDesc.mSelectedItem = mStartItem+6;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MKEY_Left:
|
||||||
|
if (mDesc.mSelectedItem == mStartItem+7)
|
||||||
|
{
|
||||||
|
MenuSound ("menu/cursor");
|
||||||
|
if (--mGridPosX < 0) mGridPosX = 15;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MKEY_Right:
|
||||||
|
if (mDesc.mSelectedItem == mStartItem+7)
|
||||||
|
{
|
||||||
|
MenuSound ("menu/cursor");
|
||||||
|
if (++mGridPosX > 15) mGridPosX = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MKEY_Enter:
|
||||||
|
if (mDesc.mSelectedItem == mStartItem+7)
|
||||||
|
{
|
||||||
|
// Choose selected palette entry
|
||||||
|
int index = mGridPosX + mGridPosY * 16;
|
||||||
|
color col = Screen.PaletteColor(index);
|
||||||
|
mRed = col.r;
|
||||||
|
mGreen = col.g;
|
||||||
|
mBlue = col.b;
|
||||||
|
MenuSound ("menu/choose");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (mDesc.mSelectedItem >= 0 && mDesc.mSelectedItem < mStartItem+7)
|
||||||
|
{
|
||||||
|
if (mDesc.mItems[mDesc.mSelectedItem].MenuEvent(mkey, fromcontroller)) return true;
|
||||||
|
}
|
||||||
|
return Super.MenuEvent(mkey, fromcontroller);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,25 @@
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
class Menu : Object native
|
class Menu : Object native
|
||||||
{
|
{
|
||||||
//native static int MenuTime();
|
//native static int MenuTime();
|
||||||
|
@ -25,7 +46,8 @@ class MenuItemBase : object native
|
||||||
native Name mAction;
|
native Name mAction;
|
||||||
native bool mEnabled;
|
native bool mEnabled;
|
||||||
|
|
||||||
native virtual bool MenuEvent (int mkey, bool fromcontroller);
|
// making this virtual now would require exporting all classes at once.
|
||||||
|
native /*virtual*/ bool MenuEvent (int mkey, bool fromcontroller);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue