- ported the inventory display on the status bar.

This commit is contained in:
Christoph Oelckers 2020-08-13 21:57:53 +02:00
parent eafaa56834
commit 9ccf717311
6 changed files with 148 additions and 145 deletions

View file

@ -183,11 +183,6 @@ void SetBorder(PLAYERp pp, int value)
BorderSetView(pp, &Xdim, &Ydim, &ScreenSize);
if (gs.BorderNum >= BORDER_BAR)
{
PlayerUpdatePanelInfo(Player + screenpeek);
}
SetFragBar(pp);
}

View file

@ -2172,7 +2172,6 @@ void PlayerUpdateHealth(PLAYERp pp, short value);
void PlayerUpdateAmmo(PLAYERp pp, short WeaponNum, short value);
void PlayerUpdateWeapon(PLAYERp pp, short WeaponNum);
void PlayerUpdateKills(PLAYERp pp, short value);
void PlayerUpdatePanelInfo(PLAYERp pp);
void RefreshInfoLine(PLAYERp pp);
void DoAnim(int numtics);

View file

@ -54,9 +54,6 @@ void InventoryBarUpdatePosition(PLAYERp pp);
void InventoryUse(PLAYERp pp);
void InventoryStop(PLAYERp pp, short InventoryNum);
void KillInventoryBar(PLAYERp pp);
void PlayerUpdateInventoryPercent(PLAYERp pp);
void PlayerUpdateInventoryPic(PLAYERp pp);
void PlayerUpdateInventoryState(PLAYERp pp);
//#define INVENTORY_ICON_WIDTH 32
@ -764,7 +761,6 @@ void InventoryTimer(PLAYERp pp)
pp->InventoryTics[inv] = SEC(1);
}
//PlayerUpdateInventoryPercent(pp);
PlayerUpdateInventory(pp, pp->InventoryNum);
}
}
@ -795,7 +791,6 @@ void InventoryTimer(PLAYERp pp)
pp->InventoryActive[inv] = FALSE;
}
//PlayerUpdateInventoryPercent(pp);
PlayerUpdateInventory(pp, pp->InventoryNum);
}
}
@ -891,25 +886,6 @@ void InventoryStop(PLAYERp pp, short InventoryNum)
//
/////////////////////////////////////////////////////////////////
#define INVENTORY_BOX_X 231
#define INVENTORY_BOX_Y (176-8)
#define INVENTORY_BOX_ERASE 2403
short InventoryBoxX;
short InventoryBoxY;
short InventoryXoff;
short InventoryYoff;
void (*InventoryDisplayString)(PLAYERp, short, short, short, const char *);
#define INVENTORY_PIC_XOFF 1
#define INVENTORY_PIC_YOFF 1
#define INVENTORY_PERCENT_XOFF 19
#define INVENTORY_PERCENT_YOFF 13
#define INVENTORY_STATE_XOFF 19
#define INVENTORY_STATE_YOFF 1
void PlayerUpdateInventory(PLAYERp pp, short InventoryNum)
{
// Check for items that need to go translucent from use
@ -950,103 +926,6 @@ void PlayerUpdateInventory(PLAYERp pp, short InventoryNum)
if (pp->InventoryNum >= MAX_INVENTORY)
pp->InventoryNum = 0;
if (pp - Player != screenpeek)
return;
if (gs.BorderNum == BORDER_MINI_BAR)
{
InventoryBoxX = MINI_BAR_INVENTORY_BOX_X;
InventoryBoxY = MINI_BAR_INVENTORY_BOX_Y;
InventoryXoff = 1;
InventoryYoff = 1;
InventoryDisplayString = DisplayMiniBarSmString;
}
else
{
if (gs.BorderNum < BORDER_BAR)
return;
InventoryBoxX = INVENTORY_BOX_X;
InventoryBoxY = INVENTORY_BOX_Y;
InventoryXoff = 0;
InventoryYoff = 0;
InventoryDisplayString = DisplaySmString;
// erase old info
pSpawnFullScreenSprite(pp, INVENTORY_BOX_ERASE, PRI_MID, INVENTORY_BOX_X, INVENTORY_BOX_Y);
// put pic
if (pp->InventoryAmount[pp->InventoryNum])
PlayerUpdateInventoryPic(pp);
}
if (pp->InventoryAmount[pp->InventoryNum])
{
// Auto/On/Off
PlayerUpdateInventoryState(pp);
// Percent count/Item count
PlayerUpdateInventoryPercent(pp);
}
}
void PlayerUpdateInventoryPercent(PLAYERp pp)
{
short x,y;
INVENTORY_DATAp id = &InventoryData[pp->InventoryNum];
x = InventoryBoxX + INVENTORY_PERCENT_XOFF + InventoryXoff;
y = InventoryBoxY + INVENTORY_PERCENT_YOFF + InventoryYoff;
if (TEST(id->Flags, INVF_COUNT))
{
sprintf(ds,"%d", pp->InventoryAmount[pp->InventoryNum]);
InventoryDisplayString(pp, x, y, 0, ds);
}
else
{
sprintf(ds,"%d%c", pp->InventoryPercent[pp->InventoryNum],'%');
InventoryDisplayString(pp, x, y, 0, ds);
}
}
void PlayerUpdateInventoryPic(PLAYERp pp)
{
PANEL_SPRITEp psp;
short pic;
short x,y;
INVENTORY_DATAp id = &InventoryData[pp->InventoryNum];
x = InventoryBoxX + INVENTORY_PIC_XOFF + InventoryXoff;
y = InventoryBoxY + INVENTORY_PIC_YOFF + InventoryYoff;
pic = id->State->picndx;
psp = pSpawnFullScreenSprite(pp, pic, PRI_FRONT_MAX, x, y);
psp->scale = id->Scale;
}
void PlayerUpdateInventoryState(PLAYERp pp)
{
short x,y;
INVENTORY_DATAp id = &InventoryData[pp->InventoryNum];
x = InventoryBoxX + INVENTORY_STATE_XOFF + InventoryXoff;
y = InventoryBoxY + INVENTORY_STATE_YOFF + InventoryYoff;
if (TEST(id->Flags, INVF_AUTO_USE))
{
sprintf(ds,"%s", "AUTO");
InventoryDisplayString(pp, x, y, 0, ds);
}
else if (TEST(id->Flags, INVF_TIMED))
{
sprintf(ds,"%s", pp->InventoryActive[pp->InventoryNum] ? "ON" : "OFF");
InventoryDisplayString(pp, x, y, 0, ds);
}
}
END_SW_NS

