Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2008, 5:30:11 AM (16 years ago)
Author:
landauf
Message:

merged console branch into network branch

after several heavy troubles it compiles, but there is still a bug I couldn't fix: orxonox crashes as soon as one presses a key after opening the console… maybe someone else sees the problem?

File:
1 edited

Legend:

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

    r1362 r1446  
    2323 *      Felix Schulthess
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau
    2626 *
    2727 */
     
    4040#include "core/Debug.h"
    4141#include "core/CoreIncludes.h"
     42#include "core/ConfigValueIncludes.h"
    4243#include "core/ConsoleCommand.h"
    4344#include "core/InputManager.h"
     45#include "util/Math.h"
    4446#include "GraphicsEngine.h"
    4547
    46 #define LINES 20
     48#define LINES 30
     49#define CHAR_WIDTH 7.85 // fix this please - determine the char-width dynamically
    4750
    4851namespace orxonox
    4952{
     53    SetConsoleCommand(InGameConsole, openConsole, true);
     54    SetConsoleCommand(InGameConsole, closeConsole, true);
     55
    5056    using namespace Ogre;
    5157
    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    {
    117198        // 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;
    121202
    122203        // create overlay and elements
    123         om = &Ogre::OverlayManager::getSingleton();
     204        this->om_ = &Ogre::OverlayManager::getSingleton();
    124205
    125206        // 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);
    130211
    131212        // 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");
    135216        // 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);
    143224
    144225        // 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("");
    154236        }
    155237
    156238        // 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();
    169253
    170254        // move overlay "above" the top edge of the screen
    171255        // 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);
    173257        // 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            {
    188304                // scroll
    189                 top = top + 0.02*scroll;
    190                 consoleOverlayContainer->setTop(top);
     305                top = top + 0.02 * this->scroll_;
     306                this->consoleOverlayContainer_->setTop(top);
    191307            }
    192             if(top <= -1.2*REL_HEIGHT){
     308            if (top <= -1.2 * InGameConsole::REL_HEIGHT)
     309            {
    193310                // 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);
    197315            }
    198             if(top >= 0){
     316            if (top >= 0)
     317            {
    199318                // 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;
    203322            }
    204323        }
    205324
    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();
    236354        // just in case window size has changed...
    237         resize();
     355        this->resize();
    238356        // scroll down
    239         scroll = 1;
     357        this->scroll_ = 1;
    240358        // the rest is done by tick
    241359    }
    242360
    243361    /**
    244     @brief hides console
    245     */
    246     void InGameConsole::deactivate(){
     362    @brief Hides the InGameConsole.
     363    */
     364    void InGameConsole::deactivate()
     365    {
    247366        // scroll up
    248         scroll = -1;
     367        this->scroll_ = -1;
    249368        // 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    {
    277498        Ogre::UTFString utf;
    278         int i;
    279499        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        {
    281502          cp = s[i];
    282503          cp &= 0xFF;
Note: See TracChangeset for help on using the changeset viewer.