Begin Hotwheel, InventoryLists can specify the amt of slots they display
parent
83287cebf1
commit
6add7becb4
|
@ -22,6 +22,8 @@ std::shared_ptr<GuiComponent> GameGuiBuilder::createComponent(LuaGuiElement& ele
|
|||
|
||||
if (!c) return nullptr;
|
||||
|
||||
elem.updateFunction = std::bind(&GameGuiBuilder::elementUpdated, this);
|
||||
|
||||
if (elem.callbacks.count("primary")) c->setCallback(GuiComponent::CallbackType::PRIMARY, [=](bool b, glm::vec2 v) {
|
||||
elem.callbacks.at("primary")(b, LuaParser::luaVec(elem.callbacks.at("primary").lua_state(), {v.x, v.y, 0})); });
|
||||
|
||||
|
|
|
@ -19,32 +19,38 @@ std::shared_ptr<GuiInventoryList> GuiInventoryList::fromSerialized(const LuaGuiE
|
|||
glm::vec4 padding = SerialGui::get<glm::vec4>(elem, "padding", bounds);
|
||||
glm::vec2 slotspc = SerialGui::get<glm::vec2>(elem, "slot_spacing", bounds);
|
||||
|
||||
std::string source = elem.get_or<std::string>("source", "");
|
||||
std::string list = elem.get_or<std::string>("list", "");
|
||||
std::string source = elem.get_or<std::string>("source", "");
|
||||
std::string list = elem.get_or<std::string>("list", "");
|
||||
unsigned short start = static_cast<unsigned short>(elem.get_or<float>("start", 1) - 1);
|
||||
unsigned short length = static_cast<unsigned short>(elem.get_or<float>("length", 0));
|
||||
|
||||
auto invList = refs.getList(source, list);
|
||||
auto inv = std::make_shared<GuiInventoryList>(elem.key);
|
||||
|
||||
inv->create(glm::vec2(SerialGui::SCALE_MODIFIER), padding * SerialGui::SCALE_MODIFIER,
|
||||
slotspc * SerialGui::SCALE_MODIFIER, invList, refs.getHand(), game);
|
||||
slotspc * SerialGui::SCALE_MODIFIER, invList, refs.getHand(), game, start, length);
|
||||
inv->setPos(pos);
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
void GuiInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding,
|
||||
std::shared_ptr<LocalInventoryList> list, std::shared_ptr<LocalInventoryList> hand, ClientGame& defs) {
|
||||
std::shared_ptr<LocalInventoryList> list, std::shared_ptr<LocalInventoryList> hand, ClientGame& defs,
|
||||
unsigned short start, unsigned short length) {
|
||||
|
||||
this->list = list;
|
||||
this->hand = hand;
|
||||
this->defs = &defs;
|
||||
|
||||
this->start = start;
|
||||
this->length = length;
|
||||
|
||||
this->scale = scale;
|
||||
this->padding = padding;
|
||||
this->innerPadding = innerPadding;
|
||||
this->hitbox = (list->getWidth() == 0 ? glm::ivec2 {} : glm::ivec2 {
|
||||
padding.x + list->getWidth() * (innerPadding.x*scale.x),
|
||||
padding.y + (list->getLength() / list->getWidth()) * (innerPadding.y*scale.y)
|
||||
});
|
||||
padding.y + (list->getLength() / list->getWidth()) * (innerPadding.y*scale.y) });
|
||||
|
||||
drawContents();
|
||||
myCallback = std::make_shared<std::function<void()>>(std::bind(&GuiInventoryList::drawContents, this));
|
||||
|
@ -116,6 +122,7 @@ void GuiInventoryList::rightClick(bool down, glm::ivec2 pos) {
|
|||
|
||||
void GuiInventoryList::drawContents() {
|
||||
if (list->getWidth() == 0) return;
|
||||
unsigned short length = this->length == 0 ? list->getLength() : this->length;
|
||||
|
||||
this->hitbox = glm::ivec2 {
|
||||
padding.x + list->getWidth() * (innerPadding.x*scale.x),
|
||||
|
@ -129,12 +136,14 @@ void GuiInventoryList::drawContents() {
|
|||
|
||||
for (unsigned short i = 0; i < list->getLength() / list->getWidth(); i++) {
|
||||
for (unsigned short j = 0; j < list->getWidth(); j++) {
|
||||
unsigned short stackInd = j + i * list->getWidth();
|
||||
if (stackInd >= length) break;
|
||||
// auto bg = std::make_shared<GuiRect>("background_" + to_string(i) + "_" + to_string(j));
|
||||
// bg->create(scale * 16.f, {}, {1, 0, 0, 0.3});
|
||||
// add(bg);
|
||||
// bg->setPos({padding.x + j * (16*scale.x+innerPadding.x/scale.x), padding.y + i * (16*scale.y+innerPadding.y/scale.y)});
|
||||
|
||||
auto stack = list->getStack(j + i * list->getWidth());
|
||||
auto stack = list->getStack(stackInd);
|
||||
if (stack.id == 0) continue;
|
||||
|
||||
auto item = std::make_shared<GuiInventoryItem>("item_" + std::to_string(i) + "_" + std::to_string(j));
|
||||
|
|
|
@ -23,7 +23,8 @@ public:
|
|||
glm::ivec2 bounds, LocalInventoryRefs& refs);
|
||||
|
||||
void create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding,
|
||||
std::shared_ptr<LocalInventoryList> list, std::shared_ptr<LocalInventoryList> hand, ClientGame& defs);
|
||||
std::shared_ptr<LocalInventoryList> list, std::shared_ptr<LocalInventoryList> hand, ClientGame& defs,
|
||||
unsigned short start = 0, unsigned short length = 0);
|
||||
|
||||
void setCallback(CallbackType type, const callback& cb) override;
|
||||
|
||||
|
@ -36,6 +37,7 @@ private:
|
|||
std::shared_ptr<std::function<void()>> myCallback = nullptr;
|
||||
|
||||
std::shared_ptr<LocalInventoryList> list, hand;
|
||||
unsigned short start, length;
|
||||
glm::ivec2 innerPadding;
|
||||
ClientGame* defs = nullptr;
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Created by aurailus on 2020-04-12.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
#include "LuaGuiElement.h"
|
||||
|
@ -82,9 +83,8 @@ void LuaGuiElement::append(sol::this_state s, sol::object elem) {
|
|||
else if (elem.is<sol::function>()) children.push_back(call(s, elem.as<sol::function>()).as<std::shared_ptr<LuaGuiElement>>());
|
||||
else throw std::runtime_error("Append arg is not an element or a function to generate one.");
|
||||
|
||||
if (updateFunction) updateFunction();
|
||||
children.back()->updateFunction = updateFunction;
|
||||
children.back()->parent = this;
|
||||
if (updateFunction) updateFunction();
|
||||
}
|
||||
|
||||
void LuaGuiElement::prepend(sol::this_state s, sol::object elem) {
|
||||
|
@ -92,9 +92,8 @@ void LuaGuiElement::prepend(sol::this_state s, sol::object elem) {
|
|||
else if (elem.is<sol::function>()) children.insert(children.begin(), call(s, elem.as<sol::function>()).as<std::shared_ptr<LuaGuiElement>>());
|
||||
else throw std::runtime_error("Append arg is not an element or a function to generate one.");
|
||||
|
||||
if (updateFunction) updateFunction();
|
||||
children.front()->updateFunction = updateFunction;
|
||||
children.front()->parent = this;
|
||||
if (updateFunction) updateFunction();
|
||||
}
|
||||
|
||||
void LuaGuiElement::remove(sol::this_state s, sol::object elem) {
|
||||
|
@ -127,7 +126,8 @@ Any LuaGuiElement::getAsAny(const std::string &key) const noexcept {
|
|||
if (!traits.count(key)) return Any();
|
||||
auto object = traits.at(key);
|
||||
|
||||
if (object.is<std::string>()) return Any::from<std::string>(object.as<std::string>());
|
||||
if (object.is<float>()) return Any::from<float>(object.as<float>());
|
||||
else if (object.is<std::string>()) return Any::from<std::string>(object.as<std::string>());
|
||||
else if (object.is<sol::table>()) {
|
||||
auto table = object.as<sol::table>();
|
||||
|
||||
|
|
|
@ -1,35 +1,2 @@
|
|||
if zepha.server then return end
|
||||
|
||||
local hud = zepha.player:get_hud()
|
||||
hud:append(function() return Gui.Rect {
|
||||
key = "hot_wheel_root",
|
||||
|
||||
size = { 139, 70 },
|
||||
position = { "0%", "100%" },
|
||||
position_anchor = { "-10%", "110%" },
|
||||
-- background = "#966"
|
||||
} end)
|
||||
local root = hud:get("hot_wheel_root")
|
||||
|
||||
root(function(e)
|
||||
|
||||
e:append(Gui.Rect {
|
||||
size = { 68, 68 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_circle",
|
||||
|
||||
Gui.InventoryList {
|
||||
position = { 7, 1 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "main",
|
||||
}
|
||||
})
|
||||
|
||||
e:append(Gui.Rect {
|
||||
size = { 84, 18 },
|
||||
position = { 47, 13 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_line",
|
||||
})
|
||||
|
||||
end)
|
||||
runfile(_PATH .. "register")
|
||||
runfile(_PATH .. "menu")
|
|
@ -0,0 +1,117 @@
|
|||
if zepha.server then return end
|
||||
|
||||
local hud = zepha.player:get_hud()
|
||||
hud:append(function() return Gui.Rect {
|
||||
key = "hot_wheel_root",
|
||||
|
||||
size = { 140, 80 },
|
||||
position = { "0%", "100%" },
|
||||
position_anchor = { "-10%", "110%" },
|
||||
-- background = "#966"
|
||||
} end)
|
||||
local root = hud:get("hot_wheel_root")
|
||||
|
||||
root(function(e)
|
||||
e:append(Gui.Rect {
|
||||
size = { 80, 80 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_circle",
|
||||
|
||||
Gui.Rect {
|
||||
key = "numbers",
|
||||
size = { 80, 80 },
|
||||
background = "@aurailus:hot_wheel:circle_numbers_1"
|
||||
},
|
||||
|
||||
Gui.InventoryList {
|
||||
key = "list_1",
|
||||
position = { 12, 22 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_1",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_2",
|
||||
position = { 32, 11 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_2",
|
||||
},
|
||||
-- Gui.InventoryList {
|
||||
-- position = { 6, 16 },
|
||||
-- slot_spacing = { 2, 2 },
|
||||
-- length = 1,
|
||||
-- source = "current_player",
|
||||
-- list = "hot_wheel_3",
|
||||
-- },
|
||||
Gui.InventoryList {
|
||||
key = "list_4",
|
||||
position = { 52, 43 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_4",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_5",
|
||||
position = { 32, 54 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_5",
|
||||
},
|
||||
Gui.InventoryList {
|
||||
key = "list_6",
|
||||
position = { 12, 43 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_6",
|
||||
},
|
||||
})
|
||||
|
||||
e:append(Gui.Rect {
|
||||
size = { 100, 18 },
|
||||
position = { 52, 19 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_line",
|
||||
|
||||
Gui.InventoryList {
|
||||
key = "list_3",
|
||||
position = { 3, 1 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 6,
|
||||
source = "current_player",
|
||||
list = "hot_wheel_3",
|
||||
}
|
||||
})
|
||||
end)
|
||||
|
||||
local lists = {
|
||||
root:get("list_1"),
|
||||
root:get("list_2"),
|
||||
root:get("list_3"),
|
||||
root:get("list_4"),
|
||||
root:get("list_5"),
|
||||
root:get("list_6")
|
||||
}
|
||||
|
||||
local offset = 0
|
||||
local function select(n)
|
||||
offset = n - 1
|
||||
|
||||
for i,list in ipairs(lists) do
|
||||
list.list = "hot_wheel_" .. tostring((i + offset - 1) % 6 + 1)
|
||||
end
|
||||
|
||||
root:get("numbers").background = "@aurailus:hot_wheel:circle_numbers_" .. (offset + 1)
|
||||
zepha.player:set_selected_block(zepha.player:get_inventory():get_list("hot_wheel_" .. ((offset + 2) % 6 + 1)):get_stack(1).name)
|
||||
end
|
||||
|
||||
for i = 1, 6 do
|
||||
zepha.register_keybind("@aurailus:hot_wheel:select_slot_" .. i, {
|
||||
description = "Select Slot " .. i,
|
||||
default = zepha.keys[tostring(i)],
|
||||
on_press = function() select(i) end
|
||||
})
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
if zepha.client then return end
|
||||
|
||||
zepha.register_on("new_player", function(p)
|
||||
local inv = p:get_inventory()
|
||||
inv:add_list("hot_wheel_1", 5, 5)
|
||||
inv:add_list("hot_wheel_2", 5, 5)
|
||||
inv:add_list("hot_wheel_3", 5, 5)
|
||||
inv:add_list("hot_wheel_4", 5, 5)
|
||||
inv:add_list("hot_wheel_5", 5, 5)
|
||||
inv:add_list("hot_wheel_6", 5, 5)
|
||||
end)
|
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 416 B After Width: | Height: | Size: 444 B |
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB |
|
@ -4,19 +4,19 @@ zepha.register_entity("zeus:default:test", {
|
|||
display_texture = "zeus:default:player",
|
||||
|
||||
on_create = fn(self) {
|
||||
## self.object.anims:define({
|
||||
## walk = {0, 300}
|
||||
## })
|
||||
## self.object.anims:set_anim("walk"):play()
|
||||
## self.object.scale = 1/4
|
||||
self.object.anims:define({
|
||||
walk = {0, 300}
|
||||
})
|
||||
self.object.anims:set_anim("walk"):play()
|
||||
self.object.scale = 1/4
|
||||
},
|
||||
on_update = fn(self, delta) {
|
||||
self.object.pos = self.object.pos +
|
||||
V(0.6 * math.sin(math.rad(self.object.yaw)), 0, 0.6 * math.cos(math.rad(self.object.yaw))) * delta
|
||||
self.object.yaw += 50 * delta
|
||||
## self.object.pos = self.object.pos +
|
||||
## V(0.6 * math.sin(math.rad(self.object.yaw)), 0, 0.6 * math.cos(math.rad(self.object.yaw))) * delta
|
||||
## self.object.yaw += 50 * delta
|
||||
}
|
||||
})
|
||||
|
||||
##if (zepha.server) {
|
||||
## local entity = zepha.add_entity("zeus:default:test", V(0, 0, 0))
|
||||
##}
|
||||
if (zepha.client) {
|
||||
local entity = zepha.add_entity("zeus:default:test", V(0, 0, 0))
|
||||
}
|
|
@ -1,30 +1,6 @@
|
|||
runfile(_PATH .. "blocks/_index")
|
||||
runfile(_PATH .. "entity/_index")
|
||||
|
||||
local blockTypes = {
|
||||
"@aurailus:tnt:tnt",
|
||||
"@aurailus:basictools:flint_pickaxe",
|
||||
"zeus:default:grass_slab",
|
||||
"zeus:kinetic:axle_0",
|
||||
"zeus:default:stone",
|
||||
"zeus:default:wood",
|
||||
"zeus:default:cobblestone",
|
||||
"zeus:default:dirt",
|
||||
"zeus:default:grass",
|
||||
"zeus:default:leaves",
|
||||
"zeus:default:tallgrass_5"
|
||||
}
|
||||
|
||||
local i = 0;
|
||||
foreach block in blockTypes {
|
||||
zepha.register_keybind("zeus:default:block_" .. i, {
|
||||
description = "Select Block " .. i,
|
||||
default = zepha.keys[tostring(i)],
|
||||
on_press = () => { zepha.player:set_selected_block(block) }
|
||||
});
|
||||
i++;
|
||||
}
|
||||
|
||||
local chat_down = false
|
||||
zepha.register_keybind("zeus:default:open_chat", {
|
||||
description = "Open Chat",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name": "zeus:inventory",
|
||||
"description": "Inventory mod for the Zeus subgame.",
|
||||
"version": "0.0.1"
|
||||
"version": "0.0.1",
|
||||
"depends": [ "@aurailus:hot_wheel" ]
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ zepha.register_on("new_player", (p) => {
|
|||
|
||||
crafting.bind(craft_input, craft_output)
|
||||
|
||||
## Make hot wheel
|
||||
## Get hot wheel
|
||||
local invs = {
|
||||
inv:add_list("hot_wheel_1", 5, 5),
|
||||
inv:add_list("hot_wheel_2", 5, 5),
|
||||
inv:add_list("hot_wheel_3", 5, 5),
|
||||
inv:add_list("hot_wheel_4", 5, 5),
|
||||
inv:add_list("hot_wheel_5", 5, 5),
|
||||
inv:add_list("hot_wheel_6", 5, 5)
|
||||
inv:get_list("hot_wheel_1"),
|
||||
inv:get_list("hot_wheel_2"),
|
||||
inv:get_list("hot_wheel_3"),
|
||||
inv:get_list("hot_wheel_4"),
|
||||
inv:get_list("hot_wheel_5"),
|
||||
inv:get_list("hot_wheel_6")
|
||||
}
|
||||
|
||||
foreach inv in invs {
|
||||
|
|
Loading…
Reference in New Issue