mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-25 12:56:59 +01:00
Add server message box support
This commit is contained in:
parent
fa26ae2980
commit
75385f566b
@ -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
|
||||
|
||||
|
@ -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)))
|
||||
|
@ -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 <wiiuse/wpad.h>
|
||||
@ -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:
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
78
Src/gui/network_server_messages.cpp
Normal file
78
Src/gui/network_server_messages.cpp
Normal file
@ -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);
|
||||
}
|
24
Src/gui/network_server_messages.hh
Normal file
24
Src/gui/network_server_messages.hh
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef NETWORK_SERVER_MESSAGES_HH
|
||||
#define NETWORK_SERVER_MESSAGES_HH
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#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 */
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user