swwmgz_m/zscript/hud/swwm_hud_inventory.zsc

152 lines
5.9 KiB
Text

// Inventory drawing
extend Class SWWMStatusBar
{
private bool DrawInvIcon( Inventory i, double xx, double yy, double alpha = 1., bool forceamt = false, bool selected = false, bool aspowerup = false )
{
if ( !i || !i.Icon.IsValid() ) return false;
Vector2 scl = TexMan.GetScaledSize(i.Icon);
double mscl = min(1.,30./max(scl.x,scl.y));
double dw = (ss.x/mscl), dh = (ss.y/mscl);
double dx = (xx+(30-scl.x*mscl)/2)/mscl, dy = (yy+(30-scl.y*mscl)/2)/mscl;
if ( i is 'Powerup' )
{
Screen.DrawTexture(i.Icon,false,dx,dy,DTA_VirtualWidthF,dw,DTA_VirtualHeightF,dh,DTA_KeepRatio,true,DTA_Alpha,Powerup(i).IsBlinking()?alpha*.5:alpha,DTA_TopOffset,0,DTA_LeftOffset,0);
String nstr = String.Format("%ds",Powerup(i).EffectTics/GameTicRate);
int len = MiniHudFontOutline.StringWidth(nstr);
Screen.DrawText(MiniHudFontOutline,mhudfontcol[MCR_BRASS],(xx+30)-len,(yy+30)-6,nstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,Powerup(i).IsBlinking()?alpha*.5:alpha);
return true;
}
if ( (i is 'SWWMLamp') && aspowerup )
{
Screen.DrawTexture(i.Icon,false,dx,dy,DTA_VirtualWidthF,dw,DTA_VirtualHeightF,dh,DTA_KeepRatio,true,DTA_Alpha,SWWMLamp(i).isBlinking()?alpha*.5:alpha,DTA_TopOffset,0,DTA_LeftOffset,0);
String nstr = String.Format("%d%%",SWWMLamp(i).Charge);
int len = MiniHudFontOutline.StringWidth(nstr);
Screen.DrawText(MiniHudFontOutline,mhudfontcol[SWWMLamp(i).bActive?MCR_BRASS:MCR_WHITE],(xx+30)-len,(yy+30)-6,nstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,SWWMLamp(i).isBlinking()?alpha*.5:alpha);
return true;
}
if ( (i is 'DivineSpriteEffect') && aspowerup )
{
Screen.DrawTexture(i.Icon,false,dx,dy,DTA_VirtualWidthF,dw,DTA_VirtualHeightF,dh,DTA_KeepRatio,true,DTA_Alpha,DivineSpriteEffect(i).isBlinking()?alpha*.5:alpha,DTA_TopOffset,0,DTA_LeftOffset,0);
String nstr = String.Format("%ds",DivineSpriteEffect(i).healtim/GameTicRate);
int len = MiniHudFontOutline.StringWidth(nstr);
Screen.DrawText(MiniHudFontOutline,mhudfontcol[MCR_BRASS],(xx+30)-len,(yy+30)-6,nstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,DivineSpriteEffect(i).isBlinking()?alpha*.5:alpha);
return true;
}
Screen.DrawTexture(i.Icon,false,dx,dy,DTA_VirtualWidthF,dw,DTA_VirtualHeightF,dh,DTA_KeepRatio,true,DTA_Alpha,alpha,DTA_TopOffset,0,DTA_LeftOffset,0);
if ( (i.Amount > 1) || forceamt )
{
String nstr;
if ( (i.Amount > 99999) && !forceamt ) nstr = "99999";
else nstr = String.Format("%d",i.Amount);
int len = MiniHudFontOutline.StringWidth(nstr);
Screen.DrawText(MiniHudFontOutline,mhudfontcol[(i.Amount<=0)?MCR_RED:selected?MCR_BRASS:MCR_WHITE],(xx+30)-len,(yy+30)-6,nstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alpha);
}
return true;
}
private void DrawInventory()
{
int invy = 61;
// active items (armor / powerups)
double xx = xmargin+2;
double yy = ss.y-(ymargin+invy+9);
bool drewarmor = false;
for ( Inventory i=CPlayer.mo.Inv; i; i=i.Inv )
{
if ( (i.Amount <= 0) || (!(i is 'SWWMArmor') && !(i is 'BasicArmor')) ) continue;
if ( !DrawInvIcon(i,xx,yy,forceamt:true,selected:true) ) continue;
yy -= 34;
drewarmor = true;
}
yy = ss.y-(ymargin+invy+9);
if ( drewarmor )
{
xx += 36;
if ( CPlayer.mo.InvSel && !isInventoryBarVisible() ) yy -= 34;
}
int drawcnt = 0;
bool lastdrawn = false;
for ( Inventory i=CPlayer.mo.Inv; i; i=i.Inv )
{
if ( (drawcnt > 0) && !(drawcnt%3) && lastdrawn )
{
xx += 36;
yy = ss.y-(ymargin+invy+9);
if ( CPlayer.mo.InvSel && !isInventoryBarVisible() ) yy -= 34;
}
lastdrawn = false;
if ( (i is 'SWWMLamp') && (SWWMLamp(i).bActivated || (SWWMLamp(i).Charge < SWWMLamp(i).default.Charge)) )
{
DrawInvIcon(i,xx,yy,selected:true,aspowerup:true);
yy -= 34;
drawcnt++;
lastdrawn = true;
continue;
}
if ( (i is 'DivineSpriteEffect') && !DivineSpriteEffect(i).bHealDone )
{
DrawInvIcon(i,xx,yy,selected:true,aspowerup:true);
yy -= 34;
drawcnt++;
lastdrawn = true;
continue;
}
if ( !(i is 'Powerup') || (Powerup(i).EffectTics <= 0) || !(Powerup(i).Icon) ) continue;
if ( !DrawInvIcon(i,xx,yy) ) continue;
yy -= 34;
drawcnt++;
lastdrawn = true;
}
// inventory box / bar
if ( !CPlayer.mo.InvSel ) return;
if ( isInventoryBarVisible() )
{
int invcount = 0;
Inventory FirstInv = CPlayer.mo.FirstInv();
Inventory LastInv = CPlayer.mo.InvSel;
for ( Inventory i=FirstInv; i; i=i.NextInv() )
{
LastInv = i;
invcount++;
}
bool bSmol = (ss.x<640);
int maxj = bSmol?4:6;
double alphstep = clamp(invcount,1,maxj+1);
double xx = (ss.x-34)/2;
double yy = (ss.y+64)/2;
Screen.DrawTexture(InventoryTex,false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
// previous entries
int j = 1;
Inventory i = CPlayer.mo.InvSel.PrevInv()?CPlayer.mo.InvSel.PrevInv():LastInv;
while ( i )
{
if ( i == CPlayer.mo.InvSel ) break; // ensure we only loop around once
DrawInvIcon(i,(xx+2)-j*34,yy+2,(alphstep-j)/alphstep);
j++;
if ( j > maxj ) break;
i = i.PrevInv()?i.PrevInv():LastInv;
}
// next entries
j = 1;
i = CPlayer.mo.InvSel.NextInv()?CPlayer.mo.InvSel.NextInv():FirstInv;
while ( i )
{
if ( i == CPlayer.mo.InvSel ) break; // ensure we only loop around once
DrawInvIcon(i,(xx+2)+j*34,yy+2,(alphstep-j)/alphstep);
j++;
if ( j > maxj ) break;
i = i.NextInv()?i.NextInv():FirstInv;
}
// current
DrawInvIcon(CPlayer.mo.InvSel,xx+2,yy+2,selected:true);
return;
}
Screen.DrawTexture(InventoryTex,false,xmargin+36,ss.y-(ymargin+invy+2),DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
DrawInvIcon(CPlayer.mo.InvSel,xmargin+38,ss.y-(ymargin+invy),selected:true);
}
override void DrawPowerups()
{
// don't do anything, handled by inventory drawer
}
}