diff --git a/Makefile.host b/Makefile.host index c7b87ba..4f72907 100644 --- a/Makefile.host +++ b/Makefile.host @@ -37,7 +37,7 @@ CPP_SRCS=Src/C64_SC.cpp Src/main.cpp Src/Display.cpp Src/Prefs.cpp Src/SID.cpp \ Src/gui/dialogue_box.cpp Src/gui/widget.cpp \ Src/gui/game_info.cpp Src/gui/status_bar.cpp Src/gui/gui.cpp Src/gui/listener.cpp \ Src/timer.cpp Src/utils.cpp Src/gui/virtual_keyboard.cpp Src/gui/menu.cpp \ - Src/gui/file_browser.cpp Src/data_store.cpp + Src/gui/file_browser.cpp Src/data_store.cpp Src/gui/network_server_messages.cpp C_SRCS=Src/d64-read.c Src/gui/menu_messages.c diff --git a/Makefile.wii b/Makefile.wii index dee74ab..1e768e8 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -67,7 +67,7 @@ CPPFILES := Display.cpp main.cpp Prefs.cpp SID.cpp REU.cpp IEC.cpp 1541fs.cpp \ Network.cpp gui/dialogue_box.cpp gui/widget.cpp utils.cpp \ gui/game_info.cpp gui/status_bar.cpp gui/gui.cpp gui/listener.cpp \ timer.cpp utils.cpp gui/virtual_keyboard.cpp gui/menu.cpp \ - gui/file_browser.cpp data_store.cpp + gui/file_browser.cpp data_store.cpp Src/gui/network_server_messages.cpp sFILES := SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) diff --git a/Src/Network.cpp b/Src/Network.cpp index b68db9e..ca7b386 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -30,6 +30,7 @@ #include "gui/gui.hh" #include "gui/status_bar.hh" #include "gui/network_user_menu.hh" +#include "gui/network_server_messages.hh" #if defined(GEKKO) # include @@ -961,6 +962,9 @@ bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst) NetworkUpdateTextMessage *tm = (NetworkUpdateTextMessage*)p->data; Gui::gui->status_bar->queueMessage((const char*)tm->data); + /* Queue up text message */ + if (tm->flags & NETWORK_UPDATE_TEXT_MESSAGE_BROADCAST) + Gui::gui->server_msgs->queueMessage((const char *)tm->data); } break; case REGISTER_DATA: { diff --git a/Src/gui/gui.cpp b/Src/gui/gui.cpp index 784eb2e..d7bd8b1 100644 --- a/Src/gui/gui.cpp +++ b/Src/gui/gui.cpp @@ -16,6 +16,8 @@ #include "sdl_ttf_font.hh" #include "virtual_keyboard.hh" +#include "network_server_messages.hh" + extern SDL_Surface *screen; #define THEME_ROOT_PATH "themes" @@ -135,6 +137,8 @@ Gui::~Gui() if (this->status_bar) delete this->status_bar; + if (this->server_msgs) + delete this->server_msgs; if (this->dlg) delete this->dlg; @@ -233,6 +237,7 @@ bool Gui::setTheme(const char *path) if (!this->mv) { this->status_bar = new StatusBar(); + this->server_msgs = new NetworkServerMessages(); this->mv = new MainView(); this->dv = new DiscView(); @@ -262,6 +267,7 @@ void Gui::runLogic(void) if (!this->is_active || !cur_view) return; + Gui::gui->server_msgs->runLogic(); if (this->dlg) this->dlg->runLogic(); else diff --git a/Src/gui/gui.hh b/Src/gui/gui.hh index 8a9ea48..9e03bbf 100644 --- a/Src/gui/gui.hh +++ b/Src/gui/gui.hh @@ -15,6 +15,7 @@ class DialogueBox; class StatusBar; +class NetworkServerMessages; class GameInfo; class MainView; @@ -105,6 +106,7 @@ public: VirtualKeyboard *kbd; DialogueBox *dlg; StatusBar *status_bar; + NetworkServerMessages *server_msgs; MainView *mv; DiscView *dv; diff --git a/Src/gui/main_menu.cpp b/Src/gui/main_menu.cpp index 3528f8d..5b17f78 100644 --- a/Src/gui/main_menu.cpp +++ b/Src/gui/main_menu.cpp @@ -190,11 +190,9 @@ public: dst = (SDL_Rect){350,13,0,0}; SDL_BlitSurface(Gui::gui->infobox, NULL, where, &dst); - dst = (SDL_Rect){350,242,0,0}; - SDL_BlitSurface(Gui::gui->textbox, NULL, where, &dst); - this->menu->draw(where, 50, 70, 300, 400); this->help->draw(where, 354, 24, 264, 210); + Gui::gui->server_msgs->draw(where); } protected: diff --git a/Src/gui/network_menu.cpp b/Src/gui/network_menu.cpp index afe5ebe..0a9cb04 100644 --- a/Src/gui/network_menu.cpp +++ b/Src/gui/network_menu.cpp @@ -186,11 +186,9 @@ public: dst = (SDL_Rect){350,13,0,0}; SDL_BlitSurface(Gui::gui->infobox, NULL, where, &dst); - dst = (SDL_Rect){350,242,0,0}; - SDL_BlitSurface(Gui::gui->textbox, NULL, where, &dst); - this->menu->draw(where, 50, 70, 300, 400); this->help->draw(where, 354, 24, 264, 210); + Gui::gui->server_msgs->draw(where); } protected: diff --git a/Src/gui/network_server_messages.cpp b/Src/gui/network_server_messages.cpp new file mode 100644 index 0000000..1adb7c6 --- /dev/null +++ b/Src/gui/network_server_messages.cpp @@ -0,0 +1,78 @@ +#include "network_server_messages.hh" +#include "utils.hh" + +NetworkServerMessages::NetworkServerMessages() : StatusBar() +{ + unsigned i; + + for (i = 0; i < ARRAY_SIZE(this->flowed_messages) - 1; i++) + this->flowed_messages[i] = (char *)xmalloc(28); + this->flowed_messages[i] = NULL; +} + +NetworkServerMessages::~NetworkServerMessages() +{ + for (unsigned i = 0; i < ARRAY_SIZE(this->flowed_messages) - 1; i++) + free(this->flowed_messages[i]); +} + +void NetworkServerMessages::draw(SDL_Surface *where) +{ + SDL_Rect dst; + int x = 350; + int y = 242; + int w = Gui::gui->textbox->w; + int h = Gui::gui->textbox->h; + + dst = (SDL_Rect){x,y,0,0}; + SDL_BlitSurface(Gui::gui->textbox, NULL, where, &dst); + + Menu::draw(where, x+6, y+8, w-6, h-8); +} + +void NetworkServerMessages::timeoutCallback() +{ + const char *cur = this->messages[this->tail]; + char *cpy = xstrdup(cur); + char *msgp; + char *p; + size_t line_len = 0; + size_t line = 0; + + for (unsigned i = 0; i < ARRAY_SIZE(this->flowed_messages) - 1; i++) + this->flowed_messages[i][0] = '\0'; + + p = strtok_r(cpy, " ", &msgp); + while (p) + { + int word_len = strlen(p); + + if (line_len + word_len > 24) + { + line++; + /* Too long! */ + if (line >= ARRAY_SIZE(this->flowed_messages)) + break; + line_len = 0; + } + strcat(this->flowed_messages[line], p); + strcat(this->flowed_messages[line], " "); + + line_len += word_len + 1; + p = strtok_r(NULL, " ", &msgp); + } + for (line = line + 1; line < ARRAY_SIZE(this->flowed_messages) - 1; line++) + strcpy(this->flowed_messages[line], "#"); + + this->setText((const char **)this->flowed_messages); + + while (1) + { + this->tail = (this->tail + 1) % N_STATUS_MESSAGES; + if (this->messages[this->tail]) + break; + } + Gui::gui->timerController->arm(this, 5000); + + free(cpy); +} diff --git a/Src/gui/network_server_messages.hh b/Src/gui/network_server_messages.hh new file mode 100644 index 0000000..cf72181 --- /dev/null +++ b/Src/gui/network_server_messages.hh @@ -0,0 +1,24 @@ +#ifndef NETWORK_SERVER_MESSAGES_HH +#define NETWORK_SERVER_MESSAGES_HH + +#include + +#include "status_bar.hh" + +class NetworkServerMessages : public StatusBar +{ +public: + NetworkServerMessages(); + + ~NetworkServerMessages(); + + virtual void draw(SDL_Surface *where); + +protected: + virtual void timeoutCallback(); + +private: + char *flowed_messages[8]; +}; + +#endif /* NETWORK_SERVER_MESSAGES_HH */ diff --git a/Src/gui/status_bar.cpp b/Src/gui/status_bar.cpp index d04b71f..ab0f537 100644 --- a/Src/gui/status_bar.cpp +++ b/Src/gui/status_bar.cpp @@ -13,6 +13,9 @@ StatusBar::StatusBar() : Menu(Gui::gui->small_font), TimeoutHandler() void StatusBar::queueMessage(const char *message) { + /* Free the existing message if we are overwriting it */ + free((void*)this->messages[this->head]); + this->messages[this->head] = xstrdup(message); /* If this is the first message, display it as soon as possible */ @@ -30,6 +33,7 @@ const char *StatusBar::dequeueMessage() if (this->head == this->tail) return NULL; + this->messages[this->tail] = NULL; this->tail = (this->tail + 1) % N_STATUS_MESSAGES; return out; diff --git a/Src/gui/status_bar.hh b/Src/gui/status_bar.hh index 4395ce4..7e68ace 100644 --- a/Src/gui/status_bar.hh +++ b/Src/gui/status_bar.hh @@ -6,9 +6,9 @@ #include "menu.hh" #include "gui.hh" -#define N_STATUS_MESSAGES 8 +#define N_STATUS_MESSAGES 10 -class StatusBar : public Menu, TimeoutHandler +class StatusBar : public Menu, public TimeoutHandler { public: StatusBar();