summaryrefslogtreecommitdiffstats
path: root/src/client/clui.hpp
blob: 3ebefda06c3280c3a150e9373ff497ac5ede57b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// CLUI - Command Line User Interface

#ifndef COMMANDLINEUI_H
#define COMMANDLINEUI_H

#include <ncurses.h>

class Interface_wc {
	WINDOW *w;
	int ny, nx;
	int beg_y, beg_x;
	int ch_line;
public:
	Interface_wc(int num_y, int num_x, int by, int bx, char ch);

	WINDOW *GetWindow() { return w; }
	void SetCursor(int y, int x) { wmove(w, y, x); }
	void Clear(bool full);
	void Update() { wrefresh(w); }
	void Delete() { delwin(w); }

	void Hide();
};

class SelectionMenu : public Interface_wc {
	char const *title;
	const char**choises;
	int choises_number;
	int current_choice;

public:
	SelectionMenu(char const *i_title, const char**i_choises, int choises_num,
		int num_y, int num_x, int by, int bx, char ch);

	int Handling();
};

class ChatRoom {
	Interface_wc *chat;
	Interface_wc *players;
	Interface_wc *input;
	int i_nx, i_ny;

	struct message {
		char msg[300];
		int num_lines; // number of lines
		message *prev;
	};
	message *first;
public:
	ChatRoom();
	~ChatRoom();

	// for chat:
	void AddMessage(char *msg);

	// for players:
	//void AddPlayer()

	// for input:
	bool AddCharToSendMsg(char ch);
	bool RemoveCharFromMsg();
	void InputClear() { input->Clear(false); }
	void SetInputCursor(int y, int x);

	WINDOW *GetInputWin() { return input->GetWindow(); }
	WINDOW *GetChatWin() { return chat->GetWindow(); }
private:
	// for chat:
	void ChatRedraw();
	void PrintMessage(int line, message *m);
};

#endif