summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTametomo <irarice@gmail.com>2009-04-15 19:55:29 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-15 19:57:02 +0200
commit5f00b25ba2895704123eb3d01b3ab5d012d2f333 (patch)
tree5f94b0a8b54c8a2200c1fe568917f06551208b07
parentef13037435c671b76c75c3ecefbad83dbdc578f2 (diff)
downloadmana-client-5f00b25ba2895704123eb3d01b3ab5d012d2f333.tar.gz
mana-client-5f00b25ba2895704123eb3d01b3ab5d012d2f333.tar.bz2
mana-client-5f00b25ba2895704123eb3d01b3ab5d012d2f333.tar.xz
mana-client-5f00b25ba2895704123eb3d01b3ab5d012d2f333.zip
Some PopupMenu cleanups/fixes and additions.
Signed-off-by: Tametomo <irarice@gmail.com> Signed-off-by: Bjørn Lindeijer <bjorn@lindeijer.nl>
-rw-r--r--src/engine.cpp4
-rw-r--r--src/floor_item.cpp5
-rw-r--r--src/floor_item.h6
-rw-r--r--src/gui/popupmenu.cpp42
-rw-r--r--src/gui/viewport.cpp9
-rw-r--r--src/gui/viewport.h6
-rw-r--r--src/monster.cpp21
-rw-r--r--src/net/ea/playerhandler.cpp1
8 files changed, 63 insertions, 31 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 95f2cb1b..61293339 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -58,6 +58,10 @@ bool Engine::changeMap(const std::string &mapPath)
floorItemManager->clear();
beingManager->clear();
+ // Close the popup menu on map change so that invalid options can't be
+ // executed.
+ viewport->closePopupMenu();
+
// Unset the map of the player so that its particles are cleared before
// being deleted in the next step
if (player_node)
diff --git a/src/floor_item.cpp b/src/floor_item.cpp
index 000835ad..b8c0ffaf 100644
--- a/src/floor_item.cpp
+++ b/src/floor_item.cpp
@@ -56,6 +56,11 @@ int FloorItem::getItemId() const
return mItem->getId();
}
+Item* FloorItem::getItem() const
+{
+ return mItem;
+}
+
void FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const
{
graphics->drawImage(mItem->getImage(),
diff --git a/src/floor_item.h b/src/floor_item.h
index 7ca0f5a3..0e269c77 100644
--- a/src/floor_item.h
+++ b/src/floor_item.h
@@ -64,6 +64,12 @@ class FloorItem : public Sprite
int getItemId() const;
/**
+ * Returns the item object. Useful for adding an item link for the floor
+ * item to chat.
+ */
+ Item* getItem() const;
+
+ /**
* Returns the x coordinate.
*/
int getX() const { return mX; }
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index e8af3122..ef1990f8 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -78,13 +78,13 @@ void PopupMenu::showPopup(int x, int y, Being *being)
if (being->getType() != Being::UNKNOWN)
mBrowserBox->addRow(_("@@name|Add name to chat@@"));
+ const std::string &name = being->getName();
switch (being->getType())
{
case Being::PLAYER:
{
// Players can be traded with. Later also follow and
// add as buddy will be options in this menu.
- const std::string &name = being->getName();
mBrowserBox->addRow(strprintf(_("@@trade|Trade With %s@@"), name.c_str()));
mBrowserBox->addRow(strprintf(_("@@attack|Attack %s@@"), name.c_str()));
@@ -109,7 +109,7 @@ void PopupMenu::showPopup(int x, int y, Being *being)
break;
}
- //mBrowserBox->addRow(_("@@follow|Follow ") + name + "@@");
+ //mBrowserBox->addRow(_(strprintf("@@follow|Follow %s@@"), name.c_str()));
//mBrowserBox->addRow(_("@@buddy|Add ") + name + " to Buddy List@@");
mBrowserBox->addRow(strprintf(_("@@guild|Invite %s to join your guild@@"), name.c_str()));
mBrowserBox->addRow(strprintf(_("@@party|Invite %s to join your party@@"), name.c_str()));
@@ -123,7 +123,12 @@ void PopupMenu::showPopup(int x, int y, Being *being)
case Being::NPC:
// NPCs can be talked to (single option, candidate for removal
// unless more options would be added)
- mBrowserBox->addRow(_("@@talk|Talk To NPC@@"));
+ mBrowserBox->addRow(strprintf(_("@@talk|Talk To %s@@"), name.c_str()));
+ break;
+
+ case Being::MONSTER:
+ // Monsters can be attacked
+ mBrowserBox->addRow(strprintf(_("@@attack|Attack %s@@"), name.c_str()));
break;
/*case Being::MONSTER:
@@ -132,7 +137,7 @@ void PopupMenu::showPopup(int x, int y, Being *being)
default:
/* Other beings aren't interesting... */
- break;
+ return;
}
//browserBox->addRow("@@look|Look To@@");
@@ -145,11 +150,13 @@ void PopupMenu::showPopup(int x, int y, Being *being)
void PopupMenu::showPopup(int x, int y, FloorItem *floorItem)
{
mFloorItem = floorItem;
+ mItem = floorItem->getItem();
mBrowserBox->clearRows();
// Floor item can be picked up (single option, candidate for removal)
std::string name = ItemDB::get(mFloorItem->getItemId()).getName();
mBrowserBox->addRow(strprintf(_("@@pickup|Pick Up %s@@"), name.c_str()));
+ mBrowserBox->addRow(_("@@chat|Add to Chat@@"));
//browserBox->addRow("@@look|Look To@@");
mBrowserBox->addRow("##3---");
@@ -181,9 +188,7 @@ void PopupMenu::handleLink(const std::string &link)
}
#ifdef EATHENA_SUPPORT
// Attack action
- else if (link == "attack" &&
- being &&
- being->getType() == Being::PLAYER)
+ else if (link == "attack" && being)
{
player_node->attack(being, true);
}
@@ -224,11 +229,6 @@ void PopupMenu::handleLink(const std::string &link)
player_node->inviteToGuild(being);
}
#endif
- // Add player to your party
- else if (link == "party")
- {
- player_node->inviteToParty(dynamic_cast<Player*>(being));
- }
/*
// Follow Player action
else if (link == "follow")
@@ -244,10 +244,6 @@ void PopupMenu::handleLink(const std::string &link)
buddyWindow->addBuddy(being->getName());
}*/
- else if (link == "name")
- {
- chatWindow->addInputText(being->getName());
- }
// Pick Up Floor Item action
else if ((link == "pickup") && mFloorItem)
@@ -294,11 +290,23 @@ void PopupMenu::handleLink(const std::string &link)
new ItemAmountWindow(ItemAmountWindow::ItemSplit,
inventoryWindow, mItem);
}
+
else if (link == "drop")
{
new ItemAmountWindow(ItemAmountWindow::ItemDrop,
inventoryWindow, mItem);
}
+
+ else if (link == "party" && being && being->getType() == Being::PLAYER)
+ {
+ player_node->inviteToParty(dynamic_cast<Player*>(being));
+ }
+
+ else if (link == "name" && being)
+ {
+ chatWindow->addInputText(being->getName());
+ }
+
else if (link == "admin-kick" &&
being &&
(being->getType() == Being::PLAYER ||
@@ -308,7 +316,7 @@ void PopupMenu::handleLink(const std::string &link)
}
// Unknown actions
- else
+ else if (link != "cancel")
{
std::cout << link << std::endl;
}
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 3fc5f2d4..9ce537fc 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -313,8 +313,8 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
if ((being = beingManager->findBeingByPixel(pixelx, pixely)) &&
being != player_node)
{
- mPopupMenu->showPopup(event.getX(), event.getY(), being);
- return;
+ mPopupMenu->showPopup(event.getX(), event.getY(), being);
+ return;
}
else if ((floorItem = floorItemManager->findByCoordinates(tilex,
tiley)))
@@ -446,6 +446,11 @@ void Viewport::showPopup(int x, int y, Item *item)
mPopupMenu->showPopup(x, y, item);
}
+void Viewport::closePopupMenu()
+{
+ mPopupMenu->handleLink("cancel");
+}
+
void Viewport::optionChanged(const std::string &name)
{
mScrollLaziness = (int) config.getValue("ScrollLaziness", 32);
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index cff23862..3dae5a2a 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -109,6 +109,12 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
void showPopup(int x, int y, Item *item);
/**
+ * Closes the popup menu. Needed for when the player dies or switching
+ * maps.
+ */
+ void closePopupMenu();
+
+ /**
* A relevant config option changed.
*/
void optionChanged(const std::string &name);
diff --git a/src/monster.cpp b/src/monster.cpp
index 08a614ea..92e1f84a 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -43,8 +43,7 @@ Monster::Monster(int id, int job, Map *map):
const std::list<std::string> &sprites = info.getSprites();
for (std::list<std::string>::const_iterator i = sprites.begin();
- i != sprites.end();
- i++)
+ i != sprites.end(); i++)
{
if (c == VECTOREND_SPRITE) break;
@@ -62,15 +61,16 @@ Monster::Monster(int id, int job, Map *map):
if (mParticleEffects)
{
const std::list<std::string> &particleEffects = info.getParticleEffects();
- for ( std::list<std::string>::const_iterator i = particleEffects.begin();
- i != particleEffects.end(); i++
- )
+ for (std::list<std::string>::const_iterator i = particleEffects.begin();
+ i != particleEffects.end(); i++)
{
controlParticle(particleEngine->addEffect((*i), 0, 0));
}
}
mNameColor = &guiPalette->getColor(Palette::MONSTER);
+
+ Being::setName(getInfo().getName());
}
Monster::~Monster()
@@ -86,9 +86,7 @@ void Monster::logic()
mFrame = (get_elapsed_time(mWalkTime) * 4) / getWalkSpeed();
if (mFrame >= 4 && mAction != DEAD)
- {
nextStep();
- }
}
Being::logic();
@@ -132,8 +130,7 @@ void Monster::setAction(Action action, int attackType)
default: break;
}
Particle *p;
- p = particleEngine->addEffect(
- particleEffect, 0, 0, rotation);
+ p = particleEngine->addEffect(particleEffect, 0, 0, rotation);
controlParticle(p);
}
break;
@@ -153,9 +150,7 @@ void Monster::setAction(Action action, int attackType)
for (int i = 0; i < VECTOREND_SPRITE; i++)
{
if (mSprites[i])
- {
mSprites[i]->play(currentAction);
- }
}
mAction = action;
}
@@ -190,7 +185,9 @@ void Monster::handleAttack(Being *victim, int damage, AttackType type)
void Monster::takeDamage(Being *attacker, int amount, AttackType type)
{
- if (amount > 0) sound.playSfx(getInfo().getSound(MONSTER_EVENT_HURT));
+ if (amount > 0)
+ sound.playSfx(getInfo().getSound(MONSTER_EVENT_HURT));
+
Being::takeDamage(attacker, amount, type);
}
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index 3b8b86af..5d2a4829 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -95,6 +95,7 @@ namespace {
if (storageWindow->isVisible())
storageWindow->close();
+ viewport->closePopupMenu();
}
} deathListener;