Add some debug GUI back, fix CLion folder configuration.

master
Auri 2021-08-29 20:38:22 -07:00
parent 2cf3e7aaea
commit 921649b17b
32 changed files with 593 additions and 612 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
cmake-build-debug cmake-build-debug
cmake-build-install cmake-build-install
cmake-build-release cmake-build-release
cmake-build-minsizerel
cmake-build-relwithdebinfo
.hidden .hidden
.vscode .vscode

View File

@ -1,3 +0,0 @@
cmake-build-debug
cmake-build-install
cmake-build-release

View File

@ -7,17 +7,18 @@
<file path="$PROJECT_DIR$/test" /> <file path="$PROJECT_DIR$/test" />
</sourceRoots> </sourceRoots>
<libraryRoots> <libraryRoots>
<file path="$PROJECT_DIR$/cmake-build-debug" /> <file path="$PROJECT_DIR$/lib" />
<file path="$PROJECT_DIR$/cmake-build-release" />
</libraryRoots> </libraryRoots>
<excludeRoots> <excludeRoots>
<file path="$PROJECT_DIR$/.github" />
<file path="$PROJECT_DIR$/.idea" /> <file path="$PROJECT_DIR$/.idea" />
<file path="$PROJECT_DIR$/Libraries" /> <file path="$PROJECT_DIR$/.vscode" />
<file path="$PROJECT_DIR$/cmake-build-install" /> <file path="$PROJECT_DIR$/.github" />
<file path="$PROJECT_DIR$/lib" />
<file path="$PROJECT_DIR$/worlds" /> <file path="$PROJECT_DIR$/worlds" />
<file path="$PROJECT_DIR$/worlds/world" /> <file path="$PROJECT_DIR$/cmake-build-debug" />
<file path="$PROJECT_DIR$/cmake-build-install" />
<file path="$PROJECT_DIR$/cmake-build-release" />
<file path="$PROJECT_DIR$/cmake-build-minsizerel" />
<file path="$PROJECT_DIR$/cmake-build-relwithdebinfo" />
</excludeRoots> </excludeRoots>
</component> </component>
<component name="GCoverageShowInEditor"> <component name="GCoverageShowInEditor">

View File

@ -2,5 +2,35 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/build/_deps/corrade-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/build/_deps/glfw-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/build/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/build/_deps/imnodes-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/build/_deps/magnum-integration-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/build/_deps/magnum-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/corrade-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/glfw-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/imnodes-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/magnum-integration-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/magnum-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-minsizerel/_deps/corrade-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-minsizerel/_deps/glfw-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-minsizerel/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-minsizerel/_deps/imnodes-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-minsizerel/_deps/magnum-integration-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-minsizerel/_deps/magnum-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/corrade-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/glfw-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/imnodes-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/magnum-integration-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/magnum-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/corrade-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/glfw-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/imnodes-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/magnum-integration-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/magnum-src" vcs="Git" />
</component> </component>
</project> </project>

View File

@ -1,4 +1,4 @@
(c) 2018-2019 Nicole Collings, All rights reserved. (c) 2018-2021 Auri Collings, All rights reserved.
You do not have permission to redistribute, copy, or share this work without my explicit written permission. You do not have permission to redistribute, copy, or share this work without my explicit written permission.
You may download the repository and compile it for personal use or potential contributions. You may download the repository and compile it for personal use or potential contributions.

View File

@ -70,8 +70,8 @@ add_library(Zepha_Core
client/gui/compound/GuiInventoryList.h client/gui/compound/GuiInventoryList.h
client/gui/compound/GuiLabelledGraph.cpp client/gui/compound/GuiLabelledGraph.cpp
client/gui/compound/GuiLabelledGraph.cpp client/gui/compound/GuiLabelledGraph.cpp
client/gui/DebugGui.cpp client/gui/DebugDisplay.cpp
client/gui/DebugGui.h client/gui/DebugDisplay.h
client/gui/GameGui.cpp client/gui/GameGui.cpp
client/gui/GameGui.h client/gui/GameGui.h
client/gui/Element.cpp client/gui/Element.cpp
@ -146,8 +146,6 @@ add_library(Zepha_Core
lua/ErrorFormatter.h lua/ErrorFormatter.h
lua/LocalLuaParser.cpp lua/LocalLuaParser.cpp
lua/LocalLuaParser.h lua/LocalLuaParser.h
lua/LocalModHandler.cpp
lua/LocalModHandler.h
lua/LuaKeybindHandler.cpp lua/LuaKeybindHandler.cpp
lua/LuaKeybindHandler.h lua/LuaKeybindHandler.h
lua/LuaMod.cpp lua/LuaMod.cpp

View File

@ -51,7 +51,7 @@ Renderer::Renderer(glm::ivec2 win) :
})); }));
//VSync 1 = On, 0 = Off //VSync 1 = On, 0 = Off
glfwSwapInterval(1); // glfwSwapInterval(1);
} }
void Renderer::update(double delta) { void Renderer::update(double delta) {

View File

@ -48,10 +48,10 @@ void Gui::BoxElement::updateElement() {
entity.setModel(model); entity.setModel(model);
} }
let margin = getStyle<ivec4, Type::LENGTH>(Prop::MARGIN, {}); let margin = getStyle<vec4, Type::LENGTH>(Prop::MARGIN, {});
entity.setScale(vec3(getComputedSize(), 0)); entity.setScale(ivec3(getComputedSize(), 0));
entity.setPos(vec3(getComputedScreenPos() + ivec2 { margin.x, margin.y }, 0)); entity.setPos(ivec3(getComputedScreenPos() + vec2 { margin.x, margin.y }, 0));
Element::updateElement(); Element::updateElement();
} }

View File

