mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 14:31:50 +00:00
Merge branch 'feat-inventory-enhancements' into feat-inventory-enhancements-p2
This commit is contained in:
commit
871326555d
20 changed files with 114 additions and 123 deletions
|
|
@ -139,7 +139,7 @@ gui.confirm(
|
||||||
## Documents and templates
|
## Documents and templates
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Loads a UI document with its script, returns the name of the document if successfully loaded.
|
-- Loads a UI document with its script. Returns document environment table
|
||||||
gui.load_document(
|
gui.load_document(
|
||||||
-- Path to the xml file of the page. Example: `core:layouts/pages/main.xml`
|
-- Path to the xml file of the page. Example: `core:layouts/pages/main.xml`
|
||||||
path: str,
|
path: str,
|
||||||
|
|
@ -147,7 +147,7 @@ gui.load_document(
|
||||||
name: str
|
name: str
|
||||||
-- Table of parameters passed to the on_open event
|
-- Table of parameters passed to the on_open event
|
||||||
args: table
|
args: table
|
||||||
) -> str
|
) -> table
|
||||||
|
|
||||||
-- Loads and processes layout template from file
|
-- Loads and processes layout template from file
|
||||||
gui.template(
|
gui.template(
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ Examples:
|
||||||
- `position-func` - position supplier for an element (two numbers), called on every parent container size update or on element adding on a container. May be called before *on_hud_open*
|
- `position-func` - position supplier for an element (two numbers), called on every parent container size update or on element adding on a container. May be called before *on_hud_open*
|
||||||
- `size-func` - element size provider (two numbers), called when the size of the container in which the element is located changes, or when an element is added to the container. Can be called before on_hud_open is called.
|
- `size-func` - element size provider (two numbers), called when the size of the container in which the element is located changes, or when an element is added to the container. Can be called before on_hud_open is called.
|
||||||
- `onclick` - lua function called when an element is clicked.
|
- `onclick` - lua function called when an element is clicked.
|
||||||
|
- `onrightclick` - lua function called when the right mouse button is pressed on an element.
|
||||||
|
- `onmiddleclick` - lua function called when the middle mouse button is pressed on an element.
|
||||||
- `ondoubleclick` - lua function called when you double click on an element.
|
- `ondoubleclick` - lua function called when you double click on an element.
|
||||||
- `onfocus` - lua function called when focusing on an element.
|
- `onfocus` - lua function called when focusing on an element.
|
||||||
- `ondefocus` - lua function called when the element loses focus.
|
- `ondefocus` - lua function called when the element loses focus.
|
||||||
|
|
|
||||||
|
|
@ -140,12 +140,12 @@ gui.confirm(
|
||||||
## Документы и шаблоны
|
## Документы и шаблоны
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Загружает UI документ и его скрипт. Возвращает имя документа.
|
-- Загружает UI документ и его скрипт. Возвращает пространство имён документа
|
||||||
gui.load_document(
|
gui.load_document(
|
||||||
path: string, -- путь к xml файлу, например: core:layouts/pages/main.xml
|
path: string, -- путь к xml файлу, например: core:layouts/pages/main.xml
|
||||||
name: string, -- id документа, например: core:pages/main
|
name: string, -- id документа, например: core:pages/main
|
||||||
args: table -- параметры для события on_open
|
args: table -- параметры для события on_open
|
||||||
) -> string
|
) -> table
|
||||||
|
|
||||||
-- Обрабатывает xml шаблон макета из файла
|
-- Обрабатывает xml шаблон макета из файла
|
||||||
gui.template(
|
gui.template(
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@
|
||||||
- `position-func` - поставщик позиции элемента (два числа), вызываемый при изменении размера контейнера, в котором находится элемент, либо при добавлении элемента в контейнер. Может быть вызван до вызова on_hud_open.
|
- `position-func` - поставщик позиции элемента (два числа), вызываемый при изменении размера контейнера, в котором находится элемент, либо при добавлении элемента в контейнер. Может быть вызван до вызова on_hud_open.
|
||||||
- `size-func` - поставщик размера элемента (два числа), вызываемый при изменении размера контейнера, в котором находится элемент, либо при добавлении элемента в контейнер. Может быть вызван до вызова on_hud_open.
|
- `size-func` - поставщик размера элемента (два числа), вызываемый при изменении размера контейнера, в котором находится элемент, либо при добавлении элемента в контейнер. Может быть вызван до вызова on_hud_open.
|
||||||
- `onclick` - lua функция вызываемая при нажатии на элемент.
|
- `onclick` - lua функция вызываемая при нажатии на элемент.
|
||||||
|
- `onrightclick` - lua функция вызываемая при нажатии правой кнопки мыши на элемент.
|
||||||
|
- `onmiddleclick` - lua функция вызываемая при нажатии средней кнопки мыши на элемент.
|
||||||
- `ondoubleclick` - lua функция вызываемая при двойном нажатии на элемент.
|
- `ondoubleclick` - lua функция вызываемая при двойном нажатии на элемент.
|
||||||
- `onfocus` - lua функция вызываемая при фокусировке на элемент.
|
- `onfocus` - lua функция вызываемая при фокусировке на элемент.
|
||||||
- `ondefocus` - lua функция вызываемая при потере фокуса элеметом.
|
- `ondefocus` - lua функция вызываемая при потере фокуса элеметом.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,44 @@
|
||||||
local util = {}
|
local util = {}
|
||||||
|
|
||||||
|
local DROP_FORCE = 8
|
||||||
|
local DROP_INIT_VEL = {0, 3, 0}
|
||||||
|
|
||||||
|
---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack
|
||||||
|
function util.drop_from_slot(invid, slot, mode)
|
||||||
|
if invid == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local pid = hud.get_player()
|
||||||
|
if mode == 2 and !player.is_infinite_items(pid) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local itemid, itemcount = inventory.get(invid, slot)
|
||||||
|
if itemid == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local drop_itemcount = 1
|
||||||
|
if mode == 0 then
|
||||||
|
drop_itemcount = itemcount
|
||||||
|
end
|
||||||
|
if mode == 2 then
|
||||||
|
drop_itemcount = item.stack_size(itemid)
|
||||||
|
else
|
||||||
|
inventory.set(invid, slot, itemid, itemcount - drop_itemcount)
|
||||||
|
end
|
||||||
|
|
||||||
|
local data = inventory.get_all_data(invid, slot)
|
||||||
|
local pvel = { player.get_vel(pid) }
|
||||||
|
local ppos = vec3.add({ player.get_pos(pid) }, { 0, 0.7, 0 })
|
||||||
|
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
||||||
|
local drop = util.drop(ppos, itemid, drop_itemcount, data, 1.5)
|
||||||
|
if not drop then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))
|
||||||
|
drop.rigidbody:set_vel(velocity)
|
||||||
|
end
|
||||||
|
|
||||||
function util.drop(ppos, itemid, count, data, pickup_delay)
|
function util.drop(ppos, itemid, count, data, pickup_delay)
|
||||||
if itemid == 0 or not itemid then
|
if itemid == 0 or not itemid then
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,10 @@
|
||||||
local base_util = require "util"
|
local base_util = require "util"
|
||||||
|
|
||||||
local DROP_FORCE = 8
|
|
||||||
local DROP_INIT_VEL = {0, 3, 0}
|
|
||||||
|
|
||||||
---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack
|
|
||||||
function drop_from_slot(invid, slot, mode)
|
|
||||||
local pid = hud.get_player()
|
|
||||||
if mode == 2 and !player.is_infinite_items(pid) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local itemid, itemcount = inventory.get(invid, slot)
|
|
||||||
if itemid == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local drop_itemcount = 1
|
|
||||||
if mode == 0 then
|
|
||||||
drop_itemcount = itemcount
|
|
||||||
end
|
|
||||||
if mode == 2 then
|
|
||||||
drop_itemcount = item.stack_size(itemid)
|
|
||||||
else
|
|
||||||
inventory.set(invid, slot, itemid, itemcount - drop_itemcount)
|
|
||||||
end
|
|
||||||
|
|
||||||
local data = inventory.get_all_data(invid, slot)
|
|
||||||
local pvel = { player.get_vel(pid) }
|
|
||||||
local ppos = vec3.add({ player.get_pos(pid) }, { 0, 0.7, 0 })
|
|
||||||
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
|
||||||
local drop = base_util.drop(ppos, itemid, drop_itemcount, data, 1.5)
|
|
||||||
if not drop then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))
|
|
||||||
drop.rigidbody:set_vel(velocity)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_inventory_clicked_outside(exc_invid, exc_slot, mode)
|
|
||||||
drop_from_slot(exc_invid, exc_slot, mode)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_hud_open()
|
function on_hud_open()
|
||||||
|
events.on("core:drop_outside_inventory", function(mode)
|
||||||
|
local invid = hud.get_exchange_inventory()
|
||||||
|
base_util.drop_from_slot(invid, 0, mode)
|
||||||
|
end)
|
||||||
input.add_callback("player.drop", function()
|
input.add_callback("player.drop", function()
|
||||||
if hud.is_paused() or hud.is_inventory_open() then
|
if hud.is_paused() or hud.is_inventory_open() then
|
||||||
return
|
return
|
||||||
|
|
@ -51,7 +15,7 @@ function on_hud_open()
|
||||||
if input.is_pressed("key:left-ctrl") or input.is_pressed("key:right-ctrl") then
|
if input.is_pressed("key:left-ctrl") or input.is_pressed("key:right-ctrl") then
|
||||||
mode = 0
|
mode = 0
|
||||||
end
|
end
|
||||||
drop_from_slot(invid, slot, mode)
|
base_util.drop_from_slot(invid, slot, mode)
|
||||||
end)
|
end)
|
||||||
rules.create("do-loot-non-player", true)
|
rules.create("do-loot-non-player", true)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -192,13 +192,15 @@ function gui.ask(text, on_yes, on_no, yes_text, no_text)
|
||||||
<container id='%s' color='#00000080' size-func='-1,-1' z-index='10'>
|
<container id='%s' color='#00000080' size-func='-1,-1' z-index='10'>
|
||||||
<panel color='#507090E0' size='600' padding='16'
|
<panel color='#507090E0' size='600' padding='16'
|
||||||
gravity='center-center' interval='4'>
|
gravity='center-center' interval='4'>
|
||||||
<label margin='4'>%s</label>
|
<label margin='4' markup='md'>%s</label>
|
||||||
<button onclick='DATA.on_yes()'>@%s</button>
|
<button onclick='DATA.on_yes()'>@%s</button>
|
||||||
<button onclick='DATA.on_no()'>@%s</button>
|
<button onclick='DATA.on_no()'>@%s</button>
|
||||||
</panel>
|
</panel>
|
||||||
</container>
|
</container>
|
||||||
]], id, string.escape_xml(text)), {on_yes=yes_callback, on_no=no_callback},
|
]], id,
|
||||||
string.escape_xml(yes_text), string.escape_xml(no_text))
|
string.escape_xml(text),
|
||||||
|
string.escape_xml(yes_text),
|
||||||
|
string.escape_xml(no_text)), {on_yes=yes_callback, on_no=no_callback})
|
||||||
input.add_callback("key:escape", no_callback, gui.root[id])
|
input.add_callback("key:escape", no_callback, gui.root[id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,15 @@ Hud::Hud(Engine& engine, LevelFrontend& frontend, Player& player)
|
||||||
gui,
|
gui,
|
||||||
"<container size='4000' color='#00000080' z-index='-1' visible='false'/>"
|
"<container size='4000' color='#00000080' z-index='-1' visible='false'/>"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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)'
|
||||||
|
onmiddleclick='events.emit(\"core:drop_outside_inventory\", 2)'
|
||||||
|
/>)"
|
||||||
|
);
|
||||||
|
|
||||||
uicamera = std::make_unique<Camera>(glm::vec3(), 1);
|
uicamera = std::make_unique<Camera>(glm::vec3(), 1);
|
||||||
uicamera->perspective = false;
|
uicamera->perspective = false;
|
||||||
|
|
@ -188,6 +197,7 @@ Hud::Hud(Engine& engine, LevelFrontend& frontend, Player& player)
|
||||||
|
|
||||||
gui.add(debugPanel);
|
gui.add(debugPanel);
|
||||||
gui.add(darkOverlay);
|
gui.add(darkOverlay);
|
||||||
|
gui.add(inventoryDropArea);
|
||||||
gui.add(hotbarView);
|
gui.add(hotbarView);
|
||||||
gui.add(contentAccessPanel);
|
gui.add(contentAccessPanel);
|
||||||
|
|
||||||
|
|
@ -213,6 +223,7 @@ Hud::~Hud() {
|
||||||
}
|
}
|
||||||
gui.remove(hotbarView);
|
gui.remove(hotbarView);
|
||||||
gui.remove(darkOverlay);
|
gui.remove(darkOverlay);
|
||||||
|
gui.remove(inventoryDropArea);
|
||||||
gui.remove(contentAccessPanel);
|
gui.remove(contentAccessPanel);
|
||||||
gui.remove(debugPanel);
|
gui.remove(debugPanel);
|
||||||
}
|
}
|
||||||
|
|
@ -358,6 +369,7 @@ void Hud::update(bool visible) {
|
||||||
contentAccess->setMinSize(glm::vec2(1, windowSize.y));
|
contentAccess->setMinSize(glm::vec2(1, windowSize.y));
|
||||||
hotbarView->setVisible(visible && !(secondUI && !inventoryView));
|
hotbarView->setVisible(visible && !(secondUI && !inventoryView));
|
||||||
darkOverlay->setVisible(isMenuOpen);
|
darkOverlay->setVisible(isMenuOpen);
|
||||||
|
inventoryDropArea->setVisible(inventoryOpen);
|
||||||
menu.setVisible(isMenuOpen);
|
menu.setVisible(isMenuOpen);
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
|
|
@ -739,6 +751,10 @@ std::shared_ptr<Inventory> Hud::getSecondInventory() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Inventory> Hud::getExchangeInventory() {
|
||||||
|
return exchangeSlotInv;
|
||||||
|
}
|
||||||
|
|
||||||
bool Hud::isContentAccess() const {
|
bool Hud::isContentAccess() const {
|
||||||
return showContentPanel;
|
return showContentPanel;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,8 @@ class Hud : public util::ObjectsKeeper {
|
||||||
std::shared_ptr<gui::UINode> debugPanel;
|
std::shared_ptr<gui::UINode> debugPanel;
|
||||||
/// @brief Overlay used in pause mode
|
/// @brief Overlay used in pause mode
|
||||||
std::shared_ptr<gui::UINode> darkOverlay;
|
std::shared_ptr<gui::UINode> darkOverlay;
|
||||||
|
/// @brief Overlay used in inventory
|
||||||
|
std::shared_ptr<gui::UINode> inventoryDropArea;
|
||||||
/// @brief Inventories interaction agent (grabbed item)
|
/// @brief Inventories interaction agent (grabbed item)
|
||||||
std::shared_ptr<gui::SlotView> exchangeSlot;
|
std::shared_ptr<gui::SlotView> exchangeSlot;
|
||||||
/// @brief Exchange slot inventory (1 slot only)
|
/// @brief Exchange slot inventory (1 slot only)
|
||||||
|
|
@ -207,6 +209,8 @@ public:
|
||||||
|
|
||||||
std::shared_ptr<Inventory> getSecondInventory();
|
std::shared_ptr<Inventory> getSecondInventory();
|
||||||
|
|
||||||
|
std::shared_ptr<Inventory> getExchangeInventory();
|
||||||
|
|
||||||
bool isContentAccess() const;
|
bool isContentAccess() const;
|
||||||
|
|
||||||
void setContentAccess(bool flag);
|
void setContentAccess(bool flag);
|
||||||
|
|
|
||||||
|
|
@ -178,8 +178,6 @@ void GUI::actMouse(Frame& frame, float delta, const CursorState& cursor) {
|
||||||
}
|
}
|
||||||
it = mouseOver.erase(it);
|
it = mouseOver.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool focusHappened = false;
|
|
||||||
|
|
||||||
if (input.jclicked(Mousecode::BUTTON_1)) {
|
if (input.jclicked(Mousecode::BUTTON_1)) {
|
||||||
if (pressed == nullptr && this->hover) {
|
if (pressed == nullptr && this->hover) {
|
||||||
|
|
@ -197,10 +195,10 @@ void GUI::actMouse(Frame& frame, float delta, const CursorState& cursor) {
|
||||||
if (focus != pressed) {
|
if (focus != pressed) {
|
||||||
focus = pressed;
|
focus = pressed;
|
||||||
focus->onFocus();
|
focus->onFocus();
|
||||||
focusHappened = true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->hover == nullptr && focus && !focusHappened) {
|
if (this->hover == nullptr && focus) {
|
||||||
focus->defocus();
|
focus->defocus();
|
||||||
focus = nullptr;
|
focus = nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -209,44 +207,13 @@ void GUI::actMouse(Frame& frame, float delta, const CursorState& cursor) {
|
||||||
pressed = nullptr;
|
pressed = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hover && !focusHappened) {
|
if (hover) {
|
||||||
for (Mousecode code : MOUSECODES_ALL) {
|
for (Mousecode code : MOUSECODES_ALL) {
|
||||||
if (input.jclicked(code)) {
|
if (input.jclicked(code)) {
|
||||||
hover->clicked(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() {
|
void GUI::actFocused() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "delegates.hpp"
|
#include "delegates.hpp"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -92,7 +93,6 @@ namespace gui {
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
|
|
||||||
void actMouse(Frame& frame, float delta, const CursorState& cursor);
|
void actMouse(Frame& frame, float delta, const CursorState& cursor);
|
||||||
void performClickOutside(Frame& frame, float delta, glm::vec2 cursorPos);
|
|
||||||
void actFocused();
|
void actFocused();
|
||||||
void updateTooltip(float delta);
|
void updateTooltip(float delta);
|
||||||
void resetTooltip();
|
void resetTooltip();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
#include "graphics/ui/GUI.hpp"
|
#include "graphics/ui/GUI.hpp"
|
||||||
#include "items/Inventory.hpp"
|
#include "items/Inventory.hpp"
|
||||||
#include "items/ItemDef.hpp"
|
#include "items/ItemDef.hpp"
|
||||||
#include "items/ItemStack.hpp"
|
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "maths/voxmaths.hpp"
|
#include "maths/voxmaths.hpp"
|
||||||
#include "objects/Player.hpp"
|
#include "objects/Player.hpp"
|
||||||
|
|
@ -615,33 +614,6 @@ void InventoryView::setPos(const glm::vec2& pos) {
|
||||||
Container::setPos(pos - origin);
|
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) {
|
void InventoryView::setOrigin(const glm::vec2& origin) {
|
||||||
this->origin = origin;
|
this->origin = origin;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,8 +143,6 @@ namespace gui {
|
||||||
|
|
||||||
void setSelected(int index);
|
void setSelected(int index);
|
||||||
|
|
||||||
void clickedOutside(Mousecode button) override;
|
|
||||||
|
|
||||||
void bind(
|
void bind(
|
||||||
const std::shared_ptr<Inventory>& inventory,
|
const std::shared_ptr<Inventory>& inventory,
|
||||||
const Content* content
|
const Content* content
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include "window/Window.hpp"
|
#include "window/Window.hpp"
|
||||||
#include "../GUI.hpp"
|
#include "../GUI.hpp"
|
||||||
|
|
||||||
|
// TODO: remove
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
|
@ -24,8 +25,7 @@ ModelViewer::ModelViewer(
|
||||||
: Container(gui, size),
|
: Container(gui, size),
|
||||||
modelName(modelName),
|
modelName(modelName),
|
||||||
camera(),
|
camera(),
|
||||||
batch(std::make_unique<Batch3D>(1024)),
|
batch(std::make_unique<Batch3D>(1024)) {
|
||||||
fbo(std::make_unique<Framebuffer>(size.x, size.y)) {
|
|
||||||
camera.perspective = true;
|
camera.perspective = true;
|
||||||
camera.position = glm::vec3(2, 2, 2);
|
camera.position = glm::vec3(2, 2, 2);
|
||||||
}
|
}
|
||||||
|
|
@ -115,7 +115,13 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& prevShader = Shader::getUsed();
|
auto& prevShader = Shader::getUsed();
|
||||||
|
|
||||||
|
if (!fbo) {
|
||||||
|
if (size.x <= 0 || size.y <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fbo = std::make_unique<Framebuffer>(size.x, size.y);
|
||||||
|
}
|
||||||
fbo->resize(size.x, size.y);
|
fbo->resize(size.x, size.y);
|
||||||
{
|
{
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
|
@ -154,6 +160,13 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
Container::draw(pctx, assets);
|
Container::draw(pctx, assets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelViewer::setVisible(bool flag) {
|
||||||
|
if (!flag && fbo) {
|
||||||
|
fbo.reset();
|
||||||
|
}
|
||||||
|
Container::setVisible(flag);
|
||||||
|
}
|
||||||
|
|
||||||
void ModelViewer::setCenter(const glm::vec3& center) {
|
void ModelViewer::setCenter(const glm::vec3& center) {
|
||||||
this->center = center;
|
this->center = center;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ namespace gui {
|
||||||
bool grabbing = false;
|
bool grabbing = false;
|
||||||
public:
|
public:
|
||||||
ModelViewer(GUI& gui, const glm::vec2& size, const std::string& modelName);
|
ModelViewer(GUI& gui, const glm::vec2& size, const std::string& modelName);
|
||||||
|
|
||||||
~ModelViewer();
|
~ModelViewer();
|
||||||
|
|
||||||
void setModel(const std::string& modelName);
|
void setModel(const std::string& modelName);
|
||||||
|
|
@ -34,6 +33,7 @@ namespace gui {
|
||||||
|
|
||||||
void act(float delta) override;
|
void act(float delta) override;
|
||||||
void draw(const DrawContext& pctx, const Assets& assets) override;
|
void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
void setVisible(bool flag) override;
|
||||||
|
|
||||||
void setRotation(const glm::vec3& euler);
|
void setRotation(const glm::vec3& euler);
|
||||||
void setCenter(const glm::vec3& center);
|
void setCenter(const glm::vec3& center);
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,8 @@ void UINode::click(int, int) {
|
||||||
void UINode::clicked(Mousecode button) {
|
void UINode::clicked(Mousecode button) {
|
||||||
if (button == Mousecode::BUTTON_2) {
|
if (button == Mousecode::BUTTON_2) {
|
||||||
actions.notify(UIAction::RIGHT_CLICK, gui);
|
actions.notify(UIAction::RIGHT_CLICK, gui);
|
||||||
|
} else if (button == Mousecode::BUTTON_3) {
|
||||||
|
actions.notify(UIAction::MIDDLE_CLICK, gui);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ namespace gui {
|
||||||
FOCUS,
|
FOCUS,
|
||||||
DEFOCUS,
|
DEFOCUS,
|
||||||
RIGHT_CLICK,
|
RIGHT_CLICK,
|
||||||
|
MIDDLE_CLICK,
|
||||||
MOUSE_OVER,
|
MOUSE_OVER,
|
||||||
MOUSE_OUT,
|
MOUSE_OUT,
|
||||||
MOUSE_ENTER,
|
MOUSE_ENTER,
|
||||||
|
|
@ -207,9 +208,6 @@ namespace gui {
|
||||||
virtual void onFocus();
|
virtual void onFocus();
|
||||||
virtual void doubleClick(int x, int y);
|
virtual void doubleClick(int x, int y);
|
||||||
virtual void click(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 clicked(Mousecode button);
|
||||||
virtual void mouseMove(int x, int y) {};
|
virtual void mouseMove(int x, int y) {};
|
||||||
virtual void mouseRelease(int x, int y);
|
virtual void mouseRelease(int x, int y);
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ static void read_uinode(
|
||||||
|
|
||||||
register_action(node, reader, element, "onclick", UIAction::CLICK);
|
register_action(node, reader, element, "onclick", UIAction::CLICK);
|
||||||
register_action(node, reader, element, "onrightclick", UIAction::RIGHT_CLICK);
|
register_action(node, reader, element, "onrightclick", UIAction::RIGHT_CLICK);
|
||||||
|
register_action(node, reader, element, "onmiddleclick", UIAction::MIDDLE_CLICK);
|
||||||
register_action(node, reader, element, "onfocus", UIAction::FOCUS);
|
register_action(node, reader, element, "onfocus", UIAction::FOCUS);
|
||||||
register_action(node, reader, element, "ondefocus", UIAction::DEFOCUS);
|
register_action(node, reader, element, "ondefocus", UIAction::DEFOCUS);
|
||||||
register_action(node, reader, element, "ondoubleclick", UIAction::DOUBLE_CLICK);
|
register_action(node, reader, element, "ondoubleclick", UIAction::DOUBLE_CLICK);
|
||||||
|
|
|
||||||
|
|
@ -1127,6 +1127,7 @@ static int l_gui_load_document(lua::State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto env = scripting::create_doc_environment(parentEnv, alias);
|
auto env = scripting::create_doc_environment(parentEnv, alias);
|
||||||
|
auto envId = *env;
|
||||||
// namespace extension
|
// namespace extension
|
||||||
if (lua::istable(L, 4)) {
|
if (lua::istable(L, 4)) {
|
||||||
if (lua::get_from(L, "table", "extend")) {
|
if (lua::get_from(L, "table", "extend")) {
|
||||||
|
|
@ -1148,7 +1149,7 @@ static int l_gui_load_document(lua::State* L) {
|
||||||
engine->requireAssets().store(std::move(documentPtr), alias);
|
engine->requireAssets().store(std::move(documentPtr), alias);
|
||||||
|
|
||||||
scripting::on_ui_open(*document, {args});
|
scripting::on_ui_open(*document, {args});
|
||||||
return 0;
|
return lua::pushenv(L, envId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_set_syntax_styles(lua::State* L) {
|
static int l_set_syntax_styles(lua::State* L) {
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,15 @@ static int l_get_second_inventory(lua::State* L) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_exchange_inventory(lua::State* L) {
|
||||||
|
auto inventory = hud->getExchangeInventory();
|
||||||
|
if (inventory == nullptr) {
|
||||||
|
return lua::pushinteger(L, 0);
|
||||||
|
} else {
|
||||||
|
return lua::pushinteger(L, inventory->getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int l_get_player(lua::State* L) {
|
static int l_get_player(lua::State* L) {
|
||||||
auto player = hud->getPlayer();
|
auto player = hud->getPlayer();
|
||||||
return lua::pushinteger(L, player->getId());
|
return lua::pushinteger(L, player->getId());
|
||||||
|
|
@ -216,6 +225,7 @@ const luaL_Reg hudlib[] = {
|
||||||
{"show_overlay", wrap_hud<l_show_overlay>},
|
{"show_overlay", wrap_hud<l_show_overlay>},
|
||||||
{"get_block_inventory", wrap_hud<l_get_block_inventory>},
|
{"get_block_inventory", wrap_hud<l_get_block_inventory>},
|
||||||
{"get_second_inventory", wrap_hud<l_get_second_inventory>},
|
{"get_second_inventory", wrap_hud<l_get_second_inventory>},
|
||||||
|
{"get_exchange_inventory", wrap_hud<l_get_exchange_inventory>},
|
||||||
{"close", wrap_hud<l_close>},
|
{"close", wrap_hud<l_close>},
|
||||||
{"pause", wrap_hud<l_pause>},
|
{"pause", wrap_hud<l_pause>},
|
||||||
{"resume", wrap_hud<l_resume>},
|
{"resume", wrap_hud<l_resume>},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue