@@ -39,3 +39,6 @@ appimage-build/
|
|||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
/res/content/*
|
||||||
|
!/res/content/base
|
||||||
@@ -31,6 +31,7 @@ SlotLayout::SlotLayout(
|
|||||||
glm::vec2 position,
|
glm::vec2 position,
|
||||||
bool background,
|
bool background,
|
||||||
bool itemSource,
|
bool itemSource,
|
||||||
|
slotcallback updateFunc,
|
||||||
slotcallback shareFunc,
|
slotcallback shareFunc,
|
||||||
slotcallback rightClick
|
slotcallback rightClick
|
||||||
)
|
)
|
||||||
@@ -38,6 +39,7 @@ SlotLayout::SlotLayout(
|
|||||||
position(position),
|
position(position),
|
||||||
background(background),
|
background(background),
|
||||||
itemSource(itemSource),
|
itemSource(itemSource),
|
||||||
|
updateFunc(updateFunc),
|
||||||
shareFunc(shareFunc),
|
shareFunc(shareFunc),
|
||||||
rightClick(rightClick) {}
|
rightClick(rightClick) {}
|
||||||
|
|
||||||
@@ -218,6 +220,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) {
|
|||||||
if (layout.shareFunc) {
|
if (layout.shareFunc) {
|
||||||
layout.shareFunc(layout.index, stack);
|
layout.shareFunc(layout.index, stack);
|
||||||
}
|
}
|
||||||
|
if (layout.updateFunc) {
|
||||||
|
layout.updateFunc(layout.index, stack);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!layout.itemSource && stack.accepts(grabbed)) {
|
if (!layout.itemSource && stack.accepts(grabbed)) {
|
||||||
@@ -236,6 +241,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) {
|
|||||||
} else if (button == mousecode::BUTTON_2) {
|
} else if (button == mousecode::BUTTON_2) {
|
||||||
if (layout.rightClick) {
|
if (layout.rightClick) {
|
||||||
layout.rightClick(inventoryid, stack);
|
layout.rightClick(inventoryid, stack);
|
||||||
|
if (layout.updateFunc) {
|
||||||
|
layout.updateFunc(layout.index, stack);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (layout.itemSource)
|
if (layout.itemSource)
|
||||||
@@ -258,6 +266,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (layout.updateFunc) {
|
||||||
|
layout.updateFunc(layout.index, stack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlotView::onFocus(gui::GUI* gui) {
|
void SlotView::onFocus(gui::GUI* gui) {
|
||||||
@@ -384,10 +395,13 @@ static slotcallback readSlotFunc(InventoryView* view, gui::UiXmlReader& reader,
|
|||||||
static void readSlot(InventoryView* view, gui::UiXmlReader& reader, xml::xmlelement element) {
|
static void readSlot(InventoryView* view, gui::UiXmlReader& reader, xml::xmlelement element) {
|
||||||
int index = element->attr("index", "0").asInt();
|
int index = element->attr("index", "0").asInt();
|
||||||
bool itemSource = element->attr("item-source", "false").asBool();
|
bool itemSource = element->attr("item-source", "false").asBool();
|
||||||
SlotLayout layout(index, glm::vec2(), true, itemSource, nullptr, nullptr);
|
SlotLayout layout(index, glm::vec2(), true, itemSource, nullptr, nullptr, nullptr);
|
||||||
if (element->has("pos")) {
|
if (element->has("pos")) {
|
||||||
layout.position = element->attr("pos").asVec2();
|
layout.position = element->attr("pos").asVec2();
|
||||||
}
|
}
|
||||||
|
if (element->has("updatefunc")) {
|
||||||
|
layout.updateFunc = readSlotFunc(view, reader, element, "updatefunc");
|
||||||
|
}
|
||||||
if (element->has("sharefunc")) {
|
if (element->has("sharefunc")) {
|
||||||
layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc");
|
layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc");
|
||||||
}
|
}
|
||||||
@@ -421,10 +435,13 @@ static void readSlotsGrid(InventoryView* view, gui::UiXmlReader& reader, xml::xm
|
|||||||
count = rows * cols;
|
count = rows * cols;
|
||||||
}
|
}
|
||||||
bool itemSource = element->attr("item-source", "false").asBool();
|
bool itemSource = element->attr("item-source", "false").asBool();
|
||||||
SlotLayout layout(-1, glm::vec2(), true, itemSource, nullptr, nullptr);
|
SlotLayout layout(-1, glm::vec2(), true, itemSource, nullptr, nullptr, nullptr);
|
||||||
if (element->has("pos")) {
|
if (element->has("pos")) {
|
||||||
layout.position = element->attr("pos").asVec2();
|
layout.position = element->attr("pos").asVec2();
|
||||||
}
|
}
|
||||||
|
if (element->has("updatefunc")) {
|
||||||
|
layout.updateFunc = readSlotFunc(view, reader, element, "updatefunc");
|
||||||
|
}
|
||||||
if (element->has("sharefunc")) {
|
if (element->has("sharefunc")) {
|
||||||
layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc");
|
layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ struct SlotLayout {
|
|||||||
glm::vec2 position;
|
glm::vec2 position;
|
||||||
bool background;
|
bool background;
|
||||||
bool itemSource;
|
bool itemSource;
|
||||||
|
slotcallback updateFunc;
|
||||||
slotcallback shareFunc;
|
slotcallback shareFunc;
|
||||||
slotcallback rightClick;
|
slotcallback rightClick;
|
||||||
int padding = 0;
|
int padding = 0;
|
||||||
@@ -51,6 +52,7 @@ struct SlotLayout {
|
|||||||
glm::vec2 position,
|
glm::vec2 position,
|
||||||
bool background,
|
bool background,
|
||||||
bool itemSource,
|
bool itemSource,
|
||||||
|
slotcallback updateFunc,
|
||||||
slotcallback shareFunc,
|
slotcallback shareFunc,
|
||||||
slotcallback rightClick);
|
slotcallback rightClick);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ std::shared_ptr<InventoryView> Hud::createContentAccess() {
|
|||||||
accessInventory->getSlot(id-1).set(ItemStack(id, 1));
|
accessInventory->getSlot(id-1).set(ItemStack(id, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
SlotLayout slotLayout(-1, glm::vec2(), false, true,
|
SlotLayout slotLayout(-1, glm::vec2(), false, true, nullptr,
|
||||||
[=](uint, ItemStack& item) {
|
[=](uint, ItemStack& item) {
|
||||||
auto copy = ItemStack(item);
|
auto copy = ItemStack(item);
|
||||||
inventory->move(copy, indices);
|
inventory->move(copy, indices);
|
||||||
@@ -165,7 +165,7 @@ std::shared_ptr<InventoryView> Hud::createContentAccess() {
|
|||||||
std::shared_ptr<InventoryView> Hud::createHotbar() {
|
std::shared_ptr<InventoryView> Hud::createHotbar() {
|
||||||
auto inventory = player->getInventory();
|
auto inventory = player->getInventory();
|
||||||
|
|
||||||
SlotLayout slotLayout(-1, glm::vec2(), false, false, nullptr, nullptr);
|
SlotLayout slotLayout(-1, glm::vec2(), false, false, nullptr, nullptr, nullptr);
|
||||||
InventoryBuilder builder;
|
InventoryBuilder builder;
|
||||||
builder.addGrid(10, 10, glm::vec2(), 4, true, slotLayout);
|
builder.addGrid(10, 10, glm::vec2(), 4, true, slotLayout);
|
||||||
auto view = builder.build();
|
auto view = builder.build();
|
||||||
@@ -185,7 +185,7 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
|
|||||||
{
|
{
|
||||||
interaction = std::make_unique<InventoryInteraction>();
|
interaction = std::make_unique<InventoryInteraction>();
|
||||||
grabbedItemView = std::make_shared<SlotView>(
|
grabbedItemView = std::make_shared<SlotView>(
|
||||||
SlotLayout(-1, glm::vec2(), false, false, nullptr, nullptr)
|
SlotLayout(-1, glm::vec2(), false, false, nullptr, nullptr, nullptr)
|
||||||
);
|
);
|
||||||
grabbedItemView->bind(
|
grabbedItemView->bind(
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#ifndef OBJECT_H
|
#ifndef OBJECT_H
|
||||||
#define OBJECT_H
|
#define OBJECT_H
|
||||||
|
|
||||||
#include "stdlib.h"
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class Level;
|
class Level;
|
||||||
|
|||||||
@@ -299,12 +299,10 @@ void PlayerController::updateInteraction(){
|
|||||||
}
|
}
|
||||||
if (rclick && !input.shift) {
|
if (rclick && !input.shift) {
|
||||||
bool preventDefault = false;
|
bool preventDefault = false;
|
||||||
|
|
||||||
if (item->rt.funcsset.on_use) {
|
|
||||||
preventDefault |= scripting::on_item_use(player.get(), item);
|
|
||||||
}
|
|
||||||
if (item->rt.funcsset.on_use_on_block) {
|
if (item->rt.funcsset.on_use_on_block) {
|
||||||
preventDefault |= scripting::on_item_use_on_block(player.get(), item, x, y, z);
|
preventDefault = scripting::on_item_use_on_block(player.get(), item, x, y, z);
|
||||||
|
} else if (item->rt.funcsset.on_use) {
|
||||||
|
preventDefault = scripting::on_item_use(player.get(), item);
|
||||||
}
|
}
|
||||||
if (preventDefault) {
|
if (preventDefault) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user