Changeset 7043
- Timestamp:
- May 31, 2010, 2:02:39 PM (14 years ago)
- Location:
- code/branches/presentation3/src/orxonox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/orxonox/ChatInputHandler.cc
r6934 r7043 66 66 GUIManager::getInstance().loadGUI( "ChatBox-inputonly" ); 67 67 68 /* setup colors */ 69 setupColors(); 70 68 71 /* configure the input buffer */ 69 72 configureInputBuffer(); … … 73 76 } 74 77 78 /* configure input buffer, sub for the constructor */ 75 79 void ChatInputHandler::configureInputBuffer() 76 80 { … … 113 117 } 114 118 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 115 149 116 150 /* activate, deactivate */ … … 121 155 { ChatInputHandler::getInstance().activate( false ); } 122 156 123 124 125 126 157 void ChatInputHandler::activate( bool full ) 127 158 { 128 159 /* start listening */ 129 //COUT(0) << "chatinput activated." << std::endl;130 160 InputManager::getInstance().enterState("chatinput"); 131 161 … … 150 180 151 181 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 */ 152 201 void ChatInputHandler::incomingChat(const std::string& message, 153 202 unsigned int senderID) 154 203 { 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 */ 158 208 if (senderID != CLIENTID_UNKNOWN) 159 { 160 std::string name = "unknown"; 209 { 161 210 PlayerInfo* player = PlayerManager::getInstance().getClient(senderID); 162 211 if (player) 163 212 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 */ 171 219 CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( text ); 220 221 /* setup colors */ 222 sub_setcolor( toadd, name ); 223 224 /* now add */ 172 225 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 */ 176 230 this->lb_history->handleUpdatedItemData(); 177 231 } 178 232 179 233 234 /* sub for inputchanged */ 180 235 void ChatInputHandler::sub_adjust_dispoffset( int maxlen, 181 236 int cursorpos, -
code/branches/presentation3/src/orxonox/ChatInputHandler.h
r7009 r7043 68 68 bool fullchat; 69 69 70 /* colors for nickname coloring */ 71 static const int NumberOfColors = 10; 72 CEGUI::colour *text_colors[ NumberOfColors ]; 73 70 74 /** input state */ 71 75 InputState *inputState; … … 85 89 /** cegui handle for the history window */ 86 90 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(); 87 97 88 98 /* callbacks for input handler */
Note: See TracChangeset
for help on using the changeset viewer.