block ui test
This commit is contained in:
parent
7e553efdec
commit
af7c828d73
@ -1,4 +1,4 @@
|
|||||||
<inventory color="#1F1F1FE0" position-func="inventory_reposition">
|
<inventory color="#1F1F1FE0">
|
||||||
<slots-grid coord="0, 164" rows="1" count="10" sharefunc="inventory_share_func"/>
|
<slots-grid coord="0, 164" rows="1" count="10" sharefunc="inventory_share_func"/>
|
||||||
<slots-grid rows="3" start-index="10" count="30" sharefunc="inventory_share_func"/>
|
<slots-grid rows="3" start-index="10" count="30" sharefunc="inventory_share_func"/>
|
||||||
</inventory>
|
</inventory>
|
||||||
|
|||||||
@ -420,6 +420,8 @@ void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inven
|
|||||||
}
|
}
|
||||||
openInventory();
|
openInventory();
|
||||||
if (blockinv == nullptr) {
|
if (blockinv == nullptr) {
|
||||||
|
Events::toggleCursor();
|
||||||
|
abort();
|
||||||
blockinv = level->inventories->createVirtual(blockUI->getSlotsCount());
|
blockinv = level->inventories->createVirtual(blockUI->getSlotsCount());
|
||||||
}
|
}
|
||||||
blockUI->bind(blockinv, frontend, interaction.get());
|
blockUI->bind(blockinv, frontend, interaction.get());
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
#include "libhud.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "../scripting.h"
|
|
||||||
#include "../../../frontend/hud.h"
|
|
||||||
|
|
||||||
namespace scripting {
|
|
||||||
extern Hud* hud;
|
|
||||||
}
|
|
||||||
|
|
||||||
int l_hud_open_inventory(lua_State* L) {
|
|
||||||
scripting::hud->openInventory();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int l_hud_close_inventory(lua_State* L) {
|
|
||||||
scripting::hud->closeInventory();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "lua_util.h"
|
#include "lua_util.h"
|
||||||
#include "api/api_lua.h"
|
#include "api_lua.h"
|
||||||
#include "api/libgui.h"
|
#include "libgui.h"
|
||||||
#include "../../util/stringutil.h"
|
#include "../../../util/stringutil.h"
|
||||||
|
|
||||||
lua::luaerror::luaerror(const std::string& message) : std::runtime_error(message) {
|
lua::luaerror::luaerror(const std::string& message) : std::runtime_error(message) {
|
||||||
}
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#include "api_lua.h"
|
#include "api_lua.h"
|
||||||
|
|
||||||
#include "../scripting.h"
|
#include "../scripting.h"
|
||||||
#include "../lua_util.h"
|
#include "lua_util.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../scripting.h"
|
#include "../scripting.h"
|
||||||
#include "../lua_util.h"
|
#include "lua_util.h"
|
||||||
|
|
||||||
#include "../../../engine.h"
|
#include "../../../engine.h"
|
||||||
#include "../../../assets/Assets.h"
|
#include "../../../assets/Assets.h"
|
||||||
65
src/logic/scripting/lua/libhud.cpp
Normal file
65
src/logic/scripting/lua/libhud.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include "libhud.h"
|
||||||
|
#include "LuaState.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "../scripting.h"
|
||||||
|
#include "../../../assets/Assets.h"
|
||||||
|
#include "../../../frontend/hud.h"
|
||||||
|
#include "../../../world/Level.h"
|
||||||
|
#include "../../../voxels/Chunks.h"
|
||||||
|
#include "../../../voxels/voxel.h"
|
||||||
|
#include "../../../voxels/Block.h"
|
||||||
|
#include "../../../content/Content.h"
|
||||||
|
#include "../../../logic/BlocksController.h"
|
||||||
|
#include "../../../items/Inventories.h"
|
||||||
|
#include "../../../engine.h"
|
||||||
|
|
||||||
|
namespace scripting {
|
||||||
|
extern Hud* hud;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_hud_open_inventory(lua_State* L) {
|
||||||
|
scripting::hud->openInventory();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_hud_close_inventory(lua_State* L) {
|
||||||
|
scripting::hud->closeInventory();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_hud_open_block(lua_State* L) {
|
||||||
|
lua::luaint x = lua_tointeger(L, 1);
|
||||||
|
lua::luaint y = lua_tointeger(L, 2);
|
||||||
|
lua::luaint z = lua_tointeger(L, 3);
|
||||||
|
|
||||||
|
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||||
|
if (vox == nullptr) {
|
||||||
|
luaL_error(L, "block does not exists at %d %d %d", x, y, z);
|
||||||
|
}
|
||||||
|
auto def = scripting::content->getIndices()->getBlockDef(vox->id);
|
||||||
|
auto assets = scripting::engine->getAssets();
|
||||||
|
auto layout = assets->getLayout(def->uiLayout);
|
||||||
|
if (layout == nullptr) {
|
||||||
|
luaL_error(L, "block '%s' has no ui layout", def->name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto id = scripting::blocks->createBlockInventory(x, y, z);
|
||||||
|
if (id == 0) {
|
||||||
|
luaL_error(L,
|
||||||
|
"block '%s' at %d %d %d has no inventory",
|
||||||
|
def->name.c_str(),
|
||||||
|
x, y, z
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
scripting::hud->openInventory(
|
||||||
|
glm::ivec3(x, y, z), layout, scripting::level->inventories->get(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
lua_pushinteger(L, id);
|
||||||
|
lua_pushstring(L, def->uiLayout.c_str());
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
@ -5,10 +5,12 @@
|
|||||||
|
|
||||||
extern int l_hud_open_inventory(lua_State* L);
|
extern int l_hud_open_inventory(lua_State* L);
|
||||||
extern int l_hud_close_inventory(lua_State* L);
|
extern int l_hud_close_inventory(lua_State* L);
|
||||||
|
extern int l_hud_open_block(lua_State* L);
|
||||||
|
|
||||||
static const luaL_Reg hudlib [] = {
|
static const luaL_Reg hudlib [] = {
|
||||||
{"open_inventory", l_hud_open_inventory},
|
{"open_inventory", l_hud_open_inventory},
|
||||||
{"close_inventory", l_hud_close_inventory},
|
{"close_inventory", l_hud_close_inventory},
|
||||||
|
{"open_block", l_hud_open_block},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -14,7 +14,7 @@
|
|||||||
#include "../../logic/BlocksController.h"
|
#include "../../logic/BlocksController.h"
|
||||||
#include "../../frontend/UiDocument.h"
|
#include "../../frontend/UiDocument.h"
|
||||||
#include "../../engine.h"
|
#include "../../engine.h"
|
||||||
#include "LuaState.h"
|
#include "lua/LuaState.h"
|
||||||
#include "../../util/stringutil.h"
|
#include "../../util/stringutil.h"
|
||||||
#include "../../util/timeutil.h"
|
#include "../../util/timeutil.h"
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#include "scripting_frontend.h"
|
#include "scripting_frontend.h"
|
||||||
#include "scripting.h"
|
#include "scripting.h"
|
||||||
|
|
||||||
#include "api/libhud.h"
|
#include "lua/libhud.h"
|
||||||
#include "LuaState.h"
|
#include "lua/LuaState.h"
|
||||||
|
|
||||||
namespace scripting {
|
namespace scripting {
|
||||||
extern lua::LuaState* state;
|
extern lua::LuaState* state;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "LuaState.h"
|
#include "lua/LuaState.h"
|
||||||
#include "../../util/stringutil.h"
|
#include "../../util/stringutil.h"
|
||||||
|
|
||||||
namespace scripting {
|
namespace scripting {
|
||||||
|
|||||||
@ -97,6 +97,7 @@ public:
|
|||||||
BlockRotProfile rotations;
|
BlockRotProfile rotations;
|
||||||
std::string pickingItem = name+BLOCK_ITEM_SUFFIX;
|
std::string pickingItem = name+BLOCK_ITEM_SUFFIX;
|
||||||
std::string scriptName = name.substr(name.find(':')+1);
|
std::string scriptName = name.substr(name.find(':')+1);
|
||||||
|
std::string uiLayout = name;
|
||||||
uint inventorySize = 0;
|
uint inventorySize = 0;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#include "../world/World.h"
|
#include "../world/World.h"
|
||||||
#include "../maths/voxmaths.h"
|
#include "../maths/voxmaths.h"
|
||||||
#include "../lighting/Lightmap.h"
|
#include "../lighting/Lightmap.h"
|
||||||
|
#include "../items/Inventories.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
ChunksStorage::ChunksStorage(Level* level) : level(level) {
|
ChunksStorage::ChunksStorage(Level* level) : level(level) {
|
||||||
@ -60,6 +61,9 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
|||||||
auto invs = wfile->fetchInventories(chunk->x, chunk->z);
|
auto invs = wfile->fetchInventories(chunk->x, chunk->z);
|
||||||
chunk->setBlockInventories(std::move(invs));
|
chunk->setBlockInventories(std::move(invs));
|
||||||
chunk->setLoaded(true);
|
chunk->setLoaded(true);
|
||||||
|
for(auto& entry : chunk->inventories) {
|
||||||
|
level->inventories->store(entry.second);
|
||||||
|
}
|
||||||
verifyLoadedChunk(level->content->getIndices(), chunk.get());
|
verifyLoadedChunk(level->content->getIndices(), chunk.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user