diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-08-08 00:38:31 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-08-08 00:38:31 +0300 |
commit | 344efb2009b8c6d329a6d19dd45ed49076252710 (patch) | |
tree | 2e5c1a7d9484e1cc3bfedac7b03c7146be442896 | |
parent | fa4c5d79b04a319550996c48448cd799fe7fde56 (diff) | |
download | mv-344efb2009b8c6d329a6d19dd45ed49076252710.tar.gz mv-344efb2009b8c6d329a6d19dd45ed49076252710.tar.bz2 mv-344efb2009b8c6d329a6d19dd45ed49076252710.tar.xz mv-344efb2009b8c6d329a6d19dd45ed49076252710.zip |
Add into skill context menu for add shortcut.
Also add chat command for add skill shortcut by skill id into free slot.
-rw-r--r-- | src/actions/commands.cpp | 42 | ||||
-rw-r--r-- | src/actions/commands.h | 1 | ||||
-rw-r--r-- | src/dyetool/actions/commands.cpp | 1 | ||||
-rw-r--r-- | src/enums/input/inputaction.h | 1 | ||||
-rw-r--r-- | src/gui/popups/popupmenu.cpp | 5 | ||||
-rw-r--r-- | src/gui/shortcut/itemshortcut.cpp | 10 | ||||
-rw-r--r-- | src/gui/shortcut/itemshortcut.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/skilllistbox.h | 5 | ||||
-rw-r--r-- | src/gui/widgets/skillrectanglelistbox.h | 5 | ||||
-rw-r--r-- | src/gui/windows/skilldialog.cpp | 6 | ||||
-rw-r--r-- | src/input/inputactionmap.h | 6 | ||||
-rw-r--r-- | src/resources/skill/skillinfo.cpp | 8 | ||||
-rw-r--r-- | src/resources/skill/skillinfo.h | 2 |
13 files changed, 82 insertions, 12 deletions
diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 6b51d2270..235afecb5 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -33,11 +33,14 @@ #include "being/homunculusinfo.h" #include "being/playerinfo.h" +#include "const/resources/skill.h" + #include "gui/viewport.h" #include "gui/popups/popupmenu.h" #include "gui/shortcut/emoteshortcut.h" +#include "gui/shortcut/itemshortcut.h" #include "gui/windows/mailwindow.h" @@ -45,6 +48,7 @@ #include "gui/windows/inventorywindow.h" #include "gui/windows/npcdialog.h" #include "gui/windows/outfitwindow.h" +#include "gui/windows/shortcutwindow.h" #include "gui/windows/skilldialog.h" #include "gui/windows/socialwindow.h" @@ -71,6 +75,8 @@ #include "resources/map/map.h" +#include "resources/skill/skillinfo.h" + #include "utils/booleanoptions.h" #include "utils/chatutils.h" #include "utils/copynpaste.h" @@ -2091,4 +2097,40 @@ impHandler(movePriorityAttackDown) return false; } +impHandler(addSkillShortcut) +{ + const std::string args = event.args; + if (args.empty() || + itemShortcutWindow == nullptr) + { + return false; + } + const SkillInfo *restrict const skill = skillDialog->getSkill( + atoi(args.c_str())); + if (skill == nullptr) + return false; + + const int num = itemShortcutWindow->getTabIndex(); + if (num < 0 || + num >= CAST_S32(SHORTCUT_TABS) || + num == SHORTCUT_AUTO_TAB) + { + return false; + } + + ItemShortcut *const selShortcut = itemShortcut[num]; + const int index = selShortcut->getFreeIndex(); + if (index < 0) + return true; + + selShortcut->setItem(index, + skill->id + SKILL_MIN_ID, + fromInt(skill->customSelectedLevel, ItemColor)); + selShortcut->setItemData(index, + skill->toDataStr()); + +// popupMenu->showSkillLevelPopup(skill); + return true; +} + } // namespace Actions diff --git a/src/actions/commands.h b/src/actions/commands.h index 5d6e7ce58..414e20658 100644 --- a/src/actions/commands.h +++ b/src/actions/commands.h @@ -162,6 +162,7 @@ namespace Actions decHandler(moveAttackDown); decHandler(movePriorityAttackUp); decHandler(movePriorityAttackDown); + decHandler(addSkillShortcut); } // namespace Actions #undef decHandler diff --git a/src/dyetool/actions/commands.cpp b/src/dyetool/actions/commands.cpp index 9c998f23a..7f50ab20c 100644 --- a/src/dyetool/actions/commands.cpp +++ b/src/dyetool/actions/commands.cpp @@ -162,5 +162,6 @@ impHandlerVoid(moveAttackUp) impHandlerVoid(moveAttackDown) impHandlerVoid(movePriorityAttackUp) impHandlerVoid(movePriorityAttackDown) +impHandlerVoid(addSkillShortcut) } // namespace Actions diff --git a/src/enums/input/inputaction.h b/src/enums/input/inputaction.h index f3259b823..dc09b8f3a 100644 --- a/src/enums/input/inputaction.h +++ b/src/enums/input/inputaction.h @@ -708,6 +708,7 @@ enumStart(InputAction) PET_DROP_LOOT, PET_RETURN_TO_EGG, PET_UNEQUIP, + ADD_SKILL_SHORTCUT, TOTAL } enumEnd(InputAction); diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index 27ef1887c..ba71e8d04 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -2249,6 +2249,11 @@ void PopupMenu::showSkillPopup(const SkillInfo *const info) // TRANSLATORS: popup menu header mBrowserBox->addRow(_("Skill")); + mBrowserBox->addRow("/addskillshortcut 'ITEMID'", + // TRANSLATORS: popup menu item + // TRANSLATORS: add skill to shortcurs tab + _("Add skill shortcut")); + mBrowserBox->addSeparator("##3---"); mBrowserBox->addRow("/showskilllevels 'ITEMID'", // TRANSLATORS: popup menu item // TRANSLATORS: set skill level diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp index 7b9bab6e6..2f80f6759 100644 --- a/src/gui/shortcut/itemshortcut.cpp +++ b/src/gui/shortcut/itemshortcut.cpp @@ -277,3 +277,13 @@ void ItemShortcut::swap(const int index1, const int index2) mItemData[index2] = tmpData; save(); } + +size_t ItemShortcut::getFreeIndex() const +{ + for (size_t i = 0; i < SHORTCUT_ITEMS; i++) + { + if (mItems[i] < 0) + return i; + } + return -1; +} diff --git a/src/gui/shortcut/itemshortcut.h b/src/gui/shortcut/itemshortcut.h index b7ea160a7..15324d30c 100644 --- a/src/gui/shortcut/itemshortcut.h +++ b/src/gui/shortcut/itemshortcut.h @@ -168,6 +168,8 @@ class ItemShortcut final void clear(); + size_t getFreeIndex() const A_WARN_UNUSED; + private: int mItems[SHORTCUT_ITEMS]; /**< The items. */ ItemColor mItemColors[SHORTCUT_ITEMS]; /**< The item colors. */ diff --git a/src/gui/widgets/skilllistbox.h b/src/gui/widgets/skilllistbox.h index 93c702381..46f116d4c 100644 --- a/src/gui/widgets/skilllistbox.h +++ b/src/gui/widgets/skilllistbox.h @@ -224,10 +224,7 @@ class SkillListBox final : public ListBox return; dragDrop.dragSkill(skill, DragDropSource::Skills); dragDrop.setItem(skill->id + SKILL_MIN_ID); - dragDrop.setItemData(strprintf("%d %d %d", - CAST_S32(skill->customCastType), - skill->customOffsetX, - skill->customOffsetY)); + dragDrop.setItemData(skill->toDataStr()); } ListBox::mouseDragged(event); } diff --git a/src/gui/widgets/skillrectanglelistbox.h b/src/gui/widgets/skillrectanglelistbox.h index 88698de1c..a0775db3c 100644 --- a/src/gui/widgets/skillrectanglelistbox.h +++ b/src/gui/widgets/skillrectanglelistbox.h @@ -306,10 +306,7 @@ class SkillRectangleListBox final : public Widget, return; dragDrop.dragSkill(skill, DragDropSource::Skills); dragDrop.setItem(skill->id + SKILL_MIN_ID); - dragDrop.setItemData(strprintf("%d %d %d", - CAST_S32(skill->customCastType), - skill->customOffsetX, - skill->customOffsetY)); + dragDrop.setItemData(skill->toDataStr()); } } } diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index f48baaf83..b4e277b98 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -268,10 +268,8 @@ void SkillDialog::update() info->id + SKILL_MIN_ID, fromInt(info->customSelectedLevel, ItemColor)); - shortcuts->setItemData(idx, strprintf("%d %d %d", - CAST_S32(info->customCastType), - info->customOffsetX, - info->customOffsetY)); + shortcuts->setItemData(idx, + info->toDataStr()); idx ++; } } diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index 9f4f3f63e..6017d95dc 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -5738,6 +5738,12 @@ static const InputActionData inputActionData "petunequip|unequippet", UseArgs_false, Protected_false}, + {"keyAddSkillShortcut", + defaultAction(&Actions::addSkillShortcut), + InputCondition::INGAME, + "addskillshortcut|skillshortcut", + UseArgs_true, + Protected_false}, }; #undef defaultAction diff --git a/src/resources/skill/skillinfo.cpp b/src/resources/skill/skillinfo.cpp index 3c74fcaa9..3f6a50eb6 100644 --- a/src/resources/skill/skillinfo.cpp +++ b/src/resources/skill/skillinfo.cpp @@ -194,3 +194,11 @@ SkillData *SkillInfo::getData1(const int lev) const return (*dataMap.begin()).second; return (*it).second; } + +std::string SkillInfo::toDataStr() const +{ + return strprintf("%d %d %d", + CAST_S32(customCastType), + customOffsetX, + customOffsetY); +} diff --git a/src/resources/skill/skillinfo.h b/src/resources/skill/skillinfo.h index 391a19912..c07b3209f 100644 --- a/src/resources/skill/skillinfo.h +++ b/src/resources/skill/skillinfo.h @@ -98,6 +98,8 @@ struct SkillInfo final || type == SkillType::Self || type == SkillType::Support; } + + std::string toDataStr() const A_WARN_UNUSED; }; typedef STD_VECTOR<SkillInfo*> SkillList; |