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
+24 -17
View File
@@ -112,7 +112,7 @@ SlotView::SlotView(
layout(std::move(layout)) layout(std::move(layout))
{ {
setColor(glm::vec4(0, 0, 0, 0.2f)); setColor(glm::vec4(0, 0, 0, 0.2f));
setTooltipDelay(0.05f); setTooltipDelay(0.0f);
} }
void SlotView::draw(const DrawContext* pctx, Assets* assets) { void SlotView::draw(const DrawContext* pctx, Assets* assets) {
@@ -208,18 +208,7 @@ bool SlotView::isHighlighted() const {
return highlighted; return highlighted;
} }
void SlotView::clicked(gui::GUI* gui, mousecode button) { void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
if (bound == nullptr)
return;
auto exchangeSlot = std::dynamic_pointer_cast<SlotView>(gui->get(EXCHANGE_SLOT_NAME));
if (exchangeSlot == nullptr) {
return;
}
ItemStack& grabbed = exchangeSlot->getStack();
ItemStack& stack = *bound;
if (button == mousecode::BUTTON_1) {
if (Events::pressed(keycode::LEFT_SHIFT)) { if (Events::pressed(keycode::LEFT_SHIFT)) {
if (layout.shareFunc) { if (layout.shareFunc) {
layout.shareFunc(layout.index, stack); layout.shareFunc(layout.index, stack);
@@ -242,7 +231,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) {
std::swap(grabbed, stack); std::swap(grabbed, stack);
} }
} }
} else if (button == mousecode::BUTTON_2) { }
void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
if (layout.rightClick) { if (layout.rightClick) {
layout.rightClick(inventoryid, stack); layout.rightClick(inventoryid, stack);
if (layout.updateFunc) { if (layout.updateFunc) {
@@ -259,9 +250,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) {
grabbed.setCount(stack.getCount() - halfremain); grabbed.setCount(stack.getCount() - halfremain);
stack.setCount(halfremain); stack.setCount(halfremain);
} }
} else { return;
auto& stackDef = }
content->getIndices()->items.require(stack.getItemId()); auto& stackDef = content->getIndices()->items.require(stack.getItemId());
if (stack.isEmpty()) { if (stack.isEmpty()) {
stack.set(grabbed); stack.set(grabbed);
stack.setCount(1); stack.setCount(1);
@@ -271,6 +262,22 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) {
grabbed.setCount(grabbed.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));
if (exchangeSlot == nullptr) {
return;
}
ItemStack& grabbed = exchangeSlot->getStack();
ItemStack& stack = *bound;
if (button == mousecode::BUTTON_1) {
performLeftClick(stack, grabbed);
} else if (button == mousecode::BUTTON_2) {
performRightClick(stack, grabbed);
} }
if (layout.updateFunc) { if (layout.updateFunc) {
layout.updateFunc(layout.index, stack); layout.updateFunc(layout.index, stack);
@@ -55,6 +55,9 @@ namespace gui {
std::wstring tooltip; std::wstring tooltip;
itemid_t prevItem = 0; itemid_t prevItem = 0;
void performLeftClick(ItemStack& stack, ItemStack& grabbed);
void performRightClick(ItemStack& stack, ItemStack& grabbed);
public: public:
SlotView(SlotLayout layout); SlotView(SlotLayout layout);