Changeset 1577 for code/trunk
- Timestamp:
- Jun 9, 2008, 6:21:04 PM (16 years ago)
- Location:
- code/trunk/src/orxonox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/Orxonox.cc
r1567 r1577 70 70 // objects and tools 71 71 #include "hud/HUD.h" 72 #include "console/InGameConsole.h" 72 73 #include "objects/Tickable.h" 73 74 #include "tools/ParticleInterface.h" … … 76 77 #include "Settings.h" 77 78 78 // FIXME: is this really file scope?79 79 // globals for the server or client 80 network::Client *client_g = 0;81 network::Server *server_g = 0;80 static network::Client *client_g = 0; 81 static network::Server *server_g = 0; 82 82 83 83 namespace orxonox … … 121 121 //if (this->auMan_) 122 122 // delete this->auMan_; 123 InGameConsole::getInstance().destroy(); 123 124 if (this->timer_) 124 125 delete this->timer_; … … 263 264 return false; 264 265 266 // TODO: Spread this so that this call only initialises things needed for the Console 267 if (!ogre_->initialiseResources()) 268 return false; 269 270 // Load the InGameConsole 271 InGameConsole::getInstance().initialise(); 272 265 273 // Calls the InputManager which sets up the input devices. 266 274 // The render window width and height are used to set up the mouse movement. … … 269 277 return false; 270 278 271 // TODO: Spread this so that this call only initialises things needed for the GUI272 if (!ogre_->initialiseResources())273 return false;274 275 279 // TOOD: load the GUI here 276 280 // set InputManager to GUI mode … … 315 319 /** 316 320 * Loads everything in the scene except for the actual objects. 317 * This includes HUD, Console..321 * This includes HUD, audio.. 318 322 */ 319 323 bool Orxonox::loadPlayground() … … 331 335 orxonoxHUD_ = &HUD::getSingleton(); 332 336 orxonoxHUD_->initialise(); 337 333 338 return true; 334 339 } … … 339 344 bool Orxonox::serverLoad() 340 345 { 341 COUT( 2) << "Loading level in server mode" << std::endl;346 COUT(0) << "Loading level in server mode" << std::endl; 342 347 343 348 //server_g = new network::Server(serverPort_); … … 357 362 bool Orxonox::clientLoad() 358 363 { 359 COUT( 2) << "Loading level in client mode" << std::endl;\364 COUT(0) << "Loading level in client mode" << std::endl;\ 360 365 361 366 if (serverIp_.compare("") == 0) … … 377 382 bool Orxonox::standaloneLoad() 378 383 { 379 COUT( 2) << "Loading level in standalone mode" << std::endl;384 COUT(0) << "Loading level in standalone mode" << std::endl; 380 385 381 386 if (!loadScene()) … … 500 505 // again, just to be sure ogre works fine 501 506 ogreRoot._fireFrameEnded(evt); 502 //msleep( 200);507 //msleep(500); 503 508 } 504 509 -
code/trunk/src/orxonox/console/InGameConsole.cc
r1571 r1577 47 47 48 48 #define LINES 30 49 #define CHAR_WIDTH1 7.45 //78 //34 // fix this please - determine the char-width dynamically 50 #define CHAR_WIDTH2 CHAR_WIDTH1 //28 // fix this please - determine the char-width dynamically 51 #define CHAR_WIDTH3 CHAR_WIDTH1 //80 //78 // fix this please - determine the char-width dynamically 49 #define CHAR_WIDTH 7.45 // fix this please - determine the char-width dynamically 52 50 53 51 namespace orxonox … … 58 56 using namespace Ogre; 59 57 60 float InGameConsole::REL_WIDTH = 0.8;61 float InGameConsole::REL_HEIGHT = 0.4;62 float InGameConsole::BLINK = 0.5;63 64 58 /** 65 59 @brief Constructor: Creates and initializes the InGameConsole. 66 60 */ 67 61 InGameConsole::InGameConsole() : 68 om_(0), consoleOverlay_(0), consoleOverlayContainer_(0), 69 consoleOverlayNoise_(0), consoleOverlayBorder_(0), consoleOverlayTextAreas_(0) 62 consoleOverlay_(0), consoleOverlayContainer_(0), 63 consoleOverlayNoise_(0), consoleOverlayCursor_(0), consoleOverlayBorder_(0), 64 consoleOverlayTextAreas_(0) 70 65 { 71 66 RegisterObject(InGameConsole); 72 67 73 68 this->bActive_ = false; 74 this->cursor_ = 0.0 ;69 this->cursor_ = 0.0f; 75 70 this->cursorSymbol_ = '|'; 76 71 this->inputWindowStart_ = 0; 77 72 this->numLinesShifted_ = LINES - 1; 78 79 this->init(); 73 // for the beginning, don't scroll 74 this->scroll_ = 0; 75 80 76 this->setConfigValues(); 81 82 Shell::getInstance().addOutputLevel(true);83 77 } 84 78 … … 88 82 InGameConsole::~InGameConsole(void) 89 83 { 90 /*for (int i = 0; i < LINES; i++) 91 if (this->consoleOverlayTextAreas_[i]) 92 om_->destroyOverlayElement(this->consoleOverlayTextAreas_[i]); 93 94 if (this->consoleOverlayTextAreas_) 95 delete[] this->consoleOverlayTextAreas_;*/ 84 this->destroy(); 96 85 } 97 86 … … 110 99 void InGameConsole::setConfigValues() 111 100 { 112 SetConfigValue(REL_WIDTH, 0.8); 113 SetConfigValue(REL_HEIGHT, 0.4); 114 SetConfigValue(BLINK, 0.5); 115 } 116 117 /** 118 @brief Called if all output-lines have to be redrawn. 119 */ 120 void InGameConsole::linesChanged() 121 { 122 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator(); 123 int max = 0; 124 for (int i = 1; i < LINES; ++i) 125 { 126 if (it != Shell::getInstance().getEndIterator()) 127 { 128 ++it; 129 max = i; 130 } 131 else 132 break; 133 } 134 135 for (int i = LINES - 1; i > max; --i) 136 this->print("", i, true); 137 138 for (int i = max; i >= 1; --i) 139 { 140 --it; 141 this->print(*it, i, true); 142 } 143 } 144 145 /** 146 @brief Called if only the last output-line has changed. 147 */ 148 void InGameConsole::onlyLastLineChanged() 149 { 150 if (LINES > 1) 151 this->print(*Shell::getInstance().getNewestLineIterator(), 1); 152 } 153 154 /** 155 @brief Called if a new output-line was added. 156 */ 157 void InGameConsole::lineAdded() 158 { 159 this->numLinesShifted_ = 0; 160 this->shiftLines(); 161 this->onlyLastLineChanged(); 162 } 163 164 /** 165 @brief Called if the text in the input-line has changed. 166 */ 167 void InGameConsole::inputChanged() 168 { 169 if (LINES > 0) 170 this->print(Shell::getInstance().getInput(), 0); 171 172 if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0) 173 this->inputWindowStart_ = 0; 174 } 175 176 /** 177 @brief Called if the position of the cursor in the input-line has changed. 178 */ 179 void InGameConsole::cursorChanged() 180 { 181 /*std::string input = Shell::getInstance().getInput(); 182 input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_); 183 if (LINES > 0) 184 this->print(input, 0);*/ 185 this->setCursorPosition(Shell::getInstance().getCursorPosition() - inputWindowStart_); 186 } 187 188 /** 189 @brief Called if the console gets closed. 190 */ 191 void InGameConsole::exit() 192 { 193 this->deactivate(); 194 } 195 196 /** 197 @brief Called once by constructor, initializes the InGameConsole. 198 */ 199 void InGameConsole::init() 200 { 201 // for the beginning, don't scroll 202 this->scroll_ = 0; 203 this->cursor_ = 0; 204 101 SetConfigValue(relativeWidth, 0.8); 102 SetConfigValue(relativeHeight, 0.4); 103 SetConfigValue(blinkTime, 0.5); 104 SetConfigValue(scrollSpeed_, 3.0f); 105 SetConfigValue(noiseSize_, 1.0f); 106 } 107 108 /** 109 @brief Initializes the InGameConsole. 110 */ 111 void InGameConsole::initialise() 112 { 205 113 // create overlay and elements 206 this->om_ = &Ogre::OverlayManager::getSingleton(); 114 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); 115 116 // create actual overlay 117 this->consoleOverlay_ = ovMan->create("InGameConsoleConsole"); 207 118 208 119 // create a container 209 this->consoleOverlayContainer_ = static_cast<OverlayContainer*>( this->om_->createOverlayElement("Panel", "InGameConsoleContainer"));120 this->consoleOverlayContainer_ = static_cast<OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer")); 210 121 this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE); 211 this->consoleOverlayContainer_->setPosition((1 - InGameConsole::REL_WIDTH) / 2, 0); 212 this->consoleOverlayContainer_->setDimensions(InGameConsole::REL_WIDTH, InGameConsole::REL_HEIGHT); 122 this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0); 123 this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight); 124 this->consoleOverlay_->add2D(this->consoleOverlayContainer_); 213 125 214 126 // create BorderPanel 215 this->consoleOverlayBorder_ = static_cast<BorderPanelOverlayElement*>( this->om_->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));127 this->consoleOverlayBorder_ = static_cast<BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel")); 216 128 this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS); 217 129 this->consoleOverlayBorder_->setMaterialName("ConsoleCenter"); 218 // set parameters for border219 130 this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16); 220 131 this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder"); … … 224 135 this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); 225 136 this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); 137 this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_); 226 138 227 139 // create the text lines … … 229 141 for (int i = 0; i < LINES; i++) 230 142 { 231 this->consoleOverlayTextAreas_[i] = static_cast<TextAreaOverlayElement*>( this->om_->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i)));143 this->consoleOverlayTextAreas_[i] = static_cast<TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i))); 232 144 this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS); 233 145 this->consoleOverlayTextAreas_[i]->setFontName("Monofur"); … … 236 148 this->consoleOverlayTextAreas_[i]->setLeft(8); 237 149 this->consoleOverlayTextAreas_[i]->setCaption(""); 238 } 150 this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]); 151 } 152 153 // create cursor (also a text area overlay element) 154 this->consoleOverlayCursor_ = static_cast<TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i))); 155 this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS); 156 this->consoleOverlayCursor_->setFontName("Monofur"); 157 this->consoleOverlayCursor_->setCharHeight(18); 158 this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21"); 159 this->consoleOverlayCursor_->setLeft(7); 160 this->consoleOverlayCursor_->setCaption("|"); 161 this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_); 239 162 240 163 // create noise 241 this->consoleOverlayNoise_ = static_cast<PanelOverlayElement*>( this->om_->createOverlayElement("Panel", "InGameConsoleNoise"));164 this->consoleOverlayNoise_ = static_cast<PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise")); 242 165 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS); 243 166 this->consoleOverlayNoise_->setPosition(5,0); 244 this->consoleOverlayNoise_->setMaterialName("ConsoleNoise"); 245 246 // create cursor 247 this->consoleOverlayCursor_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleCursor")); 248 this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS); 249 this->consoleOverlayCursor_->setPosition(5,219); 250 this->consoleOverlayCursor_->setDimensions(1, 14); 251 this->consoleOverlayCursor_->setMaterialName("Orxonox/GreenDot"); 252 253 this->consoleOverlay_ = this->om_->create("InGameConsoleConsole"); 254 this->consoleOverlay_->add2D(this->consoleOverlayContainer_); 255 this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_); 256 this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_); 257 //comment following line to disable noise 167 this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall"); 168 // comment following line to disable noise 258 169 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 259 for (int i = 0; i < LINES; i++)260 this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);261 170 262 171 this->resize(); 263 172 264 173 // move overlay "above" the top edge of the screen 265 // we take -1.2 because the border m kes the panel bigger266 this->consoleOverlayContainer_->setTop(-1.2 * InGameConsole::REL_HEIGHT);267 // show overlay 268 this->consoleOverlay_->show();174 // we take -1.2 because the border makes the panel bigger 175 this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight); 176 177 Shell::getInstance().addOutputLevel(true); 269 178 270 179 COUT(4) << "Info: InGameConsole initialized" << std::endl; … … 272 181 273 182 /** 274 @brief Resizes the console elements. Call if window size changes. 275 */ 276 void InGameConsole::resize() 277 { 278 this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 279 this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 280 this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH); 281 this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT); 282 this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10); 283 this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5); 284 285 // now adjust the text lines... 286 this->desiredTextWidth_ = (int) (this->windowW_ * InGameConsole::REL_WIDTH) - 12; 287 183 @brief Destroys all the elements if necessary. 184 */ 185 void InGameConsole::destroy() 186 { 187 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); 188 if (ovMan) 189 { 190 if (this->consoleOverlayNoise_) 191 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayNoise_); 192 if (this->consoleOverlayCursor_) 193 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayCursor_); 194 if (this->consoleOverlayBorder_) 195 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayBorder_); 196 if (this->consoleOverlayTextAreas_) 197 { 198 for (int i = 0; i < LINES; i++) 199 { 200 if (this->consoleOverlayTextAreas_[i]) 201 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayTextAreas_[i]); 202 this->consoleOverlayTextAreas_[i] = 0; 203 } 204 205 } 206 if (this->consoleOverlayContainer_) 207 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayContainer_); 208 } 209 if (this->consoleOverlayTextAreas_) 210 { 211 delete[] this->consoleOverlayTextAreas_; 212 this->consoleOverlayTextAreas_ = 0; 213 } 214 } 215 216 // ############################### 217 // ### ShellListener methods ### 218 // ############################### 219 220 /** 221 @brief Called if all output-lines have to be redrawn. 222 */ 223 void InGameConsole::linesChanged() 224 { 225 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator(); 226 int max = 0; 227 for (int i = 1; i < LINES; ++i) 228 { 229 if (it != Shell::getInstance().getEndIterator()) 230 { 231 ++it; 232 max = i; 233 } 234 else 235 break; 236 } 237 238 for (int i = LINES - 1; i > max; --i) 239 this->print("", i, true); 240 241 for (int i = max; i >= 1; --i) 242 { 243 --it; 244 this->print(*it, i, true); 245 } 246 } 247 248 /** 249 @brief Called if only the last output-line has changed. 250 */ 251 void InGameConsole::onlyLastLineChanged() 252 { 253 if (LINES > 1) 254 this->print(*Shell::getInstance().getNewestLineIterator(), 1); 255 } 256 257 /** 258 @brief Called if a new output-line was added. 259 */ 260 void InGameConsole::lineAdded() 261 { 262 this->numLinesShifted_ = 0; 263 this->shiftLines(); 264 this->onlyLastLineChanged(); 265 } 266 267 /** 268 @brief Called if the text in the input-line has changed. 269 */ 270 void InGameConsole::inputChanged() 271 { 288 272 if (LINES > 0) 289 this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH3)); 290 else 291 this->maxCharsPerLine_ = 10; 292 293 for (int i = 0; i < LINES; i++) 294 { 295 this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_); 296 this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i); 297 } 298 299 this->linesChanged(); 300 this->cursorChanged(); 301 } 273 this->print(Shell::getInstance().getInput(), 0); 274 275 if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0) 276 this->inputWindowStart_ = 0; 277 } 278 279 /** 280 @brief Called if the position of the cursor in the input-line has changed. 281 */ 282 void InGameConsole::cursorChanged() 283 { 284 unsigned int pos = Shell::getInstance().getCursorPosition() - inputWindowStart_; 285 if (pos > maxCharsPerLine_) 286 pos = maxCharsPerLine_; 287 else if (pos < 0) 288 pos = 0; 289 290 this->consoleOverlayCursor_->setCaption(std::string(pos,' ') + cursorSymbol_); 291 this->consoleOverlayCursor_->setTop((int) this->windowH_ * this->relativeHeight - 24); 292 } 293 294 /** 295 @brief Called if the console gets closed. 296 */ 297 void InGameConsole::exit() 298 { 299 this->deactivate(); 300 } 301 302 // ############################### 303 // ### other external calls ### 304 // ############################### 302 305 303 306 /** … … 308 311 if (this->scroll_ != 0) 309 312 { 310 float top = this->consoleOverlayContainer_->getTop() + dt * this->scroll_; 311 this->consoleOverlayContainer_->setTop(top); 312 313 if (this->scroll_ < 0 && top <= -1.2 * InGameConsole::REL_HEIGHT) 314 { 315 // window has completely scrolled up 316 this->scroll_ = 0; 317 this->consoleOverlay_->hide(); 318 } 319 320 if (this->scroll_ > 0 && top >= 0) 321 { 322 // window has completely scrolled down 323 this->scroll_ = 0; 324 this->consoleOverlayContainer_->setTop(0); 313 float oldTop = this->consoleOverlayContainer_->getTop(); 314 315 if (this->scroll_ > 0) 316 { 317 // scrolling down 318 // enlarge oldTop a little bit so that this exponential function 319 // reaches 0 before infinite time has passed... 320 float deltaScroll = (oldTop - 0.01) * dt * this->scrollSpeed_; 321 if (oldTop - deltaScroll >= 0) 322 { 323 // window has completely scrolled down 324 this->consoleOverlayContainer_->setTop(0); 325 this->scroll_ = 0; 326 } 327 else 328 this->consoleOverlayContainer_->setTop(oldTop - deltaScroll); 329 } 330 331 else 332 { 333 // scrolling up 334 // note: +0.01 for the same reason as when scrolling down 335 float deltaScroll = (1.2 * this->relativeHeight + 0.01 + oldTop) * dt * this->scrollSpeed_; 336 if (oldTop - deltaScroll <= -1.2 * this->relativeHeight) 337 { 338 // window has completely scrolled up 339 this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight); 340 this->scroll_ = 0; 341 this->consoleOverlay_->hide(); 342 } 343 else 344 this->consoleOverlayContainer_->setTop(oldTop - deltaScroll); 325 345 } 326 346 } … … 329 349 { 330 350 this->cursor_ += dt; 331 if (this->cursor_ >= InGameConsole::BLINK)351 if (this->cursor_ >= this->blinkTime) 332 352 { 333 353 this->cursor_ = 0; 334 354 bShowCursor_ = !bShowCursor_; 335 355 if (bShowCursor_) 336 this->consoleOverlayCursor_->show();356 this->consoleOverlayCursor_->show(); 337 357 else 338 this->consoleOverlayCursor_->hide(); 339 } 340 341 /*if (this->cursor_ >= 2 * InGameConsole::BLINK) 342 this->cursor_ = 0; 343 344 if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|') 345 { 346 this->cursorSymbol_ = ' '; 347 this->cursorChanged(); 348 } 349 else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ') 350 { 351 this->cursorSymbol_ = '|'; 352 this->cursorChanged(); 353 }*/ 354 355 // this creates a flickering effect 356 this->consoleOverlayNoise_->setTiling(1, rand() % 5 + 1); 357 } 358 } 359 360 /** 361 @brief Shows the InGameConsole. 362 */ 363 void InGameConsole::activate() 364 { 365 if (!this->bActive_) 366 { 367 this->bActive_ = true; 368 InputManager::setInputState(InputManager::IS_CONSOLE); 369 Shell::getInstance().registerListener(this); 370 371 this->resize(); 372 this->linesChanged(); 373 this->cursorChanged(); 374 this->consoleOverlay_->show(); 375 376 // scroll down 377 this->scroll_ = 1; 378 // the rest is done by tick 379 } 380 } 381 382 /** 383 @brief Hides the InGameConsole. 384 */ 385 void InGameConsole::deactivate() 386 { 387 if (this->bActive_) 388 { 389 this->bActive_ = false; 390 InputManager::setInputState(InputManager::IS_NORMAL); 391 Shell::getInstance().unregisterListener(this); 392 393 // scroll up 394 this->scroll_ = -1; 395 // the rest is done by tick 396 } 397 } 398 399 /** 400 @brief Activates the console. 401 */ 402 void InGameConsole::openConsole() 403 { 404 InGameConsole::getInstance().activate(); 405 } 406 407 /** 408 @brief Deactivates the console. 409 */ 410 void InGameConsole::closeConsole() 411 { 412 InGameConsole::getInstance().deactivate(); 413 } 414 415 /** 416 @brief Shifts all output lines one line up 417 */ 418 void InGameConsole::shiftLines() 419 { 420 for (unsigned int i = LINES - 1; i > 1; --i) 421 { 422 this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption()); 423 this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop()); 424 this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom()); 425 } 426 } 427 428 void InGameConsole::colourLine(int colourcode, int index) 429 { 430 if (colourcode == -1) 431 { 432 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00)); 433 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00)); 434 } 435 else if (colourcode == 1) 436 { 437 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00)); 438 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00)); 439 } 440 else if (colourcode == 2) 441 { 442 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00)); 443 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00)); 444 } 445 else if (colourcode == 3) 446 { 447 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00)); 448 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00)); 449 } 450 else if (colourcode == 4) 451 { 452 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00)); 453 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00)); 454 } 455 else if (colourcode == 5) 456 { 457 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00)); 458 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00)); 459 } 358 this->consoleOverlayCursor_->hide(); 359 } 360 361 // this creates a flickering effect (extracts exactly 80% of the texture at a random location) 362 float uRand = (rand() & 1023) / 1023.0f * 0.2f; 363 float vRand = (rand() & 1023) / 1023.0f * 0.2f; 364 this->consoleOverlayNoise_->setUV(uRand, vRand, 0.8f + uRand, 0.8f + vRand); 365 } 366 } 367 368 /** 369 @brief Resizes the console elements. Call if window size changes. 370 */ 371 void InGameConsole::resize() 372 { 373 this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 374 this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 375 this->consoleOverlayBorder_->setWidth((int) this->windowW_* this->relativeWidth); 376 this->consoleOverlayBorder_->setHeight((int) this->windowH_ * this->relativeHeight); 377 this->consoleOverlayNoise_->setWidth((int) this->windowW_ * this->relativeWidth - 10); 378 this->consoleOverlayNoise_->setHeight((int) this->windowH_ * this->relativeHeight - 5); 379 this->consoleOverlayNoise_->setTiling(consoleOverlayNoise_->getWidth() / 80.0f * this->noiseSize_, consoleOverlayNoise_->getHeight() / 80.0f * this->noiseSize_); 380 381 // now adjust the text lines... 382 this->desiredTextWidth_ = (int) (this->windowW_ * this->relativeWidth) - 12; 383 384 if (LINES > 0) 385 this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH)); 460 386 else 461 { 462 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00)); 463 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00)); 464 } 465 } 466 467 void InGameConsole::setCursorPosition(unsigned int pos) 468 { 469 static std::string char1 = "bdefgilpqtzCEGIJKNOPQT5[}äü"; 470 static std::string char2 = "Z4"; 471 472 if (pos > maxCharsPerLine_) 473 pos = maxCharsPerLine_; 474 else if (pos < 0) 475 pos = 0; 476 477 float width = 0; 478 for (unsigned int i = 0; i < pos && i < displayedText_.size(); ++i) 479 { 480 if (char1.find(displayedText_[i]) != std::string::npos) 481 width += CHAR_WIDTH1; 482 else if (char2.find(displayedText_[i]) != std::string::npos) 483 width += CHAR_WIDTH2; 484 else 485 width += CHAR_WIDTH3; 486 } 487 this->consoleOverlayCursor_->setPosition(width + 8, this->windowH_ * InGameConsole::REL_HEIGHT - 20); 488 } 387 this->maxCharsPerLine_ = 10; 388 389 for (int i = 0; i < LINES; i++) 390 { 391 this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_); 392 this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * this->relativeHeight - 24 - 14*i); 393 } 394 395 this->linesChanged(); 396 this->cursorChanged(); 397 } 398 399 // ############################### 400 // ### internal methods ### 401 // ############################### 489 402 490 403 /** … … 544 457 545 458 /** 459 @brief Shows the InGameConsole. 460 */ 461 void InGameConsole::activate() 462 { 463 if (!this->bActive_) 464 { 465 this->bActive_ = true; 466 InputManager::setInputState(InputManager::IS_CONSOLE); 467 Shell::getInstance().registerListener(this); 468 469 this->resize(); 470 this->linesChanged(); 471 this->cursorChanged(); 472 this->consoleOverlay_->show(); 473 474 // scroll down 475 this->scroll_ = 1; 476 // the rest is done by tick 477 } 478 } 479 480 /** 481 @brief Hides the InGameConsole. 482 */ 483 void InGameConsole::deactivate() 484 { 485 if (this->bActive_) 486 { 487 this->bActive_ = false; 488 InputManager::setInputState(InputManager::IS_NORMAL); 489 Shell::getInstance().unregisterListener(this); 490 491 // scroll up 492 this->scroll_ = -1; 493 // the rest is done by tick 494 } 495 } 496 497 /** 498 @brief Shifts all output lines one line up 499 */ 500 void InGameConsole::shiftLines() 501 { 502 for (unsigned int i = LINES - 1; i > 1; --i) 503 { 504 this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption()); 505 this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop()); 506 this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom()); 507 } 508 } 509 510 void InGameConsole::colourLine(int colourcode, int index) 511 { 512 if (colourcode == -1) 513 { 514 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00)); 515 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00)); 516 } 517 else if (colourcode == 1) 518 { 519 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00)); 520 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00)); 521 } 522 else if (colourcode == 2) 523 { 524 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00)); 525 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00)); 526 } 527 else if (colourcode == 3) 528 { 529 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00)); 530 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00)); 531 } 532 else if (colourcode == 4) 533 { 534 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00)); 535 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00)); 536 } 537 else if (colourcode == 5) 538 { 539 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00)); 540 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00)); 541 } 542 else 543 { 544 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00)); 545 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00)); 546 } 547 } 548 549 // ############################### 550 // ### satic methods ### 551 // ############################### 552 553 /** 554 @brief Activates the console. 555 */ 556 /*static*/ void InGameConsole::openConsole() 557 { 558 InGameConsole::getInstance().activate(); 559 } 560 561 /** 562 @brief Deactivates the console. 563 */ 564 /*static*/ void InGameConsole::closeConsole() 565 { 566 InGameConsole::getInstance().deactivate(); 567 } 568 569 /** 546 570 @brief Converts a string into an Ogre::UTFString. 547 571 @param s The string to convert 548 572 @return The converted string 549 573 */ 550 Ogre::UTFString InGameConsole::convert2UTF(std::string s)574 /*static*/ Ogre::UTFString InGameConsole::convert2UTF(std::string s) 551 575 { 552 576 Ogre::UTFString utf; -
code/trunk/src/orxonox/console/InGameConsole.h
r1540 r1577 44 44 class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener 45 45 { 46 public: 46 public: // functions 47 void initialise(); 48 void destroy(); 49 void setConfigValues(); 50 51 void tick(float dt); 52 void resize(); 53 47 54 static InGameConsole& getInstance(); 48 55 49 void setConfigValues();50 void tick(float dt);51 52 void resize();53 56 static void openConsole(); 54 57 static void closeConsole(); 55 58 56 private: 59 private: // functions 57 60 InGameConsole(); 58 InGameConsole(const InGameConsole& other) ;61 InGameConsole(const InGameConsole& other) {} 59 62 ~InGameConsole(); 60 63 … … 62 65 void deactivate(); 63 66 64 v irtual void linesChanged();65 v irtual void onlyLastLineChanged();66 v irtual void lineAdded();67 v irtual void inputChanged();68 v irtual void cursorChanged();69 v irtual void exit();67 void linesChanged(); 68 void onlyLastLineChanged(); 69 void lineAdded(); 70 void inputChanged(); 71 void cursorChanged(); 72 void exit(); 70 73 71 void init();72 74 void shiftLines(); 73 75 void colourLine(int colourcode, int index); 74 76 void setCursorPosition(unsigned int pos); 75 77 void print(const std::string& text, int index, bool alwaysShift = false); 78 76 79 static Ogre::UTFString convert2UTF(std::string s); 77 80 78 static float REL_WIDTH; 79 static float REL_HEIGHT; 80 static float BLINK; 81 81 private: // variables 82 82 bool bActive_; 83 83 int windowW_; … … 92 92 bool bShowCursor_; 93 93 std::string displayedText_; 94 Ogre::OverlayManager* om_;95 94 Ogre::Overlay* consoleOverlay_; 96 95 Ogre::OverlayContainer* consoleOverlayContainer_; 97 96 Ogre::PanelOverlayElement* consoleOverlayNoise_; 98 Ogre:: PanelOverlayElement* consoleOverlayCursor_;97 Ogre::TextAreaOverlayElement* consoleOverlayCursor_; 99 98 Ogre::BorderPanelOverlayElement* consoleOverlayBorder_; 100 99 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_; 100 101 // config values 102 float relativeWidth; 103 float relativeHeight; 104 float blinkTime; 105 float scrollSpeed_; 106 float noiseSize_; 101 107 }; 102 108 }
Note: See TracChangeset
for help on using the changeset viewer.