diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-03-10 20:20:36 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-03-10 20:20:36 +0300 |
commit | 501f9934731114562c3659918d9d7b39625eb7b5 (patch) | |
tree | afefc8debeff97d40141a342135da8e7ab5cb9bb /src | |
parent | 307818fecbd1f258c668a1667e76e950e9d22622 (diff) | |
download | manaplus-501f9934731114562c3659918d9d7b39625eb7b5.tar.gz manaplus-501f9934731114562c3659918d9d7b39625eb7b5.tar.bz2 manaplus-501f9934731114562c3659918d9d7b39625eb7b5.tar.xz manaplus-501f9934731114562c3659918d9d7b39625eb7b5.zip |
Allow add skills to shortcuts bar (same as for magic and script commands).
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/popupmenu.cpp | 7 | ||||
-rw-r--r-- | src/gui/skilldialog.cpp | 36 | ||||
-rw-r--r-- | src/gui/skilldialog.h | 8 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/itemshortcutcontainer.cpp | 29 | ||||
-rw-r--r-- | src/itemshortcut.cpp | 11 |
6 files changed, 78 insertions, 15 deletions
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 5e5f310dc..d37e8f351 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -49,6 +49,7 @@ #include "gui/ministatuswindow.h" #include "gui/outfitwindow.h" #include "gui/selldialog.h" +#include "gui/skilldialog.h" #include "gui/socialwindow.h" #include "gui/textcommandeditor.h" #include "gui/textdialog.h" @@ -1109,10 +1110,14 @@ void PopupMenu::handleLink(const std::string &link, } } } - else if (spellManager) + else if (mItemId < SKILL_MIN_ID && spellManager) { spellManager->useItem(mItemId); } + else if (skillDialog) + { + skillDialog->useItem(mItemId); + } } else if (link == "chat") { diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 023c5a4f0..a930d3929 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -22,12 +22,14 @@ #include "gui/skilldialog.h" +#include "itemshortcut.h" #include "localplayer.h" #include "logger.h" #include "playerinfo.h" #include "configuration.h" #include "gui/setup.h" +#include "gui/shortcutwindow.h" #include "gui/textpopup.h" #include "gui/theme.h" #include "gui/viewport.h" @@ -268,9 +270,20 @@ void SkillDialog::action(const gcn::ActionEvent &event) if (tab) { if (SkillInfo *info = tab->getSelectedInfo()) + { mUseButton->setEnabled(info->range > 0); + + int num = itemShortcutWindow->getTabIndex(); + if (num >= 0 && num < SHORTCUT_TABS && itemShortcut[num]) + { + itemShortcut[num]->setItemSelected( + info->id + SKILL_MIN_ID); + } + } else + { mUseButton->setEnabled(false); + } } } else if (event.getId() == "use") @@ -361,6 +374,7 @@ void SkillDialog::loadSkills(const std::string &file) skill->id = 1; skill->name = _("basic"); skill->dispName = _("Skill: basic, Id: 1"); + skill->shortName = "bas"; skill->setIcon(""); skill->modifiable = true; skill->visible = true; @@ -416,6 +430,8 @@ void SkillDialog::loadSkills(const std::string &file) skill->name = name; skill->dispName = strprintf(_("Skill: %s, Id: %d"), name.c_str(), skill->id); + skill->shortName = XML::langProperty(node, + "shortName", name.substr(0, 3)); skill->setIcon(icon); skill->modifiable = false; skill->visible = false; @@ -507,9 +523,9 @@ void SkillModel::updateVisibilities() } SkillInfo::SkillInfo() : - id(0), name(""), dispName(""), icon(nullptr), modifiable(false), - visible(false), model(nullptr), level(0), skillLevel(""), - skillLevelWidth(0), skillExp(""), progress(0.0f), range(0), + id(0), name(""), shortName(""), dispName(""), icon(nullptr), + modifiable(false), visible(false), model(nullptr), level(0), + skillLevel(""), skillLevelWidth(0), skillExp(""), progress(0.0f), range(0), particle(""), soundHit(""), soundMiss("") { } @@ -626,3 +642,17 @@ void SkillDialog::widgetResized(const gcn::Event &event) if (mTabs) mTabs->fixSize(); } + +void SkillDialog::useItem(int itemId) +{ + const SkillInfo *info = mSkills[itemId - SKILL_MIN_ID]; + if (info && player_node && player_node->getTarget()) + { + const Being *being = player_node->getTarget(); + if (being) + { + Net::getSpecialHandler()->useBeing(info->level, + info->id, being->getId()); + } + } +} diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 1cb832906..58c4bc42a 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -32,8 +32,9 @@ #include <map> +#define SKILL_MIN_ID 200000 + class Button; -//class Image; class Label; class ScrollArea; class SkillModel; @@ -44,6 +45,7 @@ struct SkillInfo { unsigned short id; std::string name; + std::string shortName; std::string dispName; Image *icon; bool modifiable; @@ -73,10 +75,8 @@ struct SkillInfo void draw(Graphics *graphics, int y, int width); }; - typedef std::vector<SkillInfo*> SkillList; - /** * The skill dialog. * @@ -117,6 +117,8 @@ class SkillDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); + void useItem(int itemId); + private: typedef std::map<int, SkillInfo*> SkillMap; SkillMap mSkills; diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 669d05a66..6438f5deb 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -293,6 +293,8 @@ void ItemContainer::selectNone() outfitWindow->setItemSelected(-1); if (shopWindow) shopWindow->setItemSelected(-1); +// if (skillDialog) +// skillDialog->setItemSelected(-1); } void ItemContainer::setSelectedIndex(int newIndex) diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 130d641fe..1c15ccf2b 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -37,6 +37,7 @@ #include "gui/inventorywindow.h" #include "gui/itempopup.h" #include "gui/palette.h" +#include "gui/skilldialog.h" #include "gui/spellpopup.h" #include "gui/theme.h" #include "gui/viewport.h" @@ -165,7 +166,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) } } } - else if (spellManager) // this is magic shortcut + else if (itemId < SKILL_MIN_ID && spellManager) // this is magic shortcut { TextCommand *spell = spellManager->getSpellByItem(itemId); if (spell) @@ -185,7 +186,15 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) itemY + mBoxHeight / 2, gcn::Graphics::LEFT); } } - + else if (skillDialog) + { + SkillInfo *skill = skillDialog->getSkill(itemId - SKILL_MIN_ID); + if (skill) + { + g->drawText(skill->shortName, itemX + 2, + itemY + mBoxHeight / 2, gcn::Graphics::LEFT); + } + } } if (mItemMoved) @@ -239,12 +248,16 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) itemShortcut[mNumber]->removeItem(index); } } - else if (spellManager) + else if (itemId < SKILL_MIN_ID && spellManager) { TextCommand *spell = spellManager->getSpellByItem(itemId); if (spell) itemShortcut[mNumber]->removeItem(index); } + else + { + itemShortcut[mNumber]->removeItem(index); + } } if (mItemMoved) { @@ -268,8 +281,8 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) { // Stores the selected item if theirs one. if (itemShortcut[mNumber]->isItemSelected() && - (inventoryWindow && (inventoryWindow->isVisible() || - itemShortcut[mNumber]->getSelectedItem() >= SPELL_MIN_ID))) + inventoryWindow && (inventoryWindow->isVisible() || + itemShortcut[mNumber]->getSelectedItem() >= SPELL_MIN_ID)) { itemShortcut[mNumber]->setItem(index); itemShortcut[mNumber]->setItemSelected(-1); @@ -359,7 +372,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) mItemPopup->setVisible(false); } } - else if (spellManager) + else if (itemId < SKILL_MIN_ID && spellManager) { mItemPopup->setVisible(false); TextCommand *spell = spellManager->getSpellByItem(itemId); @@ -373,6 +386,10 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) mSpellPopup->setVisible(false); } } + else if (skillDialog) + { + mItemPopup->setVisible(false); + } } // Hide ItemTooltip diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index fedb92257..9cce55eb7 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -20,13 +20,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "itemshortcut.h" + #include "configuration.h" #include "inventory.h" #include "item.h" -#include "itemshortcut.h" #include "playerinfo.h" #include "spellmanager.h" +#include "gui/skilldialog.h" + #include "net/inventoryhandler.h" #include "net/net.h" @@ -142,10 +145,14 @@ void ItemShortcut::useItem(int index) } } } - else if (spellManager) + else if (itemId < SKILL_MIN_ID && spellManager) { spellManager->useItem(itemId); } + else if (skillDialog) + { + skillDialog->useItem(itemId); + } } } |