mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
revert creation of clickOutside
This commit is contained in:
parent
7c97966377
commit
c2f7f33bbf
6 changed files with 6 additions and 74 deletions
|
|
@ -1,5 +1,3 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "hud.hpp"
|
||||
|
||||
#include "ContentGfxCache.hpp"
|
||||
|
|
@ -180,8 +178,8 @@ Hud::Hud(Engine& engine, LevelFrontend& frontend, Player& player)
|
|||
inventoryDropArea = guiutil::create(
|
||||
gui,
|
||||
R"(<container size='4000' color='#00000000' z-index='-1' visible='false'
|
||||
onclick='events.emit(\"core:drop_outside_inventory\", 0)'
|
||||
onrightclick='events.emit(\"core:drop_outside_inventory\", 1)'
|
||||
onclick='events.emit(\"core:drop_outside_inventory\", 0)'
|
||||
onrightclick='events.emit(\"core:drop_outside_inventory\", 1)'
|
||||
/>)"
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -178,8 +178,6 @@ void GUI::actMouse(Frame& frame, float delta, const CursorState& cursor) {
|
|||
}
|
||||
it = mouseOver.erase(it);
|
||||
}
|
||||
|
||||
bool focusHappened = false;
|
||||
|
||||
if (input.jclicked(Mousecode::BUTTON_1)) {
|
||||
if (pressed == nullptr && this->hover) {
|
||||
|
|
@ -197,10 +195,10 @@ void GUI::actMouse(Frame& frame, float delta, const CursorState& cursor) {
|
|||
if (focus != pressed) {
|
||||
focus = pressed;
|
||||
focus->onFocus();
|
||||
focusHappened = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this->hover == nullptr && focus && !focusHappened) {
|
||||
if (this->hover == nullptr && focus) {
|
||||
focus->defocus();
|
||||
focus = nullptr;
|
||||
}
|
||||
|
|
@ -209,44 +207,13 @@ void GUI::actMouse(Frame& frame, float delta, const CursorState& cursor) {
|
|||
pressed = nullptr;
|
||||
}
|
||||
|
||||
if (hover && !focusHappened) {
|
||||
if (hover) {
|
||||
for (Mousecode code : MOUSECODES_ALL) {
|
||||
if (input.jclicked(code)) {
|
||||
hover->clicked(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
performClickOutside(frame, delta, cursorPos);
|
||||
}
|
||||
|
||||
void GUI::performClickOutside(Frame& frame, float delta, glm::vec2 cursorPos) {
|
||||
auto nodes = frame.getNodes();
|
||||
std::vector<std::shared_ptr<UINode>> activeNodes;
|
||||
|
||||
for (const auto& node : nodes) {
|
||||
if (node && node->isVisible() && node->isInteractive()) {
|
||||
activeNodes.push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
for (Mousecode code : {Mousecode::BUTTON_1, Mousecode::BUTTON_2, Mousecode::BUTTON_3}) {
|
||||
if (input.jclicked(code)) {
|
||||
bool isOverAnyNode = false;
|
||||
for (const auto& node : activeNodes) {
|
||||
if (node && node->isInside(cursorPos)) {
|
||||
isOverAnyNode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isOverAnyNode) {
|
||||
for (const auto& node : activeNodes) {
|
||||
if (node) {
|
||||
node->clickedOutside(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::actFocused() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "delegates.hpp"
|
||||
|
||||
#include <set>
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
|
@ -92,7 +93,6 @@ namespace gui {
|
|||
bool debug = false;
|
||||
|
||||
void actMouse(Frame& frame, float delta, const CursorState& cursor);
|
||||
void performClickOutside(Frame& frame, float delta, glm::vec2 cursorPos);
|
||||
void actFocused();
|
||||
void updateTooltip(float delta);
|
||||
void resetTooltip();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
#include "graphics/ui/GUI.hpp"
|
||||
#include "items/Inventory.hpp"
|
||||
#include "items/ItemDef.hpp"
|
||||
#include "items/ItemStack.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "maths/voxmaths.hpp"
|
||||
#include "objects/Player.hpp"
|
||||
|
|
@ -608,33 +607,6 @@ void InventoryView::setPos(const glm::vec2& pos) {
|
|||
Container::setPos(pos - origin);
|
||||
}
|
||||
|
||||
void InventoryView::clickedOutside(Mousecode button) {
|
||||
// root is the id of the main inventory
|
||||
if (getId() != "root") {
|
||||
return;
|
||||
}
|
||||
int mode;
|
||||
if (button == Mousecode::BUTTON_1) {
|
||||
mode = 0;
|
||||
} else if (button == Mousecode::BUTTON_2) {
|
||||
mode = 1;
|
||||
} else if (button == Mousecode::BUTTON_3) {
|
||||
mode = 2;
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
auto exchangeSlot = std::dynamic_pointer_cast<SlotView>(
|
||||
gui.get(SlotView::EXCHANGE_SLOT_NAME));
|
||||
if (exchangeSlot == nullptr) {
|
||||
return;
|
||||
}
|
||||
ItemStack& grabbed = exchangeSlot->getStack();
|
||||
if (grabbed.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
scripting::on_inventory_clicked_outside(exchangeSlot->getInventoryId(), 0, mode);
|
||||
}
|
||||
|
||||
void InventoryView::setOrigin(const glm::vec2& origin) {
|
||||
this->origin = origin;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,8 +143,6 @@ namespace gui {
|
|||
|
||||
void setSelected(int index);
|
||||
|
||||
void clickedOutside(Mousecode button) override;
|
||||
|
||||
void bind(
|
||||
const std::shared_ptr<Inventory>& inventory,
|
||||
const Content* content
|
||||
|
|
|
|||
|
|
@ -207,9 +207,6 @@ namespace gui {
|
|||
virtual void onFocus();
|
||||
virtual void doubleClick(int x, int y);
|
||||
virtual void click(int x, int y);
|
||||
virtual void clickedOutside(Mousecode button) {
|
||||
// Empty for all UINodes, except InventoryView
|
||||
}
|
||||
virtual void clicked(Mousecode button);
|
||||
virtual void mouseMove(int x, int y) {};
|
||||
virtual void mouseRelease(int x, int y);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue