initial attempt to add a visual food low warning (consumable falls to 25% and balance is ticking down)

This commit is contained in:
Mark Vejvoda
2011-10-18 15:41:37 +00:00
parent 9d1617e045
commit e5c5e22c26
2 changed files with 44 additions and 19 deletions

View File

@@ -1583,43 +1583,62 @@ void Renderer::renderResourceStatus() {
const Metrics &metrics= Metrics::getInstance(); const Metrics &metrics= Metrics::getInstance();
const World *world= game->getWorld(); const World *world= game->getWorld();
const Faction *thisFaction= world->getFaction(world->getThisFactionIndex()); const Faction *thisFaction= world->getFaction(world->getThisFactionIndex());
const Vec4f fontColor=game->getGui()->getDisplay()->getColor(); const Vec4f fontColor = game->getGui()->getDisplay()->getColor();
assertGl(); assertGl();
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
int j= 0; int j= 0;
for(int i= 0; i<world->getTechTree()->getResourceTypeCount(); ++i){ for(int i= 0; i < world->getTechTree()->getResourceTypeCount(); ++i) {
const ResourceType *rt= world->getTechTree()->getResourceType(i); const ResourceType *rt = world->getTechTree()->getResourceType(i);
const Resource *r= thisFaction->getResource(rt); const Resource *r = thisFaction->getResource(rt);
//if any unit produces the resource //if any unit produces the resource
bool showResource= false; bool showResource= false;
for(int k=0; k<thisFaction->getType()->getUnitTypeCount(); ++k){ for(int k=0; k < thisFaction->getType()->getUnitTypeCount(); ++k) {
const UnitType *ut= thisFaction->getType()->getUnitType(k); const UnitType *ut = thisFaction->getType()->getUnitType(k);
if(ut->getCost(rt)!=NULL){ if(ut->getCost(rt) != NULL) {
showResource= true; showResource = true;
break; break;
} }
} }
//draw resource status //draw resource status
if(showResource){ if(showResource) {
string str= intToStr(r->getAmount()); string str= intToStr(r->getAmount());
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glColor3f(1.f, 1.f, 1.f);
Vec4f resourceFontColor = fontColor;
bool isNegativeConsumableDisplayCycle = false;
if(rt->getClass() == rcConsumable) {
// Show in red font if negative
const double minWarnPercent = 25.0;
//if(r->getBalance() < 0) {
if(r->getBalance() < 0 &&
((thisFaction->getStoreAmount(rt) > 0 && (double)r->getAmount() / (double)thisFaction->getStoreAmount(rt) * 100.0 <= minWarnPercent) ||
(thisFaction->getStoreAmount(rt) <= 0 && (double)r->getAmount() <= minWarnPercent))) {
if(time(NULL) % 2 == 0) {
isNegativeConsumableDisplayCycle = true;
glColor3f(RED.x,RED.y,RED.z);
resourceFontColor = RED;
}
//printf("Balance is negative!");
}
}
if(isNegativeConsumableDisplayCycle == false) {
glColor3f(1.f, 1.f, 1.f);
}
renderQuad(j*100+200, metrics.getVirtualH()-30, 16, 16, rt->getImage()); renderQuad(j*100+200, metrics.getVirtualH()-30, 16, 16, rt->getImage());
if(rt->getClass() != rcStatic) if(rt->getClass() != rcStatic) {
{
str+= "/" + intToStr(thisFaction->getStoreAmount(rt)); str+= "/" + intToStr(thisFaction->getStoreAmount(rt));
} }
if(rt->getClass()==rcConsumable){ if(rt->getClass() == rcConsumable) {
str+= "("; str+= "(";
if(r->getBalance()>0){ if(r->getBalance() > 0) {
str+= "+"; str+= "+";
} }
str+= intToStr(r->getBalance()) + ")"; str+= intToStr(r->getBalance()) + ")";
@@ -1630,18 +1649,17 @@ void Renderer::renderResourceStatus() {
if(renderText3DEnabled == true) { if(renderText3DEnabled == true) {
renderTextShadow3D( renderTextShadow3D(
str, CoreData::getInstance().getDisplayFontSmall3D(), str, CoreData::getInstance().getDisplayFontSmall3D(),
fontColor, resourceFontColor,
j*100+220, metrics.getVirtualH()-30, false); j*100+220, metrics.getVirtualH()-30, false);
} }
else { else {
renderTextShadow( renderTextShadow(
str, CoreData::getInstance().getDisplayFontSmall(), str, CoreData::getInstance().getDisplayFontSmall(),
fontColor, resourceFontColor,
j*100+220, metrics.getVirtualH()-30, false); j*100+220, metrics.getVirtualH()-30, false);
} }
++j; ++j;
} }
} }
glPopAttrib(); glPopAttrib();

View File

@@ -404,9 +404,16 @@ public:
T z; T z;
T w; T w;
public: public:
Vec4(){ Vec4() {
}; };
explicit Vec4(const T *p){
this->x= p[0];
this->y= p[1];
this->z= p[2];
this->w= p[3];
}
explicit Vec4(T *p){ explicit Vec4(T *p){
this->x= p[0]; this->x= p[0];
this->y= p[1]; this->y= p[1];