diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-03-10 03:06:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-03-10 03:08:05 +0300 |
commit | 46cc993b30fe9a4da9175beb2795de91162c39fa (patch) | |
tree | bb50f135d38cda0188fb27648ec622fd4f157de6 /src | |
parent | 9b80af87b10412a9732001979b76575b49ad4552 (diff) | |
download | mv-46cc993b30fe9a4da9175beb2795de91162c39fa.tar.gz mv-46cc993b30fe9a4da9175beb2795de91162c39fa.tar.bz2 mv-46cc993b30fe9a4da9175beb2795de91162c39fa.tar.xz mv-46cc993b30fe9a4da9175beb2795de91162c39fa.zip |
Add basic skill action use on target.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/skilldialog.cpp | 44 | ||||
-rw-r--r-- | src/gui/skilldialog.h | 1 | ||||
-rw-r--r-- | src/net/tmwa/specialhandler.cpp | 4 |
3 files changed, 45 insertions, 4 deletions
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 3cd3c7a16..d5af42aae 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -22,6 +22,7 @@ #include "gui/skilldialog.h" +#include "localplayer.h" #include "logger.h" #include "playerinfo.h" #include "configuration.h" @@ -44,6 +45,7 @@ #include "net/net.h" #include "net/playerhandler.h" +#include "net/specialhandler.h" #include "resources/image.h" #include "resources/resourcemanager.h" @@ -73,6 +75,7 @@ struct SkillInfo bool visible; SkillModel *model; + int level; std::string skillLevel; int skillLevelWidth; @@ -83,8 +86,8 @@ struct SkillInfo SkillInfo() : id(0), name(""), dispName(""), icon(nullptr), modifiable(false), - visible(false), model(nullptr), skillLevel(""), skillLevelWidth(0), - skillExp(""), progress(0.0f), range(0) + visible(false), model(nullptr), level(0), skillLevel(""), + skillLevelWidth(0), skillExp(""), progress(0.0f), range(0) { } @@ -286,11 +289,14 @@ SkillDialog::SkillDialog(): mTabs = new TabbedArea(); mPointsLabel = new Label("0"); + mUseButton = new Button(_("Use"), "use", this); + mUseButton->setEnabled(false); mIncreaseButton = new Button(_("Up"), "inc", this); mDefaultModel = nullptr; place(0, 0, mTabs, 5, 5); place(0, 5, mPointsLabel, 4); + place(3, 5, mUseButton); place(4, 5, mIncreaseButton); setLocationRelativeTo(getParent()); @@ -314,6 +320,34 @@ void SkillDialog::action(const gcn::ActionEvent &event) Net::getPlayerHandler()->increaseSkill(info->id); } } + else if (event.getId() == "sel") + { + SkillTab *tab = static_cast<SkillTab*>(mTabs->getSelectedTab()); + if (tab) + { + if (SkillInfo *info = tab->getSelectedInfo()) + mUseButton->setEnabled(info->range > 0); + else + mUseButton->setEnabled(false); + } + } + else if (event.getId() == "use") + { + SkillTab *tab = static_cast<SkillTab*>(mTabs->getSelectedTab()); + if (tab) + { + const SkillInfo *info = tab->getSelectedInfo(); + if (info && player_node && player_node->getTarget()) + { + const Being *being = player_node->getTarget(); + if (being) + { + Net::getSpecialHandler()->useBeing(info->level, + info->id, being->getId()); + } + } + } + } else if (event.getId() == "close") { setVisible(false); @@ -397,6 +431,8 @@ void SkillDialog::loadSkills(const std::string &file) model->updateVisibilities(); listbox = new SkillListBox(model); + listbox->setActionEventId("sel"); + listbox->addActionListener(this); scroll = new ScrollArea(listbox); scroll->setOpaque(false); scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); @@ -454,6 +490,8 @@ void SkillDialog::loadSkills(const std::string &file) // possible leak listbox, scroll listbox = new SkillListBox(model); + listbox->setActionEventId("sel"); + listbox->addActionListener(this); scroll = new ScrollArea(listbox); scroll->setOpaque(false); scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); @@ -498,6 +536,7 @@ void SkillDialog::addSkill(int id, int level, int range, bool modifiable) skill->modifiable = modifiable; skill->visible = false; skill->model = mDefaultModel; + skill->level = level; skill->skillLevel = strprintf(_("Lvl: %d"), level); skill->range = range; skill->update(); @@ -556,6 +595,7 @@ void SkillInfo::update() else skillLevel = strprintf(_("Lvl: %d"), baseLevel); } + level = baseLevel; skillLevelWidth = -1; if (exp.second) diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 1ef609f88..56858ef5e 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -88,6 +88,7 @@ class SkillDialog : public Window, public gcn::ActionListener TabbedArea *mTabs; std::list<Tab*> mDeleteTabs; Label *mPointsLabel; + Button *mUseButton; Button *mIncreaseButton; SkillModel *mDefaultModel; }; diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp index 129f0b47e..2941422d0 100644 --- a/src/net/tmwa/specialhandler.cpp +++ b/src/net/tmwa/specialhandler.cpp @@ -72,9 +72,9 @@ void SpecialHandler::handleMessage(Net::MessageIn &msg) void SpecialHandler::useBeing(int id, int level, int beingId) { MessageOut outMsg(CMSG_SKILL_USE_BEING); - outMsg.writeInt16(static_cast<Sint16>(level)); outMsg.writeInt16(static_cast<Sint16>(id)); - outMsg.writeInt16(static_cast<Sint16>(beingId)); + outMsg.writeInt16(static_cast<Sint16>(level)); + outMsg.writeInt32(beingId); } void SpecialHandler::usePos(int id, int level, int x, int y) |