@ -0,0 +1,221 @@
#include "DebugDisplay.h"
#include "world/LocalWorld.h"
#include "game/def/BiomeDef.h"
#include "game/def/BlockDef.h"
#include "world/dim/chunk/Chunk.h"
#include "client/gui/BoxElement.h"
#include "client/gui/TextElement.h"
#include "world/player/LocalPlayer.h"
//#include "client/gui/compound/GuiPerfGraph.h"
//#include "client/gui/compound/GuiCellGraph.h"
//#include "client/gui/compound/GuiLabelledGraph.h"
DebugDisplay::DebugDisplay(sptr<Gui::Element> root, SubgamePtr game, LocalWorld& world, vec<string>& perfSections) :
root(root), game(game), world(world) {
using Expr = Gui::Expression;
crosshair = root->append<Gui::TextElement>({{
{ Gui::Prop::TEXT_SIZE, Expr("2px") },
{ Gui::Prop::POS, array<Expr, 2> { Expr("50cw + 8dp"), Expr("50ch - 3.333dp") } },
{ Gui::Prop::BACKGROUND, vec4 { 0.2, 0.2, 0.2, 0.3 } }
}});
data = root->append<Gui::TextElement>({{
{ Gui::Prop::TEXT_SIZE, Expr("2px") },
{ Gui::Prop::POS, array<Expr, 2> { Expr("4dp"), Expr("4dp") } },
{ Gui::Prop::BACKGROUND, vec4 { 0.2, 0.2, 0.2, 0.3 } }
}});
// auto interpGraph = make_shared<GuiLabelledGraph>(window, "interpGraph");
// interpGraph->create({ 244, 64 }, {}, "Interp", 120, 256, genericHistogramRef, f);
// add(interpGraph);
//
// auto meshGraph = make_shared<GuiLabelledGraph>(window, "meshGraph");
// meshGraph->create({ 244, 64 }, {}, "Mesh", 120, 32, genericHistogramRef, f);
// add(meshGraph);
//
// auto genGraph = make_shared<GuiLabelledGraph>(window, "genGraph");
// genGraph->create({ 244, 64 }, {}, "Gen", 120, 16, genericHistogramRef, f);
// add(genGraph);
//
// auto packetGraph = make_shared<GuiLabelledGraph>(window, "packetGraph");
// packetGraph->create({ 244, 64 }, {}, "Packets", 120, 32, genericHistogramRef, f);
// add(packetGraph);
//
// auto fpsGraph = make_shared<GuiLabelledGraph>(window, "fpsGraph");
// fpsGraph->create({ 244, 64 }, {}, "FPS", 120, 60, fpsHistogramRef, f);
// add(fpsGraph);
//
// auto drawsGraph = make_shared<GuiLabelledGraph>(window, "drawsGraph");
// drawsGraph->create({ 244, 64 }, {}, "Draw Calls", 120, 0, genericHistogramRef, f);
// add(drawsGraph);
//
// auto gpuGraph = make_shared<GuiLabelledGraph>(window, "gpuGraph");
// gpuGraph->create({ 244, 64 }, {}, "GPU", 120, 1, genericHistogramRef, f);
// add(gpuGraph);
//
// auto perfGraph = make_shared<GuiPerfGraph>(window, "perfGraph");
// perfGraph->create(344, {}, perfSections, "Performance", f);
// add(perfGraph);
//
// auto chunkStates = make_shared<GuiCellGraph>(window, "chunkStates");
// chunkStates->create(12, vec4(4), MAPBLOCK_RANGE, "Mapblocks", f);
// chunkStates->refresh();
// add(chunkStates);
}
//void DebugGui::positionElements(u16vec2 buffer) {
// get<GuiText>("crosshairText")->setPos({ buffer.x / 2 + 22, buffer.y / 2 - 7 });
// get<GuiText>("dataText")->setPos({ 10, 10 });
//
// get<GuiLabelledGraph>("genGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 160 });
// get<GuiLabelledGraph>("packetGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 240 });
// get<GuiLabelledGraph>("meshGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 80 });
// get<GuiLabelledGraph>("interpGraph")->setPos({ buffer.x - 254, buffer.y - 70 });
//
// get<GuiLabelledGraph>("fpsGraph")->setPos({ buffer.x - 254, 10 });
// get<GuiLabelledGraph>("drawsGraph")->setPos({ buffer.x - 254, 90 });
// get<GuiLabelledGraph>("gpuGraph")->setPos({ buffer.x - 254, 90 + 80 });
// get<GuiLabelledGraph>("perfGraph")->setPos({ buffer.x - 354 - 254, 10 });
//
// get<GuiLabelledGraph>("chunkStates")->setPos({ buffer.x - 264 - 144, buffer.y - 178 });
//}
void DebugDisplay::update(sptr<LocalPlayer> player, f64 delta, u32 interpolatedChunks, u32 generatedChunks,
u32 recievedPackets, vec<usize>& perfTimings, u32 drawnMeshChunks, u32 generatedMeshChunks) {
Target target = player->getTarget();
auto& onBiomeDef = game->getBiomes().biomeFromId(
world.getActiveDimension()->getBiome(glm::floor(player->getPos())));
// // FPS and Draw calls graphs
//
// get<GuiPerfGraph>("perfGraph")->updateTimings(perfTimings);
// get<GuiLabelledGraph>("fpsGraph")->pushValue(1 / delta);
// get<GuiLabelledGraph>("drawsGraph")->pushValue(drawnMeshChunks);
//
// int videoMemAvail, videoMemTotal;
//
// glGetIntegerv(0x9048, &videoMemTotal);
// glGetIntegerv(0x9049, &videoMemAvail);
//
// get<GuiLabelledGraph>("gpuGraph")->pushValue(std::round(
// (videoMemTotal - videoMemAvail) / static_cast<f32>(videoMemTotal) * 100.0) / 100.0f);
//
//
// // Thread information graphs
//
// get<GuiLabelledGraph>("meshGraph")->pushValue(generatedMeshChunks);
// get<GuiLabelledGraph>("interpGraph")->pushValue(interpolatedChunks);
// get<GuiLabelledGraph>("genGraph")->pushValue(generatedChunks);
// get<GuiLabelledGraph>("packetGraph")->pushValue(recievedPackets);
// Textual information
vec3 playerPos = glm::floor(player->getPos());
vec3 chunkPos = Space::Chunk::world::fromBlock(playerPos);
vec3 mapBlockPos = Space::MapBlock::world::fromChunk(chunkPos);
vec3 regionPos = Space::Region::world::fromChunk(chunkPos);
vec3 posOffsetFromChunk = Space::Block::relative::toChunk(playerPos);
vec3 posOffsetFromBlock = Space::Block::relative::toMapBlock(playerPos);
vec3 posOffsetFromRegion = Space::Block::relative::toRegion(playerPos);
std::ostringstream str;
str << "Dimension: " << world.getActiveDimension()->getIdentifier()
<< " [" << world.getActiveDimension()->getInd() << "]" << std::endl << std::endl
<< "Pos: " << playerPos << " (" << player->getPos() << ")" << std::endl
<< "Vel: " << player->getVel() << std::endl
<< "Yaw: " << player->getYaw() << ", "
<< "Pitch: " << player->getPitch() << std::endl << std::endl
<< "C: " << posOffsetFromChunk << " [" << chunkPos << "]" << std::endl
<< "M: " << posOffsetFromBlock << " [" << mapBlockPos << "]" << std::endl
<< "R: " << posOffsetFromRegion << " [" << regionPos << "]" << std::endl
<< std::endl
<< "Texture Slots: " << game.l()->textures.textureSlotsUsed << " / " << game.l()->textures.maxTextureSlots
<< " ("
<< round(game.l()->textures.textureSlotsUsed / static_cast<float>(game.l()->textures.maxTextureSlots) * 100)
<< "%)" << std::endl << std::endl
<< "Biome: " << onBiomeDef.identifier << " [" << onBiomeDef.index << "]" << std::endl << std::endl;
if (target.type == Target::Type::BLOCK) {
string face =
target.data.block.face == EVec::TOP ? "Top" :
target.data.block.face == EVec::BOTTOM ? "Bottom" :
target.data.block.face == EVec::LEFT ? "Left" :
target.data.block.face == EVec::RIGHT ? "Right" :
target.data.block.face == EVec::FRONT ? "Front" :
target.data.block.face == EVec::BACK ? "Back" :
"None (!)";
const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos));
str << "Pointing At: " << def.identifier << " [" << def.index << "]" << std::endl
<< "Pointed Position: " << target.data.block.pos << std::endl
<< "Pointed Face: " << face << std::endl;
}
else if (target.type == Target::Type::ENTITY) {
const auto& entity = **world.getActiveDimension().l()->getEntityById(target.data.entity.id).entity;
str << "Pointing At: " << (target.data.entity.id < 0 ? "Local" : "Server")
<< " Entity #" << std::fabs(target.data.entity.id) << std::endl
<< "Pointed Position: " << entity.getPos() << std::endl << std::endl;
}
else {
str << "No Target" << std::endl << std::endl;
}
data->setProp(Gui::Prop::CONTENT, str.str());
// // Chunk States
//
// auto chunkStates = get<GuiCellGraph>("chunkStates");
// ivec3 off = { 0, 0, 0 };
// for (off.x = 0; off.x < MAPBLOCK_RANGE; off.x++) {
// if ((off.x - mapBlockScanX) % MAPBLOCK_SCAN_X_INTERVAL != 0) continue;
//
// for (off.z = 0; off.z < MAPBLOCK_RANGE; off.z++) {
// f32 existAmount = 0;
// ivec3 check = ivec3(mapBlockPos) + off -
// ivec3(MAPBLOCK_RANGE / 2, 0, MAPBLOCK_RANGE / 2);
//
// for (off.y = 0; off.y < MAPBLOCK_VERT; off.y++) {
// check.y = static_cast<i32>(mapBlockPos.y) + off.y - MAPBLOCK_VERT / 2;
// const auto mapBlock = world.getActiveDimension()->getMapBlock(check);
// if (mapBlock) existAmount++;
// }
//
// const auto color =
// (off.x == MAPBLOCK_RANGE / 2 && off.z == MAPBLOCK_RANGE / 2) ? MAPBLOCK_CURRENT
// : glm::mix(MAPBLOCK_UNLOADED, MAPBLOCK_LOADED, existAmount / MAPBLOCK_VERT);
// chunkStates->setCellColor(u16vec2(off.x, off.z), color);
// }
// }
// chunkStates->refresh();
//
// mapBlockScanX = (mapBlockScanX + 1) % MAPBLOCK_SCAN_X_INTERVAL;
if (target.type == Target::Type::BLOCK) {
const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos));
crosshair->setProp(Gui::Prop::CONTENT, "`b" + def.name + " (`r` `c1" +
def.identifier + "`cr - " + std::to_string(def.index) + "` `b)");
}
else {
crosshair->setProp(Gui::Prop::CONTENT, string(""));
}
root->updateElement();
}
//void DebugDisplay::changeVisibility(Visibility state) {
//// setVisible(state == Visibility::ON);
//// get<GuiLabelledGraph>("fpsGraph")->setVisible(state != Visibility::OFF);
//}

View File

@ -0,0 +1,52 @@
#pragma once
#include "util/Types.h"
//#include "client/Window.h"
#include "util/CovariantPtr.h"
class Window;
class LocalWorld;
class LocalPlayer;
class LocalSubgame;
namespace Gui {
class Element;
class BoxElement;
class TextElement;
};
/**
* Renders debug information, in the form of graphs and text.
* Can be enabled, disabled, or displayed with FPS only.
*/
class DebugDisplay {
public:
enum class Visibility { OFF, FPS_ONLY, ON };
DebugDisplay(sptr<Gui::Element> root, SubgamePtr game, LocalWorld& world, vec<string>& perfSections);
/** Updates the debug screen with the latest data. */
void update(sptr<LocalPlayer> player, f64 delta, u32 interpolatedChunks, u32 generatedChunks,
u32 recievedPackets, vec<usize>& perfTimings, u32 drawnMeshChunks, u32 generatedMeshChunks);
private:
constexpr static vec4 MAPBLOCK_UNLOADED = { 1, 1, 1, 0.15 };
constexpr static vec4 MAPBLOCK_LOADED = { 1, 1, 1, 0.75 };
constexpr static vec4 MAPBLOCK_CURRENT = { 1, 0.93, 0.35, 1 };
constexpr static i32 MAPBLOCK_VERT = 3;
constexpr static i32 MAPBLOCK_RANGE = 11;
u32 mapBlockScanX = 0;
constexpr static u32 MAPBLOCK_SCAN_X_INTERVAL = 9;
SubgamePtr game;
LocalWorld& world;
sptr<Gui::Element> root;
sptr<Gui::TextElement> crosshair, data;
Visibility state = Visibility::ON;
};

View File

