Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 19, 2008, 2:33:09 AM (16 years ago)
Author:
landauf
Message:

The InGameConsole is now using the new Shell. There's a clear separation between the two classes: InGameConsole implements all graphical parts of the console (and has a tick), while Shell handles the internal actions (like listening on input and output changes). That's why InGameConsole has no longer it's own InputBuffer and doesn't care about command-executing or anything else.

There are currently three new features:

  • Every output through COUT(level) is now visible in the InGameConsole, provided the configured output-level for the shell matches. default: 1 (only forced output and errors)
  • The cursor in the input-line is movable with the left and right arrow keys (home and end works too)
  • You can scroll through all output-lines by pressing page up and page down

There's another feature to come, providing a command history, accessible with up and down arrow keys, but I couldn't finish it yet, because there's still a bug, causing Orxonox to scroll through the entire memory - that's maybe a bit too much history ;)

Location:
code/branches/console/src/orxonox/console
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/orxonox/console/InGameConsole.cc

    r1317 r1322  
    4242#include "core/ConfigValueIncludes.h"
    4343#include "core/ConsoleCommand.h"
     44#include "core/InputManager.h"
    4445#include "GraphicsEngine.h"
    4546
     
    4849namespace orxonox
    4950{
     51    ConsoleCommand(InGameConsole, openConsole, AccessLevel::None, true);
     52    ConsoleCommand(InGameConsole, closeConsole, AccessLevel::None, true);
     53
    5054    using namespace Ogre;
    5155
    5256    float InGameConsole::REL_WIDTH = 0.8;
    5357    float InGameConsole::REL_HEIGHT = 0.4;
    54     float InGameConsole::BLINK = 0.25;
     58    float InGameConsole::BLINK = 0.5;
    5559
    5660    /**
     
    6367        this->active_ = false;
    6468        this->cursor_ = 0.0;
     69        this->cursorSymbol_ = '|';
    6570
    6671        this->init();
    6772        this->setConfigValues();
     73
     74        Shell::getInstance().registerListener(this);
    6875    }
    6976
     
    95102        SetConfigValue(REL_WIDTH, 0.8);
    96103        SetConfigValue(REL_HEIGHT, 0.4);
    97         SetConfigValue(BLINK, 0.25);
     104        SetConfigValue(BLINK, 0.5);
    98105    }
    99106
     
    104111    {
    105112        std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();
    106         for (int i = 1; i < LINES && it != Shell::getInstance().getEndIterator(); i++)
    107         {
    108             this->consoleOverlayTextAreas_[i]->setCaption(*it);
    109             ++it;
     113        for (int i = 1; i < LINES; i++)
     114        {
     115            if (it != Shell::getInstance().getEndIterator())
     116            {
     117                this->print(*it, i);
     118                ++it;
     119            }
     120            else
     121            {
     122                this->print("", i);
     123            }
    110124        }
    111125    }
     
    117131    {
    118132        if (LINES > 1)
    119             this->consoleOverlayTextAreas_[1]->setCaption(*Shell::getInstance().getNewestLineIterator());
     133            this->print(*Shell::getInstance().getNewestLineIterator(), 1);
    120134    }
    121135
     
    125139    void InGameConsole::lineAdded()
    126140    {
    127         for (int i = LINES - 1; i > 1; i--)
    128             this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption());
    129 
    130         if (LINES > 1)
    131             this->consoleOverlayTextAreas_[1]->setCaption(*Shell::getInstance().getNewestLineIterator());
     141        this->linesChanged();
    132142    }
    133143
     
    138148    {
    139149        if (LINES > 0)
    140             this->consoleOverlayTextAreas_[0]->setCaption(Shell::getInstance().getInput());
     150            this->print(Shell::getInstance().getInput(), 0);
    141151    }
    142152
     
    147157    {
    148158        std::string input = Shell::getInstance().getInput();
    149         input.insert(Shell::getInstance().getCursorPosition(), 1, '|');
     159        input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_);
    150160        if (LINES > 0)
    151             this->consoleOverlayTextAreas_[0]->setCaption(input);
     161            this->print(input, 0);
    152162    }
    153163
     
    158168    {
    159169        this->deactivate();
    160         CommandExecutor::execute("set InputMode 2");
     170        InputManager::getSingleton().setInputMode(IM_INGAME);
    161171    }
    162172
     
    266276        if (this->cursor_ >= 2 * InGameConsole::BLINK)
    267277            this->cursor_ = 0;
    268 //        print(convert2UTF(this->ib_->get()));
     278
     279        if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|')
     280        {
     281            this->cursorSymbol_ = ' ';
     282            this->cursorChanged();
     283        }
     284        else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ')
     285        {
     286            this->cursorSymbol_ = '|';
     287            this->cursorChanged();
     288        }
    269289
    270290        // this creates a flickering effect
     
    296316    void InGameConsole::activate()
    297317    {
     318        this->linesChanged();
     319
    298320        this->consoleOverlay_->show();
    299321        // just in case window size has changed...
     
    334356        @param s String to be printed
    335357    */
    336     void InGameConsole::print(Ogre::UTFString s)
    337     {
    338         if (this->cursor_ > InGameConsole::BLINK)
    339             this->consoleOverlayTextAreas_[0]->setCaption(">" + s);
    340         else
    341             this->consoleOverlayTextAreas_[0]->setCaption(">" + s + "_");
    342     }
    343 
    344     /**
    345         @brief Shifts all lines up and clears the bottom line.
    346     */
    347     void InGameConsole::newline()
    348     {
    349         Ogre::UTFString line;
    350         for (int i = LINES - 1; i >= 1; i--)
    351         {
    352             line = this->consoleOverlayTextAreas_[i - 1]->getCaption();
    353             // don't copy the cursor...
    354             int l = line.length();
    355             if (!line.empty() && line.substr(l-1) == "_")
    356                 line.erase(l-1);
    357             this->consoleOverlayTextAreas_[i]->setCaption(line);
    358         }
    359         this->consoleOverlayTextAreas_[0]->setCaption(">");
     358    void InGameConsole::print(const std::string& text, int index)
     359    {
     360        if (LINES > index)
     361            this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(text));
    360362    }
    361363
  • code/branches/console/src/orxonox/console/InGameConsole.h

    r1317 r1322  
    7171            void init();
    7272            void resize();
    73             void print(Ogre::UTFString s);
    74             void newline();
     73            void print(const std::string& text, int index);
    7574            static Ogre::UTFString convert2UTF(std::string s);
    7675
     
    8483            float scrollTimer_;
    8584            float cursor_;
     85            char cursorSymbol_;
    8686            bool active_;
    8787            Ogre::OverlayManager* om_;
Note: See TracChangeset for help on using the changeset viewer.