Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/InGameConsole.cc @ 9287

Last change on this file since 9287 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
  • Property svn:eol-style set to native
File size: 23.6 KB
RevLine 
[1505]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Felix Schulthess
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29
30#include "InGameConsole.h"
31
[3280]32#include <algorithm>
[1505]33#include <string>
34#include <OgreOverlay.h>
35#include <OgreOverlayElement.h>
36#include <OgreOverlayManager.h>
37#include <OgreOverlayContainer.h>
[3196]38#include <OgreBorderPanelOverlayElement.h>
39#include <OgreTextAreaOverlayElement.h>
[1633]40#include <OgreFontManager.h>
41#include <OgreFont.h>
[1505]42
[5929]43#include "util/Clock.h"
44#include "util/Convert.h"
[1633]45#include "util/Math.h"
[6417]46#include "util/DisplayStringConversions.h"
[7284]47#include "util/ScopedSingletonManager.h"
[8858]48#include "util/output/MemoryWriter.h"
[1505]49#include "core/CoreIncludes.h"
50#include "core/ConfigValueIncludes.h"
[7284]51#include "core/command/ConsoleCommand.h"
[7689]52#include "core/GUIManager.h"
[1535]53#include "core/input/InputManager.h"
[3327]54#include "core/input/InputState.h"
[1755]55#include "core/input/InputBuffer.h"
[7689]56#include "core/LuaState.h"
[1505]57
58namespace orxonox
59{
[1784]60    const int LINES = 30;
[8858]61    const float CHAR_WIDTH = 8.0f; // fix this please - determine the char-width dynamically
[1784]62
[8079]63    SetConsoleCommand("InGameConsole", "openConsole", &InGameConsole::openConsole);
64    SetConsoleCommand("InGameConsole", "closeConsole", &InGameConsole::closeConsole);
[1505]65
[5929]66    ManageScopedSingleton(InGameConsole, ScopeID::Graphics, false);
[1755]67
[1505]68    /**
69        @brief Constructor: Creates and initializes the InGameConsole.
70    */
[1755]71    InGameConsole::InGameConsole()
[6417]72        : shell_(new Shell("InGameConsole", true))
73        , bShowCursor_(false)
[6105]74        , consoleOverlay_(0)
[1755]75        , consoleOverlayContainer_(0)
76        , consoleOverlayNoise_(0)
77        , consoleOverlayCursor_(0)
78        , consoleOverlayBorder_(0)
79        , consoleOverlayTextAreas_(0)
[1878]80        , inputState_(0)
[1505]81    {
82        RegisterObject(InGameConsole);
83
[1540]84        this->bActive_ = false;
[1577]85        this->cursor_ = 0.0f;
[1505]86        this->cursorSymbol_ = '|';
87        this->inputWindowStart_ = 0;
88        this->numLinesShifted_ = LINES - 1;
[1577]89        // for the beginning, don't scroll
90        this->scroll_ = 0;
[1505]91
92        this->setConfigValues();
[5929]93        this->initialise();
[8729]94
95        // Output buffering is not anymore needed. Not the best solution to do
96        // this here, but there isn't much of another way.
[8858]97        MemoryWriter::getInstance().disable();
[1505]98    }
99
100    /**
101        @brief Destructor: Destroys the TextAreas.
102    */
[3301]103    InGameConsole::~InGameConsole()
[1505]104    {
[1755]105        this->deactivate();
[1505]106
[1755]107        // destroy the input state previously created (InputBuffer gets destroyed by the Shell)
[3327]108        InputManager::getInstance().destroyState("console");
[1755]109
[6105]110        // destroy the underlaying shell
111        this->shell_->destroy();
112
[1755]113        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
114        if (ovMan)
115        {
116            if (this->consoleOverlayNoise_)
117                Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayNoise_);
118            if (this->consoleOverlayCursor_)
119                Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayCursor_);
[1819]120            Ogre::FontManager::getSingleton().remove("MonofurConsole");
[1755]121            if (this->consoleOverlayBorder_)
122                Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayBorder_);
123            if (this->consoleOverlayTextAreas_)
124            {
125                for (int i = 0; i < LINES; i++)
126                {
127                    if (this->consoleOverlayTextAreas_[i])
[7689]128                        Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayTextAreas_[i]);
[1755]129                    this->consoleOverlayTextAreas_[i] = 0;
130                }
131
132            }
133            if (this->consoleOverlayContainer_)
134                Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayContainer_);
135        }
136        if (this->consoleOverlayTextAreas_)
137        {
138            delete[] this->consoleOverlayTextAreas_;
139            this->consoleOverlayTextAreas_ = 0;
140        }
141
[1819]142        if (this->consoleOverlay_)
143            Ogre::OverlayManager::getSingleton().destroy(consoleOverlay_);
[1505]144    }
145
146    /**
147        @brief Sets the config values, describing the size of the console.
148    */
149    void InGameConsole::setConfigValues()
150    {
[1577]151        SetConfigValue(relativeWidth, 0.8);
152        SetConfigValue(relativeHeight, 0.4);
153        SetConfigValue(blinkTime, 0.5);
154        SetConfigValue(scrollSpeed_, 3.0f);
155        SetConfigValue(noiseSize_, 1.0f);
[1578]156        SetConfigValue(cursorSymbol_, '|');
[1878]157        SetConfigValue(bHidesAllInput_, false).callback(this, &InGameConsole::bHidesAllInputChanged);
[1505]158    }
159
160    /**
[1878]161        @brief Called whenever bHidesAllInput_ changes.
162    */
163    void InGameConsole::bHidesAllInputChanged()
164    {
165        if (inputState_)
166        {
167            if (bHidesAllInput_)
168            {
[3327]169                inputState_->setMouseHandler(&InputHandler::EMPTY);
170                inputState_->setJoyStickHandler(&InputHandler::EMPTY);
[1878]171            }
172            else
173            {
174                inputState_->setMouseHandler(0);
175                inputState_->setJoyStickHandler(0);
176            }
177        }
178    }
179
180    /**
[1577]181        @brief Initializes the InGameConsole.
182    */
[3327]183    void InGameConsole::initialise()
[1577]184    {
[1755]185        // create the corresponding input state
[3327]186        inputState_ = InputManager::getInstance().createInputState("console", false, false, InputStatePriority::Console);
[6105]187        inputState_->setKeyHandler(this->shell_->getInputBuffer());
[1878]188        bHidesAllInputChanged();
[1755]189
[1577]190        // create overlay and elements
191        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
192
193        // create actual overlay
194        this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
195
196        // create a container
[1615]197        this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
[1577]198        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
199        this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
200        this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
201        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
202
203        // create BorderPanel
[1615]204        this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
[1577]205        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
206        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
207        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
208        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
[6502]209        this->consoleOverlayBorder_->setLeftBorderUV(0.0f, 0.49f, 0.5f, 0.51f);
210        this->consoleOverlayBorder_->setRightBorderUV(0.5f, 0.49f, 1.0f, 0.5f);
211        this->consoleOverlayBorder_->setBottomBorderUV(0.49f, 0.5f, 0.51f, 1.0f);
212        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0f, 0.5f, 0.5f, 1.0f);
213        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5f, 0.5f, 1.0f, 1.0f);
[1577]214        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
215
[1633]216        // create a new font to match the requested size exactly
217        Ogre::FontPtr font = static_cast<Ogre::FontPtr>
218            (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
219        font->setType(Ogre::FT_TRUETYPE);
220        font->setSource("Monofur.ttf");
221        font->setTrueTypeSize(18);
222        // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
223        font->setTrueTypeResolution(192);
224        font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
225        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
226
[6417]227        // create noise
228        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
229        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
230        this->consoleOverlayNoise_->setPosition(5,0);
231        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
232        // comment following line to disable noise
233        this->consoleOverlayBorder_->addChild(this->consoleOverlayNoise_);
234
[1577]235        // create the text lines
[1615]236        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
[1577]237        for (int i = 0; i < LINES; i++)
238        {
[3280]239            this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + multi_cast<std::string>(i)));
[1577]240            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
[1633]241            this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
[1577]242            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
243            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
244            this->consoleOverlayTextAreas_[i]->setLeft(8);
245            this->consoleOverlayTextAreas_[i]->setCaption("");
[6417]246            this->consoleOverlayNoise_->addChild(this->consoleOverlayTextAreas_[i]);
[1577]247        }
248
249        // create cursor (also a text area overlay element)
[1615]250        this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
[1577]251        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
[1633]252        this->consoleOverlayCursor_->setFontName("MonofurConsole");
[1577]253        this->consoleOverlayCursor_->setCharHeight(18);
254        this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
255        this->consoleOverlayCursor_->setLeft(7);
[1578]256        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
[6417]257        this->consoleOverlayNoise_->addChild(this->consoleOverlayCursor_);
[1577]258
[3327]259        this->windowResized(this->getWindowWidth(), this->getWindowWidth());
[1577]260
261        // move overlay "above" the top edge of the screen
[5960]262        // we take -1.3 because the border makes the panel bigger
[6502]263        this->consoleOverlayContainer_->setTop(-1.3f * this->relativeHeight);
[1577]264
[8858]265        orxout(internal_info) << "InGameConsole initialized" << endl;
[1577]266    }
267
268    // ###############################
269    // ###  ShellListener methods  ###
270    // ###############################
271
272    /**
[1505]273        @brief Called if all output-lines have to be redrawn.
274    */
275    void InGameConsole::linesChanged()
276    {
[6417]277        Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator();
[1505]278        int max = 0;
279        for (int i = 1; i < LINES; ++i)
280        {
[6105]281            if (it != this->shell_->getEndIterator())
[1505]282            {
283                ++it;
284                max = i;
285            }
286            else
287                break;
288        }
289
290        for (int i = LINES - 1; i > max; --i)
[8858]291            this->print("", Shell::DebugOutput, i, true);
[1505]292
293        for (int i = max; i >= 1; --i)
294        {
295            --it;
[6417]296            this->print(it->first, it->second, i, true);
[1505]297        }
298    }
299
300    /**
301        @brief Called if a new output-line was added.
302    */
303    void InGameConsole::lineAdded()
304    {
305        this->numLinesShifted_ = 0;
306        this->shiftLines();
[8858]307        if (LINES > 1)
308            this->print(this->shell_->getNewestLineIterator()->first, this->shell_->getNewestLineIterator()->second, 1);
[1505]309    }
310
311    /**
312        @brief Called if the text in the input-line has changed.
313    */
314    void InGameConsole::inputChanged()
315    {
316        if (LINES > 0)
[6417]317            this->print(this->shell_->getInput(), Shell::Input, 0);
[1505]318
[6417]319        if (this->shell_->getInput().empty())
[1505]320            this->inputWindowStart_ = 0;
321    }
322
323    /**
324        @brief Called if the position of the cursor in the input-line has changed.
325    */
326    void InGameConsole::cursorChanged()
327    {
[6105]328        unsigned int pos = this->shell_->getCursorPosition() - inputWindowStart_;
[1577]329        if (pos > maxCharsPerLine_)
330            pos = maxCharsPerLine_;
331
332        this->consoleOverlayCursor_->setCaption(std::string(pos,' ') + cursorSymbol_);
[6502]333        this->consoleOverlayCursor_->setTop(static_cast<int>(this->windowH_ * this->relativeHeight) - 24.0f);
[1505]334    }
335
336    /**
[6105]337        @brief Called if a command is about to be executed
338    */
339    void InGameConsole::executed()
340    {
[8858]341        this->shell_->addOutput(this->shell_->getInput(), Shell::Command);
[6105]342    }
343
344    /**
[1505]345        @brief Called if the console gets closed.
346    */
347    void InGameConsole::exit()
348    {
349        this->deactivate();
350    }
351
[1577]352    // ###############################
353    // ###  other external calls   ###
354    // ###############################
355
[1505]356    /**
[1577]357        @brief Used to control the actual scrolling and the cursor.
[1505]358    */
[6417]359    void InGameConsole::preUpdate(const Clock& time)
[1505]360    {
[1577]361        if (this->scroll_ != 0)
362        {
363            float oldTop = this->consoleOverlayContainer_->getTop();
[1505]364
[1577]365            if (this->scroll_ > 0)
366            {
367                // scrolling down
368                // enlarge oldTop a little bit so that this exponential function
369                // reaches 0 before infinite time has passed...
[6502]370                float deltaScroll = (oldTop - 0.01f) * time.getDeltaTime() * this->scrollSpeed_;
[1577]371                if (oldTop - deltaScroll >= 0)
372                {
373                    // window has completely scrolled down
374                    this->consoleOverlayContainer_->setTop(0);
375                    this->scroll_ = 0;
376                }
377                else
378                    this->consoleOverlayContainer_->setTop(oldTop - deltaScroll);
379            }
[1505]380
[1577]381            else
382            {
383                // scrolling up
384                // note: +0.01 for the same reason as when scrolling down
[6502]385                float deltaScroll = (1.3f * this->relativeHeight + 0.01f + oldTop) * time.getDeltaTime() * this->scrollSpeed_;
[5960]386                if (oldTop - deltaScroll <= -1.3 * this->relativeHeight)
[1577]387                {
388                    // window has completely scrolled up
[6502]389                    this->consoleOverlayContainer_->setTop(-1.3f * this->relativeHeight);
[1577]390                    this->scroll_ = 0;
391                    this->consoleOverlay_->hide();
392                }
393                else
394                    this->consoleOverlayContainer_->setTop(oldTop - deltaScroll);
395            }
396        }
[1505]397
[1577]398        if (this->bActive_)
399        {
[2896]400            this->cursor_ += time.getDeltaTime();
[1577]401            if (this->cursor_ >= this->blinkTime)
402            {
403                this->cursor_ = 0;
404                bShowCursor_ = !bShowCursor_;
405                if (bShowCursor_)
406                    this->consoleOverlayCursor_->show();
407                else
408                    this->consoleOverlayCursor_->hide();
409            }
[1505]410
[1577]411            // this creates a flickering effect (extracts exactly 80% of the texture at a random location)
412            float uRand = (rand() & 1023) / 1023.0f * 0.2f;
413            float vRand = (rand() & 1023) / 1023.0f * 0.2f;
414            this->consoleOverlayNoise_->setUV(uRand, vRand, 0.8f + uRand, 0.8f + vRand);
[1505]415        }
416    }
417
418    /**
419        @brief Resizes the console elements. Call if window size changes.
420    */
[2896]421    void InGameConsole::windowResized(unsigned int newWidth, unsigned int newHeight)
[1505]422    {
[1590]423        this->windowW_ = newWidth;
424        this->windowH_ = newHeight;
[6502]425        this->consoleOverlayBorder_->setWidth((float)(int)(this->windowW_* this->relativeWidth));
426        this->consoleOverlayBorder_->setHeight((float)(int)(this->windowH_ * this->relativeHeight));
427        this->consoleOverlayNoise_->setWidth((float)(int)(this->windowW_ * this->relativeWidth) - 10.0f);
428        this->consoleOverlayNoise_->setHeight((float)(int)(this->windowH_ * this->relativeHeight) - 5.0f);
[1601]429        this->consoleOverlayNoise_->setTiling(consoleOverlayNoise_->getWidth() / (50.0f * this->noiseSize_), consoleOverlayNoise_->getHeight() / (50.0f * this->noiseSize_));
[1505]430
431        // now adjust the text lines...
[8858]432        this->desiredTextWidth_ = static_cast<int>(this->windowW_ * this->relativeWidth) - 24;
[1505]433
434        if (LINES > 0)
[3300]435            this->maxCharsPerLine_ = std::max(10U, static_cast<unsigned int>(static_cast<float>(this->desiredTextWidth_) / CHAR_WIDTH));
[1505]436        else
437            this->maxCharsPerLine_ = 10;
438
439        for (int i = 0; i < LINES; i++)
440        {
[6502]441            this->consoleOverlayTextAreas_[i]->setWidth((float)this->desiredTextWidth_);
442            this->consoleOverlayTextAreas_[i]->setTop((float)(int)(this->windowH_ * this->relativeHeight) - 24 - 14*i);
[1505]443        }
444
445        this->linesChanged();
[1538]446        this->cursorChanged();
[1505]447    }
448
[1577]449    // ###############################
450    // ###    internal methods     ###
451    // ###############################
452
[1505]453    /**
[1577]454        @brief Prints string to bottom line.
[7401]455        @param text The string to be printed
456        @param type The type of the text, defines the color
457        @param index The index of the text overlay in which the string will be displayed
458        @param alwaysShift If true the ohter lines in the console are always shifted by one line
[1505]459    */
[6417]460    void InGameConsole::print(const std::string& text, Shell::LineType type, int index, bool alwaysShift)
[1505]461    {
[1577]462        std::string output = text;
463        if (LINES > index)
[1505]464        {
[6417]465            this->colourLine(type, index);
[1505]466
[1577]467            if (index > 0)
[1540]468            {
[1577]469                unsigned int linesUsed = 1;
470                while (output.size() > this->maxCharsPerLine_)
471                {
472                    ++linesUsed;
[6417]473                    this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output.substr(0, this->maxCharsPerLine_)));
[1577]474                    output.erase(0, this->maxCharsPerLine_);
475                    output.insert(0, 1, ' ');
476                    if (linesUsed > numLinesShifted_ || alwaysShift)
477                        this->shiftLines();
[6417]478                    this->colourLine(type, index);
[1577]479                }
[6417]480                this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output));
[1577]481                this->displayedText_ = output;
482                this->numLinesShifted_ = linesUsed;
[1540]483            }
[1577]484            else
[1540]485            {
[1577]486                if (output.size() > this->maxCharsPerLine_)
487                {
[6105]488                    if (this->shell_->getInputBuffer()->getCursorPosition() < this->inputWindowStart_)
489                        this->inputWindowStart_ = this->shell_->getInputBuffer()->getCursorPosition();
490                    else if (this->shell_->getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
491                        this->inputWindowStart_ = this->shell_->getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;
[1540]492
[1577]493                    output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
494                }
495                else
[7689]496                    this->inputWindowStart_ = 0;
[1577]497                this->displayedText_ = output;
[6417]498                this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output));
[1577]499            }
[1505]500        }
501    }
502
503    /**
504        @brief Shows the InGameConsole.
505    */
506    void InGameConsole::activate()
507    {
[1540]508        if (!this->bActive_)
509        {
510            this->bActive_ = true;
[3327]511            InputManager::getInstance().enterState("console");
[6105]512            this->shell_->registerListener(this);
[1505]513
[1590]514            this->windowResized(this->windowW_, this->windowH_);
[1540]515            this->linesChanged();
516            this->cursorChanged();
517            this->consoleOverlay_->show();
518
519            // scroll down
520            this->scroll_ = 1;
521            // the rest is done by tick
522        }
[1505]523    }
524
525    /**
526    @brief Hides the InGameConsole.
527    */
528    void InGameConsole::deactivate()
529    {
[1540]530        if (this->bActive_)
531        {
532            this->bActive_ = false;
[8484]533            GUIManager::getInstance().getLuaState()->doString("inGameConsoleClosed()"); // Notify the SheetManager in lua, that the console has been closed.
[3327]534            InputManager::getInstance().leaveState("console");
[6105]535            this->shell_->unregisterListener(this);
[1540]536
537            // scroll up
538            this->scroll_ = -1;
539            // the rest is done by tick
540        }
[1505]541    }
542
543    /**
544        @brief Shifts all output lines one line up
545    */
546    void InGameConsole::shiftLines()
547    {
548        for (unsigned int i = LINES - 1; i > 1; --i)
549        {
550            this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption());
551            this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop());
552            this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom());
553        }
554    }
555
[6417]556    void InGameConsole::colourLine(Shell::LineType type, int index)
[1505]557    {
[6417]558        ColourValue colourTop, colourBottom;
559        switch (type)
[1505]560        {
[8858]561            case Shell::Message:
562            case Shell::DebugOutput:     colourTop = ColourValue(0.9f, 0.9f, 0.9f); break;
[6417]563
[8858]564            case Shell::UserError:       colourTop = ColourValue(0.9f, 0.0f, 0.0f); break;
565            case Shell::UserWarning:     colourTop = ColourValue(0.9f, 0.5f, 0.0f); break;
566            case Shell::UserStatus:      colourTop = ColourValue(0.0f, 0.9f, 0.0f); break;
567            case Shell::UserInfo:        colourTop = ColourValue(0.0f, 0.8f, 0.8f); break;
[6417]568
[8858]569            case Shell::InternalError:   colourTop = ColourValue(0.5f, 0.0f, 0.0f); break;
570            case Shell::InternalWarning: colourTop = ColourValue(0.5f, 0.2f, 0.0f); break;
571            case Shell::InternalStatus:  colourTop = ColourValue(0.0f, 0.5f, 0.0f); break;
572            case Shell::InternalInfo:    colourTop = ColourValue(0.0f, 0.4f, 0.4f); break;
[6417]573
[8858]574            case Shell::Verbose:         colourTop = ColourValue(0.3f, 0.3f, 0.9f); break;
575            case Shell::VerboseMore:     colourTop = ColourValue(0.2f, 0.2f, 0.7f); break;
576            case Shell::VerboseUltra:    colourTop = ColourValue(0.1f, 0.1f, 0.5f); break;
[6417]577
[8858]578            case Shell::Command:         colourTop = ColourValue(0.8f, 0.2f, 0.8f); break;
579            case Shell::Hint:            colourTop = ColourValue(0.4f, 0.0f, 0.4f); break;
580            case Shell::Input:           colourTop = ColourValue(0.9f, 0.9f, 0.9f); break;
[6417]581
[8858]582            default:                     colourTop = ColourValue(0.5f, 0.5f, 0.5f); break;
583        }
[6417]584
[8858]585        colourBottom = ColourValue(sqrt(colourTop.r), sqrt(colourTop.g), sqrt(colourTop.b));
[6417]586
587        this->consoleOverlayTextAreas_[index]->setColourTop   (colourTop);
588        this->consoleOverlayTextAreas_[index]->setColourBottom(colourBottom);
[1505]589    }
590
[6105]591    // ################################
592    // ###      static methods      ###
593    // ################################
[1577]594
595    /**
596        @brief Activates the console.
597    */
598    /*static*/ void InGameConsole::openConsole()
[1505]599    {
[1577]600        InGameConsole::getInstance().activate();
[1505]601    }
602
603    /**
[1577]604        @brief Deactivates the console.
[1505]605    */
[1577]606    /*static*/ void InGameConsole::closeConsole()
[1505]607    {
[7689]608        GUIManager::getInstance().getLuaState()->doString("inGameConsoleClosed()");  // Notify the SheetManager in lua, that the console has been closed, but not by ESC.
[1577]609        InGameConsole::getInstance().deactivate();
[1505]610    }
[7689]611
[1505]612}
Note: See TracBrowser for help on using the repository browser.