Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6846 for code/branches


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

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

Location:
code/branches/chat2
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/chat2/data/gui/layouts/ChatBox.layout

    r6837 r6846  
    88        <Window Type="MenuWidgets/FrameWindow" Name="/ChatBox" >
    99            <Property Name="Text" Value="Chat" />
    10             <Property Name="TitlebarFont" Value="Commonwealth-10" />
    1110            <Property Name="InheritsAlpha" Value="False" />
    1211            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    1312            <Property Name="TitlebarEnabled" Value="True" />
    1413            <Property Name="UnifiedAreaRect" Value="{{0.01,0},{0.03,0},{0.6,0},{0.69375,0}}" />
    15             <Window Type="MenuWidgets/Listbox" Name="/ChatBox/List" >
     14            <Window Type="MenuWidgets/Listbox" Name="orxonox/ChatBox/history" >
    1615                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    1716                <Property Name="UnifiedAreaRect" Value="{{0.02,0},{0.078,0},{0.98,0},{1,-30}}" />
    1817            </Window>
    19             <!--<Window Type="MenuWidgets/Editbox" Name="/ChatBox/Text" >-->
    20                 <!--<Property Name="Text" Value="Error: you did not register any font or none were valid" />-->
    21                 <!--<Property Name="MaxTextLength" Value="1073741823" />-->
    22                 <!--<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />-->
    23                 <!--<Property Name="UnifiedAreaRect" Value="{{0.02,0},{1,-30},{0.98,0},{1,-5}}" />-->
    24             <!--</Window>-->
    25             <Window Type="MenuWidgets/StaticText" Name="/ChatBox/Text" >
    26                 <Property Name="Text" Value="History" />
    27                 <Property Name="HorzFormatting" Value="RightAligned" />
     18            <Window Type="MenuWidgets/Editbox" Name="orxonox/ChatBox/input" >
     19                <Property Name="Text" Value="" />
     20                <Property Name="MaxTextLength" Value="1073741823" />
    2821                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    2922                <Property Name="UnifiedAreaRect" Value="{{0.02,0},{1,-30},{0.98,0},{1,-5}}" />
    3023            </Window>
    3124        </Window>
    32         <!--<Window Type="MenuWidgets/Editbox" Name="/ChatBox/History" >-->
    33             <!--<Property Name="Text" Value="5" />-->
    34             <!--<Property Name="MaxTextLength" Value="1073741823" />-->
    35             <!--<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />-->
    36             <!--<Property Name="UnifiedAreaRect" Value="{{0.77,0},{0.03,0},{0.81,0},{0.1,0}}" />-->
    37         <!--</Window>-->
    38         <Window Type="MenuWidgets/StaticText" Name="/ChatBox/History" >
    39             <Property Name="Text" Value="5" />
    40             <Property Name="HorzFormatting" Value="RightAligned" />
    41             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    42             <Property Name="UnifiedAreaRect" Value="{{0.77,0},{0.03,0},{0.81,0},{0.1,0}}" />
    43         </Window>
    44         <Window Type="MenuWidgets/StaticText" Name="/ChatBox/HistoryLabel" >
    45             <Property Name="Text" Value="History size:" />
    46             <Property Name="HorzFormatting" Value="RightAligned" />
    47             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    48             <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.03,0},{0.77,0},{0.1,0}}" />
    49         </Window>
    50         <Window Type="MenuWidgets/StaticText" Name="/ChatBox/FonSizeLabel" >
    51             <Property Name="Font" Value="Commonwealth-10" />
    52             <Property Name="Text" Value="Font size:" />
    53             <Property Name="HorzFormatting" Value="RightAligned" />
    54             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    55             <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.1,0},{0.77,0},{0.17,0}}" />
    56         </Window>
    57         <Window Type="MenuWidgets/Spinner" Name="/ChatBox/FontSize" >
    58             <Property Name="Text" Value="10" />
    59             <Property Name="StepSize" Value="1" />
    60             <Property Name="CurrentValue" Value="10" />
    61             <Property Name="MaximumValue" Value="72" />
    62             <Property Name="MinimumValue" Value="-32768" />
    63             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    64             <Property Name="UnifiedAreaRect" Value="{{0.77,0},{0.1,0},{0.83,0},{0.17,0}}" />
    65         </Window>
    66         <Window Type="MenuWidgets/StaticText" Name="/ChatBox/FontNameLabel" >
    67             <Property Name="Font" Value="Commonwealth-10" />
    68             <Property Name="Text" Value="Font name:" />
    69             <Property Name="HorzFormatting" Value="RightAligned" />
    70             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    71             <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.17,0},{0.77,0},{0.24,0}}" />
    72         </Window>
    73         <Window Type="MenuWidgets/Combobox" Name="/ChatBox/FontName" >
    74             <Property Name="Text" Value="ChatBoxFont" />
    75             <Property Name="ReadOnly" Value="True" />
    76             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    77             <Property Name="UnifiedAreaRect" Value="{{0.77,0},{0.17,0},{0.99,0},{0.45,0}}" />
    78             <Property Name="MaxEditTextLength" Value="1073741823" />
    79         </Window>
    8025    </Window>
    8126</GUILayout>
  • code/branches/chat2/src/orxonox/ChatHistory.cc

    r6836 r6846  
    8080    std::string text;
    8181
    82     COUT(0) << "Meow.\n";
     82    //COUT(0) << "Meow.\n";
    8383
    8484#ifndef CHATTEST
  • 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}
  • code/branches/chat2/src/orxonox/ChatInputHandler.h

    r6836 r6846  
    3636#include <iostream>
    3737#include <cassert>
     38#include <CEGUIForwardRefs.h>
    3839
    3940/* project includes */
     
    7172      static ChatInputHandler* singletonPtr_s;
    7273
     74      /* cegui stuff */
     75      CEGUI::Window *input;
     76      CEGUI::Listbox *lb_history;
     77
    7378    public:
    7479      /** constructor */
Note: See TracChangeset for help on using the changeset viewer.