Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/windowing/StarItemGridWidget.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-03-27 16:00:13 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-03-27 16:00:13 +1100
commit888cde79ef8f6d1b008e86207b41e1fd686c7636 (patch)
tree576e23c94d227f76bec06cd0357809c703dc4c53 /source/windowing/StarItemGridWidget.cpp
parentc484fab32dcac655164f082805d1d55d1d058f2f (diff)
feat: middle click objects in the inventory to open their interface
makes carrying around shop objects easier might need to restrict the allowed interaction types more, as some may break due to the source entity being the player
Diffstat (limited to 'source/windowing/StarItemGridWidget.cpp')
-rw-r--r--source/windowing/StarItemGridWidget.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/source/windowing/StarItemGridWidget.cpp b/source/windowing/StarItemGridWidget.cpp
index 3302ca6..be1cc42 100644
--- a/source/windowing/StarItemGridWidget.cpp
+++ b/source/windowing/StarItemGridWidget.cpp
@@ -106,7 +106,9 @@ Vec2I ItemGridWidget::positionOfSlot(size_t slotNumber) {
bool ItemGridWidget::sendEvent(InputEvent const& event) {
if (m_visible) {
if (auto mouseButton = event.ptr<MouseButtonDownEvent>()) {
- if (mouseButton->mouseButton == MouseButton::Left || (m_rightClickCallback && mouseButton->mouseButton == MouseButton::Right)) {
+ if (mouseButton->mouseButton == MouseButton::Left
+ || (m_rightClickCallback && mouseButton->mouseButton == MouseButton::Right)
+ || (m_middleClickCallback && mouseButton->mouseButton == MouseButton::Middle)) {
Vec2I mousePos = *context()->mousePosition(event);
for (size_t i = 0; i < (m_bag->size() - m_bagOffset) && i < unsigned(m_dimensions[0] * m_dimensions[1]); ++i) {
Vec2I loc = locOfItemSlot(i);
@@ -116,6 +118,8 @@ bool ItemGridWidget::sendEvent(InputEvent const& event) {
m_selectedIndex = i;
if (mouseButton->mouseButton == MouseButton::Right)
m_rightClickCallback(this);
+ else if (mouseButton->mouseButton == MouseButton::Middle)
+ m_middleClickCallback(this);
else
m_callback(this);
return true;
@@ -145,6 +149,10 @@ void ItemGridWidget::setRightClickCallback(WidgetCallbackFunc callback) {
m_rightClickCallback = callback;
}
+void ItemGridWidget::setMiddleClickCallback(WidgetCallbackFunc callback) {
+ m_middleClickCallback = callback;
+}
+
void ItemGridWidget::setItemBag(ItemBagConstPtr bag) {
m_bag = bag;