Very first version of irrlicht energy meter.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3752 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-07-14 12:57:04 +00:00
parent f978c25cf4
commit 1ef58fce9a

View File

@ -252,149 +252,71 @@ void RaceGUI::drawPowerupIcons(Kart* player_kart, int offset_x,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/* Energy meter that gets filled with coins */ /* Energy meter that gets filled with coins */
// Meter fluid color (0 - 255)
#define METER_TOP_COLOR 240, 0, 0, 255
#define METER_BOTTOM_COLOR 240, 200, 0, 160
// Meter border color (0.0 - 1.0)
#define METER_BORDER_BLACK 0.0, 0.0, 0.0
#define METER_BORDER_WHITE 1.0, 1.0, 1.0
#define METER_TARGET_RED 1.0, 0.0, 0.0
//-----------------------------------------------------------------------------
void RaceGUI::drawEnergyMeter ( Kart *player_kart, int offset_x, int offset_y, void RaceGUI::drawEnergyMeter ( Kart *player_kart, int offset_x, int offset_y,
float ratio_x, float ratio_y ) float ratio_x, float ratio_y )
{ {
float state = (float)(player_kart->getEnergy()) / float state = (float)(player_kart->getEnergy()) / MAX_ITEMS_COLLECTED;
MAX_ITEMS_COLLECTED;
int x = (int)((UserConfigParams::m_width-24) * ratio_x) + offset_x; int x = (int)((UserConfigParams::m_width-24) * ratio_x) + offset_x;
int y = (int)(250 * ratio_y) + offset_y; int y = (int)(250 * ratio_y) + offset_y;
int w = (int)(16 * ratio_x); int w = (int)(16 * ratio_x);
int h = (int)(UserConfigParams::m_height/4 * ratio_y); int h = (int)(UserConfigParams::m_height/4 * ratio_y);
int wl = (int)(ratio_x);
if(wl < 1)
wl = 1;
const int GRADS = (int)(MAX_ITEMS_COLLECTED/5); // each graduation equals 5 items
int gh = (int)(h/GRADS); //graduation height
float coin_target = (float)race_manager->getCoinTarget(); float coin_target = (float)race_manager->getCoinTarget();
int th = (int)(h*(coin_target/MAX_ITEMS_COLLECTED)); int th = (int)(h*(coin_target/MAX_ITEMS_COLLECTED));
glDisable(GL_TEXTURE_2D); video::SColor black_border(255, 0, 0, 0);
// Draw a Meter border video::SColor white_border(255, 255, 255, 255);
x-=1; video::IVideoDriver *video = irr_driver->getVideoDriver();
y-=1; #define LINE(x0,y0,x1,y1, color) video->draw2DLine(core::position2di(x0,y0), \
// left side core::position2di(x1,y1), color)
glBegin ( GL_QUADS ) ;
glColor3f ( METER_BORDER_BLACK ) ;
glVertex2i ( x-wl, y-wl ) ;
glVertex2i ( x, y-wl ) ;
glVertex2i ( x, y + h+1) ;
glVertex2i ( x-wl, y + h+1) ;
glEnd () ;
// right side // FIXME: the original code drew a rectangle, i.e. two lines. This seems to be
glBegin ( GL_QUADS ) ; // unnecesssary, so it's commented out here
glColor3f ( METER_BORDER_BLACK ) ; // Left side:
glVertex2i ( x+w, y-wl ) ; LINE(x-1, y+1, x-1, y-h-1, black_border);
glVertex2i ( x+w+wl, y-wl ) ; //LINE(x, y-1, x, y+h+1, black_border);
glVertex2i ( x+w+wl, y + h+1) ; LINE(x, y, x, y-h-2, white_border);
glVertex2i ( x+w, y + h+1) ; //LINE(x+1, y, x+1, y+h+2, white_border);
glEnd () ;
// down side // Right side:
glBegin ( GL_QUADS ) ; LINE(x+w, y+1, x+w, y-h-1, black_border);
glColor3f ( METER_BORDER_BLACK ) ; //LINE(x+w+1, y-1, x+w+1, y+h+1, black_border);
glVertex2i ( x, y-wl ) ; LINE(x+w+1, y, x+w+1, y-h-2, white_border);
glVertex2i ( x+w, y-wl ) ; //LINE(x+w+2, y, x+w+2, y+h+2, white_border);
glVertex2i ( x+w, y ) ;
glVertex2i ( x, y ) ;
glEnd () ;
// up side // Bottom
glBegin ( GL_QUADS ) ; LINE(x, y+1, x+w, y+1, black_border);
glColor3f ( METER_BORDER_BLACK ) ; //LINE(x, y, x+w, y, black_border);
glVertex2i ( x, y+h ) ; LINE(x+1, y, x+w+1, y, white_border);
glVertex2i ( x+w, y+h ) ; //LINE(x+1, y+1, x+w+1, y+1, white_border);
glVertex2i ( x+w, y+h+wl ) ; // Top
glVertex2i ( x, y+h+wl ) ; LINE(x, y-h, x+w, y-h, black_border);
glEnd () ; //LINE(x, y+h+1, x+w, y+h+1, black_border);
LINE(x, y-h-1, x+w, y-h-1, white_border);
//LINE(x, y+h+2, x+w, y+h+2, white_border);
x+=1; const int GRADS = (int)(MAX_ITEMS_COLLECTED/5); // each graduation equals 5 items
y+=1; int gh = (int)(h/GRADS); //graduation height
// left side // 'Meter marks;
glBegin ( GL_QUADS ) ;
glColor3f ( METER_BORDER_WHITE ) ;
glVertex2i ( x-wl, y-wl ) ;
glVertex2i ( x, y-wl ) ;
glVertex2i ( x, y + h+1) ;
glVertex2i ( x-wl, y + h+1) ;
glEnd () ;
// right side
glBegin ( GL_QUADS ) ;
glColor3f ( METER_BORDER_WHITE ) ;
glVertex2i ( x+w, y-wl ) ;
glVertex2i ( x+w+wl, y-wl ) ;
glVertex2i ( x+w+wl, y + h+1) ;
glVertex2i ( x+w, y + h+1) ;
glEnd () ;
// down side
glBegin ( GL_QUADS ) ;
glColor3f ( METER_BORDER_WHITE ) ;
glVertex2i ( x, y-wl ) ;
glVertex2i ( x+w, y-wl ) ;
glVertex2i ( x+w, y ) ;
glVertex2i ( x, y ) ;
glEnd () ;
//Graduations
int gh_incr = gh; int gh_incr = gh;
for (int i=0; i<GRADS-1; i++) for (int i=0; i<GRADS-1; i++)
{ {
glBegin( GL_QUADS ); LINE(x+1, y-1-gh, x+1+w, y-1-gh, white_border);
glColor3f(METER_BORDER_WHITE);
glVertex2i(x, y+gh);
glVertex2i(x+w, y+gh);
glVertex2i(x+w, y+gh+wl);
glVertex2i(x, y+gh+wl);
glEnd();
gh+=gh_incr; gh+=gh_incr;
} }
//Target line //Target line
if (coin_target > 0) if (coin_target > 0)
{ {
glBegin ( GL_QUADS ); LINE(x+1, y-1-th, x+1+w, y-1-th, video::SColor(255, 255, 0, 0));
glColor3f(METER_TARGET_RED);
glVertex2i(x, y+th);
glVertex2i(x+w, y+th);
glVertex2i(x+w, y+th+wl);
glVertex2i(x, y+th+wl);
glEnd();
} }
#undef LINE
// up side // The actual energy meter
glBegin ( GL_QUADS ) ; core::rect<s32> energy(x+1, y-1-(int)(state*h), x+1+w, y-1);
glColor3f ( METER_BORDER_WHITE ) ; video::SColor bottom(255, 240, 0, 0);
glVertex2i ( x, y+h ) ; video::SColor top (160, 240, 200, 0);
glVertex2i ( x+w, y+h ) ; video->draw2DRectangle(energy, top, top, bottom, bottom);
glVertex2i ( x+w, y+h+wl ) ;
glVertex2i ( x, y+h+wl ) ;
glEnd () ;
// Draw the Meter fluid
glBegin ( GL_QUADS ) ;
glColor4ub ( METER_BOTTOM_COLOR ) ;
glVertex2i ( x, y ) ;
glVertex2i ( x+w, y ) ;
glColor4ub ( METER_TOP_COLOR ) ;
glVertex2i ( x+w, y + (int)(state * h));
glVertex2i ( x, y + (int)(state * h) ) ;
glEnd () ;
glEnable(GL_TEXTURE_2D);
} // drawEnergyMeter } // drawEnergyMeter
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -710,8 +632,8 @@ void RaceGUI::drawStatusText()
Kart* player_kart = RaceManager::getWorld()->getLocalPlayerKart(pla); Kart* player_kart = RaceManager::getWorld()->getLocalPlayerKart(pla);
drawPowerupIcons(player_kart, offset_x, offset_y, drawPowerupIcons(player_kart, offset_x, offset_y,
split_screen_ratio_x, split_screen_ratio_y ); split_screen_ratio_x, split_screen_ratio_y );
// drawEnergyMeter (player_kart, offset_x, offset_y, drawEnergyMeter (player_kart, offset_x, offset_y,
// split_screen_ratio_x, split_screen_ratio_y ); split_screen_ratio_x, split_screen_ratio_y );
// drawSpeed (player_kart, offset_x, offset_y, // drawSpeed (player_kart, offset_x, offset_y,
// split_screen_ratio_x, split_screen_ratio_y ); // split_screen_ratio_x, split_screen_ratio_y );
drawLap (info, player_kart, offset_x, offset_y, drawLap (info, player_kart, offset_x, offset_y,