Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10685 in orxonox.OLD for branches/hud/src/util/hud.cc


Ignore:
Timestamp:
Jun 11, 2007, 4:40:33 PM (17 years ago)
Author:
bknecht
Message:

My computer is not working anymore, so I upload my unfinished work to continue my work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/hud/src/util/hud.cc

    r10516 r10685  
    1111   ### File Specific:
    1212   main-programmer: Benjamin Grauer
    13    co-programmer: ...
     13   co-programmer: Benjamin Knecht
    1414*/
    1515
     
    5252  this->energyWidget = NULL;
    5353  this->shieldWidget = NULL;
    54   this->armorWidget = NULL;
     54  this->healthWidget = NULL;
    5555  //this->leftRect = NULL;
    5656  //this->rightRect = NULL;
     
    6060  this->overlayPercentage = 40;
    6161  this->overlayActive = false;
    62   this->rightRect = new OrxGui::GLGuiImage();
    63   this->leftRect = new OrxGui::GLGuiImage();
    64 
    65   this->inputLine = new OrxGui::GLGuiInputLine();
    66   this->inputLine->setParent2D(this);
     62  //this->rightRect = new OrxGui::GLGuiImage();
     63  //this->leftRect = new OrxGui::GLGuiImage();
     64  this->topRect = new OrxGui::GLGuiImage();
     65  this->bottomRect = new OrxGui::GLGuiImage();
     66  this->middleRect = new OrxGui::GLGuiImage();
     67
     68  //this->inputLine = new OrxGui::GLGuiInputLine();
     69  //this->inputLine->setParent2D(this);
    6770  this->notifier = new OrxGui::GLGuiNotifier();
    68   this->notifier->setParent2D(this);
    69   notifier->setAbsCoor2D(100,100);
     71  this->notifier->setParent2D(this->bottomRect);
     72  notifier->setRelCoor2D(5,5);
     73 
     74  this->barSocket = new OrxGui::GLGuiImage();
     75  this->barSocket->setParent2D(this->bottomRect);
    7076
    7177  this->_radar = new OrxGui::GLGuiRadar();
     
    9096  delete this->rightRect;
    9197  delete this->leftRect;
     98  delete this->topRect;
     99  delete this->bottomRect;
     100  delete this->middleRect;
    92101  //if (this->shipValuesBox != NULL)
    93102    //delete this->shipValuesBox;
     
    135144  }
    136145
    137   this->updateResolution();
    138 }
    139 
    140 void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget)
     146  this->updateResolution(); 
     147}
     148
     149void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget)
    141150{
    142151  /*
     
    169178}
    170179
    171 void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget)
    172 {
    173   /*
    174   if (this->shipValuesBox == NULL)
    175     this->createShipValuesBox();
    176   */
    177 
    178 // decopple old widget
    179   if (this->armorWidget != NULL)
    180   {
    181     this->armorWidget->hide();
    182   }
    183 
    184   this->armorWidget = widget;
    185   if (this->armorWidget != NULL)
    186   {
    187     //this->armorWidget->shiftDir2D(270);
    188     //this->shipValuesBox->pack(this->armorWidget);
    189     //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->armorWidget)->setStandardSettings();
    190     this->armorWidget->setParent2D(this->leftRect);
    191     dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->armorWidget)->setDisplayedImage("textures/gui/gui_health_icon.png");
    192     this->armorWidget->show();
    193     /*    this->armorWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
    194         this->armorWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
     180void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget)
     181{
     182        if( this->playmode == FirstPerson )
     183        {
     184                this->healthWidget = new OrxGui::GLGuiBar();
     185                this->healthWidget->setMaximum(widget->getBarWidget()->maximum());
     186        this->healthWidget->setValue(widget->getBarWidget()->value());
     187        this->healthWidget->setParent2D(this->barSocket);
     188        }
     189        else
     190        {
     191          /*
     192          if (this->shipValuesBox == NULL)
     193            this->createShipValuesBox();
     194          */
     195       
     196        // decopple old widget
     197          if (this->healthWidget != NULL)
     198          {
     199            this->healthWidget->hide();
     200          }
     201       
     202          this->healthWidget = widget;
     203          if (this->healthWidget != NULL)
     204          {
     205            //this->healthWidget->shiftDir2D(270);
     206            //this->shipValuesBox->pack(this->healthWidget);
     207            //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setStandardSettings();
     208            this->healthWidget->setParent2D(this->leftRect);
     209            //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setDisplayedImage("textures/gui/gui_health_icon.png");
     210            this->healthWidget->show();
     211            /*    this->healthWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
     212                this->healthWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
     213          }
     214        }
     215
     216  this->updateResolution();
     217}
     218
     219
     220void Hud::setImplantWidget(OrxGui::GLGuiWidget* widget)
     221{
     222  //if (this->shipValuesBox == NULL)
     223    //this->createShipValuesBox();
     224
     225  // decopple old widget
     226  if (this->implantWidget != NULL)
     227  {
     228    this->implantWidget->hide();
     229  }
     230
     231  this->implantWidget = widget;
     232  if (this->implantWidget != NULL)
     233  {
     234    //this->energyWidget->shiftDir2D(270);
     235    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics");
     236    //this->shipValuesBox->pack(this->energyWidget);
     237    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings();
     238    this->implantWidget->setParent2D(this->leftRect);
     239    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->implantWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png");
     240    this->implantWidget->show();
     241    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
     242        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
    195243  }
    196244
     
    341389
    342390  this->setSize2D(.2 * this->resX, this->resY);
    343   this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
    344   this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
     391  if( this->playmode != FirstPerson )
     392  {
     393          this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
     394          this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
     395  }
    345396
    346397  int overlayWidth = 0;
     
    354405  this->rightRect->hide();
    355406  this->leftRect->hide();
    356 
    357   this->leftRect->setParent2D(this);
    358   this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY));
    359   this->leftRect->setAbsCoor2D(0,0);
    360   this->leftRect->setBackgroundTexture(Texture());
    361   this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2));
    362   this->leftRect->setForegroundTexture(Texture());
    363   this->leftRect->setForegroundColor(Color(0,0,0,0));
    364 
    365   this->rightRect->setParent2D(this);
    366   this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY));
    367   this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0);
    368   this->rightRect->setBackgroundTexture(Texture());
    369   this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2));
    370   this->rightRect->setForegroundTexture(Texture());
    371   this->rightRect->setForegroundColor(Color(0,0,0,0));
    372 
     407 
     408  if( this->playmode != FirstPerson )
     409  {
     410          this->leftRect->setParent2D(this);
     411          this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY));
     412          this->leftRect->setAbsCoor2D(0,0);
     413          this->leftRect->setBackgroundTexture(Texture());
     414          this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2));
     415          this->leftRect->setForegroundTexture(Texture());
     416          this->leftRect->setForegroundColor(Color(0,0,0,0));
     417       
     418          this->rightRect->setParent2D(this);
     419          this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY));
     420          this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0);
     421          this->rightRect->setBackgroundTexture(Texture());
     422          this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2));
     423          this->rightRect->setForegroundTexture(Texture());
     424          this->rightRect->setForegroundColor(Color(0,0,0,0));
     425  }
     426  else
     427  {
     428          this->bottomRect->setParent2D(this);
     429          this->bottomRect->setWidgetSize(float(this->resX), float(overlayWidth));
     430          this->bottomRect->setAbsCoor2D(0, this->resY - overlayWidth);
     431          this->topRect->setParent2D(this);
     432          this->topRect->setWidgetSize(float(this->resX), float(overlayWidth));
     433          this->topRect->setAbsCoor2D(0, 0);
     434          this->middleRect->setParent2D(this);
     435          this->middleRect->setWidgetSize(float(this->resY)/2, float(this->resY)/2);
     436          this->middleRect->setAbsCoor2D(float(this->resX - this->resY/2)/2, float(this->resY)/4);
     437  }
    373438
    374439  if (this->overlayActive == true)
     
    382447  {
    383448    PRINTF(4)("UPDATING RADAR\n");
    384     this->_radar->setParent2D(this->leftRect);
     449    if( this->playmode != FirstPerson )
     450        this->_radar->setParent2D(this->leftRect);
     451    else
     452        this->_radar->setParent2D(this->topRect);
    385453    if (radarCenterNode == NULL)
    386454      this->_radar->setCenterNode(State::getPlayer()->getPlayable());
     
    397465   
    398466    int statWidgetsNumber = 0;
    399     float expectedArmorSizeX = 0;
    400     float expectedArmorSizeY = 0;
     467    float expectedHealthSizeX = 0;
     468    float expectedHealthSizeY = 0;
    401469    float newSizeY = 0; float newSizeX = 0;
    402470    float moduloWidth = 0;
    403471
    404     if (this->armorWidget != NULL)
    405     {
    406       expectedArmorSizeX = 150;
    407       expectedArmorSizeY = 50;
    408       statWidgetsNumber++;
    409     }
    410 
     472        if( this->playmode != FirstPerson )
     473        {
     474            if (this->healthWidget != NULL)
     475            {
     476              expectedHealthSizeX = 150;
     477              expectedHealthSizeY = 50;
     478              statWidgetsNumber++;
     479            }
     480
     481            if (this->shieldWidget != NULL)
     482              statWidgetsNumber++;
     483           
     484            if (this->energyWidget != NULL)
     485              statWidgetsNumber++;
     486       
     487            if (expectedHealthSizeY * statWidgetsNumber > overlayWidth)
     488            {
     489              newSizeY = overlayWidth / float(statWidgetsNumber);
     490              newSizeX = expectedHealthSizeX;
     491              PRINTF(0)("Statwidgets resized\n");
     492            }
     493            else
     494            {
     495              newSizeY = expectedHealthSizeY;
     496              newSizeX = expectedHealthSizeX;
     497              moduloWidth = int(overlayWidth) % int(expectedHealthSizeY * statWidgetsNumber);
     498            }
     499       
     500            float posY = overlayWidth + newSizeX;
     501       
     502            if (this->healthWidget != NULL)
     503            {
     504              this->healthWidget->setSize2D(newSizeX, newSizeY);
     505              this->healthWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY);
     506            }
     507            if (this->shieldWidget != NULL)
     508            {
     509              this->shieldWidget->setSize2D(newSizeX, newSizeY);
     510              this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY);
     511            }
     512            if (this->energyWidget != NULL)
     513            {
     514              this->energyWidget->setSize2D(newSizeX, newSizeY);
     515              this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY);
     516            }
     517        }
     518        else
     519        {
     520                this->barSocket->setParent2D(this->bottomRect);
     521                this->barSocket->setWidgetSize( float(overlayWidth), float(overlayWidth));
     522                this->barSocket->setRelCoor2D(0,this->resX - float(overlayWidth));
     523               
     524                this->healthWidget->setRelCoor2D(10,-20);
     525        }
     526       
     527
     528    /*
     529    if (this->healthWidget != NULL)
     530      this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D());
    411531    if (this->shieldWidget != NULL)
    412       statWidgetsNumber++;
    413    
     532      this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D());
    414533    if (this->energyWidget != NULL)
    415       statWidgetsNumber++;
    416 
    417     if (expectedArmorSizeY * statWidgetsNumber > overlayWidth)
    418     {
    419       newSizeY = overlayWidth / float(statWidgetsNumber);
    420       newSizeX = expectedArmorSizeX;
    421       PRINTF(0)("Statwidgets resized\n");
    422     }
    423     else
    424     {
    425       newSizeY = expectedArmorSizeY;
    426       newSizeX = expectedArmorSizeX;
    427       moduloWidth = int(overlayWidth) % int(expectedArmorSizeY * statWidgetsNumber);
    428     }
    429 
    430     float posY = overlayWidth + newSizeX;
    431 
    432     if (this->armorWidget != NULL)
    433     {
    434       this->armorWidget->setSize2D(newSizeX, newSizeY);
    435       this->armorWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY);
    436     }
    437     if (this->shieldWidget != NULL)
    438     {
    439       this->shieldWidget->setSize2D(newSizeX, newSizeY);
    440       this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY);
    441     }
    442     if (this->energyWidget != NULL)
    443     {
    444       this->energyWidget->setSize2D(newSizeX, newSizeY);
    445       this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY);
    446     }
    447 
    448     /*
    449     if (this->armorWidget != NULL)
    450       this->armorWidget->setRelCoor2D(100,0.2*this->resY + this->armorWidget->getSizeX2D());
    451     if (this->shieldWidget != NULL)
    452       this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->armorWidget->getSizeX2D());
    453     if (this->energyWidget != NULL)
    454       this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->armorWidget->getSizeX2D());
     534      this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D());
    455535    */
    456     //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->armorWidget->getSizeX2D(),0);
    457     //this->energyWidget->setRelCoor2D(0.1*this->resX + this->armorWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0);
     536    //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D(),0);
     537    //this->energyWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0);
    458538  }
    459539
Note: See TracChangeset for help on using the changeset viewer.