Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 31, 2010, 2:02:39 PM (14 years ago)
Author:
smerkli
Message:
 
Location:
code/branches/presentation3/src/orxonox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/orxonox/ChatInputHandler.cc

    r6934 r7043  
    6666    GUIManager::getInstance().loadGUI( "ChatBox-inputonly" );
    6767
     68    /* setup colors */
     69    setupColors();
     70
    6871    /* configure the input buffer */
    6972    configureInputBuffer();
     
    7376  }
    7477
     78  /* configure input buffer, sub for the constructor */
    7579  void ChatInputHandler::configureInputBuffer()
    7680  {
     
    113117  }
    114118
     119  /* setup the colors, sub for the constructor */
     120  void ChatInputHandler::setupColors()
     121  {
     122    float red = 1.0, green = 0.5, blue = 0.5;
     123    int i = 0;
     124
     125    // reds
     126    for( i = 0; i < NumberOfColors/3; ++i )
     127    { this->text_colors[ i ] = new CEGUI::colour( red, green, blue );
     128      assert( this->text_colors[ i ] );
     129      green += 0.2, blue += 0.2;
     130    }
     131
     132    // greens
     133    red = 0.5, green = 1, blue = 0.5;
     134    for( ; i < NumberOfColors*2/3; ++i )
     135    { this->text_colors[ i ] = new CEGUI::colour( red, green, blue );
     136      assert( this->text_colors[ i ] );
     137      red += 0.2, blue += 0.2;
     138    }
     139
     140    // blues
     141    red = 0.5, green = 0.5, blue = 1;
     142    for( ; i < NumberOfColors; ++i )
     143    { this->text_colors[ i ] = new CEGUI::colour( red, green, blue );
     144      assert( this->text_colors[ i ] );
     145      red += 0.2, green += 0.2;
     146    }
     147  }
     148
    115149
    116150  /* activate, deactivate */
     
    121155  { ChatInputHandler::getInstance().activate( false ); }
    122156
    123 
    124 
    125 
    126157  void ChatInputHandler::activate( bool full )
    127158  {
    128159    /* start listening */
    129     //COUT(0) << "chatinput activated." << std::endl;
    130160    InputManager::getInstance().enterState("chatinput");
    131161
     
    150180
    151181
     182  /* subs for incomingChat */
     183  void ChatInputHandler::sub_setcolor( CEGUI::ListboxTextItem *tocolor,
     184    std::string name )
     185  {
     186    if( !tocolor )
     187      COUT(2) << "Empty ListBoxTextItem given to "
     188        "ChatInputhandler::sub_setcolor().\n";
     189
     190    /* "hash" the name */
     191    int hash = 0;
     192    for( int i = name.length(); i > 0; --i )
     193      hash += name[i-1];
     194    hash = hash % this->NumberOfColors;
     195
     196    /* set the color according to the hash */
     197    tocolor->setTextColours( *(this->text_colors[ hash ]) );
     198  }
     199
     200  /* handle incoming chat */
    152201  void ChatInputHandler::incomingChat(const std::string& message,
    153202    unsigned int senderID)
    154203  {
    155     /* --> a) look up the actual name of the sender */
    156     std::string text;
    157 
     204    /* look up the actual name of the sender */
     205    std::string text, name = "unknown";
     206
     207    /* setup player name info */
    158208    if (senderID != CLIENTID_UNKNOWN)
    159     {
    160        std::string name = "unknown";
     209    {
    161210       PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
    162211       if (player)
    163212         name = player->getName();
    164 
    165          text = name + ": " + message;
    166     }
    167     else
    168       text = message;
    169 
    170     /* e) create item and add to history */
     213    }
     214
     215    /* assemble the text */
     216    text = name + ": " + message;
     217
     218    /* create item */
    171219    CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( text );
     220
     221    /* setup colors */
     222    sub_setcolor( toadd, name );
     223
     224    /* now add */
    172225    this->lb_history->addItem( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
    173     this->lb_history->ensureItemIsVisible( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
    174 
    175     /* f) make sure the history handles it */
     226    this->lb_history->ensureItemIsVisible(
     227      dynamic_cast<CEGUI::ListboxItem*>(toadd) );
     228
     229    /* make sure the history handles it */
    176230    this->lb_history->handleUpdatedItemData();
    177231  }
    178232
    179233
     234  /* sub for inputchanged */
    180235  void ChatInputHandler::sub_adjust_dispoffset( int maxlen,
    181236    int cursorpos,
  • code/branches/presentation3/src/orxonox/ChatInputHandler.h

    r7009 r7043  
    6868      bool fullchat;
    6969
     70      /* colors for nickname coloring */
     71      static const int NumberOfColors = 10;
     72      CEGUI::colour *text_colors[ NumberOfColors ];
     73
    7074      /** input state */
    7175      InputState *inputState;
     
    8589      /** cegui handle for the history window */
    8690      CEGUI::Listbox *lb_history;
     91
     92      /* methods to deal with colors */
     93      void sub_setcolor( CEGUI::ListboxTextItem *tocolor,
     94        std::string name );
     95
     96      void setupColors();
    8797
    8898      /* callbacks for input handler */
Note: See TracChangeset for help on using the changeset viewer.