3 Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "common_irrlicht.h"
26 // Chat console related classes, only used by the client
32 // name of sending player, or empty if sent by server
37 ChatLine(std::wstring a_name, std::wstring a_text):
45 struct ChatFormattedFragment
55 struct ChatFormattedLine
57 // Array of text fragments
58 core::array<ChatFormattedFragment> fragments;
59 // true if first line of one formatted ChatLine
66 ChatBuffer(u32 scrollback);
70 // Removes oldest chat line if scrollback size is reached
71 void addLine(std::wstring name, std::wstring text);
73 // Remove all chat lines
76 // Get number of lines currently in buffer.
77 u32 getLineCount() const;
78 // Get scrollback size, maximum number of lines in buffer.
79 u32 getScrollback() const;
80 // Get reference to i-th chat line.
81 const ChatLine& getLine(u32 index) const;
83 // Increase each chat line's age by dtime.
85 // Delete oldest N chat lines.
86 void deleteOldest(u32 count);
87 // Delete lines older than maxAge.
88 void deleteByAge(f32 maxAge);
90 // Get number of columns, 0 if reformat has not been called yet.
91 u32 getColumns() const;
92 // Get number of rows, 0 if reformat has not been called yet.
94 // Update console size and reformat all formatted lines.
95 void reformat(u32 cols, u32 rows);
96 // Get formatted line for a given row (0 is top of screen).
97 // Only valid after reformat has been called at least once
98 const ChatFormattedLine& getFormattedLine(u32 row) const;
99 // Scrolling in formatted buffer (relative)
100 // positive rows == scroll up, negative rows == scroll down
101 void scroll(s32 rows);
102 // Scrolling in formatted buffer (absolute)
103 void scrollAbsolute(s32 scroll);
104 // Scroll to bottom of buffer (newest)
106 // Scroll to top of buffer (oldest)
109 // Format a chat line for the given number of columns.
110 // Appends the formatted lines to the destination array and
111 // returns the number of formatted lines.
112 u32 formatChatLine(const ChatLine& line, u32 cols,
113 core::array<ChatFormattedLine>& destination) const;
116 s32 getTopScrollPos() const;
117 s32 getBottomScrollPos() const;
122 // Array of unformatted chat lines
123 core::array<ChatLine> m_unformatted;
125 // Number of character columns in console
127 // Number of character rows in console
129 // Scroll position (console's top line index into m_formatted)
131 // Array of formatted lines
132 core::array<ChatFormattedLine> m_formatted;
133 // Empty formatted line, for error returns
134 ChatFormattedLine m_empty_formatted_line;
140 ChatPrompt(std::wstring prompt, u32 history_limit);
144 void input(wchar_t ch);
146 // Submit, clear and return current line
147 std::wstring submit();
149 // Clear the current line
152 // Replace the current line with the given text
153 void replace(std::wstring line);
155 // Select previous command from history
157 // Select next command from history
161 void nickCompletion(const core::list<std::wstring>& names, bool backwards);
163 // Update console size and reformat the visible portion of the prompt
164 void reformat(u32 cols);
165 // Get visible portion of the prompt.
166 std::wstring getVisiblePortion() const;
167 // Get cursor position (relative to visible portion). -1 if invalid
168 s32 getVisibleCursorPosition() const;
176 // Cursor operation direction
182 // Cursor operation scope
184 CURSOROP_SCOPE_CHARACTER,
190 // op specifies whether it's a move or delete operation
191 // dir specifies whether the operation goes left or right
192 // scope specifies how far the operation will reach (char/word/line)
194 // cursorOperation(CURSOROP_MOVE, CURSOROP_DIR_RIGHT, CURSOROP_SCOPE_LINE)
195 // moves the cursor to the end of the line.
196 // cursorOperation(CURSOROP_DELETE, CURSOROP_DIR_LEFT, CURSOROP_SCOPE_WORD)
197 // deletes the word to the left of the cursor.
198 void cursorOperation(CursorOp op, CursorOpDir dir, CursorOpScope scope);
201 // set m_view to ensure that 0 <= m_view <= m_cursor < m_view + m_cols
202 // if line can be fully shown, set m_view to zero
203 // else, also ensure m_view <= m_line.size() + 1 - m_cols
208 std::wstring m_prompt;
209 // Currently edited line
212 core::array<std::wstring> m_history;
213 // History index (0 <= m_history_index <= m_history.size())
215 // Maximum number of history entries
218 // Number of columns excluding columns reserved for the prompt
220 // Start of visible portion (index into m_line)
222 // Cursor (index into m_line)
225 // Last nick completion start (index into m_line)
226 s32 m_nick_completion_start;
227 // Last nick completion start (index into m_line)
228 s32 m_nick_completion_end;
238 void addMessage(std::wstring name, std::wstring text);
239 // Parse and add unparsed chat message
240 void addUnparsedMessage(std::wstring line);
242 // Get the console buffer
243 ChatBuffer& getConsoleBuffer();
244 // Get the recent messages buffer
245 ChatBuffer& getRecentBuffer();
246 // Concatenate all recent messages
247 std::wstring getRecentChat();
248 // Get the console prompt
249 ChatPrompt& getPrompt();
251 // Reformat all buffers
252 void reformat(u32 cols, u32 rows);
254 // Clear all recent messages
255 void clearRecentChat();
257 // Age recent messages
258 void step(float dtime);
261 void scroll(s32 rows);
262 void scrollPageDown();
266 ChatBuffer m_console_buffer;
267 ChatBuffer m_recent_buffer;