[Orxonox-commit 2072] r6788 - code/branches/chat/src/orxonox

smerkli at orxonox.net smerkli at orxonox.net
Mon Apr 26 16:09:23 CEST 2010


Author: smerkli
Date: 2010-04-26 16:09:23 +0200 (Mon, 26 Apr 2010)
New Revision: 6788

Modified:
   code/branches/chat/src/orxonox/CMakeLists.txt
   code/branches/chat/src/orxonox/ChatInputHandler.cc
   code/branches/chat/src/orxonox/ChatInputHandler.h
Log:
stuff works, but keybinding still does only work in the build folder

Modified: code/branches/chat/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/chat/src/orxonox/CMakeLists.txt	2010-04-26 14:07:18 UTC (rev 6787)
+++ code/branches/chat/src/orxonox/CMakeLists.txt	2010-04-26 14:09:23 UTC (rev 6788)
@@ -32,6 +32,7 @@
   PlayerManager.cc
   Radar.cc
   ChatHistory.cc
+  ChatInputHandler.cc
 COMPILATION_BEGIN SceneCompilation.cc
   CameraManager.cc
   Scene.cc

Modified: code/branches/chat/src/orxonox/ChatInputHandler.cc
===================================================================
--- code/branches/chat/src/orxonox/ChatInputHandler.cc	2010-04-26 14:07:18 UTC (rev 6787)
+++ code/branches/chat/src/orxonox/ChatInputHandler.cc	2010-04-26 14:09:23 UTC (rev 6788)
@@ -27,60 +27,77 @@
  */
 
 #include "ChatInputHandler.h"
+#include <core/ScopedSingletonManager.h>
+#include "core/ConsoleCommand.h"
+#include "core/CoreIncludes.h"
+#include <string>
 
 namespace orxonox 
 {
   /* singleton */
-  ManageScopedSingleton( ChatInputHandler, ScopeID::Root, false );
+  ManageScopedSingleton( ChatInputHandler, ScopeID::Graphics, false );
 
   /* constructor */
-  void ChatInputHandler::ChatInputHandler()
+  ChatInputHandler::ChatInputHandler()
   {
     /* register the object  */
     RegisterObject(ChatInputHandler);
 
+    //COUT(0) << "Singleton registered for ChatInputHandler." << std::endl;
+
     /* create necessary objects */
     this->inpbuf = new InputBuffer();
 
+    /* configure the input buffer */
 		configureInputBuffer();
+
+    this->inputState = InputManager::getInstance().createInputState( "chatinput", false, false, InputStatePriority::Dynamic );
+    this->inputState->setKeyHandler(this->inpbuf);
+
+    /* set console shortcut */
+    this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(
+      &ChatInputHandler::activate, this), "startchat"), false);
   }
 
   void ChatInputHandler::configureInputBuffer()
   {
 	  /* input has changed */
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::inputChanged, true);
+    this->inpbuf->registerListener(this, &ChatInputHandler::inputChanged, true);
 		
 		/* add a line */
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::addline,         '\r',   false);
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::addline,         '\n',   false);
+    this->inpbuf->registerListener(this, &ChatInputHandler::addline,         '\r',   false);
+    this->inpbuf->registerListener(this, &ChatInputHandler::addline,         '\n',   false);
 
 		/* backspace */
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::backspace,       '\b',   true);
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::backspace,       '\177', true);
+    this->inpbuf->registerListener(this, &ChatInputHandler::backspace,       '\b',   true);
+    this->inpbuf->registerListener(this, &ChatInputHandler::backspace,       '\177', true);
 
 		/* exit the chatinputhandler thingy (tbd) */
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::exit,            '\033', true); // escape
+    this->inpbuf->registerListener(this, &ChatInputHandler::exit,            '\033', true); // escape
 
 		/* delete character */
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::deleteChar,      KeyCode::Delete);
+    this->inpbuf->registerListener(this, &ChatInputHandler::deleteChar,      KeyCode::Delete);
 
 		/* cursor movement */
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::cursorRight,     KeyCode::Right);
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::cursorLeft,      KeyCode::Left);
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::cursorEnd,       KeyCode::End);
-    this->inputBuffer_->registerListener(this, &ChatInputHandler::cursorHome,      KeyCode::Home);
+    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);
   }
 
 
   /* activate, deactivate */
-  void ChatInputHandler::activate()   /* TBI */
+  void ChatInputHandler::activate()
   {
     /* start listening */
+    COUT(0) << "chatinput activated." << std::endl;
+    InputManager::getInstance().enterState("chatinput");
   }
 
