2017-03-21 19:09:09 +00:00
2017-03-25 00:22:42 +00:00
struct MugShot
{
enum StateFlags
{
STANDARD = 0x0,
XDEATHFACE = 0x1,
ANIMATEDGODMODE = 0x2,
DISABLEGRIN = 0x4,
DISABLEOUCH = 0x8,
DISABLEPAIN = 0x10,
DISABLERAMPAGE = 0x20,
CUSTOM = 0x40,
}
}
2017-03-26 16:41:24 +00:00
class HUDFont native ui
{
2017-03-26 23:02:10 +00:00
native Font mFont;
2019-04-13 16:10:58 +00:00
native static HUDFont Create(Font fnt, int spacing = 0, EMonospacing monospacing = Mono_Off, int shadowx = 0, int shadowy = 0);
2017-03-26 16:41:24 +00:00
}
2017-03-26 23:02:10 +00:00
class InventoryBarState ui
{
TextureID box;
TextureID selector;
Vector2 boxsize;
2017-03-27 19:01:40 +00:00
Vector2 boxofs;
2017-03-28 09:00:05 +00:00
Vector2 selectofs;
2017-03-26 23:02:10 +00:00
Vector2 innersize;
2017-03-27 19:01:40 +00:00
2017-03-26 23:02:10 +00:00
TextureID left;
TextureID right;
Vector2 arrowoffset;
double itemalpha;
HUDFont amountfont;
int cr;
int flags;
2017-03-27 19:29:31 +00:00
private static void Init(InventoryBarState me, HUDFont indexfont, int cr, double itemalpha, Vector2 innersize, String leftgfx, String rightgfx, Vector2 arrowoffs, int flags)
2017-03-26 23:02:10 +00:00
{
me.itemalpha = itemalpha;
2017-03-27 19:01:40 +00:00
if (innersize == (0, 0))
{
me.boxofs = (2, 2);
me.innersize = me.boxsize - (4, 4); // Default is based on Heretic's and Hexens icons.
}
else
{
me.innersize = innersize;
me.boxofs = (me.boxsize - me.innersize) / 2;
}
2017-03-28 09:00:05 +00:00
if (me.selector.IsValid())
{
Vector2 sel = TexMan.GetScaledSize(me.selector);
me.selectofs = (me.boxsize - sel) / 2;
}
2017-03-26 23:02:10 +00:00
me.left = TexMan.CheckForTexture(leftgfx, TexMan.TYPE_MiscPatch);
me.right = TexMan.CheckForTexture(rightgfx, TexMan.TYPE_MiscPatch);
me.arrowoffset = arrowoffs;
me.arrowoffset.Y += me.boxsize.Y/2; // default is centered to the side of the box.
if (indexfont == null)
{
me.amountfont = HUDFont.Create("INDEXFONT");
if (cr == Font.CR_UNTRANSLATED) cr = Font.CR_GOLD;
}
else me.amountfont = indexfont;
me.cr = cr;
me.flags = flags;
2017-03-27 19:29:31 +00:00
}
// The default settings here are what SBARINFO is using.
static InventoryBarState Create(HUDFont indexfont = null, int cr = Font.CR_UNTRANSLATED, double itemalpha = 1.,
String boxgfx = "ARTIBOX", String selgfx = "SELECTBO", Vector2 innersize = (0, 0),
String leftgfx = "INVGEML1", String rightgfx = "INVGEMR1", Vector2 arrowoffs = (0, 0), int flags = 0)
{
let me = new ("InventoryBarState");
me.box = TexMan.CheckForTexture(boxgfx, TexMan.TYPE_MiscPatch);
me.selector = TexMan.CheckForTexture(selgfx, TexMan.TYPE_MiscPatch);
if (me.box.IsValid() || me.selector.IsValid()) me.boxsize = TexMan.GetScaledSize(me.box.IsValid()? me.box : me.selector);
else me.boxsize = (32., 32.);
Init(me, indexfont, cr, itemalpha, innersize, leftgfx, rightgfx, arrowoffs, flags);
2017-03-26 23:02:10 +00:00
return me;
}
2017-03-27 19:29:31 +00:00
// The default settings here are what SBARINFO is using.
static InventoryBarState CreateNoBox(HUDFont indexfont = null, int cr = Font.CR_UNTRANSLATED, double itemalpha = 1.,
Vector2 boxsize = (32, 32), String selgfx = "SELECTBO", Vector2 innersize = (0, 0),
String leftgfx = "INVGEML1", String rightgfx = "INVGEMR1", Vector2 arrowoffs = (0, 0), int flags = 0)
{
let me = new ("InventoryBarState");
me.box.SetInvalid();
me.selector = TexMan.CheckForTexture(selgfx, TexMan.TYPE_MiscPatch);
me.boxsize = boxsize;
Init(me, indexfont, cr, itemalpha, innersize, leftgfx, rightgfx, arrowoffs, flags);
return me;
}
2017-03-26 23:02:10 +00:00
}
2018-03-01 10:45:19 +00:00
class HUDMessageBase native ui
{
virtual native bool Tick();
virtual native void ScreenSizeChanged();
virtual native void Draw(int bottom, int visibility);
}
2017-03-25 00:22:42 +00:00
2017-03-21 19:09:09 +00:00
class BaseStatusBar native ui
{
enum EPop
{
POP_NoChange = -1,
POP_None,
POP_Log,
POP_Keys,
POP_Status
}
// Status face stuff
enum EMug
{
ST_NUMPAINFACES = 5,
ST_NUMSTRAIGHTFACES = 3,
ST_NUMTURNFACES = 2,
ST_NUMSPECIALFACES = 3,
ST_NUMEXTRAFACES = 2,
ST_FACESTRIDE = ST_NUMSTRAIGHTFACES+ST_NUMTURNFACES+ST_NUMSPECIALFACES,
ST_NUMFACES = ST_FACESTRIDE*ST_NUMPAINFACES+ST_NUMEXTRAFACES,
ST_TURNOFFSET = ST_NUMSTRAIGHTFACES,
ST_OUCHOFFSET = ST_TURNOFFSET + ST_NUMTURNFACES,
ST_EVILGRINOFFSET = ST_OUCHOFFSET + 1,
ST_RAMPAGEOFFSET = ST_EVILGRINOFFSET + 1,
ST_GODFACE = ST_NUMPAINFACES*ST_FACESTRIDE,
ST_DEADFACE = ST_GODFACE + 1
}
enum EHudState
{
HUD_StatusBar,
HUD_Fullscreen,
HUD_None,
HUD_AltHud // Used for passing through popups to the alt hud
}
2018-03-07 13:58:43 +00:00
enum EHUDMSGLayer
{
HUDMSGLayer_OverHUD,
HUDMSGLayer_UnderHUD,
HUDMSGLayer_OverMap,
NUM_HUDMSGLAYERS,
HUDMSGLayer_Default = HUDMSGLayer_OverHUD,
};
2017-03-24 01:12:03 +00:00
enum DI_Flags
{
DI_SKIPICON = 0x1,
DI_SKIPALTICON = 0x2,
DI_SKIPSPAWN = 0x4,
DI_SKIPREADY = 0x8,
DI_ALTICONFIRST = 0x10,
DI_TRANSLATABLE = 0x20,
2017-03-24 19:07:22 +00:00
DI_FORCESCALE = 0x40,
DI_DIM = 0x80,
2017-03-26 16:41:24 +00:00
DI_DRAWCURSORFIRST = 0x100, // only for DrawInventoryBar.
DI_ALWAYSSHOWCOUNT = 0x200, // only for DrawInventoryBar.
DI_DIMDEPLETED = 0x400,
DI_DONTANIMATE = 0x800, // do not animate the texture
2018-03-22 12:22:39 +00:00
DI_MIRROR = 0x1000, // flip the texture horizontally, like a mirror
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_SCREEN_AUTO = 0, // decide based on given offsets.
DI_SCREEN_MANUAL_ALIGN = 0x4000, // If this is on, the following flags will have an effect
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_SCREEN_TOP = DI_SCREEN_MANUAL_ALIGN,
DI_SCREEN_VCENTER = 0x8000 | DI_SCREEN_MANUAL_ALIGN,
DI_SCREEN_BOTTOM = 0x10000 | DI_SCREEN_MANUAL_ALIGN,
DI_SCREEN_VOFFSET = 0x18000 | DI_SCREEN_MANUAL_ALIGN,
DI_SCREEN_VMASK = 0x18000 | DI_SCREEN_MANUAL_ALIGN,
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_SCREEN_LEFT = DI_SCREEN_MANUAL_ALIGN,
DI_SCREEN_HCENTER = 0x20000 | DI_SCREEN_MANUAL_ALIGN,
DI_SCREEN_RIGHT = 0x40000 | DI_SCREEN_MANUAL_ALIGN,
DI_SCREEN_HOFFSET = 0x60000 | DI_SCREEN_MANUAL_ALIGN,
DI_SCREEN_HMASK = 0x60000 | DI_SCREEN_MANUAL_ALIGN,
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_SCREEN_LEFT_TOP = DI_SCREEN_TOP|DI_SCREEN_LEFT,
DI_SCREEN_RIGHT_TOP = DI_SCREEN_TOP|DI_SCREEN_RIGHT,
DI_SCREEN_LEFT_BOTTOM = DI_SCREEN_BOTTOM|DI_SCREEN_LEFT,
DI_SCREEN_RIGHT_BOTTOM = DI_SCREEN_BOTTOM|DI_SCREEN_RIGHT,
DI_SCREEN_CENTER = DI_SCREEN_VCENTER|DI_SCREEN_HCENTER,
DI_SCREEN_CENTER_BOTTOM = DI_SCREEN_BOTTOM|DI_SCREEN_HCENTER,
DI_SCREEN_OFFSETS = DI_SCREEN_HOFFSET|DI_SCREEN_VOFFSET,
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_ITEM_AUTO = 0, // equivalent with bottom center, which is the default alignment.
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_ITEM_TOP = 0x80000,
DI_ITEM_VCENTER = 0x100000,
DI_ITEM_BOTTOM = 0, // this is the default vertical alignment
DI_ITEM_VOFFSET = 0x180000,
DI_ITEM_VMASK = 0x180000,
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_ITEM_LEFT = 0x200000,
2018-11-26 16:15:40 +00:00
DI_ITEM_HCENTER = 0, // this is the default horizontal alignment
2017-03-26 16:41:24 +00:00
DI_ITEM_RIGHT = 0x400000,
DI_ITEM_HOFFSET = 0x600000,
DI_ITEM_HMASK = 0x600000,
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_ITEM_LEFT_TOP = DI_ITEM_TOP|DI_ITEM_LEFT,
DI_ITEM_RIGHT_TOP = DI_ITEM_TOP|DI_ITEM_RIGHT,
DI_ITEM_LEFT_BOTTOM = DI_ITEM_BOTTOM|DI_ITEM_LEFT,
DI_ITEM_RIGHT_BOTTOM = DI_ITEM_BOTTOM|DI_ITEM_RIGHT,
DI_ITEM_CENTER = DI_ITEM_VCENTER|DI_ITEM_HCENTER,
DI_ITEM_CENTER_BOTTOM = DI_ITEM_BOTTOM|DI_ITEM_HCENTER,
DI_ITEM_OFFSETS = DI_ITEM_HOFFSET|DI_ITEM_VOFFSET,
2017-03-27 19:01:40 +00:00
2017-03-26 16:41:24 +00:00
DI_TEXT_ALIGN_LEFT = 0,
DI_TEXT_ALIGN_RIGHT = 0x800000,
DI_TEXT_ALIGN_CENTER = 0x1000000,
2017-03-27 19:01:40 +00:00
DI_TEXT_ALIGN = 0x1800000,
2017-03-21 19:09:09 +00:00
2017-03-26 16:41:24 +00:00
DI_ALPHAMAPPED = 0x2000000,
2017-03-26 20:04:58 +00:00
DI_NOSHADOW = 0x4000000,
2017-03-26 23:02:10 +00:00
DI_ALWAYSSHOWCOUNTERS = 0x8000000,
2017-03-27 19:01:40 +00:00
DI_ARTIFLASH = 0x10000000,
DI_FORCEFILL = 0x20000000,
// These 2 flags are only used by SBARINFO so these duplicate other flags not used by SBARINFO
DI_DRAWINBOX = DI_TEXT_ALIGN_RIGHT,
DI_ALTERNATEONFAIL = DI_TEXT_ALIGN_CENTER,
2017-03-26 16:41:24 +00:00
};
2017-03-24 01:12:03 +00:00
enum IconType
{
2017-03-24 19:07:22 +00:00
ITYPE_PLAYERICON = 1000,
ITYPE_AMMO1,
ITYPE_AMMO2,
ITYPE_ARMOR,
ITYPE_WEAPON,
ITYPE_SIGIL,
ITYPE_WEAPONSLOT,
ITYPE_SELECTEDINVENTORY,
}
enum HexArmorType
{
2017-03-24 01:12:03 +00:00
HEXENARMOR_ARMOR,
HEXENARMOR_SHIELD,
HEXENARMOR_HELM,
HEXENARMOR_AMULET,
};
enum AmmoModes
{
AMMO_PRIMARY,
AMMO_SECONDARY,
AMMO_ANY,
AMMO_BOTH
};
2017-03-21 19:09:09 +00:00
enum EHudDraw
{
HUD_Normal,
HUD_HorizCenter
}
2017-03-24 19:07:22 +00:00
enum ENumFlags
{
2018-01-07 22:04:51 +00:00
FNF_WHENNOTZERO = 0x1,
FNF_FILLZEROS = 0x2,
2017-03-24 19:07:22 +00:00
}
2017-03-27 19:01:40 +00:00
enum EShade
{
SHADER_HORZ = 0,
SHADER_VERT = 2,
SHADER_REVERSE = 1
}
2017-03-21 19:09:09 +00:00
const XHAIRSHRINKSIZE =(1./18);
const XHAIRPICKUPSIZE = (2+XHAIRSHRINKSIZE);
2017-03-24 21:57:44 +00:00
const POWERUPICONSIZE = 32;
2017-03-21 19:09:09 +00:00
native int RelTop;
native int HorizontalResolution, VerticalResolution;
native bool Centering;
native bool FixedOrigin;
native bool CompleteBorder;
native double CrosshairSize;
native double Displacement;
native PlayerInfo CPlayer;
2017-03-22 16:29:13 +00:00
native bool ShowLog;
2017-03-25 17:31:53 +00:00
native Vector2 defaultScale; // factor for fully scaled fullscreen display.
2018-12-01 16:17:08 +00:00
clearscope native int artiflashTick;
clearscope native double itemflashFade;
2017-03-24 01:12:03 +00:00
// These are block properties for the drawers. A child class can set them to have a block of items use the same settings.
native double Alpha;
native Vector2 drawOffset; // can be set by subclasses to offset drawing operations
native double drawClip[4]; // defines a clipping rectangle (not used yet)
native bool fullscreenOffsets; // current screen is displayed with fullscreen behavior.
2017-03-29 12:20:22 +00:00
private HUDFont mSmallFont;
2018-03-07 14:00:08 +00:00
native void AttachMessage(HUDMessageBase msg, uint msgid = 0, int layer = HUDMSGLayer_Default);
2018-03-01 10:45:19 +00:00
native HUDMessageBase DetachMessage(HUDMessageBase msg);
native HUDMessageBase DetachMessageID(uint msgid);
native void DetachAllMessages();
2017-03-21 19:09:09 +00:00
2017-03-29 17:23:40 +00:00
native void SetSize(int height, int vwidth, int vheight, int hwidth = -1, int hheight = -1);
2017-03-25 17:31:53 +00:00
native Vector2 GetHUDScale();
2017-03-29 17:23:40 +00:00
native void BeginStatusBar(bool forceScaled = false, int resW = -1, int resH = -1, int rel = -1);
native void BeginHUD(double Alpha = 1., bool forcescaled = false, int resW = -1, int resH = -1);
2017-03-25 17:31:53 +00:00
2018-10-20 17:22:11 +00:00
native void UpdateScreenGeometry();
2017-03-29 12:20:22 +00:00
virtual void Init()
{
mSmallFont = HUDFont.Create("SmallFont");
}
2017-03-22 16:29:13 +00:00
2017-03-21 19:09:09 +00:00
native virtual void Tick ();
native virtual void Draw (int state, double TicFrac);
2017-03-22 16:29:13 +00:00
native virtual void ScreenSizeChanged ();
2017-03-25 00:22:42 +00:00
native virtual clearscope void ReceivedWeapon (Weapon weapn);
2017-03-25 17:31:53 +00:00
native virtual clearscope void SetMugShotState (String state_name, bool wait_till_done=false, bool reset=false);
2017-03-22 16:29:13 +00:00
2018-12-01 16:17:08 +00:00
clearscope virtual void FlashItem (class<Inventory> itemtype) { artiflashTick = 4; itemflashFade = 0.75; }
2018-10-20 17:22:11 +00:00
virtual void AttachToPlayer (PlayerInfo player) { CPlayer = player; UpdateScreenGeometry(); }
2017-03-21 19:09:09 +00:00
virtual void FlashCrosshair () { CrosshairSize = XHAIRPICKUPSIZE; }
2017-03-27 07:52:30 +00:00
virtual void NewGame () { if (CPlayer != null) AttachToPlayer(CPlayer); }
2017-03-22 16:29:13 +00:00
virtual void ShowPop (int popnum) { ShowLog = (popnum == POP_Log && !ShowLog); }
2017-03-21 19:09:09 +00:00
virtual bool MustDrawLog(int state) { return true; }
2019-08-16 13:45:49 +00:00
// [MK] let the HUD handle notifications and centered print messages
virtual bool ProcessNotify(EPrintLevel printlevel, String outline) { return false; }
virtual void FlushNotify() {}
virtual bool ProcessMidPrint(Font fnt, String msg, bool bold) { return false; }
// [MK] let the HUD handle drawing the chat prompt
virtual bool DrawChat(String txt) { return false; }
2017-03-26 20:04:58 +00:00
native TextureID GetMugshot(int accuracy, int stateflags=MugShot.STANDARD, String default_face = "STF");
2017-03-24 19:07:22 +00:00
// These functions are kept native solely for performance reasons. They get called repeatedly and can drag down performance easily if they get too slow.
2017-03-23 14:18:09 +00:00
native static TextureID, bool GetInventoryIcon(Inventory item, int flags);
2017-03-26 16:41:24 +00:00
native void DrawTexture(TextureID texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1));
native void DrawImage(String texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1));
2019-11-14 15:51:06 +00:00
native void DrawString(HUDFont font, String string, Vector2 pos, int flags = 0, int translation = Font.CR_UNTRANSLATED, double Alpha = 1., int wrapwidth = -1, int linespacing = 4, Vector2 scale = (1, 1));
2017-04-02 10:56:26 +00:00
native double, double, double, double TransformRect(double x, double y, double w, double h, int flags = 0);
2017-03-28 09:00:05 +00:00
native void Fill(Color col, double x, double y, double w, double h, int flags = 0);
2017-03-26 16:41:24 +00:00
native static String FormatNumber(int number, int minsize = 0, int maxsize = 0, int format = 0, String prefix = "");
2017-03-29 12:20:22 +00:00
native double, double, double, double StatusbarToRealCoords(double x, double y=0, double w=0, double h=0);
2017-03-29 17:23:40 +00:00
native int GetTopOfStatusBar();
2017-03-30 10:13:28 +00:00
native void SetClipRect(double x, double y, double w, double h, int flags = 0);
void ClearClipRect()
{
screen.ClearClipRect();
}
2017-03-22 17:38:09 +00:00
2018-12-01 16:46:20 +00:00
//---------------------------------------------------------------------------
//
// ValidateInvFirst
//
// Returns an inventory item that, when drawn as the first item, is sure to
// include the selected item in the inventory bar.
//
//---------------------------------------------------------------------------
Inventory ValidateInvFirst (int numVisible) const
{
Inventory item;
int i;
let pmo = CPlayer.mo;
if (pmo.InvFirst == NULL)
{
pmo.InvFirst = pmo.FirstInv();
if (pmo.InvFirst == NULL)
{ // Nothing to show
return NULL;
}
}
// If there are fewer than numVisible items shown, see if we can shift the
// view left to show more.
for (i = 0, item = pmo.InvFirst; item != NULL && i < numVisible; ++i, item = item.NextInv())
{ }
while (i < numVisible)
{
item = pmo.InvFirst.PrevInv ();
if (item == NULL)
{
break;
}
else
{
pmo.InvFirst = item;
++i;
}
}
if (pmo.InvSel == NULL)
{
// Nothing selected, so don't move the view.
return pmo.InvFirst == NULL ? pmo.Inv : pmo.InvFirst;
}
else
{
// Check if InvSel is already visible
for (item = pmo.InvFirst, i = numVisible;
item != NULL && i != 0;
item = item.NextInv(), --i)
{
if (item == pmo.InvSel)
{
return pmo.InvFirst;
}
}
// Check if InvSel is to the right of the visible range
for (i = 1; item != NULL; item = item.NextInv(), ++i)
{
if (item == pmo.InvSel)
{
// Found it. Now advance InvFirst
for (item = pmo.InvFirst; i != 0; --i)
{
item = item.NextInv();
}
return item;
}
}
// Check if InvSel is to the left of the visible range
for (item = pmo.Inv;
item != pmo.InvSel;
item = item.NextInv())
{ }
if (item != NULL)
{
// Found it, so let it become the first item shown
return item;
}
// Didn't find the selected item, so don't move the view.
// This should never happen.
return pmo.InvFirst;
}
}
2017-03-22 17:38:09 +00:00
//============================================================================
//
// DBaseStatusBar :: GetCurrentAmmo
//
// Returns the types and amounts of ammo used by the current weapon. If the
// weapon only uses one type of ammo, it is always returned as ammo1.
//
//============================================================================
2017-03-27 19:01:40 +00:00
Ammo, Ammo, int, int GetCurrentAmmo () const
2017-03-22 17:38:09 +00:00
{
Ammo ammo1, ammo2;
if (CPlayer.ReadyWeapon != NULL)
{
ammo1 = CPlayer.ReadyWeapon.Ammo1;
ammo2 = CPlayer.ReadyWeapon.Ammo2;
if (ammo1 == NULL)
{
ammo1 = ammo2;
ammo2 = NULL;
}
}
else
{
ammo1 = ammo2 = NULL;
}
let ammocount1 = ammo1 != NULL ? ammo1.Amount : 0;
let ammocount2 = ammo2 != NULL ? ammo2.Amount : 0;
return ammo1, ammo2, ammocount1, ammocount2;
}
2017-03-23 14:18:09 +00:00
//============================================================================
//
// Get an icon
//
//============================================================================
2017-03-25 22:43:19 +00:00
TextureID, Vector2 GetIcon(Inventory item, int flags, bool showdepleted = true)
2017-03-23 14:18:09 +00:00
{
TextureID icon;
Vector2 scale = (1,1);
icon.SetInvalid();
if (item != null)
{
bool applyscale;
[icon, applyscale] = GetInventoryIcon(item, flags);
2017-03-25 22:43:19 +00:00
if (item.Amount == 0 && !showdepleted) return icon, scale;
2017-03-23 14:18:09 +00:00
if (applyscale)
scale = item.Scale;
}
2017-03-25 22:43:19 +00:00
return icon, scale;
2017-03-23 14:18:09 +00:00
}
2017-03-29 08:36:16 +00:00
//============================================================================
//
// Returns how much the status bar's graphics extend into the view
// Used for automap text positioning
// The parameter specifies how much of the status bar area will be covered
// by the element requesting this information.
//
//============================================================================
virtual int GetProtrusion(double scaleratio) const
{
return 0;
}
2017-03-24 01:12:03 +00:00
//============================================================================
//
// Convenience functions to retrieve item tags
//
//============================================================================
String GetAmmoTag(bool secondary = false)
{
let w = CPlayer.ReadyWeapon;
if (w == null) return "";
let ammo = secondary? w.ammo2 : w.ammo1;
return ammo.GetTag();
}
String GetWeaponTag()
{
let w = CPlayer.ReadyWeapon;
if (w == null) return "";
return w.GetTag();
}
String GetSelectedInventoryTag()
{
let w = CPlayer.mo.InvSel;
if (w == null) return "";
return w.GetTag();
}
2017-03-24 19:07:22 +00:00
2017-03-24 01:12:03 +00:00
// These cannot be done in ZScript.
2017-03-29 19:54:11 +00:00
native static String GetGlobalACSString(int index);
native static String GetGlobalACSArrayString(int arrayno, int index);
native static int GetGlobalACSValue(int index);
native static int GetGlobalACSArrayValue(int arrayno, int index);
2017-03-24 19:07:22 +00:00
//============================================================================
//
// Convenience functions to retrieve some numbers
//
//============================================================================
int GetArmorAmount()
{
let armor = CPlayer.mo.FindInventory("BasicArmor");
return armor? armor.Amount : 0;
}
2017-03-26 20:04:58 +00:00
int, int GetAmount(class<Inventory> item)
{
let it = CPlayer.mo.FindInventory(item);
2017-04-01 11:33:42 +00:00
int ret1 = it? it.Amount : 0;
2017-03-26 20:04:58 +00:00
int ret2 = it? it.MaxAmount : GetDefaultByType(item).MaxAmount;
return ret1, ret2;
}
2017-03-24 19:07:22 +00:00
int GetMaxAmount(class<Inventory> item)
{
let it = CPlayer.mo.FindInventory(item);
return it? it.MaxAmount : GetDefaultByType(item).MaxAmount;
}
int GetArmorSavePercent()
{
double add = 0;
let harmor = HexenArmor(CPlayer.mo.FindInventory("HexenArmor"));
if(harmor != NULL)
{
add = harmor.Slots[0] + harmor.Slots[1] + harmor.Slots[2] + harmor.Slots[3] + harmor.Slots[4];
}
//Hexen counts basic armor also so we should too.
let armor = BasicArmor(CPlayer.mo.FindInventory("BasicArmor"));
2019-08-10 06:26:55 +00:00
if(armor != NULL && armor.Amount > 0)
2017-03-24 19:07:22 +00:00
{
add += armor.SavePercent * 100;
}
return int(add);
}
// Note that this retrieves the value in tics, not seconds like the equivalent SBARINFO function.
// The idea is to let the caller decide what to do with it instead of destroying accuracy here.
int GetAirTime()
{
if(CPlayer.mo.waterlevel < 3)
return level.airsupply;
else
return max(CPlayer.air_finished - level.time, 0);
}
int GetSelectedInventoryAmount()
{
if(CPlayer.mo.InvSel != NULL) return CPlayer.mo.InvSel.Amount;
return 0;
}
int GetKeyCount()
{
int num = 0;
for(Inventory item = CPlayer.mo.Inv;item != NULL;item = item.Inv)
{
if(item is "Key") num++;
}
return num;
}
2017-03-23 14:18:09 +00:00
//============================================================================
//
// various checker functions, based on SBARINFOs condition nodes.
//
//============================================================================
//============================================================================
//
// checks ammo use of current weapon
//
//============================================================================
bool WeaponUsesAmmo(int ValidModes)
{
if (CPlayer == null) return false;
let w = CPlayer.ReadyWeapon;
if (w == null) return false;
bool usesammo1 = w.AmmoType1 != NULL;
bool usesammo2 = w.AmmoType2 != NULL;
if (ValidModes == AMMO_PRIMARY) return usesammo1;
if (ValidModes == AMMO_SECONDARY) return usesammo2;
if (ValidModes == AMMO_ANY) return (usesammo1 || usesammo2);
if (ValidModes == AMMO_BOTH) return (usesammo1 && usesammo2);
return false;
}
//============================================================================
//
// checks if inventory bar is visible
//
//============================================================================
bool isInventoryBarVisible()
{
if (CPlayer == null) return false;
2017-03-28 09:00:05 +00:00
return (CPlayer.inventorytics > 0 && !level.NoInventoryBar);
2017-03-23 14:18:09 +00:00
}
//============================================================================
//
// checks if aspect ratio is in a given range
//
//============================================================================
bool CheckAspectRatio(double min, double max)
{
if (CPlayer == null) return false;
double aspect = screen.GetAspectRatio();
return (aspect >= min && aspect < max);
}
//============================================================================
//
// checks if weapon is selected.
//
//============================================================================
bool CheckWeaponSelected(class<Weapon> weap, bool checksister = true)
{
if (CPlayer == null) return false;
let w = CPlayer.ReadyWeapon;
if (w == null) return false;
if (w.GetClass() == weap) return true;
if (checksister && w.SisterWeapon != null && w.SisterWeapon.GetClass() == weap) return true;
return false;
}
//============================================================================
//
// checks if player has the given display name
//
//============================================================================
2017-04-02 08:47:10 +00:00
bool CheckDisplayName(String displayname)
2017-03-23 14:18:09 +00:00
{
if (CPlayer == null) return false;
return displayname == PlayerPawn.GetPrintableDisplayName(CPlayer.mo.GetClass());
}
//============================================================================
//
// checks if player has the given weapon piece
//
//============================================================================
2017-03-28 09:00:05 +00:00
int CheckWeaponPiece(class<Weapon> weap, int piecenum)
2017-03-23 14:18:09 +00:00
{
if (CPlayer == null) return false;
for(let inv = CPlayer.mo.Inv; inv != NULL; inv = inv.Inv)
{
let wh = WeaponHolder(inv);
if (wh != null && wh.PieceWeapon == weap)
{
return (!!(wh.PieceMask & (1 << (PieceNum-1))));
}
}
return false;
}
//============================================================================
//
// checks if player has the given weapon piece
//
//============================================================================
2017-03-28 09:00:05 +00:00
int GetWeaponPieceMask(class<Weapon> weap)
{
if (CPlayer == null) return false;
for(let inv = CPlayer.mo.Inv; inv != NULL; inv = inv.Inv)
{
let wh = WeaponHolder(inv);
if (wh != null && wh.PieceWeapon == weap)
{
return wh.PieceMask;
}
}
return 0;
}
//============================================================================
//
// checks if player has the given weapon piece
//
//============================================================================
2017-03-23 14:18:09 +00:00
bool WeaponUsesAmmoType(class<Ammo> ammotype)
{
if (CPlayer == null) return false;
let w = CPlayer.ReadyWeapon;
if (w == NULL) return false;
return w.AmmoType1 == ammotype || w.AmmoType2 == ammotype;
}
//============================================================================
//
// checks if player has the required health
//
//============================================================================
bool CheckHealth(int Amount, bool percentage = false)
{
if (CPlayer == null) return false;
int phealth = percentage ? CPlayer.mo.health * 100 / CPlayer.mo.GetMaxHealth() : CPlayer.mo.health;
return (phealth >= Amount);
}
//============================================================================
//
// checks if player is invulnerable
//
//============================================================================
bool isInvulnerable()
{
if (CPlayer == null) return false;
return ((CPlayer.mo.bInvulnerable) || (CPlayer.cheats & (CF_GODMODE | CF_GODMODE2)));
}
//============================================================================
//
// checks if player owns enough of the item
//
//============================================================================
bool CheckInventory(class<Inventory> item, int amount = 1)
{
if (CPlayer == null) return false;
let it = CPlayer.mo.FindInventory(item);
return it != null && it.Amount >= amount;
}
2017-03-29 17:23:40 +00:00
//============================================================================
//
// mypos cheat
//
//============================================================================
virtual void DrawMyPos()
{
2017-03-29 21:51:53 +00:00
int height = SmallFont.GetHeight();
2017-03-29 17:23:40 +00:00
int i;
int vwidth;
int vheight;
int xpos;
int y;
2017-03-29 21:51:53 +00:00
let scalevec = GetHUDScale();
int scale = int(scalevec.X);
2017-03-29 17:23:40 +00:00
2017-03-29 21:51:53 +00:00
vwidth = screen.GetWidth() / scale;
vheight = screen.GetHeight() / scale;
xpos = vwidth - SmallFont.StringWidth("X: -00000")-6;
y = GetTopOfStatusBar() / (3*scale) - height;
2017-03-29 17:23:40 +00:00
2017-03-29 21:51:53 +00:00
Vector3 pos = CPlayer.mo.Pos;
for (i = 0; i < 3; y += height, ++i)
2017-03-29 17:23:40 +00:00
{
2017-03-29 21:51:53 +00:00
double v = i == 0? pos.X : i == 1? pos.Y : pos.Z;
String line = String.Format("%c: %d", int("X") + i, v);
screen.DrawText (SmallFont, Font.CR_GREEN, xpos, y, line, DTA_KeepRatio, true,
DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight);
2017-03-29 17:23:40 +00:00
}
}
2017-03-23 14:18:09 +00:00
2017-03-29 12:20:22 +00:00
//============================================================================
//
// automap HUD common drawer
// This is not called directly to give a status bar the opportunity to
// change the text colors. If you want to do something different,
// override DrawAutomap directly.
//
//============================================================================
protected void DoDrawAutomapHUD(int crdefault, int highlight)
{
let scale = GetHUDScale();
double textdist = 8. / scale.Y;
int height = SmallFont.GetHeight();
String printtext;
int SCREENWIDTH = screen.GetWidth();
2017-03-29 17:23:40 +00:00
BeginHUD();
2017-03-29 12:20:22 +00:00
// Draw timer
let y = textdist;
let width = SmallFont.StringWidth("00:00:00");
if (am_showtime)
{
printtext = level.TimeFormatted();
DrawString(mSmallFont, level.TimeFormatted(), (-textdist-width, y), 0, crdefault);
y += height;
}
if (am_showtotaltime)
{
DrawString(mSmallFont, level.TimeFormatted(true), (-textdist-width, y), 0, crdefault);
}
if (!deathmatch)
{
y = textdist;
// Draw monster count
if (am_showmonsters)
{
DrawString(mSmallFont, String.Format("%s\34%c %d/%d", Stringtable.Localize("$AM_MONSTERS"), crdefault+65, level.killed_monsters, level.total_monsters), (textdist, y), 0, highlight);
y += height;
}
// Draw secret count
if (am_showsecrets)
{
DrawString(mSmallFont, String.Format("%s\34%c %d/%d", Stringtable.Localize("$AM_SECRETS"), crdefault+65, level.found_secrets, level.total_secrets), (textdist, y), 0, highlight);
y += height;
}
// Draw item count
if (am_showitems)
{
2017-04-21 08:45:27 +00:00
DrawString(mSmallFont, String.Format("%s\34%c %d/%d", Stringtable.Localize("$AM_ITEMS"), crdefault+65, level.found_items, level.total_items), (textdist, y), 0, highlight);
2017-03-29 12:20:22 +00:00
}
}
String mapname = level.FormatMapName(crdefault);
2017-04-27 08:23:31 +00:00
BrokenLines lines = SmallFont.BreakLines(mapname, int(SCREENWIDTH / scale.X));
2017-03-29 12:20:22 +00:00
int numlines = lines.Count();
2017-04-27 08:23:31 +00:00
int finalwidth = int(SmallFont.StringWidth(lines.StringAt(numlines-1)) * scale.X);
2017-03-29 12:20:22 +00:00
// calculate the top of the statusbar including any protrusion and transform it from status bar to screen space.
double tmp, hres;
[tmp, tmp, hres] = StatusbarToRealCoords(0, 0, HorizontalResolution);
int protrusion = GetProtrusion(finalwidth / hres);
[tmp, tmp, tmp, hres] = StatusbarToRealCoords(0, 0, 0, protrusion);
// transform the top of the status bar position from screen to HUD space (a direct transformation from status bar to HUD space does not exist.)
y = (GetTopOfStatusBar() - hres) / scale.Y - height * numlines;
// Draw the texts centered above the status bar.
for(int i = 0; i < numlines; i++)
{
DrawString(mSmallFont, lines.StringAt(i), (0, y), DI_TEXT_ALIGN_CENTER|DI_SCREEN_HCENTER|DI_SCREEN_TOP, highlight);
y += height;
}
}
virtual void DrawAutomapHUD(double ticFrac)
{
2017-05-04 09:37:36 +00:00
// game needs to be checked here, so that SBARINFO also gets the correct colors.
DoDrawAutomapHUD(Font.CR_GREY, gameinfo.gametype & GAME_DoomChex? Font.CR_UNTRANSLATED : Font.CR_YELLOW);
2017-03-29 12:20:22 +00:00
}
2017-03-24 21:57:44 +00:00
//---------------------------------------------------------------------------
//
// DrawPowerups
//
//---------------------------------------------------------------------------
virtual void DrawPowerups ()
{
// The AltHUD specific adjustments have been removed here, because the AltHUD uses its own variant of this function
// that can obey AltHUD rules - which this cannot.
Vector2 pos = (-20, POWERUPICONSIZE * 5 / 4);
double maxpos = screen.GetWidth() / 2;
2017-04-21 16:08:30 +00:00
for (let iitem = CPlayer.mo.Inv; iitem != NULL; iitem = iitem.Inv)
2017-03-24 21:57:44 +00:00
{
2017-04-21 16:08:30 +00:00
let item = Powerup(iitem);
if (item != null)
2017-03-24 21:57:44 +00:00
{
2017-04-21 16:08:30 +00:00
let icon = item.GetPowerupIcon();
if (icon.IsValid() && !item.IsBlinking())
2017-03-24 21:57:44 +00:00
{
2017-04-21 16:08:30 +00:00
// Each icon gets a 32x32 block.
DrawTexture(icon, pos, DI_SCREEN_RIGHT_TOP, 1.0, (POWERUPICONSIZE, POWERUPICONSIZE));
pos.x -= POWERUPICONSIZE;
if (pos.x < -maxpos)
{
pos.x = -20;
pos.y += POWERUPICONSIZE * 3 / 2;
}
2017-03-24 21:57:44 +00:00
}
}
}
}
2017-03-23 14:18:09 +00:00
//============================================================================
//
// draw stuff
//
//============================================================================
int GetTranslation() const
{
if(gameinfo.gametype & GAME_Raven)
return Translation.MakeID(TRANSLATION_PlayersExtra, CPlayer.mo.PlayerNumber());
else
return Translation.MakeID(TRANSLATION_Players, CPlayer.mo.PlayerNumber());
}
//============================================================================
//
//
//
//============================================================================
2017-03-26 16:41:24 +00:00
void DrawHexenArmor(int armortype, String image, Vector2 pos, int flags = 0, double alpha = 1.0, Vector2 boxsize = (-1, -1), Vector2 scale = (1.,1.))
2017-03-23 14:18:09 +00:00
{
let harmor = HexenArmor(statusBar.CPlayer.mo.FindInventory("HexenArmor"));
if (harmor != NULL)
{
let slotval = harmor.Slots[armorType];
let slotincr = harmor.SlotsIncrement[armorType];
if (slotval > 0 && slotincr > 0)
{
//combine the alpha values
alpha *= MIN(1., slotval / slotincr);
}
else return;
}
2017-03-26 16:41:24 +00:00
DrawImage(image, pos, flags, alpha, boxsize, scale);
2017-03-23 14:18:09 +00:00
}
//============================================================================
//
//
//
//============================================================================
2017-03-26 16:41:24 +00:00
void DrawInventoryIcon(Inventory item, Vector2 pos, int flags = 0, double alpha = 1.0, Vector2 boxsize = (-1, -1), Vector2 scale = (1.,1.))
2017-03-23 14:18:09 +00:00
{
2017-03-27 19:01:40 +00:00
static const String flashimgs[]= { "USEARTID", "USEARTIC", "USEARTIB", "USEARTIA" };
2017-03-25 22:43:19 +00:00
TextureID texture;
2017-03-26 16:41:24 +00:00
Vector2 applyscale;
2017-03-25 22:43:19 +00:00
[texture, applyscale] = GetIcon(item, flags, false);
2017-03-27 19:01:40 +00:00
if((flags & DI_ARTIFLASH) && artiflashTick > 0)
{
2020-09-26 17:22:17 +00:00
DrawImage(flashimgs[artiflashTick-1], pos, flags, alpha, boxsize);
2017-03-27 19:01:40 +00:00
}
else if (texture.IsValid())
2017-03-23 14:18:09 +00:00
{
2017-03-26 16:41:24 +00:00
if ((flags & DI_DIMDEPLETED) && item.Amount <= 0) flags |= DI_DIM;
applyscale.X *= scale.X;
applyscale.Y *= scale.Y;
DrawTexture(texture, pos, flags, alpha, boxsize, applyscale);
2017-03-23 14:18:09 +00:00
}
}
2017-03-25 00:22:42 +00:00
2017-03-26 23:02:10 +00:00
//============================================================================
//
//
//
//============================================================================
2017-03-27 19:01:40 +00:00
void DrawShader(int which, Vector2 pos, Vector2 size, int flags = 0, double alpha = 1.)
{
static const String texnames[] = {"BarShaderHF", "BarShaderHR", "BarShaderVF", "BarShaderVR" };
DrawImage(texnames[which], pos, DI_ITEM_LEFT_TOP|DI_ALPHAMAPPED|DI_FORCEFILL | (flags & ~(DI_ITEM_HMASK|DI_ITEM_VMASK)), alpha, size);
}
//============================================================================
//
//
//
//============================================================================
Vector2, int AdjustPosition(Vector2 position, int flags, double width, double height)
2017-03-26 23:02:10 +00:00
{
// This must be done here, before altered coordinates get sent to the draw functions.
if (!(flags & DI_SCREEN_MANUAL_ALIGN))
{
if (position.x < 0) flags |= DI_SCREEN_RIGHT;
else flags |= DI_SCREEN_LEFT;
if (position.y < 0) flags |= DI_SCREEN_BOTTOM;
else flags |= DI_SCREEN_TOP;
}
// placement by offset is not supported because the inventory bar is a composite.
switch (flags & DI_ITEM_HMASK)
{
case DI_ITEM_HCENTER: position.x -= width / 2; break;
case DI_ITEM_RIGHT: position.x -= width; break;
}
switch (flags & DI_ITEM_VMASK)
{
2017-03-27 19:01:40 +00:00
case DI_ITEM_VCENTER: position.y -= height / 2; break;
case DI_ITEM_BOTTOM: position.y -= height; break;
2017-03-26 23:02:10 +00:00
}
2017-03-27 19:01:40 +00:00
// clear all alignment flags so that the following code only passes on the rest
2017-03-26 23:02:10 +00:00
flags &= ~(DI_ITEM_VMASK|DI_ITEM_HMASK);
2017-03-27 19:01:40 +00:00
return position, flags;
}
//============================================================================
//
// note that this does not implement chain wiggling, this is because
// it would severely complicate the parameter list. The calling code is
// normally in a better position to do the needed calculations anyway.
//
//============================================================================
void DrawGem(String chain, String gem, int displayvalue, int maxrange, Vector2 pos, int leftpadding, int rightpadding, int chainmod, int flags = 0)
{
TextureID chaintex = TexMan.CheckForTexture(chain, TexMan.TYPE_MiscPatch);
if (!chaintex.IsValid()) return;
Vector2 chainsize = TexMan.GetScaledSize(chaintex);
[pos, flags] = AdjustPosition(pos, flags, chainsize.X, chainsize.Y);
displayvalue = clamp(displayvalue, 0, maxrange);
int offset = int(double(chainsize.X - leftpadding - rightpadding) * displayvalue / maxrange);
DrawTexture(chaintex, pos + (offset % chainmod, 0), flags | DI_ITEM_LEFT_TOP);
DrawImage(gem, pos + (offset + leftPadding, 0), flags | DI_ITEM_LEFT_TOP);
}
2017-03-28 09:00:05 +00:00
//============================================================================
//
// DrawBar
//
//============================================================================
2020-03-31 11:30:27 +00:00
void DrawBar(String ongfx, String offgfx, double curval, double maxval, Vector2 position, int border, int vertical, int flags = 0, double alpha = 1.0)
2017-03-28 09:00:05 +00:00
{
let ontex = TexMan.CheckForTexture(ongfx, TexMan.TYPE_MiscPatch);
if (!ontex.IsValid()) return;
let offtex = TexMan.CheckForTexture(offgfx, TexMan.TYPE_MiscPatch);
Vector2 texsize = TexMan.GetScaledSize(ontex);
[position, flags] = AdjustPosition(position, flags, texsize.X, texsize.Y);
2017-04-19 04:12:21 +00:00
double value = (maxval != 0) ? clamp(curval / maxval, 0, 1) : 0;
2017-03-28 09:00:05 +00:00
if(border != 0) value = 1. - value; //invert since the new drawing method requires drawing the bg on the fg.
// {cx, cb, cr, cy}
double Clip[4];
Clip[0] = Clip[1] = Clip[2] = Clip[3] = 0;
bool horizontal = !(vertical & SHADER_VERT);
bool reverse = !!(vertical & SHADER_REVERSE);
double sizeOfImage = (horizontal ? texsize.X - border*2 : texsize.Y - border*2);
Clip[(!horizontal) | ((!reverse)<<1)] = sizeOfImage - sizeOfImage *value;
2017-03-30 10:13:28 +00:00
// preserve the active clipping rectangle
int cx, cy, cw, ch;
[cx, cy, cw, ch] = screen.GetClipRect();
2017-03-28 09:00:05 +00:00
if(border != 0)
{
for(int i = 0; i < 4; i++) Clip[i] += border;
//Draw the whole foreground
2020-03-31 11:30:27 +00:00
DrawTexture(ontex, position, flags | DI_ITEM_LEFT_TOP, alpha);
2017-03-30 10:13:28 +00:00
SetClipRect(position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3], flags);
2017-03-28 09:00:05 +00:00
}
2020-03-31 17:45:28 +00:00
if (offtex.IsValid() && TexMan.GetScaledSize(offtex) == texsize) DrawTexture(offtex, position, flags | DI_ITEM_LEFT_TOP, alpha);
2020-03-31 11:30:27 +00:00
else Fill(color(int(255*alpha),0,0,0), position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3]);
2017-03-28 09:00:05 +00:00
2020-03-31 11:30:27 +00:00
if (border == 0)
2017-03-28 09:00:05 +00:00
{
2017-03-30 10:13:28 +00:00
SetClipRect(position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3], flags);
2020-03-31 11:30:27 +00:00
DrawTexture(ontex, position, flags | DI_ITEM_LEFT_TOP, alpha);
2017-03-28 09:00:05 +00:00
}
2017-03-30 10:13:28 +00:00
// restore the previous clipping rectangle
screen.SetClipRect(cx, cy, cw, ch);
2017-03-28 09:00:05 +00:00
}
2017-03-27 19:01:40 +00:00
//============================================================================
//
// DrawInventoryBar
//
// This function needs too many parameters, so most have been offloaded to
// a struct to keep code readable and allow initialization somewhere outside
// the actual drawing code.
//
//============================================================================
// Except for the placement information this gets all info from the struct that gets passed in.
void DrawInventoryBar(InventoryBarState parms, Vector2 position, int numfields, int flags = 0, double bgalpha = 1.)
{
double width = parms.boxsize.X * numfields;
[position, flags] = AdjustPosition(position, flags, width, parms.boxsize.Y);
2017-03-26 23:02:10 +00:00
CPlayer.mo.InvFirst = ValidateInvFirst(numfields);
if (CPlayer.mo.InvFirst == null) return; // Player has no listed inventory items.
Vector2 boxsize = parms.boxsize;
// First draw all the boxes
for(int i = 0; i < numfields; i++)
{
DrawTexture(parms.box, position + (boxsize.X * i, 0), flags | DI_ITEM_LEFT_TOP, bgalpha);
}
// now the items and the rest
2017-03-27 19:01:40 +00:00
Vector2 itempos = position + boxsize / 2;
Vector2 textpos = position + boxsize - (1, 1 + parms.amountfont.mFont.GetHeight());
2017-03-26 23:02:10 +00:00
int i = 0;
Inventory item;
for(item = CPlayer.mo.InvFirst; item != NULL && i < numfields; item = item.NextInv())
{
2017-03-27 19:01:40 +00:00
for(int j = 0; j < 2; j++)
{
2017-06-18 13:57:05 +00:00
if (j ^ !!(flags & DI_DRAWCURSORFIRST))
2017-03-27 19:01:40 +00:00
{
if (item == CPlayer.mo.InvSel)
{
double flashAlpha = bgalpha;
if (flags & DI_ARTIFLASH) flashAlpha *= itemflashFade;
2017-03-28 09:00:05 +00:00
DrawTexture(parms.selector, position + parms.selectofs + (boxsize.X * i, 0), flags | DI_ITEM_LEFT_TOP, flashAlpha);
2017-03-27 19:01:40 +00:00
}
}
else
{
DrawInventoryIcon(item, itempos + (boxsize.X * i, 0), flags | DI_ITEM_CENTER );
}
}
2017-03-26 23:02:10 +00:00
2017-06-18 13:57:05 +00:00
if (parms.amountfont != null && (item.Amount > 1 || (flags & DI_ALWAYSSHOWCOUNTERS)))
2017-03-26 23:02:10 +00:00
{
DrawString(parms.amountfont, FormatNumber(item.Amount, 0, 5), textpos + (boxsize.X * i, 0), flags | DI_TEXT_ALIGN_RIGHT, parms.cr, parms.itemalpha);
}
i++;
}
// Is there something to the left?
if (CPlayer.mo.FirstInv() != CPlayer.mo.InvFirst)
{
DrawTexture(parms.left, position + (-parms.arrowoffset.X, parms.arrowoffset.Y), flags | DI_ITEM_RIGHT|DI_ITEM_VCENTER);
}
// Is there something to the right?
if (item != NULL)
{
DrawTexture(parms.right, position + parms.arrowoffset + (width, 0), flags | DI_ITEM_LEFT|DI_ITEM_VCENTER);
}
}
2017-03-21 19:09:09 +00:00
}
2017-03-24 19:07:22 +00:00
//============================================================================
//
// a generic value interpolator for status bar elements that can change
// gradually to their new value.
//
//============================================================================
class LinearValueInterpolator : Object
{
int mCurrentValue;
int mMaxChange;
static LinearValueInterpolator Create(int startval, int maxchange)
{
let v = new("LinearValueInterpolator");
v.mCurrentValue = startval;
v.mMaxChange = maxchange;
return v;
}
2017-03-27 19:01:40 +00:00
void Reset(int value)
{
mCurrentValue = value;
}
2018-11-26 16:15:40 +00:00
// This must be called periodically in the status bar's Tick function.
2017-03-24 19:07:22 +00:00
// Do not call this in the Draw function because that may skip some frames!
void Update(int destvalue)
{
if (mCurrentValue > destvalue)
{
mCurrentValue = max(destvalue, mCurrentValue - mMaxChange);
}
else
{
mCurrentValue = min(destvalue, mCurrentValue + mMaxChange);
}
}
// This must be called in the draw function to retrieve the value for output.
int GetValue()
{
return mCurrentValue;
}
}
class DynamicValueInterpolator : Object
{
int mCurrentValue;
int mMinChange;
2017-03-27 07:52:30 +00:00
int mMaxChange;
2017-03-24 19:07:22 +00:00
double mChangeFactor;
2017-03-27 07:52:30 +00:00
static DynamicValueInterpolator Create(int startval, double changefactor, int minchange, int maxchange)
2017-03-24 19:07:22 +00:00
{
let v = new("DynamicValueInterpolator");
v.mCurrentValue = startval;
v.mMinChange = minchange;
2017-03-27 07:52:30 +00:00
v.mMaxChange = maxchange;
2017-03-24 19:07:22 +00:00
v.mChangeFactor = changefactor;
return v;
}
2017-03-27 19:01:40 +00:00
void Reset(int value)
{
mCurrentValue = value;
}
2018-11-26 16:15:40 +00:00
// This must be called periodically in the status bar's Tick function.
2017-03-24 19:07:22 +00:00
// Do not call this in the Draw function because that may skip some frames!
void Update(int destvalue)
{
2017-03-27 07:52:30 +00:00
int diff = int(clamp(abs(destvalue - mCurrentValue) * mChangeFactor, mMinChange, mMaxChange));
2017-03-24 19:07:22 +00:00
if (mCurrentValue > destvalue)
{
mCurrentValue = max(destvalue, mCurrentValue - diff);
}
else
{
mCurrentValue = min(destvalue, mCurrentValue + diff);
}
}
// This must be called in the draw function to retrieve the value for output.
int GetValue()
{
return mCurrentValue;
}
}
2017-03-24 21:57:44 +00:00