View file

@ -2211,7 +2211,6 @@ PlayerLevelReset(PLAYERp pp)
pp->StartColor = 0;
pp->FadeAmt = 0;
pp->DeathType = 0;
PlayerUpdatePanelInfo(pp);
RESET(sp->cstat, CSTAT_SPRITE_YCENTER);
RESET(sp->cstat, CSTAT_SPRITE_TRANSLUCENT);
RESET(pp->Flags, PF_WEAPON_DOWN|PF_WEAPON_RETRACT);
@ -2279,7 +2278,6 @@ PlayerDeathReset(PLAYERp pp)
pp->StartColor = 0;
pp->FadeAmt = 0;
pp->DeathType = 0;
PlayerUpdatePanelInfo(pp);
RESET(sp->cstat, CSTAT_SPRITE_TRANSLUCENT);
RESET(pp->Flags, PF_WEAPON_DOWN|PF_WEAPON_RETRACT);
RESET(pp->Flags, PF_DEAD);
@ -2367,7 +2365,6 @@ PlayerGameReset(PLAYERp pp)
pp->FadeAmt = 0;
pp->DeathType = 0;
PlayerUpdatePanelInfo(pp);
RESET(sp->cstat, CSTAT_SPRITE_TRANSLUCENT);
pp->sop_control = NULL;
@ -2466,7 +2463,6 @@ InitPlayerSprite(PLAYERp pp)
pp->StartColor = 0;
pp->FadeAmt = 0;
pp->DeathType = 0;
PlayerUpdatePanelInfo(pp);
}
void

View file

