set slot tooltip delay to 0 & refactor

This commit is contained in:
MihailRis 2024-11-24 17:56:14 +03:00
parent e8ee3e04b1
commit 4e25362f9b
2 changed files with 63 additions and 53 deletions

View File

@ -112,7 +112,7 @@ SlotView::SlotView(
layout(std::move(layout))
{
setColor(glm::vec4(0, 0, 0, 0.2f));
setTooltipDelay(0.05f);
setTooltipDelay(0.0f);
}
void SlotView::draw(const DrawContext* pctx, Assets* assets) {
@ -208,11 +208,66 @@ bool SlotView::isHighlighted() const {
return highlighted;
}
void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
if (Events::pressed(keycode::LEFT_SHIFT)) {
if (layout.shareFunc) {
layout.shareFunc(layout.index, stack);
}
if (layout.updateFunc) {
layout.updateFunc(layout.index, stack);
}
return;
}
if (!layout.itemSource && stack.accepts(grabbed)) {
stack.move(grabbed, content->getIndices());
} else {
if (layout.itemSource) {
if (grabbed.isEmpty()) {
grabbed.set(stack);
} else {
grabbed.clear();
}
} else {
std::swap(grabbed, stack);
}
}
}
void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
if (layout.rightClick) {
layout.rightClick(inventoryid, stack);
if (layout.updateFunc) {
layout.updateFunc(layout.index, stack);
}
return;
}
if (layout.itemSource)
return;
if (grabbed.isEmpty()) {
if (!stack.isEmpty()) {
grabbed.set(stack);
int halfremain = stack.getCount() / 2;
grabbed.setCount(stack.getCount() - halfremain);
stack.setCount(halfremain);
}
return;
}
auto& stackDef = content->getIndices()->items.require(stack.getItemId());
if (stack.isEmpty()) {
stack.set(grabbed);
stack.setCount(1);
grabbed.setCount(grabbed.getCount() - 1);
} else if (stack.accepts(grabbed) && stack.getCount() < stackDef.stackSize) {
stack.setCount(stack.getCount() + 1);
grabbed.setCount(grabbed.getCount() - 1);
}
}
void SlotView::clicked(gui::GUI* gui, mousecode button) {
if (bound == nullptr)
return;
auto exchangeSlot = std::dynamic_pointer_cast<SlotView>(gui->get(EXCHANGE_SLOT_NAME));
auto exchangeSlot =
std::dynamic_pointer_cast<SlotView>(gui->get(EXCHANGE_SLOT_NAME));
if (exchangeSlot == nullptr) {
return;
}
@ -220,57 +275,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) {
ItemStack& stack = *bound;
if (button == mousecode::BUTTON_1) {
if (Events::pressed(keycode::LEFT_SHIFT)) {
if (layout.shareFunc) {
layout.shareFunc(layout.index, stack);
}
if (layout.updateFunc) {
layout.updateFunc(layout.index, stack);
}
return;
}
if (!layout.itemSource && stack.accepts(grabbed)) {
stack.move(grabbed, content->getIndices());
} else {
if (layout.itemSource) {
if (grabbed.isEmpty()) {
grabbed.set(stack);
} else {
grabbed.clear();
}
} else {
std::swap(grabbed, stack);
}
}
performLeftClick(stack, grabbed);
} else if (button == mousecode::BUTTON_2) {
if (layout.rightClick) {
layout.rightClick(inventoryid, stack);
if (layout.updateFunc) {
layout.updateFunc(layout.index, stack);
}
return;
}
if (layout.itemSource)
return;
if (grabbed.isEmpty()) {
if (!stack.isEmpty()) {
grabbed.set(stack);
int halfremain = stack.getCount() / 2;
grabbed.setCount(stack.getCount() - halfremain);
stack.setCount(halfremain);
}
} else {
auto& stackDef =
content->getIndices()->items.require(stack.getItemId());
if (stack.isEmpty()) {
stack.set(grabbed);
stack.setCount(1);
grabbed.setCount(grabbed.getCount() - 1);
} else if (stack.accepts(grabbed) && stack.getCount() < stackDef.stackSize) {
stack.setCount(stack.getCount() + 1);
grabbed.setCount(grabbed.getCount() - 1);
}
}
performRightClick(stack, grabbed);
}
if (layout.updateFunc) {
layout.updateFunc(layout.index, stack);

View File

@ -55,6 +55,9 @@ namespace gui {
std::wstring tooltip;
itemid_t prevItem = 0;
void performLeftClick(ItemStack& stack, ItemStack& grabbed);
void performRightClick(ItemStack& stack, ItemStack& grabbed);
public:
SlotView(SlotLayout layout);