gzdoom-gles/wadsrc/static/zscript/menu/listmenu.txt
2017-02-13 17:45:03 +01:00

108 lines
2.4 KiB
Text

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;
}
}