void HUD::Update( FONT & lcdfont, FONT & sansfont, FONT & sansfont_noshader, float displaywidth, float displayheight, float curlap, float lastlap, float bestlap, float stagingtimeleft, int curlapnum, int numlaps, int curplace, int numcars, float rpm, float redrpm, float maxrpm, float speed, float maxspeed, bool mph, float clutch, int newgear, const std::string & debug_string1, const std::string & debug_string2, const std::string & debug_string3, const std::string & debug_string4, bool absenabled, bool absactive, bool tcsenabled, bool tcsactive, bool outofgas, bool nosactive, float nosamount, bool drifting, float driftscore, float thisdriftscore) { if (!lastvisible) return; float screenhwratio = displayheight/displaywidth; if (debug_hud_info) { debugtext1.Revise(sansfont, debug_string1); debugtext2.Revise(sansfont, debug_string2); debugtext3.Revise(sansfont, debug_string3); debugtext4.Revise(sansfont, debug_string4); } #ifdef GAUGES FONT & gaugefont = sansfont_noshader; if (fabs(this->maxrpm - maxrpm) > 1) { this->maxrpm = maxrpm; rpmgauge.Revise(hudroot, gaugefont, 0, maxrpm * 0.001, 1); } if (fabs(this->maxspeed - maxspeed) > 1 || this->mph != mph) { this->maxspeed = maxspeed; this->mph = mph; if (mph) { speedlabel.Revise(gaugefont, "mph"); speedscale = 2.23693629; } else { speedlabel.Revise(gaugefont, "kph"); speedscale = 3.6; } speedgauge.Revise(hudroot, gaugefont, 0, maxspeed * speedscale, 10); } rpmgauge.Update(hudroot, rpm * 0.001); speedgauge.Update(hudroot, fabs(speed) * speedscale); // gear std::stringstream gearstr; if (newgear == -1) gearstr << "R"; else if (newgear == 0) gearstr << "N"; else gearstr << newgear; geartext.Revise(gaugefont, gearstr.str()); float geartext_alpha = clutch * 0.5 + 0.5; if (newgear == 0) geartext_alpha = 1; DRAWABLE & geartextdrawref = hudroot.GetDrawlist().text.get(geartextdraw); geartextdrawref.SetColor(1, 1, 1, geartext_alpha); // speed std::stringstream sstr; sstr << std::abs(int(speed * speedscale)); //float sx = mphtext.GetScale().first; //float sy = mphtext.GetScale().second; //float w = gaugefont.GetWidth(sstr.str()) * sx; //float x = 1 - w; //float y = 1 - sy * 0.5; mphtext.Revise(gaugefont, sstr.str());//, x, y, fontscalex, fontscaley); #else std::stringstream gearstr; if (newgear == -1) gearstr << "R"; else if (newgear == 0) gearstr << "N"; else gearstr << newgear; geartext.Revise(lcdfont, gearstr.str()); float geartext_alpha = (newgear == 0) ? 1 : clutch * 0.5 + 0.5; DRAWABLE & geartextdrawref = hudroot.GetDrawlist().text.get(geartextdraw); geartextdrawref.SetColor(1, 1, 1, geartext_alpha); float rpmpercent = std::min(1.0f, rpm / maxrpm); float rpmredpoint = redrpm / maxrpm; float rpmxstart = 60.0 / displaywidth; float rpmwidth = 200.0 / displaywidth; float rpmredx = rpmwidth * rpmredpoint + rpmxstart; float rpmy = 1.0 - 26.0 / displayheight; float rpmheight = 20.0 / displayheight; float rpmxend = rpmxstart + rpmwidth * rpmredpoint; float rpmrealend = rpmxstart + rpmwidth * rpmpercent; if (rpmxend > rpmrealend) rpmxend = rpmrealend; float rpmredxend = rpmrealend; if (rpmrealend < rpmredx) rpmredxend = rpmredx; rpmbarverts.SetToBillboard(rpmxstart, rpmy, rpmxend, rpmy + rpmheight); rpmredbarverts.SetToBillboard(rpmredx, rpmy, rpmredxend, rpmy + rpmheight); rpmboxverts.SetToBillboard(rpmxstart, rpmy, rpmxstart + rpmwidth, rpmy + rpmheight); std::stringstream speedo; if (mph) speedo << std::abs((int)(2.23693629 * speed)) << " MPH"; else speedo << std::abs((int)(3.6 * speed)) << " KPH"; float fontscalex = mphtext.GetScale().first; float fontscaley = mphtext.GetScale().second; float speedotextwidth = lcdfont.GetWidth(speedo.str()) * fontscalex; float x = 1.0 - screenhwratio * 0.02 - speedotextwidth; float y = 1 - fontscaley * 0.5; mphtext.Revise(lcdfont, speedo.str(), x, y, fontscalex, fontscaley); #endif //update ABS alpha value if (!absenabled) { abs.SetAlpha(hudroot, 0.0); } else { if (absactive) abs.SetAlpha(hudroot, 1.0); else abs.SetAlpha(hudroot, 0.2); } //update TCS alpha value if (!tcsenabled) { tcs.SetAlpha(hudroot, 0.0); } else { if (tcsactive) tcs.SetAlpha(hudroot, 1.0); else tcs.SetAlpha(hudroot, 0.2); } //update GAS indicator if (outofgas) { gas.SetAlpha(hudroot, 1.0); } else { gas.SetAlpha(hudroot, 0.0); } //update NOS indicator if (nosamount > 0) { if (nosactive) nos.SetAlpha(hudroot, 1.0); else nos.SetAlpha(hudroot, 0.2); } else { nos.SetAlpha(hudroot, 0.0); } //update timer info { std::string tempstr; GetTimeString(curlap, tempstr); laptime.Revise(tempstr); GetTimeString(lastlap, tempstr); lastlaptime.Revise(tempstr); GetTimeString(bestlap, tempstr); bestlaptime.Revise(tempstr); } //update drift score if (numlaps == 0) //this is how we determine practice mode, for now { std::stringstream scorestream; scorestream << "Score " << (int)driftscore; if (drifting) { scorestream << " + " << (int)thisdriftscore; driftscoreindicator.SetColor(hudroot, 1,0,0); } else { driftscoreindicator.SetColor(hudroot, 1,1,1); } driftscoreindicator.Revise(scorestream.str()); } else { driftscoreindicator.SetDrawEnable(hudroot, false); } if (numlaps > 0) { //update lap std::stringstream lapstream; //std::cout << curlapnum << std::endl; lapstream << "Lap " << std::max(1, std::min(curlapnum, numlaps)) << "/" << numlaps; lapindicator.Revise(lapstream.str()); //update place std::stringstream stream; stream << "Place " << curplace << "/" << numcars; placeindicator.Revise(stream.str()); //update race prompt std::stringstream t; if (stagingtimeleft > 0.5) { t << ((int)stagingtimeleft)+1; raceprompt.SetColor(hudroot, 1,0,0); racecomplete = false; } else if (stagingtimeleft > 0.0) { t << "Ready"; raceprompt.SetColor(hudroot, 1,1,0); } else if (stagingtimeleft < 0.0f && stagingtimeleft > -1.0f) //stagingtimeleft needs to go negative to get the GO message { t << "GO"; raceprompt.SetColor(hudroot, 0,1,0); } else if (curlapnum > numlaps && !racecomplete) { if (curplace == 1) { t << "You won!"; raceprompt.SetColor(hudroot, 0,1,0); } else { t << "You lost"; raceprompt.SetColor(hudroot, 1,0,0); } raceprompt.Revise(t.str()); float width = raceprompt.GetWidth(); raceprompt.SetPosition(0.5-width*0.5,0.5); racecomplete = true; } if (!racecomplete) { raceprompt.Revise(t.str()); float width = raceprompt.GetWidth(); raceprompt.SetPosition(0.5-width*0.5,0.5); } } else { lapindicator.SetDrawEnable(hudroot, false); placeindicator.SetDrawEnable(hudroot, false); raceprompt.SetDrawEnable(hudroot, false); } }
float WIDGET_LABEL::GetWidth(const FONT & font, const std::string & text, float scale) const { return font.GetWidth(text) * scale; }