Add a info box for the network peers. Completely untested, of course.

This commit is contained in:
simon.kagstrom 2010-02-11 06:37:01 +00:00
parent c5053b8c61
commit 46d0980f50

View File

@ -38,22 +38,111 @@ public:
return this->scr;
}
const char *getRegion()
{
switch (this->region)
{
case 1: return "Europe";
case 2: return "Africa";
case 3: return "North America";
case 4: return "South America";
case 5: return "Asia";
case 6: return "Australia";
case 7: return "Antartica"; // Likely, yes
default:
break;
}
return "Unknown";
}
SDL_Surface *scr;
const char *name;
int region;
int scr_key;
};
class PeerInfoBox : public Menu
{
public:
PeerInfoBox(Font *font) : Menu(font)
{
this->pi = NULL;
memset(this->pi_messages, 0, sizeof(this->pi_messages));
this->setSelectedBackground(NULL, NULL, NULL, NULL, NULL, NULL);
}
void setPeerInfo(PeerInfo *pi)
{
this->pi = pi;
this->updateMessages();
}
virtual void selectCallback(int which) { }
virtual void hoverCallback(int which) { }
virtual void escapeCallback(int which) { }
void draw(SDL_Surface *where, int x, int y, int w, int h)
{
SDL_Surface *screenshot;
SDL_Rect dst;
if (!this->pi)
return;
screenshot = this->pi->getScreenshot();
if (!screenshot)
{
Menu::draw(where, x, y + 10, w, h - 10);
return;
}
/* Blit the screenshot */
dst = (SDL_Rect){x + w / 2 - screenshot->w / 2, y, w, h};
SDL_BlitSurface(screenshot, NULL, where, &dst);
Menu::draw(where, x, y + screenshot->h + 10, w, h - screenshot->h - 10);
}
void updateMessages()
{
this->setText(NULL);
memset(this->pi_messages, 0, sizeof(this->pi_messages));
this->pi_messages[0] = "Name:";
this->pi_messages[1] = " ";
this->pi_messages[2] = "Region:";
this->pi_messages[3] = " ";
this->pi_messages[4] = "Vobb:";
this->pi_messages[5] = " ";
if (this->pi)
{
this->pi_messages[1] = this->pi->name;
this->pi_messages[3] = this->pi->getRegion();
this->pi_messages[5] = " ";
}
this->setText(this->pi_messages);
}
const char *pi_messages[8];
PeerInfo *pi;
};
class NetworkUserMenu : public Menu
{
friend class NetworkUserView;
public:
NetworkUserMenu(Font *font) : Menu(font)
NetworkUserMenu(Font *font, PeerInfoBox *infoBox) : Menu(font)
{
this->setText(NULL);
this->peers = NULL;
this->n_peers = 0;
this->infoBox = infoBox;
}
~NetworkUserMenu()
@ -89,6 +178,11 @@ public:
virtual void hoverCallback(int which)
{
panic_if(which >= (int)this->n_peers,
"Which is impossibly large: %d vs %d\n",
which, this->n_peers);
this->infoBox->setPeerInfo(this->peers[which]);
}
virtual void escapeCallback(int which)
@ -105,6 +199,7 @@ private:
}
PeerInfo **peers;
PeerInfoBox *infoBox;
unsigned int n_peers;
};
@ -114,7 +209,8 @@ class NetworkUserView : public GuiView
public:
NetworkUserView() : GuiView()
{
this->menu = new NetworkUserMenu(Gui::gui->default_font);
this->peerInfo = new PeerInfoBox(Gui::gui->default_font);
this->menu = new NetworkUserMenu(Gui::gui->default_font, this->peerInfo);
}
~NetworkUserView()
@ -144,8 +240,10 @@ public:
SDL_BlitSurface(Gui::gui->disc_info, NULL, where, &dst);
this->menu->draw(where, 50, 70, 280, 375);
this->peerInfo->draw(where, 360, 55, 262, 447);
}
protected:
NetworkUserMenu *menu;
PeerInfoBox *peerInfo;
};