sources/interface.h

Fri, 15 May 2015 22:46:53 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Fri, 15 May 2015 22:46:53 +0300
branch
protocol5
changeset 78
c1d43ade656e
parent 73
07dda51a7a8e
child 80
f992b027374b
permissions
-rw-r--r--

Added support for colored nicknames

14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
73
07dda51a7a8e Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
2 Copyright 2014, 2015 Teemu Piippo
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. Neither the name of the copyright holder nor the names of its
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 contributors may be used to endorse or promote products derived from
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 this software without specific prior written permission.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 */
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #pragma once
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "main.h"
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
33 #include "network/ipaddress.h"
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
34 #include "coloredline.h"
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
35 #include "network/rconsession.h"
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
37 class Interface
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
39 public:
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
40 enum InputState
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
41 {
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
42 INPUTSTATE_NORMAL,
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
43 INPUTSTATE_ADDRESS,
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
44 INPUTSTATE_PASSWORD,
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
45 INPUTSTATE_CONFIRM_DISCONNECTION,
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
46 };
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
47
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
48 Interface();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
49 void handle_input();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
50 void render();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
51 void render_full();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
52 void set_title (const String& message);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
53 void update_statusbar();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
54 void connect (String address, String password);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
55 void set_player_names (const StringList& names);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
56 void need_refresh();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
57 void tab_complete (const String& part, String complete);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
58 RCONSession* get_session() { return &Session; }
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
59
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
60 template<typename... argtypes>
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
61 void print (const String& fmtstr, const argtypes&... args)
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
62 {
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
63 print_to_console (format (fmtstr, args...));
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
64 }
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
65
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
66 template<typename... argtypes>
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
67 void print_warning (const String& fmtstr, const argtypes&... args)
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
68 {
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
69 print_to_console (TEXTCOLOR_BrightYellow "-!- " + format (fmtstr, args...) + TEXTCOLOR_Reset);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
70 }
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
71
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
72 template<typename... argtypes>
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
73 void print_error (const String& fmtstr, const argtypes&... args)
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
74 {
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
75 print_to_console (TEXTCOLOR_BrightRed "!!! " + format (fmtstr, args...) + TEXTCOLOR_Reset);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
76 }
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
77
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
78 private:
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
79 StringList InputHistory;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
80 int InputCursor = 0;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
81 int CursorPosition = 0;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
82 int InputPanning = 0;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
83 bool NeedRefresh = false;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
84 bool NeedStatusBarRender = false;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
85 bool NeedInputRender = false;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
86 bool NeedOutputRender = false;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
87 bool NeedNicklistRender = false;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
88 struct { char ch; int x; } CursorCharacter;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
89 Vector<ColoredLine> OutputLines;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
90 int OutputScroll = 0;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
91 String Title;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
92 InputState CurrentInputState = INPUTSTATE_NORMAL;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
93 Function<void (void)> DisconnectConfirmFunction = nullptr;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
94 IPAddress CurrentAddress;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
95 String StatusBarText;
78
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
96 List<ColoredLine> PlayerNames;
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
97 String PasteBuffer;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
98 RCONSession Session;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
99
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
100 void render_titlebar();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
101 void safe_disconnect (Function<void()> afterwards);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
102 int render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
103 int nicklist_width();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
104 void render_output();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
105 void render_nicklist();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
106 void render_input();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
107 void render_statusbar();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
108 void position_cursor();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
109 int color_pair (Color fg, Color bg);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
110 const String& current_input();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
111 void detach_input();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
112 String& mutable_current_input();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
113 void move_input_cursor (int delta);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
114 String prompt_string();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
115 void set_input_state (InputState newstate);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
116 void print_to_console (String a);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
117 void yank (int a, int b);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
118 int find_previous_word();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
119 int find_next_word();
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 };

mercurial