[Orxonox-commit 2130] r6846 - in code/branches/chat2: data/gui/layouts data/gui/scripts src/orxonox
smerkli at orxonox.net
smerkli at orxonox.net
Mon May 3 16:46:01 CEST 2010
Author: smerkli
Date: 2010-05-03 16:46:00 +0200 (Mon, 03 May 2010)
New Revision: 6846
Added:
code/branches/chat2/data/gui/scripts/ChatBox.lua
Modified:
code/branches/chat2/data/gui/layouts/ChatBox.layout
code/branches/chat2/src/orxonox/ChatHistory.cc
code/branches/chat2/src/orxonox/ChatInputHandler.cc
code/branches/chat2/src/orxonox/ChatInputHandler.h
Log:
Chatbox done, with cursor goodness and everything. Thanks for the help
Modified: code/branches/chat2/data/gui/layouts/ChatBox.layout
===================================================================
--- code/branches/chat2/data/gui/layouts/ChatBox.layout 2010-05-03 14:28:30 UTC (rev 6845)
+++ code/branches/chat2/data/gui/layouts/ChatBox.layout 2010-05-03 14:46:00 UTC (rev 6846)
@@ -7,75 +7,20 @@
<Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
<Window Type="MenuWidgets/FrameWindow" Name="/ChatBox" >
<Property Name="Text" Value="Chat" />
- <Property Name="TitlebarFont" Value="Commonwealth-10" />
<Property Name="InheritsAlpha" Value="False" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="TitlebarEnabled" Value="True" />
<Property Name="UnifiedAreaRect" Value="{{0.01,0},{0.03,0},{0.6,0},{0.69375,0}}" />
- <Window Type="MenuWidgets/Listbox" Name="/ChatBox/List" >
+ <Window Type="MenuWidgets/Listbox" Name="orxonox/ChatBox/history" >
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0.02,0},{0.078,0},{0.98,0},{1,-30}}" />
</Window>
- <!--<Window Type="MenuWidgets/Editbox" Name="/ChatBox/Text" >-->
- <!--<Property Name="Text" Value="Error: you did not register any font or none were valid" />-->
- <!--<Property Name="MaxTextLength" Value="1073741823" />-->
- <!--<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />-->
- <!--<Property Name="UnifiedAreaRect" Value="{{0.02,0},{1,-30},{0.98,0},{1,-5}}" />-->
- <!--</Window>-->
- <Window Type="MenuWidgets/StaticText" Name="/ChatBox/Text" >
- <Property Name="Text" Value="History" />
- <Property Name="HorzFormatting" Value="RightAligned" />
+ <Window Type="MenuWidgets/Editbox" Name="orxonox/ChatBox/input" >
+ <Property Name="Text" Value="" />
+ <Property Name="MaxTextLength" Value="1073741823" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0.02,0},{1,-30},{0.98,0},{1,-5}}" />
</Window>
</Window>
- <!--<Window Type="MenuWidgets/Editbox" Name="/ChatBox/History" >-->
- <!--<Property Name="Text" Value="5" />-->
- <!--<Property Name="MaxTextLength" Value="1073741823" />-->
- <!--<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />-->
- <!--<Property Name="UnifiedAreaRect" Value="{{0.77,0},{0.03,0},{0.81,0},{0.1,0}}" />-->
- <!--</Window>-->
- <Window Type="MenuWidgets/StaticText" Name="/ChatBox/History" >
- <Property Name="Text" Value="5" />
- <Property Name="HorzFormatting" Value="RightAligned" />
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.77,0},{0.03,0},{0.81,0},{0.1,0}}" />
- </Window>
- <Window Type="MenuWidgets/StaticText" Name="/ChatBox/HistoryLabel" >
- <Property Name="Text" Value="History size:" />
- <Property Name="HorzFormatting" Value="RightAligned" />
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.03,0},{0.77,0},{0.1,0}}" />
- </Window>
- <Window Type="MenuWidgets/StaticText" Name="/ChatBox/FonSizeLabel" >
- <Property Name="Font" Value="Commonwealth-10" />
- <Property Name="Text" Value="Font size:" />
- <Property Name="HorzFormatting" Value="RightAligned" />
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.1,0},{0.77,0},{0.17,0}}" />
- </Window>
- <Window Type="MenuWidgets/Spinner" Name="/ChatBox/FontSize" >
- <Property Name="Text" Value="10" />
- <Property Name="StepSize" Value="1" />
- <Property Name="CurrentValue" Value="10" />
- <Property Name="MaximumValue" Value="72" />
- <Property Name="MinimumValue" Value="-32768" />
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.77,0},{0.1,0},{0.83,0},{0.17,0}}" />
- </Window>
- <Window Type="MenuWidgets/StaticText" Name="/ChatBox/FontNameLabel" >
- <Property Name="Font" Value="Commonwealth-10" />
- <Property Name="Text" Value="Font name:" />
- <Property Name="HorzFormatting" Value="RightAligned" />
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.17,0},{0.77,0},{0.24,0}}" />
- </Window>
- <Window Type="MenuWidgets/Combobox" Name="/ChatBox/FontName" >
- <Property Name="Text" Value="ChatBoxFont" />
- <Property Name="ReadOnly" Value="True" />
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.77,0},{0.17,0},{0.99,0},{0.45,0}}" />
- <Property Name="MaxEditTextLength" Value="1073741823" />
- </Window>
</Window>
</GUILayout>
Added: code/branches/chat2/data/gui/scripts/ChatBox.lua
===================================================================
--- code/branches/chat2/data/gui/scripts/ChatBox.lua (rev 0)
+++ code/branches/chat2/data/gui/scripts/ChatBox.lua 2010-05-03 14:46:00 UTC (rev 6846)
@@ -0,0 +1,5 @@
+-- ChatBox.lua
+
+local P = createMenuSheet("ChatBox")
+return P
+
Modified: code/branches/chat2/src/orxonox/ChatHistory.cc
===================================================================
--- code/branches/chat2/src/orxonox/ChatHistory.cc 2010-05-03 14:28:30 UTC (rev 6845)
+++ code/branches/chat2/src/orxonox/ChatHistory.cc 2010-05-03 14:46:00 UTC (rev 6846)
@@ -79,7 +79,7 @@
/* --> a) look up the actual name of the sender */
std::string text;
- COUT(0) << "Meow.\n";
+ //COUT(0) << "Meow.\n";
#ifndef CHATTEST
if (senderID != CLIENTID_UNKNOWN)
Modified: code/branches/chat2/src/orxonox/ChatInputHandler.cc
===================================================================
--- code/branches/chat2/src/orxonox/ChatInputHandler.cc 2010-05-03 14:28:30 UTC (rev 6845)
+++ code/branches/chat2/src/orxonox/ChatInputHandler.cc 2010-05-03 14:46:00 UTC (rev 6846)
@@ -30,6 +30,13 @@
#include <core/ScopedSingletonManager.h>
#include "core/ConsoleCommand.h"
#include "core/CoreIncludes.h"
+#include "core/GUIManager.h"
+#include "core/CorePrereqs.h"
+#include <CEGUIWindow.h>
+#include <CEGUI/elements/CEGUIListbox.h>
+#include <CEGUI/elements/CEGUIListboxItem.h>
+#include <CEGUI/elements/CEGUIListboxTextItem.h>
+#include <CEGUIWindowManager.h>
#include <string>
namespace orxonox
@@ -39,6 +46,7 @@
SetConsoleCommandAlias( ChatInputHandler, activate_static, "startchat",
true );
+
/* constructor */
ChatInputHandler::ChatInputHandler()
{
@@ -47,7 +55,11 @@
/* create necessary objects */
this->inpbuf = new InputBuffer();
+ assert( this->inpbuf != NULL );
+ /* MARK add generation of ChatBox thingy here */
+ GUIManager::getInstance().loadGUI( "ChatBox" );
+
/* configure the input buffer */
configureInputBuffer();
@@ -61,28 +73,36 @@
void ChatInputHandler::configureInputBuffer()
{
- /* input has changed */
+ /* input has changed */
this->inpbuf->registerListener(this, &ChatInputHandler::inputChanged, true);
-
- /* add a line */
+
+ /* add a line */
this->inpbuf->registerListener(this, &ChatInputHandler::addline, '\r', false);
this->inpbuf->registerListener(this, &ChatInputHandler::addline, '\n', false);
- /* backspace */
+ /* backspace */
this->inpbuf->registerListener(this, &ChatInputHandler::backspace, '\b', true);
this->inpbuf->registerListener(this, &ChatInputHandler::backspace, '\177', true);
- /* exit the chatinputhandler thingy (tbd) */
+ /* exit the chatinputhandler thingy (tbd) */
this->inpbuf->registerListener(this, &ChatInputHandler::exit, '\033', true); // escape
- /* delete character */
+ /* delete character */
this->inpbuf->registerListener(this, &ChatInputHandler::deleteChar, KeyCode::Delete);
- /* cursor movement */
+ /* cursor movement */
this->inpbuf->registerListener(this, &ChatInputHandler::cursorRight, KeyCode::Right);
this->inpbuf->registerListener(this, &ChatInputHandler::cursorLeft, KeyCode::Left);
this->inpbuf->registerListener(this, &ChatInputHandler::cursorEnd, KeyCode::End);
this->inpbuf->registerListener(this, &ChatInputHandler::cursorHome, KeyCode::Home);
+
+ /* get window pointers */
+ input = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/input" );
+ CEGUI::Window *history = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/history" );
+ lb_history = dynamic_cast<CEGUI::Listbox*>(history);
+
+ /* assert wee */
+ assert( lb_history );
}
@@ -93,32 +113,51 @@
void ChatInputHandler::activate()
{
/* start listening */
- COUT(0) << "chatinput activated." << std::endl;
+ //COUT(0) << "chatinput activated." << std::endl;
InputManager::getInstance().enterState("chatinput");
+
+ /* MARK add spawning of chat widget stuff here.*/
+ GUIManager::getInstance().showGUI( "ChatBox" );
}
void ChatInputHandler::deactivate()
{
/* stop listening */
InputManager::getInstance().leaveState("chatinput");
+
+ /* MARK add un-spawning of chat widget stuff here. */
+ GUIManager::getInstance().hideGUI( "ChatBox" );
}
-
-
/* callbacks for InputBuffer */
void ChatInputHandler::inputChanged()
{
+ /* update the cursor and the window */
+ std::string raw = this->inpbuf->get();
+
+ /* get string before cursor */
+ std::string left = raw.substr( 0, this->inpbuf->getCursorPosition() );
+ /* see if there's a string after the cursor */
+ std::string right = "";
+ if( raw.length() >= left.length()+1 )
+ right = raw.substr( this->inpbuf->getCursorPosition() );
+
+ /* set the text */
+ this->input->setProperty( "Text", left + "|" + right );
}
void ChatInputHandler::addline()
{
- /* MARK MARK */
-
/* actually do send what was input */
/* a) get the string out of the inputbuffer */
std::string msgtosend = this->inpbuf->get();
+ if( msgtosend.length() == 0 )
+ { this->deactivate();
+ return;
+ }
+
/* b) clear the input buffer */
if (this->inpbuf->getSize() > 0)
this->inpbuf->clear();
@@ -128,41 +167,35 @@
/* d) stop listening to input */
this->deactivate();
+
+ /* e) create item and add to history */
+ CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( msgtosend );
+ this->lb_history->addItem( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
+ this->lb_history->ensureItemIsVisible( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
+
+ /* f) make sure the history handles it */
+ this->lb_history->handleUpdatedItemData();
}
void ChatInputHandler::backspace()
- {
- this->inpbuf->removeBehindCursor();
- }
+ { this->inpbuf->removeBehindCursor(); }
void ChatInputHandler::deleteChar()
- {
- this->inpbuf->removeAtCursor();
- }
+ { this->inpbuf->removeAtCursor(); }
void ChatInputHandler::cursorRight()
- {
- this->inpbuf->increaseCursor();
- }
+ { this->inpbuf->increaseCursor(); }
void ChatInputHandler::cursorLeft()
- {
- this->inpbuf->decreaseCursor();
- }
+ { this->inpbuf->decreaseCursor(); }
void ChatInputHandler::cursorEnd()
- {
- this->inpbuf->setCursorToEnd();
- }
+ { this->inpbuf->setCursorToEnd(); }
void ChatInputHandler::cursorHome()
- {
- this->inpbuf->setCursorToBegin();
- }
+ { this->inpbuf->setCursorToBegin(); }
void ChatInputHandler::exit()
- {
+ { }
- }
-
}
Modified: code/branches/chat2/src/orxonox/ChatInputHandler.h
===================================================================
--- code/branches/chat2/src/orxonox/ChatInputHandler.h 2010-05-03 14:28:30 UTC (rev 6845)
+++ code/branches/chat2/src/orxonox/ChatInputHandler.h 2010-05-03 14:46:00 UTC (rev 6846)
@@ -35,6 +35,7 @@
#include <fstream>
#include <iostream>
#include <cassert>
+#include <CEGUIForwardRefs.h>
/* project includes */
#include <OrxonoxPrereqs.h>
@@ -70,6 +71,10 @@
/* singleton pointer */
static ChatInputHandler* singletonPtr_s;
+ /* cegui stuff */
+ CEGUI::Window *input;
+ CEGUI::Listbox *lb_history;
+
public:
/** constructor */
ChatInputHandler();
More information about the Orxonox-commit
mailing list