@ -1,226 +0,0 @@
//#include <client/gui/compound/GuiPerfGraph.h>
//#include <client/gui/compound/GuiCellGraph.h>
//#include "DebugGui.h"
//
//#include "world/LocalWorld.h"
//#include "game/def/BiomeDef.h"
//#include "game/def/BlockDef.h"
//#include "client/graph/Font.h"
//#include "world/dim/chunk/Chunk.h"
//#include "client/gui/basic/GuiText.h"
//#include "world/player/LocalPlayer.h"
//#include "client/gui/compound/GuiLabelledGraph.h"
//
//DebugGui::DebugGui(Window& window, SubgamePtr game, LocalWorld& world, vec<string>& perfSections) :
// game(game), world(world) {
//
// auto fontRef = game.l()->textures["font"];
// auto fpsHistogramRef = game.l()->textures["histogram"];
// auto genericHistogramRef = game.l()->textures["histogram_white"];
//
// Font f(game.l()->textures, fontRef);
//
// auto crosshairText = make_shared<GuiText>(window, "crosshairText");
// crosshairText->create({ 2, 2 }, {}, { 1, 1, 1, 1 }, { 0.2, 0.2, 0.2, 0.5 }, f);
// add(crosshairText);
//
// auto dataText = make_shared<GuiText>(window, "dataText");
// dataText->create({ 2, 2 }, {}, { 1, 1, 1, 1 }, { 0.2, 0.2, 0.2, 0.5 }, f);
// add(dataText);
//
// auto interpGraph = make_shared<GuiLabelledGraph>(window, "interpGraph");
// interpGraph->create({ 244, 64 }, {}, "Interp", 120, 256, genericHistogramRef, f);
// add(interpGraph);
//
// auto meshGraph = make_shared<GuiLabelledGraph>(window, "meshGraph");
// meshGraph->create({ 244, 64 }, {}, "Mesh", 120, 32, genericHistogramRef, f);
// add(meshGraph);
//
// auto genGraph = make_shared<GuiLabelledGraph>(window, "genGraph");
// genGraph->create({ 244, 64 }, {}, "Gen", 120, 16, genericHistogramRef, f);
// add(genGraph);
//
// auto packetGraph = make_shared<GuiLabelledGraph>(window, "packetGraph");
// packetGraph->create({ 244, 64 }, {}, "Packets", 120, 32, genericHistogramRef, f);
// add(packetGraph);
//
// auto fpsGraph = make_shared<GuiLabelledGraph>(window, "fpsGraph");
// fpsGraph->create({ 244, 64 }, {}, "FPS", 120, 60, fpsHistogramRef, f);
// add(fpsGraph);
//
// auto drawsGraph = make_shared<GuiLabelledGraph>(window, "drawsGraph");
// drawsGraph->create({ 244, 64 }, {}, "Draw Calls", 120, 0, genericHistogramRef, f);
// add(drawsGraph);
//
// auto gpuGraph = make_shared<GuiLabelledGraph>(window, "gpuGraph");
// gpuGraph->create({ 244, 64 }, {}, "GPU", 120, 1, genericHistogramRef, f);
// add(gpuGraph);
//
// auto perfGraph = make_shared<GuiPerfGraph>(window, "perfGraph");
// perfGraph->create(344, {}, perfSections, "Performance", f);
// add(perfGraph);
//
// auto chunkStates = make_shared<GuiCellGraph>(window, "chunkStates");
// chunkStates->create(12, vec4(4), MAPBLOCK_RANGE, "Mapblocks", f);
// chunkStates->refresh();
// add(chunkStates);
//
// positionElements(window.getSize());
//}
//
//void DebugGui::positionElements(u16vec2 buffer) {
// get<GuiText>("crosshairText")->setPos({ buffer.x / 2 + 22, buffer.y / 2 - 7 });
// get<GuiText>("dataText")->setPos({ 10, 10 });
//
// get<GuiLabelledGraph>("genGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 160 });
// get<GuiLabelledGraph>("packetGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 240 });
// get<GuiLabelledGraph>("meshGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 80 });
// get<GuiLabelledGraph>("interpGraph")->setPos({ buffer.x - 254, buffer.y - 70 });
//
// get<GuiLabelledGraph>("fpsGraph")->setPos({ buffer.x - 254, 10 });
// get<GuiLabelledGraph>("drawsGraph")->setPos({ buffer.x - 254, 90 });
// get<GuiLabelledGraph>("gpuGraph")->setPos({ buffer.x - 254, 90 + 80 });
// get<GuiLabelledGraph>("perfGraph")->setPos({ buffer.x - 354 - 254, 10 });
//
// get<GuiLabelledGraph>("chunkStates")->setPos({ buffer.x - 264 - 144, buffer.y - 178 });
//}
//
//void DebugGui::update(sptr<LocalPlayer> player, f64 delta, u32 interpolatedChunks, u32 generatedChunks,
// u32 recievedPackets, vec<usize>& perfTimings, u32 drawnMeshChunks, u32 generatedMeshChunks) {
//
// Target target = player->getTarget();
//
// auto& onBiomeDef = game->getBiomes().biomeFromId(
// world.getActiveDimension()->getBiome(glm::floor(player->getPos())));
//
// // FPS and Draw calls graphs
//
// get<GuiPerfGraph>("perfGraph")->updateTimings(perfTimings);
// get<GuiLabelledGraph>("fpsGraph")->pushValue(1 / delta);
// get<GuiLabelledGraph>("drawsGraph")->pushValue(drawnMeshChunks);
//
// int videoMemAvail, videoMemTotal;
//
// glGetIntegerv(0x9048, &videoMemTotal);
// glGetIntegerv(0x9049, &videoMemAvail);
//
// get<GuiLabelledGraph>("gpuGraph")->pushValue(std::round(
// (videoMemTotal - videoMemAvail) / static_cast<f32>(videoMemTotal) * 100.0) / 100.0f);
//
//
// // Thread information graphs
//
// get<GuiLabelledGraph>("meshGraph")->pushValue(generatedMeshChunks);
// get<GuiLabelledGraph>("interpGraph")->pushValue(interpolatedChunks);
// get<GuiLabelledGraph>("genGraph")->pushValue(generatedChunks);
// get<GuiLabelledGraph>("packetGraph")->pushValue(recievedPackets);
//
// // Textual information
//
// vec3 playerPos = glm::floor(player->getPos());
// vec3 chunkPos = Space::Chunk::world::fromBlock(playerPos);
// vec3 mapBlockPos = Space::MapBlock::world::fromChunk(chunkPos);
// vec3 regionPos = Space::Region::world::fromChunk(chunkPos);
//
// vec3 posOffsetFromChunk = Space::Block::relative::toChunk(playerPos);
// vec3 posOffsetFromBlock = Space::Block::relative::toMapBlock(playerPos);
// vec3 posOffsetFromRegion = Space::Block::relative::toRegion(playerPos);
//
// std::ostringstream str;
//
// str << "Dimension: " << world.getActiveDimension()->getIdentifier()
// << " [" << world.getActiveDimension()->getInd() << "]" << std::endl << std::endl
//
// << "Pos: " << playerPos << " (" << player->getPos() << ")" << std::endl
// << "Vel: " << player->getVel() << std::endl
//
// << "Yaw: " << player->getYaw() << ", "
// << "Pitch: " << player->getPitch() << std::endl << std::endl
//
// << "C: " << posOffsetFromChunk << " [" << chunkPos << "]" << std::endl
// << "M: " << posOffsetFromBlock << " [" << mapBlockPos << "]" << std::endl
// << "R: " << posOffsetFromRegion << " [" << regionPos << "]" << std::endl
// << std::endl
//
// << "Texture Slots: " << game.l()->textures.textureSlotsUsed << " / " << game.l()->textures.maxTextureSlots
// << " ("
// << round(game.l()->textures.textureSlotsUsed / static_cast<float>(game.l()->textures.maxTextureSlots) * 100)
// << "%)" << std::endl << std::endl
//
// << "Biome: " << onBiomeDef.identifier << " [" << onBiomeDef.index << "]" << std::endl << std::endl;
//
// if (target.type == Target::Type::BLOCK) {
// string face =
// target.data.block.face == EVec::TOP ? "Top" :
// target.data.block.face == EVec::BOTTOM ? "Bottom" :
// target.data.block.face == EVec::LEFT ? "Left" :
// target.data.block.face == EVec::RIGHT ? "Right" :
// target.data.block.face == EVec::FRONT ? "Front" :
// target.data.block.face == EVec::BACK ? "Back" :
// "None (!)";
//
// const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos));
//
// str << "Pointing At: " << def.identifier << " [" << def.index << "]" << std::endl
// << "Pointed Position: " << target.data.block.pos << std::endl
// << "Pointed Face: " << face << std::endl;
// }
// else if (target.type == Target::Type::ENTITY) {
// const auto& entity = **world.getActiveDimension().l()->getEntityById(target.data.entity.id).entity;
//
// str << "Pointing At: " << (target.data.entity.id < 0 ? "Local" : "Server")
// << " Entity #" << std::fabs(target.data.entity.id) << std::endl
// << "Pointed Position: " << entity.getPos() << std::endl << std::endl;
// }
// else {
// str << "No Target" << std::endl << std::endl;
// }
//
// get<GuiText>("dataText")->setText(str.str());
//
// // Chunk States
//
// auto chunkStates = get<GuiCellGraph>("chunkStates");
// ivec3 off = { 0, 0, 0 };
// for (off.x = 0; off.x < MAPBLOCK_RANGE; off.x++) {
// if ((off.x - mapBlockScanX) % MAPBLOCK_SCAN_X_INTERVAL != 0) continue;
//
// for (off.z = 0; off.z < MAPBLOCK_RANGE; off.z++) {
// f32 existAmount = 0;
// ivec3 check = ivec3(mapBlockPos) + off -
// ivec3(MAPBLOCK_RANGE / 2, 0, MAPBLOCK_RANGE / 2);
//
// for (off.y = 0; off.y < MAPBLOCK_VERT; off.y++) {
// check.y = static_cast<i32>(mapBlockPos.y) + off.y - MAPBLOCK_VERT / 2;
// const auto mapBlock = world.getActiveDimension()->getMapBlock(check);
// if (mapBlock) existAmount++;
// }
//
// const auto color =
// (off.x == MAPBLOCK_RANGE / 2 && off.z == MAPBLOCK_RANGE / 2) ? MAPBLOCK_CURRENT
// : glm::mix(MAPBLOCK_UNLOADED, MAPBLOCK_LOADED, existAmount / MAPBLOCK_VERT);
// chunkStates->setCellColor(u16vec2(off.x, off.z), color);
// }
// }
// chunkStates->refresh();
//
// mapBlockScanX = (mapBlockScanX + 1) % MAPBLOCK_SCAN_X_INTERVAL;
//
// if (target.type == Target::Type::BLOCK) {
// const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos));
// get<GuiText>("crosshairText")->setText("`b" + def.name + " (`r` `c7" +
// def.identifier + "`cr - " + std::to_string(def.index) + "` `b)");
// }
// else {
// get<GuiText>("crosshairText")->setText("");
// }
//}
//
//void DebugGui::bufferResized(u16vec2 buffer) {
// positionElements(buffer);
//}
//
//void DebugGui::changeVisibility(Visibility state) {
// setVisible(state == Visibility::ON);
// get<GuiLabelledGraph>("fpsGraph")->setVisible(state != Visibility::OFF);
//}

