[6776] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Sandro 'smerkli' Merkli |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _ChatInputHandler_H__ |
---|
| 30 | #define _ChatInputHandler_H__ |
---|
| 31 | |
---|
| 32 | /* std includes */ |
---|
| 33 | #include <deque> |
---|
| 34 | #include <string> |
---|
| 35 | #include <fstream> |
---|
| 36 | #include <iostream> |
---|
| 37 | #include <cassert> |
---|
[6846] | 38 | #include <CEGUIForwardRefs.h> |
---|
[8000] | 39 | #include <CEGUIcolour.h> |
---|
[6776] | 40 | |
---|
| 41 | /* project includes */ |
---|
| 42 | #include <OrxonoxPrereqs.h> |
---|
[6791] | 43 | #include <core/BaseObject.h> |
---|
| 44 | #include <core/PathConfig.h> |
---|
| 45 | |
---|
[6788] | 46 | #include "core/input/InputBuffer.h" |
---|
| 47 | #include "core/input/InputManager.h" |
---|
| 48 | #include "core/input/InputState.h" |
---|
[6791] | 49 | |
---|
[6885] | 50 | #include <network/ChatListener.h> |
---|
| 51 | #include <PlayerManager.h> |
---|
| 52 | #include <infos/PlayerInfo.h> |
---|
| 53 | |
---|
[6788] | 54 | #include "../libraries/network/Host.h" |
---|
| 55 | #include <util/Singleton.h> |
---|
[6776] | 56 | |
---|
[7009] | 57 | namespace orxonox // tolua_export |
---|
| 58 | { // tolua_export |
---|
[6776] | 59 | /* class to handle chat using an InputBuffer */ |
---|
[7009] | 60 | class _OrxonoxExport ChatInputHandler // tolua_export |
---|
| 61 | : public Singleton<ChatInputHandler>, public ChatListener |
---|
| 62 | { // tolua_export |
---|
[6776] | 63 | private: |
---|
| 64 | /** Input buffer, to be used to catch input from the |
---|
[7127] | 65 | * keyboard |
---|
[6776] | 66 | */ |
---|
| 67 | InputBuffer *inpbuf; |
---|
[6876] | 68 | int disp_offset, width; |
---|
[6879] | 69 | bool fullchat; |
---|
[6776] | 70 | |
---|
[7043] | 71 | /* colors for nickname coloring */ |
---|
| 72 | static const int NumberOfColors = 10; |
---|
[8000] | 73 | CEGUI::colour text_colors[ NumberOfColors ]; |
---|
[7043] | 74 | |
---|
[6788] | 75 | /** input state */ |
---|
| 76 | InputState *inputState; |
---|
| 77 | |
---|
| 78 | /** setup input buffer, the constructor calls this */ |
---|
[6776] | 79 | void configureInputBuffer(); |
---|
| 80 | |
---|
[6876] | 81 | /** adjust display offset depending on cursor position */ |
---|
| 82 | void sub_adjust_dispoffset( int maxlen, int cursorpos, int inplen ); |
---|
| 83 | |
---|
[6910] | 84 | /** singleton pointer */ |
---|
[6788] | 85 | static ChatInputHandler* singletonPtr_s; |
---|
| 86 | |
---|
[6910] | 87 | /** cegui window handles */ |
---|
[6870] | 88 | CEGUI::Window *input, *inputonly; |
---|
[6910] | 89 | |
---|
| 90 | /** cegui handle for the history window */ |
---|
[6846] | 91 | CEGUI::Listbox *lb_history; |
---|
| 92 | |
---|
[7043] | 93 | /* methods to deal with colors */ |
---|
| 94 | void sub_setcolor( CEGUI::ListboxTextItem *tocolor, |
---|
| 95 | std::string name ); |
---|
| 96 | |
---|
| 97 | void setupColors(); |
---|
| 98 | |
---|
[6910] | 99 | /* callbacks for input handler */ |
---|
| 100 | void inputChanged(); |
---|
| 101 | void addline(); |
---|
| 102 | void backspace(); |
---|
| 103 | void deleteChar(); |
---|
| 104 | void cursorRight(); |
---|
| 105 | void cursorLeft(); |
---|
| 106 | void cursorEnd(); |
---|
| 107 | void cursorHome(); |
---|
| 108 | void exit(); |
---|
| 109 | |
---|
[6776] | 110 | public: |
---|
| 111 | /** constructor */ |
---|
| 112 | ChatInputHandler(); |
---|
[8000] | 113 | ~ChatInputHandler(); |
---|
[6777] | 114 | friend class Singleton<ChatInputHandler>; |
---|
[6776] | 115 | |
---|
[7009] | 116 | static ChatInputHandler& getInstance(void) { return Singleton<ChatInputHandler>::getInstance(); } // tolua_export |
---|
| 117 | |
---|
[6910] | 118 | /** start listening */ |
---|
[6791] | 119 | static void activate_static(); |
---|
[6910] | 120 | |
---|
| 121 | /** stop listening */ |
---|
[6870] | 122 | static void activate_small_static(); |
---|
[6885] | 123 | |
---|
[6910] | 124 | /** \param message the message text |
---|
| 125 | * \param senderID ID of the player who sent the message |
---|
| 126 | * |
---|
| 127 | * Deal with incoming chat (which means in our case: Add it to the |
---|
| 128 | * history window of the full chat window) |
---|
| 129 | */ |
---|
[7127] | 130 | void incomingChat( const std::string& message, |
---|
[6885] | 131 | unsigned int senderID ); |
---|
| 132 | |
---|
[6910] | 133 | /** \param full true means show full chat window with history, |
---|
| 134 | false means show only an input line |
---|
[7127] | 135 | * |
---|
| 136 | * Show the chat window and redirect the game's keyboard input |
---|
[6910] | 137 | * into it. |
---|
| 138 | */ |
---|
[6870] | 139 | void activate( bool full ); |
---|
[6910] | 140 | |
---|
| 141 | /** Deactivate the chat window, meaning: hide it. */ |
---|
[7009] | 142 | void deactivate(); // tolua_export |
---|
[6777] | 143 | |
---|
[7009] | 144 | }; // tolua_export |
---|
[6776] | 145 | |
---|
| 146 | |
---|
[7009] | 147 | } // tolua_export |
---|
[6776] | 148 | |
---|
| 149 | |
---|
| 150 | #endif /*_ChatInputHandler_H__*/ |
---|