diff --git a/src/menu/listmenu.cpp b/src/menu/listmenu.cpp index 42164c16b3..882f974895 100644 --- a/src/menu/listmenu.cpp +++ b/src/menu/listmenu.cpp @@ -53,8 +53,8 @@ IMPLEMENT_CLASS(DListMenu) DListMenu::DListMenu(DMenu *parent, FListMenuDescriptor *desc) : DMenu(parent) { - mDesc = desc; - mFocusControl = NULL; + mDesc = NULL; + if (desc != NULL) Init(parent, desc); } //============================================================================= @@ -68,6 +68,31 @@ void DListMenu::Init(DMenu *parent, FListMenuDescriptor *desc) mParentMenu = parent; GC::WriteBarrier(this, parent); mDesc = desc; + if (desc->mCenter) + { + int center = 160; + for(unsigned i=0;imItems.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(unsigned i=0;imItems.Size(); i++) + { + int width = mDesc->mItems[i]->GetWidth(); + + if (width > 0) + { + mDesc->mItems[i]->SetX(center); + } + } + } } //============================================================================= @@ -334,6 +359,11 @@ bool FListMenuItem::CheckHotkey(int c) return false; } +int FListMenuItem::GetWidth() +{ + return 0; +} + //============================================================================= // @@ -492,6 +522,18 @@ void FListMenuItemText::Drawer(bool selected) } } +int FListMenuItemText::GetWidth() +{ + const char *text = mText; + if (text != NULL) + { + if (*text == '$') text = GStrings(text+1); + return mFont->StringWidth(text); + } + return 1; +} + + //============================================================================= // // patch item @@ -509,3 +551,9 @@ void FListMenuItemPatch::Drawer(bool selected) { screen->DrawTexture (TexMan(mTexture), mXpos, mYpos, DTA_Clean, true, TAG_DONE); } + +int FListMenuItemPatch::GetWidth() +{ + return TexMan[mTexture]->GetScaledWidth(); +} + diff --git a/src/menu/menu.h b/src/menu/menu.h index 07acd78495..692542198d 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -110,6 +110,7 @@ struct FListMenuDescriptor : public FMenuDescriptor EColorRange mFontColor2; const PClass *mClass; FMenuDescriptor *mRedirect; // used to redirect overlong skill and episode menus to option menu based alternatives + bool mCenter; }; struct FOptionMenuSettings @@ -262,9 +263,12 @@ public: virtual bool MenuEvent (int mkey, bool fromcontroller); virtual bool MouseEvent(int type, int x, int y); virtual bool CheckHotkey(int c); + virtual int GetWidth(); void DrawSelector(int xofs, int yofs, FTextureID tex); void OffsetPositionY(int ydelta) { mYpos += ydelta; } int GetY() { return mYpos; } + int GetX() { return mXpos; } + void SetX(int x) { mXpos = x; } }; class FListMenuItemStaticPatch : public FListMenuItem @@ -370,6 +374,7 @@ public: FListMenuItemText(int x, int y, int height, int hotkey, const char *text, FFont *font, EColorRange color, FName child, int param = 0); ~FListMenuItemText(); void Drawer(bool selected); + int GetWidth(); }; class FListMenuItemPatch : public FListMenuItemSelectable @@ -378,6 +383,7 @@ class FListMenuItemPatch : public FListMenuItemSelectable public: FListMenuItemPatch(int x, int y, int height, int hotkey, FTextureID patch, FName child, int param = 0); void Drawer(bool selected); + int GetWidth(); }; //============================================================================= diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index 6028d8fd7e..66145bff64 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -238,6 +238,10 @@ static void ParseListMenuBody(FScanner &sc, FListMenuDescriptor *desc) sc.MustGetNumber(); desc->mYpos = sc.Number; } + else if (sc.Compare("Centermenu")) + { + desc->mCenter = true; + } else if (sc.Compare("MouseWindow")) { sc.MustGetNumber(); @@ -463,6 +467,7 @@ static void ParseListMenu(FScanner &sc) desc->mRedirect = NULL; desc->mWLeft = 0; desc->mWRight = 0; + desc->mCenter = false; FMenuDescriptor **pOld = MenuDescriptors.CheckKey(desc->mMenuName); if (pOld != NULL && *pOld != NULL) delete *pOld; @@ -1228,16 +1233,6 @@ void M_StartupSkillMenu(FGameStartup *gs) FListMenuDescriptor *ld = static_cast(*desc); int x = ld->mXpos; int y = ld->mYpos; - if (gameinfo.gametype == GAME_Hexen) - { - // THere really needs to be a better way to do this... :( - if (gs->PlayerClass != NULL) - { - if (!stricmp(gs->PlayerClass, "fighter")) x = 120; - else if (!stricmp(gs->PlayerClass, "cleric")) x = 116; - else if (!stricmp(gs->PlayerClass, "mage")) x = 112; - } - } // Delete previous contents for(unsigned i=0; imItems.Size(); i++) diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 7f42c0e568..edbeecb6a3 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -204,7 +204,8 @@ ListMenu "SkillMenu" IfGame (Hexen) { StaticText 74, 16, "$MNU_CHOOSESKILL" - Position 38, 44 + Position 160, 44 + centermenu } }