- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/orxonox/overlays/InGameConsole.cc
r5929 r6412 44 44 #include "util/Convert.h" 45 45 #include "util/Math.h" 46 #include "util/ UTFStringConversions.h"46 #include "util/DisplayStringConversions.h" 47 47 #include "core/CoreIncludes.h" 48 48 #include "core/ConfigValueIncludes.h" … … 61 61 SetConsoleCommand(InGameConsole, closeConsole, true); 62 62 63 InGameConsole* InGameConsole::singletonPtr_s = 0;64 63 ManageScopedSingleton(InGameConsole, ScopeID::Graphics, false); 65 64 … … 68 67 */ 69 68 InGameConsole::InGameConsole() 70 : consoleOverlay_(0) 69 : shell_(new Shell("InGameConsole", true)) 70 , bShowCursor_(false) 71 , consoleOverlay_(0) 71 72 , consoleOverlayContainer_(0) 72 73 , consoleOverlayNoise_(0) … … 99 100 // destroy the input state previously created (InputBuffer gets destroyed by the Shell) 100 101 InputManager::getInstance().destroyState("console"); 102 103 // destroy the underlaying shell 104 this->shell_->destroy(); 101 105 102 106 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); … … 174 178 // create the corresponding input state 175 179 inputState_ = InputManager::getInstance().createInputState("console", false, false, InputStatePriority::Console); 176 inputState_->setKeyHandler( Shell::getInstance().getInputBuffer());180 inputState_->setKeyHandler(this->shell_->getInputBuffer()); 177 181 bHidesAllInputChanged(); 178 182 … … 214 218 font->addCodePointRange(Ogre::Font::CodePointRange(161, 255)); 215 219 220 // create noise 221 this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise")); 222 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS); 223 this->consoleOverlayNoise_->setPosition(5,0); 224 this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall"); 225 // comment following line to disable noise 226 this->consoleOverlayBorder_->addChild(this->consoleOverlayNoise_); 227 216 228 // create the text lines 217 229 this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES]; … … 225 237 this->consoleOverlayTextAreas_[i]->setLeft(8); 226 238 this->consoleOverlayTextAreas_[i]->setCaption(""); 227 this->consoleOverlay Container_->addChild(this->consoleOverlayTextAreas_[i]);239 this->consoleOverlayNoise_->addChild(this->consoleOverlayTextAreas_[i]); 228 240 } 229 241 … … 236 248 this->consoleOverlayCursor_->setLeft(7); 237 249 this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1)); 238 this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_); 239 240 // create noise 241 this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise")); 242 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS); 243 this->consoleOverlayNoise_->setPosition(5,0); 244 this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall"); 245 // comment following line to disable noise 246 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 250 this->consoleOverlayNoise_->addChild(this->consoleOverlayCursor_); 247 251 248 252 this->windowResized(this->getWindowWidth(), this->getWindowWidth()); 249 253 250 254 // move overlay "above" the top edge of the screen 251 // we take -1.2 because the border makes the panel bigger 252 this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight); 253 254 Shell::getInstance().addOutputLevel(true); 255 // we take -1.3 because the border makes the panel bigger 256 this->consoleOverlayContainer_->setTop(-1.3 * this->relativeHeight); 255 257 256 258 COUT(4) << "Info: InGameConsole initialized" << std::endl; … … 266 268 void InGameConsole::linesChanged() 267 269 { 268 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();270 Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator(); 269 271 int max = 0; 270 272 for (int i = 1; i < LINES; ++i) 271 273 { 272 if (it != Shell::getInstance().getEndIterator())274 if (it != this->shell_->getEndIterator()) 273 275 { 274 276 ++it; … … 280 282 281 283 for (int i = LINES - 1; i > max; --i) 282 this->print("", i, true);284 this->print("", Shell::None, i, true); 283 285 284 286 for (int i = max; i >= 1; --i) 285 287 { 286 288 --it; 287 this->print( *it, i, true);289 this->print(it->first, it->second, i, true); 288 290 } 289 291 } … … 295 297 { 296 298 if (LINES > 1) 297 this->print( *Shell::getInstance().getNewestLineIterator(), 1);299 this->print(this->shell_->getNewestLineIterator()->first, this->shell_->getNewestLineIterator()->second, 1); 298 300 } 299 301 … … 314 316 { 315 317 if (LINES > 0) 316 this->print( Shell::getInstance().getInput(), 0);317 318 if ( Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0)318 this->print(this->shell_->getInput(), Shell::Input, 0); 319 320 if (this->shell_->getInput().empty()) 319 321 this->inputWindowStart_ = 0; 320 322 } … … 325 327 void InGameConsole::cursorChanged() 326 328 { 327 unsigned int pos = Shell::getInstance().getCursorPosition() - inputWindowStart_;329 unsigned int pos = this->shell_->getCursorPosition() - inputWindowStart_; 328 330 if (pos > maxCharsPerLine_) 329 331 pos = maxCharsPerLine_; … … 331 333 this->consoleOverlayCursor_->setCaption(std::string(pos,' ') + cursorSymbol_); 332 334 this->consoleOverlayCursor_->setTop(static_cast<int>(this->windowH_ * this->relativeHeight) - 24); 335 } 336 337 /** 338 @brief Called if a command is about to be executed 339 */ 340 void InGameConsole::executed() 341 { 342 this->shell_->addOutput(this->shell_->getInput() + '\n', Shell::Command); 333 343 } 334 344 … … 348 358 @brief Used to control the actual scrolling and the cursor. 349 359 */ 350 void InGameConsole:: update(const Clock& time)360 void InGameConsole::preUpdate(const Clock& time) 351 361 { 352 362 if (this->scroll_ != 0) … … 374 384 // scrolling up 375 385 // note: +0.01 for the same reason as when scrolling down 376 float deltaScroll = (1. 2* this->relativeHeight + 0.01 + oldTop) * time.getDeltaTime() * this->scrollSpeed_;377 if (oldTop - deltaScroll <= -1. 2* this->relativeHeight)386 float deltaScroll = (1.3 * this->relativeHeight + 0.01 + oldTop) * time.getDeltaTime() * this->scrollSpeed_; 387 if (oldTop - deltaScroll <= -1.3 * this->relativeHeight) 378 388 { 379 389 // window has completely scrolled up 380 this->consoleOverlayContainer_->setTop(-1. 2* this->relativeHeight);390 this->consoleOverlayContainer_->setTop(-1.3 * this->relativeHeight); 381 391 this->scroll_ = 0; 382 392 this->consoleOverlay_->hide(); … … 446 456 @param s String to be printed 447 457 */ 448 void InGameConsole::print(const std::string& text, int index, bool alwaysShift) 449 { 450 char level = 0; 451 if (text.size() > 0) 452 level = text[0]; 453 458 void InGameConsole::print(const std::string& text, Shell::LineType type, int index, bool alwaysShift) 459 { 454 460 std::string output = text; 455 456 if (level >= -1 && level <= 5)457 output.erase(0, 1);458 459 461 if (LINES > index) 460 462 { 461 this->colourLine( level, index);463 this->colourLine(type, index); 462 464 463 465 if (index > 0) … … 467 469 { 468 470 ++linesUsed; 469 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre:: UTFString>(output.substr(0, this->maxCharsPerLine_)));471 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output.substr(0, this->maxCharsPerLine_))); 470 472 output.erase(0, this->maxCharsPerLine_); 471 473 output.insert(0, 1, ' '); 472 474 if (linesUsed > numLinesShifted_ || alwaysShift) 473 475 this->shiftLines(); 474 this->colourLine( level, index);476 this->colourLine(type, index); 475 477 } 476 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre:: UTFString>(output));478 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output)); 477 479 this->displayedText_ = output; 478 480 this->numLinesShifted_ = linesUsed; … … 482 484 if (output.size() > this->maxCharsPerLine_) 483 485 { 484 if ( Shell::getInstance().getInputBuffer()->getCursorPosition() < this->inputWindowStart_)485 this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition();486 else if ( Shell::getInstance().getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))487 this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;486 if (this->shell_->getInputBuffer()->getCursorPosition() < this->inputWindowStart_) 487 this->inputWindowStart_ = this->shell_->getInputBuffer()->getCursorPosition(); 488 else if (this->shell_->getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1)) 489 this->inputWindowStart_ = this->shell_->getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1; 488 490 489 491 output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_); … … 492 494 this->inputWindowStart_ = 0; 493 495 this->displayedText_ = output; 494 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre:: UTFString>(output));496 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output)); 495 497 } 496 498 } … … 506 508 this->bActive_ = true; 507 509 InputManager::getInstance().enterState("console"); 508 Shell::getInstance().registerListener(this);510 this->shell_->registerListener(this); 509 511 510 512 this->windowResized(this->windowW_, this->windowH_); … … 528 530 this->bActive_ = false; 529 531 InputManager::getInstance().leaveState("console"); 530 Shell::getInstance().unregisterListener(this);532 this->shell_->unregisterListener(this); 531 533 532 534 // scroll up … … 549 551 } 550 552 551 void InGameConsole::colourLine(int colourcode, int index) 552 { 553 if (colourcode == -1) 554 { 555 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00)); 556 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00)); 557 } 558 else if (colourcode == 1) 559 { 560 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00)); 561 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00)); 562 } 563 else if (colourcode == 2) 564 { 565 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00)); 566 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00)); 567 } 568 else if (colourcode == 3) 569 { 570 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00)); 571 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00)); 572 } 573 else if (colourcode == 4) 574 { 575 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00)); 576 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00)); 577 } 578 else if (colourcode == 5) 579 { 580 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00)); 581 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00)); 582 } 583 else 584 { 585 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00)); 586 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00)); 587 } 588 } 589 590 // ############################### 591 // ### satic methods ### 592 // ############################### 553 void InGameConsole::colourLine(Shell::LineType type, int index) 554 { 555 ColourValue colourTop, colourBottom; 556 switch (type) 557 { 558 case Shell::Error: colourTop = ColourValue(0.95, 0.25, 0.25, 1.00); 559 colourBottom = ColourValue(1.00, 0.50, 0.50, 1.00); break; 560 561 case Shell::Warning: colourTop = ColourValue(0.95, 0.50, 0.20, 1.00); 562 colourBottom = ColourValue(1.00, 0.70, 0.50, 1.00); break; 563 564 case Shell::Info: colourTop = ColourValue(0.50, 0.50, 0.95, 1.00); 565 colourBottom = ColourValue(0.80, 0.80, 1.00, 1.00); break; 566 567 case Shell::Debug: colourTop = ColourValue(0.65, 0.48, 0.44, 1.00); 568 colourBottom = ColourValue(1.00, 0.90, 0.90, 1.00); break; 569 570 case Shell::Verbose: colourTop = ColourValue(0.40, 0.20, 0.40, 1.00); 571 colourBottom = ColourValue(0.80, 0.60, 0.80, 1.00); break; 572 573 case Shell::Ultra: colourTop = ColourValue(0.21, 0.69, 0.21, 1.00); 574 colourBottom = ColourValue(0.80, 1.00, 0.80, 1.00); break; 575 576 case Shell::Command: colourTop = ColourValue(0.80, 0.80, 0.80, 1.00); 577 colourBottom = ColourValue(0.90, 0.90, 0.90, 0.90); break; 578 579 case Shell::Hint: colourTop = ColourValue(0.80, 0.80, 0.80, 1.00); 580 colourBottom = ColourValue(0.90, 0.90, 0.90, 1.00); break; 581 582 default: colourTop = ColourValue(0.90, 0.90, 0.90, 1.00); 583 colourBottom = ColourValue(1.00, 1.00, 1.00, 1.00); break; 584 } 585 586 this->consoleOverlayTextAreas_[index]->setColourTop (colourTop); 587 this->consoleOverlayTextAreas_[index]->setColourBottom(colourBottom); 588 } 589 590 // ################################ 591 // ### static methods ### 592 // ################################ 593 593 594 594 /**
Note: See TracChangeset
for help on using the changeset viewer.