Healthbars
Textures (border and background) Faction.xml can specify more healthbars details
This commit is contained in:
parent
d1597334bf
commit
791e1edec6
|
@ -5259,7 +5259,7 @@ void Game::render3d(){
|
||||||
|
|
||||||
//renderOnTopBars (aka Healthbars)
|
//renderOnTopBars (aka Healthbars)
|
||||||
if(photoModeEnabled == false) {
|
if(photoModeEnabled == false) {
|
||||||
renderer.renderOnTopBars(forcedHealthbars);
|
renderer.renderHealthBars(forcedHealthbars);
|
||||||
}
|
}
|
||||||
|
|
||||||
//particles
|
//particles
|
||||||
|
|
|
@ -5610,7 +5610,7 @@ void Renderer::renderSelectionEffects() {
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderOnTopBars(bool forceHealthbars){
|
void Renderer::renderHealthBars(bool forceHealthbars){
|
||||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5644,15 +5644,31 @@ void Renderer::renderOnTopBars(bool forceHealthbars){
|
||||||
int healthbarVisible;
|
int healthbarVisible;
|
||||||
const Texture2D *healthbarTexture;
|
const Texture2D *healthbarTexture;
|
||||||
const Texture2D *healthbarBackgroundTexture;
|
const Texture2D *healthbarBackgroundTexture;
|
||||||
|
bool healthbarLineBorder;
|
||||||
|
|
||||||
//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();
|
||||||
|
healthbarLineBorder=unit->getFaction()->getType()->isHealthbarLineBorder();
|
||||||
CoreData &coreData= CoreData::getInstance();
|
CoreData &coreData= CoreData::getInstance();
|
||||||
healthbarTexture=coreData.getHealthbarTexture();
|
//First try faction texture then use core Texture
|
||||||
healthbarBackgroundTexture=coreData.getHealthbarBackgroundTexture();
|
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
|
//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) {
|
||||||
|
@ -5680,12 +5696,9 @@ void Renderer::renderOnTopBars(bool forceHealthbars){
|
||||||
|
|
||||||
if(unit->getType()->getMaxEp() > 0) {
|
if(unit->getType()->getMaxEp() > 0) {
|
||||||
healthbarthickness=healthbarthickness*2;
|
healthbarthickness=healthbarthickness*2;
|
||||||
}
|
renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,healthbarLineBorder,healthbarTexture,healthbarBackgroundTexture,unit->getEpRatio());
|
||||||
|
|
||||||
if(unit->getType()->getMaxEp() > 0) {
|
|
||||||
renderHealthBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),healthbarthickness,healthbarTexture,healthbarBackgroundTexture,unit->getEpRatio());
|
|
||||||
} else {
|
} 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 ====================
|
// ==================== 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) {
|
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -8336,23 +8349,24 @@ void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, const
|
||||||
green=brightness+(hp-0.5f)*brightness;
|
green=brightness+(hp-0.5f)*brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
//backgroundTexture
|
if(backgroundTexture!=NULL) {
|
||||||
glEnable(GL_TEXTURE_2D);
|
//backgroundTexture
|
||||||
glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(backgroundTexture)->getHandle());
|
glEnable(GL_TEXTURE_2D);
|
||||||
glColor4f(1.f,1.f,1.f,1.f);
|
glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(backgroundTexture)->getHandle());
|
||||||
//glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
|
glColor4f(1.f,1.f,1.f,1.f);
|
||||||
glBegin(GL_QUADS);
|
//glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
|
||||||
glTexCoord2i(0,1);
|
glBegin(GL_QUADS);
|
||||||
glVertex3fv((v - (rightVectorTexture*width - upVectorTexture*height)).ptr());
|
glTexCoord2i(0,1);
|
||||||
glTexCoord2i(0,0);
|
glVertex3fv((v - (rightVectorTexture*width - upVectorTexture*height)).ptr());
|
||||||
glVertex3fv((v - (rightVectorTexture*width + upVectorTexture*height)).ptr());
|
glTexCoord2i(0,0);
|
||||||
glTexCoord2i(1,0);
|
glVertex3fv((v - (rightVectorTexture*width + upVectorTexture*height)).ptr());
|
||||||
glVertex3fv((v + (rightVectorTexture*width - upVectorTexture*height)).ptr());
|
glTexCoord2i(1,0);
|
||||||
glTexCoord2i(1,1);
|
glVertex3fv((v + (rightVectorTexture*width - upVectorTexture*height)).ptr());
|
||||||
glVertex3fv((v + (rightVectorTexture*width + upVectorTexture*height)).ptr());
|
glTexCoord2i(1,1);
|
||||||
glEnd();
|
glVertex3fv((v + (rightVectorTexture*width + upVectorTexture*height)).ptr());
|
||||||
glDisable(GL_TEXTURE_2D);
|
glEnd();
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
//healthbar
|
//healthbar
|
||||||
glColor4f(red,green,0.0f,0.4f);
|
glColor4f(red,green,0.0f,0.4f);
|
||||||
|
@ -8379,31 +8393,35 @@ void Renderer::renderHealthBar(Vec3f v, int size, float hp, float height, const
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
//border
|
if(lineBorder) {
|
||||||
glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
|
//border
|
||||||
glBegin(GL_LINE_LOOP);
|
glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
|
||||||
glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
|
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());
|
||||||
glVertex3fv((v + (rightVector*width + upVector*height)).ptr());
|
glVertex3fv((v + (rightVector*width - upVector*height)).ptr());
|
||||||
glEnd();
|
glVertex3fv((v + (rightVector*width + upVector*height)).ptr());
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
//BorderTexture
|
if(texture!=NULL) {
|
||||||
glEnable(GL_TEXTURE_2D);
|
//BorderTexture
|
||||||
glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(texture)->getHandle());
|
glEnable(GL_TEXTURE_2D);
|
||||||
glColor4f(1.f,1.f,1.f,1.f);
|
glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(texture)->getHandle());
|
||||||
//glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
|
glColor4f(1.f,1.f,1.f,1.f);
|
||||||
glBegin(GL_QUADS);
|
//glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
|
||||||
glTexCoord2i(0,1);
|
glBegin(GL_QUADS);
|
||||||
glVertex3fv((v - (rightVectorTexture*width - upVectorTexture*height)).ptr());
|
glTexCoord2i(0,1);
|
||||||
glTexCoord2i(0,0);
|
glVertex3fv((v - (rightVectorTexture*width - upVectorTexture*height)).ptr());
|
||||||
glVertex3fv((v - (rightVectorTexture*width + upVectorTexture*height)).ptr());
|
glTexCoord2i(0,0);
|
||||||
glTexCoord2i(1,0);
|
glVertex3fv((v - (rightVectorTexture*width + upVectorTexture*height)).ptr());
|
||||||
glVertex3fv((v + (rightVectorTexture*width - upVectorTexture*height)).ptr());
|
glTexCoord2i(1,0);
|
||||||
glTexCoord2i(1,1);
|
glVertex3fv((v + (rightVectorTexture*width - upVectorTexture*height)).ptr());
|
||||||
glVertex3fv((v + (rightVectorTexture*width + upVectorTexture*height)).ptr());
|
glTexCoord2i(1,1);
|
||||||
glEnd();
|
glVertex3fv((v + (rightVectorTexture*width + upVectorTexture*height)).ptr());
|
||||||
glDisable(GL_TEXTURE_2D);
|
glEnd();
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
|
@ -549,7 +549,7 @@ public:
|
||||||
void renderUnitsToBuild(const int renderFps);
|
void renderUnitsToBuild(const int renderFps);
|
||||||
|
|
||||||
void renderSelectionEffects();
|
void renderSelectionEffects();
|
||||||
void renderOnTopBars(bool forceHealthbars=false);
|
void renderHealthBars(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, 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 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);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "xml_parser.h"
|
#include "xml_parser.h"
|
||||||
#include "tech_tree.h"
|
#include "tech_tree.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
#include "renderer.h"
|
||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
#include "game_util.h"
|
#include "game_util.h"
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
|
@ -37,6 +38,11 @@ FactionType::FactionType() {
|
||||||
healthbarheight= -100.0f;
|
healthbarheight= -100.0f;
|
||||||
healthbarthickness= 0.05f;
|
healthbarthickness= 0.05f;
|
||||||
healthbarVisible=hbvUndefined;
|
healthbarVisible=hbvUndefined;
|
||||||
|
healthbarBorderTextureEnabled=false;
|
||||||
|
healthbarBackgroundTextureEnabled=false;
|
||||||
|
healthbarLineBorder=true;
|
||||||
|
healthbarTexture=NULL;
|
||||||
|
healthbarBackgroundTexture=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//load a faction, given a directory
|
//load a faction, given a directory
|
||||||
|
@ -277,15 +283,15 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec
|
||||||
|
|
||||||
//healthbar
|
//healthbar
|
||||||
if(factionNode->hasChild("healthbar")) {
|
if(factionNode->hasChild("healthbar")) {
|
||||||
const XmlNode *HealthbarNode= factionNode->getChild("healthbar");
|
const XmlNode *healthbarNode= factionNode->getChild("healthbar");
|
||||||
if(HealthbarNode->hasChild("height")) {
|
if(healthbarNode->hasChild("height")) {
|
||||||
healthbarheight= HealthbarNode->getChild("height")->getAttribute("value")->getFloatValue();
|
healthbarheight= healthbarNode->getChild("height")->getAttribute("value")->getFloatValue();
|
||||||
}
|
}
|
||||||
if(HealthbarNode->hasChild("thickness")) {
|
if(healthbarNode->hasChild("thickness")) {
|
||||||
healthbarthickness= HealthbarNode->getChild("thickness")->getAttribute("value")->getFloatValue(0.f, 1.f);
|
healthbarthickness= healthbarNode->getChild("thickness")->getAttribute("value")->getFloatValue(0.f, 1.f);
|
||||||
}
|
}
|
||||||
if(HealthbarNode->hasChild("visible")) {
|
if(healthbarNode->hasChild("visible")) {
|
||||||
string healthbarVisibleString=HealthbarNode->getChild("visible")->getAttribute("value")->getValue();
|
string healthbarVisibleString=healthbarNode->getChild("visible")->getAttribute("value")->getValue();
|
||||||
vector<string> v=split(healthbarVisibleString,"|");
|
vector<string> v=split(healthbarVisibleString,"|");
|
||||||
for (int i = 0; i < (int)v.size(); ++i) {
|
for (int i = 0; i < (int)v.size(); ++i) {
|
||||||
string current=trim(v[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
|
//read ai behavior
|
||||||
|
|
|
@ -95,9 +95,15 @@ private:
|
||||||
std::map<AIBehaviorStaticValueCategory, int > mapAIBehaviorStaticOverrideValues;
|
std::map<AIBehaviorStaticValueCategory, int > mapAIBehaviorStaticOverrideValues;
|
||||||
|
|
||||||
bool isLinked;
|
bool isLinked;
|
||||||
|
|
||||||
float healthbarheight;
|
float healthbarheight;
|
||||||
float healthbarthickness;
|
float healthbarthickness;
|
||||||
int healthbarVisible;
|
int healthbarVisible;
|
||||||
|
bool healthbarBorderTextureEnabled;
|
||||||
|
bool healthbarBackgroundTextureEnabled;
|
||||||
|
bool healthbarLineBorder;
|
||||||
|
Texture2D *healthbarTexture;
|
||||||
|
Texture2D *healthbarBackgroundTexture;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -127,6 +133,11 @@ public:
|
||||||
inline float getHealthbarHeight() const {return healthbarheight;}
|
inline float getHealthbarHeight() const {return healthbarheight;}
|
||||||
inline float getHealthbarThickness() const {return healthbarthickness;}
|
inline float getHealthbarThickness() const {return healthbarthickness;}
|
||||||
inline int getHealthbarVisible() const {return healthbarVisible;}
|
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;
|
const UnitType *getUnitType(const string &name) const;
|
||||||
|
|
|
@ -451,15 +451,15 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
|
||||||
|
|
||||||
//healthbar
|
//healthbar
|
||||||
if(parametersNode->hasChild("healthbar")) {
|
if(parametersNode->hasChild("healthbar")) {
|
||||||
const XmlNode *HealthbarNode= parametersNode->getChild("healthbar");
|
const XmlNode *healthbarNode= parametersNode->getChild("healthbar");
|
||||||
if(HealthbarNode->hasChild("height")) {
|
if(healthbarNode->hasChild("height")) {
|
||||||
healthbarheight= HealthbarNode->getChild("height")->getAttribute("value")->getFloatValue();
|
healthbarheight= healthbarNode->getChild("height")->getAttribute("value")->getFloatValue();
|
||||||
}
|
}
|
||||||
if(HealthbarNode->hasChild("thickness")) {
|
if(healthbarNode->hasChild("thickness")) {
|
||||||
healthbarthickness= HealthbarNode->getChild("thickness")->getAttribute("value")->getFloatValue(0.f, 1.f);
|
healthbarthickness= healthbarNode->getChild("thickness")->getAttribute("value")->getFloatValue(0.f, 1.f);
|
||||||
}
|
}
|
||||||
if(HealthbarNode->hasChild("visible")) {
|
if(healthbarNode->hasChild("visible")) {
|
||||||
string healthbarVisibleString=HealthbarNode->getChild("visible")->getAttribute("value")->getValue();
|
string healthbarVisibleString=healthbarNode->getChild("visible")->getAttribute("value")->getValue();
|
||||||
vector<string> v=split(healthbarVisibleString,"|");
|
vector<string> v=split(healthbarVisibleString,"|");
|
||||||
for (int i = 0; i < (int)v.size(); ++i) {
|
for (int i = 0; i < (int)v.size(); ++i) {
|
||||||
string current=trim(v[i]);
|
string current=trim(v[i]);
|
||||||
|
|
Loading…
Reference in New Issue