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

summaryrefslogtreecommitdiff
path: root/source/windowing/StarItemSlotWidget.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/StarItemSlotWidget.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/StarItemSlotWidget.cpp')
-rw-r--r--source/windowing/StarItemSlotWidget.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/source/windowing/StarItemSlotWidget.cpp b/source/windowing/StarItemSlotWidget.cpp
index 2958957..93d95d3 100644
--- a/source/windowing/StarItemSlotWidget.cpp
+++ b/source/windowing/StarItemSlotWidget.cpp
@@ -67,12 +67,16 @@ void ItemSlotWidget::update(float dt) {
bool ItemSlotWidget::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);
RectI itemArea = m_itemDraggableArea.translated(screenPosition());
if (itemArea.contains(mousePos)) {
if (mouseButton->mouseButton == MouseButton::Right)
m_rightClickCallback(this);
+ else if (mouseButton->mouseButton == MouseButton::Middle)
+ m_middleClickCallback(this);
else
m_callback(this);
return true;
@@ -92,6 +96,10 @@ void ItemSlotWidget::setRightClickCallback(WidgetCallbackFunc callback) {
m_rightClickCallback = callback;
}
+void ItemSlotWidget::setMiddleClickCallback(WidgetCallbackFunc callback) {
+ m_middleClickCallback = callback;
+}
+
void ItemSlotWidget::setItem(ItemPtr const& item) {
m_item = item;
}