*Adjusted Healthbar color

*Hotkey for Healthbars (ToggleHealthbars)
*Background and Border Texture in core data
This commit is contained in:
titison 2014-11-02 18:18:20 +01:00
parent fe936f5c8c
commit d1597334bf
6 changed files with 103 additions and 14 deletions

View File

@ -115,6 +115,7 @@ Game::Game() : ProgramState(NULL) {
renderFpsAvgTest=0; renderFpsAvgTest=0;
renderExtraTeamColor=0; renderExtraTeamColor=0;
photoModeEnabled=false; photoModeEnabled=false;
forcedHealthbars=false;
visibleHUD=false; visibleHUD=false;
timeDisplay=false; timeDisplay=false;
withRainEffect=false; withRainEffect=false;
@ -235,6 +236,7 @@ void Game::resetMembers() {
scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5"); scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5");
photoModeEnabled = Config::getInstance().getBool("PhotoMode","false"); photoModeEnabled = Config::getInstance().getBool("PhotoMode","false");
forcedHealthbars = Config::getInstance().getBool("ForcedHealthbars","false");
visibleHUD = Config::getInstance().getBool("VisibleHud","true"); visibleHUD = Config::getInstance().getBool("VisibleHud","true");
timeDisplay = Config::getInstance().getBool("TimeDisplay","true"); timeDisplay = Config::getInstance().getBool("TimeDisplay","true");
withRainEffect = Config::getInstance().getBool("RainEffect","true"); withRainEffect = Config::getInstance().getBool("RainEffect","true");
@ -4655,6 +4657,10 @@ void Game::keyDown(SDL_KeyboardEvent key) {
} }
} }
//Toggle Healthbars
else if(isKeyPressed(configKeys.getSDLKey("ToggleHealthbars"),key, false) == true) {
forcedHealthbars = !forcedHealthbars;
}
//Toggle music //Toggle music
//else if(key == configKeys.getCharKey("ToggleMusic")) { //else if(key == configKeys.getCharKey("ToggleMusic")) {
else if(isKeyPressed(configKeys.getSDLKey("ToggleMusic"),key, false) == true) { else if(isKeyPressed(configKeys.getSDLKey("ToggleMusic"),key, false) == true) {
@ -5253,7 +5259,7 @@ void Game::render3d(){
//renderOnTopBars (aka Healthbars) //renderOnTopBars (aka Healthbars)
if(photoModeEnabled == false) { if(photoModeEnabled == false) {
renderer.renderOnTopBars(); renderer.renderOnTopBars(forcedHealthbars);
} }
//particles //particles

View File

@ -141,6 +141,7 @@ private:
static const int renderTeamColorPlaneBit=2; static const int renderTeamColorPlaneBit=2;
bool photoModeEnabled; bool photoModeEnabled;
bool forcedHealthbars;
bool visibleHUD; bool visibleHUD;
bool timeDisplay; bool timeDisplay;
bool withRainEffect; bool withRainEffect;

View File

@ -78,6 +78,9 @@ CoreData::CoreData() {
statusNotReadyTexture=NULL; statusNotReadyTexture=NULL;
statusBRBTexture=NULL; statusBRBTexture=NULL;
healthbarTexture=NULL;
healthbarBackgroundTexture=NULL;
miscTextureList.clear(); miscTextureList.clear();
displayFont=NULL; displayFont=NULL;
@ -181,6 +184,12 @@ Texture2D *CoreData::getTextureBySystemId(TextureSystemType type) const {
case tsyst_statusBRBTexture: case tsyst_statusBRBTexture:
result = statusBRBTexture; result = statusBRBTexture;
break; break;
case tsyst_healthbarTexture:
result = healthbarTexture;
break;
case tsyst_healthbarBackgroundTexture:
result = healthbarBackgroundTexture;
break;
//std::vector<Texture2D *> miscTextureList; //std::vector<Texture2D *> miscTextureList;
} }
@ -417,6 +426,24 @@ Texture2D *CoreData::getGameWinnerTexture() {
return gameWinnerTexture; return gameWinnerTexture;
} }
Texture2D *CoreData::getHealthbarTexture() {
string data_path = getDataPath();
loadTextureIfRequired(&healthbarTexture,data_path,
CORE_MISC_TEXTURES_PATH + "healthbar.png", tsyst_healthbarTexture,
true, false, false, true);
return healthbarTexture;
}
Texture2D *CoreData::getHealthbarBackgroundTexture() {
string data_path = getDataPath();
loadTextureIfRequired(&healthbarBackgroundTexture,data_path,
CORE_MISC_TEXTURES_PATH + "healthbarBackground.png", tsyst_healthbarBackgroundTexture,
true, false, false, true);
return healthbarBackgroundTexture;
}
void CoreData::loadLogoTextureExtraIfRequired() { void CoreData::loadLogoTextureExtraIfRequired() {
int loadAttemptLookupKey = tsyst_COUNT + 1; int loadAttemptLookupKey = tsyst_COUNT + 1;
if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) {

View File

@ -78,6 +78,9 @@ private:
Texture2D *statusNotReadyTexture; Texture2D *statusNotReadyTexture;
Texture2D *statusBRBTexture; Texture2D *statusBRBTexture;
Texture2D *healthbarTexture;
Texture2D *healthbarBackgroundTexture;
std::vector<Texture2D *> miscTextureList; std::vector<Texture2D *> miscTextureList;
Font2D *displayFont; Font2D *displayFont;
@ -133,6 +136,8 @@ public:
tsyst_statusReadyTexture, tsyst_statusReadyTexture,
tsyst_statusNotReadyTexture, tsyst_statusNotReadyTexture,
tsyst_statusBRBTexture, tsyst_statusBRBTexture,
tsyst_healthbarTexture,
tsyst_healthbarBackgroundTexture,
tsyst_COUNT tsyst_COUNT
}; };
@ -171,6 +176,9 @@ public:
Texture2D *getStatusBRBTexture(); Texture2D *getStatusBRBTexture();
Texture2D *getGameWinnerTexture(); Texture2D *getGameWinnerTexture();
Texture2D *getHealthbarTexture();
Texture2D *getHealthbarBackgroundTexture();
size_t getLogoTextureExtraCount(); size_t getLogoTextureExtraCount();
Texture2D *getLogoTextureExtra(int idx); Texture2D *getLogoTextureExtra(int idx);

View File

@ -5610,7 +5610,7 @@ void Renderer::renderSelectionEffects() {
glPopAttrib(); glPopAttrib();
} }
void Renderer::renderOnTopBars(){ void Renderer::renderOnTopBars(bool forceHealthbars){
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
return; return;
} }
@ -5642,11 +5642,17 @@ void Renderer::renderOnTopBars(){
float healthbarheight; float healthbarheight;
float healthbarthickness; float healthbarthickness;
int healthbarVisible; int healthbarVisible;
const Texture2D *healthbarTexture;
const Texture2D *healthbarBackgroundTexture;
//get settings of the faction //get settings of the faction
healthbarheight=unit->getFaction()->getType()->getHealthbarHeight(); healthbarheight=unit->getFaction()->getType()->getHealthbarHeight();
healthbarthickness=unit->getFaction()->getType()->getHealthbarThickness(); healthbarthickness=unit->getFaction()->getType()->getHealthbarThickness();
healthbarVisible=unit->getFaction()->getType()->getHealthbarVisible(); healthbarVisible=unit->getFaction()->getType()->getHealthbarVisible();
CoreData &coreData= CoreData::getInstance();
healthbarTexture=coreData.getHealthbarTexture();
healthbarBackgroundTexture=coreData.getHealthbarBackgroundTexture();
//replace them by the ones from the unit if existent //replace them by the ones from the unit if existent
if(unit->getType()->getHealthbarVisible()!=hbvOff && unit->getType()->getHealthbarVisible()!=hbvUndefined) { if(unit->getType()->getHealthbarVisible()!=hbvOff && unit->getType()->getHealthbarVisible()!=hbvUndefined) {
@ -5659,10 +5665,12 @@ void Renderer::renderOnTopBars(){
healthbarVisible=unit->getType()->getHealthbarVisible(); healthbarVisible=unit->getType()->getHealthbarVisible();
} }
if(unit->isAlive() && !(healthbarVisible==hbvUndefined || (healthbarVisible&hbvOff)) bool settingsWantToRenderThem=!(healthbarVisible==hbvUndefined || (healthbarVisible&hbvOff))
&& ((healthbarVisible&hbvAlways) && ((healthbarVisible&hbvAlways)
|| ((healthbarVisible&hbvDamaged) && unit->getHp()!=unit->getType()->getMaxHp()) || ((healthbarVisible&hbvDamaged) && unit->getHp()!=unit->getType()->getMaxHp())
|| ((healthbarVisible&hbvSelected) && game->getGui()->isSelected(unit)))) { || ((healthbarVisible&hbvSelected) && game->getGui()->isSelected(unit)));
if(unit->isAlive() && (settingsWantToRenderThem || forceHealthbars)) {
Vec3f currVec= unit->getCurrVectorFlat(); Vec3f currVec= unit->getCurrVectorFlat();
if(healthbarheight==-100.0f) { if(healthbarheight==-100.0f) {
currVec.y+=unit->getType()->getHeight(); currVec.y+=unit->getType()->getHeight();
@ -5675,9 +5683,9 @@ void Renderer::renderOnTopBars(){
} }
if(unit->getType()->getMaxEp() > 0) { if(unit->getType()->getMaxEp() > 0) {
renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,unit->getEpRatio()); renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,healthbarTexture,healthbarBackgroundTexture,unit->getEpRatio());
} else { } else {
renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness); renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,healthbarTexture,healthbarBackgroundTexture);
} }
} }
} }
@ -8290,13 +8298,15 @@ void Renderer::enableProjectiveTexturing() {
} }
// ==================== private aux drawing ==================== // ==================== private aux drawing ====================
void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, float ep) { void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, const Texture2D *texture, const Texture2D *backgroundTexture , float ep) {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
return; return;
} }
Vec3f rightVector; Vec3f rightVector;
Vec3f upVector; Vec3f upVector;
Vec3f rightVectorTexture;
Vec3f upVectorTexture;
v.y+=1; v.y+=1;
float modelview[16]; float modelview[16];
float width=(float)size/6+0.25f; float width=(float)size/6+0.25f;
@ -8311,19 +8321,40 @@ void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, float
glGetFloatv(GL_MODELVIEW_MATRIX , modelview); glGetFloatv(GL_MODELVIEW_MATRIX , modelview);
rightVector= Vec3f(modelview[0], modelview[4], modelview[8]); rightVector= Vec3f(modelview[0], modelview[4], modelview[8]);
upVector= Vec3f(modelview[1], modelview[5], modelview[9]); upVector= Vec3f(modelview[1], modelview[5], modelview[9]);
rightVectorTexture=rightVector*2;
upVectorTexture=upVector*4;
hp=hp*2-1; hp=hp*2-1;
ep=ep*2-1; ep=ep*2-1;
//from green to yellow to red //from green to yellow to red
if(hp >= 0.0f) { if(hp >= 0.5f) {
green=brightness; green=brightness;
red=brightness-hp*brightness; red=brightness-(hp-0.5f)*brightness;
} else { } else {
red=brightness; red=brightness;
green=brightness+hp*brightness; green=brightness+(hp-0.5f)*brightness;
} }
//backgroundTexture
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(backgroundTexture)->getHandle());
glColor4f(1.f,1.f,1.f,1.f);
//glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
glBegin(GL_QUADS);
glTexCoord2i(0,1);
glVertex3fv((v - (rightVectorTexture*width - upVectorTexture*height)).ptr());
glTexCoord2i(0,0);
glVertex3fv((v - (rightVectorTexture*width + upVectorTexture*height)).ptr());
glTexCoord2i(1,0);
glVertex3fv((v + (rightVectorTexture*width - upVectorTexture*height)).ptr());
glTexCoord2i(1,1);
glVertex3fv((v + (rightVectorTexture*width + upVectorTexture*height)).ptr());
glEnd();
glDisable(GL_TEXTURE_2D);
//healthbar
glColor4f(red,green,0.0f,0.4f); glColor4f(red,green,0.0f,0.4f);
glBegin(GL_QUADS); glBegin(GL_QUADS);
if(ep < -2.0f) { if(ep < -2.0f) {
@ -8357,6 +8388,22 @@ void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, float
glVertex3fv((v + (rightVector*width + upVector*height)).ptr()); glVertex3fv((v + (rightVector*width + upVector*height)).ptr());
glEnd(); glEnd();
//BorderTexture
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(texture)->getHandle());
glColor4f(1.f,1.f,1.f,1.f);
//glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
glBegin(GL_QUADS);
glTexCoord2i(0,1);
glVertex3fv((v - (rightVectorTexture*width - upVectorTexture*height)).ptr());
glTexCoord2i(0,0);
glVertex3fv((v - (rightVectorTexture*width + upVectorTexture*height)).ptr());
glTexCoord2i(1,0);
glVertex3fv((v + (rightVectorTexture*width - upVectorTexture*height)).ptr());
glTexCoord2i(1,1);
glVertex3fv((v + (rightVectorTexture*width + upVectorTexture*height)).ptr());
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix(); glPopMatrix();
} }

View File

@ -549,7 +549,7 @@ public:
void renderUnitsToBuild(const int renderFps); void renderUnitsToBuild(const int renderFps);
void renderSelectionEffects(); void renderSelectionEffects();
void renderOnTopBars(); void renderOnTopBars(bool forceHealthbars=false);
void renderWaterEffects(); void renderWaterEffects();
void renderHud(); void renderHud();
void renderMinimap(); void renderMinimap();
@ -681,7 +681,7 @@ private:
//private aux drawing //private aux drawing
void renderSelectionCircle(Vec3f v, int size, float radius, float thickness=0.2f); void renderSelectionCircle(Vec3f v, int size, float radius, float thickness=0.2f);
void renderHealthBar(Vec3f v, int size, float hp, float height, float ep=-1.0f); void renderHealthBar(Vec3f v, int size, float hp, float height, const Texture2D *texture, const Texture2D *backgroundTexture , float ep=-1.0f);
void renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec3f color, const Texture2D *texture); void renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec3f color, const Texture2D *texture);
void renderArrow(const Vec3f &pos1, const Vec3f &pos2, const Vec3f &color, float width); void renderArrow(const Vec3f &pos1, const Vec3f &pos2, const Vec3f &color, float width);
void renderTile(const Vec2i &pos); void renderTile(const Vec2i &pos);