Changeset 1446 for code/branches/network/src/orxonox
- Timestamp:
- May 28, 2008, 5:30:11 AM (16 years ago)
- Location:
- code/branches/network/src/orxonox
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/orxonox/GraphicsEngine.cc
r1349 r1446 45 45 #include "core/Debug.h" 46 46 #include "core/CommandExecutor.h" 47 47 #include "console/InGameConsole.h" 48 48 49 49 namespace orxonox { … … 345 345 int h = rw->getHeight(); 346 346 InputManager::setWindowExtents(w, h); 347 InGameConsole::getInstance().resize(); 347 348 } 348 349 -
code/branches/network/src/orxonox/Orxonox.cc
r1443 r1446 51 51 //#include "util/Sleep.h" 52 52 #include "util/ArgReader.h" 53 #include "util/ExprParser.h"54 53 55 54 // core … … 57 56 #include "core/ConsoleCommand.h" 58 57 #include "core/Debug.h" 59 #include "core/Factory.h"60 58 #include "core/Loader.h" 61 59 #include "core/Tickable.h" 62 #include "core/InputBuffer.h"63 60 #include "core/InputManager.h" 64 61 #include "core/TclBind.h" … … 72 69 73 70 // objects and tools 74 #include "tools/Timer.h"75 71 #include "hud/HUD.h" 76 #include "console/InGameConsole.h"77 72 78 73 // FIXME: is this really file scope? … … 83 78 namespace orxonox 84 79 { 85 ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None).setKeybindMode(KeybindMode::OnPress); 86 ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0) 87 .setAxisParamIndex(0).setIsAxisRelative(false); 88 ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0); 89 ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None); 90 class Testconsole : public InputBufferListener 91 { 92 public: 93 Testconsole(InputBuffer* ib) : ib_(ib) {} 94 void listen() const 95 { 96 std::cout << "> " << this->ib_->get() << std::endl; 97 } 98 void execute() const 99 { 100 std::cout << ">> " << this->ib_->get() << std::endl; 101 if (!CommandExecutor::execute(this->ib_->get())) 102 std::cout << "Error" << std::endl; 103 this->ib_->clear(); 104 } 105 void hintandcomplete() const 106 { 107 std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl; 108 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 109 } 110 void clear() const 111 { 112 this->ib_->clear(); 113 } 114 void removeLast() const 115 { 116 this->ib_->removeLast(); 117 } 118 void exit() const 119 { 120 InputManager::setInputState(InputManager::IS_NORMAL); 121 } 122 123 private: 124 InputBuffer* ib_; 125 }; 126 127 class Calculator 128 { 129 public: 130 static float calculate(const std::string& calculation) 131 { 132 ExprParser expr(calculation); 133 if (expr.getSuccess()) 134 { 135 if (expr.getResult() == 42.0) 136 std::cout << "Greetings from the restaurant at the end of the universe." << std::endl; 137 // FIXME: insert modifier to display in full precision 138 std::cout << "Result is: " << expr.getResult() << std::endl; 139 if (expr.getRemains() != "") 140 std::cout << "Warning: Expression could not be parsed to the end! Remains: '" 141 << expr.getRemains() << "'" << std::endl; 142 return expr.getResult(); 143 } 144 else 145 { 146 std::cout << "Cannot calculate expression: Parse error" << std::endl; 147 return 0; 148 } 149 } 150 }; 151 ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None); 80 SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress); 81 SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); 82 SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); 152 83 153 84 /** … … 165 96 // turn on frame smoothing by setting a value different from 0 166 97 frameSmoothingTime_(0.0f), 167 orxonoxConsole_(0),168 98 orxonoxHUD_(0), 169 99 bAbort_(false), … … 351 281 COUT(3) << "Orxonox: Loading HUD..." << std::endl; 352 282 orxonoxHUD_ = &HUD::getSingleton(); 353 354 COUT(3) << "Orxonox: Loading Console..." << std::endl;355 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));356 /*357 Testconsole* console = new Testconsole(ib);358 ib->registerListener(console, &Testconsole::listen, true);359 ib->registerListener(console, &Testconsole::execute, '\r', false);360 ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);361 ib->registerListener(console, &Testconsole::clear, '�', true);362 ib->registerListener(console, &Testconsole::removeLast, '\b', true);363 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);364 */365 orxonoxConsole_ = new InGameConsole(ib);366 ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);367 ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false);368 ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true);369 //ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true);370 ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true);371 ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);372 373 283 return true; 374 284 } … … 495 405 renderTime = 0.0f; 496 406 } 497 407 498 408 // Call those objects that need the real time 499 409 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) … … 502 412 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 503 413 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 504 // TODO: currently a hack. Somehow the console doesn't work with OrxonoxClass505 orxonoxConsole_->tick((float)evt.timeSinceLastFrame);506 414 507 415 // don't forget to call _fireFrameStarted in ogre to make sure … … 571 479 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000); 572 480 } 573 574 /**575 * Static function that shows the console in game mode.576 */577 void Orxonox::activateConsole()578 {579 // currently, the console shows itself when feeded with input.580 InputManager::setInputState(InputManager::IS_CONSOLE);581 }582 481 } -
code/branches/network/src/orxonox/Orxonox.h
r1379 r1446 70 70 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; } 71 71 static inline void exit() { Orxonox::getSingleton()->abortRequest(); } 72 static inline void activateConsole();73 72 74 73 private: … … 97 96 // TODO: make this a config-value by creating a config class for orxonox 98 97 float frameSmoothingTime_; 99 InGameConsole* orxonoxConsole_;100 98 HUD* orxonoxHUD_; 101 99 bool bAbort_; //!< aborts the render loop if true -
code/branches/network/src/orxonox/console/InGameConsole.cc
r1362 r1446 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 40 40 #include "core/Debug.h" 41 41 #include "core/CoreIncludes.h" 42 #include "core/ConfigValueIncludes.h" 42 43 #include "core/ConsoleCommand.h" 43 44 #include "core/InputManager.h" 45 #include "util/Math.h" 44 46 #include "GraphicsEngine.h" 45 47 46 #define LINES 20 48 #define LINES 30 49 #define CHAR_WIDTH 7.85 // fix this please - determine the char-width dynamically 47 50 48 51 namespace orxonox 49 52 { 53 SetConsoleCommand(InGameConsole, openConsole, true); 54 SetConsoleCommand(InGameConsole, closeConsole, true); 55 50 56 using namespace Ogre; 51 57 52 const float REL_WIDTH = 0.8; 53 const float REL_HEIGHT = 0.4; 54 const float BLINK = 0.25; 55 56 InGameConsole::InGameConsole(InputBuffer* ib) : 57 windowW(0), windowH(0), 58 scroll(0), scrollTimer(0.0f), 59 cursor(0.0f), 60 active(false), 61 ib_(ib), 62 om(0), 63 consoleOverlay(0), 64 consoleOverlayContainer(0), 65 consoleOverlayNoise(0), 66 consoleOverlayBorder(0), 67 consoleOverlayTextAreas(0) 68 { 69 //RegisterObject(InGameConsole); 70 init(); 71 } 72 73 InGameConsole::~InGameConsole(void){ 74 for(int i=0; i<LINES; i++) delete consoleOverlayTextAreas[i]; 75 delete consoleOverlayTextAreas; 76 } 77 78 void InGameConsole::listen(){ 79 if(!active) activate(); 80 print(convert2UTF(this->ib_->get())); 81 } 82 83 void InGameConsole::execute(){ 84 newline(); 85 if (!CommandExecutor::execute(this->ib_->get())){ 86 print("Error"); 87 newline(); 88 } 89 this->ib_->clear(); 90 } 91 92 void InGameConsole::hintandcomplete(){ 93 print(CommandExecutor::hint(this->ib_->get())); 94 newline(); 95 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 96 print(convert2UTF(this->ib_->get())); 97 } 98 99 void InGameConsole::clear(){ 100 this->ib_->clear(); 101 } 102 103 void InGameConsole::removeLast(){ 104 this->ib_->removeLast(); 105 } 106 107 void InGameConsole::exit(){ 108 clear(); 109 deactivate(); 110 InputManager::setInputState(InputManager::IS_NORMAL); 111 } 112 113 /** 114 @brief called once by constructor 115 */ 116 void InGameConsole::init(){ 58 float InGameConsole::REL_WIDTH = 0.8; 59 float InGameConsole::REL_HEIGHT = 0.4; 60 float InGameConsole::BLINK = 0.5; 61 62 /** 63 @brief Constructor: Creates and initializes the InGameConsole. 64 */ 65 InGameConsole::InGameConsole() : 66 om_(0), consoleOverlay_(0), consoleOverlayContainer_(0), 67 consoleOverlayNoise_(0), consoleOverlayBorder_(0), consoleOverlayTextAreas_(0) 68 { 69 RegisterObject(InGameConsole); 70 71 this->active_ = false; 72 this->cursor_ = 0.0; 73 this->cursorSymbol_ = '|'; 74 this->inputWindowStart_ = 0; 75 this->numLinesShifted_ = LINES - 1; 76 77 this->init(); 78 this->setConfigValues(); 79 80 Shell::getInstance().addOutputLevel(true); 81 } 82 83 /** 84 @brief Destructor: Destroys the TextAreas. 85 */ 86 InGameConsole::~InGameConsole(void) 87 { 88 for (int i = 0; i < LINES; i++) 89 if (this->consoleOverlayTextAreas_[i]) 90 delete this->consoleOverlayTextAreas_[i]; 91 92 if (this->consoleOverlayTextAreas_) 93 delete this->consoleOverlayTextAreas_; 94 } 95 96 /** 97 @brief Returns a reference to the only existing instance of InGameConsole. 98 */ 99 InGameConsole& InGameConsole::getInstance() 100 { 101 static InGameConsole instance; 102 return instance; 103 } 104 105 /** 106 @brief Sets the config values, describing the size of the console. 107 */ 108 void InGameConsole::setConfigValues() 109 { 110 SetConfigValue(REL_WIDTH, 0.8); 111 SetConfigValue(REL_HEIGHT, 0.4); 112 SetConfigValue(BLINK, 0.5); 113 } 114 115 /** 116 @brief Called if all output-lines have to be redrawn. 117 */ 118 void InGameConsole::linesChanged() 119 { 120 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator(); 121 int max = 0; 122 for (int i = 1; i < LINES; ++i) 123 { 124 if (it != Shell::getInstance().getEndIterator()) 125 { 126 ++it; 127 max = i; 128 } 129 else 130 break; 131 } 132 133 for (int i = LINES - 1; i > max; --i) 134 this->print("", i, true); 135 136 for (int i = max; i >= 1; --i) 137 { 138 --it; 139 this->print(*it, i, true); 140 } 141 } 142 143 /** 144 @brief Called if only the last output-line has changed. 145 */ 146 void InGameConsole::onlyLastLineChanged() 147 { 148 if (LINES > 1) 149 this->print(*Shell::getInstance().getNewestLineIterator(), 1); 150 } 151 152 /** 153 @brief Called if a new output-line was added. 154 */ 155 void InGameConsole::lineAdded() 156 { 157 this->numLinesShifted_ = 0; 158 this->shiftLines(); 159 this->onlyLastLineChanged(); 160 } 161 162 /** 163 @brief Called if the text in the input-line has changed. 164 */ 165 void InGameConsole::inputChanged() 166 { 167 if (LINES > 0) 168 this->print(Shell::getInstance().getInput(), 0); 169 170 if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0) 171 this->inputWindowStart_ = 0; 172 } 173 174 /** 175 @brief Called if the position of the cursor in the input-line has changed. 176 */ 177 void InGameConsole::cursorChanged() 178 { 179 std::string input = Shell::getInstance().getInput(); 180 input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_); 181 if (LINES > 0) 182 this->print(input, 0); 183 } 184 185 /** 186 @brief Called if the console gets closed. 187 */ 188 void InGameConsole::exit() 189 { 190 this->deactivate(); 191 } 192 193 /** 194 @brief Called once by constructor, initializes the InGameConsole. 195 */ 196 void InGameConsole::init() 197 { 117 198 // for the beginning, don't scroll 118 scroll= 0;119 scrollTimer= 0;120 cursor= 0;199 this->scroll_ = 0; 200 this->scrollTimer_ = 0; 201 this->cursor_ = 0; 121 202 122 203 // create overlay and elements 123 om= &Ogre::OverlayManager::getSingleton();204 this->om_ = &Ogre::OverlayManager::getSingleton(); 124 205 125 206 // create a container 126 consoleOverlayContainer = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", "container"));127 consoleOverlayContainer->setMetricsMode(Ogre::GMM_RELATIVE);128 consoleOverlayContainer->setPosition((1-REL_WIDTH)/2, 0);129 consoleOverlayContainer->setDimensions(REL_WIDTH,REL_HEIGHT);207 this->consoleOverlayContainer_ = static_cast<OverlayContainer*>(this->om_->createOverlayElement("Panel", "InGameConsoleContainer")); 208 this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE); 209 this->consoleOverlayContainer_->setPosition((1 - InGameConsole::REL_WIDTH) / 2, 0); 210 this->consoleOverlayContainer_->setDimensions(InGameConsole::REL_WIDTH, InGameConsole::REL_HEIGHT); 130 211 131 212 // create BorderPanel 132 consoleOverlayBorder = static_cast<BorderPanelOverlayElement*>(om->createOverlayElement("BorderPanel", "borderPanel"));133 consoleOverlayBorder->setMetricsMode(Ogre::GMM_PIXELS);134 consoleOverlayBorder->setMaterialName("ConsoleCenter");213 this->consoleOverlayBorder_ = static_cast<BorderPanelOverlayElement*>(this->om_->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel")); 214 this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS); 215 this->consoleOverlayBorder_->setMaterialName("ConsoleCenter"); 135 216 // set parameters for border 136 consoleOverlayBorder->setBorderSize(16, 16, 0, 16);137 consoleOverlayBorder->setBorderMaterialName("ConsoleBorder");138 consoleOverlayBorder->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);139 consoleOverlayBorder->setRightBorderUV(0.5, 0.49, 1.0, 0.5);140 consoleOverlayBorder->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);141 consoleOverlayBorder->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);142 consoleOverlayBorder->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);217 this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16); 218 this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder"); 219 this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51); 220 this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5); 221 this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0); 222 this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); 223 this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); 143 224 144 225 // create the text lines 145 consoleOverlayTextAreas = new TextAreaOverlayElement*[LINES]; 146 for(int i = 0; i<LINES; i++){ 147 consoleOverlayTextAreas[i] = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "textArea"+Ogre::StringConverter::toString(i))); 148 consoleOverlayTextAreas[i]->setMetricsMode(Ogre::GMM_PIXELS); 149 consoleOverlayTextAreas[i]->setFontName("Console"); 150 consoleOverlayTextAreas[i]->setCharHeight(20); 151 consoleOverlayTextAreas[i]->setParameter("colour_top", "0.21 0.69 0.21"); 152 consoleOverlayTextAreas[i]->setLeft(8); 153 consoleOverlayTextAreas[i]->setCaption(""); 226 this->consoleOverlayTextAreas_ = new TextAreaOverlayElement*[LINES]; 227 for (int i = 0; i < LINES; i++) 228 { 229 this->consoleOverlayTextAreas_[i] = static_cast<TextAreaOverlayElement*>(this->om_->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i))); 230 this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS); 231 this->consoleOverlayTextAreas_[i]->setFontName("Console"); 232 this->consoleOverlayTextAreas_[i]->setCharHeight(18); 233 this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21"); 234 this->consoleOverlayTextAreas_[i]->setLeft(8); 235 this->consoleOverlayTextAreas_[i]->setCaption(""); 154 236 } 155 237 156 238 // create noise 157 consoleOverlayNoise = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "noise")); 158 consoleOverlayNoise->setMetricsMode(Ogre::GMM_PIXELS); 159 consoleOverlayNoise->setPosition(5,0); 160 consoleOverlayNoise->setMaterialName("ConsoleNoise"); 161 162 consoleOverlay = om->create("Console"); 163 consoleOverlay->add2D(consoleOverlayContainer); 164 consoleOverlayContainer->addChild(consoleOverlayBorder); 165 //comment following line to disable noise 166 consoleOverlayContainer->addChild(consoleOverlayNoise); 167 for(int i = 0; i<LINES; i++) consoleOverlayContainer->addChild(consoleOverlayTextAreas[i]); 168 resize(); 239 this->consoleOverlayNoise_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleNoise")); 240 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS); 241 this->consoleOverlayNoise_->setPosition(5,0); 242 this->consoleOverlayNoise_->setMaterialName("ConsoleNoise"); 243 244 this->consoleOverlay_ = this->om_->create("InGameConsoleConsole"); 245 this->consoleOverlay_->add2D(this->consoleOverlayContainer_); 246 this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_); 247 //comment following line to disable noise 248 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 249 for (int i = 0; i < LINES; i++) 250 this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]); 251 252 this->resize(); 169 253 170 254 // move overlay "above" the top edge of the screen 171 255 // we take -1.2 because the border mkes the panel bigger 172 consoleOverlayContainer->setTop(-1.2*REL_HEIGHT);256 this->consoleOverlayContainer_->setTop(-1.2 * InGameConsole::REL_HEIGHT); 173 257 // show overlay 174 consoleOverlay->show(); 175 176 COUT(3) << "Info: InGameConsole initialized" << std::endl; 177 } 178 179 /** 180 @brief used to control the actual scrolling and cursor 181 */ 182 void InGameConsole::tick(float dt){ 183 scrollTimer += dt; 184 if(scrollTimer >= 0.01){ 185 float top = consoleOverlayContainer->getTop(); 186 scrollTimer = 0; 187 if(scroll!=0){ 258 this->consoleOverlay_->show(); 259 260 COUT(4) << "Info: InGameConsole initialized" << std::endl; 261 } 262 263 /** 264 @brief Resizes the console elements. Call if window size changes. 265 */ 266 void InGameConsole::resize() 267 { 268 this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 269 this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 270 this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH); 271 this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT); 272 this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10); 273 this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5); 274 275 // now adjust the text lines... 276 this->desiredTextWidth_ = (int) (this->windowW_ * InGameConsole::REL_WIDTH) - 12; 277 278 if (LINES > 0) 279 this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH)); 280 else 281 this->maxCharsPerLine_ = 10; 282 283 for (int i = 0; i < LINES; i++) 284 { 285 this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_); 286 this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i); 287 } 288 289 this->linesChanged(); 290 } 291 292 /** 293 @brief Used to control the actual scrolling and the cursor. 294 */ 295 void InGameConsole::tick(float dt) 296 { 297 this->scrollTimer_ += dt; 298 if (this->scrollTimer_ >= 0.01) 299 { 300 float top = this->consoleOverlayContainer_->getTop(); 301 this->scrollTimer_ = 0; 302 if (this->scroll_ != 0) 303 { 188 304 // scroll 189 top = top + 0.02 *scroll;190 consoleOverlayContainer->setTop(top);305 top = top + 0.02 * this->scroll_; 306 this->consoleOverlayContainer_->setTop(top); 191 307 } 192 if(top <= -1.2*REL_HEIGHT){ 308 if (top <= -1.2 * InGameConsole::REL_HEIGHT) 309 { 193 310 // window has completely scrolled up 194 scroll = 0; 195 consoleOverlay->hide(); 196 active = false; 311 this->scroll_ = 0; 312 this->consoleOverlay_->hide(); 313 this->active_ = false; 314 Shell::getInstance().unregisterListener(this); 197 315 } 198 if(top >= 0){ 316 if (top >= 0) 317 { 199 318 // window has completely scrolled down 200 scroll= 0;201 consoleOverlayContainer->setTop(0);202 active= true;319 this->scroll_ = 0; 320 this->consoleOverlayContainer_->setTop(0); 321 this->active_ = true; 203 322 } 204 323 } 205 324 206 cursor += dt; 207 if(cursor >= 2*BLINK) cursor = 0; 208 print(convert2UTF(this->ib_->get())); 209 210 // this creates a flickering effect 211 consoleOverlayNoise->setTiling(1, rand()%5+1); 212 } 213 214 /** 215 @brief resizes the console elements. call if window size changes 216 */ 217 void InGameConsole::resize(){ 218 windowW = GraphicsEngine::getSingleton().getWindowWidth(); 219 windowH = GraphicsEngine::getSingleton().getWindowHeight(); 220 consoleOverlayBorder->setWidth((int) windowW*REL_WIDTH); 221 consoleOverlayBorder->setHeight((int) windowH*REL_HEIGHT); 222 consoleOverlayNoise->setWidth((int) windowW*REL_WIDTH - 10); 223 consoleOverlayNoise->setHeight((int) windowH*REL_HEIGHT - 5); 224 // now adjust the text lines... 225 for(int i = 0; i<LINES; i++){ 226 consoleOverlayTextAreas[i]->setWidth(windowW*REL_WIDTH); 227 consoleOverlayTextAreas[i]->setTop((int)windowH*REL_HEIGHT - 24 - 16*i); 228 } 229 } 230 231 /** 232 @brief shows console 233 */ 234 void InGameConsole::activate(){ 235 consoleOverlay->show(); 325 this->cursor_ += dt; 326 if (this->cursor_ >= 2 * InGameConsole::BLINK) 327 this->cursor_ = 0; 328 329 if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|') 330 { 331 this->cursorSymbol_ = ' '; 332 this->cursorChanged(); 333 } 334 else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ') 335 { 336 this->cursorSymbol_ = '|'; 337 this->cursorChanged(); 338 } 339 340 // this creates a flickering effect 341 this->consoleOverlayNoise_->setTiling(1, rand() % 5 + 1); 342 } 343 344 /** 345 @brief Shows the InGameConsole. 346 */ 347 void InGameConsole::activate() 348 { 349 InputManager::setInputState(InputManager::IS_CONSOLE); 350 Shell::getInstance().registerListener(this); 351 this->linesChanged(); 352 353 this->consoleOverlay_->show(); 236 354 // just in case window size has changed... 237 resize();355 this->resize(); 238 356 // scroll down 239 scroll= 1;357 this->scroll_ = 1; 240 358 // the rest is done by tick 241 359 } 242 360 243 361 /** 244 @brief hides console 245 */ 246 void InGameConsole::deactivate(){ 362 @brief Hides the InGameConsole. 363 */ 364 void InGameConsole::deactivate() 365 { 247 366 // scroll up 248 scroll= -1;367 this->scroll_ = -1; 249 368 // the rest is done by tick 250 } 251 252 /** 253 @brief prints string to bottom line 254 @param s string to be printed 255 */ 256 void InGameConsole::print(Ogre::UTFString s){ 257 if(cursor>BLINK) consoleOverlayTextAreas[0]->setCaption(">" + s); 258 else consoleOverlayTextAreas[0]->setCaption(">" + s + "_"); 259 } 260 261 /** 262 @brief shifts all lines up and clears the bottom line 263 */ 264 void InGameConsole::newline(){ 265 Ogre::UTFString line; 266 for(int i = LINES-1; i>=1; i--){ 267 line = consoleOverlayTextAreas[i-1]->getCaption(); 268 // don't copy the cursor... 269 int l = line.length(); 270 if(!line.empty() && line.substr(l-1) == "_") line.erase(l-1); 271 consoleOverlayTextAreas[i]->setCaption(line); 272 } 273 consoleOverlayTextAreas[0]->setCaption(">"); 274 } 275 276 Ogre::UTFString InGameConsole::convert2UTF(std::string s){ 369 InputManager::setInputState(InputManager::IS_NORMAL); 370 } 371 372 /** 373 @brief Activates the console. 374 */ 375 void InGameConsole::openConsole() 376 { 377 InGameConsole::getInstance().activate(); 378 } 379 380 /** 381 @brief Deactivates the console. 382 */ 383 void InGameConsole::closeConsole() 384 { 385 InGameConsole::getInstance().deactivate(); 386 } 387 388 /** 389 @brief Shifts all output lines one line up 390 */ 391 void InGameConsole::shiftLines() 392 { 393 for (unsigned int i = LINES - 1; i > 1; --i) 394 { 395 this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption()); 396 this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop()); 397 this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom()); 398 } 399 } 400 401 void InGameConsole::colourLine(int colourcode, int index) 402 { 403 if (colourcode == -1) 404 { 405 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00)); 406 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00)); 407 } 408 else if (colourcode == 1) 409 { 410 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00)); 411 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00)); 412 } 413 else if (colourcode == 2) 414 { 415 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00)); 416 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00)); 417 } 418 else if (colourcode == 3) 419 { 420 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00)); 421 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00)); 422 } 423 else if (colourcode == 4) 424 { 425 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00)); 426 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00)); 427 } 428 else if (colourcode == 5) 429 { 430 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00)); 431 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00)); 432 } 433 else 434 { 435 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00)); 436 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00)); 437 } 438 } 439 440 /** 441 @brief Prints string to bottom line. 442 @param s String to be printed 443 */ 444 void InGameConsole::print(const std::string& text, int index, bool alwaysShift) 445 { 446 char level = 0; 447 if (text.size() > 0) 448 level = text[0]; 449 450 std::string output = text; 451 452 if (level >= -1 && level <= 5) 453 output.erase(0, 1); 454 455 if (LINES > index) 456 { 457 this->colourLine(level, index); 458 459 if (index > 0) 460 { 461 unsigned int linesUsed = 1; 462 while (output.size() > this->maxCharsPerLine_) 463 { 464 ++linesUsed; 465 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output.substr(0, this->maxCharsPerLine_))); 466 output.erase(0, this->maxCharsPerLine_); 467 output.insert(0, 1, ' '); 468 if (linesUsed > numLinesShifted_ || alwaysShift) 469 this->shiftLines(); 470 this->colourLine(level, index); 471 } 472 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output)); 473 this->numLinesShifted_ = linesUsed; 474 } 475 else 476 { 477 if (output.size() > this->maxCharsPerLine_) 478 { 479 if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_) 480 this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition(); 481 else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1)) 482 this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1; 483 484 output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_); 485 } 486 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output)); 487 } 488 } 489 } 490 491 /** 492 @brief Converts a string into an Ogre::UTFString. 493 @param s The string to convert 494 @return The converted string 495 */ 496 Ogre::UTFString InGameConsole::convert2UTF(std::string s) 497 { 277 498 Ogre::UTFString utf; 278 int i;279 499 Ogre::UTFString::code_point cp; 280 for (i=0; i<(int)s.size(); ++i){ 500 for (unsigned int i = 0; i < s.size(); ++i) 501 { 281 502 cp = s[i]; 282 503 cp &= 0xFF; -
code/branches/network/src/orxonox/console/InGameConsole.h
r1214 r1446 37 37 38 38 #include "core/Tickable.h" 39 #include "core/ InputBuffer.h"39 #include "core/Shell.h" 40 40 41 41 42 42 namespace orxonox 43 43 { 44 class _OrxonoxExport InGameConsole : public InputBufferListener44 class _OrxonoxExport InGameConsole : public Tickable, public ShellListener 45 45 { 46 46 public: 47 InGameConsole(InputBuffer* ib); 48 ~InGameConsole(); 49 void listen(); 50 void execute(); 51 void hintandcomplete(); 52 void clear(); 53 void removeLast(); 54 void exit(); 55 void init(); 47 static InGameConsole& getInstance(); 48 49 void setConfigValues(); 56 50 void tick(float dt); 51 57 52 void activate(); 58 53 void deactivate(); 54 void resize(); 55 56 static void openConsole(); 57 static void closeConsole(); 59 58 60 59 private: 61 void resize(); 62 void print(Ogre::UTFString s); 63 void newline(); 64 Ogre::UTFString convert2UTF(std::string s); 60 InGameConsole(); 61 InGameConsole(const InGameConsole& other); 62 ~InGameConsole(); 65 63 66 int windowW; 67 int windowH; 68 int scroll; 69 float scrollTimer; 70 float cursor; 71 bool active; 72 InputBuffer* ib_; 73 Ogre::OverlayManager* om; 74 Ogre::Overlay* consoleOverlay; 75 Ogre::OverlayContainer* consoleOverlayContainer; 76 Ogre::PanelOverlayElement* consoleOverlayNoise; 77 Ogre::BorderPanelOverlayElement* consoleOverlayBorder; 78 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas; 64 virtual void linesChanged(); 65 virtual void onlyLastLineChanged(); 66 virtual void lineAdded(); 67 virtual void inputChanged(); 68 virtual void cursorChanged(); 69 virtual void exit(); 70 71 void init(); 72 void shiftLines(); 73 void colourLine(int colourcode, int index); 74 void print(const std::string& text, int index, bool alwaysShift = false); 75 static Ogre::UTFString convert2UTF(std::string s); 76 77 static float REL_WIDTH; 78 static float REL_HEIGHT; 79 static float BLINK; 80 81 int windowW_; 82 int windowH_; 83 int desiredTextWidth_; 84 unsigned int maxCharsPerLine_; 85 unsigned int numLinesShifted_; 86 int scroll_; 87 float scrollTimer_; 88 float cursor_; 89 unsigned int inputWindowStart_; 90 char cursorSymbol_; 91 bool active_; 92 Ogre::OverlayManager* om_; 93 Ogre::Overlay* consoleOverlay_; 94 Ogre::OverlayContainer* consoleOverlayContainer_; 95 Ogre::PanelOverlayElement* consoleOverlayNoise_; 96 Ogre::BorderPanelOverlayElement* consoleOverlayBorder_; 97 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_; 79 98 }; 80 99 } -
code/branches/network/src/orxonox/hud/HUD.cc
r1422 r1446 47 47 namespace orxonox 48 48 { 49 ConsoleCommandShortcut(HUD, cycleNavigationFocus,AccessLevel::User);49 SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User); 50 50 51 51 using namespace Ogre; -
code/branches/network/src/orxonox/objects/Ambient.cc
r1418 r1446 47 47 namespace orxonox 48 48 { 49 ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1));49 SetConsoleCommand(Ambient, setAmbientLightTest, false).setDefaultValues(ColourValue(1, 1, 1, 1)).setAccessLevel(AccessLevel::Offline); 50 50 51 51 CreateFactory(Ambient); -
code/branches/network/src/orxonox/objects/SpaceShip.cc
r1443 r1446 51 51 namespace orxonox 52 52 { 53 ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);54 ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true);55 ConsoleCommand(SpaceShip, moveLongitudinal, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);56 ConsoleCommand(SpaceShip, moveLateral, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);57 ConsoleCommand(SpaceShip, moveYaw, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);58 ConsoleCommand(SpaceShip, movePitch, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);59 ConsoleCommand(SpaceShip, moveRoll, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);60 ConsoleCommand(SpaceShip, fire, AccessLevel::User, true).setKeybindMode(KeybindMode::OnHold);61 ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);62 ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);63 ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false);53 SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug); 54 SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User); 55 SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 56 SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 57 SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 58 SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 59 SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 60 SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold); 61 SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug); 62 SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug); 63 SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug); 64 64 65 65 CreateFactory(SpaceShip); -
code/branches/network/src/orxonox/tools/Timer.cc
r1293 r1446 27 27 */ 28 28 29 #include <set> 30 29 31 #include "OrxonoxStableHeaders.h" 30 32 #include "Timer.h" … … 37 39 namespace orxonox 38 40 { 39 ConsoleCommandShortcutExtern(delay, AccessLevel::None); 41 SetConsoleCommandShortcutExtern(delay); 42 SetConsoleCommandShortcutExtern(killdelays); 43 44 static std::set<StaticTimer*> delaytimerset; 40 45 41 46 /** … … 47 52 { 48 53 StaticTimer *delaytimer = new StaticTimer(); 54 delaytimerset.insert(delaytimer); 55 49 56 ExecutorStatic* delayexecutor = createExecutor(createFunctor(&executeDelayedCommand)); 50 57 delayexecutor->setDefaultValues(delaytimer, command); … … 61 68 CommandExecutor::execute(command); 62 69 delete timer; 70 delaytimerset.erase(timer); 71 } 72 73 /** 74 @brief Kills all delayed commands. 75 */ 76 void killdelays() 77 { 78 for (std::set<StaticTimer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it) 79 delete (*it); 80 81 delaytimerset.clear(); 63 82 } 64 83 -
code/branches/network/src/orxonox/tools/Timer.h
r1056 r1446 69 69 class StaticTimer; 70 70 void delay(float delay, const std::string& command); 71 void killdelays(); 71 72 void executeDelayedCommand(StaticTimer* timer, const std::string& command); 72 73
Note: See TracChangeset
for help on using the changeset viewer.