Skip to content

Commit

Permalink
* Battle window popup menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Fries committed May 18, 2009
1 parent a06ff98 commit 007e4d7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
89 changes: 88 additions & 1 deletion ui/battlewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
#include "../net/protocolgame.h"
extern int g_lastmousebutton;

winBattle_t::BattleEntry* winBattle_t::get(uint32_t id)
{
std::vector<BattleEntry*>::iterator it;
for(it = entries.begin(); it != entries.end(); ++it)
{
BattleEntry* e = (*it);
if(e->creatureId == id)
{
return e;
}
}
}

void winBattle_t::add(uint32_t id)
{
BattleEntry* entry = new BattleEntry;
Expand Down Expand Up @@ -138,6 +151,79 @@ void winBattle_t::paintEntry(glictRect *real, glictRect *clipped, glictContainer
g_engine->drawText(creature->getName().c_str(), "aafont", (int)real->left+23, (int)real->top, col);
creature->Blit((int)real->left+4, (int)real->top+4, 20.f/32.f, 0, 0);
}

void winBattle_t::onAttack(Popup::Item* parent)
{
GM_Gameworld *gw = (GM_Gameworld*)g_game;
gw->m_protocol->sendAttackCreature((uint32_t)parent->data);
GlobalVariables::setAttackID((uint32_t)parent->data);
}

void winBattle_t::onFollow(Popup::Item* parent)
{
GM_Gameworld *gw = (GM_Gameworld*)g_game;
gw->m_protocol->sendFollowCreature((uint32_t)parent->data);
GlobalVariables::setFollowID((uint32_t)parent->data);
}

void winBattle_t::onMessageTo(Popup::Item *parent)
{
Creature* c = Creatures::getInstance().getCreature((uint32_t)parent->data);
if(c != NULL)
{
GM_Gameworld *gw = (GM_Gameworld*)g_game;
gw->setActiveConsole(gw->findConsole(c->getName()));
}
}

void winBattle_t::onUnimplemented(Popup::Item *parent)
{
GM_Gameworld *gw = (GM_Gameworld*)g_game;
gw->msgBox(gettext("This functionality is not yet finished"),"TODO");
}

void winBattle_t::makeConsolePopup(Popup* popup, void* owner, void* arg)
{
BattleEntry* e = (BattleEntry*)arg;
Creature* c = Creatures::getInstance().getCreature(e->creatureId);

std::stringstream s;
s.str("");
s << gettext("Attack");
popup->addItem(s.str(), winBattle_t::onAttack, (void*)c->getID());

s.str("");
s << gettext("Follow");
popup->addItem(s.str(), winBattle_t::onFollow, (void*)c->getID());

popup->addItem("-",NULL,NULL);

if (!c->isMonster() && !c->isNpc())
{
s.str("");
s << gettext("Message to") << " " << c->getName();
popup->addItem(s.str(), winBattle_t::onMessageTo, (void*)c->getID());

s.str("");
s << gettext("Add to VIP list");
popup->addItem(s.str(), winBattle_t::onUnimplemented, (void*)c->getID());

s.str("");
s << gettext("Ignore") << " " << c->getName();
popup->addItem(s.str(), winBattle_t::onUnimplemented, (void*)c->getID());

s.str("");
s << gettext("Invite to Party");
popup->addItem(s.str(), winBattle_t::onUnimplemented, (void*)c->getID());

popup->addItem("-",NULL,NULL);

s.str("");
s << gettext("Copy Name");
popup->addItem(s.str(), GM_Gameworld::onCopyName, (void*)c->getID());
}
}

void winBattle_t::clickEntry(glictPos* relmousepos, glictContainer* callerclass)
{
Creature* creature = Creatures::getInstance().getCreature((int)callerclass->GetCustomData());
Expand Down Expand Up @@ -166,6 +252,7 @@ void winBattle_t::clickEntry(glictPos* relmousepos, glictContainer* callerclass)
}
else
{
// TODO (nfries88): popup
winBattle_t::BattleEntry* e = gw->sbvlPanel.winBattle.get(creature->getID());
gw->performPopup(winBattle_t::makeConsolePopup, NULL, (void*) e);
}
}
10 changes: 9 additions & 1 deletion ui/battlewindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include <GLICT/panel.h>
#include <GLICT/progressbar.h>

#include "stackpanel.h"
#include "../stackpanel.h"
#include "../popup.h"

#include "../util.h"
#if defined(HAVE_LIBINTL_H)
Expand Down Expand Up @@ -76,6 +77,7 @@ class winBattle_t : public yatcStackPanelWindow
}
~winBattle_t(){}

BattleEntry* get(uint32_t id);
void add(uint32_t id);
void update(uint32_t id);
void remove(uint32_t id);
Expand All @@ -84,6 +86,12 @@ class winBattle_t : public yatcStackPanelWindow
virtual float GetDefaultHeight(){ return 160.F; }
virtual void OnClose();

static void makeConsolePopup(Popup* popup, void* owner, void* arg);
static void onUnimplemented(Popup::Item *parent);
static void onMessageTo(Popup::Item *parent);
static void onFollow(Popup::Item* parent);
static void onAttack(Popup::Item* parent);

static void paintEntry(glictRect *real, glictRect *clipped, glictContainer *caller);
static void clickEntry(glictPos* relmousepos, glictContainer* callerclass);
};
Expand Down

0 comments on commit 007e4d7

Please sign in to comment.