diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-02-08 23:18:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-02-08 23:18:03 +0300 |
commit | 7380aa6e86b51ef62530bea5d6f6f63244dffc4a (patch) | |
tree | 1b9915284b2b9c3e0969ae05f54a53adba72e527 /src/gui/windows | |
parent | 7e66a4606bb15d98197f71245fe191d03152ee5f (diff) | |
download | manaplus-7380aa6e86b51ef62530bea5d6f6f63244dffc4a.tar.gz manaplus-7380aa6e86b51ef62530bea5d6f6f63244dffc4a.tar.bz2 manaplus-7380aa6e86b51ef62530bea5d6f6f63244dffc4a.tar.xz manaplus-7380aa6e86b51ef62530bea5d6f6f63244dffc4a.zip |
Add some missing checks and remove useless checks.
Diffstat (limited to 'src/gui/windows')
-rw-r--r-- | src/gui/windows/inventorywindow.cpp | 34 | ||||
-rw-r--r-- | src/gui/windows/shopwindow.cpp | 28 | ||||
-rw-r--r-- | src/gui/windows/skilldialog.cpp | 139 |
3 files changed, 93 insertions, 108 deletions
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index e21299583..5c6ae3faa 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -572,28 +572,32 @@ void InventoryWindow::mouseClicked(MouseEvent &event) tradeWindow->isWindowVisible() && inputManager.isActionActive(InputAction::STOP_ATTACK)); - if (!mod && !mod2 && event.getButton() == MouseButton::RIGHT) + if (mInventory) { - Item *const item = mItems->getSelectedItem(); + if (!mod && !mod2 && event.getButton() == MouseButton::RIGHT) + { + Item *const item = mItems->getSelectedItem(); - if (!item) - return; + if (!item) + return; - /* Convert relative to the window coordinates to absolute screen - * coordinates. - */ - const int mx = event.getX() + getX(); - const int my = event.getY() + getY(); + /* Convert relative to the window coordinates to absolute screen + * coordinates. + */ + const int mx = event.getX() + getX(); + const int my = event.getY() + getY(); - if (popupMenu) - popupMenu->showPopup(this, mx, my, item, mInventory->getType()); + if (popupMenu) + popupMenu->showPopup(this, mx, my, item, mInventory->getType()); + } } - - if (!mInventory) + else + { return; + } - if (event.getButton() == MouseButton::LEFT - || event.getButton() == MouseButton::RIGHT) + if (event.getButton() == MouseButton::LEFT || + event.getButton() == MouseButton::RIGHT) { Item *const item = mItems->getSelectedItem(); diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index 7c75c4f92..cf57312dd 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -270,10 +270,10 @@ void ShopWindow::action(const ActionEvent &event) { if (isBuySelected) { - if (mBuyShopItems && mBuyShopItems->getNumberOfElements() > 0) + if (mBuyShopItems->getNumberOfElements() > 0) announce(mBuyShopItems, BUY); } - else if (mSellShopItems && mSellShopItems->getNumberOfElements() > 0) + else if (mSellShopItems->getNumberOfElements() > 0) { announce(mSellShopItems, SELL); } @@ -493,7 +493,7 @@ void ShopWindow::setVisible(Visible visible) void ShopWindow::addBuyItem(const Item *const item, const int amount, const int price) { - if (!mBuyShopItems || !item) + if (!item) return; const bool emp = isShopEmpty(); mBuyShopItems->addItemNoDup(item->getId(), @@ -510,7 +510,7 @@ void ShopWindow::addBuyItem(const Item *const item, const int amount, void ShopWindow::addSellItem(const Item *const item, const int amount, const int price) { - if (!mBuyShopItems || !item) + if (!item) return; const bool emp = isShopEmpty(); mSellShopItems->addItemNoDup(item->getId(), @@ -526,9 +526,6 @@ void ShopWindow::addSellItem(const Item *const item, const int amount, void ShopWindow::loadList() { - if (!mBuyShopItems || !mSellShopItems) - return; - std::ifstream shopFile; struct stat statbuf; @@ -562,12 +559,12 @@ void ShopWindow::loadList() if (tokens.size() == 5 && tokens[0]) { // +++ need impliment colors? - if (tokens[1] && tokens[2] && mBuyShopItems) + if (tokens[1] && tokens[2]) { mBuyShopItems->addItem( tokens[0], 0, ItemColor_one, tokens[1], tokens[2]); } - if (tokens[3] && tokens[4] && mSellShopItems) + if (tokens[3] && tokens[4]) { mSellShopItems->addItem( tokens[0], 0, ItemColor_one, tokens[3], tokens[4]); @@ -581,9 +578,6 @@ void ShopWindow::loadList() void ShopWindow::saveList() const { - if (!mBuyShopItems || !mSellShopItems) - return; - std::ofstream shopFile; const std::string shopListName = settings.serverConfigDir + "/shoplist.txt"; @@ -1045,17 +1039,9 @@ bool ShopWindow::findShopItem(const ShopItem *const shopItem, std::vector<ShopItem*> items; if (mode == SELL) - { - if (!mSellShopItems) - return false; items = mSellShopItems->items(); - } else - { - if (!mBuyShopItems) - return false; items = mBuyShopItems->items(); - } FOR_EACH (std::vector<ShopItem*>::const_iterator, it, items) { @@ -1095,8 +1081,6 @@ int ShopWindow::sumAmount(const Item *const shopItem) bool ShopWindow::isShopEmpty() const { - if (!mBuyShopItems || !mSellShopItems) - return true; if (mBuyShopItems->empty() && mSellShopItems->empty()) return true; return false; diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index d8ae3ef2d..c5eb45c02 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -745,95 +745,92 @@ void SkillDialog::useSkill(const SkillInfo *const info, if (!cmd.empty()) SpellManager::invokeCommand(cmd, localPlayer->getTarget()); } - if (localPlayer) + switch (info->type) { - switch (info->type) + case SkillType::Attack: { - case SkillType::Attack: + const Being *being = localPlayer->getTarget(); + if (!being && autoTarget == AutoTarget_true) { - const Being *being = localPlayer->getTarget(); - if (!being && autoTarget == AutoTarget_true) - { - being = localPlayer->setNewTarget(ActorType::Monster, - AllowSort_true); - } - if (being) - { - skillHandler->useBeing(info->id, - level, - being->getId()); - } - break; + being = localPlayer->setNewTarget(ActorType::Monster, + AllowSort_true); } - case SkillType::Support: + if (being) { - const Being *being = localPlayer->getTarget(); - if (!being) - being = localPlayer; - if (being) - { - skillHandler->useBeing(info->id, - level, - being->getId()); - } - break; + skillHandler->useBeing(info->id, + level, + being->getId()); } - case SkillType::Self: + break; + } + case SkillType::Support: + { + const Being *being = localPlayer->getTarget(); + if (!being) + being = localPlayer; + if (being) + { skillHandler->useBeing(info->id, level, - localPlayer->getId()); - break; + being->getId()); + } + break; + } + case SkillType::Self: + skillHandler->useBeing(info->id, + level, + localPlayer->getId()); + break; - case SkillType::Ground: + case SkillType::Ground: + { + int x = 0; + int y = 0; + viewport->getMouseTile(x, y); + if (info->useTextParameter) { - int x = 0; - int y = 0; - viewport->getMouseTile(x, y); - if (info->useTextParameter) + if (withText) { - if (withText) - { - skillHandler->usePos(info->id, - level, - x, y, - text); - } - else - { - textSkillListener.setSkill(info->id, - x, - y, - level); - TextDialog *const dialog = CREATEWIDGETR(TextDialog, - // TRANSLATORS: text skill dialog header - strprintf(_("Add text to skill %s"), - data->name.c_str()), - // TRANSLATORS: text skill dialog field - _("Text: ")); - dialog->setModal(Modal_true); - textSkillListener.setDialog(dialog); - dialog->setActionEventId("ok"); - dialog->addActionListener(&textSkillListener); - } + skillHandler->usePos(info->id, + level, + x, y, + text); } else { - skillHandler->usePos(info->id, - level, - x, y); + textSkillListener.setSkill(info->id, + x, + y, + level); + TextDialog *const dialog = CREATEWIDGETR(TextDialog, + // TRANSLATORS: text skill dialog header + strprintf(_("Add text to skill %s"), + data->name.c_str()), + // TRANSLATORS: text skill dialog field + _("Text: ")); + dialog->setModal(Modal_true); + textSkillListener.setDialog(dialog); + dialog->setActionEventId("ok"); + dialog->addActionListener(&textSkillListener); } - break; } + else + { + skillHandler->usePos(info->id, + level, + x, y); + } + break; + } - case SkillType::TargetTrap: - // for now unused - break; + case SkillType::TargetTrap: + // for now unused + break; - case SkillType::Unknown: - case SkillType::Unused: - default: - break; - } + case SkillType::Unknown: + case SkillType::Unused: + default: + break; } } |