-  void ChatInputHandler::deactivate()   /* TBI */
+  void ChatInputHandler::deactivate() 
   {
     /* stop listening */
+    InputManager::getInstance().leaveState("chatinput");
   }
 
 
@@ -98,57 +115,59 @@
 
     /* actually do send what was input */
     /* a) get the string out of the inputbuffer */
-    String msgtosend = this->inpbuf->get();
+    std::string msgtosend = this->inpbuf->get();
 
     /* b) clear the input buffer */
-    this->inpbuf->clear();
+    if (this->inpbuf->getSize() > 0)
+      this->inpbuf->clear();
 
     /* c) send the chat via some call */
     Host::Chat( msgtosend );
 
     /* d) stop listening to input  */
+    this->deactivate();
   }
 
   void ChatInputHandler::backspace()
   {
-    this->inputBuffer_->removeBehindCursor();
+    this->inpbuf->removeBehindCursor();
     //this->updateListeners<&ShellListener::inputChanged>();
     //this->updateListeners<&ShellListener::cursorChanged>();
   }
 
   void ChatInputHandler::deleteChar()
   {
-    this->inputBuffer_->removeAtCursor();
+    this->inpbuf->removeAtCursor();
     //this->updateListeners<&ShellListener::inputChanged>();
   }
 
   void ChatInputHandler::cursorRight()
   {
-    this->inputBuffer_->increaseCursor();
+    this->inpbuf->increaseCursor();
     //this->updateListeners<&ShellListener::cursorChanged>();
   }
   
   void ChatInputHandler::cursorLeft()
   {
-    this->inputBuffer_->decreaseCursor();
+    this->inpbuf->decreaseCursor();
     //this->updateListeners<&ShellListener::cursorChanged>();
   }
   
   void ChatInputHandler::cursorEnd()
   {
-    this->inputBuffer_->setCursorToEnd();
+    this->inpbuf->setCursorToEnd();
     //this->updateListeners<&ShellListener::cursorChanged>();
   }
 
   void ChatInputHandler::cursorHome()
   {
-    this->inputBuffer_->setCursorToBegin();
+    this->inpbuf->setCursorToBegin();
     //this->updateListeners<&ShellListener::cursorChanged>();
   }
 
   void ChatInputHandler::exit()
   {
-    //if (this->inputBuffer_->getSize() > 0)
+    //if (this->inpbuf->getSize() > 0)
     //{
       //this->clearInput();
       //return;

Modified: code/branches/chat/src/orxonox/ChatInputHandler.h
===================================================================
--- code/branches/chat/src/orxonox/ChatInputHandler.h	2010-04-26 14:07:18 UTC (rev 6787)
+++ code/branches/chat/src/orxonox/ChatInputHandler.h	2010-04-26 14:09:23 UTC (rev 6788)
@@ -38,14 +38,23 @@
 
 /* project includes */
 #include <OrxonoxPrereqs.h>
-#include <InputBuffer.h>
-#include <Host.h>
+#include "core/input/InputBuffer.h"
+#include "core/input/InputManager.h"
+#include "core/input/InputState.h"
+#include "../libraries/network/Host.h"
+#include <core/BaseObject.h>
+#include <PlayerManager.h>
+#include <infos/PlayerInfo.h>
+#include <network/ChatListener.h>
+#include <core/PathConfig.h>
+#include <util/Singleton.h>
 
 
 namespace orxonox
 {
   /* class to handle chat using an InputBuffer */
-  class _OrxonoxExport ChatInputHandler : public Singleton<ChatInputHandler>
+  class _OrxonoxExport ChatInputHandler : public Singleton<ChatInputHandler>,
+    public OrxonoxClass
   {
     private:
       /** Input buffer, to be used to catch input from the
@@ -53,9 +62,15 @@
        */
       InputBuffer *inpbuf;
 
-      /* setup input buffer, the constructor calls this */
+      /** input state */
+      InputState *inputState;
+
+      /** setup input buffer, the constructor calls this */
       void configureInputBuffer();
 
+      /* singleton pointer */
+      static ChatInputHandler* singletonPtr_s;
+
     public:
       /** constructor */
       ChatInputHandler();
@@ -65,6 +80,8 @@
       void activate();
       void deactivate();
 
+      /* callbacks for input handler */
+
       void inputChanged();
       void addline();
       void backspace();




More information about the Orxonox-commit mailing list