Menus Part 1 - Refactored TextureRect class to GUIRect class.
- Made mouse not lock immediately upon game opening.master
parent
758054fa17
commit
4db2351408
|
@ -3,4 +3,5 @@ local path = zeus.get_path("default")
|
|||
dofile(path .. "blocks/ground.lua")
|
||||
dofile(path .. "blocks/tree.lua")
|
||||
dofile(path .. "blocks/foliage.lua")
|
||||
dofile(path .. "blocks/desert.lua")
|
||||
dofile(path .. "blocks/desert.lua")
|
||||
dofile(path .. "blocks/formspec.lua")
|
|
@ -0,0 +1,24 @@
|
|||
zeus.register_block("default:open_formspec", {
|
||||
name = "Open Formspec Block",
|
||||
model = "default:block",
|
||||
textures = {"default_brick"},
|
||||
on_place_client = function()
|
||||
print("Open Menu")
|
||||
zeus.show_menu({
|
||||
{
|
||||
type = "rect",
|
||||
size = {x = 32, y = 24},
|
||||
padding = {h = 1, v = 1},
|
||||
background_color = "#171717",
|
||||
children = {
|
||||
{
|
||||
type = "text",
|
||||
contents = "Hello world",
|
||||
color = "#0ff",
|
||||
position = {x = 2, y = 0}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
})
|
|
@ -3,36 +3,4 @@ print("Hello from default, Zeus " .. (zeus.is_server() and "Server" or "Client")
|
|||
local path = zeus.get_path("default")
|
||||
|
||||
dofile(path .. "models.lua")
|
||||
dofile(path .. "blocks.lua")
|
||||
|
||||
-- API DOCUMENTATION --
|
||||
|
||||
-- # Register BlockModel
|
||||
-- `zeus.register_blockmodel(string identifier, table definition)`
|
||||
--
|
||||
-- Definition is stored as `zeus.registered_blockmodels[identifier] = definition`.
|
||||
-- There are no requirements for the contents of the definition table in this function, but for it to be well
|
||||
-- formed and usable in `register_block`, it should be an array-table of face tables, which contain the following
|
||||
-- information:
|
||||
--
|
||||
-- face: One of "left", "right", "front", "back", "top", "bottom", or "nocull". Used when determining which parts
|
||||
-- of the model to cull.
|
||||
--
|
||||
-- tex: The texture index which this face uses. What textures these refer to are defined in the `register_block`
|
||||
-- `textures` table. The index must be greater than or equal to 1.
|
||||
--
|
||||
-- points: An array of integers that define one or more quads. Each quad is defined by 20 numbers or 4 vertices,
|
||||
-- in the format of x, y, z, tex_coord_x, tex_coord_y. The vertices are indexed in the order
|
||||
-- 0, 1, 2, 2, 3, 0.
|
||||
--
|
||||
-- ## Example
|
||||
-- {
|
||||
-- face = "left"
|
||||
-- tex = 3,
|
||||
-- points = {
|
||||
-- 0, 0, 0, 0, 1,
|
||||
-- 0, 0, 1, 1, 1,
|
||||
-- 0, 1, 1, 1, 0,
|
||||
-- 0, 1, 0, 0, 0
|
||||
-- }
|
||||
-- }
|
||||
dofile(path .. "blocks.lua")
|
|
@ -1,11 +1,11 @@
|
|||
#version 330 core
|
||||
#version 420 core
|
||||
|
||||
in float useTex;
|
||||
in vec4 colorData;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
layout (binding = 0) uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
if (useTex > 0.5) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version 330 core
|
||||
#version 420 core
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec4 aColorData;
|
||||
|
|
|
@ -37,8 +37,8 @@ set(ZEUS_SRC_FILES
|
|||
game/graph/Renderer.h
|
||||
api/client/LocalLuaParser.cpp
|
||||
api/client/LocalLuaParser.h
|
||||
game/entity/hud/TextEntity.cpp
|
||||
game/entity/hud/TextEntity.h
|
||||
game/entity/hud/components/TextEntity.cpp
|
||||
game/entity/hud/components/TextEntity.h
|
||||
game/entity/hud/DebugGui.cpp
|
||||
game/entity/hud/DebugGui.h
|
||||
game/scene/world/Player.cpp
|
||||
|
@ -75,10 +75,10 @@ set(ZEUS_SRC_FILES
|
|||
util/net/PacketChannel.h
|
||||
game/entity/world/PlayerEntity.cpp
|
||||
game/entity/world/PlayerEntity.h
|
||||
game/entity/hud/GraphEntity.cpp
|
||||
game/entity/hud/GraphEntity.h
|
||||
game/entity/hud/TextureRect.cpp
|
||||
game/entity/hud/TextureRect.h
|
||||
game/entity/hud/components/GraphEntity.cpp
|
||||
game/entity/hud/components/GraphEntity.h
|
||||
game/entity/hud/components/basic/GUIRect.cpp
|
||||
game/entity/hud/components/basic/GUIRect.h
|
||||
def/gen/MapGenJob.h
|
||||
util/Interp.h
|
||||
def/gen/NoiseSample.cpp
|
||||
|
@ -121,7 +121,7 @@ set(ZEUS_SRC_FILES
|
|||
world/region/Region.cpp
|
||||
world/region/MapBlock.cpp
|
||||
game/entity/hud/StatGraph.cpp
|
||||
game/entity/hud/StatGraph.h
|
||||
game/entity/hud/StatGraph.cpp
|
||||
util/Util.h
|
||||
world/block/PointedThing.h
|
||||
game/entity/world/ParticleEntity.cpp
|
||||
|
@ -173,6 +173,9 @@ set(ZEUS_SRC_FILES
|
|||
util/net/NetState.h
|
||||
game/scene/ConnectScene.cpp
|
||||
game/scene/ConnectScene.h
|
||||
util/net/Address.h game/scene/net/ServerConnection.cpp game/scene/net/ServerConnection.h game/scene/world/MeshDetails.h)
|
||||
util/net/Address.h
|
||||
game/scene/net/ServerConnection.cpp
|
||||
game/scene/net/ServerConnection.h
|
||||
game/scene/world/MeshDetails.h game/entity/hud/components/GUIComponent.cpp game/entity/hud/components/GUIComponent.h)
|
||||
|
||||
add_library (zeusCore ${ZEUS_SRC_FILES})
|
|
@ -10,7 +10,7 @@
|
|||
namespace ClientApi {
|
||||
void dump(sol::state& lua) {
|
||||
lua.script(R"(
|
||||
local function dump(tbl, indent)
|
||||
function dump(tbl, indent)
|
||||
if not indent then indent = 0 end
|
||||
for k, v in pairs(tbl) do
|
||||
if type(k) == "number" then
|
||||
|
@ -29,8 +29,6 @@ namespace ClientApi {
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
zeus.dump = dump
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
namespace ServerApi {
|
||||
void dump(sol::state& lua) {
|
||||
lua.script(R"(
|
||||
local function dump(tbl, indent)
|
||||
function dump(tbl, indent)
|
||||
if not indent then indent = 0 end
|
||||
for k, v in pairs(tbl) do
|
||||
if type(k) == "number" then
|
||||
|
@ -29,8 +29,6 @@ namespace ServerApi {
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
zeus.dump = dump
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ DebugGui::DebugGui(glm::vec2 bufferSize, Texture* tex) :
|
|||
coloredGraphTexture("../res/tex/gui/histogram.png"),
|
||||
monochromeGraphTexture("../res/tex/gui/histogram_white.png"),
|
||||
|
||||
atlasTex(tex),
|
||||
crosshairText(&fontTexture, true),
|
||||
dataText(&fontTexture, true),
|
||||
|
||||
|
@ -24,7 +23,7 @@ DebugGui::DebugGui(glm::vec2 bufferSize, Texture* tex) :
|
|||
drawCallsGraph ("Draw Calls", 244, 64, 120, 0, &monochromeGraphTexture, &fontTexture),
|
||||
vRamGraph ("VRam", 244, 64, 120, 1, &monochromeGraphTexture, &fontTexture) {
|
||||
|
||||
atlasTex.setScale({0, 0, 1});
|
||||
// atlasTex.setScale({0, 0});
|
||||
|
||||
positionElements(bufferSize);
|
||||
|
||||
|
@ -39,11 +38,11 @@ DebugGui::DebugGui(glm::vec2 bufferSize, Texture* tex) :
|
|||
children.push_back(&drawCallsGraph);
|
||||
children.push_back(&vRamGraph);
|
||||
|
||||
children.push_back(&atlasTex);
|
||||
// children.push_back(&atlasTex);
|
||||
}
|
||||
|
||||
void DebugGui::changeImage(Texture *tex) {
|
||||
atlasTex.setTexture(tex);
|
||||
// atlasTex.setTexture(tex);
|
||||
}
|
||||
|
||||
void DebugGui::positionElements(glm::vec2 bufferSize) {
|
||||
|
@ -51,7 +50,7 @@ void DebugGui::positionElements(glm::vec2 bufferSize) {
|
|||
auto bufferHeight = (int)bufferSize.y;
|
||||
|
||||
crosshairText.setPos({bufferWidth / 2 + 22, bufferHeight / 2 - 7, 0});
|
||||
atlasTex.setPos({8, 350, 0});
|
||||
// atlasTex.setPos({8, 350, 0});
|
||||
|
||||
dataText.setPos(glm::vec3(10, 10, 0));
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
#include "../../../util/Util.h"
|
||||
#include "../../../util/Ray.h"
|
||||
#include "StatGraph.h"
|
||||
#include "TextureRect.h"
|
||||
#include "GraphEntity.h"
|
||||
#include "TextEntity.h"
|
||||
#include "components/basic/GUIRect.h"
|
||||
#include "components/GraphEntity.h"
|
||||
#include "components/TextEntity.h"
|
||||
|
||||
class DebugGui : public Drawable {
|
||||
public:
|
||||
|
@ -37,7 +37,7 @@ private:
|
|||
Texture coloredGraphTexture;
|
||||
Texture monochromeGraphTexture;
|
||||
|
||||
TextureRect atlasTex;
|
||||
// GUIRect atlasTex;
|
||||
|
||||
TextEntity crosshairText;
|
||||
TextEntity dataText;
|
||||
|
|
|
@ -4,31 +4,28 @@
|
|||
|
||||
#include "GameGui.h"
|
||||
|
||||
GameGui::GameGui(glm::vec2 bufferSize) :
|
||||
crosshairTexture(const_cast<char*>("../res/tex/gui/crosshair.png")),
|
||||
viginetteTexture(const_cast<char*>("../res/tex/gui/viginette.png")),
|
||||
crosshair(new TextureRect(&crosshairTexture)),
|
||||
viginette(new TextureRect(&viginetteTexture)) {
|
||||
GameGui::GameGui(glm::vec2 bufferSize, TextureAtlas& atlas) :
|
||||
crosshairRef(atlas.getTextureRef("crosshair")),
|
||||
viginetteRef(atlas.getTextureRef("viginette")) {
|
||||
|
||||
crosshair->setPos(glm::vec3(bufferSize.x / 2 - 11, bufferSize.y / 2 - 9, 0));
|
||||
crosshair->setScale(22);
|
||||
crosshair.create({22, 22}, {}, crosshairRef);
|
||||
crosshair.setPos({bufferSize.x / 2 - 11, bufferSize.y / 2 - 9});
|
||||
viginette.create(bufferSize, {}, viginetteRef);
|
||||
}
|
||||
|
||||
addDrawable(crosshair);
|
||||
|
||||
viginette->setScale(glm::vec3(bufferSize.x, bufferSize.y, 1));
|
||||
viginette->setPos(glm::vec3(0, 0, -5));
|
||||
|
||||
addDrawable(viginette);
|
||||
void GameGui::draw(Renderer &renderer) {
|
||||
viginette.draw(renderer);
|
||||
crosshair.draw(renderer);
|
||||
}
|
||||
|
||||
void GameGui::bufferResized(glm::vec2 bufferSize) {
|
||||
crosshair->setPos(glm::vec3(bufferSize.x / 2 - 11, bufferSize.y / 2 - 9, 0));
|
||||
viginette->setScale(glm::vec3(bufferSize.x, bufferSize.y, 1));
|
||||
crosshair.setPos({bufferSize.x / 2 - 11, bufferSize.y / 2 - 9});
|
||||
viginette.setScale({bufferSize.x, bufferSize.y});
|
||||
}
|
||||
|
||||
void GameGui::setVisible(bool visible) {
|
||||
this->visible = visible;
|
||||
|
||||
crosshair->setVisible(visible);
|
||||
viginette->setVisible(visible);
|
||||
}
|
||||
crosshair.setVisible(visible);
|
||||
viginette.setVisible(visible);
|
||||
}
|
||||
|
|
|
@ -5,24 +5,25 @@
|
|||
#ifndef ZEUS_GAMEGUI_H
|
||||
#define ZEUS_GAMEGUI_H
|
||||
|
||||
#include "TextureRect.h"
|
||||
#include "components/basic/GUIRect.h"
|
||||
#include "../Entity.h"
|
||||
#include "../../ClientState.h"
|
||||
#include "../../graph/drawable/DrawableGroup.h"
|
||||
|
||||
class GameGui : public DrawableGroup {
|
||||
class GameGui : public Drawable {
|
||||
public:
|
||||
explicit GameGui(glm::vec2 bufferSize);
|
||||
explicit GameGui(glm::vec2 bufferSize, TextureAtlas& atlas);
|
||||
|
||||
void draw(Renderer& renderer) override;
|
||||
|
||||
void bufferResized(glm::vec2 bufferSize);
|
||||
|
||||
void setVisible(bool visible) override;
|
||||
private:
|
||||
Texture crosshairTexture;
|
||||
Texture viginetteTexture;
|
||||
std::shared_ptr<AtlasRef> crosshairRef;
|
||||
std::shared_ptr<AtlasRef> viginetteRef;
|
||||
|
||||
TextureRect* crosshair;
|
||||
TextureRect* viginette;
|
||||
GUIRect crosshair;
|
||||
GUIRect viginette;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -9,11 +9,10 @@ StatGraph::StatGraph(const std::string& title, int graphLength, int graphScale,
|
|||
|
||||
StatGraph::StatGraph(const std::string& title, int xSize, int ySize, int graphLength, int graphScale, Texture* graphTex, Texture* textTex) :
|
||||
title(title),
|
||||
background({0.1, 0.1, 0.1, 0.2}, {0.1, 0.1, 0.1, 0.2}, {0.1, 0.1, 0.1, 0.7}, {0.1, 0.1, 0.1, 0.7}),
|
||||
graph(graphTex, graphLength, graphScale, true),
|
||||
text(textTex) {
|
||||
|
||||
background.setScale({xSize, ySize, 1});
|
||||
background.create({xSize, ySize}, {}, {0.1, 0.1, 0.1, 0.2}, {0.1, 0.1, 0.1, 0.2}, {0.1, 0.1, 0.1, 0.7}, {0.1, 0.1, 0.1, 0.7});
|
||||
graph.setScale({(xSize - GRAPH_PAD_X * 2) / graphLength, 28, 1});
|
||||
text.setScale(2);
|
||||
|
||||
|
@ -26,7 +25,7 @@ StatGraph::StatGraph(const std::string& title, int xSize, int ySize, int graphLe
|
|||
void StatGraph::setPos(glm::vec2 pos) {
|
||||
text.setPos({pos.x + TEXT_PAD_X, pos.y + TEXT_PAD_Y, 0});
|
||||
graph.setPos({pos.x + GRAPH_PAD_X, pos.y + GRAPH_PAD_Y, 0});
|
||||
background.setPos({pos.x, pos.y, 0});
|
||||
background.setPos({pos.x, pos.y});
|
||||
}
|
||||
|
||||
void StatGraph::update(float value) {
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#define ZEUS_STATGRAPH_H
|
||||
|
||||
#include "../Entity.h"
|
||||
#include "TextureRect.h"
|
||||
#include "GraphEntity.h"
|
||||
#include "TextEntity.h"
|
||||
#include "components/basic/GUIRect.h"
|
||||
#include "components/GraphEntity.h"
|
||||
#include "components/TextEntity.h"
|
||||
#include "../../../util/Util.h"
|
||||
|
||||
class StatGraph : public Drawable {
|
||||
|
@ -26,7 +26,7 @@ private:
|
|||
int ind = 0;
|
||||
float history[5];
|
||||
|
||||
TextureRect background;
|
||||
GUIRect background;
|
||||
GraphEntity graph;
|
||||
TextEntity text;
|
||||
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 10/02/19.
|
||||
//
|
||||
|
||||
#include "TextureRect.h"
|
||||
|
||||
TextureRect::TextureRect(glm::vec4 color) {
|
||||
createColored(color, color, color, color);
|
||||
}
|
||||
|
||||
TextureRect::TextureRect(glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br) {
|
||||
createColored(tl, tr, bl, br);
|
||||
}
|
||||
|
||||
TextureRect::TextureRect(Texture *texture) {
|
||||
createTextured(texture);
|
||||
}
|
||||
|
||||
void TextureRect::createColored(glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br) {
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{0, 0, 0}, {tl.x, tl.y, tl.z, tl.w}, false, {}},
|
||||
{{0, 1, 0}, {bl.x, bl.y, bl.z, bl.w}, false, {}},
|
||||
{{1, 1, 0}, {br.x, br.y, br.z, br.w}, false, {}},
|
||||
{{1, 0, 0}, {tr.x, tr.y, tr.z, tr.w}, false, {}},
|
||||
};
|
||||
std::vector<unsigned int> indices { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
auto m = new EntityMesh();
|
||||
m->create(vertices, indices);
|
||||
|
||||
setMesh(m);
|
||||
}
|
||||
|
||||
|
||||
void TextureRect::createTextured(Texture *texture) {
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{0, 0, 0}, {0, 0, 0, 0}, true, {0, 0, 0}},
|
||||
{{0, 1, 0}, {0, 1, 0, 0}, true, {0, 0, 0}},
|
||||
{{1, 1, 0}, {1, 1, 0, 0}, true, {0, 0, 0}},
|
||||
{{1, 0, 0}, {1, 0, 0, 0}, true, {0, 0, 0}},
|
||||
};
|
||||
std::vector<unsigned int> indices { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
auto m = new EntityMesh();
|
||||
m->create(vertices, indices);
|
||||
|
||||
setMesh(m, texture);
|
||||
}
|
||||
|
||||
void TextureRect::setTexture(Texture *texture) {
|
||||
createTextured(texture);
|
||||
}
|
||||
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 10/02/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_RECTENTITY_H
|
||||
#define ZEUS_RECTENTITY_H
|
||||
|
||||
|
||||
#include "../Entity.h"
|
||||
|
||||
class TextureRect : public Entity {
|
||||
public:
|
||||
TextureRect() = default;
|
||||
|
||||
explicit TextureRect(glm::vec4 color);
|
||||
TextureRect(glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br);
|
||||
|
||||
void setTexture(Texture* texture);
|
||||
|
||||
explicit TextureRect(Texture* texture);
|
||||
private:
|
||||
void createColored(glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br);
|
||||
void createTextured(Texture* texture);
|
||||
|
||||
using Entity::setTexture;
|
||||
};
|
||||
|
||||
|
||||
#endif //ZEUS_RECTENTITY_H
|
|
@ -0,0 +1,61 @@
|
|||
#include <utility>
|
||||
|
||||
//
|
||||
// Created by aurailus on 27/07/19.
|
||||
//
|
||||
|
||||
#include "GUIComponent.h"
|
||||
|
||||
GUIComponent::GUIComponent(const std::string& key, GUIComponent *parent) :
|
||||
key(key),
|
||||
parent(parent) {}
|
||||
|
||||
void GUIComponent::setScale(glm::vec2 scale) {
|
||||
this->scale = scale;
|
||||
entity.setScale({scale.x, scale.y, 1});
|
||||
}
|
||||
|
||||
glm::vec2 GUIComponent::getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
void GUIComponent::setPadding(glm::vec4 padding) {
|
||||
this->padding = padding;
|
||||
}
|
||||
|
||||
glm::vec4 GUIComponent::getPadding() {
|
||||
return padding;
|
||||
}
|
||||
|
||||
void GUIComponent::setPos(glm::vec2 pos) {
|
||||
this->pos = pos;
|
||||
entity.setPos({pos.x, pos.y, 0});
|
||||
}
|
||||
|
||||
glm::vec2 GUIComponent::getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
void GUIComponent::set(std::string key, std::shared_ptr<GUIComponent> component) {
|
||||
children[key] = std::move(component);
|
||||
}
|
||||
|
||||
std::shared_ptr<GUIComponent> GUIComponent::operator[](std::string) {
|
||||
return children[key];
|
||||
}
|
||||
|
||||
void GUIComponent::remove(std::string key) {
|
||||
children.erase(key);
|
||||
}
|
||||
|
||||
void GUIComponent::draw(Renderer& renderer) {
|
||||
entity.draw(renderer);
|
||||
for (const auto& child : children) {
|
||||
child.second->draw(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
void GUIComponent::setVisible(bool visible) {
|
||||
Drawable::setVisible(visible);
|
||||
entity.setVisible(visible);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// Created by aurailus on 27/07/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_GUICOMPONENT_H
|
||||
#define ZEUS_GUICOMPONENT_H
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include "../../Entity.h"
|
||||
|
||||
class GUIComponent : Drawable {
|
||||
public:
|
||||
GUIComponent() = default;
|
||||
GUIComponent(const std::string& key, GUIComponent* parent);
|
||||
|
||||
virtual void setScale(glm::vec2 scale);
|
||||
virtual glm::vec2 getScale();
|
||||
|
||||
virtual void setPadding(glm::vec4 padding);
|
||||
virtual glm::vec4 getPadding();
|
||||
|
||||
virtual void setPos(glm::vec2 pos);
|
||||
virtual glm::vec2 getPos();
|
||||
|
||||
void set(std::string key, std::shared_ptr<GUIComponent> component);
|
||||
void remove(std::string key);
|
||||
std::shared_ptr<GUIComponent> operator[](std::string);
|
||||
|
||||
void setVisible(bool visible) override;
|
||||
|
||||
void draw(Renderer& renderer) override;
|
||||
protected:
|
||||
std::string key = "";
|
||||
GUIComponent* parent = nullptr;
|
||||
std::unordered_map<std::string, std::shared_ptr<GUIComponent>> children;
|
||||
|
||||
glm::vec2 pos {};
|
||||
glm::vec2 scale {};
|
||||
glm::vec4 padding {};
|
||||
bool visible = true;
|
||||
|
||||
Entity entity;
|
||||
};
|
||||
|
||||
|
||||
#endif //ZEUS_GUICOMPONENT_H
|
|
@ -6,7 +6,7 @@
|
|||
#define ZEUS_HISTOGRAM_H
|
||||
|
||||
|
||||
#include "../Entity.h"
|
||||
#include "../../Entity.h"
|
||||
|
||||
class GraphEntity : public Entity {
|
||||
public:
|
|
@ -6,7 +6,7 @@
|
|||
#define ZEUS_TEXTENTITY_H
|
||||
|
||||
|
||||
#include "../Entity.h"
|
||||
#include "../../Entity.h"
|
||||
|
||||
class TextEntity : public Entity {
|
||||
public:
|
|
@ -0,0 +1,70 @@
|
|||
//
|
||||
// Created by aurailus on 10/02/19.
|
||||
//
|
||||
|
||||
#include "GUIRect.h"
|
||||
|
||||
GUIRect::GUIRect(const std::string &key, GUIComponent *parent) : GUIComponent(key, parent) {}
|
||||
|
||||
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 color) {
|
||||
// Single Color Constructor
|
||||
// Creates a GUIRect object whose background
|
||||
// is a flat color defined by 'color'.
|
||||
|
||||
this->scale = scale;
|
||||
this->padding = padding;
|
||||
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{0, 0, 0}, {color}, false, {}}, {{0, 1, 0}, {color}, false, {}},
|
||||
{{1, 1, 0}, {color}, false, {}}, {{1, 0, 0}, {color}, false, {}}
|
||||
};
|
||||
std::vector<unsigned int> indices {0, 1, 2, 2, 3, 0};
|
||||
|
||||
auto mesh = new EntityMesh();
|
||||
mesh->create(vertices, indices);
|
||||
entity.setMesh(mesh);
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z, 1});
|
||||
}
|
||||
|
||||
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br) {
|
||||
// Multiple Color Constructor
|
||||
// Creates a GUIRect object with a gradient background
|
||||
// defined by 'tl', 'tr', 'bl', and 'br'.
|
||||
|
||||
this->scale = scale;
|
||||
this->padding = padding;
|
||||
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{0, 0, 0}, tl, false, {}}, {{0, 1, 0}, bl, false, {}},
|
||||
{{1, 1, 0}, br, false, {}}, {{1, 0, 0}, tr, false, {}}
|
||||
};
|
||||
std::vector<unsigned int> indices {0, 1, 2, 2, 3, 0};
|
||||
|
||||
auto mesh = new EntityMesh();
|
||||
mesh->create(vertices, indices);
|
||||
entity.setMesh(mesh);
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z, 1});
|
||||
}
|
||||
|
||||
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture) {
|
||||
// Texture Constructor
|
||||
// Creates a GUIRect object with a textured background
|
||||
// defined by the 'texture' reference.
|
||||
|
||||
this->scale = scale;
|
||||
this->padding = padding;
|
||||
this->texture = std::move(texture);
|
||||
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{0, 0, 0}, {this->texture->uv.x, this->texture->uv.y, 0, 0}, true, {}},
|
||||
{{0, 1, 0}, {this->texture->uv.x, this->texture->uv.w, 0, 0}, true, {}},
|
||||
{{1, 1, 0}, {this->texture->uv.z, this->texture->uv.w, 0, 0}, true, {}},
|
||||
{{1, 0, 0}, {this->texture->uv.z, this->texture->uv.y, 0, 0}, true, {}}
|
||||
};
|
||||
std::vector<unsigned int> indices {0, 1, 2, 2, 3, 0};
|
||||
|
||||
auto mesh = new EntityMesh();
|
||||
mesh->create(vertices, indices);
|
||||
entity.setMesh(mesh);
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z, 1});
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// Created by aurailus on 10/02/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_RECTENTITY_H
|
||||
#define ZEUS_RECTENTITY_H
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include "../GUIComponent.h"
|
||||
#include "../../../../../def/texture/AtlasRef.h"
|
||||
|
||||
class GUIRect : public GUIComponent {
|
||||
public:
|
||||
GUIRect() = default;
|
||||
GUIRect(const std::string& key, GUIComponent* parent);
|
||||
|
||||
void create(glm::vec2 scale, glm::vec4 padding, glm::vec4 color);
|
||||
void create(glm::vec2 scale, glm::vec4 padding, glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br);
|
||||
void create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture);
|
||||
private:
|
||||
std::shared_ptr<AtlasRef> texture = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif //ZEUS_RECTENTITY_H
|
|
@ -230,6 +230,7 @@ void Renderer::beginEntityDeferredCalls() {
|
|||
}
|
||||
|
||||
void Renderer::endDeferredCalls() {
|
||||
activeTexture = nullptr;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
auto winSize = window.getSize();
|
||||
|
@ -265,6 +266,7 @@ void Renderer::endDeferredCalls() {
|
|||
}
|
||||
|
||||
void Renderer::beginGUIDrawCalls() {
|
||||
activeTexture = nullptr;
|
||||
currentModelUniform = gu.model;
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -318,7 +320,7 @@ void Renderer::setModelMatrix(const glm::mat4& modelMatrix) {
|
|||
void Renderer::enableTexture(Texture *texture) {
|
||||
if (texture != activeTexture) {
|
||||
activeTexture = texture;
|
||||
texture->use();
|
||||
texture->use(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ Window::Window(GLint windowWidth, GLint windowHeight) {
|
|||
centerX = width / 2;
|
||||
centerY = height / 2;
|
||||
|
||||
mouseLocked = true;
|
||||
forceMouseUnlocked = false;
|
||||
mouseIsLocked = false;
|
||||
resized = false;
|
||||
}
|
||||
|
||||
|
@ -68,7 +69,7 @@ int Window::initialize() {
|
|||
glfwSetWindowUserPointer(mainWindow, this);
|
||||
glfwSetKeyCallback(mainWindow, handleKeys);
|
||||
glfwSetWindowSizeCallback(mainWindow, handleResize);
|
||||
glfwSetInputMode(mainWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
glfwSetInputMode(mainWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
|
||||
glfwMaximizeWindow(mainWindow);
|
||||
|
||||
|
@ -78,16 +79,19 @@ int Window::initialize() {
|
|||
void Window::update() {
|
||||
double mouseX, mouseY;
|
||||
if (glfwGetWindowAttrib(mainWindow, GLFW_FOCUSED) == GL_FALSE) {
|
||||
mouseLocked = false;
|
||||
mouseIsLocked = false;
|
||||
deltaX = 0;
|
||||
deltaY = 0;
|
||||
}
|
||||
else {
|
||||
glfwGetCursorPos(mainWindow, &mouseX, &mouseY);
|
||||
|
||||
if (!mouseLocked) {
|
||||
//Allow user to grab window edges without locking the mouse
|
||||
if (mouseX > 128 && mouseY > 128 && mouseX < bufferWidth - 128 && mouseY < bufferHeight - 128) mouseLocked = true;
|
||||
if (!mouseIsLocked) {
|
||||
if (!forceMouseUnlocked && input.isMousePressed(GLFW_MOUSE_BUTTON_LEFT)) {
|
||||
glfwSetInputMode(mainWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
glfwSetCursorPos(mainWindow, centerX, centerY);
|
||||
mouseIsLocked = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
deltaX = mouseX - centerX;
|
||||
|
@ -132,6 +136,9 @@ void Window::handleResize(GLFWwindow *glfwWindow, int, int) {
|
|||
glfwGetFramebufferSize(glfwWindow, &window->bufferWidth, &window->bufferHeight);
|
||||
glViewport(0, 0, window->bufferWidth, window->bufferHeight);
|
||||
window->resized = true;
|
||||
|
||||
window->centerX = window->bufferWidth / 2;
|
||||
window->centerY = window->bufferHeight / 2;
|
||||
}
|
||||
|
||||
Window::~Window() {
|
||||
|
@ -150,4 +157,10 @@ bool Window::shouldClose() {
|
|||
|
||||
void Window::swapBuffers() {
|
||||
glfwSwapBuffers(mainWindow);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::lockMouse(bool lock) {
|
||||
forceMouseUnlocked = !lock;
|
||||
if (lock) mouseIsLocked = true;
|
||||
glfwSetInputMode(mainWindow, GLFW_CURSOR, (mouseIsLocked ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
glm::vec2 getSize();
|
||||
bool resized;
|
||||
|
||||
void lockMouse(bool lock);
|
||||
bool shouldClose();
|
||||
|
||||
double getDeltaX();
|
||||
|
@ -38,9 +39,9 @@ private:
|
|||
|
||||
GLint width, height;
|
||||
GLint centerX, centerY;
|
||||
bool mouseLocked;
|
||||
bool mouseIsLocked, forceMouseUnlocked;
|
||||
|
||||
bool keys[1024];
|
||||
bool keys[1024] {};
|
||||
|
||||
GLint bufferWidth, bufferHeight;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <utility>
|
||||
#include "../graph/scene/Scene.h"
|
||||
#include "../entity/hud/TextEntity.h"
|
||||
#include "../entity/hud/components/TextEntity.h"
|
||||
#include "net/ServerConnection.h"
|
||||
|
||||
class ConnectScene : public Scene {
|
||||
|
|
|
@ -11,10 +11,11 @@ GameScene::GameScene(ClientState& state) : Scene(state),
|
|||
|
||||
player(world, defs, state.renderer.getCamera()),
|
||||
|
||||
gameGui (state.renderer.getCamera().getBufferDimensions()),
|
||||
debugGui(state.renderer.getCamera().getBufferDimensions(), &defs.textures().getAtlasTexture()) {
|
||||
gameGui (state.renderer.getCamera().getBufferDimensions(), defs.textures()),
|
||||
debugGui(state.renderer.getCamera().getBufferDimensions(), nullptr) {
|
||||
|
||||
state.renderer.setClearColor(148, 194, 240);
|
||||
state.renderer.getWindow().lockMouse(true);
|
||||
|
||||
defs.init(world);
|
||||
world.init();
|
||||
|
@ -84,6 +85,8 @@ void GameScene::draw() {
|
|||
renderer.endDeferredCalls();
|
||||
renderer.beginGUIDrawCalls();
|
||||
|
||||
renderer.enableTexture(&defs.textures().getAtlasTexture());
|
||||
defs.textures().getAtlasTexture().use(0);
|
||||
for (auto entity : gui) entity->draw(renderer);
|
||||
|
||||
renderer.swapBuffers();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "../../game/ClientState.h"
|
||||
#include "../../game/graph/scene/Scene.h"
|
||||
#include "../entity/hud/TextEntity.h"
|
||||
#include "../entity/hud/components/TextEntity.h"
|
||||
|
||||
class MenuScene : public Scene {
|
||||
public:
|
||||
|
|
|
@ -143,7 +143,7 @@ void Player::pointerUpdate(InputManager &input, double delta) {
|
|||
}
|
||||
if (input.isMousePressed(GLFW_MOUSE_BUTTON_RIGHT)) {
|
||||
world.localSetBlock(pointedThing.pos + SelectionBox::faceToOffset(pointedThing.face),
|
||||
defs.blocks().fromIdentifier("kinetic:axle_0").index);
|
||||
defs.blocks().fromIdentifier("default:open_formspec").index);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -11,10 +11,7 @@ void ServerClients::handleConnect(ENetEvent e) {
|
|||
std::cout << Log::info << NetHandler::intToIPString(addr.host) << ":" << addr.port << " connected." << Log::endl;
|
||||
|
||||
clients.emplace_back(peer, addr);
|
||||
ServerClient& client = clients.back();
|
||||
|
||||
//TODO: Create this later
|
||||
peer->data = &client;
|
||||
peer->data = &clients.back();
|
||||
}
|
||||
|
||||
void ServerClients::handleDisconnect(ENetEvent e) {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
class ServerPlayer {
|
||||
public:
|
||||
const static int ACTIVE_RANGE_H = 16;
|
||||
const static int ACTIVE_RANGE_H = 8;
|
||||
const static int ACTIVE_RANGE_V = 8;
|
||||
|
||||
explicit ServerPlayer(glm::vec3 pos, unsigned int connectID, const std::string& username);
|
||||
|
|
|
@ -59,7 +59,7 @@ void Dimension::update() {
|
|||
float distance = max(abs(diffVec.x), max(abs(diffVec.y), abs(diffVec.z)));
|
||||
|
||||
//TODO: Don't hard code this number
|
||||
if (distance > 24) {
|
||||
if (distance >= 16) {
|
||||
if (chunk->meshChunk != nullptr) {
|
||||
meshChunks.erase(chunk->meshChunkIter);
|
||||
delete chunk->meshChunk;
|
||||
|
|
Loading…
Reference in New Issue