From 5f00b25ba2895704123eb3d01b3ab5d012d2f333 Mon Sep 17 00:00:00 2001 From: Tametomo Date: Wed, 15 Apr 2009 19:55:29 +0200 Subject: Some PopupMenu cleanups/fixes and additions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tametomo Signed-off-by: Bjørn Lindeijer --- src/engine.cpp | 4 ++++ src/floor_item.cpp | 5 +++++ src/floor_item.h | 6 ++++++ src/gui/popupmenu.cpp | 42 +++++++++++++++++++++++++----------------- src/gui/viewport.cpp | 9 +++++++-- src/gui/viewport.h | 6 ++++++ src/monster.cpp | 21 +++++++++------------ src/net/ea/playerhandler.cpp | 1 + 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 @@ -63,6 +63,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. */ 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(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(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 @@ -108,6 +108,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. */ 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 &sprites = info.getSprites(); for (std::list::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 &particleEffects = info.getParticleEffects(); - for ( std::list::const_iterator i = particleEffects.begin(); - i != particleEffects.end(); i++ - ) + for (std::list::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; -- cgit v1.2.3-70-g09d2