View File

@ -1,55 +0,0 @@
//#pragma once
//
//#include "client/gui/basic/GuiContainer.h"
//
//#include "util/Types.h"
//#include "util/CovariantPtr.h"
//
//class GuiRect;
//class LocalWorld;
//class LocalPlayer;
//class LocalSubgame;
//
///**
// * Renders debug information, in the form of graphs and text.
// * Can be enabled, disabled, or displayed with FPS only.
// */
//
//class DebugGui : public GuiContainer {
//public:
//
// enum class Visibility { OFF, FPS_ONLY, ON };
//
// DebugGui(Window& window, SubgamePtr game, LocalWorld& world, vec<string>& perfSections);
//
// /** Resizes elements when the screen buffer is resized. */
// void bufferResized(u16vec2 bufferSize);
//
// /** Sets which elements are visible based on the state provided. */
// void changeVisibility(Visibility state);
//
// /** Positions all elements based on the buffer size. */
// void positionElements(u16vec2 buffer);
//
// /** Updates the debug screen with the latest data. */
// void update(sptr<LocalPlayer> player, f64 delta, u32 interpolatedChunks, u32 generatedChunks,
// u32 recievedPackets, vec<usize>& perfTimings, u32 drawnMeshChunks, u32 generatedMeshChunks);
//
//private:
//
// constexpr static vec4 MAPBLOCK_UNLOADED = { 1, 1, 1, 0.15 };
// constexpr static vec4 MAPBLOCK_LOADED = { 1, 1, 1, 0.75 };
// constexpr static vec4 MAPBLOCK_CURRENT = { 1, 0.93, 0.35, 1 };
//
// constexpr static i32 MAPBLOCK_VERT = 3;
// constexpr static i32 MAPBLOCK_RANGE = 11;
//
// u32 mapBlockScanX = 0;
// constexpr static u32 MAPBLOCK_SCAN_X_INTERVAL = 9;
//
// Window& window;
// SubgamePtr game;
// LocalWorld& world;
//
// Visibility state = Visibility::ON;
//};

View File

