summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-01 23:59:31 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-02 01:42:48 +0300
commit8aa68056aec80c775a3ddb152bea8a90a7097199 (patch)
tree2a131c77e27ea4d5a7a3e3d5102f0bbc12957569
parent96805601e06e6ed6f7b5aaffc3bbb22dd9e8d58a (diff)
downloadmanaplus-8aa68056aec80c775a3ddb152bea8a90a7097199.tar.gz
manaplus-8aa68056aec80c775a3ddb152bea8a90a7097199.tar.bz2
manaplus-8aa68056aec80c775a3ddb152bea8a90a7097199.tar.xz
manaplus-8aa68056aec80c775a3ddb152bea8a90a7097199.zip
Add actions for switch to next/prev tab in inventory.
Keys not assigned.
-rw-r--r--src/actions/tabs.cpp13
-rw-r--r--src/actions/tabs.h2
-rw-r--r--src/gui/widgets/basiccontainer.cpp10
-rw-r--r--src/gui/widgets/basiccontainer.h3
-rw-r--r--src/gui/widgets/tabstrip.cpp38
-rw-r--r--src/gui/widgets/tabstrip.h4
-rw-r--r--src/gui/windows/inventorywindow.cpp28
-rw-r--r--src/gui/windows/inventorywindow.h6
-rw-r--r--src/input/inputaction.h2
-rw-r--r--src/input/inputactionmap.h18
-rw-r--r--src/input/pages/windows.cpp12
-rw-r--r--src/localconsts.h3
12 files changed, 139 insertions, 0 deletions
diff --git a/src/actions/tabs.cpp b/src/actions/tabs.cpp
index 7ede6e428..eabbd4126 100644
--- a/src/actions/tabs.cpp
+++ b/src/actions/tabs.cpp
@@ -22,6 +22,7 @@
#include "actions/actiondef.h"
+#include "gui/windows/inventorywindow.h"
#include "gui/windows/socialwindow.h"
#include "gui/windows/shortcutwindow.h"
@@ -92,4 +93,16 @@ impHandler0(prevCommandsTab)
return false;
}
+impHandler0(nextInvTab)
+{
+ InventoryWindow::nextTab();
+ return true;
+}
+
+impHandler0(prevInvTab)
+{
+ InventoryWindow::prevTab();
+ return true;
+}
+
} // namespace Actions
diff --git a/src/actions/tabs.h b/src/actions/tabs.h
index 89468d67f..74b45cf71 100644
--- a/src/actions/tabs.h
+++ b/src/actions/tabs.h
@@ -33,6 +33,8 @@ namespace Actions
decHandler(prevShortcutsTab);
decHandler(nextCommandsTab);
decHandler(prevCommandsTab);
+ decHandler(nextInvTab);
+ decHandler(prevInvTab);
} // namespace Actions
#undef decHandler
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp
index 4803373f2..a66a244a0 100644
--- a/src/gui/widgets/basiccontainer.cpp
+++ b/src/gui/widgets/basiccontainer.cpp
@@ -372,3 +372,13 @@ void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler)
(*iter)->setFocusHandler(mInternalFocusHandler);
}
}
+
+Widget *BasicContainer::findFirstWidget(const std::set<Widget*> &list)
+{
+ FOR_EACHR (WidgetListReverseIterator, iter, mWidgets)
+ {
+ if (list.find(*iter) != list.end())
+ return *iter;
+ }
+ return nullptr;
+}
diff --git a/src/gui/widgets/basiccontainer.h b/src/gui/widgets/basiccontainer.h
index 85067daff..47fa2abc1 100644
--- a/src/gui/widgets/basiccontainer.h
+++ b/src/gui/widgets/basiccontainer.h
@@ -64,6 +64,7 @@
#ifndef GUI_WIDGETS_BASICCONTAINER_H
#define GUI_WIDGETS_BASICCONTAINER_H
+#include <set>
#include <vector>
#include "gui/widgets/widget.h"
@@ -134,6 +135,8 @@ class BasicContainer notfinal : public Widget,
virtual void death(const Event& event) override;
+ Widget *findFirstWidget(const std::set<Widget*> &list);
+
protected:
/**
* Adds a widget to the basic container.
diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp
index 7c6627fbf..644fa3d48 100644
--- a/src/gui/widgets/tabstrip.cpp
+++ b/src/gui/widgets/tabstrip.cpp
@@ -77,3 +77,41 @@ void TabStrip::action(const ActionEvent &event)
}
}
}
+
+void TabStrip::nextTab()
+{
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
+ {
+ Button *button = static_cast<Button*>(*iter);
+ if (button->isPressed2())
+ {
+ button->setPressed(false);
+ ++iter;
+ if (iter == mWidgets.end())
+ iter = mWidgets.begin();
+ button = static_cast<Button*>(*iter);
+ action(ActionEvent(button, button->getActionEventId()));
+ return;
+ }
+ }
+}
+
+void TabStrip::prevTab()
+{
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
+ {
+ Button *button = static_cast<Button*>(*iter);
+ if (button->isPressed2())
+ {
+ button->setPressed(false);
+ if (iter == mWidgets.begin())
+ iter = mWidgets.end();
+ if (iter == mWidgets.begin())
+ return;
+ --iter;
+ button = static_cast<Button*>(*iter);
+ action(ActionEvent(button, button->getActionEventId()));
+ return;
+ }
+ }
+}
diff --git a/src/gui/widgets/tabstrip.h b/src/gui/widgets/tabstrip.h
index a89dd5144..daadad35c 100644
--- a/src/gui/widgets/tabstrip.h
+++ b/src/gui/widgets/tabstrip.h
@@ -41,6 +41,10 @@ class TabStrip final : public WidgetGroup
const override final A_WARN_UNUSED;
void action(const ActionEvent &event) override final;
+
+ void nextTab();
+
+ void prevTab();
};
#endif // GUI_WIDGETS_TABSTRIP_H
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index c1fea4158..ea3cc5ad3 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -54,6 +54,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabstrip.h"
#include "gui/widgets/textfield.h"
+#include "gui/widgets/windowcontainer.h"
#include "net/inventoryhandler.h"
@@ -746,6 +747,33 @@ bool InventoryWindow::isAnyInputFocused()
return false;
}
+InventoryWindow *InventoryWindow::getFirstVisible()
+{
+ std::set<Widget*> list;
+ FOR_EACH (WindowList::const_iterator, it, invInstances)
+ {
+ if ((*it) && (*it)->isWindowVisible())
+ list.insert(*it);
+ }
+ InventoryWindow *const window = dynamic_cast<InventoryWindow*>(
+ windowContainer->findFirstWidget(list));
+ return window;
+}
+
+void InventoryWindow::nextTab()
+{
+ InventoryWindow *const window = getFirstVisible();
+ if (window)
+ window->mFilter->nextTab();
+}
+
+void InventoryWindow::prevTab()
+{
+ InventoryWindow *const window = getFirstVisible();
+ if (window)
+ window->mFilter->prevTab();
+}
+
void InventoryWindow::widgetResized(const Event &event)
{
Window::widgetResized(event);
diff --git a/src/gui/windows/inventorywindow.h b/src/gui/windows/inventorywindow.h
index 98cac78a6..f2952c2f5 100644
--- a/src/gui/windows/inventorywindow.h
+++ b/src/gui/windows/inventorywindow.h
@@ -156,6 +156,12 @@ class InventoryWindow final : public Window,
static bool isAnyInputFocused();
+ static InventoryWindow *getFirstVisible();
+
+ static void nextTab();
+
+ static void prevTab();
+
private:
/**
* Updates the weight bar.
diff --git a/src/input/inputaction.h b/src/input/inputaction.h
index f049d209f..7ab68911c 100644
--- a/src/input/inputaction.h
+++ b/src/input/inputaction.h
@@ -487,6 +487,8 @@ namespace InputAction
HOMUNCULUS_SET_NAME,
HOMUNCULUS_FIRE,
WINDOW_BANK,
+ PREV_INV_TAB,
+ NEXT_INV_TAB,
TOTAL
};
} // namespace InputAction
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index 460f11048..cb9805d3a 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -4125,6 +4125,24 @@ static const InputActionData inputActionData[InputAction::TOTAL] = {
InputCondition::SHORTCUT0,
"bank|openbank",
false},
+ {"keyInventoryPrevTab",
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ Input::GRP_DEFAULT | Input::GRP_GUI,
+ &Actions::prevInvTab,
+ InputAction::NO_VALUE, 50,
+ InputCondition::NOINPUT | InputCondition::INGAME,
+ "previnvtab",
+ false},
+ {"keyInventoryNextTab",
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ Input::GRP_DEFAULT | Input::GRP_GUI,
+ &Actions::nextInvTab,
+ InputAction::NO_VALUE, 50,
+ InputCondition::NOINPUT | InputCondition::INGAME,
+ "nextinvtab",
+ false},
};
#endif // INPUT_INPUTACTIONMAP_H
diff --git a/src/input/pages/windows.cpp b/src/input/pages/windows.cpp
index 32fc18c49..0bde9cb9e 100644
--- a/src/input/pages/windows.cpp
+++ b/src/input/pages/windows.cpp
@@ -224,6 +224,18 @@ SetupActionData setupActionDataWindows[] =
"",
},
{
+ // TRANSLATORS: input action name
+ N_("Previous inventory tab"),
+ InputAction::PREV_INV_TAB,
+ "",
+ },
+ {
+ // TRANSLATORS: input action name
+ N_("Next inventory tab"),
+ InputAction::NEXT_INV_TAB,
+ "",
+ },
+ {
"",
InputAction::NO_VALUE,
""
diff --git a/src/localconsts.h b/src/localconsts.h
index 549838619..777d0f540 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -85,6 +85,9 @@
#define FOR_EACH(type, iter, array) for (type iter = array.begin(), \
iter##_end = array.end(); iter != iter##_end; ++ iter)
+#define FOR_EACHR(type, iter, array) for (type iter = array.rbegin(), \
+ iter##_end = array.rend(); iter != iter##_end; ++ iter)
+
#define FOR_EACHP(type, iter, array) for (type iter = array->begin(), \
iter##_end = array->end(); iter != iter##_end; ++ iter)