From 9f6cdb671ca3c045085bd8eed623e0a797894e1f Mon Sep 17 00:00:00 2001 From: Joursoir Date: Sat, 12 Dec 2020 12:41:39 +0000 Subject: GUI feature: handle players and online info from server, show it; fix: close app; --- src/client/gui/Client.cpp | 74 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 9 deletions(-) (limited to 'src/client/gui/Client.cpp') diff --git a/src/client/gui/Client.cpp b/src/client/gui/Client.cpp index 137558d..1d743ae 100644 --- a/src/client/gui/Client.cpp +++ b/src/client/gui/Client.cpp @@ -1,14 +1,69 @@ +#include "../dimensions_client.hpp" #include "Client.hpp" -void Client::AddMessage(const char *msg, int type) +void Client::AddMessage(const char *msg, const char spec_char) +{ + if(spec_char == USERS_CHAR) + UpdatePlayerList(msg); + else if(spec_char == GONLINE_CHAR) + SetGeneralOnline(msg); + else if(spec_char == RONLINE_CHAR) + SetRoomOnline(msg); + else + UpdateMessagesInChat(msg, spec_char); +} + +void Client::UpdatePlayerList(const char *list) +{ + // clear line: + for(int i = 0; i < PLAYERS_LINES-1; i++) + players[i]->value(""); + + + int len_list = strlen(list); + int p = 0; + int start = 0; + for(int i = 0; i < len_list; i++) { + if(list[i] == ';') + { + char *str = new char[max_name_len+1]; + int size = i - start; + memcpy(str, list+start, size); + str[size] = '\0'; + + players[p]->value(str); + start = i+1; + p++; + delete[] str; + } + } +} + +void Client::SetGeneralOnline(const char *online) +{ + char *str = new char[max_name_len+1]; + sprintf(str, "Online: %s", online); + tips[TIPS_LINE_GONLINE-1]->value(str); + delete[] str; +} + +void Client::SetRoomOnline(const char *online) +{ + char *str = new char[max_name_len+1]; + sprintf(str, "Online room: %s", online); + tips[TIPS_LINE_RONLINE-1]->value(str); + delete[] str; +} + +void Client::UpdateMessagesInChat(const char *msg, const char spec_char) { int len_msg = strlen(msg); char *source = new char[len_msg+1]; strcpy(source, msg); - int lines = (len_msg / oneline_len) + 1; + int lines = (len_msg / CHAT_COLUMNS) + 1; - for(int i = lines; i < lines_in_chat; i++) { + for(int i = lines; i < CHAT_LINES; i++) { chat[i-lines]->value(chat[i]->value()); chat[i-lines]->textfont(chat[i]->textfont()); } @@ -17,17 +72,18 @@ void Client::AddMessage(const char *msg, int type) while(need_print > 0) { int len = strlen(source); - int size = len > oneline_len ? oneline_len : len; + int size = len > CHAT_COLUMNS ? CHAT_COLUMNS : len; - char *str = new char[oneline_len + 1]; - int str_ptr = oneline_len * (lines - need_print); - memcpy(str, source + str_ptr, oneline_len); + char *str = new char[CHAT_COLUMNS + 1]; + int str_ptr = CHAT_COLUMNS * (lines - need_print); + memcpy(str, source + str_ptr, CHAT_COLUMNS); str[size] = '\0'; int spec = 0; - if(type == system_msg) spec = FL_ITALIC; + if(spec_char == SYSTEM_CHAR) spec = FL_ITALIC; + else spec = FL_BOLD; - int p = lines_in_chat-need_print; + int p = CHAT_LINES-need_print; chat[p]->textfont(STD_FONT+spec); chat[p]->value(str); delete[] str; -- cgit v1.2.3-18-g5258