@ -59,44 +59,48 @@ void Gui::Element::onClick(const std::function<void(i32, bool)>& cb) {
Gui::ExpressionInfo Gui::Element::getExpr() const { Gui::ExpressionInfo Gui::Element::getExpr() const {
return { return {
parent ? parent->getComputedSize() : ivec2 {}, parent ? parent->getComputedSize() : vec2 {},
getComputedSize() getComputedSize()
}; };
} }
ivec2 Gui::Element::getComputedSize() const { vec2 Gui::Element::getComputedSize() const {
let size = getStyleWithExpr<vec2, Type::LENGTH>(Prop::SIZE, vec2(nanf("")), let size = getStyleWithExpr<vec2, Type::LENGTH>(Prop::SIZE, vec2(nanf("")),
{ parent ? parent->computedSize : ivec2 {}, {} }); { parent ? parent->computedSize : vec2 {}, {} });
if (std::isnan(size.x)) size.x = std::max(layoutSize.x, 0); if (std::isnan(size.x)) size.x = std::max(layoutSize.x, 0.f);
if (std::isnan(size.y)) size.y = std::max(layoutSize.y, 0); if (std::isnan(size.y)) size.y = std::max(layoutSize.y, 0.f);
computedSize = ivec2(size); computedSize = size;
return size; return size;
} }
ivec2 Gui::Element::getComputedContentSize() const { vec2 Gui::Element::getComputedContentSize() const {
let size = getComputedSize(); let size = getComputedSize();
let padding = getStyle<ivec4, Type::LENGTH>(Prop::PADDING, {}); let padding = getStyle<vec4, Type::LENGTH>(Prop::PADDING, {});
return glm::max(ivec2 { size.x - padding.x - padding.z, size.y - padding.y - padding.w }, 0); return glm::max(vec2 { size.x - padding.x - padding.z, size.y - padding.y - padding.w }, vec2(0));
} }
ivec2 Gui::Element::getExplicitSize() const { vec2 Gui::Element::getExplicitSize() const {
return getStyle<ivec2, Type::LENGTH>(Prop::SIZE, ivec2(-1)); return getStyle<vec2, Type::LENGTH>(Prop::SIZE, vec2(-1));
} }
ivec2 Gui::Element::getComputedPos() const { vec2 Gui::Element::getComputedPos() const {
return getStyle<ivec2, Type::LENGTH>(Prop::POS, layoutPosition); return getStyle<vec2, Type::LENGTH>(Prop::POS, layoutPosition);
} }
ivec2 Gui::Element::getComputedScreenPos() const { vec2 Gui::Element::getComputedScreenPos() const {
return getComputedPos() + parentOffset; return getComputedPos() + parentOffset;
} }
vec2 Gui::Element::getExplicitPos() const {
return getStyle<vec2, Type::LENGTH>(Prop::POS, vec2(nanf("")));
}
bool Gui::Element::handleMouseHover(ivec2 mousePos, bool& pointer) { bool Gui::Element::handleMouseHover(ivec2 mousePos, bool& pointer) {
bool childIntersects = false; bool childIntersects = false;
for (let& child : children) if (child->handleMouseHover(mousePos, pointer)) childIntersects = true; for (let& child : children) if (child->handleMouseHover(mousePos, pointer)) childIntersects = true;
ivec2 size = getComputedSize(); vec2 size = getComputedSize();
ivec2 pos = getComputedScreenPos(); vec2 pos = getComputedScreenPos();
bool intersects = mousePos.x >= pos.x && mousePos.x <= pos.x + size.x && bool intersects = mousePos.x >= pos.x && mousePos.x <= pos.x + size.x &&
mousePos.y >= pos.y && mousePos.y <= pos.y + size.y; mousePos.y >= pos.y && mousePos.y <= pos.y + size.y;
@ -115,8 +119,8 @@ bool Gui::Element::handleMouseClick(ivec2 mousePos, u32 button, bool down) {
for (i32 i = children.size() - 1; i >= 0; i--) for (i32 i = children.size() - 1; i >= 0; i--)
if (children[i]->handleMouseClick(mousePos, button, down)) return true; if (children[i]->handleMouseClick(mousePos, button, down)) return true;
ivec2 size = getComputedSize(); vec2 size = getComputedSize();
ivec2 pos = getComputedScreenPos(); vec2 pos = getComputedScreenPos();
bool intersects = mousePos.x >= pos.x && mousePos.x <= pos.x + size.x && bool intersects = mousePos.x >= pos.x && mousePos.x <= pos.x + size.x &&
mousePos.y >= pos.y && mousePos.y <= pos.y + size.y; mousePos.y >= pos.y && mousePos.y <= pos.y + size.y;
if (!intersects) return false; if (!intersects) return false;
@ -166,8 +170,8 @@ void Gui::Element::layoutChildren() {
* The element gap across the primary axis. * The element gap across the primary axis.
*/ */
const i32 gap = getStyle<ivec2, Type::LENGTH>(Prop::GAP, ivec2(0))[primary]; const f32 gap = getStyle<vec2, Type::LENGTH>(Prop::GAP, vec2(0))[primary];
const ivec4& padding = getStyle<ivec4, Type::LENGTH>(Prop::PADDING, ivec4 {}); const vec4& padding = getStyle<vec4, Type::LENGTH>(Prop::PADDING, {});
/* /*
* Calculates the explicit spaced used up by children across the primary axis, * Calculates the explicit spaced used up by children across the primary axis,
@ -176,14 +180,15 @@ void Gui::Element::layoutChildren() {
*/ */
let selfSize = getComputedContentSize(); let selfSize = getComputedContentSize();
i32 explicitSize = gap * (children.size() - 1); f32 explicitSize = gap * (children.size() - 1);
i32 implicitCount = 0; u32 implicitCount = 0;
for (const let& child : children) { for (const let& child : children) {
if (!std::isnan(child->getExplicitPos()[primary])) continue;
let childExplicitSize = child->getExplicitSize(); let childExplicitSize = child->getExplicitSize();
if (childExplicitSize[primary] != -1) explicitSize += childExplicitSize[primary]; if (childExplicitSize[primary] != -1) explicitSize += childExplicitSize[primary];
else implicitCount++; else implicitCount++;
let childMargin = child->getStyle<ivec4, Type::LENGTH>(Prop::MARGIN, {}); let childMargin = child->getStyle<vec4, Type::LENGTH>(Prop::MARGIN, {});
explicitSize += childMargin[primary] + childMargin[primary + 2]; explicitSize += childMargin[primary] + childMargin[primary + 2];
} }
@ -191,7 +196,7 @@ void Gui::Element::layoutChildren() {
* The cumulative layout offset of the children across the x and y axis. * The cumulative layout offset of the children across the x and y axis.
*/ */
ivec2 offset = { padding.x, padding.y }; vec2 offset = { padding.x, padding.y };
if (align[primary] == 1) offset[primary] += selfSize[primary] - explicitSize - (gap * (children.size() - 1)); if (align[primary] == 1) offset[primary] += selfSize[primary] - explicitSize - (gap * (children.size() - 1));
else if (align[primary] == 0) offset[primary] += selfSize[primary] / 2 - else if (align[primary] == 0) offset[primary] += selfSize[primary] / 2 -
explicitSize / 2 - (gap * (children.size() - 1)) / 2; explicitSize / 2 - (gap * (children.size() - 1)) / 2;
@ -200,17 +205,17 @@ void Gui::Element::layoutChildren() {
* The amount of size each implicitly sized element should occupy. * The amount of size each implicitly sized element should occupy.
*/ */
i32 implicitElemSize = floor((selfSize[primary] - explicitSize) / (std::max)(implicitCount, 1)); f32 implicitElemSize = floor((selfSize[primary] - explicitSize) / (std::max)(implicitCount, u32(1)));
ivec2 selfOffset = getComputedPos() + parentOffset; vec2 selfOffset = getComputedPos() + parentOffset;
/** /**
* Position each child according to `offset`, size implicitly sized elements using `implicitElemSize`. * Position each child according to `offset`, size implicitly sized elements using `implicitElemSize`.
*/ */
for (const let& child : children) { for (const let& child : children) {
let childExplicitSize = child->getExplicitSize(); vec2 childExplicitSize = child->getExplicitSize();
let childMargin = child->getStyle<ivec4, Type::LENGTH>(Prop::MARGIN, {}); vec4 childMargin = child->getStyle<vec4, Type::LENGTH>(Prop::MARGIN, {});
child->layoutSize[primary] = child->layoutSize[primary] =
(childExplicitSize[primary] == -1 && align[primary] == 2) ? implicitElemSize : 0; (childExplicitSize[primary] == -1 && align[primary] == 2) ? implicitElemSize : 0;
@ -224,13 +229,13 @@ void Gui::Element::layoutChildren() {
else if (align[!primary] == 1) child->layoutPosition[!primary] = else if (align[!primary] == 1) child->layoutPosition[!primary] =
selfSize[!primary] - childExplicitSize[!primary]; selfSize[!primary] - childExplicitSize[!primary];
child->layoutPosition[primary] = offset[primary]; child->layoutPosition[primary] = offset[primary];
offset[primary] += ((childExplicitSize[primary] == -1 && align[primary] == 2) if (std::isnan(child->getExplicitPos()[primary]))
? implicitElemSize : childExplicitSize[primary]) offset[primary] += ((childExplicitSize[primary] == -1 && align[primary] == 2)
+ gap + childMargin[primary] + childMargin[primary + 2]; ? implicitElemSize : childExplicitSize[primary])
+ gap + childMargin[primary] + childMargin[primary + 2];
child->parentOffset = selfOffset; child->parentOffset = selfOffset;
child->updateElement(); child->updateElement();
} }
break; break;

View File

@ -94,19 +94,22 @@ namespace Gui {
void onClick(const std::function<void(i32, bool)>& cb); void onClick(const std::function<void(i32, bool)>& cb);
/** Returns the element's computed size. */ /** Returns the element's computed size. */
virtual ivec2 getComputedSize() const; virtual vec2 getComputedSize() const;
/** Returns the element's computed content size, which is its size - padding. */ /** Returns the element's computed content size, which is its size - padding. */
virtual ivec2 getComputedContentSize() const; virtual vec2 getComputedContentSize() const;
/** Returns the element's explicit size. Unspecified dimensions are -1. */ /** Returns the element's explicit size. Unspecified dimensions are -1. */
virtual ivec2 getExplicitSize() const; virtual vec2 getExplicitSize() const;
/** Returns the element's computed position relative to its parent. */ /** Returns the element's computed position relative to its parent. */
virtual ivec2 getComputedPos() const; virtual vec2 getComputedPos() const;
/** Returns the element's computed position relative to the screen. */ /** Returns the element's computed position relative to the screen. */
virtual ivec2 getComputedScreenPos() const; virtual vec2 getComputedScreenPos() const;
/** Returns the element's explicit position. Unspecified dimensions are nan. */
virtual vec2 getExplicitPos() const;
/** Gets a style value from the element's styles or the root's stylesheets. */ /** Gets a style value from the element's styles or the root's stylesheets. */
const optional<any> getStyle(Prop rule) const { const optional<any> getStyle(Prop rule) const {
@ -232,16 +235,16 @@ namespace Gui {
std::function<void(u32, bool)> clickCb = nullptr; std::function<void(u32, bool)> clickCb = nullptr;
/** The screen offset of the parent. */ /** The screen offset of the parent. */
ivec2 parentOffset {}; vec2 parentOffset {};
/** The last computed size of the element. */ /** The last computed size of the element. */
mutable ivec2 computedSize {}; mutable vec2 computedSize {};
/** The element's implicit size, as defined by the parent layout. */ /** The element's implicit size, as defined by the parent layout. */
ivec2 layoutSize { -1, -1 }; vec2 layoutSize { -1, -1 };
/** The element's implicit position, as defined by the parent layout. */ /** The element's implicit position, as defined by the parent layout. */
ivec2 layoutPosition {}; vec2 layoutPosition {};
/** Updates child sizes and offsets based on layout styles. */ /** Updates child sizes and offsets based on layout styles. */
virtual void layoutChildren(); virtual void layoutChildren();

View File

@ -105,9 +105,7 @@ void Gui::Expression::setExpression(string exp) {
} }
f32 Gui::Expression::eval(const ExpressionInfo& info) { f32 Gui::Expression::eval(const ExpressionInfo& info) {
if (!expression.size()) { if (!expression.size()) return nanf("");
return nanf("");
}
std::stack<Token> eval {}; std::stack<Token> eval {};

View File

@ -191,10 +191,10 @@ void Gui::TextElement::updateElement() {
} }
let scale = getStyle<f32, Type::LENGTH>(Prop::TEXT_SIZE, 3.f); let scale = getStyle<f32, Type::LENGTH>(Prop::TEXT_SIZE, 3.f);
let margin = getStyle<ivec4, Type::LENGTH>(Prop::MARGIN, {}); let margin = getStyle<vec4, Type::LENGTH>(Prop::MARGIN, {});
entity.setScale(vec3(scale, scale, 0)); entity.setScale(ivec3(scale, scale, 0));
entity.setPos(vec3(getComputedScreenPos() + ivec2 { margin.x, margin.y }, 0)); entity.setPos(ivec3(getComputedScreenPos() + vec2 { margin.x, margin.y }, 0));
Element::updateElement(); Element::updateElement();
} }

View File

@ -33,7 +33,7 @@
// Util // Util
#include "lua/register/CreateRegister.h" #include "lua/register/CreateRegister.h"
LocalLuaParser::LocalLuaParser(LocalSubgame& game) : LuaParser(game), keybinds(this) {} LocalLuaParser::LocalLuaParser(LocalSubgame& game) : LuaParser(game) {}
void LocalLuaParser::init(WorldPtr world, PlayerPtr player, Client& client) { void LocalLuaParser::init(WorldPtr world, PlayerPtr player, Client& client) {
this->client = &client; this->client = &client;
@ -139,13 +139,13 @@ void LocalLuaParser::loadApi(WorldPtr world, PlayerPtr player) {
Api::Util::createRegister(lua, core, "mesh"); Api::Util::createRegister(lua, core, "mesh");
Api::Util::createRegister(lua, core, "item", Api::Util::createRegister(lua, core, "item",
[&](const auto& iden) { RegisterItem::client(core, game, iden); }); [&](const string& iden) { RegisterItem::client(core, game, iden); });
Api::Util::createRegister(lua, core, "block", Api::Util::createRegister(lua, core, "block",
[&](const auto& iden) { RegisterBlock::client(core, game, iden); }); [&](const string& iden) { RegisterBlock::client(core, game, iden); });
Api::Util::createRegister(lua, core, "biome", Api::Util::createRegister(lua, core, "biome",
[&](const auto& iden) { RegisterBiome::client(core, game, iden); }); [&](const string& iden) { RegisterBiome::client(core, game, iden); });
Api::Util::createRegister(lua, core, "keybind", Api::Util::createRegister(lua, core, "keybind",
[&](const auto& iden) { RegisterKeybind::client(core, keybinds, iden); }); [&](const string& iden) { RegisterKeybind::client(core, client->renderer.window.input, refs, iden); });
Api::Util::createRegister(lua, core, "blockmodel"); Api::Util::createRegister(lua, core, "blockmodel");
Api::Util::createRegister(lua, core, "entity", nullptr, "entities"); Api::Util::createRegister(lua, core, "entity", nullptr, "entities");

View File

@ -9,6 +9,7 @@
#include "lua/LuaParser.h" #include "lua/LuaParser.h"
#include "LuaMod.h" #include "LuaMod.h"
#include "client/Callback.h"
#include "util/CovariantPtr.h" #include "util/CovariantPtr.h"
#include "lua/LuaKeybindHandler.h" #include "lua/LuaKeybindHandler.h"
@ -35,9 +36,9 @@ private:
sol::protected_function_result runFileSandboxed(const std::string& file); sol::protected_function_result runFileSandboxed(const std::string& file);
Client* client; Client* client;
LuaKeybindHandler keybinds;
double accumulatedDelta = 0; double accumulatedDelta = 0;
std::unordered_map<string, LuaMod> mods {}; vec<CallbackRef> refs;
vec<string> modLoadOrder {}; vec<string> modLoadOrder {};
std::unordered_map<string, LuaMod> mods {};
}; };

View File

@ -1,37 +0,0 @@
////
//// Created by aurailus on 2020-02-19.
////
//
//#include "lua/Lua.h"
//
//#include "LocalModHandler.h"
//
//void LocalModHandler::addLuaMod(const LuaMod& mod) {
// mods.emplace_back(mod);
//}
//
//void LocalModHandler::setModsOrder(const std::vector<std::string>& order) {
// modsOrder = order;
//}
//
//void LocalModHandler::executeMods(std::function<void(std::string)> run) {
// try {
// for (std::string& modName : modsOrder) {
// if (modName == "base") {
// run(modName + "/init");
// break;
// }
// }
//
// for (std::string& modName : modsOrder) {
// if (modName != "base") run(modName + "/init");
// }
// }
// catch (sol::error e) {
// std::cout << "CAUGHT B " << e.what() << std::endl;
// }
//}
//
//const std::vector<LuaMod>& LocalModHandler::cGetMods() const {
// return mods;
//}

View File

@ -1,24 +0,0 @@
////
//// Created by aurailus on 2020-02-19.
////
//
//#pragma once
//
//#include <functional>
//
//#include "LuaMod.h"
//
//class LocalModHandler {
// public:
// void addLuaMod(const LuaMod& mod);
//
// void setModsOrder(const std::vector<std::string>& order);
//
// void executeMods(std::function<void(std::string)> run);
//
// const std::vector<LuaMod>& cGetMods() const;
//
// private:
// std::vector<LuaMod> mods;
// std::vector<std::string> modsOrder;
//};

View File

@ -16,15 +16,17 @@ namespace RegisterKeybind {
* @param handler - The keybind handler to add the keybind to. * @param handler - The keybind handler to add the keybind to.
*/ */
static void registerKeybind(sol::table keybinds, const std::string& identifier, LuaKeybindHandler& handler) { static void registerKeybind(Input& input, vec<CallbackRef>& refs, sol::table keybinds, const string& identifier) {
sol::table keybindTbl = keybinds[identifier]; sol::table keybindTbl = keybinds[identifier];
unsigned short def = keybindTbl.get<unsigned short>("default"); u32 def = keybindTbl.get<unsigned short>("default");
auto onPress = keybindTbl.get<sol::optional<sol::function>>("on_press"); auto onPress = keybindTbl.get<sol::optional<sol::function>>("on_press");
auto onRelease = keybindTbl.get<sol::optional<sol::function>>("on_release"); auto onRelease = keybindTbl.get<sol::optional<sol::function>>("on_release");
if (onPress) handler.bindOnDown(def, *onPress); if (onPress) refs.emplace_back(input.events.bind(Input::CBType::KEY_PRESS, [=](u32 key, i32) {
if (onRelease) handler.bindOnUp(def, *onRelease); if (key == def) (*onPress)(); }));
if (onRelease) refs.emplace_back(input.events.bind(Input::CBType::KEY_RELEASE, [=](u32 key, i32) {
if (key == def) (*onRelease)(); }));
} }
} }
@ -35,11 +37,11 @@ namespace RegisterKeybind {
* Registers a keybind to the keybind handler. * Registers a keybind to the keybind handler.
* *
* @param core - The core table to index for 'registered_keybinds', i.e. `_G['zepha']`. * @param core - The core table to index for 'registered_keybinds', i.e. `_G['zepha']`.
* @param game - The keybind handler to add the keybind to. * @param game - The input manager to add the keybind to.
* @param identifier - The identifier of the keybind to add. * @param identifier - The identifier of the keybind to add.
*/ */
static void client(sol::table& core, LuaKeybindHandler& handler, const std::string& identifier) { static void client(sol::table& core, Input& input, vec<CallbackRef>& refs, const string& identifier) {
registerKeybind(core.get<sol::table>("registered_keybinds"), identifier, handler); registerKeybind(input, refs, core.get<sol::table>("registered_keybinds"), identifier);
} }
}; };

View File

@ -164,8 +164,8 @@ void Api::Usertype::GuiElement::bind(sol::state& lua, sol::table& core, Gui::Roo
}), }),
"prepend", [&](sol::this_state s, Gui::Element& self, sol::object child) { "prepend", [&](sol::this_state s, Gui::Element& self, sol::object child) {
if (child.is<sptr<Gui::Element>>()) self.prepend(child.as<sptr<Gui::Element>>()); if (child.is<sptr<Gui::Element>>()) self.prepend(child.as<sptr<Gui::Element>>());
else if (child.is<sol::protected_function>()) { else if (child.is<sol::function>()) {
sol::protected_function fn = child.as<sol::protected_function>(); sol::protected_function fn = child.as<sol::function>();
sol::table tbl = sol::state_view(s)["zepha"]["__builtin"]["gui_env"]; sol::table tbl = sol::state_view(s)["zepha"]["__builtin"]["gui_env"];
sol::environment env(s, sol::create, tbl); sol::environment env(s, sol::create, tbl);
sol::set_environment(env, fn); sol::set_environment(env, fn);
@ -176,8 +176,8 @@ void Api::Usertype::GuiElement::bind(sol::state& lua, sol::table& core, Gui::Roo
}, },
"append", [&](sol::this_state s, Gui::Element& self, sol::object child) { "append", [&](sol::this_state s, Gui::Element& self, sol::object child) {
if (child.is<sptr<Gui::Element>>()) self.append(child.as<sptr<Gui::Element>>()); if (child.is<sptr<Gui::Element>>()) self.append(child.as<sptr<Gui::Element>>());
else if (child.is<sol::protected_function>()) { else if (child.is<sol::function>()) {
let fn = child.as<sol::protected_function>(); let fn = child.as<sol::function>();
sol::table tbl = sol::state_view(s)["zepha"]["__builtin"]["gui_env"]; sol::table tbl = sol::state_view(s)["zepha"]["__builtin"]["gui_env"];
sol::environment env(s, sol::create, tbl); sol::environment env(s, sol::create, tbl);
sol::set_environment(env, fn); sol::set_environment(env, fn);

View File

@ -13,7 +13,7 @@ LocalWorld::LocalWorld(SubgamePtr game, ServerConnection& conn, Renderer& render
renderer(renderer), renderer(renderer),
net(conn, *this), net(conn, *this),
refs(make_shared<LocalInventoryRefs>(game, net)), refs(make_shared<LocalInventoryRefs>(game, net)),
// debugGui(renderer.window.getSize(), game, *this, perfSections), debug(player.l()->getDebug(), game, *this, perfSections),
// worldGenStream(make_shared<WorldInterpolationStream>(*game.l(), *this, 55)), // worldGenStream(make_shared<WorldInterpolationStream>(*game.l(), *this, 55)),
player(make_shared<LocalPlayer>(game, *this, DimensionPtr(nullptr), renderer)) { player(make_shared<LocalPlayer>(game, *this, DimensionPtr(nullptr), renderer)) {
@ -49,12 +49,12 @@ void LocalWorld::update(f64 delta, vec<usize>& perfTimings, PerfTimer& perf) {
// Update debug interface // Update debug interface
perf.start("update:debug"); perf.start("update:debug");
// debugGui.update( debug.update(
// player.l(), delta, player.l(), delta,
// lastInterpolations, net.serverSideChunkGens, net.recvPackets, lastInterpolations, net.serverSideChunkGens, net.recvPackets,
// perfTimings, perfTimings,
// activeDimension->getMeshChunksDrawn(), activeDimension->getMeshChunksDrawn(),
// activeDimension->getMeshChunksCommitted()); activeDimension->getMeshChunksCommitted());
perf.resume("other"); perf.resume("other");
// Toggle regular interface // Toggle regular interface

View File

@ -3,7 +3,7 @@
#include "World.h" #include "World.h"
#include "client/Window.h" #include "client/Window.h"
#include "client/gui/DebugGui.h" #include "client/gui/DebugDisplay.h"
#include "world/dim/LocalDimension.h" #include "world/dim/LocalDimension.h"
#include "client/conn/ClientNetworkInterpreter.h" #include "client/conn/ClientNetworkInterpreter.h"
@ -90,7 +90,7 @@ private:
PlayerPtr player; PlayerPtr player;
/** The debug interface. */ /** The debug interface. */
// DebugGui debugGui; DebugDisplay debug;
/** The number of chunks that were interpolated last frome. */ /** The number of chunks that were interpolated last frome. */
u32 lastInterpolations = 0; u32 lastInterpolations = 0;

View File

@ -17,19 +17,19 @@
LocalPlayer::LocalPlayer(SubgamePtr game, LocalWorld& world, DimensionPtr dim, Renderer& renderer) : LocalPlayer::LocalPlayer(SubgamePtr game, LocalWorld& world, DimensionPtr dim, Renderer& renderer) :
Player(game, world, dim), DrawableEntity(game, dim), Entity(game, dim), Player(game, world, dim), DrawableEntity(game, dim), Entity(game, dim),
root(renderer.window, game.l()->textures), root(renderer.window, game.l()->textures),
hud(root.body->append<Gui::BoxElement>({{ { Gui::Prop::CLASS, vec<string> { "_GUI_ROOT" } } }})),
menu(root.body->append<Gui::BoxElement>({{ { Gui::Prop::CLASS, vec<string> { "_GUI_ROOT" } } }})),
debug(root.body->append<Gui::BoxElement>({{ { Gui::Prop::CLASS, vec<string> { "_GUI_ROOT" } } }})),
wireframe(game, dim, { 1, 1, 1 }), wireframe(game, dim, { 1, 1, 1 }),
renderer(renderer) { renderer(renderer) {
handItemModel.parent = &handModel; handItemModel.parent = &handModel;
hud = root.body->append<Gui::BoxElement>({{ root.addStylesheet({
{ Gui::Prop::POS, array<Gui::Expression, 2> { Gui::Expression("0"), Gui::Expression("0") }}, { "_GUI_ROOT", {{
{ Gui::Prop::SIZE, array<Gui::Expression, 2> { Gui::Expression("100cw"), Gui::Expression("100ch") }} { Gui::Prop::POS, array<Gui::Expression, 2> { Gui::Expression("0"), Gui::Expression("0") }},
}}); { Gui::Prop::SIZE, array<Gui::Expression, 2> { Gui::Expression("100cw"), Gui::Expression("100ch") }}
}}}
menu = root.body->append<Gui::BoxElement>({{ });
{ Gui::Prop::POS, array<Gui::Expression, 2> { Gui::Expression("0"), Gui::Expression("0") }},
{ Gui::Prop::SIZE, array<Gui::Expression, 2> { Gui::Expression("100cw"), Gui::Expression("100ch") }}
}});
} }
void LocalPlayer::update(f64 delta, vec2 mouseDelta) { void LocalPlayer::update(f64 delta, vec2 mouseDelta) {
@ -100,7 +100,7 @@ InventoryPtr LocalPlayer::getInventory() {
} }
bool LocalPlayer::isInMenu() { bool LocalPlayer::isInMenu() {
// return gameGui.isInMenu(); return menu->get(0) != nullptr;
} }
void LocalPlayer::showMenu(sptr<Gui::Element> newMenu) { void LocalPlayer::showMenu(sptr<Gui::Element> newMenu) {
@ -118,6 +118,10 @@ Gui::Root& LocalPlayer::getRoot() {
return root; return root;
} }
sptr<Gui::Element> LocalPlayer::getDebug() {
return debug;
}
sptr<Gui::Element> LocalPlayer::getHud() { sptr<Gui::Element> LocalPlayer::getHud() {
return hud->get(0); return hud->get(0);
} }
@ -138,6 +142,7 @@ void LocalPlayer::draw(Renderer&) {
void LocalPlayer::drawHud(Renderer&) { void LocalPlayer::drawHud(Renderer&) {
hud->draw(renderer); hud->draw(renderer);
debug->draw(renderer);
} }
void LocalPlayer::drawMenu(Renderer&) { void LocalPlayer::drawMenu(Renderer&) {

View File

@ -65,6 +65,9 @@ public:
/** Returns the Gui root. */ /** Returns the Gui root. */
Gui::Root& getRoot(); Gui::Root& getRoot();
/** Gets the debug element. */
sptr<Gui::Element> getDebug();
/** Gets the hud element. */ /** Gets the hud element. */
sptr<Gui::Element> getHud(); sptr<Gui::Element> getHud();
@ -116,7 +119,7 @@ private:
Gui::Root root; Gui::Root root;
/** Element roots for the hud and menu, respectively. */ /** Element roots for the hud and menu, respectively. */
sptr<Gui::BoxElement> hud, menu; sptr<Gui::BoxElement> hud, menu, debug;
/** A reference to the renderer. */ /** A reference to the renderer. */
Renderer& renderer; Renderer& renderer;

View File

@ -1,6 +1,6 @@
-- _G['health'] = {} _G['health'] = {}
-- health.internal = {} health.internal = {}
--
-- require(_PATH .. 'api') require(_PATH .. 'api')
-- require(_PATH .. 'interface') require(_PATH .. 'interface')
-- require(_PATH .. 'hooks') require(_PATH .. 'hooks')

View File

@ -2,11 +2,7 @@ if not zepha.client then return end
local hud = zepha.player:get_hud() local hud = zepha.player:get_hud()
health.internal._wrapper = zepha.gui(function() health.internal._wrapper = zepha.Gui.Box { id = 'health_wrapper' }
return Gui.Box {
id = 'health_wrapper'
}
end)
function health.internal.update() function health.internal.update()
local hp = health.my_health local hp = health.my_health
@ -16,14 +12,14 @@ function health.internal.update()
health.internal._wrapper:append(function() health.internal._wrapper:append(function()
local elem = Gui.Box { local elem = Gui.Box {
id = '@health:component', id = '@health:component',
size = { health.internal._width, 9 }, size = { health.internal._width .. 'dp', '9dp' }
} }
-- Background -- Background
for i = 1, hp.max do for i = 1, hp.max do
elem:append(Gui.Box { elem:append(Gui.Box {
size = { 9, 9 }, size = '9dp',
position = { 8 * (i - 1), 0 }, pos = { 8 * (i - 1) .. 'dp', 0 },
background = 'crop(0, 0, 9, 9, @auri:health:hearts)' background = 'crop(0, 0, 9, 9, @auri:health:hearts)'
}) })
end end
@ -36,15 +32,15 @@ function health.internal.update()
if i > red_start and i <= red_end then if i > red_start and i <= red_end then
local segment = start ~= 0 and 9 or 18 local segment = start ~= 0 and 9 or 18
elem:append(Gui.Box { elem:append(Gui.Box {
size = { 9, 9 }, size = '9dp',
position = { 8 * math.floor((i - 1) / 2), 0 }, pos = { 8 * math.floor((i - 1) / 2) .. 'dp', 0 },
background = 'crop(9, ' .. segment .. ', 9, 9, @auri:health:hearts)' background = 'crop(9, ' .. segment .. ', 9, 9, @auri:health:hearts)'
}) })
elseif i > blue_start and i <= blue_end then elseif i > blue_start and i <= blue_end then
local segment = start ~= 0 and 9 or 18 local segment = start ~= 0 and 9 or 18
elem:append(Gui.Box { elem:append(Gui.Box {
size = { 9, 9 }, size = '9dp',
position = { 8 * math.floor((i - 1) / 2), 0 }, pos = { 8 * math.floor((i - 1) / 2) .. 'dp', 0 },
background = 'crop(18, ' .. segment .. ', 9, 9, @auri:health:hearts)' background = 'crop(18, ' .. segment .. ', 9, 9, @auri:health:hearts)'
}) })
end end
@ -57,16 +53,14 @@ end
function health.render_default(render) function health.render_default(render)
hud:remove('@health:default') hud:remove('@health:default')
if render then if render then
hud:append(function() hud:append(zepha.Gui.Box {
return Gui.Rect { id = '@health:default',
id = '@health:default',
size = { health.internal._width, 9 }, pos = { '50cw - 50sw', '100ch - 18dp' },
position = { '50cw - 50sw', '100cw - 30px' }, size = { health.internal._width .. "dp", 9 },
health.internal._wrapper health.internal._wrapper
} })
end)
end end
end end

View File

@ -1,10 +1,10 @@
-- _G["hot_wheel"] = {} _G["hot_wheel"] = {}
--
-- if zepha.server then if zepha.server then
-- require(_PATH .. "register") require(_PATH .. "register")
-- end end
--
-- if zepha.client then if zepha.client then
-- require(_PATH .. "interface") require(_PATH .. "interface")
-- require(_PATH .. "keys") require(_PATH .. "keys")
-- end end

View File

@ -8,134 +8,136 @@ if health then
end end
hud:append(function() hud:append(function()
local root = Gui.Rect { local root = Gui.Box {
key = "hot_wheel_root", id = 'hot_wheel_root',
size = { 140, 80 }, size = { '140dp', '80dp' },
position = { "0%", "100%" }, pos = { '0', '100ch - 100sh' },
position_anchor = { "-10%", "110%" },
Gui.Rect { Gui.Box {
size = { 94, 18 }, pos = { '52dp', '19dp' },
position = { 52, 19 }, size = { '94dp', '18dp' },
background = "@auri:hot_wheel:hot_wheel_line", background = '@auri:hot_wheel:hot_wheel_line',
Gui.Rect { Gui.Box {
key = "expanded_indicator", id = 'expanded_indicator',
size = { 18, 18 },
position = { 2, 0 }, size = '18dp',
background = "@auri:hot_wheel:hot_wheel_selection" pos = { '2dp', 0 },
background = '@auri:hot_wheel:hot_wheel_selection'
}, },
Gui.InventoryList { -- Gui.InventoryList {
key = "list_expanded", -- key = 'list_expanded',
position = { 3, 1 }, -- pos = { 3, 1 },
slot_spacing = { 2, 2 }, -- gap = { 2, 2 },
length = 6, --
source = "current_player", -- length = 6,
list = "hot_wheel_1", -- list = 'hot_wheel_1',
-- source = 'current_player',
-- }
},
Gui.Box {
size = '80dp',
background = '@auri:hot_wheel:hot_wheel_circle',
-- Gui.InventoryList {
-- key = 'list_1',
-- slot_spacing = { 2, 2 },
-- length = 1,
-- source = 'current_player',
-- list = 'hot_wheel_1',
-- },
-- Gui.InventoryList {
-- key = 'list_2',
-- slot_spacing = { 2, 2 },
-- length = 1,
-- source = 'current_player',
-- list = 'hot_wheel_2',
-- },
-- Gui.InventoryList {
-- key = 'list_3',
-- slot_spacing = { 2, 2 },
-- length = 1,
-- source = 'current_player',
-- list = 'hot_wheel_3',
-- },
-- Gui.InventoryList {
-- key = 'list_4',
-- slot_spacing = { 2, 2 },
-- length = 1,
-- source = 'current_player',
-- list = 'hot_wheel_4',
-- },
-- Gui.InventoryList {
-- key = 'list_5',
-- slot_spacing = { 2, 2 },
-- length = 1,
-- source = 'current_player',
-- list = 'hot_wheel_5',
-- },
-- Gui.InventoryList {
-- key = 'list_6',
-- slot_spacing = { 2, 2 },
-- length = 1,
-- source = 'current_player',
-- list = 'hot_wheel_6',
-- },
Gui.Text {
id = 'label_1',
content = '1'
},
Gui.Text {
id = 'label_2',
content = '2'
},
Gui.Text {
id = 'label_3',
content = '3'
},
Gui.Text {
id = 'label_4',
content = '4'
},
Gui.Text {
id = 'label_5',
content = '5'
},
Gui.Text {
id = 'label_6',
content = '6'
} }
}, },
Gui.Rect { Gui.Box {
size = { 80, 80 }, pos = { '75dp', '40dp' },
background = "@auri:hot_wheel:hot_wheel_circle",
Gui.InventoryList {
key = "list_1",
slot_spacing = { 2, 2 },
length = 1,
source = "current_player",
list = "hot_wheel_1",
},
Gui.InventoryList {
key = "list_2",
slot_spacing = { 2, 2 },
length = 1,
source = "current_player",
list = "hot_wheel_2",
},
Gui.InventoryList {
key = "list_3",
slot_spacing = { 2, 2 },
length = 1,
source = "current_player",
list = "hot_wheel_3",
},
Gui.InventoryList {
key = "list_4",
slot_spacing = { 2, 2 },
length = 1,
source = "current_player",
list = "hot_wheel_4",
},
Gui.InventoryList {
key = "list_5",
slot_spacing = { 2, 2 },
length = 1,
source = "current_player",
list = "hot_wheel_5",
},
Gui.InventoryList {
key = "list_6",
slot_spacing = { 2, 2 },
length = 1,
source = "current_player",
list = "hot_wheel_6",
},
Gui.Text {
key = "label_1",
content = "1"
},
Gui.Text {
key = "label_2",
content = "2"
},
Gui.Text {
key = "label_3",
content = "3"
},
Gui.Text {
key = "label_4",
content = "4"
},
Gui.Text {
key = "label_5",
content = "5"
},
Gui.Text {
key = "label_6",
content = "6"
}
},
Gui.Rect {
position = { 75, 40 },
health_elem health_elem
} }
} }
api.labels = { api.labels = {
root:get("label_1"), root:get('label_1'),
root:get("label_2"), root:get('label_2'),
root:get("label_3"), root:get('label_3'),
root:get("label_4"), root:get('label_4'),
root:get("label_5"), root:get('label_5'),
root:get("label_6") root:get('label_6')
} }
api.lists = { api.lists = {
root:get("list_1"), root:get('list_1'),
root:get("list_2"), root:get('list_2'),
root:get("list_3"), root:get('list_3'),
root:get("list_4"), root:get('list_4'),
root:get("list_5"), root:get('list_5'),
root:get("list_6") root:get('list_6')
} }
api.list_expanded = root:get("list_expanded") api.list_expanded = root:get('list_expanded')
api.list_expanded_indicator = root:get("expanded_indicator") api.list_expanded_indicator = root:get('expanded_indicator')
return root return root
end) end)

View File

@ -16,9 +16,17 @@ local function position()
currentRotation = currentRotation + (desiredRotation - currentRotation) / 2 currentRotation = currentRotation + (desiredRotation - currentRotation) / 2
for i, list in ipairs(api.lists) do for i, list in ipairs(api.lists) do
list.position = { 32.5 + 22 * math.sin(currentRotation - (r * (i + 3))), 32.5 + 22 * math.cos(currentRotation - (r * (i + 3))) } end list.pos = {
32.5 + 22 * math.sin(currentRotation - (r * (i + 3))) .. 'dp',
32.5 + 22 * math.cos(currentRotation - (r * (i + 3))) .. 'dp'
}
end
for i, label in ipairs(api.labels) do for i, label in ipairs(api.labels) do
label.position = { 37 + 35 * math.sin(currentRotation - (r * (i + 3))), 36 + 35 * math.cos(currentRotation - (r * (i + 3))) } end label.pos = {
37 + 35 * math.sin(currentRotation - (r * (i + 3))) .. 'dp',
36 + 35 * math.cos(currentRotation - (r * (i + 3))) .. 'dp'
}
end
if currentRotation == desiredRotation then if currentRotation == desiredRotation then
rotating = false rotating = false
@ -35,19 +43,19 @@ local function select_slot(n)
local offset = n - 1 local offset = n - 1
desiredRotation = offset * r desiredRotation = offset * r
api.list_expanded.list = "hot_wheel_" .. n -- api.list_expanded.list = 'hot_wheel_' .. n
for i, list in ipairs(api.lists) do list.visible = i ~= n end -- for i, list in ipairs(api.lists) do list.visible = i ~= n end
for i, label in ipairs(api.labels) do label.visible = i ~= n end -- for i, label in ipairs(api.labels) do label.visible = i ~= n end
zepha.player:set_wield_list("hot_wheel_" .. slot); zepha.player:set_wield_list('hot_wheel_' .. slot);
if not rotating then position() end if not rotating then position() end
end end
local function select_item(n) local function select_item(n)
item = ((item + n) - 1) % 5 + 1 item = ((item + n) - 1) % 5 + 1
local offset = slot - 1 local offset = slot - 1
api.list_expanded_indicator.position = { 2 + 18 * (item - 1), 0 } api.list_expanded_indicator.pos = { 2 + 18 * (item - 1) .. 'dp', 0 }
zepha.player:set_wield_index(item) zepha.player:set_wield_index(item)
end end

View File

@ -5,15 +5,15 @@ local menu = zepha.gui(function()
Gui.Box { Gui.Box {
id = "inventory", id = "inventory",
size = { 342, 187 }, size = { "342dp", "187dp" },
pos = { "50cw - 50sw", "50ch - 50sh" }, pos = { "50cw - 50sw", "50ch - 50sh" },
Gui.Box { Gui.Box {
id = "backpack", id = "backpack",
pos = { 1, 0 }, pos = { 1, 0 },
size = { 106, 187 }, size = { "106dp", "187dp" },
padding = { 19, 9, 8, 9 }, padding = { "19dp", "9dp", "8dp", "9dp" },
background = "zeus:inventory:backpack" background = "zeus:inventory:backpack"
@ -70,8 +70,8 @@ local menu = zepha.gui(function()
Gui.Box { Gui.Box {
id = "player_frame", id = "player_frame",
pos = { 105, 0 }, pos = { "105dp", 0 },
size = { 106, 187 }, size = { "106dp", "187dp" },
background = "zeus:inventory:player_frame", background = "zeus:inventory:player_frame",
@ -88,25 +88,26 @@ local menu = zepha.gui(function()
Gui.Box { Gui.Box {
id = "equipment", id = "equipment",
pos = { 209, 1 }, pos = { "209dp", "1dp" },
size = { 132, 80 }, size = { "132dp", "80dp" },
padding = { 18, 8, 8, 8 }, padding = { "18dp", "8dp", "8dp", "8dp" },
background = "zeus:inventory:equipment", background = "zeus:inventory:equipment",
Gui.Box { Gui.Box {
id = "player_clamp", id = "player_clamp",
pos = { 41, 1 }, pos = { "41dp", "1dp" },
size = { 34, 52 }, size = { "34dp", "52dp" },
overflow = "hidden" overflow = "hidden"
} }
}, },
Gui.Box { Gui.Box {
id = "dynamic", id = "dynamic",
pos = { 209, 80 }, pos = { "209dp", "80dp" },
size = { 132, 107 }, size = { "132dp", "107dp" },
padding = { 8, 8, 8, 8 }, padding = "8dp",
background = "zeus:inventory:dynamic" background = "zeus:inventory:dynamic"
-- Gui.InventoryList { -- Gui.InventoryList {