Example #1
0
static void DrawHudNumber(FFont *font, int color, int num, int x, int y, int trans=0xc000)
{
	char text[15];

	mysnprintf(text, countof(text), "%d", num);
	DrawHudText(font, color, text, x, y, trans);
}
Example #2
0
static void DrawLatency()
{
	if (hud_showlag <= 0 ||
		(hud_showlag == 1 && !netgame) ||
		hud_showlag > 2)
	{
		return;
	}
	int i, localdelay = 0, arbitratordelay = 0;
	for (i = 0; i < BACKUPTICS; i++) localdelay += netdelay[0][i];
	for (i = 0; i < BACKUPTICS; i++) arbitratordelay += netdelay[nodeforplayer[Net_Arbitrator]][i];
	localdelay = ((localdelay / BACKUPTICS) * ticdup) * (1000 / TICRATE);
	arbitratordelay = ((arbitratordelay / BACKUPTICS) * ticdup) * (1000 / TICRATE);
	int color = CR_GREEN;
	if (MAX(localdelay, arbitratordelay) > 200)
	{
		color = CR_YELLOW;
	}
	if (MAX(localdelay, arbitratordelay) > 400)
	{
		color = CR_ORANGE;
	}
	if (MAX(localdelay, arbitratordelay) >= ((BACKUPTICS / 2 - 1) * ticdup) * (1000 / TICRATE))
	{
		color = CR_RED;
	}

	char tempstr[32];

	const int millis = (level.time % TICRATE) * (1000 / TICRATE);
	mysnprintf(tempstr, sizeof(tempstr), "a:%dms - l:%dms", arbitratordelay, localdelay);

	const int characterCount = (int)strlen(tempstr);
	const int width = SmallFont->GetCharWidth('0') * characterCount + 2; // small offset from screen's border
	const int height = SmallFont->GetHeight() * 2;

	DrawHudText(SmallFont, color, tempstr, hudwidth - width, height, FRACUNIT);
}
Example #3
0
static void DrawTime()
{
	if (!ST_IsTimeVisible())
	{
		return;
	}

	int hours   = 0;
	int minutes = 0;
	int seconds = 0;

	if (hud_showtime < 8)
	{
		const int timeTicks =
			hud_showtime < 4
				? level.maptime
				: (hud_showtime < 6
					? level.time
					: level.totaltime);
		const int timeSeconds = Tics2Seconds(timeTicks);

		hours   =  timeSeconds / 3600;
		minutes = (timeSeconds % 3600) / 60;
		seconds =  timeSeconds % 60;
	}
	else
	{
		time_t now;
		time(&now);

		struct tm* timeinfo = localtime(&now);

		if (NULL != timeinfo)
		{
			hours   = timeinfo->tm_hour;
			minutes = timeinfo->tm_min;
			seconds = timeinfo->tm_sec;
		}
	}

	const bool showMillis  = 1 == hud_showtime;
	const bool showSeconds = showMillis || (0 == hud_showtime % 2);

	char timeString[sizeof "HH:MM:SS.MMM"];

	if (showMillis)
	{
		const int millis  = (level.time % TICRATE) * (1000 / TICRATE);

		mysnprintf(timeString, sizeof(timeString), "%02i:%02i:%02i.%03i", hours, minutes, seconds, millis);
	}
	else if (showSeconds)
	{
		mysnprintf(timeString, sizeof(timeString), "%02i:%02i:%02i", hours, minutes, seconds);
	}
	else
	{
		mysnprintf(timeString, sizeof(timeString), "%02i:%02i", hours, minutes);
	}

	const int characterCount = static_cast<int>( sizeof "HH:MM" - 1
		+ (showSeconds ? sizeof ":SS"  - 1 : 0)
		+ (showMillis  ? sizeof ".MMM" - 1 : 0) );
	const int width  = SmallFont->GetCharWidth('0') * characterCount + 2; // small offset from screen's border
	const int height = SmallFont->GetHeight();

	DrawHudText(SmallFont, hud_timecolor, timeString, hudwidth - width, height, FRACUNIT);
}
Example #4
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;
}
Example #5
0
void DrawHUD()
{
	player_t * CPlayer = StatusBar->CPlayer;

	players[consoleplayer].inventorytics = 0;
	if (hud_althudscale && SCREENWIDTH>640) 
	{
		hudwidth=SCREENWIDTH/2;
		if (hud_althudscale == 2) 
		{
			// Optionally just double the pixels to reduce scaling artifacts.
			hudheight=SCREENHEIGHT/2;
		}
		else 
		{
			if (WidescreenRatio == 4)
			{
				hudheight = hudwidth * 30 / BaseRatioSizes[WidescreenRatio][3];	// BaseRatioSizes is inverted for this mode
			}
			else
			{
				hudheight = hudwidth * 30 / (48*48/BaseRatioSizes[WidescreenRatio][3]);
			}
		}
	}
	else
	{
		hudwidth=SCREENWIDTH;
		hudheight=SCREENHEIGHT;
	}

	if (!automapactive)
	{
		int i;

		// No HUD in the title level!
		if (gamestate == GS_TITLELEVEL || !CPlayer) return;

		if (!deathmatch) DrawStatus(CPlayer, 5, hudheight-50);
		else
		{
			DrawStatus(CPlayer, 5, hudheight-75);
			DrawFrags(CPlayer, 5, hudheight-70);
		}
		DrawHealth(CPlayer, 5, hudheight-45);
		DrawArmor(CPlayer->mo->FindInventory<ABasicArmor>(), 
			CPlayer->mo->FindInventory<AHexenArmor>(),	5, hudheight-20);
		i=DrawKeys(CPlayer, hudwidth-4, hudheight-10);
		i=DrawAmmo(CPlayer, hudwidth-5, i);
		if (hud_showweapons) DrawWeapons(CPlayer, hudwidth - 5, i);
		DrawInventory(CPlayer, 144, hudheight-28);
		if (CPlayer->camera && CPlayer->camera->player)
		{
			StatusBar->DrawCrosshair();
		}
		if (idmypos) DrawCoordinates(CPlayer);

		DrawTime();
		DrawLatency();
	}
	else
	{
		FString mapname;
		char printstr[256];
		int seconds;
		int length=8*SmallFont->GetCharWidth('0');
		int fonth=SmallFont->GetHeight()+1;
		int bottom=hudheight-1;

		if (am_showtotaltime)
		{
			seconds = Tics2Seconds(level.totaltime);
			mysnprintf(printstr, countof(printstr), "%02i:%02i:%02i", seconds/3600, (seconds%3600)/60, seconds%60);
			DrawHudText(SmallFont, hudcolor_ttim, printstr, hudwidth-length, bottom, FRACUNIT);
			bottom -= fonth;
		}

		if (am_showtime)
		{
			if (level.clusterflags&CLUSTER_HUB)
			{
				seconds = Tics2Seconds(level.time);
				mysnprintf(printstr, countof(printstr), "%02i:%02i:%02i", seconds/3600, (seconds%3600)/60, seconds%60);
				DrawHudText(SmallFont, hudcolor_time, printstr, hudwidth-length, bottom, FRACUNIT);
				bottom -= fonth;
			}

			// Single level time for hubs
			seconds= Tics2Seconds(level.maptime);
			mysnprintf(printstr, countof(printstr), "%02i:%02i:%02i", seconds/3600, (seconds%3600)/60, seconds%60);
			DrawHudText(SmallFont, hudcolor_ltim, printstr, hudwidth-length, bottom, FRACUNIT);
		}

		ST_FormatMapName(mapname);
		screen->DrawText(SmallFont, hudcolor_titl, 1, hudheight-fonth-1, mapname,
			DTA_KeepRatio, true,
			DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, TAG_DONE);

		DrawCoordinates(CPlayer);
	}
}
Example #6
0
void DrawHUD()
{
	player_t * CPlayer = StatusBar->CPlayer;

	// [BB] The player may not have a body while connecting.
	if ( CPlayer->mo == NULL )
		return;

	players[consoleplayer].inventorytics = 0;
	if (hud_althudscale && SCREENWIDTH>640) 
	{
		hudwidth=SCREENWIDTH/2;
		if (hud_althudscale == 2) 
		{
			// Optionally just double the pixels to reduce scaling artifacts.
			hudheight=SCREENHEIGHT/2;
		}
		else 
		{
			if (WidescreenRatio == 4)
			{
				hudheight = hudwidth * 30 / BaseRatioSizes[WidescreenRatio][3];	// BaseRatioSizes is inverted for this mode
			}
			else
			{
				hudheight = hudwidth * 30 / (48*48/BaseRatioSizes[WidescreenRatio][3]);
			}
		}
	}
	else
	{
		hudwidth=SCREENWIDTH;
		hudheight=SCREENHEIGHT;
	}

	if (!automapactive)
	{
		int i;

		// No HUD in the title level!
		if (gamestate == GS_TITLELEVEL || !CPlayer) return;

		if (!deathmatch) DrawStatus(CPlayer, 5, hudheight-50);
		else
		{
			DrawStatus(CPlayer, 5, hudheight-75);

			// [TP] Only draw frags if not playing in teams
			if (( GAMEMODE_GetCurrentFlags() & GMF_PLAYERSONTEAMS ) == 0 )
				DrawFrags(CPlayer, 5, hudheight-70);
		}

		// [TP] Only draw health and armor if we are allowed to know those stats. Also don't
		// draw spectator's health/armor stats.
		if ( ShouldDrawHealth( CPlayer ))
		{
			DrawHealth(CPlayer, 5, hudheight-45);
			DrawArmor(CPlayer->mo->FindInventory<ABasicArmor>(), 
				CPlayer->mo->FindInventory<AHexenArmor>(),	5, hudheight-20);
		}

		// [TP] Draw team stuff.
		DrawTeamScores( 10, hudheight - 90 );

		i=DrawKeys(CPlayer, hudwidth-4, hudheight-10);
		i=DrawAmmo(CPlayer, hudwidth-5, i);
		DrawWeapons(CPlayer, hudwidth-5, i);
		DrawInventory(CPlayer, 144, hudheight-28);
		if (CPlayer->camera && CPlayer->camera->player)
		{
			StatusBar->DrawCrosshair();
		}
		if (idmypos) DrawCoordinates(CPlayer);

		DrawTime();
	}
	else
	{
		FString mapname;
		char printstr[256];
		int seconds;
		int length=8*SmallFont->GetCharWidth('0');
		int fonth=SmallFont->GetHeight()+1;
		int bottom=hudheight-1;

		if (am_showtotaltime)
		{
			seconds = level.totaltime / TICRATE;
			mysnprintf(printstr, countof(printstr), "%02i:%02i:%02i", seconds/3600, (seconds%3600)/60, seconds%60);
			DrawHudText(SmallFont, hudcolor_ttim, printstr, hudwidth-length, bottom, FRACUNIT);
			bottom -= fonth;
		}

		if (am_showtime)
		{
			if (level.clusterflags&CLUSTER_HUB)
			{
				seconds = level.time /TICRATE;
				mysnprintf(printstr, countof(printstr), "%02i:%02i:%02i", seconds/3600, (seconds%3600)/60, seconds%60);
				DrawHudText(SmallFont, hudcolor_time, printstr, hudwidth-length, bottom, FRACUNIT);
				bottom -= fonth;
			}

			// Single level time for hubs
			seconds= level.maptime /TICRATE;
			mysnprintf(printstr, countof(printstr), "%02i:%02i:%02i", seconds/3600, (seconds%3600)/60, seconds%60);
			DrawHudText(SmallFont, hudcolor_ltim, printstr, hudwidth-length, bottom, FRACUNIT);
		}

		ST_FormatMapName(mapname);
		screen->DrawText(SmallFont, hudcolor_titl, 1, hudheight-fonth-1, mapname,
			DTA_KeepRatio, true,
			DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, TAG_DONE);

		DrawCoordinates(CPlayer);
	}
}