Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7019 in orxonox.OLD


Ignore:
Timestamp:
Feb 3, 2006, 4:33:45 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Using TextEngine in the Menu

Location:
trunk/src
Files:
4 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r7002 r7019  
    216216  CL_BILLBOARD                  =    0x00000514,
    217217  CL_MODEL_ENTITY               =    0x00000515,
     218  CL_TEXT_ELEMENT               =    0x00000516, /// TODO MOVE
    218219
    219220
  • trunk/src/story_entities/simple_game_menu.cc

    r7016 r7019  
    170170      this->menuSelector->setBindNode((const PNode*)NULL);
    171171    }
    172     else if( !strcmp( "StartGame_Menu", (*entity)->getName()))
    173     {
    174       this->menuStartGame = dynamic_cast<ImageEntity*>(*entity);
     172  }
     173
     174  imageEntityList = ClassList::getList(CL_TEXT_ELEMENT);
     175  for (entity = imageEntityList->begin(); entity != imageEntityList->end(); entity++)
     176  {
     177    if( !strcmp( "StartGame_Menu", (*entity)->getName()))
     178    {
     179      this->menuStartGame = dynamic_cast<TextElement*>(*entity);
    175180      this->menuStartGame->setBindNode((const PNode*)NULL);
    176181      this->menuStartGame->setRelCoor2D(State::getResX() / 2.0f,
    177182                                        State::getResY() / 2.0f - 60.0f,
    178183                                        0.0f);
    179       this->menuLayers[0].menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
     184      this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity));
    180185
    181186    }
    182187    else if( !strcmp( "Multiplayer_Menu", (*entity)->getName()))
    183188    {
    184       this->menuStartMultiplayerGame = dynamic_cast<ImageEntity*>(*entity);
     189      this->menuStartMultiplayerGame = dynamic_cast<TextElement*>(*entity);
    185190      this->menuStartMultiplayerGame->setBindNode((const PNode*)NULL);
    186191      this->menuStartMultiplayerGame->setRelCoor2D(State::getResX() / 2.0f,
    187192                                                   State::getResY() / 2.0f + ((this->menuLayers[0].menuList.size() -1 ) * 60.0f),
    188193                                                   0.0f);
    189       this->menuLayers[0].menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
     194      this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity));
    190195    }
    191196    else if( !strcmp( "Quit_Menu", (*entity)->getName()))
    192197    {
    193       this->menuQuitGame = dynamic_cast<ImageEntity*>(*entity);
     198      this->menuQuitGame = dynamic_cast<TextElement*>(*entity);
    194199      this->menuQuitGame->setBindNode((const PNode*)NULL);
    195200      this->menuQuitGame->setRelCoor2D(State::getResX() / 2.0f,
    196201                                       State::getResY() / 2.0f + ((this->menuLayers[0].menuList.size() -1 )* 60.0f),
    197202                                       0.0f);
    198       this->menuLayers[0].menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
     203      this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity));
    199204    }
    200205  }
     
    216221
    217222      // generating menu item
     223      TextElement* te = new TextElement();
     224      te->setVisibility(false);
     225      te->setText(se->getName());
     226      te->setRelCoor2D(State::getResX() / 2.0f - 200.0f, State::getResY() / 2.0f + ((this->menuLayers[1].menuList.size() - 2.0f) * 60.0f), 0.0f);
     227      this->menuLayers[1].menuList.push_back(te);
     228
     229      // generating screenshoot item
    218230      ImageEntity* ie = new ImageEntity();
    219       ie->setTexture(se->getMenuItemImage());
    220231      ie->setVisibility(false);
    221232      ie->setBindNode((const PNode*)NULL);
    222       ie->setRelCoor2D(State::getResX() / 2.0f - 200.0f, State::getResY() / 2.0f + ((this->menuLayers[1].menuList.size() - 2.0f) * 60.0f), 0.0f);
    223       ie->setSize2D(100.0f, 50.0f);
    224       this->menuLayers[1].menuList.push_back(ie);
    225 
    226       // generating screenshoot item
    227       ie = new ImageEntity();
    228233      ie->setTexture(se->getMenuScreenshoot());
    229       ie->setVisibility(false);
    230       ie->setBindNode((const PNode*)NULL);
    231234      ie->setRelCoor2D(State::getResX() / 2.0f + 250.0f, State::getResY() / 2.0f, 0.0f);
    232235      ie->setSize2D(140.0f, 105.0f);
     
    246249  for(mit = this->menuLayers.begin(); mit != this->menuLayers.end(); mit++)
    247250  {
    248     (*mit).menuList.clear(); //erase((*mit).menuList.begin(), (*mit).menuList.end());
    249     (*mit).storyList.clear(); //erase((*mit).storyList.begin(), (*mit).storyList.end());
     251    while(!(*mit).menuList.empty())
     252    {
     253      delete (*mit).menuList.back();
     254      (*mit).menuList.pop_back();
     255    }
     256
     257    (*mit).menuList.clear();
     258    (*mit).storyList.clear();
    250259    (*mit).screenshootList.clear();
    251260  }
     
    404413
    405414  PRINTF(0)("Removing layer %i\n", layer1);
     415  std::vector<TextElement*>::iterator te;
     416  // fade old menu
     417  for( te = this->menuLayers[layer1].menuList.begin(); te != this->menuLayers[layer1].menuList.end(); te++)
     418  {
     419    (*te)->setVisibility(false);
     420  }
     421
    406422  std::vector<ImageEntity*>::iterator it;
    407   // fade old menu
    408   for( it = this->menuLayers[layer1].menuList.begin(); it != this->menuLayers[layer1].menuList.end(); it++)
    409   {
    410     (*it)->setVisibility(false);
    411   }
     423
    412424  //also fade the screenshots if in level choosement mode
    413425  for( it = this->menuLayers[layer1].screenshootList.begin(); it != this->menuLayers[layer1].screenshootList.end(); it++)
     
    419431  PRINTF(0)("Showing layer %i\n", layer1);
    420432  // beam here the new menu
    421   for( it = this->menuLayers[layer2].menuList.begin(); it != this->menuLayers[layer2].menuList.end(); it++ )
    422   {
    423     (*it)->setVisibility(true);
     433  for( te = this->menuLayers[layer2].menuList.begin(); te != this->menuLayers[layer2].menuList.end(); te++ )
     434  {
     435    (*te)->setVisibility(true);
    424436  }
    425437
  • trunk/src/story_entities/simple_game_menu.h

    r6991 r7019  
    1515
    1616
     17#include "elements/text_element.h"
     18
    1719class SimpleGameMenuData;
    1820class TiXmlElement;
     
    2931
    3032  public:
    31     std::vector<ImageEntity*>         menuList;                        //!< the list of the menu items
     33    std::vector<TextElement*>          menuList;                        //!< the list of the menu items
    3234    std::vector<StoryEntity*>         storyList;                       //!< the list of the StoryEntities for the menu
    3335    std::vector<ImageEntity*>         screenshootList;                 //!< list of the screen shoots FIXME: make a better structure for this stuff
     
    7577
    7678    //std::vector<ImageEntity*>         menuList;                        //!< the list of the menu items
    77     ImageEntity*                      menuSelected;                    //!< ref to the selected menu entity
    7879    ImageEntity*                      menuSelector;                    //!< ref to the selector image
    79     ImageEntity*                      menuStartGame;
    80     ImageEntity*                      menuStartMultiplayerGame;
    81     ImageEntity*                      menuQuitGame;
     80    TextElement*                      menuSelected;                    //!< ref to the selected menu entity
     81    TextElement*                      menuStartGame;
     82    TextElement*                      menuStartMultiplayerGame;
     83    TextElement*                      menuQuitGame;
    8284    int                               menuSelectedIndex;
    8385
  • trunk/src/world_entities/Makefile.am

    r7016 r7019  
    6363                  world_entities/environments/model_entity.cc \
    6464                  \
    65                   world_entities/elements/image_entity.cc
     65                  world_entities/elements/image_entity.cc \
     66                  world_entities/elements/text_element.cc
    6667
    6768
  • trunk/src/world_entities/elements/text_element.cc

    r7016 r7019  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
    1717
    18 #include "image_entity.h"
     18#include "text_element.h"
    1919
    2020#include "load_param.h"
     
    2222
    2323#include "graphics_engine.h"
    24 #include "material.h"
    25 #include "glincl.h"
    2624#include "state.h"
    2725
     
    3028
    3129
    32 CREATE_FACTORY(ImageEntity, CL_IMAGE_ENTITY);
     30CREATE_FACTORY(TextElement, CL_TEXT_ELEMENT);
    3331
    3432
     
    3634 * standart constructor
    3735 */
    38 ImageEntity::ImageEntity (const TiXmlElement* root)
     36TextElement::TextElement (const TiXmlElement* root)
    3937{
    40   this->init();
     38  this->setClassID(CL_TEXT_ELEMENT, "TextElement");
     39  this->setName("TextElement");
     40
     41  this->setLayer(E2D_LAYER_TOP);
     42  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
     43
     44  this->setSize(20);
     45  this->setFont("fonts/earth.ttf");
     46
    4147  if(root != NULL)
    4248    this->loadParams(root);
     
    4551
    4652/**
    47  * destroys a ImageEntity
     53 * destroys a TextElement
    4854*/
    49 ImageEntity::~ImageEntity ()
     55TextElement::~TextElement ()
    5056{
    51   if (this->material)
    52     delete this->material;
    5357}
    5458
    5559
    56 /**
    57  * initializes the ImageEntity
    58  */
    59 void ImageEntity::init()
     60void TextElement::loadParams(const TiXmlElement* root)
    6061{
    61   this->setClassID(CL_IMAGE_ENTITY, "ImageEntity");
    62   this->setName("ImageEntity");
     62  Element2D::loadParams(root);
    6363
    64   this->setLayer(E2D_LAYER_TOP);
    65   this->setRotationSpeed(5);
    66   this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0);
     64  LoadParam(root, "size", this, Text, setSize);
    6765
    68   this->setBindNode(this);
    69   this->material = new Material;
    70   this->setTexture("pictures/error_texture.png");
    71   this->bBillboarding = false;
     66  LoadParam(root, "text", this, TextElement, setText);
     67
     68  LoadParam(root, "font", this, TextElement, setFont);
    7269}
    7370
    74 
    75 void ImageEntity::loadParams(const TiXmlElement* root)
     71void TextElement::setText(const char* text)
    7672{
    77   PNode::loadParams(root);
    78   Element2D::loadParams(root);
    79 
    80   LoadParam(root, "texture", this, ImageEntity, setTexture)
    81       .describe("the texture-file to load onto the ImageEntity");
    82 
    83   LoadParam(root, "size", this, ImageEntity, setSize)
    84       .describe("the size of the ImageEntity in Pixels");
    85 
    86   LoadParam(root, "rotation-speed", this, ImageEntity, setRotationSpeed)
    87       .describe("the Speed with which the ImageEntity should rotate");
    88 
    89   LoadParam(root, "billboarding", this, ImageEntity, toggleBillboarding)
    90       .describe("sets the Billboard to always look in the direction of the Player");
     73  Text::setText(text);
    9174}
    9275
    93 
    94 /**
    95  * sets the size of the ImageEntity.
    96  * @param size the size in pixels
    97  */
    98 void ImageEntity::setSize(float sizeX, float sizeY)
     76void TextElement::setFont(const char* font)
    9977{
    100   this->setSize2D(sizeX, sizeY);
     78  Text::setFont(font, (unsigned int)this->getSizeY2D());
    10179}
    102 
    103 
    104 /**
    105  * sets the material to load
    106  * @param textureFile The texture-file to load onto the crosshair
    107  */
    108 void ImageEntity::setTexture(const char* textureFile)
    109 {
    110   this->material->setDiffuseMap(textureFile);
    111 }
    112 
    113 
    114 /** this turns on/off the billboarding of this WorldEntity
    115  *
    116  * This means that the image will always look in the direction of the Player
    117  */
    118 void ImageEntity::toggleBillboarding()
    119 {
    120   this->bBillboarding = !this->bBillboarding;
    121 }
    122 
    123 
    124 /**
    125  * ticks the ImageEntity
    126  * @param dt the time to ticks
    127  */
    128 void ImageEntity::tick(float dt)
    129 {
    130 
    131 }
    132 
    133 
    134 /**
    135  * draws the crosshair
    136  */
    137 void ImageEntity::draw() const
    138 {
    139   if( !this->isVisible())
    140     return;
    141 
    142   glPushMatrix();
    143   glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
    144 
    145   //glRotatef(this->getAbsDir2D(), 0,0,1);
    146   this->material->select();
    147   glBegin(GL_TRIANGLE_STRIP);
    148   glTexCoord2f(0, 0);
    149   glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
    150   glTexCoord2f(1, 0);
    151   glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
    152   glTexCoord2f(0, 1);
    153   glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
    154   glTexCoord2f(1, 1);
    155   glVertex2f(this->getSizeX2D(), this->getSizeY2D());
    156   glEnd();
    157   glPopMatrix();
    158 
    159 }
  • trunk/src/world_entities/elements/text_element.h

    r7016 r7019  
    11/*!
    2  * @file image_entity.h
    3  *  Definition of an ImageEntity
     2 * @file text_element.h
     3 *  Definition of an TextElement
    44 */
    55
    6 #ifndef _IMAGE_ENTITY_H
    7 #define _IMAGE_ENTITY_H
     6#ifndef _TEXT_ELEMENT_H
     7#define _TEXT_ELEMENT_H
    88
    99#include "p_node.h"
    10 #include "element_2d.h"
     10#include "text.h"
    1111#include "event_listener.h"
    1212
     
    2020
    2121//! A class that enables the
    22 class ImageEntity : public PNode, public Element2D {
     22class TextElement : public Text {
    2323
    2424 public:
    25   ImageEntity(const TiXmlElement* root = NULL);
    26   virtual ~ImageEntity();
     25  TextElement(const TiXmlElement* root = NULL);
     26  virtual ~TextElement();
    2727
    2828  void init();
    2929  virtual void loadParams(const TiXmlElement* root);
    3030
    31   void setSize(float sizeX, float sizeY);
    32   void setTexture(const char* textureFile);
    33   /** @param rotationSpeed the speed at what the crosshair should rotate */
    34   void setRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; };
    35   void toggleBillboarding();
    36 
    37   virtual void tick(float dt);
    38   virtual void draw() const;
     31  void setText(const char* text);
     32  void setFont(const char* font);
    3933
    4034 private:
    41    Material*        material;             //!< a material for the Aim.
    42    float            rotationSpeed;        //!< Speed of the Rotation.
    43    bool             bBillboarding;        //!< true if billboarding is on
     35
    4436};
    4537
    46 #endif /* _IMAGE_ENTITY_H */
     38#endif /* _TEXT_ELEMENT_H */
Note: See TracChangeset for help on using the changeset viewer.