From ebf394f568766b89741989b32efe49254b8089a4 Mon Sep 17 00:00:00 2001 From: Marisa the Magician Date: Wed, 5 Jul 2023 17:38:51 +0200 Subject: [PATCH] More weapon selector work, should be good now. --- language.version | 4 +- zscript/handler/swwm_handler_process.zsc | 4 +- zscript/hud/swwm_hudextra.zsc | 111 ++++++++++++++++++----- 3 files changed, 95 insertions(+), 24 deletions(-) diff --git a/language.version b/language.version index 5ce38780f..09c626353 100644 --- a/language.version +++ b/language.version @@ -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-"; diff --git a/zscript/handler/swwm_handler_process.zsc b/zscript/handler/swwm_handler_process.zsc index 41cd7e6d8..9556de094 100644 --- a/zscript/handler/swwm_handler_process.zsc +++ b/zscript/handler/swwm_handler_process.zsc @@ -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; } diff --git a/zscript/hud/swwm_hudextra.zsc b/zscript/hud/swwm_hudextra.zsc index d2b3e9a3e..ce5807cd7 100644 --- a/zscript/hud/swwm_hudextra.zsc +++ b/zscript/hud/swwm_hudextra.zsc @@ -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 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()-1) ) return; - cursel++; + if ( (weaps.Size() <= 1) || !CanScroll() ) return; + for ( int i=0; i= 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= 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.; } }