From f886c62eee04a89c01d30322db1a9eb85f699ac3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 2 Aug 2017 21:32:53 +0300 Subject: Add item shortcuts tab with automatically filled with skills. --- src/game.cpp | 4 +++- src/gui/shortcut/itemshortcut.cpp | 24 +++++++++++++++++++++++- src/gui/shortcut/itemshortcut.h | 9 ++++++++- src/gui/widgets/itemshortcutcontainer.cpp | 2 ++ src/gui/windows/skilldialog.cpp | 29 ++++++++++++++++++++++++++++- 5 files changed, 64 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 54c1581d1..ac6df64c1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -231,11 +231,13 @@ static void createGuiWindows() CREATEWIDGETV(itemShortcutWindow, ShortcutWindow, "ItemShortcut", "items.xml", 83, 460); - for (unsigned f = 0; f < SHORTCUT_TABS; f ++) + for (unsigned f = 0; f < SHORTCUT_TABS - 1; f ++) { itemShortcutWindow->addTab(toString(f + 1), new ItemShortcutContainer(nullptr, f)); } + itemShortcutWindow->addTab("A", + new ItemShortcutContainer(nullptr, SHORTCUT_TABS - 1)); if (config.getBoolValue("showDidYouKnow")) { didYouKnowWindow->setVisible(Visible_true); diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp index 5828ae4e7..d4e96a3e2 100644 --- a/src/gui/shortcut/itemshortcut.cpp +++ b/src/gui/shortcut/itemshortcut.cpp @@ -62,8 +62,10 @@ void ItemShortcut::load() std::string name; std::string color; std::string data; - const Configuration *cfg = &serverConfig; + if (mNumber == SHORTCUT_AUTO_TAB) + return; + const Configuration *cfg = &serverConfig; if (mNumber != 0) { name = std::string("shortcut").append(toString(mNumber)).append("_"); @@ -96,6 +98,8 @@ void ItemShortcut::save() const std::string name; std::string color; std::string data; + if (mNumber == SHORTCUT_AUTO_TAB) + return; if (mNumber != 0) { name = std::string("shortcut").append(toString(mNumber)).append("_"); @@ -131,6 +135,16 @@ void ItemShortcut::save() const } } +void ItemShortcut::clear() +{ + for (size_t i = 0; i < SHORTCUT_ITEMS; i++) + { + mItems[i] = 0; + mItemColors[i] = ItemColor_zero; + mItemData[i].clear(); + } +} + void ItemShortcut::useItem(const int index) const { const Inventory *const inv = PlayerInfo::getInventory(); @@ -232,6 +246,14 @@ void ItemShortcut::setItem(const int index, save(); } +void ItemShortcut::setItemFast(const int index, + const int item, + const ItemColor color) +{ + mItems[index] = item; + mItemColors[index] = color; +} + void ItemShortcut::swap(const int index1, const int index2) { if (index1 < 0 || index2 < 0 diff --git a/src/gui/shortcut/itemshortcut.h b/src/gui/shortcut/itemshortcut.h index c62fe3721..a2107207d 100644 --- a/src/gui/shortcut/itemshortcut.h +++ b/src/gui/shortcut/itemshortcut.h @@ -30,7 +30,8 @@ #include "localconsts.h" const unsigned int SHORTCUT_ITEMS = 20; -const unsigned int SHORTCUT_TABS = 4; +const unsigned int SHORTCUT_TABS = 5; +const unsigned int SHORTCUT_AUTO_TAB = 4; class Item; @@ -103,6 +104,10 @@ class ItemShortcut final const int item, const ItemColor color); + void setItemFast(const int index, + const int item, + const ItemColor color); + /** * Adds an item to the items store specified by the index. * @@ -161,6 +166,8 @@ class ItemShortcut final void swap(const int index1, const int index2); + void clear(); + private: int mItems[SHORTCUT_ITEMS]; /**< The items. */ ItemColor mItemColors[SHORTCUT_ITEMS]; /**< The item colors. */ diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 1f50637e4..915923610 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -360,6 +360,8 @@ void ItemShortcutContainer::safeDraw(Graphics *const graphics) void ItemShortcutContainer::mouseDragged(MouseEvent &event) { + if (mNumber == SHORTCUT_AUTO_TAB) + return; ItemShortcut *const selShortcut = itemShortcut[mNumber]; if (selShortcut == nullptr) return; diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index a0401012d..fdc1b7409 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -241,11 +241,38 @@ void SkillDialog::update() PlayerInfo::getAttribute(Attributes::PLAYER_SKILL_POINTS))); mPointsLabel->adjustSize(); + ItemShortcut *const shortcuts = itemShortcut[SHORTCUT_AUTO_TAB]; + shortcuts->clear(); + size_t idx = 0; + FOR_EACH (SkillMap::const_iterator, it, mSkills) { SkillInfo *const info = (*it).second; - if ((info != nullptr) && info->modifiable == Modifiable_true) + if (info == nullptr) + continue; + if (info->modifiable == Modifiable_true) info->update(); + if (info->visible == Visible_false || + idx >= SHORTCUT_ITEMS) + { + continue; + } + const SkillType::SkillType type = info->type; + if (type == SkillType::Attack || + type == SkillType::Ground || + type == SkillType::Self || + type == SkillType::Support) + { + shortcuts->setItemFast(idx, + info->id + SKILL_MIN_ID, + fromInt(info->customSelectedLevel, ItemColor)); + + shortcuts->setItemData(idx, strprintf("%d %d %d", + CAST_S32(info->customCastType), + info->customOffsetX, + info->customOffsetY)); + idx ++; + } } skillPopup->reset(); -- cgit v1.2.3-60-g2f50