- added automatic centering of Hexen's skill menu so that it can adjust automatically to the different player classes.

SVN r2840 (trunk)
This commit is contained in:
Christoph Oelckers 2010-09-21 12:58:59 +00:00
parent 583cbd49a6
commit a3e98eb4ab
4 changed files with 63 additions and 13 deletions

View file

@ -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;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(unsigned i=0;i<mDesc->mItems.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();
}

View file

@ -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();
};
//=============================================================================

View file

@ -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<FListMenuDescriptor*>(*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; i<ld->mItems.Size(); i++)

View file

@ -204,7 +204,8 @@ ListMenu "SkillMenu"
IfGame (Hexen)
{
StaticText 74, 16, "$MNU_CHOOSESKILL"
Position 38, 44
Position 160, 44
centermenu
}
}