diff options
author | Joursoir <chat@joursoir.net> | 2020-12-12 12:44:08 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2020-12-12 12:44:08 +0000 |
commit | f27143165f1f3c2e47aaa65c4da24875e1639ceb (patch) | |
tree | 52ab0245d0de62c2dae987196850c07acb8fea0d /src/client | |
parent | 9f6cdb671ca3c045085bd8eed623e0a797894e1f (diff) | |
download | want-chat-f27143165f1f3c2e47aaa65c4da24875e1639ceb.tar.gz want-chat-f27143165f1f3c2e47aaa65c4da24875e1639ceb.tar.bz2 want-chat-f27143165f1f3c2e47aaa65c4da24875e1639ceb.zip |
some changes in work spec-symbols; clui: refactor;
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/ClientBase.cpp | 19 | ||||
-rw-r--r-- | src/client/ClientBase.hpp | 2 | ||||
-rw-r--r-- | src/client/clui/Client.cpp | 21 | ||||
-rw-r--r-- | src/client/clui/WindowInterface.cpp | 4 | ||||
-rw-r--r-- | src/client/clui/clui.cpp | 26 |
5 files changed, 37 insertions, 35 deletions
diff --git a/src/client/ClientBase.cpp b/src/client/ClientBase.cpp index aa54365..8988622 100644 --- a/src/client/ClientBase.cpp +++ b/src/client/ClientBase.cpp @@ -66,7 +66,7 @@ int ClientBase::Run() else { if(connection) { strcpy(out_buffer, "Server closed the connection. Use ESC to exit."); - AddMessage(out_buffer, system_msg); + AddMessage(out_buffer, SYSTEM_CHAR); connection = false; } } @@ -79,14 +79,21 @@ int ClientBase::Run() out_buffer[i] = 0; // in first char have may spec-symbol, check it: - int spec_msg = usual_msg; + char spec_char = USUAL_CHAR; char *buf = out_buffer; - if(out_buffer[0] == system_char) { - spec_msg = system_msg; - buf += 1; + switch(out_buffer[0]) { + case SYSTEM_CHAR: + case USERS_CHAR: + case GONLINE_CHAR: + case RONLINE_CHAR: { + spec_char = out_buffer[0]; + buf += 1; + break; + } + default: break; } - AddMessage(buf, spec_msg); + AddMessage(buf, spec_char); memmove(out_buffer, out_buffer + i + 1, out_buf_used - i - 1); out_buf_used -= i + 1; break; diff --git a/src/client/ClientBase.hpp b/src/client/ClientBase.hpp index 387505c..a5e76ed 100644 --- a/src/client/ClientBase.hpp +++ b/src/client/ClientBase.hpp @@ -21,7 +21,7 @@ public: void BreakLoop() { exit_flag = true; } virtual void HandleActions() {} - virtual void AddMessage(const char *msg, int type) {} + virtual void AddMessage(const char *msg, const char spec_char) {} void SendMessage(const char *msg); private: int CreateSocket(const char* ip, int port); diff --git a/src/client/clui/Client.cpp b/src/client/clui/Client.cpp index 9b697b6..fa89710 100644 --- a/src/client/clui/Client.cpp +++ b/src/client/clui/Client.cpp @@ -1,17 +1,11 @@ #include <string.h> +#include "../dimensions_client.hpp" #include "Client.hpp" #include "clui.hpp" -#define CHAT_HEIGHT 20 -#define CHAT_WIDTH 59 -#define PLAYERS_WIDTH 20 -#define PLAYERS_HEIGHT 12 -#define TIPS_WIDTH 20 -#define TIPS_HEIGHT 8 -#define INPUT_HEIGHT 4 -#define INPUT_WIDTH 80 - +const int input_lines = 2; +const int input_columns = 78; const int key_enter = 10; const int key_escape = 27; const int key_backspace = 127; @@ -19,10 +13,11 @@ const int key_backspace = 127; Client::Client(const char* ip, int port) : ClientBase(ip, port), in_buf_used(0), exit_flag(false) { - chat = new WindowChat(CHAT_HEIGHT, CHAT_WIDTH, 0, 0, 0); - players = new WindowPlayers(PLAYERS_HEIGHT, PLAYERS_WIDTH, 0, 60, 0); - tips = new WindowTips(TIPS_HEIGHT, TIPS_WIDTH, PLAYERS_HEIGHT, 60, 0); - input = new WindowInput(INPUT_HEIGHT, INPUT_WIDTH, 20, 0, 0); + // y+2 and x+2 for outlines + chat = new WindowChat(CHAT_LINES+2, CHAT_COLUMNS+2, 0, 0, 0); + players = new WindowPlayers(PLAYERS_LINES+2, PLAYERS_COLUMNS+2, 0, CHAT_COLUMNS+2+1, 0); + tips = new WindowTips(TIPS_LINES+2, TIPS_COLUMNS+2, PLAYERS_LINES+2, CHAT_COLUMNS+2+1, 0); + input = new WindowInput(input_lines+2, input_columns+2, CHAT_LINES+2, 0, 0); } Client::~Client() diff --git a/src/client/clui/WindowInterface.cpp b/src/client/clui/WindowInterface.cpp index 336d3b1..ffa8bc5 100644 --- a/src/client/clui/WindowInterface.cpp +++ b/src/client/clui/WindowInterface.cpp @@ -22,9 +22,9 @@ void WindowInterface::SetCursor(int y, int x) void WindowInterface::Clear(bool full) { - werase(this->GetWindow()); + werase(GetWindow()); if(!full) - box(this->GetWindow(), ch_line, ch_line); + box(GetWindow(), ch_line, ch_line); } void WindowInterface::Update() diff --git a/src/client/clui/clui.cpp b/src/client/clui/clui.cpp index 7b32478..46d3821 100644 --- a/src/client/clui/clui.cpp +++ b/src/client/clui/clui.cpp @@ -2,6 +2,7 @@ #include <unistd.h> #include <ncurses.h> +#include "../dimensions_client.hpp" #include "clui.hpp" WindowChat::~WindowChat() @@ -18,7 +19,7 @@ void WindowChat::AddMessage(const char *msg, const char spec_ch) message *recent_msg = new message; int len = strlen(msg); - int lines = (len / oneline_len) + 1; + int lines = (len / CHAT_COLUMNS) + 1; strcpy(recent_msg->text, msg); recent_msg->num_lines = lines; @@ -36,7 +37,7 @@ void WindowChat::ChatRedraw() return; Clear(false); - int available_lines = lines_in_chat; + int available_lines = CHAT_LINES; bool remove = false; message *tmp; @@ -75,9 +76,9 @@ void WindowChat::PrintMessage(int line, message *m) else wattron(w, A_BOLD); wmove(w, line-need_print+1, 1); - char *tmp = new char[oneline_len]; - int str = oneline_len * (m->num_lines - need_print); - memcpy(tmp, m->text + str, oneline_len); + char *tmp = new char[CHAT_COLUMNS]; + int str = CHAT_COLUMNS * (m->num_lines - need_print); + memcpy(tmp, m->text + str, CHAT_COLUMNS); wprintw(w, tmp); if(m->spec_char == SYSTEM_CHAR) wattroff(w, A_ITALIC); @@ -133,8 +134,8 @@ WindowTips::WindowTips(int num_y, int num_x, int by, int bx, char ch) : WindowInterface(num_y, num_x, by, bx, ch) { mvwprintw(w, num_y-7, 1, " Tips"); - mvwprintw(w, num_y-6, 1, "Online: "); - mvwprintw(w, num_y-5, 1, "Online room: "); + mvwprintw(w, TIPS_LINE_GONLINE, 1, "Online: "); + mvwprintw(w, TIPS_LINE_RONLINE, 1, "Online room: "); mvwprintw(w, num_y-4, 1, ""); mvwprintw(w, num_y-3, 1, "ESC - exit"); mvwprintw(w, num_y-2, 1, "ENTER - send msg"); @@ -144,15 +145,14 @@ WindowTips::WindowTips(int num_y, int num_x, int by, int bx, char ch) void WindowTips::SetGeneralOnline(const char *online) { // clear line: - wmove(w, ny-6, 1); + wmove(w, TIPS_LINE_GONLINE, 1); for(int i = 1; i < nx-1; i++) waddch(w, ' '); // print online char *str = new char[nx]; sprintf(str, "Online: %s", online); - mvwprintw(w, ny-6, 1, str); - Update(); + mvwprintw(w, TIPS_LINE_GONLINE, 1, str); delete[] str; Update(); } @@ -160,16 +160,16 @@ void WindowTips::SetGeneralOnline(const char *online) void WindowTips::SetRoomOnline(const char *online) { // clear line: - wmove(w, ny-5, 1); + wmove(w, TIPS_LINE_RONLINE, 1); for(int i = 1; i < nx-1; i++) waddch(w, ' '); // print online char *str = new char[nx]; sprintf(str, "Online room: %s", online); - mvwprintw(w, ny-5, 1, str); - Update(); + mvwprintw(w, TIPS_LINE_RONLINE, 1, str); delete[] str; + Update(); } |