Scrollable achievement menu for lower resolutions.

This commit is contained in:
Mari the Deer 2022-08-30 18:29:25 +02:00
commit 95d59ba72a
2 changed files with 97 additions and 24 deletions

View file

@ -9,9 +9,8 @@ Class SWWMAchievementMenu : GenericMenu
SWWMStaticHandler hnd;
Array<SWWMAchievementInfo> mItems;
String mTitle;
int mSelected;
int mBaseY; // Y position achievement boxes are being drawn at
// needed to tune mouse selection
int mSelected, mBaseY, mRows;
int ofs, maxofs; // physical scroll offset, and offset limit
int completed, incomplete, total;
Font mSmallFont, mTinyFont;
@ -61,6 +60,12 @@ Class SWWMAchievementMenu : GenericMenu
if ( !!(hnd.achievementstate.At(mItems[i].basename).ToInt()) ) completed++;
else if ( mItems[i].maxval && mItems[i].val ) incomplete++;
}
// calculate how many rows to display
int realh = (Screen.GetHeight()/CleanYFac_1)-160;
int rows = int(ceil(mItems.Size()/12.));
mRows = min(rows,realh/40);
mBaseY = (Screen.GetHeight()-mRows*40*CleanYFac_1)/2;
maxofs = max(0,rows-mRows);
}
int DrawCaption()
@ -166,19 +171,74 @@ Class SWWMAchievementMenu : GenericMenu
case MKEY_Right:
if ( ((mSelected%12) < 11) && (mSelected < mItems.Size()-1) ) mSelected++;
break;
case MKEY_PageUp:
if ( ofs > 0 ) MenuSound("menu/cursor");
ofs = max(0,ofs-1);
break;
case MKEY_PageDown:
if ( ofs < maxofs ) MenuSound("menu/cursor");
ofs = min(ofs+1,maxofs);
break;
default:
return Super.MenuEvent(mkey,fromcontroller);
}
if ( mSelected != prevsel ) MenuSound("menu/cursor");
if ( mSelected != prevsel )
{
MenuSound("menu/cursor");
// auto-scroll to selection
int irow = mSelected/12;
if ( irow < ofs ) ofs = max(0,irow);
else if ( irow >= (ofs+mRows) ) ofs = min(maxofs,(irow+1)-mRows);
}
return true;
}
override bool OnUiEvent( UIEvent ev )
{
switch ( ev.type )
{
case UIEvent.Type_WheelDown:
MenuEvent(MKEY_PageDown,false);
return false;
case UIEvent.Type_WheelUp:
MenuEvent(MKEY_PageUp,false);
return false;
}
return Super.OnUiEvent(ev);
}
override bool MouseEvent( int type, int mx, int my )
{
bool res = Super.MouseEvent(type,mx,my);
int xx = (Screen.GetWidth()-480*CleanXFac_1)/2;
int yy = mBaseY;
for ( int i=0; i<mItems.Size(); i++ )
if ( type != MOUSE_Click ) return res;
int xx, yy;
// first of all, check the scroll buttons
if ( maxofs > 0 )
{
xx = (Screen.GetWidth()+488*CleanXFac_1)/2;
yy = mBaseY;
if ( (mx >= xx) && (mx < xx+8*CleanXFac_1) && (my >= yy) && (my < yy+mRows*40*CleanYFac_1) )
{
if ( my < yy+mSmallFont.GetHeight()*CleanYFac_1 )
{
if ( ofs > 0 ) MenuSound("menu/cursor");
ofs = max(0,ofs-1);
return res;
}
yy += (mRows*40-mSmallFont.GetHeight())*CleanYFac_1;
if ( my >= yy )
{
if ( ofs < maxofs ) MenuSound("menu/cursor");
ofs = min(ofs+1,maxofs);
return res;
}
}
}
if ( (my < mBaseY) || (my >= mBaseY+mRows*40*CleanYFac_1) )
return res;
xx = (Screen.GetWidth()-480*CleanXFac_1)/2;
yy = mBaseY;
for ( int i=ofs*12; i<mItems.Size(); i++ )
{
int left = xx+4*CleanXFac_1;
int top = yy+4*CleanXFac_1;
@ -196,6 +256,7 @@ Class SWWMAchievementMenu : GenericMenu
xx = (Screen.GetWidth()-480*CleanXFac_1)/2;
yy += 40*CleanYFac_1;
}
if ( yy >= mBaseY+mRows*40*CleanYFac_1 ) break;
}
return res;
}
@ -203,35 +264,47 @@ Class SWWMAchievementMenu : GenericMenu
override void Drawer()
{
Super.Drawer();
int y = DrawCaption()+16*CleanYFac_1;
DrawTooltip(y);
int xx = (Screen.GetWidth()-480*CleanXFac_1)/2;
int yy = y+48*CleanYFac_1;
mBaseY = yy;
int i;
for ( i=0; i<mItems.Size(); i++ )
DrawCaption();
DrawTooltip(mBaseY-40*CleanYFac_1);
// draw scroll buttons (if any)
int xx, yy;
if ( maxofs > 0 )
{
let a = mItems[i];
bool completed = !!a.state;
bool hasprogress = (a.maxval && a.val);
Screen.DrawTexture(BaseBox,false,xx+5*CleanXFac_1,yy+5*CleanYFac_1,DTA_CleanNoMove_1,true,DTA_FillColor,(!completed&&!hasprogress&&ShouldObscure)?Color(8,8,8):Color(16,16,16));
Screen.DrawTexture((!completed&&!hasprogress&&ShouldObscure)?AchievementUnknown:a.icon,false,xx+4*CleanXFac_1,yy+4*CleanYFac_1,DTA_CleanNoMove_1,true,DTA_Desaturate,(!completed)*255,DTA_ColorOverlay,completed?Color(0,0,0,0):(hasprogress||!ShouldObscure)?Color(96,0,0,0):Color(192,0,0,0));
if ( mSelected == i ) Screen.DrawTexture(SelectBox,false,xx,yy,DTA_CleanNoMove_1,true);
xx = (Screen.GetWidth()+488*CleanXFac_1)/2;
yy = mBaseY;
Screen.DrawText(mSmallFont,(ofs>0)?Font.CR_GREEN:Font.CR_DARKGREEN,xx*CleanXFac_1,yy*CleanYFac_1,(ofs>0)?"▲":"△",DTA_CleanNoMove_1,true);
yy += (mRows*40-mSmallFont.GetHeight())*CleanYFac_1;
Screen.DrawText(mSmallFont,(ofs<maxofs)?Font.CR_GREEN:Font.CR_DARKGREEN,xx*CleanXFac_1,yy*CleanYFac_1,(ofs<maxofs)?"▼":"▽",DTA_CleanNoMove_1,true);
}
xx = (Screen.GetWidth()-480*CleanXFac_1)/2;
yy = int(mBaseY);
int i;
for ( i=ofs*12; i<mItems.Size(); i++ )
{
if ( (yy+40*CleanYFac_1 >= mBaseY) && (yy < mBaseY+mRows*40*CleanYFac_1) )
{
let a = mItems[i];
bool completed = !!a.state;
bool hasprogress = (a.maxval && a.val);
Screen.DrawTexture(BaseBox,false,xx+5*CleanXFac_1,yy+5*CleanYFac_1,DTA_CleanNoMove_1,true,DTA_FillColor,(!completed&&!hasprogress&&ShouldObscure)?Color(8,8,8):Color(16,16,16));
Screen.DrawTexture((!completed&&!hasprogress&&ShouldObscure)?AchievementUnknown:a.icon,false,xx+4*CleanXFac_1,yy+4*CleanYFac_1,DTA_CleanNoMove_1,true,DTA_Desaturate,(!completed)*255,DTA_ColorOverlay,completed?Color(0,0,0,0):(hasprogress||!ShouldObscure)?Color(96,0,0,0):Color(192,0,0,0));
if ( mSelected == i ) Screen.DrawTexture(SelectBox,false,xx,yy,DTA_CleanNoMove_1,true);
}
xx += 40*CleanXFac_1;
if ( !((i+1)%12) )
{
xx = (Screen.GetWidth()-480*CleanXFac_1)/2;
yy += 40*CleanYFac_1;
}
if ( yy >= mBaseY+mRows*40*CleanYFac_1 ) break;
}
while ( i%12 )
if ( yy < mBaseY+mRows*40*CleanYFac_1 ) while ( i%12 )
{
Screen.DrawTexture(BaseBox,false,xx+5*CleanXFac_1,yy+5*CleanYFac_1,DTA_CleanNoMove_1,true,DTA_FillColor,Color(8,8,8));
Screen.DrawTexture(BaseBox,false,xx+4*CleanXFac_1,yy+4*CleanYFac_1,DTA_CleanNoMove_1,true);
xx += 40*CleanXFac_1;
i++;
}
yy += 48*CleanYFac_1;
DrawFooter(yy);
DrawFooter(mBaseY+(mRows*40+8)*CleanYFac_1);
}
}