@ -500,16 +500,6 @@ void PlayerUpdateArmor(PLAYERp pp, short value)
}
void PlayerUpdatePanelInfo(PLAYERp pp)
{
USERp u = User[pp->PlayerSprite];
if (Prediction)
return;
PlayerUpdateInventory(pp, pp->InventoryNum);
}
int WeaponOperate(PLAYERp pp)
{
short weapon;

View file

@ -70,6 +70,23 @@ class DSWStatusBar : public DBaseStatusBar
PANEL_ARMOR_YOFF = 4,
FRAG_YOFF = 2,
INVENTORY_BOX_X = 231,
INVENTORY_BOX_Y = (176-8),
INVENTORY_PIC_XOFF = 1,
INVENTORY_PIC_YOFF = 1,
INVENTORY_PERCENT_XOFF = 19,
INVENTORY_PERCENT_YOFF = 13,
INVENTORY_STATE_XOFF = 19,
INVENTORY_STATE_YOFF = 1,
MINI_BAR_Y = 174 ,
MINI_BAR_INVENTORY_BOX_X = 64,
MINI_BAR_INVENTORY_BOX_Y = MINI_BAR_Y,
};
enum
@ -174,11 +191,11 @@ class DSWStatusBar : public DBaseStatusBar
//---------------------------------------------------------------------------
//
//
// todo: migrate to FFont to support localization
//
//---------------------------------------------------------------------------
void DisplayFragString(PLAYERp pp, double xs, double ys, const char* buffer)
void DisplayTinyString(double xs, double ys, const char* buffer, int pal)
{
double x;
const char* ptr;
@ -194,11 +211,16 @@ class DSWStatusBar : public DBaseStatusBar
assert(*ptr >= '!' && *ptr <= '}');
auto tex = tileGetTexture(FRAG_FIRST_TILE + (*ptr - FRAG_FIRST_ASCII));
DrawGraphic(tex, x, ys, DI_ITEM_LEFT_TOP, 1, -1, -1, 1, 1, 0xffffffff, TRANSLATION(Translation_Remap, User[pp->SpriteP - sprite]->spal));
DrawGraphic(tex, x, ys, DI_ITEM_LEFT_TOP, 1, -1, -1, 1, 1, 0xffffffff, TRANSLATION(Translation_Remap, pal));
x += 4;
}
}
void DisplayFragString(PLAYERp pp, double xs, double ys, const char* buffer)
{
DisplayTinyString(xs, ys, buffer, User[pp->SpriteP - sprite]->spal);
}
//---------------------------------------------------------------------------
//
//
@ -396,7 +418,129 @@ class DSWStatusBar : public DBaseStatusBar
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void PlayerUpdateInventoryPercent(PLAYERp pp, int InventoryBoxX, int InventoryBoxY, int InventoryXoff, int InventoryYoff)
{
char ds[32];
INVENTORY_DATAp id = &InventoryData[pp->InventoryNum];
int x = InventoryBoxX + INVENTORY_PERCENT_XOFF + InventoryXoff;
int y = InventoryBoxY + INVENTORY_PERCENT_YOFF + InventoryYoff;
if (TEST(id->Flags, INVF_COUNT))
{
mysnprintf(ds, 32, "%d", pp->InventoryAmount[pp->InventoryNum]);
}
else
{
mysnprintf(ds, 32, "%d%c", pp->InventoryPercent[pp->InventoryNum], '%');
}
DisplayTinyString(x, y, ds, 0);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void PlayerUpdateInventoryPic(PLAYERp pp, int InventoryBoxX, int InventoryBoxY, int InventoryXoff, int InventoryYoff)
{
INVENTORY_DATAp id = &InventoryData[pp->InventoryNum];
int x = InventoryBoxX + INVENTORY_PIC_XOFF + InventoryXoff;
int y = InventoryBoxY + INVENTORY_PIC_YOFF + InventoryYoff;
int pic = id->State->picndx;
DrawGraphic(tileGetTexture(pic), x, y, DI_ITEM_LEFT_TOP, 1, -1, -1, id->Scale/65536., id->Scale / 65536.);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void PlayerUpdateInventoryState(PLAYERp pp, int InventoryBoxX, int InventoryBoxY, int InventoryXoff, int InventoryYoff)
{
char ds[32];
INVENTORY_DATAp id = &InventoryData[pp->InventoryNum];
int x = InventoryBoxX + INVENTORY_STATE_XOFF + InventoryXoff;
int y = InventoryBoxY + INVENTORY_STATE_YOFF + InventoryYoff;
if (TEST(id->Flags, INVF_AUTO_USE))
{
DisplayTinyString(x, y, "AUTO", 0);
}
else if (TEST(id->Flags, INVF_TIMED))
{
sprintf(ds, "%s", pp->InventoryActive[pp->InventoryNum] ? "ON" : "OFF");
DisplayTinyString(x, y, pp->InventoryActive[pp->InventoryNum] ? "ON" : "OFF", 0);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void DisplayBarInventory(PLAYERp pp)
{
int InventoryBoxX = INVENTORY_BOX_X;
int InventoryBoxY = INVENTORY_BOX_Y;
int InventoryXoff = 0;
int InventoryYoff = 0;
// put pic
if (pp->InventoryAmount[pp->InventoryNum])
if (pp->InventoryAmount[pp->InventoryNum])
{
PlayerUpdateInventoryPic(pp, InventoryBoxX, InventoryBoxY, InventoryXoff, InventoryYoff);
// Auto/On/Off
PlayerUpdateInventoryState(pp, InventoryBoxX, InventoryBoxY, InventoryXoff, InventoryYoff);
// Percent count/Item count
PlayerUpdateInventoryPercent(pp, InventoryBoxX, InventoryBoxY, InventoryXoff, InventoryYoff);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void DisplayMinibarInventory(PLAYERp pp)
{
int InventoryBoxX = MINI_BAR_INVENTORY_BOX_X;
int InventoryBoxY = MINI_BAR_INVENTORY_BOX_Y;
int InventoryXoff = 1;
int InventoryYoff = 1;
if (pp->InventoryAmount[pp->InventoryNum])
{
PlayerUpdateInventoryPic(pp, InventoryBoxX, InventoryBoxY, InventoryXoff, InventoryYoff);
// Auto/On/Off
PlayerUpdateInventoryState(pp, InventoryBoxX, InventoryBoxY, InventoryXoff, InventoryYoff);
// Percent count/Item count
PlayerUpdateInventoryPercent(pp, InventoryBoxX, InventoryBoxY, InventoryXoff, InventoryYoff);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void DrawStatusBar()
{
@ -413,7 +557,7 @@ class DSWStatusBar : public DBaseStatusBar
DisplayKeys(pp);
else if (gNet.TimeLimit)
DisplayTimeLimit(pp);
DisplayBarInventory(pp);
}