Minor hud.cpp cleanup

This commit is contained in:
kwolekr 2013-04-25 20:56:12 -04:00
parent 43a388ec53
commit 0fb9567f13
2 changed files with 10 additions and 9 deletions

@ -45,6 +45,8 @@ Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
hotbar_imagesize = 48; hotbar_imagesize = 48;
hotbar_itemcount = 8; hotbar_itemcount = 8;
tsrc = gamedef->getTextureSource();
v3f crosshair_color = g_settings->getV3F("crosshair_color"); v3f crosshair_color = g_settings->getV3F("crosshair_color");
u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255); u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255);
u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255); u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255);
@ -57,6 +59,8 @@ Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255); u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255);
u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255); u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255);
selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b); selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
} }
@ -175,8 +179,7 @@ void Hud::drawLuaElements() {
v2s32 pos(e->pos.X * screensize.X, e->pos.Y * screensize.Y); v2s32 pos(e->pos.X * screensize.X, e->pos.Y * screensize.Y);
switch (e->type) { switch (e->type) {
case HUD_ELEM_IMAGE: { case HUD_ELEM_IMAGE: {
video::ITexture *texture = video::ITexture *texture = tsrc->getTextureRaw(e->text);
gamedef->getTextureSource()->getTextureRaw(e->text);
if (!texture) if (!texture)
continue; continue;
@ -226,8 +229,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s
const video::SColor color(255, 255, 255, 255); const video::SColor color(255, 255, 255, 255);
const video::SColor colors[] = {color, color, color, color}; const video::SColor colors[] = {color, color, color, color};
video::ITexture *stat_texture = video::ITexture *stat_texture = tsrc->getTextureRaw(texture);
gamedef->getTextureSource()->getTextureRaw(texture);
if (!stat_texture) if (!stat_texture)
return; return;
@ -299,9 +301,8 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) {
void Hud::drawCrosshair() { void Hud::drawCrosshair() {
if (!(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE)) if (!(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE))
return; return;
ITextureSource *tsrc = gamedef->getTextureSource(); if (use_crosshair_image) {
if (tsrc->isKnownSourceImage("crosshair.png")) {
video::ITexture *crosshair = tsrc->getTextureRaw("crosshair.png"); video::ITexture *crosshair = tsrc->getTextureRaw("crosshair.png");
v2u32 size = crosshair->getOriginalSize(); v2u32 size = crosshair->getOriginalSize();
v2s32 lsize = v2s32(displaycenter.X - (size.X / 2), v2s32 lsize = v2s32(displaycenter.X - (size.X / 2),

@ -82,8 +82,6 @@ inline u32 hud_get_free_id(Player *player) {
#ifndef SERVER #ifndef SERVER
#include <deque>
#include <IGUIFont.h> #include <IGUIFont.h>
#include "gamedef.h" #include "gamedef.h"
@ -99,6 +97,7 @@ public:
IGameDef *gamedef; IGameDef *gamedef;
LocalPlayer *player; LocalPlayer *player;
Inventory *inventory; Inventory *inventory;
ITextureSource *tsrc;
v2u32 screensize; v2u32 screensize;
v2s32 displaycenter; v2s32 displaycenter;
@ -107,6 +106,7 @@ public:
video::SColor crosshair_argb; video::SColor crosshair_argb;
video::SColor selectionbox_argb; video::SColor selectionbox_argb;
bool use_crosshair_image;
Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv, Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
gui::IGUIFont *font, u32 text_height, IGameDef *gamedef, gui::IGUIFont *font, u32 text_height, IGameDef *gamedef,