diff --git a/language.version b/language.version index 180767b69..dfa516df9 100644 --- a/language.version +++ b/language.version @@ -1,3 +1,3 @@ [default] -SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r387 \cu(Tue 30 Aug 17:44:34 CEST 2022)\c-"; -SWWM_SHORTVER="\cw1.3pre r387 \cu(2022-08-30 17:44:34)\c-"; +SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r388 \cu(Tue 30 Aug 18:29:25 CEST 2022)\c-"; +SWWM_SHORTVER="\cw1.3pre r388 \cu(2022-08-30 18:29:25)\c-"; diff --git a/zscript/menu/swwm_achievementmenu.zsc b/zscript/menu/swwm_achievementmenu.zsc index 87a7cfd89..5a1925727 100644 --- a/zscript/menu/swwm_achievementmenu.zsc +++ b/zscript/menu/swwm_achievementmenu.zsc @@ -9,9 +9,8 @@ Class SWWMAchievementMenu : GenericMenu SWWMStaticHandler hnd; Array 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 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= 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 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= 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); } }