Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 3, 2010, 4:46:00 PM (14 years ago)
Author:
smerkli
Message:

Chatbox done, with cursor goodness and everything. Thanks for the help

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/chat2/src/orxonox/ChatInputHandler.cc

    r6837 r6846  
    3131#include "core/ConsoleCommand.h"
    3232#include "core/CoreIncludes.h"
     33#include "core/GUIManager.h"
     34#include "core/CorePrereqs.h"
     35#include <CEGUIWindow.h>
     36#include <CEGUI/elements/CEGUIListbox.h>
     37#include <CEGUI/elements/CEGUIListboxItem.h>
     38#include <CEGUI/elements/CEGUIListboxTextItem.h>
     39#include <CEGUIWindowManager.h>
    3340#include <string>
    3441
     
    4047    true );
    4148
     49
    4250  /* constructor */
    4351  ChatInputHandler::ChatInputHandler()
     
    4856    /* create necessary objects */
    4957    this->inpbuf = new InputBuffer();
     58    assert( this->inpbuf != NULL );
     59
     60    /* MARK add generation of ChatBox thingy here */
     61    GUIManager::getInstance().loadGUI( "ChatBox" );
    5062
    5163    /* configure the input buffer */
     
    6274  void ChatInputHandler::configureInputBuffer()
    6375  {
    64           /* input has changed */
     76    /* input has changed */
    6577    this->inpbuf->registerListener(this, &ChatInputHandler::inputChanged, true);
    66                
    67                 /* add a line */
     78
     79    /* add a line */
    6880    this->inpbuf->registerListener(this, &ChatInputHandler::addline,         '\r',   false);
    6981    this->inpbuf->registerListener(this, &ChatInputHandler::addline,         '\n',   false);
    7082
    71                 /* backspace */
     83    /* backspace */
    7284    this->inpbuf->registerListener(this, &ChatInputHandler::backspace,       '\b',   true);
    7385    this->inpbuf->registerListener(this, &ChatInputHandler::backspace,       '\177', true);
    7486
    75                 /* exit the chatinputhandler thingy (tbd) */
     87    /* exit the chatinputhandler thingy (tbd) */
    7688    this->inpbuf->registerListener(this, &ChatInputHandler::exit,            '\033', true); // escape
    7789
    78                 /* delete character */
     90    /* delete character */
    7991    this->inpbuf->registerListener(this, &ChatInputHandler::deleteChar,      KeyCode::Delete);
    8092
    81                 /* cursor movement */
     93    /* cursor movement */
    8294    this->inpbuf->registerListener(this, &ChatInputHandler::cursorRight,     KeyCode::Right);
    8395    this->inpbuf->registerListener(this, &ChatInputHandler::cursorLeft,      KeyCode::Left);
    8496    this->inpbuf->registerListener(this, &ChatInputHandler::cursorEnd,       KeyCode::End);
    8597    this->inpbuf->registerListener(this, &ChatInputHandler::cursorHome,      KeyCode::Home);
     98
     99    /* get window pointers */
     100    input = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/input" );
     101    CEGUI::Window *history = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/history" );
     102    lb_history = dynamic_cast<CEGUI::Listbox*>(history);
     103
     104    /* assert wee */
     105    assert( lb_history );
    86106  }
    87107
     
    94114  {
    95115    /* start listening */
    96     COUT(0) << "chatinput activated." << std::endl;
     116    //COUT(0) << "chatinput activated." << std::endl;
    97117    InputManager::getInstance().enterState("chatinput");
     118
     119    /* MARK add spawning of chat widget stuff here.*/
     120    GUIManager::getInstance().showGUI( "ChatBox" );
    98121  }
    99122
     
    102125    /* stop listening */
    103126    InputManager::getInstance().leaveState("chatinput");
    104   }
    105 
    106 
     127
     128    /* MARK add un-spawning of chat widget stuff here. */
     129    GUIManager::getInstance().hideGUI( "ChatBox" );
     130  }
    107131
    108132  /* callbacks for InputBuffer */
    109133  void ChatInputHandler::inputChanged()
    110134  {
    111 
     135    /* update the cursor and the window */
     136    std::string raw = this->inpbuf->get();
     137   
     138    /* get string before cursor */
     139    std::string left = raw.substr( 0, this->inpbuf->getCursorPosition() );
     140
     141    /* see if there's a string after the cursor */
     142    std::string right = "";
     143    if( raw.length() >= left.length()+1 )
     144      right = raw.substr( this->inpbuf->getCursorPosition() );
     145     
     146    /* set the text */
     147    this->input->setProperty( "Text", left + "|" + right );
    112148  }
    113149
    114150  void ChatInputHandler::addline()
    115151  {
    116     /* MARK MARK */
    117 
    118152    /* actually do send what was input */
    119153    /* a) get the string out of the inputbuffer */
    120154    std::string msgtosend = this->inpbuf->get();
    121155
     156    if( msgtosend.length() == 0 )
     157    { this->deactivate();
     158      return;
     159    }
     160
    122161    /* b) clear the input buffer */
    123162    if (this->inpbuf->getSize() > 0)
     
    129168    /* d) stop listening to input  */
    130169    this->deactivate();
     170
     171    /* e) create item and add to history */
     172    CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( msgtosend );
     173    this->lb_history->addItem( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
     174    this->lb_history->ensureItemIsVisible( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
     175
     176    /* f) make sure the history handles it */
     177    this->lb_history->handleUpdatedItemData();
    131178  }
    132179
    133180  void ChatInputHandler::backspace()
    134   {
    135     this->inpbuf->removeBehindCursor();
    136   }
     181  { this->inpbuf->removeBehindCursor(); }
    137182
    138183  void ChatInputHandler::deleteChar()
    139   {
    140     this->inpbuf->removeAtCursor();
    141   }
     184  { this->inpbuf->removeAtCursor(); }
    142185
    143186  void ChatInputHandler::cursorRight()
    144   {
    145     this->inpbuf->increaseCursor();
    146   }
     187  { this->inpbuf->increaseCursor(); }
    147188 
    148189  void ChatInputHandler::cursorLeft()
    149   {
    150     this->inpbuf->decreaseCursor();
    151   }
     190  { this->inpbuf->decreaseCursor(); }
    152191 
    153192  void ChatInputHandler::cursorEnd()
    154   {
    155     this->inpbuf->setCursorToEnd();
    156   }
     193  { this->inpbuf->setCursorToEnd(); }
    157194
    158195  void ChatInputHandler::cursorHome()
    159   {
    160     this->inpbuf->setCursorToBegin();
    161   }
     196  { this->inpbuf->setCursorToBegin(); }
    162197
    163198  void ChatInputHandler::exit()
    164   {
    165 
    166   }
     199  { }
    167200
    168201}
Note: See TracChangeset for help on using the changeset viewer.