clickable resources with display ; softcoder please look at unit_updater.cpp line 1032

This commit is contained in:
Titus Tscharntke 2011-02-13 21:04:30 +00:00
parent 62a2b7cc94
commit a214fa87f5
5 changed files with 121 additions and 84 deletions

View File

@ -2550,6 +2550,7 @@ void Renderer::renderSelectionEffects() {
const World *world= game->getWorld();
const Map *map= world->getMap();
const Selection *selection= game->getGui()->getSelection();
const Object *selectedResourceObject= game->getGui()->getSelectedResourceObject();
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
@ -2620,7 +2621,14 @@ void Renderer::renderSelectionEffects() {
renderSelectionCircle(currVec, unit->getType()->getSize(), magicCircleRadius);
}
}
if(selectedResourceObject!=NULL)
{
Resource *r= selectedResourceObject->getResource();
int defaultValue= r->getType()->getDefResPerPatch();
float colorValue=static_cast<float>(r->getAmount())/static_cast<float>(defaultValue);
glColor4f(0.1f, 0.1f , colorValue, 0.4f);
renderSelectionCircle(selectedResourceObject->getPos(),2, selectionCircleRadius);
}
//target arrow
if(selection->getCount() == 1) {
const Unit *unit= selection->getUnit(0);

View File

@ -108,6 +108,7 @@ Gui::Gui(){
lastQuadCalcFrame=0;
selectionCalculationFrameSkip=10;
minQuadSize=20;
selectedResourceObject=NULL;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
}
@ -693,111 +694,120 @@ void Gui::computeInfoString(int posDisplay){
}
}
void Gui::computeDisplay() {
void Gui::computeDisplay(){
//printf("Start ===> computeDisplay()\n");
Lang &lang= Lang::getInstance();
//init
display.clear();
// ================ PART 1 ================
// ================ PART 1 ================
//title, text and progress bar
if(selection.getCount()==1){
display.setTitle(selection.getFrontUnit()->getFullName());
display.setText(selection.getFrontUnit()->getDesc());
display.setProgressBar(selection.getFrontUnit()->getProductionPercent());
}
//portraits
for(int i=0; i<selection.getCount(); ++i){
display.setUpImage(i, selection.getUnit(i)->getType()->getImage());
if(selection.isEmpty() && selectedResourceObject!=NULL){
Resource *r = selectedResourceObject->getResource();
display.setTitle(r->getType()->getName());
display.setText(lang.get("Amount")+ ": "+intToStr(r->getAmount())+" / "+intToStr(r->getType()->getDefResPerPatch()));
//display.setProgressBar(r->);
display.setUpImage(0, r->getType()->getImage());
}
else{
//title, text and progress bar
if(selection.getCount() == 1){
display.setTitle(selection.getFrontUnit()->getFullName());
display.setText(selection.getFrontUnit()->getDesc());
display.setProgressBar(selection.getFrontUnit()->getProductionPercent());
}
// ================ PART 2 ================
//portraits
for(int i= 0; i < selection.getCount(); ++i){
display.setUpImage(i, selection.getUnit(i)->getType()->getImage());
}
if(selectingPos || selectingMeetingPoint) {
//printf("selectingPos || selectingMeetingPoint\n");
display.setDownSelectedPos(activePos);
}
// ================ PART 2 ================
if(selection.isCommandable()) {
//printf("selection.isComandable()\n");
if(selectingPos || selectingMeetingPoint){
//printf("selectingPos || selectingMeetingPoint\n");
display.setDownSelectedPos(activePos);
}
if(selectingBuilding == false) {
if(selection.isCommandable()){
//printf("selection.isComandable()\n");
//cancel button
const Unit *u= selection.getFrontUnit();
const UnitType *ut= u->getType();
if(selection.isCancelable()) {
//printf("selection.isCancelable() commandcount = %d\n",selection.getUnit(0)->getCommandSize());
if(selection.getUnit(0)->getCommandSize() > 0) {
//printf("Current Command [%s]\n",selection.getUnit(0)->getCurrCommand()->toString().c_str());
if(selectingBuilding == false){
//cancel button
const Unit *u= selection.getFrontUnit();
const UnitType *ut= u->getType();
if(selection.isCancelable()){
//printf("selection.isCancelable() commandcount = %d\n",selection.getUnit(0)->getCommandSize());
if(selection.getUnit(0)->getCommandSize() > 0){
//printf("Current Command [%s]\n",selection.getUnit(0)->getCurrCommand()->toString().c_str());
}
display.setDownImage(cancelPos, ut->getCancelImage());
display.setDownLighted(cancelPos, true);
}
display.setDownImage(cancelPos, ut->getCancelImage());
display.setDownLighted(cancelPos, true);
}
//meeting point
if(selection.isMeetable()){
//printf("selection.isMeetable()\n");
//meeting point
if(selection.isMeetable()) {
//printf("selection.isMeetable()\n");
display.setDownImage(meetingPointPos, ut->getMeetingPointImage());
display.setDownLighted(meetingPointPos, true);
}
display.setDownImage(meetingPointPos, ut->getMeetingPointImage());
display.setDownLighted(meetingPointPos, true);
}
if(selection.isUniform()){
//printf("selection.isUniform()\n");
if(selection.isUniform()) {
//printf("selection.isUniform()\n");
//uniform selection
if(u->isBuilt()){
//printf("u->isBuilt()\n");
//uniform selection
if(u->isBuilt()) {
//printf("u->isBuilt()\n");
int morphPos= 8;
for(int i=0; i<ut->getCommandTypeCount(); ++i) {
int displayPos= i;
const CommandType *ct= ut->getCommandType(i);
if(ct->getClass()==ccMorph) {
displayPos= morphPos++;
int morphPos= 8;
for(int i= 0; i < ut->getCommandTypeCount(); ++i){
int displayPos= i;
const CommandType *ct= ut->getCommandType(i);
if(ct->getClass() == ccMorph){
displayPos= morphPos++;
}
display.setDownImage(displayPos, ct->getImage());
display.setCommandType(displayPos, ct);
display.setDownLighted(displayPos, u->getFaction()->reqsOk(ct));
}
}
}
else{
//printf("selection.isUniform() == FALSE\n");
//non uniform selection
int lastCommand= 0;
for(int i= 0; i < ccCount; ++i){
CommandClass cc= static_cast<CommandClass> (i);
if(isSharedCommandClass(cc) && cc != ccBuild){
display.setDownLighted(lastCommand, true);
display.setDownImage(lastCommand, ut->getFirstCtOfClass(cc)->getImage());
display.setCommandClass(lastCommand, cc);
lastCommand++;
}
display.setDownImage(displayPos, ct->getImage());
display.setCommandType(displayPos, ct);
display.setDownLighted(displayPos, u->getFaction()->reqsOk(ct));
}
}
}
else {
//printf("selection.isUniform() == FALSE\n");
else{
//non uniform selection
int lastCommand= 0;
for(int i=0; i<ccCount; ++i) {
CommandClass cc= static_cast<CommandClass>(i);
if(isSharedCommandClass(cc) && cc!=ccBuild) {
display.setDownLighted(lastCommand, true);
display.setDownImage(lastCommand, ut->getFirstCtOfClass(cc)->getImage());
display.setCommandClass(lastCommand, cc);
lastCommand++;
//selecting building
const Unit *unit= selection.getFrontUnit();
if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild){
const BuildCommandType* bct= static_cast<const BuildCommandType*> (activeCommandType);
for(int i= 0; i < bct->getBuildingCount(); ++i){
display.setDownImage(i, bct->getBuilding(i)->getImage());
display.setDownLighted(i, unit->getFaction()->reqsOk(bct->getBuilding(i)));
}
display.setDownImage(cancelPos, selection.getFrontUnit()->getType()->getCancelImage());
display.setDownLighted(cancelPos, true);
}
}
}
else {
//selecting building
const Unit *unit= selection.getFrontUnit();
if(activeCommandType!=NULL && activeCommandType->getClass()==ccBuild){
const BuildCommandType* bct= static_cast<const BuildCommandType*>(activeCommandType);
for(int i=0; i<bct->getBuildingCount(); ++i){
display.setDownImage(i, bct->getBuilding(i)->getImage());
display.setDownLighted(i, unit->getFaction()->reqsOk(bct->getBuilding(i)));
}
display.setDownImage(cancelPos, selection.getFrontUnit()->getType()->getCancelImage());
display.setDownLighted(cancelPos, true);
}
}
}
}
}
int Gui::computePosDisplay(int x, int y){
@ -907,12 +917,12 @@ void Gui::computeSelected(bool doubleClick, bool force){
if( force || ( lastQuadCalcFrame+selectionCalculationFrameSkip < game->getTotalRenderFps() ) ){
lastQuadCalcFrame=game->getTotalRenderFps();
const Object* obj=NULL;
selectedResourceObject=NULL;
if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())<minQuadSize){
Renderer::getInstance().computeSelected(units, obj, false, selectionQuad.getPosDown(), selectionQuad.getPosDown());
Renderer::getInstance().computeSelected(units, selectedResourceObject, true, selectionQuad.getPosDown(), selectionQuad.getPosDown());
}
else{
Renderer::getInstance().computeSelected(units, obj, false, selectionQuad.getPosDown(), selectionQuad.getPosUp());
Renderer::getInstance().computeSelected(units, selectedResourceObject, true, selectionQuad.getPosDown(), selectionQuad.getPosUp());
}
selectingBuilding= false;
activeCommandType= NULL;
@ -942,6 +952,9 @@ void Gui::computeSelected(bool doubleClick, bool force){
if(!controlDown){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.select(units)\n",__FILE__,__FUNCTION__,__LINE__);
selection.select(units);
if(!selection.isEmpty()){
selectedResourceObject=NULL;
}
}
else{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] selection.unSelect(units)\n",__FILE__,__FUNCTION__,__LINE__);
@ -980,4 +993,10 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
}
}
void Gui::removeObject(Object* o){
if(getSelectedResourceObject()==o){
selectedResourceObject=NULL;
}
}
}}//end namespace

View File

@ -20,6 +20,7 @@
#include "selection.h"
#include "randomgen.h"
#include <map>
#include "object.h"
#include "leak_dumper.h"
using Shared::Util::RandomGen;
@ -135,6 +136,7 @@ private:
bool selectingMeetingPoint;
CardinalDir selectedBuildingFacing;
const Object *selectedResourceObject;
public:
Gui();
@ -148,6 +150,9 @@ public:
const Mouse3d *getMouse3d() const {return &mouse3d;}
const Display *getDisplay() const {return &display;}
const Selection *getSelection() const {return &selection;}
const Object *getSelectedResourceObject() const {return selectedResourceObject;}
void removeObject(Object* o) ;
const SelectionQuad *getSelectionQuad() const {return &selectionQuad;}
CardinalDir getSelectedFacing() const {return selectedBuildingFacing;}
bool isSelected(const Unit *unit) const {return selection.hasUnit(unit);}

View File

@ -47,10 +47,10 @@ Object::Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos) {
}
Object::~Object(){
delete resource;
Renderer &renderer= Renderer::getInstance();
renderer.removeObjectFromQuadCache(this);
//renderer.getGame()->getGui()->removeObject(this);
delete resource;
}
Model *Object::getModelPtr() const {

View File

@ -1028,6 +1028,11 @@ void UnitUpdater::updateHarvest(Unit *unit) {
//if resource exausted, then delete it and stop
if (r->decAmount(1)) {
const ResourceType *rt = r->getType();
//TODO:
// the following line should be done in Object::~Object(), but I don't know how (titi)!
this->game->getGui()->removeObject(sc->getObject());
sc->deleteResource();
unit->getFaction()->removeResourceTargetFromCache(unitTargetPos);