mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31:49 +00:00
fix middle click on access panel
This commit is contained in:
parent
1040a3a183
commit
047f050364
4 changed files with 34 additions and 5 deletions
|
|
@ -6,13 +6,18 @@ function on_hud_open()
|
|||
base_util.drop_from_slot(invid, 0, mode)
|
||||
end)
|
||||
|
||||
events.on("core:access_panel_slot_middle_click", function(itemid)
|
||||
local exc_invid = hud.get_exchange_inventory()
|
||||
inventory.set(exc_invid, 0, itemid, item.stack_size(itemid))
|
||||
end)
|
||||
|
||||
events.on("core:slot_middle_click", function(invid, slot)
|
||||
if not player.is_infinite_items(hud.get_player()) then
|
||||
return
|
||||
end
|
||||
local itemid = inventory.get(invid, slot)
|
||||
local exc_invid = hud.get_exchange_inventory()
|
||||
local exc_itemid = inventory.get(exc_invid, 0)
|
||||
local itemid = inventory.get(invid, slot)
|
||||
if itemid == 0 then
|
||||
if exc_itemid ~= 0 then
|
||||
local stack_size = item.stack_size(exc_itemid)
|
||||
|
|
@ -22,6 +27,11 @@ function on_hud_open()
|
|||
if exc_itemid == 0 then
|
||||
local stack_size = item.stack_size(itemid)
|
||||
inventory.set(exc_invid, 0, itemid, stack_size)
|
||||
else
|
||||
if exc_itemid == itemid then
|
||||
local stack_size = item.stack_size(exc_itemid)
|
||||
inventory.set(invid, slot, exc_itemid, stack_size)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "InventoryView.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
#include "assets/Assets.hpp"
|
||||
|
|
@ -501,10 +502,14 @@ void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
|
|||
}
|
||||
|
||||
void SlotView::performMiddleClick(ItemStack& stack, ItemStack& grabbed) {
|
||||
scripting::on_slot_middle_click(
|
||||
inventoryId,
|
||||
layout.index
|
||||
);
|
||||
if (layout.itemSource) {
|
||||
scripting::on_access_panel_slot_middle_click(stack.getItemId());
|
||||
} else {
|
||||
scripting::on_slot_middle_click(
|
||||
inventoryId,
|
||||
layout.index
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void SlotView::clicked(Mousecode button) {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ namespace scripting {
|
|||
void on_inventory_interact(int invid, int slot, int action, int mode);
|
||||
|
||||
void on_slot_middle_click(int invid, int slot);
|
||||
void on_access_panel_slot_middle_click(const itemid_t itemid);
|
||||
|
||||
void on_player_tick(Player* player, int tps);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "lua/libs/api_lua.hpp"
|
||||
#include "lua/lua_engine.hpp"
|
||||
#include "scripting.hpp"
|
||||
#include "typedefs.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
|
|
@ -123,6 +124,18 @@ void scripting::on_slot_middle_click(int invid, int slot) {
|
|||
);
|
||||
}
|
||||
|
||||
void scripting::on_access_panel_slot_middle_click(const itemid_t itemid) {
|
||||
auto L = lua::get_main_state();
|
||||
lua::emit_event(
|
||||
L,
|
||||
"core:access_panel_slot_middle_click",
|
||||
[&](lua::State* L) {
|
||||
lua::pushinteger(L, itemid);
|
||||
return 1;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void scripting::load_hud_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& packid,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue