From fe936f5c8c621f0d6c5a201de21d26ca7eb4f603 Mon Sep 17 00:00:00 2001 From: titison Date: Thu, 30 Oct 2014 00:55:18 +0100 Subject: [PATCH 1/4] Adjusting healthbar related things *unit height=healthbar height per default *no hpbars in photomode *renamed function --- source/glest_game/game/game.cpp | 4 +++- source/glest_game/graphics/renderer.cpp | 16 ++++++++++++---- source/glest_game/graphics/renderer.h | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 39acbd64..67c83374 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -5252,7 +5252,9 @@ void Game::render3d(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); //renderOnTopBars (aka Healthbars) - renderer.renderOnTopBars(); + if(photoModeEnabled == false) { + renderer.renderOnTopBars(); + } //particles renderer.renderParticleManager(rsGame); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index fea57fc7..ec35eb5b 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5620,6 +5620,10 @@ void Renderer::renderOnTopBars(){ return; } + if(config.getBool("PhotoMode")) { + return; + } + glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); @@ -5661,7 +5665,7 @@ void Renderer::renderOnTopBars(){ || ((healthbarVisible&hbvSelected) && game->getGui()->isSelected(unit)))) { Vec3f currVec= unit->getCurrVectorFlat(); if(healthbarheight==-100.0f) { - currVec.y+=unit->getType()->getHeight()+1; + currVec.y+=unit->getType()->getHeight(); } else { currVec.y+=healthbarheight; } @@ -5671,9 +5675,9 @@ void Renderer::renderOnTopBars(){ } if(unit->getType()->getMaxEp() > 0) { - renderSelectionHpBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,unit->getEpRatio()); + renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,unit->getEpRatio()); } else { - renderSelectionHpBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness); + renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness); } } } @@ -8286,7 +8290,11 @@ void Renderer::enableProjectiveTexturing() { } // ==================== private aux drawing ==================== -void Renderer::renderSelectionHpBar(Vec3f v, int size, float hp, float height, float ep) { +void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, float ep) { + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + return; + } + Vec3f rightVector; Vec3f upVector; v.y+=1; diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index fa15818b..84059abc 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -681,7 +681,7 @@ private: //private aux drawing void renderSelectionCircle(Vec3f v, int size, float radius, float thickness=0.2f); - void renderSelectionHpBar(Vec3f v, int size, float hp, float height, float ep=-1.0f); + void renderHealthBar(Vec3f v, int size, float hp, float height, float ep=-1.0f); 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 renderTile(const Vec2i &pos); From d1597334bfa0b85ffeb7463152fadf2adf827869 Mon Sep 17 00:00:00 2001 From: titison Date: Sun, 2 Nov 2014 18:18:20 +0100 Subject: [PATCH 2/4] *Adjusted Healthbar color *Hotkey for Healthbars (ToggleHealthbars) *Background and Border Texture in core data --- source/glest_game/game/game.cpp | 8 ++- source/glest_game/game/game.h | 1 + source/glest_game/global/core_data.cpp | 27 ++++++++++ source/glest_game/global/core_data.h | 8 +++ source/glest_game/graphics/renderer.cpp | 69 +++++++++++++++++++++---- source/glest_game/graphics/renderer.h | 4 +- 6 files changed, 103 insertions(+), 14 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 67c83374..f3bfca0a 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -115,6 +115,7 @@ Game::Game() : ProgramState(NULL) { renderFpsAvgTest=0; renderExtraTeamColor=0; photoModeEnabled=false; + forcedHealthbars=false; visibleHUD=false; timeDisplay=false; withRainEffect=false; @@ -235,6 +236,7 @@ void Game::resetMembers() { scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5"); photoModeEnabled = Config::getInstance().getBool("PhotoMode","false"); + forcedHealthbars = Config::getInstance().getBool("ForcedHealthbars","false"); visibleHUD = Config::getInstance().getBool("VisibleHud","true"); timeDisplay = Config::getInstance().getBool("TimeDisplay","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 //else if(key == configKeys.getCharKey("ToggleMusic")) { else if(isKeyPressed(configKeys.getSDLKey("ToggleMusic"),key, false) == true) { @@ -5253,7 +5259,7 @@ void Game::render3d(){ //renderOnTopBars (aka Healthbars) if(photoModeEnabled == false) { - renderer.renderOnTopBars(); + renderer.renderOnTopBars(forcedHealthbars); } //particles diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 1ebfc6c6..d4aae999 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -141,6 +141,7 @@ private: static const int renderTeamColorPlaneBit=2; bool photoModeEnabled; + bool forcedHealthbars; bool visibleHUD; bool timeDisplay; bool withRainEffect; diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 6315d5d0..e0945aea 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -78,6 +78,9 @@ CoreData::CoreData() { statusNotReadyTexture=NULL; statusBRBTexture=NULL; + healthbarTexture=NULL; + healthbarBackgroundTexture=NULL; + miscTextureList.clear(); displayFont=NULL; @@ -181,6 +184,12 @@ Texture2D *CoreData::getTextureBySystemId(TextureSystemType type) const { case tsyst_statusBRBTexture: result = statusBRBTexture; break; + case tsyst_healthbarTexture: + result = healthbarTexture; + break; + case tsyst_healthbarBackgroundTexture: + result = healthbarBackgroundTexture; + break; //std::vector miscTextureList; } @@ -417,6 +426,24 @@ Texture2D *CoreData::getGameWinnerTexture() { 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() { int loadAttemptLookupKey = tsyst_COUNT + 1; if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index b184338e..d0ce3afa 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -78,6 +78,9 @@ private: Texture2D *statusNotReadyTexture; Texture2D *statusBRBTexture; + Texture2D *healthbarTexture; + Texture2D *healthbarBackgroundTexture; + std::vector miscTextureList; Font2D *displayFont; @@ -133,6 +136,8 @@ public: tsyst_statusReadyTexture, tsyst_statusNotReadyTexture, tsyst_statusBRBTexture, + tsyst_healthbarTexture, + tsyst_healthbarBackgroundTexture, tsyst_COUNT }; @@ -171,6 +176,9 @@ public: Texture2D *getStatusBRBTexture(); Texture2D *getGameWinnerTexture(); + Texture2D *getHealthbarTexture(); + Texture2D *getHealthbarBackgroundTexture(); + size_t getLogoTextureExtraCount(); Texture2D *getLogoTextureExtra(int idx); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index ec35eb5b..f5928c70 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5610,7 +5610,7 @@ void Renderer::renderSelectionEffects() { glPopAttrib(); } -void Renderer::renderOnTopBars(){ +void Renderer::renderOnTopBars(bool forceHealthbars){ if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -5642,11 +5642,17 @@ void Renderer::renderOnTopBars(){ float healthbarheight; float healthbarthickness; int healthbarVisible; + const Texture2D *healthbarTexture; + const Texture2D *healthbarBackgroundTexture; //get settings of the faction healthbarheight=unit->getFaction()->getType()->getHealthbarHeight(); healthbarthickness=unit->getFaction()->getType()->getHealthbarThickness(); 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 if(unit->getType()->getHealthbarVisible()!=hbvOff && unit->getType()->getHealthbarVisible()!=hbvUndefined) { @@ -5659,10 +5665,12 @@ void Renderer::renderOnTopBars(){ healthbarVisible=unit->getType()->getHealthbarVisible(); } - if(unit->isAlive() && !(healthbarVisible==hbvUndefined || (healthbarVisible&hbvOff)) - && ((healthbarVisible&hbvAlways) - || ((healthbarVisible&hbvDamaged) && unit->getHp()!=unit->getType()->getMaxHp()) - || ((healthbarVisible&hbvSelected) && game->getGui()->isSelected(unit)))) { + bool settingsWantToRenderThem=!(healthbarVisible==hbvUndefined || (healthbarVisible&hbvOff)) + && ((healthbarVisible&hbvAlways) + || ((healthbarVisible&hbvDamaged) && unit->getHp()!=unit->getType()->getMaxHp()) + || ((healthbarVisible&hbvSelected) && game->getGui()->isSelected(unit))); + + if(unit->isAlive() && (settingsWantToRenderThem || forceHealthbars)) { Vec3f currVec= unit->getCurrVectorFlat(); if(healthbarheight==-100.0f) { currVec.y+=unit->getType()->getHeight(); @@ -5675,9 +5683,9 @@ void Renderer::renderOnTopBars(){ } 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 { - 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 ==================== -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) { return; } Vec3f rightVector; Vec3f upVector; + Vec3f rightVectorTexture; + Vec3f upVectorTexture; v.y+=1; float modelview[16]; 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); rightVector= Vec3f(modelview[0], modelview[4], modelview[8]); upVector= Vec3f(modelview[1], modelview[5], modelview[9]); + rightVectorTexture=rightVector*2; + upVectorTexture=upVector*4; hp=hp*2-1; ep=ep*2-1; //from green to yellow to red - if(hp >= 0.0f) { + if(hp >= 0.5f) { green=brightness; - red=brightness-hp*brightness; + red=brightness-(hp-0.5f)*brightness; } else { red=brightness; - green=brightness+hp*brightness; + green=brightness+(hp-0.5f)*brightness; } + //backgroundTexture + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, static_cast(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); glBegin(GL_QUADS); 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()); glEnd(); + //BorderTexture + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, static_cast(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(); } diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 84059abc..451ffc28 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -549,7 +549,7 @@ public: void renderUnitsToBuild(const int renderFps); void renderSelectionEffects(); - void renderOnTopBars(); + void renderOnTopBars(bool forceHealthbars=false); void renderWaterEffects(); void renderHud(); void renderMinimap(); @@ -681,7 +681,7 @@ private: //private aux drawing 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 renderArrow(const Vec3f &pos1, const Vec3f &pos2, const Vec3f &color, float width); void renderTile(const Vec2i &pos); From 791e1edec6f556bff238a5a514081755bec1fa6f Mon Sep 17 00:00:00 2001 From: titison Date: Wed, 5 Nov 2014 02:05:47 +0100 Subject: [PATCH 3/4] Healthbars Textures (border and background) Faction.xml can specify more healthbars details --- source/glest_game/game/game.cpp | 2 +- source/glest_game/graphics/renderer.cpp | 120 +++++++++++++---------- source/glest_game/graphics/renderer.h | 4 +- source/glest_game/types/faction_type.cpp | 44 +++++++-- source/glest_game/types/faction_type.h | 11 +++ source/glest_game/types/unit_type.cpp | 14 +-- 6 files changed, 127 insertions(+), 68 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index f3bfca0a..7daac218 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -5259,7 +5259,7 @@ void Game::render3d(){ //renderOnTopBars (aka Healthbars) if(photoModeEnabled == false) { - renderer.renderOnTopBars(forcedHealthbars); + renderer.renderHealthBars(forcedHealthbars); } //particles diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index f5928c70..60be150e 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5610,7 +5610,7 @@ void Renderer::renderSelectionEffects() { glPopAttrib(); } -void Renderer::renderOnTopBars(bool forceHealthbars){ +void Renderer::renderHealthBars(bool forceHealthbars){ if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -5644,15 +5644,31 @@ void Renderer::renderOnTopBars(bool forceHealthbars){ int healthbarVisible; const Texture2D *healthbarTexture; const Texture2D *healthbarBackgroundTexture; + bool healthbarLineBorder; //get settings of the faction healthbarheight=unit->getFaction()->getType()->getHealthbarHeight(); healthbarthickness=unit->getFaction()->getType()->getHealthbarThickness(); healthbarVisible=unit->getFaction()->getType()->getHealthbarVisible(); + healthbarLineBorder=unit->getFaction()->getType()->isHealthbarLineBorder(); CoreData &coreData= CoreData::getInstance(); - healthbarTexture=coreData.getHealthbarTexture(); - healthbarBackgroundTexture=coreData.getHealthbarBackgroundTexture(); - + //First try faction texture then use core Texture + if(unit->getFaction()->getType()->isHealthbarBorderTextureEnabled()) { + healthbarTexture=unit->getFaction()->getType()->getHealthbarTexture(); + if(healthbarTexture==NULL) { + healthbarTexture=coreData.getHealthbarTexture(); + } + } else { + healthbarTexture=NULL; + } + if(unit->getFaction()->getType()->isHealthbarBackgroundTextureEnabled()) { + healthbarBackgroundTexture=unit->getFaction()->getType()->getHealthbarBackgroundTexture(); + if(healthbarBackgroundTexture==NULL) { + healthbarBackgroundTexture=coreData.getHealthbarBackgroundTexture(); + } + } else { + healthbarBackgroundTexture=NULL; + } //replace them by the ones from the unit if existent if(unit->getType()->getHealthbarVisible()!=hbvOff && unit->getType()->getHealthbarVisible()!=hbvUndefined) { @@ -5680,12 +5696,9 @@ void Renderer::renderOnTopBars(bool forceHealthbars){ if(unit->getType()->getMaxEp() > 0) { healthbarthickness=healthbarthickness*2; - } - - if(unit->getType()->getMaxEp() > 0) { - renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,healthbarTexture,healthbarBackgroundTexture,unit->getEpRatio()); + renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,healthbarLineBorder,healthbarTexture,healthbarBackgroundTexture,unit->getEpRatio()); } else { - renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,healthbarTexture,healthbarBackgroundTexture); + renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,healthbarLineBorder,healthbarTexture,healthbarBackgroundTexture); } } } @@ -8298,7 +8311,7 @@ void Renderer::enableProjectiveTexturing() { } // ==================== private aux drawing ==================== -void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, const Texture2D *texture, const Texture2D *backgroundTexture , float ep) { +void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, bool lineBorder, const Texture2D *texture, const Texture2D *backgroundTexture , float ep) { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -8336,23 +8349,24 @@ void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, const green=brightness+(hp-0.5f)*brightness; } - //backgroundTexture - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, static_cast(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); - + if(backgroundTexture!=NULL) { + //backgroundTexture + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, static_cast(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); @@ -8379,31 +8393,35 @@ void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, const } glEnd(); - //border - glColor4f(red+0.1f,green+0.1f,0.1f,0.5f); - glBegin(GL_LINE_LOOP); - glVertex3fv((v - (rightVector*width - upVector*height)).ptr()); - glVertex3fv((v - (rightVector*width + upVector*height)).ptr()); - glVertex3fv((v + (rightVector*width - upVector*height)).ptr()); - glVertex3fv((v + (rightVector*width + upVector*height)).ptr()); - glEnd(); + if(lineBorder) { + //border + glColor4f(red+0.1f,green+0.1f,0.1f,0.5f); + glBegin(GL_LINE_LOOP); + glVertex3fv((v - (rightVector*width - upVector*height)).ptr()); + glVertex3fv((v - (rightVector*width + upVector*height)).ptr()); + glVertex3fv((v + (rightVector*width - upVector*height)).ptr()); + glVertex3fv((v + (rightVector*width + upVector*height)).ptr()); + glEnd(); + } - //BorderTexture - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, static_cast(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); + if(texture!=NULL) { + //BorderTexture + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, static_cast(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(); } diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 451ffc28..724e7375 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -549,7 +549,7 @@ public: void renderUnitsToBuild(const int renderFps); void renderSelectionEffects(); - void renderOnTopBars(bool forceHealthbars=false); + void renderHealthBars(bool forceHealthbars=false); void renderWaterEffects(); void renderHud(); void renderMinimap(); @@ -681,7 +681,7 @@ private: //private aux drawing void renderSelectionCircle(Vec3f v, int size, float radius, float thickness=0.2f); - void renderHealthBar(Vec3f v, int size, float hp, float height, const Texture2D *texture, const Texture2D *backgroundTexture , float ep=-1.0f); + void renderHealthBar(Vec3f v, int size, float hp, float height, bool lineBorder, const Texture2D *texture=NULL, const Texture2D *backgroundTexture=NULL , float ep=-1.0f); 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 renderTile(const Vec2i &pos); diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index 1c335ef7..2ce40783 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -16,6 +16,7 @@ #include "xml_parser.h" #include "tech_tree.h" #include "resource.h" +#include "renderer.h" #include "platform_util.h" #include "game_util.h" #include "conversion.h" @@ -37,6 +38,11 @@ FactionType::FactionType() { healthbarheight= -100.0f; healthbarthickness= 0.05f; healthbarVisible=hbvUndefined; + healthbarBorderTextureEnabled=false; + healthbarBackgroundTextureEnabled=false; + healthbarLineBorder=true; + healthbarTexture=NULL; + healthbarBackgroundTexture=NULL; } //load a faction, given a directory @@ -277,15 +283,15 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec //healthbar if(factionNode->hasChild("healthbar")) { - const XmlNode *HealthbarNode= factionNode->getChild("healthbar"); - if(HealthbarNode->hasChild("height")) { - healthbarheight= HealthbarNode->getChild("height")->getAttribute("value")->getFloatValue(); + const XmlNode *healthbarNode= factionNode->getChild("healthbar"); + if(healthbarNode->hasChild("height")) { + healthbarheight= healthbarNode->getChild("height")->getAttribute("value")->getFloatValue(); } - if(HealthbarNode->hasChild("thickness")) { - healthbarthickness= HealthbarNode->getChild("thickness")->getAttribute("value")->getFloatValue(0.f, 1.f); + if(healthbarNode->hasChild("thickness")) { + healthbarthickness= healthbarNode->getChild("thickness")->getAttribute("value")->getFloatValue(0.f, 1.f); } - if(HealthbarNode->hasChild("visible")) { - string healthbarVisibleString=HealthbarNode->getChild("visible")->getAttribute("value")->getValue(); + if(healthbarNode->hasChild("visible")) { + string healthbarVisibleString=healthbarNode->getChild("visible")->getAttribute("value")->getValue(); vector v=split(healthbarVisibleString,"|"); for (int i = 0; i < (int)v.size(); ++i) { string current=trim(v[i]); @@ -302,6 +308,30 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec } } } + if(healthbarNode->hasChild("borderTexture")) { + healthbarBorderTextureEnabled=healthbarNode->getChild("borderTexture")->getAttribute("enabled")->getBoolValue(); + if(healthbarBorderTextureEnabled && healthbarNode->getChild("borderTexture")->hasAttribute("path")) { + healthbarTexture= Renderer::getInstance().newTexture2D(rsGame); + if(healthbarTexture) { + healthbarTexture->load(healthbarNode->getChild("borderTexture")->getAttribute("path")->getRestrictedValue(currentPath)); + } + loadedFileList[healthbarNode->getChild("borderTexture")->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(path,healthbarNode->getChild("borderTexture")->getAttribute("path")->getRestrictedValue())); + } + } + if(healthbarNode->hasChild("backgroundTexture")) { + healthbarBackgroundTextureEnabled=healthbarNode->getChild("backgroundTexture")->getAttribute("enabled")->getBoolValue(); + if(healthbarBackgroundTextureEnabled && healthbarNode->getChild("backgroundTexture")->hasAttribute("path")) { + healthbarBackgroundTexture= Renderer::getInstance().newTexture2D(rsGame); + if(healthbarBackgroundTexture) { + healthbarBackgroundTexture->load(healthbarNode->getChild("backgroundTexture")->getAttribute("path")->getRestrictedValue(currentPath)); + } + loadedFileList[healthbarNode->getChild("backgroundTexture")->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(path,healthbarNode->getChild("backgroundTexture")->getAttribute("path")->getRestrictedValue())); + } + } + if(healthbarNode->hasChild("lineBorder")) { + healthbarLineBorder= healthbarNode->getChild("lineBorder")->getAttribute("enabled")->getBoolValue(); + } + } //read ai behavior diff --git a/source/glest_game/types/faction_type.h b/source/glest_game/types/faction_type.h index 909e9571..386df6bc 100644 --- a/source/glest_game/types/faction_type.h +++ b/source/glest_game/types/faction_type.h @@ -95,9 +95,15 @@ private: std::map mapAIBehaviorStaticOverrideValues; bool isLinked; + float healthbarheight; float healthbarthickness; int healthbarVisible; + bool healthbarBorderTextureEnabled; + bool healthbarBackgroundTextureEnabled; + bool healthbarLineBorder; + Texture2D *healthbarTexture; + Texture2D *healthbarBackgroundTexture; public: @@ -127,6 +133,11 @@ public: inline float getHealthbarHeight() const {return healthbarheight;} inline float getHealthbarThickness() const {return healthbarthickness;} inline int getHealthbarVisible() const {return healthbarVisible;} + inline bool isHealthbarBorderTextureEnabled() const {return healthbarBorderTextureEnabled;} + inline bool isHealthbarBackgroundTextureEnabled() const {return healthbarBackgroundTextureEnabled;} + inline bool isHealthbarLineBorder() const {return healthbarLineBorder;} + Texture2D *getHealthbarTexture() const {return healthbarTexture;} + Texture2D *getHealthbarBackgroundTexture() const {return healthbarBackgroundTexture;} const UnitType *getUnitType(const string &name) const; diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 74c3cab6..fd673b1d 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -451,15 +451,15 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, //healthbar if(parametersNode->hasChild("healthbar")) { - const XmlNode *HealthbarNode= parametersNode->getChild("healthbar"); - if(HealthbarNode->hasChild("height")) { - healthbarheight= HealthbarNode->getChild("height")->getAttribute("value")->getFloatValue(); + const XmlNode *healthbarNode= parametersNode->getChild("healthbar"); + if(healthbarNode->hasChild("height")) { + healthbarheight= healthbarNode->getChild("height")->getAttribute("value")->getFloatValue(); } - if(HealthbarNode->hasChild("thickness")) { - healthbarthickness= HealthbarNode->getChild("thickness")->getAttribute("value")->getFloatValue(0.f, 1.f); + if(healthbarNode->hasChild("thickness")) { + healthbarthickness= healthbarNode->getChild("thickness")->getAttribute("value")->getFloatValue(0.f, 1.f); } - if(HealthbarNode->hasChild("visible")) { - string healthbarVisibleString=HealthbarNode->getChild("visible")->getAttribute("value")->getValue(); + if(healthbarNode->hasChild("visible")) { + string healthbarVisibleString=healthbarNode->getChild("visible")->getAttribute("value")->getValue(); vector v=split(healthbarVisibleString,"|"); for (int i = 0; i < (int)v.size(); ++i) { string current=trim(v[i]); From 2f60d179e9d7ca3c3c228a7695fb3a351bb4520a Mon Sep 17 00:00:00 2001 From: titison Date: Thu, 6 Nov 2014 21:12:47 +0100 Subject: [PATCH 4/4] Healthbars * Hotkey now toggles between Default/Off/Always/Damaged/Selected * Code clean up --- source/glest_game/game/game.cpp | 33 ++++++++++++++++++++++--- source/glest_game/game/game.h | 2 +- source/glest_game/graphics/renderer.cpp | 17 +++++++++---- source/glest_game/graphics/renderer.h | 2 +- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 7daac218..8e57592d 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -115,7 +115,7 @@ Game::Game() : ProgramState(NULL) { renderFpsAvgTest=0; renderExtraTeamColor=0; photoModeEnabled=false; - forcedHealthbars=false; + healthbarMode=hbvUndefined; visibleHUD=false; timeDisplay=false; withRainEffect=false; @@ -236,7 +236,7 @@ void Game::resetMembers() { scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5"); photoModeEnabled = Config::getInstance().getBool("PhotoMode","false"); - forcedHealthbars = Config::getInstance().getBool("ForcedHealthbars","false"); + healthbarMode = Config::getInstance().getInt("HealthbarMode","0"); visibleHUD = Config::getInstance().getBool("VisibleHud","true"); timeDisplay = Config::getInstance().getBool("TimeDisplay","true"); withRainEffect = Config::getInstance().getBool("RainEffect","true"); @@ -4659,7 +4659,32 @@ void Game::keyDown(SDL_KeyboardEvent key) { } //Toggle Healthbars else if(isKeyPressed(configKeys.getSDLKey("ToggleHealthbars"),key, false) == true) { - forcedHealthbars = !forcedHealthbars; + switch (healthbarMode) { + case hbvUndefined: + healthbarMode=hbvOff; + console.addLine(lang.getString("HealthbarsOff")); + break; + case hbvOff: + healthbarMode=hbvAlways; + console.addLine(lang.getString("HealthbarsAlways")); + break; + case hbvAlways: + healthbarMode=hbvDamaged; + console.addLine(lang.getString("HealthbarsDamaged")); + break; + case hbvDamaged: + healthbarMode=hbvSelected; + console.addLine(lang.getString("HealthbarsSelected")); + break; + case hbvSelected: + healthbarMode=hbvUndefined; + console.addLine(lang.getString("HealthbarsDefault")); + break; + default: + printf("In [%s::%s Line: %d] Toggle Healthbars Hotkey - Invalid Value. Setting to default.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + healthbarMode=hbvUndefined; + break; + } } //Toggle music //else if(key == configKeys.getCharKey("ToggleMusic")) { @@ -5259,7 +5284,7 @@ void Game::render3d(){ //renderOnTopBars (aka Healthbars) if(photoModeEnabled == false) { - renderer.renderHealthBars(forcedHealthbars); + renderer.renderHealthBars(healthbarMode); } //particles diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index d4aae999..05f470fe 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -141,7 +141,7 @@ private: static const int renderTeamColorPlaneBit=2; bool photoModeEnabled; - bool forcedHealthbars; + int healthbarMode; bool visibleHUD; bool timeDisplay; bool withRainEffect; diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 60be150e..38f6e700 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5610,7 +5610,7 @@ void Renderer::renderSelectionEffects() { glPopAttrib(); } -void Renderer::renderHealthBars(bool forceHealthbars){ +void Renderer::renderHealthBars(int healthbarMode){ if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -5641,7 +5641,7 @@ void Renderer::renderHealthBars(bool forceHealthbars){ float healthbarheight; float healthbarthickness; - int healthbarVisible; + int healthbarVisible=hbvUndefined; const Texture2D *healthbarTexture; const Texture2D *healthbarBackgroundTexture; bool healthbarLineBorder; @@ -5649,7 +5649,12 @@ void Renderer::renderHealthBars(bool forceHealthbars){ //get settings of the faction healthbarheight=unit->getFaction()->getType()->getHealthbarHeight(); healthbarthickness=unit->getFaction()->getType()->getHealthbarThickness(); - healthbarVisible=unit->getFaction()->getType()->getHealthbarVisible(); + //check options (hotkey) + if(healthbarMode==hbvUndefined) { + healthbarVisible=unit->getFaction()->getType()->getHealthbarVisible(); + } else { + healthbarVisible=healthbarMode; + } healthbarLineBorder=unit->getFaction()->getType()->isHealthbarLineBorder(); CoreData &coreData= CoreData::getInstance(); //First try faction texture then use core Texture @@ -5678,7 +5683,9 @@ void Renderer::renderHealthBars(bool forceHealthbars){ if(unit->getType()->getHealthbarThickness()!=-1.0f) { healthbarthickness=unit->getType()->getHealthbarThickness(); } - healthbarVisible=unit->getType()->getHealthbarVisible(); + if(healthbarMode==hbvUndefined) { //don't override the visible setting when hotkey is not hbvUndefined + healthbarVisible=unit->getType()->getHealthbarVisible(); + } } bool settingsWantToRenderThem=!(healthbarVisible==hbvUndefined || (healthbarVisible&hbvOff)) @@ -5686,7 +5693,7 @@ void Renderer::renderHealthBars(bool forceHealthbars){ || ((healthbarVisible&hbvDamaged) && unit->getHp()!=unit->getType()->getMaxHp()) || ((healthbarVisible&hbvSelected) && game->getGui()->isSelected(unit))); - if(unit->isAlive() && (settingsWantToRenderThem || forceHealthbars)) { + if(unit->isAlive() && (settingsWantToRenderThem)) { Vec3f currVec= unit->getCurrVectorFlat(); if(healthbarheight==-100.0f) { currVec.y+=unit->getType()->getHeight(); diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 724e7375..75a9e010 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -549,7 +549,7 @@ public: void renderUnitsToBuild(const int renderFps); void renderSelectionEffects(); - void renderHealthBars(bool forceHealthbars=false); + void renderHealthBars(int forceHealthbars=hbvUndefined); void renderWaterEffects(); void renderHud(); void renderMinimap();