More weapon selector work, should be good now.
This commit is contained in:
parent
fa0796396e
commit
ebf394f568
3 changed files with 95 additions and 24 deletions
|
|
@ -1,3 +1,3 @@
|
|||
[default]
|
||||
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r825 \cu(Tue 4 Jul 17:35:57 CEST 2023)\c-";
|
||||
SWWM_SHORTVER="\cw1.3pre r825 \cu(2023-07-04 17:35:57)\c-";
|
||||
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r826 \cu(Wed 5 Jul 17:38:51 CEST 2023)\c-";
|
||||
SWWM_SHORTVER="\cw1.3pre r826 \cu(2023-07-05 17:38:51)\c-";
|
||||
|
|
|
|||
|
|
@ -582,7 +582,9 @@ extend Class SWWMHandler
|
|||
if ( !wsel && SWWMWeaponSelect.PlayerHasWeapons(players[consoleplayer].mo) )
|
||||
{
|
||||
wsel = new("SWWMWeaponSelect").Init(players[consoleplayer].mo);
|
||||
StatusBar.AttachMessage(wsel,-2920);
|
||||
StatusBar.AttachMessage(wsel,-2920,layer:StatusBar.HUDMSGLayer_UnderHUD);
|
||||
if ( WeapSel == 1 ) wsel.WeapNext();
|
||||
else if ( WeapSel == -1 ) wsel.WeapPrev();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -829,6 +829,7 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
double alph, olalph;
|
||||
double curY, smoothY, olsmoothY;
|
||||
int stage;
|
||||
Font fnt;
|
||||
|
||||
private int CmpWeapon( Weapon a, Weapon b )
|
||||
{
|
||||
|
|
@ -897,6 +898,7 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
sz *= .125;
|
||||
h += sz.y;
|
||||
}
|
||||
else h += fnt.GetHeight();
|
||||
if ( i == cursel ) cur = th+(h*.5);
|
||||
th += h;
|
||||
}
|
||||
|
|
@ -919,9 +921,12 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
// sort weapons
|
||||
qsort_weapons(0,weaps.Size()-1);
|
||||
// find current selected
|
||||
Weapon curweap = mo.player.ReadyWeapon;
|
||||
if ( curweap is 'SWWMGesture' ) curweap = SWWMGesture(curweap).formerweapon;
|
||||
else if ( curweap is 'SWWMItemGesture' ) curweap = SWWMItemGesture(curweap).gest.formerweapon;
|
||||
for ( int i=0; i<weaps.Size(); i++ )
|
||||
{
|
||||
if ( (weaps[i] != mo.player.ReadyWeapon) && (weaps[i].SisterWeapon != mo.player.ReadyWeapon) )
|
||||
if ( (weaps[i] != curweap) && (weaps[i].SisterWeapon != curweap) )
|
||||
continue;
|
||||
cursel = i;
|
||||
break;
|
||||
|
|
@ -930,6 +935,7 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
S_StartSound("menu/demotab",CHAN_AUTO,CHANF_UI);
|
||||
stage = 0;
|
||||
alph = 0.;
|
||||
fnt = Font.FindFont("TewiFontOutline");
|
||||
olsmoothY = smoothY = curY = CalcHeight();
|
||||
return self;
|
||||
}
|
||||
|
|
@ -946,10 +952,41 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
bar.ntagcol = nametagcolor;
|
||||
}
|
||||
|
||||
private bool CanScroll()
|
||||
{
|
||||
double ht = 20.; // extra padding
|
||||
if ( weaps[cursel] )
|
||||
{
|
||||
if ( weaps[cursel].Icon.IsValid() )
|
||||
{
|
||||
Vector2 sz = TexMan.GetScaledSize(weaps[cursel].Icon);
|
||||
if ( weaps[cursel] is 'SWWMWeapon' )
|
||||
ht += sz.y*.0625;
|
||||
else ht += sz.y*.5;
|
||||
}
|
||||
else ht += fnt.GetHeight()*.5;
|
||||
}
|
||||
return (abs(smoothY-curY) < ht);
|
||||
}
|
||||
|
||||
private bool WeaponHasAmmo( Weapon w )
|
||||
{
|
||||
if ( SWWMWeapon(w) )
|
||||
return SWWMWeapon(w).ReportHUDAmmo();
|
||||
if ( (!w.Ammo1 || (w.Ammo1.Amount > 0) || w.bAMMO_OPTIONAL) || (w.Ammo2 && ((w.Ammo2.Amount > 0) || w.bALT_AMMO_OPTIONAL)) )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void WeapPrev()
|
||||
{
|
||||
if ( (weaps.Size() <= 1) || (cursel <= 0) ) return;
|
||||
cursel--;
|
||||
if ( (weaps.Size() <= 1) || !CanScroll() ) return;
|
||||
for ( int i=0; i<weaps.Size(); i++ )
|
||||
{
|
||||
cursel--;
|
||||
if ( cursel < 0 ) cursel = weaps.Size()-1;
|
||||
if ( WeaponHasAmmo(weaps[cursel]) ) break;
|
||||
}
|
||||
curY = CalcHeight();
|
||||
S_StartSound("menu/demoscroll",CHAN_AUTO,CHANF_UI);
|
||||
if ( !weaps[cursel] || !(displaynametags&2) ) return;
|
||||
|
|
@ -958,8 +995,13 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
|
||||
void WeapNext()
|
||||
{
|
||||
if ( (weaps.Size() <= 1) || (cursel >= weaps.Size()-1) ) return;
|
||||
cursel++;
|
||||
if ( (weaps.Size() <= 1) || !CanScroll() ) return;
|
||||
for ( int i=0; i<weaps.Size(); i++ )
|
||||
{
|
||||
cursel++;
|
||||
if ( cursel >= weaps.Size() ) cursel = 0;
|
||||
if ( WeaponHasAmmo(weaps[cursel]) ) break;
|
||||
}
|
||||
curY = CalcHeight();
|
||||
S_StartSound("menu/demoscroll",CHAN_AUTO,CHANF_UI);
|
||||
if ( !weaps[cursel] || !(displaynametags&2) ) return;
|
||||
|
|
@ -968,13 +1010,15 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
|
||||
void WeapSel()
|
||||
{
|
||||
if ( !CanScroll() ) return;
|
||||
stage = 2;
|
||||
if ( !weaps[cursel] ) return;
|
||||
EventHandler.SendNetworkEvent(String.Format("swwmselweapon.%s",weaps[cursel].GetClassName()),mo.PlayerNumber());
|
||||
if ( !weaps[cursel] ) S_StartSound("menu/democlose",CHAN_AUTO,CHANF_UI|CHANF_OVERLAP);
|
||||
else EventHandler.SendNetworkEvent(String.Format("swwmselweapon.%s",weaps[cursel].GetClassName()),mo.PlayerNumber());
|
||||
}
|
||||
|
||||
void WeapCancel()
|
||||
{
|
||||
if ( !CanScroll() ) return;
|
||||
stage = 2;
|
||||
S_StartSound("menu/democlose",CHAN_AUTO,CHANF_UI|CHANF_OVERLAP);
|
||||
}
|
||||
|
|
@ -982,11 +1026,14 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
override bool Tick()
|
||||
{
|
||||
int oldsiz = weaps.Size();
|
||||
bool bChanged = false;
|
||||
Weapon oldsel = (weaps.Size()<=0)?null:weaps[cursel];
|
||||
for ( int i=0; i<weaps.Size(); i++ )
|
||||
{
|
||||
if ( weaps[i] ) continue;
|
||||
if ( weaps[i] && (weaps[i].Owner == mo) ) continue;
|
||||
bChanged = true;
|
||||
weaps.Delete(i);
|
||||
if ( cursel >= i ) cursel--;
|
||||
if ( cursel > i ) cursel--;
|
||||
i--;
|
||||
}
|
||||
for ( Inventory i=mo.inv; i; i=i.inv )
|
||||
|
|
@ -997,14 +1044,16 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
if ( (w is 'SWWMWeapon') && SWWMWeapon(w).bHIDEINMENU ) continue;
|
||||
if ( weaps.Find(w) < weaps.Size() ) continue;
|
||||
weaps.Push(w);
|
||||
bChanged = true;
|
||||
}
|
||||
if ( cursel >= weaps.Size() ) cursel = max(0,weaps.Size()-1);
|
||||
if ( weaps.Size() <= 0 ) stage = 2; // force close if no weapons available
|
||||
else if ( weaps.Size() != oldsiz )
|
||||
else if ( bChanged )
|
||||
{
|
||||
// re-sort and reposition
|
||||
let csel = weaps[cursel];
|
||||
qsort_weapons(0,weaps.Size()-1);
|
||||
cursel = weaps.Find(csel);
|
||||
let idx = weaps.Find(oldsel);
|
||||
if ( idx < weaps.Size() ) cursel = idx;
|
||||
curY = CalcHeight();
|
||||
}
|
||||
olalph = alph;
|
||||
|
|
@ -1035,7 +1084,9 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
}
|
||||
// smooth scroll
|
||||
olsmoothY = smoothY;
|
||||
smoothY = smoothY*.6+curY*.4;
|
||||
smoothY = smoothY*.8+curY*.2;
|
||||
double hs = max(min(floor(Screen.GetWidth()/640.),floor(Screen.GetHeight()/360.)),1.);
|
||||
if ( abs(smoothY-curY) < (1./hs) ) smoothY = curY;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1062,25 +1113,43 @@ Class SWWMWeaponSelect : HUDMessageBase
|
|||
let sw = SWWMWeapon(weaps[i]);
|
||||
double scl = sw?.125:1.;
|
||||
y += 8.;
|
||||
double fade = clamp(.8-abs(y-hss.y)/hss.y,0.,.8)/.8;
|
||||
bool bHasAmmo = WeaponHasAmmo(w);
|
||||
TextureID ico = w.Icon;
|
||||
if ( ico.IsValid() )
|
||||
{
|
||||
Vector2 sz = TexMan.GetScaledSize(ico);
|
||||
y += sz.y*scl*.5;
|
||||
double fade = clamp(.75-abs(y-hss.y)/hss.y,0.,.75)/.75;
|
||||
bool bHasAmmo = false;
|
||||
if ( sw ) bHasAmmo = sw.ReportHUDAmmo();
|
||||
else if ( (!w.Ammo1 || (w.Ammo1.Amount > 0) || w.bAMMO_OPTIONAL) || (w.Ammo2 && ((w.Ammo2.Amount > 0) || w.bALT_AMMO_OPTIONAL)) )
|
||||
bHasAmmo = true;
|
||||
if ( sw && sw.SisterWeapon && (sw.Amount > 1) && ((mo.player.ReadyWeapon == sw) || ((mo.player.ReadyWeapon != sw.SisterWeapon) && !swwm_singlefirst)) )
|
||||
{
|
||||
// double draw
|
||||
Screen.DrawTexture(ico,false,x-(4.*hs),(y-4.)*hs,DTA_ScaleX,scl*hs,DTA_ScaleY,scl*hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true,DTA_Color,bHasAmmo?0xFFFFFFFF:0xFF800000,DTA_ColorOverlay,(i==cursel)?0x00000000:0x40000000);
|
||||
Screen.DrawTexture(ico,false,x+(4.*hs),(y+4.)*hs,DTA_ScaleX,scl*hs,DTA_ScaleY,scl*hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true,DTA_Color,bHasAmmo?0xFFFFFFFF:0xFF800000,DTA_ColorOverlay,(i==cursel)?0x00000000:0x40000000);
|
||||
Screen.DrawTexture(ico,false,x-(4.*hs),(y-4.)*hs,DTA_ScaleX,scl*hs,DTA_ScaleY,scl*hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true,DTA_Color,bHasAmmo?0xFFFFFFFF:0xFF800000,DTA_ColorOverlay,(i==cursel)?0x00000000:0x80000000);
|
||||
Screen.DrawTexture(ico,false,x+(4.*hs),(y+4.)*hs,DTA_ScaleX,scl*hs,DTA_ScaleY,scl*hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true,DTA_Color,bHasAmmo?0xFFFFFFFF:0xFF800000,DTA_ColorOverlay,(i==cursel)?0x00000000:0x80000000);
|
||||
}
|
||||
else Screen.DrawTexture(ico,false,x,y*hs,DTA_ScaleX,scl*hs,DTA_ScaleY,scl*hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true,DTA_Color,bHasAmmo?0xFFFFFFFF:0xFF800000,DTA_ColorOverlay,(i==cursel)?0x00000000:0x80000000);
|
||||
if ( i == cursel )
|
||||
{
|
||||
Screen.DrawChar(fnt,Font.CR_FIRE,x-((sz.x*scl*.5+16.+2.*sin((gametic+fractic)*8.))*hs),y*hs,0x25BA,DTA_ScaleX,hs,DTA_ScaleY,hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true);
|
||||
Screen.DrawChar(fnt,Font.CR_FIRE,x+((sz.x*scl*.5+16.+2.*sin((gametic+fractic)*8.))*hs),y*hs,0x25C4,DTA_ScaleX,hs,DTA_ScaleY,hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true);
|
||||
}
|
||||
else Screen.DrawTexture(ico,false,x,y*hs,DTA_ScaleX,scl*hs,DTA_ScaleY,scl*hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true,DTA_Color,bHasAmmo?0xFFFFFFFF:0xFF800000,DTA_ColorOverlay,(i==cursel)?0x00000000:0x40000000);
|
||||
y += sz.y*scl*.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
String label = "?WeaponName?";
|
||||
if ( sw && sw.SisterWeapon && (sw.Amount > 1) && ((mo.player.ReadyWeapon == sw) || ((mo.player.ReadyWeapon != sw.SisterWeapon) && !swwm_singlefirst)) )
|
||||
label = sw.SisterWeapon.GetTag();
|
||||
else label = w.GetTag();
|
||||
Vector2 sz = (fnt.StringWidth(label),fnt.GetHeight());
|
||||
Screen.DrawText(fnt,bHasAmmo?Font.CR_WHITE:Font.CR_RED,x-sz.x*.5*hs,y*hs,label,DTA_ScaleX,hs,DTA_ScaleY,hs,DTA_Alpha,salph*fade,DTA_ColorOverlay,(i==cursel)?0x00000000:0x80000000);
|
||||
y += sz.y*.5;
|
||||
if ( i == cursel )
|
||||
{
|
||||
Screen.DrawChar(fnt,Font.CR_FIRE,x-((sz.x*.5+16.+2.*sin((gametic+fractic)*8.))*hs),y*hs,0x25BA,DTA_ScaleX,hs,DTA_ScaleY,hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true);
|
||||
Screen.DrawChar(fnt,Font.CR_FIRE,x+((sz.x*.5+16.+2.*sin((gametic+fractic)*8.))*hs),y*hs,0x25C4,DTA_ScaleX,hs,DTA_ScaleY,hs,DTA_Alpha,salph*fade,DTA_CenterOffset,true);
|
||||
}
|
||||
y += sz.y*.5;
|
||||
}
|
||||
y += 8.;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue