diff --git a/src/menu/listmenu.cpp b/src/menu/listmenu.cpp index 18c627359d..beaa687f1e 100644 --- a/src/menu/listmenu.cpp +++ b/src/menu/listmenu.cpp @@ -115,167 +115,13 @@ DMenuItemBase *DListMenu::GetItem(FName name) return NULL; } -//============================================================================= -// -// -// -//============================================================================= - -bool DListMenu::Responder (event_t *ev) -{ - if (ev->type == EV_GUI_Event) - { - if (ev->subtype == EV_GUI_KeyDown) - { - int ch = tolower (ev->data1); - - for(unsigned i = mDesc->mSelectedItem + 1; i < mDesc->mItems.Size(); i++) - { - if (mDesc->mItems[i]->CheckHotkey(ch)) - { - mDesc->mSelectedItem = i; - S_Sound(CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); - return true; - } - } - for(int i = 0; i < mDesc->mSelectedItem; i++) - { - if (mDesc->mItems[i]->CheckHotkey(ch)) - { - mDesc->mSelectedItem = i; - S_Sound(CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); - return true; - } - } - } - } - return Super::Responder(ev); -} - -//============================================================================= -// -// -// -//============================================================================= - -bool DListMenu::MenuEvent (int mkey, bool fromcontroller) -{ - int oldSelect = mDesc->mSelectedItem; - int startedAt = mDesc->mSelectedItem; - if (startedAt < 0) startedAt = 0; - - switch (mkey) - { - case MKEY_Up: - do - { - if (--mDesc->mSelectedItem < 0) mDesc->mSelectedItem = mDesc->mItems.Size()-1; - } - while (!mDesc->mItems[mDesc->mSelectedItem]->Selectable() && mDesc->mSelectedItem != startedAt); - if (mDesc->mSelectedItem == startedAt) mDesc->mSelectedItem = oldSelect; - S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); - return true; - - case MKEY_Down: - do - { - if (++mDesc->mSelectedItem >= (int)mDesc->mItems.Size()) mDesc->mSelectedItem = 0; - } - while (!mDesc->mItems[mDesc->mSelectedItem]->Selectable() && mDesc->mSelectedItem != startedAt); - if (mDesc->mSelectedItem == startedAt) mDesc->mSelectedItem = oldSelect; - S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); - return true; - - case MKEY_Enter: - if (mDesc->mSelectedItem >= 0 && mDesc->mItems[mDesc->mSelectedItem]->Activate()) - { - S_Sound (CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE); - } - return true; - - default: - return Super::MenuEvent(mkey, fromcontroller); - } -} - -//============================================================================= -// -// -// -//============================================================================= - -bool DListMenu::MouseEvent(int type, int x, int y) -{ - int sel = -1; - - // convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture - x = ((x - (screen->GetWidth() / 2)) / CleanXfac) + 160; - y = ((y - (screen->GetHeight() / 2)) / CleanYfac) + 100; - - if (mFocusControl != NULL) - { - mFocusControl->MouseEvent(type, x, y); - return true; - } - else - { - if ((mDesc->mWLeft <= 0 || x > mDesc->mWLeft) && - (mDesc->mWRight <= 0 || x < mDesc->mWRight)) - { - for(unsigned i=0;imItems.Size(); i++) - { - if (mDesc->mItems[i]->CheckCoordinate(x, y)) - { - if ((int)i != mDesc->mSelectedItem) - { - //S_Sound (CHAN_VOICE | CHAN_UI, "menu/cursor", snd_menuvolume, ATTN_NONE); - } - mDesc->mSelectedItem = i; - mDesc->mItems[i]->MouseEvent(type, x, y); - return true; - } - } - } - } - mDesc->mSelectedItem = -1; - return Super::MouseEvent(type, x, y); -} - -//============================================================================= -// -// -// -//============================================================================= - -void DListMenu::Ticker () -{ - Super::Ticker(); - for(unsigned i=0;imItems.Size(); i++) - { - mDesc->mItems[i]->Ticker(); - } -} - -//============================================================================= -// -// -// -//============================================================================= - -void DListMenu::Drawer () -{ - for(unsigned i=0;imItems.Size(); i++) - { - if (mDesc->mItems[i]->mEnabled) mDesc->mItems[i]->Drawer(mDesc->mSelectedItem == (int)i); - } - if (mDesc->mSelectedItem >= 0 && mDesc->mSelectedItem < (int)mDesc->mItems.Size()) - mDesc->mItems[mDesc->mSelectedItem]->DrawSelector(mDesc->mSelectOfsX, mDesc->mSelectOfsY, mDesc->mSelector); - Super::Drawer(); -} - //============================================================================= // // base class for menu items // //============================================================================= IMPLEMENT_CLASS(DMenuItemBase, false, false) + +DEFINE_FIELD(DListMenu, mDesc) +DEFINE_FIELD(DListMenu, mFocusControl) + diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index ee7d5cbdb1..dc7e021267 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -629,7 +629,7 @@ void M_SetMenu(FName menu, int param) if (cls == nullptr) cls = DefaultListMenuClass; if (cls == nullptr) cls = PClass::FindClass("ListMenu"); - DListMenu *newmenu = (DListMenu *)cls->CreateNew(); + DMenu *newmenu = (DMenu *)cls->CreateNew(); IFVIRTUALPTRNAME(newmenu, "ListMenu", Init) { VMValue params[3] = { newmenu, DMenu::CurrentMenu, ld }; @@ -1220,9 +1220,6 @@ DEFINE_FIELD(DMenuItemBase, mYpos) DEFINE_FIELD(DMenuItemBase, mAction) DEFINE_FIELD(DMenuItemBase, mEnabled) -DEFINE_FIELD(DListMenu, mDesc) -DEFINE_FIELD(DListMenu, mFocusControl) - DEFINE_FIELD(DListMenuDescriptor, mItems) DEFINE_FIELD(DListMenuDescriptor, mSelectedItem) DEFINE_FIELD(DListMenuDescriptor, mSelectOfsX) @@ -1344,15 +1341,6 @@ void DMenuItemBase::Ticker() } } -void DMenuItemBase::Drawer(bool selected) -{ - IFVIRTUAL(DMenuItemBase, Drawer) - { - VMValue params[] = { (DObject*)this, selected }; - GlobalVMStack.Call(func, params, countof(params), nullptr, 0, nullptr); - } -} - bool DMenuItemBase::Selectable() { IFVIRTUAL(DMenuItemBase, Selectable) @@ -1534,25 +1522,3 @@ int DMenuItemBase::Draw(DOptionMenuDescriptor *desc, int y, int indent, bool sel } return false; } - -void DMenuItemBase::DrawSelector(int xofs, int yofs, FTextureID tex) -{ - if (tex.isNull()) - { - if ((DMenu::MenuTime % 8) < 6) - { - screen->DrawText(ConFont, OptionSettings.mFontColorSelection, - (mXpos + xofs - 160) * CleanXfac + screen->GetWidth() / 2, - (mYpos + yofs - 100) * CleanYfac + screen->GetHeight() / 2, - "\xd", - DTA_CellX, 8 * CleanXfac, - DTA_CellY, 8 * CleanYfac, - TAG_DONE); - } - } - else - { - screen->DrawTexture(TexMan(tex), mXpos + xofs, mYpos + yofs, DTA_Clean, true, TAG_DONE); - } -} - diff --git a/src/menu/menu.h b/src/menu/menu.h index dd06dc6058..e197a62ef5 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -319,7 +319,6 @@ public: bool CheckCoordinate(int x, int y); void Ticker(); - void Drawer(bool selected); bool Selectable(); bool Activate(); FName GetAction(int *pparam); @@ -338,9 +337,6 @@ public: int GetY() { return mYpos; } int GetX() { return mXpos; } void SetX(int x) { mXpos = x; } - - void DrawSelector(int xofs, int yofs, FTextureID tex); - }; //============================================================================= @@ -361,11 +357,6 @@ public: DListMenu(DMenu *parent = NULL, DListMenuDescriptor *desc = NULL); virtual void Init(DMenu *parent = NULL, DListMenuDescriptor *desc = NULL); DMenuItemBase *GetItem(FName name); - bool Responder (event_t *ev); - bool MenuEvent (int mkey, bool fromcontroller); - bool MouseEvent(int type, int x, int y); - void Ticker (); - void Drawer (); void SetFocus(DMenuItemBase *fc) { mFocusControl = fc; diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index 8afed617e4..252533091e 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -294,7 +294,7 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) { sc.MustGetString(); PClass *cls = PClass::FindClass(sc.String); - if (cls == nullptr || !cls->IsDescendantOf(RUNTIME_CLASS(DListMenu))) + if (cls == nullptr || !cls->IsDescendantOf("ListMenu")) { sc.ScriptError("Unknown menu class '%s'", sc.String); } diff --git a/src/menu/playermenu.cpp b/src/menu/playermenu.cpp index 519af0a9d7..c900cc4a79 100644 --- a/src/menu/playermenu.cpp +++ b/src/menu/playermenu.cpp @@ -61,7 +61,7 @@ EXTERN_CVAR(Bool, cl_run) DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_INT(r); PARAM_INT(g); PARAM_INT(b); @@ -86,7 +86,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_STRING(s); const char *pp = s; FString command("name \""); @@ -116,7 +116,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_INT(sel); if (self == DMenu::CurrentMenu) { @@ -136,7 +136,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, ClassChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_INT(sel); PARAM_POINTER(cls, FPlayerClass); if (self == DMenu::CurrentMenu) @@ -156,7 +156,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, ClassChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, SkinChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_INT(sel); if (self == DMenu::CurrentMenu) { @@ -174,7 +174,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, SkinChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_FLOAT(val); // only allow if the menu is active to prevent abuse. if (self == DMenu::CurrentMenu) @@ -192,7 +192,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_INT(val); // only allow if the menu is active to prevent abuse. if (self == DMenu::CurrentMenu) @@ -210,7 +210,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_INT(v); // only allow if the menu is active to prevent abuse. if (self == DMenu::CurrentMenu) @@ -228,7 +228,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_INT(v); // only allow if the menu is active to prevent abuse. if (self == DMenu::CurrentMenu) @@ -246,7 +246,7 @@ DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged) DEFINE_ACTION_FUNCTION(DPlayerMenu, AlwaysRunChanged) { - PARAM_SELF_PROLOGUE(DListMenu); + PARAM_SELF_PROLOGUE(DMenu); PARAM_INT(v); // only allow if the menu is active to prevent abuse. if (self == DMenu::CurrentMenu) diff --git a/wadsrc/static/zscript/menu/listmenu.txt b/wadsrc/static/zscript/menu/listmenu.txt index d920dc26c4..2aacbb94c4 100644 --- a/wadsrc/static/zscript/menu/listmenu.txt +++ b/wadsrc/static/zscript/menu/listmenu.txt @@ -76,6 +76,12 @@ class ListMenu : Menu native } } + //============================================================================= + // + // + // + //============================================================================= + MenuItemBase GetItem(Name name) { for(int i = 0; i < mDesc.mItems.Size(); i++) @@ -86,12 +92,173 @@ class ListMenu : Menu native return NULL; } - //bool Responder (InputEventData ev); - //bool MenuEvent (int mkey, bool fromcontroller); - //bool MouseEvent(int type, int x, int y); - //void Ticker (); - //void Drawer (); + + //============================================================================= + // + // + // + //============================================================================= + + override bool Responder (InputEventData ev) + { + if (ev.type == InputEventData.GUI_Event) + { + if (ev.subtype == InputEventData.GUI_KeyDown) + { + // tolower + int ch = ev.data1; + ch = ch >= 65 && ch <91? ch + 32 : ch; + + for(int i = mDesc.mSelectedItem + 1; i < mDesc.mItems.Size(); i++) + { + if (mDesc.mItems[i].CheckHotkey(ch)) + { + mDesc.mSelectedItem = i; + MenuSound("menu/cursor"); + return true; + } + } + for(int i = 0; i < mDesc.mSelectedItem; i++) + { + if (mDesc.mItems[i].CheckHotkey(ch)) + { + mDesc.mSelectedItem = i; + MenuSound("menu/cursor"); + return true; + } + } + } + } + return Super.Responder(ev); + } + + //============================================================================= + // + // + // + //============================================================================= + + override bool MenuEvent (int mkey, bool fromcontroller) + { + int oldSelect = mDesc.mSelectedItem; + int startedAt = mDesc.mSelectedItem; + if (startedAt < 0) startedAt = 0; + + switch (mkey) + { + case MKEY_Up: + do + { + if (--mDesc.mSelectedItem < 0) mDesc.mSelectedItem = mDesc.mItems.Size()-1; + } + while (!mDesc.mItems[mDesc.mSelectedItem].Selectable() && mDesc.mSelectedItem != startedAt); + if (mDesc.mSelectedItem == startedAt) mDesc.mSelectedItem = oldSelect; + MenuSound("menu/cursor"); + return true; + + case MKEY_Down: + do + { + if (++mDesc.mSelectedItem >= mDesc.mItems.Size()) mDesc.mSelectedItem = 0; + } + while (!mDesc.mItems[mDesc.mSelectedItem].Selectable() && mDesc.mSelectedItem != startedAt); + if (mDesc.mSelectedItem == startedAt) mDesc.mSelectedItem = oldSelect; + MenuSound("menu/cursor"); + return true; + + case MKEY_Enter: + if (mDesc.mSelectedItem >= 0 && mDesc.mItems[mDesc.mSelectedItem].Activate()) + { + MenuSound("menu/choose"); + } + return true; + + default: + return Super.MenuEvent(mkey, fromcontroller); + } + } + + //============================================================================= + // + // + // + //============================================================================= + + override bool MouseEvent(int type, int x, int y) + { + int sel = -1; + + // convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture + x = ((x - (screen.GetWidth() / 2)) / CleanXfac) + 160; + y = ((y - (screen.GetHeight() / 2)) / CleanYfac) + 100; + + if (mFocusControl != NULL) + { + mFocusControl.MouseEvent(type, x, y); + return true; + } + else + { + if ((mDesc.mWLeft <= 0 || x > mDesc.mWLeft) && + (mDesc.mWRight <= 0 || x < mDesc.mWRight)) + { + for(int i=0;i= 0 && mDesc.mSelectedItem < mDesc.mItems.Size()) + mDesc.mItems[mDesc.mSelectedItem].DrawSelector(mDesc.mSelectOfsX, mDesc.mSelectOfsY, mDesc.mSelector); + Super.Drawer(); + } + //============================================================================= + // + // + // + //============================================================================= + override void SetFocus(MenuItemBase fc) { mFocusControl = fc; @@ -106,3 +273,4 @@ class ListMenu : Menu native } } + diff --git a/wadsrc/static/zscript/menu/listmenuitems.txt b/wadsrc/static/zscript/menu/listmenuitems.txt index 8920e617bd..e3eec6dd18 100644 --- a/wadsrc/static/zscript/menu/listmenuitems.txt +++ b/wadsrc/static/zscript/menu/listmenuitems.txt @@ -52,7 +52,7 @@ class ListMenuItem : MenuItemBase } else { - screen.DrawTexture (tex, mXpos + xofs, mYpos + yofs, DTA_Clean, true); + screen.DrawTexture (tex, true, mXpos + xofs, mYpos + yofs, DTA_Clean, true); } } }