FTextureID GetWeaponIcon(AWeapon *weapon) // This function is also used by SBARINFO { FTextureID AltIcon = GetHUDIcon(weapon->GetClass()); FState * state=NULL, *ReadyState; FTextureID picnum = !AltIcon.isNull()? AltIcon : weapon->Icon; if (picnum.isNull()) { if (weapon->SpawnState && weapon->SpawnState->sprite!=0) { state = weapon->SpawnState; } // no spawn state - now try the ready state else if ((ReadyState = weapon->FindState(NAME_Ready)) && ReadyState->sprite!=0) { state = ReadyState; } if (state && (unsigned)state->sprite < (unsigned)sprites.Size ()) { spritedef_t * sprdef = &sprites[state->sprite]; spriteframe_t * sprframe = &SpriteFrames[sprdef->spriteframes + state->GetFrame()]; picnum = sprframe->Texture[0]; } } return picnum; }
static void DrawInventory(player_t * CPlayer, int x,int y) { AInventory * rover; int numitems = (hudwidth - 2*x) / 32; int i; CPlayer->mo->InvFirst = rover = StatusBar->ValidateInvFirst(numitems); if (rover!=NULL) { if(rover->PrevInv()) { screen->DrawTexture(invgems[!!(level.time&4)], x-10, y, DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, 0x6666, TAG_DONE); } for(i=0;i<numitems && rover;rover=rover->NextInv()) { if (rover->Amount>0) { FTextureID AltIcon = GetHUDIcon(rover->GetClass()); if (AltIcon.Exists() && (rover->Icon.isValid() || AltIcon.isValid()) ) { int trans = rover==CPlayer->mo->InvSel ? FRACUNIT : 0x6666; DrawImageToBox(TexMan[AltIcon.isValid()? AltIcon : rover->Icon], x, y, 19, 25, trans); if (rover->Amount>1) { char buffer[10]; int xx; mysnprintf(buffer, countof(buffer), "%d", rover->Amount); if (rover->Amount>=1000) xx = 32 - IndexFont->StringWidth(buffer); else xx = 22; screen->DrawText(IndexFont, CR_GOLD, x+xx, y+20, buffer, DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, trans, TAG_DONE); } x+=32; i++; } } } if(rover) { screen->DrawTexture(invgems[2 + !!(level.time&4)], x-10, y, DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, 0x6666, TAG_DONE); } } }
static void DrawOneWeapon(player_t * CPlayer, int x, int & y, AWeapon * weapon) { int trans; FTextureID picnum; // Powered up weapons and inherited sister weapons are not displayed. if (weapon->WeaponFlags & WIF_POWERED_UP) return; if (weapon->SisterWeapon && weapon->IsKindOf(RUNTIME_TYPE(weapon->SisterWeapon))) return; trans=0x6666; if (CPlayer->ReadyWeapon) { if (weapon==CPlayer->ReadyWeapon || weapon==CPlayer->ReadyWeapon->SisterWeapon) trans=0xd999; } FState * state=NULL, *ReadyState; FTextureID AltIcon = GetHUDIcon(weapon->GetClass()); picnum = !AltIcon.isNull()? AltIcon : weapon->Icon; if (picnum.isNull()) { if (weapon->SpawnState && weapon->SpawnState->sprite!=0) { state = weapon->SpawnState; } // no spawn state - now try the ready state else if ((ReadyState = weapon->FindState(NAME_Ready)) && ReadyState->sprite!=0) { state = ReadyState; } if (state && (unsigned)state->sprite < (unsigned)sprites.Size ()) { spritedef_t * sprdef = &sprites[state->sprite]; spriteframe_t * sprframe = &SpriteFrames[sprdef->spriteframes + state->GetFrame()]; picnum = sprframe->Texture[0]; } } if (picnum.isValid()) { FTexture * tex = TexMan[picnum]; int w = tex->GetWidth(); int h = tex->GetHeight(); int rh; if (w>h) rh=8; else rh=16,y-=8; // don't draw tall sprites too small! DrawImageToBox(tex, x-24, y, 20, rh, trans); y-=10; } }
//--------------------------------------------------------------------------- // // Weapons List // //--------------------------------------------------------------------------- FTextureID GetInventoryIcon(AInventory *item, DWORD flags, bool *applyscale=NULL) // This function is also used by SBARINFO { FTextureID picnum, AltIcon = GetHUDIcon(item->GetClass()); FState * state=NULL, *ReadyState; picnum.SetNull(); if (flags & DI_ALTICONFIRST) { if (!(flags & DI_SKIPALTICON) && AltIcon.isValid()) picnum = AltIcon; else if (!(flags & DI_SKIPICON)) picnum = item->Icon; } else { if (!(flags & DI_SKIPICON) && item->Icon.isValid()) picnum = item->Icon; else if (!(flags & DI_SKIPALTICON)) picnum = AltIcon; } if (!picnum.isValid()) //isNull() is bad for checking, because picnum could be also invalid (-1) { if (!(flags & DI_SKIPSPAWN) && item->SpawnState && item->SpawnState->sprite!=0) { state = item->SpawnState; if (applyscale != NULL && !(flags & DI_FORCESCALE)) { *applyscale = true; } } // no spawn state - now try the ready state if it's weapon else if (!(flags & DI_SKIPREADY) && item->GetClass()->IsDescendantOf(RUNTIME_CLASS(AWeapon)) && (ReadyState = item->FindState(NAME_Ready)) && ReadyState->sprite!=0) { state = ReadyState; } if (state && (unsigned)state->sprite < (unsigned)sprites.Size ()) { spritedef_t * sprdef = &sprites[state->sprite]; spriteframe_t * sprframe = &SpriteFrames[sprdef->spriteframes + state->GetFrame()]; picnum = sprframe->Texture[0]; } } return picnum; }
static void DrawOneKey(int xo, int & x, int & y, int & c, AInventory * inv) { FTextureID icon = FNullTextureID(); FTextureID AltIcon = GetHUDIcon(inv->GetClass()); if (!AltIcon.Exists()) return; if (AltIcon.isValid()) { icon = AltIcon; } else if (inv->SpawnState && inv->SpawnState->sprite!=0) { FState * state = inv->SpawnState; if (state && (unsigned)state->sprite < (unsigned)sprites.Size ()) { spritedef_t * sprdef = &sprites[state->sprite]; spriteframe_t * sprframe = &SpriteFrames[sprdef->spriteframes + state->GetFrame()]; icon = sprframe->Texture[0]; } } if (icon.isNull()) icon = inv->Icon; if (icon.isValid()) { x -= 9; DrawImageToBox(TexMan[icon], x, y, 8, 10); c++; if (c>=10) { x=xo; y-=11; c=0; } } }
static int DrawAmmo(player_t *CPlayer, int x, int y) { int i,j,k; char buf[256]; AInventory *inv; AWeapon *wi=CPlayer->ReadyWeapon; orderedammos.Clear(); if (0 == hud_showammo) { // Show ammo for current weapon if any if (wi) AddAmmoToList(wi); } else { // Order ammo by use of weapons in the weapon slots for (k = 0; k < NUM_WEAPON_SLOTS; k++) for(j = 0; j < CPlayer->weapons.Slots[k].Size(); j++) { PClassActor *weap = CPlayer->weapons.Slots[k].GetWeapon(j); if (weap) { // Show ammo for available weapons if hud_showammo CVAR is 1 // or show ammo for all weapons if hud_showammo is greater than 1 if (hud_showammo > 1 || CPlayer->mo->FindInventory(weap)) { AddAmmoToList((AWeapon*)GetDefaultByType(weap)); } } } // Now check for the remaining weapons that are in the inventory but not in the weapon slots for(inv=CPlayer->mo->Inventory;inv;inv=inv->Inventory) { if (inv->IsKindOf(RUNTIME_CLASS(AWeapon))) { AddAmmoToList((AWeapon*)inv); } } } // ok, we got all ammo types. Now draw the list back to front (bottom to top) int def_width = ConFont->StringWidth("000/000"); x-=def_width; int yadd = ConFont->GetHeight(); for(i=orderedammos.Size()-1;i>=0;i--) { PClassAmmo * type = orderedammos[i]; AAmmo * ammoitem = (AAmmo*)CPlayer->mo->FindInventory(type); AAmmo * inv = ammoitem? ammoitem : (AAmmo*)GetDefaultByType(orderedammos[i]); FTextureID AltIcon = GetHUDIcon(type); FTextureID icon = !AltIcon.isNull()? AltIcon : inv->Icon; if (!icon.isValid()) continue; int trans= (wi && (type==wi->AmmoType1 || type==wi->AmmoType2)) ? 0xc000:0x6000; int maxammo = inv->MaxAmount; int ammo = ammoitem? ammoitem->Amount : 0; mysnprintf(buf, countof(buf), "%3d/%3d", ammo, maxammo); int tex_width= clamp<int>(ConFont->StringWidth(buf)-def_width, 0, 1000); int fontcolor=( !maxammo ? CR_GRAY : ammo < ( (maxammo * hud_ammo_red) / 100) ? CR_RED : ammo < ( (maxammo * hud_ammo_yellow) / 100) ? CR_GOLD : CR_GREEN ); DrawHudText(ConFont, fontcolor, buf, x-tex_width, y+yadd, trans); DrawImageToBox(TexMan[icon], x-20, y, 16, 8, trans); y-=10; } return y; }