halflife-thewastes-sdk/cl_dll/thewastes_hud.cpp

394 lines
8 KiB
C++
Raw Normal View History

/***
*
* Copyright (C) 2002 The Wastes Project, All Rights Reserved.
*
* This product contains software technology from Valve Software, LLC,
* Copyright © 1996-2001, Valve LLC, All rights reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* The Wastes Project. All other use, distribution, or modification is prohibited
* without written permission from The Wastes Project.
*
***/
//
// thewastes_hud.cpp
//
#include "STDIO.H"
#include "STDLIB.H"
#include "MATH.H"
#include <string.h>
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include "cl_entity.h"
#include "tw_common.h"
#include "tw_vgui.h"
#include "vgui_TheWastesViewport.h"
#define MAX_CLIENTS 32
/*
===================
CrosshairInfo
===================
*/
int CCrosshairInfo::Init()
{
m_iFlags |= HUD_ACTIVE;
gHUD.AddHudElem(this);
m_flCenterTime = 0.0f;
strcpy(m_szCenterName,"");
return 1;
}
int CCrosshairInfo::VidInit()
{
return 1;
}
// We do this client side now ;)
int CCrosshairInfo::Draw(float fTime)
{
// print in middle of screen
// TODO: Disabled until i can fix the code from
// flagging the wrong entities
/* if(!gHUD.m_iIntermission && gHUD.m_flTime < m_flCenterTime)
{
int x,y;
int width,height;
GetConsoleStringSize(m_szCenterName,&width,&height);
y = ScreenHeight * 0.55f;
x = ScreenWidth/2 - width/2;
DrawConsoleString(x,y,m_szCenterName);
}
*/
return 1;
}
void CCrosshairInfo::UpdateInfo(int index)
{
cl_entity_t *pEnt = gEngfuncs.GetEntityByIndex(index);
gViewPort->GetAllPlayersInfo();
if(pEnt == NULL)
return;
// Player checks
if(!pEnt->player || pEnt == gEngfuncs.GetLocalPlayer())
return;
sprintf(m_szCenterName,"%s (%i%%)",g_PlayerInfoList[pEnt->index].name,pEnt->curstate.health);
m_flCenterTime = gHUD.m_flTime + 0.25f;
}
/*
===================
PlayerState
===================
*/
DECLARE_MESSAGE(m_PlayerState,PlayerState);
int CHudPlayerState::Init()
{
m_iFlags |= HUD_ACTIVE;
gHUD.AddHudElem(this);
HOOK_MESSAGE(PlayerState);
return 1;
}
int CHudPlayerState::VidInit()
{
m_iActiveSprite = 0;
m_HUD_bleeding = gHUD.GetSpriteIndex("bleeding");
m_HUD_composure = gHUD.GetSpriteIndex("composure");
m_HUD_willpower = gHUD.GetSpriteIndex("willpower");
return 1;
}
int CHudPlayerState::Draw(float fTime)
{
if(gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH)
return 1;
if(gHUD.m_Health.m_iHealth >= 100 || gHUD.m_Health.m_iHealth <= 0)
return 1;
int r,g,b,x,y;
wrect_t *prc;
int cursprite;
switch(m_iActiveSprite)
{
case 0: return 1;
case 1: cursprite = m_HUD_composure; break;
case 2: cursprite = m_HUD_bleeding; break;
case 3: cursprite = m_HUD_willpower; break;
}
UnpackRGB(r,g,b,RGB_WHITE);
ScaleColors(r,g,b,225);
prc = &gHUD.GetSpriteRect(cursprite);
x = 5;
y = ScreenHeight / 2 - (prc->bottom - prc->top) / 2;
// Draw sprite
SPR_Set(gHUD.GetSprite(cursprite),r,g,b);
SPR_DrawHoles(0,x,y,prc);
return 1;
}
int CHudPlayerState::MsgFunc_PlayerState(const char *pszName,int iSize,void *pbuf)
{
BEGIN_READ(pbuf,iSize);
m_iActiveSprite = READ_BYTE();
return 1;
}
int CHudPlayerState::ActiveState()
{
return m_iActiveSprite;
}
/*
===================
Scope
===================
*/
int CHudScope::Init()
{
m_iFlags |= HUD_ACTIVE;
gHUD.AddHudElem(this);
return 1;
}
int CHudScope::VidInit()
{
m_h320Scope = SPR_Load("sprites/320scope.spr");
m_h640Scope = SPR_Load("sprites/640scope.spr");
m_h1280Scope = SPR_Load("sprites/1280scope.spr");
return 1;
}
void CHudScope::DrawScopePart(int frame,int x,int y,HSPRITE hSprite,wrect_t *rect)
{
SPR_Set(hSprite,255,255,255);
SPR_DrawHoles(frame,x,y,rect);
}
int CHudScope::Draw(float flTime)
{
if(gHUD.m_iHideHUDDisplay & HIDEHUD_ALL)
return 1;
// y Yes~
return 1;
int x,y;
int center_x,center_y;
wrect_t rect;
x = y = 0;
center_x = ScreenWidth / 2;
center_y = ScreenHeight / 2;
// We have a few scope sprites to choose from
// To match the best resolution
switch(ScreenWidth)
{
case 320:
// 320x240
rect = gHUD.GetSpriteRect(gHUD.GetSpriteIndex("320scope"));
DrawScopePart(0,0,0,m_h320Scope,&rect);
DrawScopePart(1,160,0,m_h320Scope,&rect);
DrawScopePart(1,0,120,m_h320Scope,&rect);
DrawScopePart(1,160,120,m_h320Scope,&rect);
break;
case 640:
case 800:
// 640x480
// 800x600
rect = gHUD.GetSpriteRect(gHUD.GetSpriteIndex("640scope"));
x = center_x - 160*2;
y = center_y - 240;
DrawScopePart(0,x,y,m_h640Scope,&rect);
x += 160;
DrawScopePart(1,x,y,m_h640Scope,&rect);
x += 160;
DrawScopePart(2,x,y,m_h640Scope,&rect);
x += 160;
DrawScopePart(3,x,y,m_h640Scope,&rect);
y += 240;
x = center_x - 160*2;
DrawScopePart(4,x,y,m_h640Scope,&rect);
x += 160;
DrawScopePart(5,x,y,m_h640Scope,&rect);
x += 160;
DrawScopePart(6,x,y,m_h640Scope,&rect);
x += 160;
DrawScopePart(7,x,y,m_h640Scope,&rect);
// Fill blank areas
{
int r,g,b,a;
r = g = b = 128;
a = 255;
ScaleColors(r, g, b, a );
FillRGBA(0,(ScreenHeight-480)/2,ScreenWidth/2-160*2,480,r,g,b,a);
FillRGBA(ScreenWidth-(ScreenWidth/2-160*2),(ScreenHeight-480)/2,ScreenWidth/2-160*2,480,r,g,b,a);
FillRGBA(0,0,ScreenWidth,(ScreenHeight-480)/2,r,g,b,a);
FillRGBA(0,ScreenHeight-((ScreenHeight-480)/2),ScreenWidth,(ScreenHeight-480)/2,r,g,b,a);
}
break;
case 1280:
case 1600:
// 1280x960
// 1600x1200
rect = gHUD.GetSpriteRect(gHUD.GetSpriteIndex("1280scope"));
x = 0;
DrawScopePart(0,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(1,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(2,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(3,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(4,x,y,m_h1280Scope,&rect);
y += 240;
x = 0;
DrawScopePart(5,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(6,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(7,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(8,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(9,x,y,m_h1280Scope,&rect);
y += 240;
x = 0;
DrawScopePart(10,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(11,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(12,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(13,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(14,x,y,m_h1280Scope,&rect);
y += 240;
x = 0;
DrawScopePart(15,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(16,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(17,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(18,x,y,m_h1280Scope,&rect);
x += 256;
DrawScopePart(19,x,y,m_h1280Scope,&rect);
break;
}
return 1;
}
/*
===================
Scanlines
===================
*/
#define SCROLL_WIDTH ScreenWidth
#include <string.h>
extern int ev_thermal;
int CHudScanlines::Init()
{
m_iFlags |= HUD_ACTIVE;
gHUD.AddHudElem(this);
m_flScrollY = 0;
return 1;
}
int CHudScanlines::VidInit()
{
m_iScanlines = gHUD.GetSpriteIndex("scanlines");
m_iScrolllines = gHUD.GetSpriteIndex("scrolllines");
return 1;
}
int CHudScanlines::Draw(float fTime)
{
m_flScrollY += (150*(ScreenHeight/640)) * gHUD.m_flTimeDelta; // always increment the scroll line
// Dont draw unless we are in thermal vision
if(!ev_thermal || (gHUD.m_iHideHUDDisplay & HIDEHUD_ALL))
return 1;
int r,g,b,a;
wrect_t rect;
int iScanWidth,iScanHeight;
int x,y;
UnpackRGB(r,g,b,RGB_REDISH);
a = 128;
ScaleColors(r,g,b,a);
rect = gHUD.GetSpriteRect(m_iScanlines);
iScanWidth = rect.right - rect.left;
iScanHeight = rect.bottom - rect.top;
SPR_Set(gHUD.GetSprite(m_iScanlines), r, g, b);
// Tile across screen
for(y = 0;y < ScreenHeight;y += iScanHeight)
for(x = 0;x < ScreenWidth;x += iScanWidth)
SPR_DrawAdditive(0,x,y,&rect);
// Sync scroll
if(m_flScrollY > ScreenHeight)
m_flScrollY = -(gHUD.GetSpriteRect(m_iScrolllines).bottom-gHUD.GetSpriteRect(m_iScrolllines).top);
SPR_Set(gHUD.GetSprite(m_iScrolllines),r,g,b);
for(x = 0;x < ScreenWidth;x += gHUD.GetSpriteRect(m_iScrolllines).right-gHUD.GetSpriteRect(m_iScrolllines).left)
SPR_DrawAdditive(0,x,m_flScrollY,&gHUD.GetSpriteRect(m_iScrolllines));
return 1;
}
void CHudScanlines::Reset()
{
}