Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1416


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
Location:
code/branches/console/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/ArgumentCompletionFunctions.cc

    r1402 r1416  
    3535    namespace autocompletion
    3636    {
    37         const std::list<std::pair<std::string, std::string> >& fallback()
     37        std::list<std::pair<std::string, std::string> > fallback()
    3838        {
    39 std::cout << "5_1\n";
    40             static std::list<std::pair<std::string, std::string> > list;
    41 std::cout << "5_2\n";
     39            static std::list<std::pair<std::string, std::string> > list(1, std::pair<std::string, std::string>("muh", "MUH"));
    4240            return list;
    4341        }
  • code/branches/console/src/core/ArgumentCompletionFunctions.h

    r1390 r1416  
    3737    namespace autocompletion
    3838    {
    39         const std::list<std::pair<std::string, std::string> >& fallback();
     39        std::list<std::pair<std::string, std::string> > fallback();
    4040    }
    4141}
  • code/branches/console/src/core/CommandEvaluation.cc

    r1402 r1416  
    5353        this->listOfPossibleIdentifiers_.clear();
    5454        this->listOfPossibleFunctions_.clear();
     55        this->listOfPossibleArguments_.clear();
    5556
    5657        this->functionclass_ = 0;
     
    114115std::cout << "complete: function != 0" << std::endl;
    115116                    if (this->commandTokens_.size() > 1)
    116                         return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size() - 1).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
     117                    {
     118                        if ((this->commandTokens_.size() - 1) >= this->function_->getParamCount())
     119                            return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join());
     120                        else
     121                            return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
     122                    }
    117123                    else
    118124                        return (this->function_->getName() + " ");
     
    125131std::cout << "complete: function != 0" << std::endl;
    126132                    if (this->commandTokens_.size() > 1)
    127                         return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size() - 1).join());
     133                        return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join());
    128134                    else
    129135                        return (this->function_->getName());
     
    144150std::cout << "complete: function und functionclass != 0" << std::endl;
    145151                    if (this->commandTokens_.size() > 2)
    146                         return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
     152                    {
     153                        if ((this->commandTokens_.size() - 2) >= this->function_->getParamCount())
     154                            return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join());
     155                        else
     156                            return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
     157                    }
    147158                    else
    148159                        return (this->functionclass_->getName() + " " + this->function_->getName() + " ");
  • code/branches/console/src/core/CommandExecutor.cc

    r1402 r1416  
    108108    {
    109109        CommandExecutor::parseIfNeeded(command);
     110
     111        if (!CommandExecutor::getEvaluation().isNewCommand())
     112            CommandExecutor::parse(CommandExecutor::getEvaluation().getCommand(), false);
     113        else
     114            CommandExecutor::getEvaluation().setNewCommand(false);
     115
    110116        return CommandExecutor::getEvaluation().complete();
    111117    }
     
    119125    CommandEvaluation CommandExecutor::evaluate(const std::string& command)
    120126    {
    121         CommandExecutor::parse(command, true);
     127        CommandExecutor::parse(command);
    122128        CommandExecutor::getEvaluation().evaluateParams();
    123129        return CommandExecutor::getEvaluation();
     
    126132    void CommandExecutor::parseIfNeeded(const std::string& command)
    127133    {
    128         if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized))
     134        if ((CommandExecutor::getEvaluation().getOriginalCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized))
    129135            CommandExecutor::parse(command);
    130         else if (!CommandExecutor::getEvaluation().isValid())
    131         {
    132             CommandExecutor::getEvaluation().setNewCommand(false);
    133             CommandExecutor::parse(command, false);
    134         }
    135136    }
    136137
     
    301302                if (CommandExecutor::getEvaluation().getFunction())
    302303                {
    303 std::cout << "1\n";
    304304                    unsigned int startindex = 0;
    305305                    if (CommandExecutor::getEvaluation().getState() == CS_Shortcut_Params)
     
    307307                    else if (CommandExecutor::getEvaluation().getState() == CS_Function_Params)
    308308                        startindex = 2;
    309 std::cout << "2\n";
    310309
    311310                    if (CommandExecutor::argumentsGiven() >= startindex)
    312311                    {
    313 std::cout << "3\n";
    314                         if (CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().getFunction()))
    315                         {
    316 std::cout << "4\n";
     312                        if ((CommandExecutor::argumentsGiven() == CommandExecutor::argumentsFinished() || !CommandExecutor::getEvaluation().isNewCommand()) && CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().getFunction()))
     313                        {
    317314                            if (CommandExecutor::getEvaluation().getState() == CS_Shortcut_Params)
    318315                                CommandExecutor::getEvaluation().setState(CS_Shortcut_Finished);
     
    324321                        else
    325322                        {
    326 std::cout << "5\n";
    327 std::cout << "last argument: " << CommandExecutor::getLastArgument() << std::endl;
    328 std::cout << "function: " << CommandExecutor::getEvaluation().getFunction() << std::endl;
    329 std::cout << "functionname: " << CommandExecutor::getEvaluation().getFunction()->getName() << std::endl;
    330 std::cout << "param nr: " << CommandExecutor::getEvaluation().getTokens().size() - startindex << std::endl;
    331323                            CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getTokens().size() - startindex);
    332 std::cout << "6\n";
    333324                            unsigned int numArguments = CommandExecutor::getEvaluation().getListOfPossibleArguments().size();
    334325
    335326                            if (numArguments == 1)
    336327                            {
    337 std::cout << "7\n";
    338328                                // There is exactly one possible argument
    339329                                const std::string* possibleArgument = (*CommandExecutor::getEvaluation().getListOfPossibleArguments().begin()).second;
    340                                 CommandExecutor::parse(CommandExecutor::getEvaluation().getTokens().subSet(0, CommandExecutor::getEvaluation().getTokens().size() - 1 - startindex).join() + " " + (*possibleArgument) + " ");
     330                                if (CommandExecutor::argumentsGiven() > CommandExecutor::argumentsFinished())
     331                                    CommandExecutor::parse(CommandExecutor::getEvaluation().getTokens().subSet(0, CommandExecutor::getEvaluation().getTokens().size() - 1).join() + " " + (*possibleArgument) + " ", false);
     332                                else
     333                                    CommandExecutor::parse(CommandExecutor::getEvaluation().getTokens().subSet(0, CommandExecutor::getEvaluation().getTokens().size()).join() + " " + (*possibleArgument) + " ", false);
     334
    341335                                return;
    342336                            }
    343337
    344 std::cout << "8\n";
    345338                            if ((CommandExecutor::argumentsGiven() > CommandExecutor::argumentsFinished()) && (!CommandExecutor::getEvaluation().isNewCommand()))
    346339                            {
    347 std::cout << "9\n";
    348340                                // There is more than one argument, but the user wants to use this - check if there is a perfect match
    349341                                const std::string* possibleArgument = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getTokens().size() - startindex);
    350342                                if (possibleArgument)
    351343                                {
    352 std::cout << "10\n";
    353344                                    // There is such an argument - use it
    354345                                    CommandExecutor::parse(command + " ", false);
    355346                                    return;
    356347                                }
    357 std::cout << "11\n";
    358348                            }
    359 std::cout << "12\n";
    360                         }
    361 std::cout << "13\n";
     349                        }
    362350
    363351                        // Nothing to do
     
    426414    void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment)
    427415    {
     416        CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().clear();
    428417        std::string lowercase = getLowercase(fragment);
    429418        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
     
    437426    void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
    438427    {
     428        CommandExecutor::getEvaluation().getListOfPossibleFunctions().clear();
    439429        std::string lowercase = getLowercase(fragment);
    440430        if (!identifier)
     
    456446    void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param)
    457447    {
    458 std::cout << "2_1\n";
     448        CommandExecutor::getEvaluation().getListOfPossibleArguments().clear();
    459449        std::string lowercase = getLowercase(fragment);
    460 std::cout << "2_2\n";
    461450        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it)
    462         {
    463 std::cout << "2_3\n";
    464451            if ((*it).first.find(lowercase) == 0 || fragment == "")
    465             {
    466 std::cout << "2_4\n";
    467452                CommandExecutor::getEvaluation().getListOfPossibleArguments().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second));
    468 std::cout << "2_5\n";
    469             }
    470         }
    471 
    472 std::cout << "2_6\n";
     453
    473454        CommandExecutor::getEvaluation().getListOfPossibleArguments().sort(CommandExecutor::compareStringsInList);
    474 std::cout << "2_7\n";
    475455    }
    476456
  • code/branches/console/src/core/ConsoleCommand.cc

    r1402 r1416  
    4141    }
    4242
    43     ConsoleCommand& ConsoleCommand::setArgumentCompletionList(unsigned int param, const std::list<std::pair<std::string, std::string> >& (*function) (void))
     43    ConsoleCommand& ConsoleCommand::setArgumentCompletionList(unsigned int param, std::list<std::pair<std::string, std::string> > (*function) (void))
    4444    {
    4545        if (param < 5)
     
    5252    }
    5353
    54     const std::list<std::pair<std::string, std::string> >& ConsoleCommand::getArgumentCompletionList(unsigned int param) const
     54    const std::list<std::pair<std::string, std::string> >& ConsoleCommand::getArgumentCompletionList(unsigned int param)
    5555    {
    5656        if (param < 5)
    57             return (*this->autocompletionFunction_[param])();
     57            this->argumentList_ = (*this->autocompletionFunction_[param])();
    5858        else
    59             return autocompletion::fallback();
     59            this->argumentList_ = autocompletion::fallback();
     60
     61        return this->argumentList_;
    6062    }
    6163
    62     std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListBegin(unsigned int param) const
     64    std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListBegin(unsigned int param)
    6365    {
    64 std::cout << "3_1: param: " << param << "\n";
    6566        if (param < 5)
    66         {
    67 std::cout << "3_2: >" << this->autocompletionFunction_[param] << "<\n";
    68             return (*this->autocompletionFunction_[param])().begin();
    69         }
     67            this->argumentList_ = (*this->autocompletionFunction_[param])();
    7068        else
    71         {
    72 std::cout << "3_3\n";
    73             return autocompletion::fallback().begin();
    74         }
     69            this->argumentList_ = autocompletion::fallback();
     70
     71        return this->argumentList_.begin();
    7572    }
    7673
    77     std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListEnd(unsigned int param) const
     74    std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListEnd(unsigned int param)
    7875    {
    79 std::cout << "4_1: param: " << param << "\n";
    8076        if (param < 5)
    81         {
    82 std::cout << "4_2: >" << this->autocompletionFunction_[param] << "<\n";
    83             return (*this->autocompletionFunction_[param])().end();
    84         }
     77            this->argumentList_ = (*this->autocompletionFunction_[param])();
    8578        else
    86         {
    87 std::cout << "4_3\n";
    88             return autocompletion::fallback().end();
    89         }
     79            this->argumentList_ = autocompletion::fallback();
     80
     81        return this->argumentList_.end();
    9082    }
    9183}
  • code/branches/console/src/core/ConsoleCommand.h

    r1390 r1416  
    4242    SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut)
    4343
    44 #define SetConsoleCommandGeneric(fakevariable, classname, executor, bCreateShortcut) \
    45     Executor& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ConsoleCommand*)executor, bCreateShortcut)
     44#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
     45    ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ConsoleCommand*)command, bCreateShortcut)
    4646
    4747
     
    5252    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function))
    5353
    54 #define SetConsoleCommandShortcutGeneric(fakevariable, executor) \
    55     Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ConsoleCommand*)executor)
     54#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
     55    ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut((ConsoleCommand*)command)
    5656
    5757
     
    100100                { return this->accessLevel_; }
    101101
    102             ConsoleCommand& setArgumentCompletionList(unsigned int param, const std::list<std::pair<std::string, std::string> >& (*function) (void));
     102            ConsoleCommand& setArgumentCompletionList(unsigned int param, std::list<std::pair<std::string, std::string> > (*function) (void));
    103103
    104             const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList(unsigned int param) const;
    105             std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin(unsigned int param) const;
    106             std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd(unsigned int param) const;
     104            const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList(unsigned int param);
     105            std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin(unsigned int param);
     106            std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd(unsigned int param);
    107107
    108108        private:
    109109            AccessLevel::Level accessLevel_;
    110             const std::list<std::pair<std::string, std::string> >& (*autocompletionFunction_[5]) (void);
     110            std::list<std::pair<std::string, std::string> > (*autocompletionFunction_[5]) (void);
     111            std::list<std::pair<std::string, std::string> > argumentList_;
    111112    };
    112113
  • code/branches/console/src/core/Debug.h

    r1089 r1416  
    206206   COUT ## x
    207207
     208  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
     209   #define COUT0  \
     210    if (getSoftDebugLevel() >= ORX_NONE)  \
     211     COUT_EXEC(0)
     212  #else
     213   #define COUT0 if (ORX_NONE)\
     214    COUT_EXEC(0)
     215  #endif
     216
    208217  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
    209218   #define COUT1  \
     
    256265 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
    257266
    258  #define COUT0 \
    259   COUT_EXEC(0)
    260267#endif /* ifndef COUT */
    261268
     
    274281   CCOUT ## x
    275282
     283  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
     284   #define CCOUT0  \
     285    if (getSoftDebugLevel() >= ORX_NONE)  \
     286     CCOUT_EXEC(0)
     287  #else
     288   #define CCOUT0 if (ORX_NONE)\
     289    CCOUT_EXEC(0)
     290  #endif
     291
    276292  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
    277293   #define CCOUT1  \
     
    324340 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
    325341
    326  #define CCOUT0 \
    327   CCOUT_EXEC(0)
    328342#endif /* ifndef CCOUT */
    329343
  • code/branches/console/src/core/OutputHandler.cc

    r1341 r1416  
    3838namespace orxonox
    3939{
    40     SetConsoleCommandShortcutGeneric(log,     createExecutor(createFunctor(&OutputHandler::log),     "log"    ));
    41     SetConsoleCommandShortcutGeneric(error,   createExecutor(createFunctor(&OutputHandler::error),   "error"  ));
    42     SetConsoleCommandShortcutGeneric(warning, createExecutor(createFunctor(&OutputHandler::warning), "warning"));
    43     SetConsoleCommandShortcutGeneric(info,    createExecutor(createFunctor(&OutputHandler::info),    "info"   ));
    44     SetConsoleCommandShortcutGeneric(debug,   createExecutor(createFunctor(&OutputHandler::debug),   "debug"  ));
     40    SetConsoleCommandShortcutGeneric(log,     createConsoleCommand(createFunctor(&OutputHandler::log),     "log"    ));
     41    SetConsoleCommandShortcutGeneric(error,   createConsoleCommand(createFunctor(&OutputHandler::error),   "error"  ));
     42    SetConsoleCommandShortcutGeneric(warning, createConsoleCommand(createFunctor(&OutputHandler::warning), "warning"));
     43    SetConsoleCommandShortcutGeneric(info,    createConsoleCommand(createFunctor(&OutputHandler::info),    "info"   ));
     44    SetConsoleCommandShortcutGeneric(debug,   createConsoleCommand(createFunctor(&OutputHandler::debug),   "debug"  ));
    4545
    4646    /**
  • code/branches/console/src/core/TclBind.cc

    r1341 r1416  
    3939namespace orxonox
    4040{
    41     SetConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl"));
    42     SetConsoleCommandShortcutGeneric(bgerror, createExecutor(createFunctor(&TclBind::bgerror), "bgerror"));
     41    SetConsoleCommandShortcutGeneric(tcl, createConsoleCommand(createFunctor(&TclBind::tcl), "tcl"));
     42    SetConsoleCommandShortcutGeneric(bgerror, createConsoleCommand(createFunctor(&TclBind::bgerror), "bgerror"));
    4343
    4444    TclBind::TclBind()
  • code/branches/console/src/core/TclThreadManager.cc

    r1341 r1416  
    4848namespace orxonox
    4949{
    50     SetConsoleCommandShortcutGeneric(tclexecute, createExecutor(createFunctor(&TclThreadManager::execute), "tclexecute"));
    51     SetConsoleCommandShortcutGeneric(tclquery,   createExecutor(createFunctor(&TclThreadManager::query),   "tclquery"  ));
     50    SetConsoleCommandShortcutGeneric(tclexecute, createConsoleCommand(createFunctor(&TclThreadManager::execute), "tclexecute"));
     51    SetConsoleCommandShortcutGeneric(tclquery,   createConsoleCommand(createFunctor(&TclThreadManager::query),   "tclquery"  ));
    5252    SetConsoleCommand(TclThreadManager, create,  false);
    5353    SetConsoleCommand(TclThreadManager, destroy, false);
  • code/branches/console/src/orxonox/GraphicsEngine.cc

    r1194 r1416  
    4545#include "core/Debug.h"
    4646#include "core/TclBind.h"
    47 
     47#include "console/InGameConsole.h"
    4848
    4949namespace orxonox {
     
    304304        int h = rw->getHeight();
    305305        InputManager::getSingleton().setWindowExtents(w, h);
     306        InGameConsole::getInstance().resize();
    306307    }
    307308
  • 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    }
  • code/branches/console/src/orxonox/console/InGameConsole.h

    r1322 r1416  
    4848
    4949            void setConfigValues();
    50 
    51             virtual void linesChanged();
    52             virtual void onlyLastLineChanged();
    53             virtual void lineAdded();
    54             virtual void inputChanged();
    55             virtual void cursorChanged();
    56             virtual void exit();
    57 
    5850            void tick(float dt);
    5951
    6052            void activate();
    6153            void deactivate();
     54            void resize();
    6255
    6356            static void openConsole();
     
    6962            ~InGameConsole();
    7063
     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
    7171            void init();
    72             void resize();
    73             void print(const std::string& text, int index);
     72            void shiftLines();
     73            void colourLine(int colourcode, int index);
     74            void print(const std::string& text, int index, bool alwaysShift = false);
    7475            static Ogre::UTFString convert2UTF(std::string s);
    7576
     
    8081            int windowW_;
    8182            int windowH_;
     83            int desiredTextWidth_;
     84            unsigned int maxCharsPerLine_;
     85            unsigned int numLinesShifted_;
    8286            int scroll_;
    8387            float scrollTimer_;
    8488            float cursor_;
     89            unsigned int inputWindowStart_;
    8590            char cursorSymbol_;
    8691            bool active_;
Note: See TracChangeset for help on using the changeset viewer.