[Orxonox-commit 2328] r7043 - code/branches/presentation3/src/orxonox
smerkli at orxonox.net
smerkli at orxonox.net
Mon May 31 14:02:39 CEST 2010
Author: smerkli
Date: 2010-05-31 14:02:39 +0200 (Mon, 31 May 2010)
New Revision: 7043
Modified:
code/branches/presentation3/src/orxonox/ChatInputHandler.cc
code/branches/presentation3/src/orxonox/ChatInputHandler.h
Log:
Modified: code/branches/presentation3/src/orxonox/ChatInputHandler.cc
===================================================================
--- code/branches/presentation3/src/orxonox/ChatInputHandler.cc 2010-05-31 11:41:26 UTC (rev 7042)
+++ code/branches/presentation3/src/orxonox/ChatInputHandler.cc 2010-05-31 12:02:39 UTC (rev 7043)
@@ -65,6 +65,9 @@
GUIManager::getInstance().loadGUI( "ChatBox" );
GUIManager::getInstance().loadGUI( "ChatBox-inputonly" );
+ /* setup colors */
+ setupColors();
+
/* configure the input buffer */
configureInputBuffer();
@@ -72,6 +75,7 @@
this->inputState->setKeyHandler(this->inpbuf);
}
+ /* configure input buffer, sub for the constructor */
void ChatInputHandler::configureInputBuffer()
{
/* INSTALL CALLBACKS */
@@ -112,7 +116,37 @@
assert( lb_history );
}
+ /* setup the colors, sub for the constructor */
+ void ChatInputHandler::setupColors()
+ {
+ float red = 1.0, green = 0.5, blue = 0.5;
+ int i = 0;
+ // reds
+ for( i = 0; i < NumberOfColors/3; ++i )
+ { this->text_colors[ i ] = new CEGUI::colour( red, green, blue );
+ assert( this->text_colors[ i ] );
+ green += 0.2, blue += 0.2;
+ }
+
+ // greens
+ red = 0.5, green = 1, blue = 0.5;
+ for( ; i < NumberOfColors*2/3; ++i )
+ { this->text_colors[ i ] = new CEGUI::colour( red, green, blue );
+ assert( this->text_colors[ i ] );
+ red += 0.2, blue += 0.2;
+ }
+
+ // blues
+ red = 0.5, green = 0.5, blue = 1;
+ for( ; i < NumberOfColors; ++i )
+ { this->text_colors[ i ] = new CEGUI::colour( red, green, blue );
+ assert( this->text_colors[ i ] );
+ red += 0.2, green += 0.2;
+ }
+ }
+
+
/* activate, deactivate */
void ChatInputHandler::activate_static()
{ ChatInputHandler::getInstance().activate( true ); }
@@ -120,13 +154,9 @@
void ChatInputHandler::activate_small_static()
{ ChatInputHandler::getInstance().activate( false ); }
-
-
-
void ChatInputHandler::activate( bool full )
{
/* start listening */
- //COUT(0) << "chatinput activated." << std::endl;
InputManager::getInstance().enterState("chatinput");
/* MARK add spawning of chat widget stuff here.*/
@@ -149,34 +179,59 @@
}
+ /* subs for incomingChat */
+ void ChatInputHandler::sub_setcolor( CEGUI::ListboxTextItem *tocolor,
+ std::string name )
+ {
+ if( !tocolor )
+ COUT(2) << "Empty ListBoxTextItem given to "
+ "ChatInputhandler::sub_setcolor().\n";
+
+ /* "hash" the name */
+ int hash = 0;
+ for( int i = name.length(); i > 0; --i )
+ hash += name[i-1];
+ hash = hash % this->NumberOfColors;
+
+ /* set the color according to the hash */
+ tocolor->setTextColours( *(this->text_colors[ hash ]) );
+ }
+
+ /* handle incoming chat */
void ChatInputHandler::incomingChat(const std::string& message,
unsigned int senderID)
{
- /* --> a) look up the actual name of the sender */
- std::string text;
+ /* look up the actual name of the sender */
+ std::string text, name = "unknown";
+ /* setup player name info */
if (senderID != CLIENTID_UNKNOWN)
- {
- std::string name = "unknown";
+ {
PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
if (player)
name = player->getName();
-
- text = name + ": " + message;
}
- else
- text = message;
- /* e) create item and add to history */
+ /* assemble the text */
+ text = name + ": " + message;
+
+ /* create item */
CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( text );
+
+ /* setup colors */
+ sub_setcolor( toadd, name );
+
+ /* now add */
this->lb_history->addItem( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
- this->lb_history->ensureItemIsVisible( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
+ this->lb_history->ensureItemIsVisible(
+ dynamic_cast<CEGUI::ListboxItem*>(toadd) );
- /* f) make sure the history handles it */
+ /* make sure the history handles it */
this->lb_history->handleUpdatedItemData();
}
+ /* sub for inputchanged */
void ChatInputHandler::sub_adjust_dispoffset( int maxlen,
int cursorpos,
int inplen )
Modified: code/branches/presentation3/src/orxonox/ChatInputHandler.h
===================================================================
--- code/branches/presentation3/src/orxonox/ChatInputHandler.h 2010-05-31 11:41:26 UTC (rev 7042)
+++ code/branches/presentation3/src/orxonox/ChatInputHandler.h 2010-05-31 12:02:39 UTC (rev 7043)
@@ -67,6 +67,10 @@
int disp_offset, width;
bool fullchat;
+ /* colors for nickname coloring */
+ static const int NumberOfColors = 10;
+ CEGUI::colour *text_colors[ NumberOfColors ];
+
/** input state */
InputState *inputState;
@@ -85,6 +89,12 @@
/** cegui handle for the history window */
CEGUI::Listbox *lb_history;
+ /* methods to deal with colors */
+ void sub_setcolor( CEGUI::ListboxTextItem *tocolor,
+ std::string name );
+
+ void setupColors();
+
/* callbacks for input handler */
void inputChanged();
void addline();
More information about the Orxonox-commit
mailing list