Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2008, 1:11:51 AM (16 years ago)
Author:
landauf
Message:
  • fixed a bug in CommandExecutor
  • InGameConsole wraps now too long output lines and does something similar for the input line
File:
1 edited

Legend:

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

    r1341 r1416  
    4343#include "core/ConsoleCommand.h"
    4444#include "core/InputManager.h"
     45#include "util/Math.h"
     46
    4547#include "GraphicsEngine.h"
    4648
    4749#define LINES 30
     50#define CHAR_WIDTH 7.85 // fix this please - determine the char-width dynamically
    4851
    4952namespace orxonox
     
    6871        this->cursor_ = 0.0;
    6972        this->cursorSymbol_ = '|';
     73        this->inputWindowStart_ = 0;
     74        this->numLinesShifted_ = LINES - 1;
    7075
    7176        this->init();
     
    111116    {
    112117        std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();
    113         for (int i = 1; i < LINES; i++)
     118        int max = 0;
     119        for (int i = 1; i < LINES; ++i)
    114120        {
    115121            if (it != Shell::getInstance().getEndIterator())
    116122            {
    117                 this->print(*it, i);
    118123                ++it;
     124                max = i;
    119125            }
    120126            else
    121             {
    122                 this->print("", i);
    123             }
     127                break;
     128        }
     129
     130        for (int i = LINES - 1; i > max; --i)
     131            this->print("", i, true);
     132
     133        for (int i = max; i >= 1; --i)
     134        {
     135            --it;
     136            this->print(*it, i, true);
    124137        }
    125138    }
     
    139152    void InGameConsole::lineAdded()
    140153    {
    141         for (unsigned int i = LINES - 1; i > 1; --i)
    142         {
    143             this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption());
    144             this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop());
    145             this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom());
    146         }
    147 
     154        this->numLinesShifted_ = 0;
     155        this->shiftLines();
    148156        this->onlyLastLineChanged();
    149157    }
     
    156164        if (LINES > 0)
    157165            this->print(Shell::getInstance().getInput(), 0);
     166
     167        if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0)
     168            this->inputWindowStart_ = 0;
    158169    }
    159170
     
    246257
    247258        COUT(4) << "Info: InGameConsole initialized" << std::endl;
     259    }
     260
     261    /**
     262        @brief Resizes the console elements. Call if window size changes.
     263    */
     264    void InGameConsole::resize()
     265    {
     266        this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
     267        this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
     268        this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH);
     269        this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT);
     270        this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10);
     271        this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5);
     272
     273        // now adjust the text lines...
     274        this->desiredTextWidth_ = (int) (this->windowW_ * InGameConsole::REL_WIDTH) - 12;
     275
     276        if (LINES > 0)
     277            this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH));
     278        else
     279            this->maxCharsPerLine_ = 10;
     280
     281        for (int i = 0; i < LINES; i++)
     282        {
     283            this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_);
     284            this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i);
     285        }
     286
     287        this->linesChanged();
    248288    }
    249289
     
    301341
    302342    /**
    303         @brief Resizes the console elements. Call if window size changes.
    304     */
    305     void InGameConsole::resize()
    306     {
    307         this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
    308         this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
    309         this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH);
    310         this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT);
    311         this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10);
    312         this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5);
    313         // now adjust the text lines...
    314         for (int i = 0; i < LINES; i++)
    315         {
    316             this->consoleOverlayTextAreas_[i]->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH);
    317             this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i);
    318         }
    319     }
    320 
    321     /**
    322343        @brief Shows the InGameConsole.
    323344    */
     
    362383
    363384    /**
     385        @brief Shifts all output lines one line up
     386    */
     387    void InGameConsole::shiftLines()
     388    {
     389        for (unsigned int i = LINES - 1; i > 1; --i)
     390        {
     391            this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption());
     392            this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop());
     393            this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom());
     394        }
     395    }
     396
     397    void InGameConsole::colourLine(int colourcode, int index)
     398    {
     399        if (colourcode == -1)
     400        {
     401            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.90, 0.90, 0.90, 1.00));
     402            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00));
     403        }
     404        else if (colourcode == 1)
     405        {
     406            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.25, 0.25, 1.00));
     407            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00));
     408        }
     409        else if (colourcode == 2)
     410        {
     411            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.50, 0.20, 1.00));
     412            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00));
     413        }
     414        else if (colourcode == 3)
     415        {
     416            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.50, 0.50, 0.95, 1.00));
     417            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00));
     418        }
     419        else if (colourcode == 4)
     420        {
     421            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.65, 0.48, 0.44, 1.00));
     422            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00));
     423        }
     424        else if (colourcode == 5)
     425        {
     426            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.40, 0.20, 0.40, 1.00));
     427            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00));
     428        }
     429        else
     430        {
     431            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.21, 0.69, 0.21, 1.00));
     432            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00));
     433        }
     434    }
     435
     436    /**
    364437        @brief Prints string to bottom line.
    365438        @param s String to be printed
    366439    */
    367     void InGameConsole::print(const std::string& text, int index)
     440    void InGameConsole::print(const std::string& text, int index, bool alwaysShift)
    368441    {
    369442        char level = 0;
     
    378451        if (LINES > index)
    379452        {
    380             if (level == -1)
     453            this->colourLine(level, index);
     454
     455            if (index > 0)
    381456            {
    382                 this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.90, 0.90, 0.90, 1.00));
    383                 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00));
    384             }
    385             else if (level == 1)
    386             {
    387                 this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.25, 0.25, 1.00));
    388                 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00));
    389             }
    390             else if (level == 2)
    391             {
    392                 this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.50, 0.20, 1.00));
    393                 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00));
    394             }
    395             else if (level == 3)
    396             {
    397                 this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.50, 0.50, 0.95, 1.00));
    398                 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00));
    399             }
    400             else if (level == 4)
    401             {
    402                 this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.65, 0.48, 0.44, 1.00));
    403                 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00));
    404             }
    405             else if (level == 5)
    406             {
    407                 this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.40, 0.20, 0.40, 1.00));
    408                 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00));
     457                unsigned int linesUsed = 1;
     458                while (output.size() > this->maxCharsPerLine_)
     459                {
     460                    ++linesUsed;
     461                    this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output.substr(0, this->maxCharsPerLine_)));
     462                    output.erase(0, this->maxCharsPerLine_);
     463                    output.insert(0, 1, ' ');
     464                    if (linesUsed > numLinesShifted_ || alwaysShift)
     465                        this->shiftLines();
     466                    this->colourLine(level, index);
     467                }
     468                this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
     469                this->numLinesShifted_ = linesUsed;
    409470            }
    410471            else
    411472            {
    412                 this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.21, 0.69, 0.21, 1.00));
    413                 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00));
     473                if (output.size() > this->maxCharsPerLine_)
     474                {
     475                    if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_)
     476                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition();
     477                    else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
     478                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1;
     479
     480                    output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
     481                }
     482                this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
    414483            }
    415 
    416             this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
    417484        }
    418485    }
Note: See TracChangeset for help on using the changeset viewer.