[MouseItemWidget] Now handles taking items from read-only inventory if it holds the same item.
This commit is contained in:
parent
3e187fe263
commit
ddcdac14b5
@ -22,7 +22,7 @@ class MouseItemWidget : public ItemWidget {
|
||||
|
||||
void onEvent(const SDL_Event &event);
|
||||
|
||||
void swapItems(ItemWidget &widget);
|
||||
void swapItems(ItemWidget &widget, bool isReadOnly = false);
|
||||
void putItem(ItemWidget &widget);
|
||||
|
||||
const ItemStack &getStack() const { return m_inventory.getStack(0, 0); }
|
||||
|
@ -34,9 +34,8 @@ void InventoryWidget::init(Inventory &inventory) {
|
||||
void InventoryWidget::onEvent(const SDL_Event &event, MouseItemWidget &mouseItemWidget, bool isReadOnly) {
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
|
||||
for (std::size_t i = 0 ; i < m_itemWidgets.size() ; ++i) {
|
||||
if (m_itemWidgets[i].isPointInWidget(event.button.x / 3.0, event.button.y / 3.0)
|
||||
&& (!isReadOnly || mouseItemWidget.getStack().item().id() == 0)) {
|
||||
mouseItemWidget.swapItems(m_itemWidgets.at(i));
|
||||
if (m_itemWidgets[i].isPointInWidget(event.button.x / 3.0, event.button.y / 3.0)) {
|
||||
mouseItemWidget.swapItems(m_itemWidgets.at(i), isReadOnly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,16 +24,22 @@ void MouseItemWidget::onEvent(const SDL_Event &event) {
|
||||
}
|
||||
|
||||
// FIXME
|
||||
void MouseItemWidget::swapItems(ItemWidget &widget) {
|
||||
void MouseItemWidget::swapItems(ItemWidget &widget, bool isReadOnly) {
|
||||
u32 id = widget.stack().item().id();
|
||||
u32 amount = widget.stack().amount();
|
||||
if (stack().item().id() != id) {
|
||||
widget.setStack(stack().item().id(), stack().amount());
|
||||
setStack(id, amount);
|
||||
}
|
||||
else {
|
||||
widget.setStack(widget.stack().item().id(), widget.stack().amount() + stack().amount());
|
||||
setStack(0, 0);
|
||||
if (!isReadOnly || stack().item().id() == 0 || stack().item().id() == id) {
|
||||
if (stack().item().id() != id) {
|
||||
widget.setStack(stack().item().id(), stack().amount());
|
||||
setStack(id, amount);
|
||||
}
|
||||
else if (!isReadOnly) {
|
||||
widget.setStack(widget.stack().item().id(), widget.stack().amount() + stack().amount());
|
||||
setStack(0, 0);
|
||||
}
|
||||
else {
|
||||
setStack(stack().item().id(), stack().amount() + widget.stack().amount());
|
||||
widget.setStack(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user