Standarize Gui casing

master
Nicole Collings 2020-02-20 16:58:36 -08:00
parent 707ccb6a51
commit 391a90d399
39 changed files with 360 additions and 360 deletions

View File

@ -33,8 +33,8 @@ set(ZEPHA_SRC
game/graph/Renderer.h
lua/parser/LocalLuaParser.cpp
lua/parser/LocalLuaParser.h
game/hud/components/basic/GUIText.cpp
game/hud/components/basic/GUIText.h
game/hud/components/basic/GuiText.cpp
game/hud/components/basic/GuiText.h
game/hud/DebugGui.cpp
game/hud/DebugGui.h
game/scene/world/Player.cpp
@ -66,10 +66,10 @@ set(ZEPHA_SRC
server/conn/ServerClient.h
util/net/PacketChannel.h
game/entity/engine/PlayerEntity.h
game/hud/components/basic/GUIRect.cpp
game/hud/components/basic/GUIRect.h
game/hud/components/basic/GUIGraph.cpp
game/hud/components/basic/GUIGraph.h
game/hud/components/basic/GuiRect.cpp
game/hud/components/basic/GuiRect.h
game/hud/components/basic/GuiGraph.cpp
game/hud/components/basic/GuiGraph.h
def/gen/MapGenJob.h
util/Interp.h
def/gen/NoiseSample.cpp
@ -113,8 +113,8 @@ set(ZEPHA_SRC
world/region/MapBlock.cpp
util/Util.h
world/block/PointedThing.h
game/hud/components/compound/GUILabelledGraph.cpp
game/hud/components/compound/GUILabelledGraph.cpp
game/hud/components/compound/GuiLabelledGraph.cpp
game/hud/components/compound/GuiLabelledGraph.cpp
game/entity/engine/ParticleEntity.cpp
game/entity/engine/ParticleEntity.h
def/ServerGame.cpp
@ -145,10 +145,10 @@ set(ZEPHA_SRC
game/scene/net/ServerConnection.cpp
game/scene/net/ServerConnection.h
game/scene/world/MeshDetails.h
game/hud/components/GUIComponent.cpp
game/hud/components/GUIComponent.h
game/hud/components/basic/GUIContainer.cpp
game/hud/components/basic/GUIContainer.h
game/hud/components/GuiComponent.cpp
game/hud/components/GuiComponent.h
game/hud/components/basic/GuiContainer.cpp
game/hud/components/basic/GuiContainer.h
lua/LuaModFile.h
lua/LuaMod.h
lua/LuaModConfig.h
@ -209,10 +209,10 @@ set(ZEPHA_SRC
lua/api/type/LocalLuaPlayer.h
game/entity/Collidable.cpp
game/entity/Collidable.h
game/hud/components/compound/GUIInventoryList.cpp
game/hud/components/compound/GUIInventoryList.h
game/hud/components/basic/GUIInventoryItem.cpp
game/hud/components/basic/GUIInventoryItem.h
game/hud/components/compound/GuiInventoryList.cpp
game/hud/components/compound/GuiInventoryList.h
game/hud/components/basic/GuiInventoryItem.cpp
game/hud/components/basic/GuiInventoryItem.h
game/scene/world/InventoryList.cpp
game/scene/world/InventoryList.h
game/scene/world/ItemStack.h
@ -232,8 +232,8 @@ set(ZEPHA_SRC
world/Dimension.cpp
world/Dimension.h
def/texture/RawTexData.h
game/hud/components/compound/GUIImageButton.cpp
game/hud/components/compound/GUIImageButton.h
game/hud/components/compound/GuiImageButton.cpp
game/hud/components/compound/GuiImageButton.h
game/ClientState.cpp
game/scene/menu/Subgame.cpp
game/scene/menu/Subgame.h
@ -258,8 +258,8 @@ set(ZEPHA_SRC
game/scene/world/ItemStack.cpp
lua/api/type/cLuaInventory.h
lua/api/type/cLuaItemStack.h
game/hud/components/basic/GUIModel.cpp
game/hud/components/basic/GUIModel.h
game/hud/components/basic/GuiModel.cpp
game/hud/components/basic/GuiModel.h
server/world/ServerEntity.cpp
server/world/ServerEntity.h
lua/api/type/ServerLuaEntity.cpp

View File

@ -4,7 +4,7 @@
#include "DebugGui.h"
#include "../../def/texture/Font.h"
#include "components/compound/GUIInventoryList.h"
#include "components/compound/GuiInventoryList.h"
DebugGui::DebugGui(glm::vec2 bufferSize, ClientGame& defs) :
displayMode(0) {
@ -15,39 +15,39 @@ DebugGui::DebugGui(glm::vec2 bufferSize, ClientGame& defs) :
Font f(defs.textures, fontRef);
auto crosshairText = std::make_shared<GUIText>("crosshairText");
auto crosshairText = std::make_shared<GuiText>("crosshairText");
crosshairText->create({2, 2}, {}, {0.2, 0.2, 0.2, 0.5}, {1, 1, 1, 1}, f);
add(crosshairText);
auto dataText = std::make_shared<GUIText>("dataText");
auto dataText = std::make_shared<GuiText>("dataText");
dataText->create({2, 2}, {}, {0.2, 0.2, 0.2, 0.5}, {1, 1, 1, 1}, f);
add(dataText);
auto interpGraph = std::make_shared<GUILabelledGraph>("interpGraph");
auto interpGraph = std::make_shared<GuiLabelledGraph>("interpGraph");
interpGraph->create({244, 64}, {}, "Interp", 120, 256, genericHistogramRef, f);
add(interpGraph);
auto meshGraph = std::make_shared<GUILabelledGraph>("meshGraph");
auto meshGraph = std::make_shared<GuiLabelledGraph>("meshGraph");
meshGraph->create({244, 64}, {}, "Mesh", 120, 32, genericHistogramRef, f);
add(meshGraph);
auto genGraph = std::make_shared<GUILabelledGraph>("genGraph");
auto genGraph = std::make_shared<GuiLabelledGraph>("genGraph");
genGraph->create({244, 64}, {}, "Gen", 120, 256, genericHistogramRef, f);
add(genGraph);
auto packetGraph = std::make_shared<GUILabelledGraph>("packetGraph");
auto packetGraph = std::make_shared<GuiLabelledGraph>("packetGraph");
packetGraph->create({244, 64}, {}, "Packets", 120, 512, genericHistogramRef, f);
add(packetGraph);
auto fpsGraph = std::make_shared<GUILabelledGraph>("fpsGraph");
auto fpsGraph = std::make_shared<GuiLabelledGraph>("fpsGraph");
fpsGraph->create({244, 64}, {}, "FPS", 120, 60, fpsHistogramRef, f);
add(fpsGraph);
auto drawsGraph = std::make_shared<GUILabelledGraph>("drawsGraph");
auto drawsGraph = std::make_shared<GuiLabelledGraph>("drawsGraph");
drawsGraph->create({244, 64}, {}, "Draw Calls", 120, 0, genericHistogramRef, f);
add(drawsGraph);
auto gpuGraph = std::make_shared<GUILabelledGraph>("gpuGraph");
auto gpuGraph = std::make_shared<GuiLabelledGraph>("gpuGraph");
gpuGraph->create({244, 64}, {}, "GPU", 120, 1, genericHistogramRef, f);
add(gpuGraph);
@ -58,40 +58,40 @@ void DebugGui::positionElements(glm::vec2 bufferSize) {
auto bufferWidth = (int)bufferSize.x;
auto bufferHeight = (int)bufferSize.y;
get<GUIText>("crosshairText")->setPos({bufferWidth / 2 + 22, bufferHeight / 2 - 7});
get<GUIText>("dataText")->setPos({10, 10});
get<GuiText>("crosshairText")->setPos({bufferWidth / 2 + 22, bufferHeight / 2 - 7});
get<GuiText>("dataText")->setPos({10, 10});
get<GUILabelledGraph>("genGraph")->setPos({bufferWidth - 254, bufferHeight - 70 - 160});
get<GUILabelledGraph>("packetGraph")->setPos({bufferWidth - 254, bufferHeight - 70 - 240});
get<GUILabelledGraph>("meshGraph")->setPos({bufferWidth - 254, bufferHeight - 70 - 80});
get<GUILabelledGraph>("interpGraph")->setPos({bufferWidth - 254, bufferHeight - 70});
get<GuiLabelledGraph>("genGraph")->setPos({bufferWidth - 254, bufferHeight - 70 - 160});
get<GuiLabelledGraph>("packetGraph")->setPos({bufferWidth - 254, bufferHeight - 70 - 240});
get<GuiLabelledGraph>("meshGraph")->setPos({bufferWidth - 254, bufferHeight - 70 - 80});
get<GuiLabelledGraph>("interpGraph")->setPos({bufferWidth - 254, bufferHeight - 70});
get<GUILabelledGraph>("fpsGraph")->setPos({bufferWidth - 254, 10});
get<GUILabelledGraph>("drawsGraph")->setPos({bufferWidth - 254, 90});
get<GUILabelledGraph>("gpuGraph")->setPos({bufferWidth - 254, 90 + 80});
get<GuiLabelledGraph>("fpsGraph")->setPos({bufferWidth - 254, 10});
get<GuiLabelledGraph>("drawsGraph")->setPos({bufferWidth - 254, 90});
get<GuiLabelledGraph>("gpuGraph")->setPos({bufferWidth - 254, 90 + 80});
}
void DebugGui::update(Player& player, LocalWorld& world, ClientGame& defs, double fps, int /*chunks*/, int drawCalls, int ssGen, int ssPack) {
{ //Top Right Graphs
get<GUILabelledGraph>("fpsGraph")->pushValue(static_cast<float>(fps));
get<GUILabelledGraph>("drawsGraph")->pushValue(drawCalls);
get<GuiLabelledGraph>("fpsGraph")->pushValue(static_cast<float>(fps));
get<GuiLabelledGraph>("drawsGraph")->pushValue(drawCalls);
int videoMemAvail, videoMemTotal;
glGetIntegerv(0x9048, &videoMemTotal);
glGetIntegerv(0x9049, &videoMemAvail);
get<GUILabelledGraph>("gpuGraph")->pushValue(static_cast<int>(std::round(
get<GuiLabelledGraph>("gpuGraph")->pushValue(static_cast<int>(std::round(
(videoMemTotal - videoMemAvail) / static_cast<float>(videoMemTotal) * 100.0))
/ 100.0f);
/ 100.0f);
}
{ //Bottom Right Graphs
get<GUILabelledGraph>("meshGraph")->pushValue(world.lastMeshUpdates);
get<GUILabelledGraph>("interpGraph")->pushValue(world.lastGenUpdates);
get<GUILabelledGraph>("genGraph")->pushValue(static_cast<float>(ssGen));
get<GUILabelledGraph>("packetGraph")->pushValue(static_cast<float>(ssPack));
get<GuiLabelledGraph>("meshGraph")->pushValue(world.lastMeshUpdates);
get<GuiLabelledGraph>("interpGraph")->pushValue(world.lastGenUpdates);
get<GuiLabelledGraph>("genGraph")->pushValue(static_cast<float>(ssGen));
get<GuiLabelledGraph>("packetGraph")->pushValue(static_cast<float>(ssPack));
}
{ //Top-left Data
@ -159,7 +159,7 @@ void DebugGui::update(Player& player, LocalWorld& world, ClientGame& defs, doubl
str << "No Target";
}
get<GUIText>("dataText")->setText(str.str());
get<GuiText>("dataText")->setText(str.str());
}
{ //Crosshair Text
@ -170,7 +170,7 @@ void DebugGui::update(Player& player, LocalWorld& world, ClientGame& defs, doubl
crossText << defs.defs.blockFromId(thing.target.block.blockId).name
<< " (" << defs.defs.blockFromId(thing.target.block.blockId).identifier << ")" << std::endl;
}
get<GUIText>("crosshairText")->setText(crossText.str());
get<GuiText>("crosshairText")->setText(crossText.str());
}
}
@ -183,5 +183,5 @@ void DebugGui::changeVisibilityState(int state) {
displayMode = state;
setVisible(displayMode == 0);
get<GUILabelledGraph>("fpsGraph")->setVisible(displayMode != 1);
get<GuiLabelledGraph>("fpsGraph")->setVisible(displayMode != 1);
}

View File

@ -10,14 +10,14 @@
#include "../../util/Space.h"
#include "../../util/Util.h"
#include "../../util/Ray.h"
#include "components/compound/GUILabelledGraph.h"
#include "components/basic/GUIRect.h"
#include "components/basic/GUIGraph.h"
#include "components/basic/GUIText.h"
#include "components/basic/GUIContainer.h"
#include "components/compound/GuiLabelledGraph.h"
#include "components/basic/GuiRect.h"
#include "components/basic/GuiGraph.h"
#include "components/basic/GuiText.h"
#include "components/basic/GuiContainer.h"
#include "../scene/world/InventoryList.h"
class DebugGui : public GUIContainer {
class DebugGui : public GuiContainer {
public:
DebugGui(glm::vec2 bufferSize, ClientGame& atlas);

View File

@ -3,11 +3,11 @@
//
#include "GameGui.h"
#include "components/compound/GUIInventoryList.h"
#include "components/compound/GuiInventoryList.h"
GameGui::GameGui(Inventory& inventory, InventoryList& hand, glm::vec2 bufferSize, ClientGame& defs, Renderer& renderer) :
menuRoot(std::make_shared<GUIContainer>("__luaroot")),
handList(std::make_shared<GUIInventoryList>("hand")),
menuRoot(std::make_shared<GuiContainer>("__luaroot")),
handList(std::make_shared<GuiInventoryList>("hand")),
builder(inventory, hand, defs, menuRoot),
inventory(inventory),
renderer(renderer),
@ -15,12 +15,12 @@ GameGui::GameGui(Inventory& inventory, InventoryList& hand, glm::vec2 bufferSize
hand(hand),
defs(defs) {
auto crosshair = std::make_shared<GUIRect>("crosshair");
auto crosshair = std::make_shared<GuiRect>("crosshair");
crosshair->create({22, 22}, {}, defs.textures["crosshair"]);
crosshair->setPos({bufferSize.x / 2 - 11, bufferSize.y / 2 - 9});
builtIn.add(crosshair);
auto viginette = std::make_shared<GUIRect>("viginette");
auto viginette = std::make_shared<GuiRect>("viginette");
viginette->create(bufferSize, {}, defs.textures["viginette"]);
builtIn.add(viginette);
@ -50,8 +50,8 @@ void GameGui::update(double delta) {
void GameGui::winResized(glm::ivec2 win) {
this->win = win;
builtIn.get<GUIRect>("crosshair")->setPos({win.x / 2 - 11, win.y / 2 - 9});
builtIn.get<GUIRect>("viginette")->setScale(win);
builtIn.get<GuiRect>("crosshair")->setPos({win.x / 2 - 11, win.y / 2 - 9});
builtIn.get<GuiRect>("viginette")->setScale(win);
builder.build(win);
}
@ -72,7 +72,7 @@ const std::string &GameGui::getMenuState() {
}
void GameGui::setVisible(bool visible) {
GUIComponent::setVisible(visible);
GuiComponent::setVisible(visible);
builtIn.setVisible(visible);
}

View File

@ -6,17 +6,17 @@
#include "GameGuiBuilder.h"
#include "SerialGui.h"
#include "components/basic/GUIText.h"
#include "components/basic/GUIRect.h"
#include "components/basic/GUIContainer.h"
#include "components/basic/GuiText.h"
#include "components/basic/GuiRect.h"
#include "components/basic/GuiContainer.h"
#include "../graph/drawable/DrawableGroup.h"
#include "../scene/world/InventoryList.h"
#include "../entity/Entity.h"
#include "../../util/Util.h"
#include "components/compound/GUIInventoryList.h"
#include "components/compound/GuiInventoryList.h"
#include "../scene/world/Inventory.h"
class GameGui : public GUIContainer {
class GameGui : public GuiContainer {
public:
explicit GameGui(Inventory& inventory, InventoryList& hand, glm::vec2 bufferSize, ClientGame& defs, Renderer& renderer);
void winResized(glm::ivec2 win);
@ -36,9 +36,9 @@ private:
glm::ivec2 win {};
std::string menuState = "";
std::shared_ptr<GUIContainer> menuRoot = {};
std::shared_ptr<GUIInventoryList> handList = {};
GUIContainer builtIn = {};
std::shared_ptr<GuiContainer> menuRoot = {};
std::shared_ptr<GuiInventoryList> handList = {};
GuiContainer builtIn = {};
GameGuiBuilder builder;
InventoryList& hand;

View File

@ -4,15 +4,15 @@
#include "GameGuiBuilder.h"
#include "components/compound/GUIInventoryList.h"
#include "components/compound/GuiInventoryList.h"
std::shared_ptr<GUIComponent> GameGuiBuilder::createComponent(SerialGui::Elem &data, glm::ivec2 bounds) {
std::shared_ptr<GuiComponent> GameGuiBuilder::createComponent(SerialGui::Elem &data, glm::ivec2 bounds) {
auto c = GuiBuilder::createComponent(data, bounds);
if (c != nullptr) return c;
GUIComponent::callback cbLeftClick = nullptr;
GUIComponent::callback cbRightClick = nullptr;
GUIComponent::callback cbHover = nullptr;
GuiComponent::callback cbLeftClick = nullptr;
GuiComponent::callback cbRightClick = nullptr;
GuiComponent::callback cbHover = nullptr;
if (callbacks.count(data.key)) {
cbLeftClick = callbacks[data.key].left;
@ -23,7 +23,7 @@ std::shared_ptr<GUIComponent> GameGuiBuilder::createComponent(SerialGui::Elem &d
switch (Util::hash(data.type.c_str())) {
default: break;
case Util::hash("inventory"): {
c = GUIInventoryList::fromSerialized(data, game, bounds, inventory, hand);
c = GuiInventoryList::fromSerialized(data, game, bounds, inventory, hand);
break;
}
}

View File

@ -10,10 +10,10 @@
class GameGuiBuilder : public GuiBuilder {
public:
GameGuiBuilder(Inventory& inventory, InventoryList& hand, ClientGame& defs, std::shared_ptr<GUIContainer> root) :
GameGuiBuilder(Inventory& inventory, InventoryList& hand, ClientGame& defs, std::shared_ptr<GuiContainer> root) :
inventory(inventory), hand(hand), GuiBuilder(defs, root) {};
std::shared_ptr<GUIComponent> createComponent(SerialGui::Elem& data, glm::ivec2 bounds) override;
std::shared_ptr<GuiComponent> createComponent(SerialGui::Elem& data, glm::ivec2 bounds) override;
private:
Inventory& inventory;

View File

@ -4,13 +4,13 @@
#include "GuiBuilder.h"
#include "components/basic/GUIRect.h"
#include "components/basic/GUIText.h"
#include "components/basic/GUIModel.h"
#include "components/basic/GUIContainer.h"
#include "components/compound/GUIImageButton.h"
#include "components/basic/GuiRect.h"
#include "components/basic/GuiText.h"
#include "components/basic/GuiModel.h"
#include "components/basic/GuiContainer.h"
#include "components/compound/GuiImageButton.h"
GuiBuilder::GuiBuilder(ClientGame& defs, std::shared_ptr<GUIContainer> root) :
GuiBuilder::GuiBuilder(ClientGame& defs, std::shared_ptr<GuiContainer> root) :
game(defs), root(root) {}
void GuiBuilder::setGui(const std::string& menu, const std::map<std::string, ComponentCallbacks>& callbacks) {
@ -112,21 +112,21 @@ void GuiBuilder::clear(bool clrCallbacks) {
root->empty();
}
void GuiBuilder::recursivelyCreate(std::vector<SerialGui::Elem> components, std::shared_ptr<GUIComponent> parent, glm::ivec2 bounds) {
void GuiBuilder::recursivelyCreate(std::vector<SerialGui::Elem> components, std::shared_ptr<GuiComponent> parent, glm::ivec2 bounds) {
for (auto& data : components) {
std::shared_ptr<GUIComponent> component = createComponent(data, bounds);
std::shared_ptr<GuiComponent> component = createComponent(data, bounds);
if (component == nullptr) continue;
parent->add(component);
recursivelyCreate(data.children, component, bounds);
}
}
std::shared_ptr<GUIComponent> GuiBuilder::createComponent(SerialGui::Elem& data, glm::ivec2 bounds) {
std::shared_ptr<GUIComponent> c = nullptr;
std::shared_ptr<GuiComponent> GuiBuilder::createComponent(SerialGui::Elem& data, glm::ivec2 bounds) {
std::shared_ptr<GuiComponent> c = nullptr;
GUIComponent::callback cbLeftClick = nullptr;
GUIComponent::callback cbRightClick = nullptr;
GUIComponent::callback cbHover = nullptr;
GuiComponent::callback cbLeftClick = nullptr;
GuiComponent::callback cbRightClick = nullptr;
GuiComponent::callback cbHover = nullptr;
if (callbacks.count(data.key)) {
cbLeftClick = callbacks[data.key].left;
@ -137,22 +137,22 @@ std::shared_ptr<GUIComponent> GuiBuilder::createComponent(SerialGui::Elem& data,
switch (Util::hash(data.type.c_str())) {
default: break;
case Util::hash("body"): {
auto body = GUIRect::fromSerialized(data, game, bounds);
auto body = GuiRect::fromSerialized(data, game, bounds);
body->setScale(bounds);
c = body;
break;
}
case Util::hash("rect"):
c = GUIRect::fromSerialized(data, game, bounds);
c = GuiRect::fromSerialized(data, game, bounds);
break;
case Util::hash("button"):
c = GUIImageButton::fromSerialized(data, game, bounds);
c = GuiImageButton::fromSerialized(data, game, bounds);
break;
case Util::hash("text"):
c = GUIText::fromSerialized(data, game, bounds);
c = GuiText::fromSerialized(data, game, bounds);
break;
case Util::hash("model"):
c = GUIModel::fromSerialized(data, game, bounds);
c = GuiModel::fromSerialized(data, game, bounds);
break;
}

View File

@ -6,15 +6,15 @@
#include "SerialGui.h"
#include "../../def/ClientGame.h"
#include "components/GUIComponent.h"
#include "components/GuiComponent.h"
class GUIContainer;
class GuiContainer;
class GuiBuilder {
public:
struct ComponentCallbacks { GUIComponent::callback left {}, right {}, hover {}; };
struct ComponentCallbacks { GuiComponent::callback left {}, right {}, hover {}; };
GuiBuilder(ClientGame& defs, std::shared_ptr<GUIContainer> root);
GuiBuilder(ClientGame& defs, std::shared_ptr<GuiContainer> root);
void setGui(const std::string& menu, const std::map<std::string, ComponentCallbacks>& callbacks = {});
void clear(bool clrCallbacks = true);
void build(glm::ivec2 winBounds);
@ -23,12 +23,12 @@ public:
protected:
void deserialize(const std::string& menu);
void recursivelyCreate(std::vector<SerialGui::Elem> components, std::shared_ptr<GUIComponent> parent, glm::ivec2 bounds);
virtual std::shared_ptr<GUIComponent> createComponent(SerialGui::Elem& component, glm::ivec2 bounds);
void recursivelyCreate(std::vector<SerialGui::Elem> components, std::shared_ptr<GuiComponent> parent, glm::ivec2 bounds);
virtual std::shared_ptr<GuiComponent> createComponent(SerialGui::Elem& component, glm::ivec2 bounds);
std::map<std::string, ComponentCallbacks> callbacks;
ClientGame& game;
std::shared_ptr<GUIContainer> root;
std::shared_ptr<GuiContainer> root;
std::vector<SerialGui::Elem> components {};
};

View File

@ -3,29 +3,29 @@
//
#include <utility>
#include "GUIComponent.h"
#include "GuiComponent.h"
GUIComponent::GUIComponent(const std::string& key) :
GuiComponent::GuiComponent(const std::string& key) :
key(key) {}
void GUIComponent::setScale(glm::vec2 scale) {
void GuiComponent::setScale(glm::vec2 scale) {
this->scale = scale;
entity.setScale({scale.x, scale.y, scale.x});
}
glm::vec2 GUIComponent::getScale() {
glm::vec2 GuiComponent::getScale() {
return scale;
}
void GUIComponent::setPadding(glm::vec4 padding) {
void GuiComponent::setPadding(glm::vec4 padding) {
this->padding = padding;
}
glm::vec4 GUIComponent::getPadding() {
glm::vec4 GuiComponent::getPadding() {
return padding;
}
void GUIComponent::setPos(glm::ivec2 pos) {
void GuiComponent::setPos(glm::ivec2 pos) {
this->pos = pos;
if (parent != nullptr) {
glm::vec3 parentPos = parent->entity.getPos();
@ -38,23 +38,23 @@ void GUIComponent::setPos(glm::ivec2 pos) {
}
}
glm::ivec2 GUIComponent::getPos() {
glm::ivec2 GuiComponent::getPos() {
return pos;
}
void GUIComponent::add(std::shared_ptr<GUIComponent> component) {
void GuiComponent::add(std::shared_ptr<GuiComponent> component) {
component->parent = this;
component->updatePos();
children.push_back(std::move(component));
}
void GUIComponent::insert(unsigned int index, std::shared_ptr<GUIComponent> component) {
void GuiComponent::insert(unsigned int index, std::shared_ptr<GuiComponent> component) {
component->parent = this;
component->updatePos();
children.insert(std::next(children.begin(), index), std::move(component));
}
void GUIComponent::remove(const std::string& key) {
void GuiComponent::remove(const std::string& key) {
for (auto it = children.cbegin(); it != children.cend(); it++) {
if (it->get()->key == key) {
children.erase(it);
@ -63,20 +63,20 @@ void GUIComponent::remove(const std::string& key) {
}
}
void GUIComponent::empty() {
void GuiComponent::empty() {
for (auto it = children.cbegin(); it != children.cend();) {
it = children.erase(it);
}
}
void GUIComponent::draw(Renderer& renderer) {
void GuiComponent::draw(Renderer& renderer) {
entity.draw(renderer);
for (const auto& child : children) {
child->draw(renderer);
}
}
void GUIComponent::setVisible(bool visible) {
void GuiComponent::setVisible(bool visible) {
Drawable::setVisible(visible);
entity.setVisible(visible);
for (const auto& child : children) {
@ -84,7 +84,7 @@ void GUIComponent::setVisible(bool visible) {
}
}
void GUIComponent::updatePos() {
void GuiComponent::updatePos() {
glm::vec2 realPos(pos);
if (parent != nullptr) {
glm::vec3 parentPos = parent->entity.getPos();
@ -97,7 +97,7 @@ void GUIComponent::updatePos() {
}
}
bool GUIComponent::mouseActivity(glm::ivec2 pos) {
bool GuiComponent::mouseActivity(glm::ivec2 pos) {
bool isHovering = false;
for (auto child = children.rbegin(); child != children.rend(); ++child) {
if ((*child)->mouseActivity(pos - (*child)->getPos() - glm::ivec2((*child)->getPadding().y, (*child)->getPadding().x))) isHovering = true;
@ -119,43 +119,43 @@ bool GUIComponent::mouseActivity(glm::ivec2 pos) {
return isHovering;
}
void GUIComponent::update(double delta) {
void GuiComponent::update(double delta) {
for (const auto& child : children) {
child->update(delta);
}
}
bool GUIComponent::leftClickEvent(bool state, glm::ivec2 pos) {
bool GuiComponent::leftClickEvent(bool state, glm::ivec2 pos) {
clickEvent(true, state, pos);
}
bool GUIComponent::rightClickEvent(bool state, glm::ivec2 pos) {
bool GuiComponent::rightClickEvent(bool state, glm::ivec2 pos) {
clickEvent(false, state, pos);
}
void GUIComponent::setHoverCallback(const callback& hoverCallback) {
void GuiComponent::setHoverCallback(const callback& hoverCallback) {
cbHover = hoverCallback;
}
void GUIComponent::setLeftClickCallback(const callback& leftClickCallback) {
void GuiComponent::setLeftClickCallback(const callback& leftClickCallback) {
cbLeftClick = leftClickCallback;
}
void GUIComponent::setRightClickCallback(const callback& rightClickCallback) {
void GuiComponent::setRightClickCallback(const callback& rightClickCallback) {
cbRightClick = rightClickCallback;
}
void GUIComponent::setCallbacks(const callback &left, const callback &right, const callback &hover) {
void GuiComponent::setCallbacks(const callback &left, const callback &right, const callback &hover) {
setLeftClickCallback(left);
setRightClickCallback(right);
setHoverCallback(hover);
}
const std::string &GUIComponent::getKey() {
const std::string &GuiComponent::getKey() {
return key;
}
bool GUIComponent::clickEvent(bool left, bool state, glm::ivec2 pos) {
bool GuiComponent::clickEvent(bool left, bool state, glm::ivec2 pos) {
for (auto child = children.rbegin(); child != children.rend(); ++child) {
glm::ivec2 cp = pos - (*child)->getPos() - glm::ivec2((*child)->getPadding().y, (*child)->getPadding().x);
if ((*child)->clickEvent(left, state, cp)) return true;

View File

@ -9,12 +9,12 @@
#include <list>
#include "../../entity/Entity.h"
class GUIComponent : public Drawable {
class GuiComponent : public Drawable {
public:
typedef std::function<void(bool, glm::ivec2)> callback;
GUIComponent() = default;
explicit GUIComponent(const std::string& key);
GuiComponent() = default;
explicit GuiComponent(const std::string& key);
virtual void setScale(glm::vec2 scale);
virtual glm::vec2 getScale();
@ -36,8 +36,8 @@ public:
virtual void setRightClickCallback(const callback& rightClickCallback);
void setCallbacks(const callback& left, const callback& right, const callback& hover);
void add(std::shared_ptr<GUIComponent> component);
void insert(unsigned int index, std::shared_ptr<GUIComponent> component);
void add(std::shared_ptr<GuiComponent> component);
void insert(unsigned int index, std::shared_ptr<GuiComponent> component);
template<class T> std::shared_ptr<T> get(const std::string &key) {
for (auto &it : children) {
if (it.get()->key == key) {
@ -58,8 +58,8 @@ protected:
bool clickEvent(bool left, bool state, glm::ivec2 pos);
std::string key = "";
GUIComponent* parent = nullptr;
std::list<std::shared_ptr<GUIComponent>> children;
GuiComponent* parent = nullptr;
std::list<std::shared_ptr<GuiComponent>> children;
bool visible = true;

View File

@ -1,13 +0,0 @@
//
// Created by aurailus on 27/07/19.
//
#include "GUIContainer.h"
GUIContainer::GUIContainer(const std::string &key) : GUIComponent(key) {}
void GUIContainer::draw(Renderer &renderer) {
for (const auto& child : children) {
child->draw(renderer);
}
}

View File

@ -1,17 +0,0 @@
//
// Created by aurailus on 27/07/19.
//
#pragma once
#include "../GUIComponent.h"
class GUIContainer : public GUIComponent {
public:
GUIContainer() = default;
explicit GUIContainer(const std::string& key);
void draw(Renderer& renderer) override;
};

View File

@ -0,0 +1,13 @@
//
// Created by aurailus on 27/07/19.
//
#include "GuiContainer.h"
GuiContainer::GuiContainer(const std::string &key) : GuiComponent(key) {}
void GuiContainer::draw(Renderer &renderer) {
for (const auto& child : children) {
child->draw(renderer);
}
}

View File

@ -0,0 +1,17 @@
//
// Created by aurailus on 27/07/19.
//
#pragma once
#include "../GuiComponent.h"
class GuiContainer : public GuiComponent {
public:
GuiContainer() = default;
explicit GuiContainer(const std::string& key);
void draw(Renderer& renderer) override;
};

View File

@ -2,12 +2,12 @@
// Created by aurailus on 08/02/19.
//
#include "GUIGraph.h"
#include "GuiGraph.h"
GUIGraph::GUIGraph(const std::string &key) : GUIComponent(key) {}
GuiGraph::GuiGraph(const std::string &key) : GuiComponent(key) {}
void GUIGraph::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr <AtlasRef> texture,
unsigned int length, float maxValue, bool editInPlace) {
void GuiGraph::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr <AtlasRef> texture,
unsigned int length, float maxValue, bool editInPlace) {
this->scale = scale;
this->padding = padding;
@ -25,7 +25,7 @@ void GUIGraph::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr <Atlas
entity.setModel(std::make_shared<Model>());
}
void GUIGraph::pushValue(float value) {
void GuiGraph::pushValue(float value) {
if (editInPlace) {
insertionPoint++;
if (insertionPoint >= length) insertionPoint = 0;
@ -50,11 +50,11 @@ void GUIGraph::pushValue(float value) {
buildHistogramMesh();
}
void GUIGraph::setMax(float max) {
void GuiGraph::setMax(float max) {
maxVal = max;
}
void GUIGraph::buildHistogramMesh() {
void GuiGraph::buildHistogramMesh() {
std::vector<EntityVertex> vertices {};
std::vector<unsigned int> indices {};

View File

@ -5,13 +5,13 @@
#pragma once
#include "../GUIComponent.h"
#include "../GuiComponent.h"
#include "../../../../def/texture/AtlasRef.h"
class GUIGraph : public GUIComponent {
class GuiGraph : public GuiComponent {
public:
GUIGraph() = default;
GUIGraph(const std::string& key);
GuiGraph() = default;
GuiGraph(const std::string& key);
void create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture, unsigned int length, float maxValue, bool editInPlace);

View File

@ -2,33 +2,33 @@
// Created by aurailus on 2019-10-29.
//
#include "GUIInventoryItem.h"
#include "GuiInventoryItem.h"
#include "GUIText.h"
#include "GUIRect.h"
#include "GUIModel.h"
#include "GuiText.h"
#include "GuiRect.h"
#include "GuiModel.h"
#include "../../../../def/texture/Font.h"
GUIInventoryItem::GUIInventoryItem(const std::string &key) : GUIContainer(key) {}
GuiInventoryItem::GuiInventoryItem(const std::string &key) : GuiContainer(key) {}
void GUIInventoryItem::create(glm::vec2 scale, unsigned short count, ItemDef& def, Font f) {
void GuiInventoryItem::create(glm::vec2 scale, unsigned short count, ItemDef& def, Font f) {
if (def.type == ItemDef::Type::CRAFTITEM) {
auto texture = static_cast<CraftItemDef&>(def).textureRefs[0];
auto shadow = std::make_shared<GUIRect>("shadow");
auto shadow = std::make_shared<GuiRect>("shadow");
shadow->create(scale * 16.f, {}, texture, {0, 0, 0, 0.2});
add(shadow);
shadow->setPos(scale);
auto item = std::make_shared<GUIRect>("item");
auto item = std::make_shared<GuiRect>("item");
item->create(scale * 16.f, {}, texture);
add(item);
}
else {
auto& model = static_cast<BlockDef&>(def).entityModel;
auto item = std::make_shared<GUIModel>("item");
auto item = std::make_shared<GuiModel>("item");
item->create(scale * 10.5f, model);
item->setPos(glm::vec2{7.75, 7.75} * scale);
@ -40,7 +40,7 @@ void GUIInventoryItem::create(glm::vec2 scale, unsigned short count, ItemDef& de
}
if (count > 1) {
auto text = std::make_shared<GUIText>("count");
auto text = std::make_shared<GuiText>("count");
text->create(scale, {}, {}, {1, 1, 1, 1}, f);
text->setText(std::to_string(count));
add(text);

View File

@ -4,15 +4,15 @@
#pragma once
#include "GUIContainer.h"
#include "GuiContainer.h"
class ItemDef;
class Font;
class GUIInventoryItem : public GUIContainer {
class GuiInventoryItem : public GuiContainer {
public:
GUIInventoryItem() = default;
GUIInventoryItem(const std::string& key);
GuiInventoryItem() = default;
GuiInventoryItem(const std::string& key);
void create(glm::vec2 scale, unsigned short itemCount, ItemDef& def, Font font);
};

View File

@ -2,13 +2,13 @@
// Created by aurailus on 2019-12-17.
//
#include "GUIModel.h"
#include "GuiModel.h"
#include "../../../../def/ClientGame.h"
GUIModel::GUIModel(const std::string &key) : GUIComponent(key) {}
GuiModel::GuiModel(const std::string &key) : GuiComponent(key) {}
std::shared_ptr<GUIModel> GUIModel::fromSerialized(SerialGui::Elem s, ClientGame &game, glm::ivec2 bounds) {
std::shared_ptr<GuiModel> GuiModel::fromSerialized(SerialGui::Elem s, ClientGame &game, glm::ivec2 bounds) {
glm::vec2 pos = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position", bounds);
glm::vec2 scale = SerialGui::deserializeToken<glm::vec2>(s.tokens, "scale");
glm::vec2 anim_range = SerialGui::deserializeToken<glm::vec2>(s.tokens, "anim_range");
@ -21,7 +21,7 @@ std::shared_ptr<GUIModel> GUIModel::fromSerialized(SerialGui::Elem s, ClientGame
auto m = std::make_shared<Model>();
if (type == "model") m->fromSerialized(game.models.models[source], {game.textures[texture]});
auto model = std::make_shared<GUIModel>(s.key);
auto model = std::make_shared<GuiModel>(s.key);
model->create(scale, m);
model->setPos(pos);
@ -30,7 +30,7 @@ std::shared_ptr<GUIModel> GUIModel::fromSerialized(SerialGui::Elem s, ClientGame
return model;
}
void GUIModel::create(glm::vec2 scale, std::shared_ptr<Model> model) {
void GuiModel::create(glm::vec2 scale, std::shared_ptr<Model> model) {
entity.setModel(model);
setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
@ -38,29 +38,29 @@ void GUIModel::create(glm::vec2 scale, std::shared_ptr<Model> model) {
setRotationY(215);
}
void GUIModel::update(double delta) {
void GuiModel::update(double delta) {
entity.update(delta);
}
void GUIModel::animate(glm::vec2 range) {
void GuiModel::animate(glm::vec2 range) {
entity.playRange(range.x, range.y, true);
}
void GUIModel::setRotationX(float x) {
void GuiModel::setRotationX(float x) {
entity.setRotateX(x);
}
void GUIModel::setRotationY(float y) {
void GuiModel::setRotationY(float y) {
entity.setRotateY(y);
}
void GUIModel::setRotationZ(float z) {
void GuiModel::setRotationZ(float z) {
entity.setRotateZ(z);
}
void GUIModel::draw(Renderer &renderer) {
void GuiModel::draw(Renderer &renderer) {
renderer.toggleDepthTest(true);
renderer.clearDepthBuffer();
GUIComponent::draw(renderer);
GuiComponent::draw(renderer);
renderer.toggleDepthTest(false);
}

View File

@ -6,18 +6,18 @@
#include <string>
#include "GUIContainer.h"
#include "GuiContainer.h"
#include "../../../../def/ItemDef.h"
#include "../../SerialGui.h"
class ClientGame;
class GUIModel : public GUIComponent {
class GuiModel : public GuiComponent {
public:
GUIModel() = default;
GUIModel(const std::string& key);
GuiModel() = default;
GuiModel(const std::string& key);
static std::shared_ptr<GUIModel> fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds);
static std::shared_ptr<GuiModel> fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds);
void create(glm::vec2 scale, std::shared_ptr<Model> model);
void update(double delta) override;

View File

@ -2,15 +2,15 @@
// Created by aurailus on 10/02/19.
//
#include "GUIRect.h"
#include "GuiRect.h"
#include "../../SerialGui.h"
#include "../../../../util/Util.h"
#include "../../../../def/ClientGame.h"
GUIRect::GUIRect(const std::string &key) : GUIComponent(key) {}
GuiRect::GuiRect(const std::string &key) : GuiComponent(key) {}
std::shared_ptr<GUIRect> GUIRect::fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds) {
std::shared_ptr<GuiRect> GuiRect::fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds) {
glm::vec2 pos = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position", bounds);
glm::vec2 offset = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position_anchor");
glm::vec2 size = SerialGui::deserializeToken<glm::vec2>(s.tokens, "size", bounds);
@ -21,7 +21,7 @@ std::shared_ptr<GUIRect> GUIRect::fromSerialized(SerialGui::Elem s, ClientGame&
std::string background = s.tokens["background"];
auto rect = std::make_shared<GUIRect>(s.key);
auto rect = std::make_shared<GuiRect>(s.key);
if (background[0] == '#') rect->create(size, padding, Util::hexToColorVec(background));
else if (background.size() > 0) rect->create(size, padding, game.textures[background]);
else rect->create(size, padding, glm::vec4 {});
@ -30,9 +30,9 @@ std::shared_ptr<GUIRect> GUIRect::fromSerialized(SerialGui::Elem s, ClientGame&
}
// Single Color Constructor
// Creates a GUIRect object whose background
// Creates a GuiRect object whose background
// is a flat color defined by 'color'.
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 color) {
void GuiRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 color) {
this->scale = scale;
this->padding = padding;
@ -50,9 +50,9 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 color) {
}
// Multiple Color Constructor
// Creates a GUIRect object with a gradient background
// Creates a GuiRect object with a gradient background
// defined by 'tl', 'tr', 'bl', and 'br'.
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br) {
void GuiRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br) {
this->scale = scale;
this->padding = padding;
@ -71,9 +71,9 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 tl, glm::vec4
}
// Texture Constructor
// Creates a GUIRect object with a textured background
// Creates a GuiRect object with a textured background
// defined by the 'texture' reference.
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture) {
void GuiRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture) {
this->scale = scale;
this->padding = padding;
this->texture = texture;
@ -94,9 +94,9 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRe
}
// Texture Constructor
// Creates a GUIRect object with a textured background
// Creates a GuiRect object with a textured background
// defined by the 'texture' reference.
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture, glm::vec4 tint) {
void GuiRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture, glm::vec4 tint) {
this->scale = scale;
this->padding = padding;
this->texture = std::move(texture);

View File

@ -7,18 +7,18 @@
#include <memory>
#include "../GUIComponent.h"
#include "../GuiComponent.h"
#include "../../SerialGui.h"
#include "../../../../def/texture/AtlasRef.h"
class ClientGame;
class GUIRect : public GUIComponent {
class GuiRect : public GuiComponent {
public:
GUIRect() = default;
GUIRect(const std::string& key);
GuiRect() = default;
GuiRect(const std::string& key);
static std::shared_ptr<GUIRect> fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds);
static std::shared_ptr<GuiRect> fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds);
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);

View File

@ -4,13 +4,13 @@
#include <utility>
#include "GUIText.h"
#include "GuiText.h"
GUIText::GUIText(const std::string &key) : GUIComponent(key) {}
GuiText::GuiText(const std::string &key) : GuiComponent(key) {}
void GUIText::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 bgcolor, glm::vec4 color, Font font) {
void GuiText::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 bgcolor, glm::vec4 color, Font font) {
// Text Constructor
// Creates a GUIText object.
// Creates a GuiText object.
this->scale = scale;
this->padding = padding;
@ -23,7 +23,7 @@ void GUIText::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 bgcolor, glm:
setText("");
}
std::shared_ptr<GUIText> GUIText::fromSerialized(SerialGui::Elem s, ClientGame &game, glm::ivec2 bounds) {
std::shared_ptr<GuiText> GuiText::fromSerialized(SerialGui::Elem s, ClientGame &game, glm::ivec2 bounds) {
glm::vec2 pos = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position", bounds);
glm::vec2 offset = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position_anchor");
glm::vec2 size = SerialGui::deserializeToken<glm::vec2>(s.tokens, "size", bounds);
@ -47,7 +47,7 @@ std::shared_ptr<GUIText> GUIText::fromSerialized(SerialGui::Elem s, ClientGame &
off += 1;
}
auto text = std::make_shared<GUIText>(s.key);
auto text = std::make_shared<GuiText>(s.key);
text->create(scale * SerialGui::SCALE_MODIFIER, padding, background_color, color, {game.textures, game.textures["font"]});
text->setText(content);
text->setPos(pos);
@ -55,7 +55,7 @@ std::shared_ptr<GUIText> GUIText::fromSerialized(SerialGui::Elem s, ClientGame &
return text;
}
void GUIText::setText(std::string text) {
void GuiText::setText(std::string text) {
this->text = std::move(text);
unsigned int indOffset = 0;
@ -169,10 +169,10 @@ void GUIText::setText(std::string text) {
entity.setModel(model);
}
std::string GUIText::getText() {
std::string GuiText::getText() {
return text;
}
unsigned int GUIText::getWidth() {
unsigned int GuiText::getWidth() {
return maxLineWidth;
}

View File

@ -6,18 +6,18 @@
#include <utility>
#include "../GUIComponent.h"
#include "../GuiComponent.h"
#include "../../SerialGui.h"
#include "../../../../def/texture/Font.h"
#include "../../../../def/texture/AtlasRef.h"
class GUIText : public GUIComponent {
class GuiText : public GuiComponent {
public:
GUIText() = default;
explicit GUIText(const std::string& key);
GuiText() = default;
explicit GuiText(const std::string& key);
static std::shared_ptr<GUIText> fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds);
static std::shared_ptr<GuiText> fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds);
void create(glm::vec2 scale, glm::vec4 padding, glm::vec4 bgcolor, glm::vec4 color, Font font);

View File

@ -2,14 +2,14 @@
// Created by aurailus on 2019-12-11.
//
#include "GUIImageButton.h"
#include "GuiImageButton.h"
#include "../../../../def/ClientGame.h"
#include "../basic/GUIText.h"
#include "../basic/GuiText.h"
GUIImageButton::GUIImageButton(const std::string &key) : GUIRect(key) {}
GuiImageButton::GuiImageButton(const std::string &key) : GuiRect(key) {}
std::shared_ptr<GUIImageButton> GUIImageButton::fromSerialized(SerialGui::Elem s, ClientGame &game, glm::ivec2 bounds) {
std::shared_ptr<GuiImageButton> GuiImageButton::fromSerialized(SerialGui::Elem s, ClientGame &game, glm::ivec2 bounds) {
glm::vec2 pos = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position", bounds);
glm::vec2 offset = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position_anchor");
glm::vec2 size = SerialGui::deserializeToken<glm::vec2>(s.tokens, "size", bounds);
@ -30,12 +30,12 @@ std::shared_ptr<GUIImageButton> GUIImageButton::fromSerialized(SerialGui::Elem s
off += 1;
}
auto button = std::make_shared<GUIImageButton>(s.key);
auto button = std::make_shared<GuiImageButton>(s.key);
button->create(size, padding, game.textures[background], game.textures[background_hover]);
button->setPos(pos);
if (content != "") {
auto text = std::make_shared<GUIText>(s.key + "__TEXT");
auto text = std::make_shared<GuiText>(s.key + "__TEXT");
text->create(glm::vec2(SerialGui::SCALE_MODIFIER), padding, {}, {1, 1, 1, 1}, {game.textures, game.textures["font"]});
text->setPos({6 * SerialGui::SCALE_MODIFIER, size.y / 2 - 4.5 * SerialGui::SCALE_MODIFIER});
text->setText(content);
@ -46,23 +46,23 @@ std::shared_ptr<GUIImageButton> GUIImageButton::fromSerialized(SerialGui::Elem s
}
// Texture Constructor
// Creates a GUIImageButton object with two textures
// Creates a GuiImageButton object with two textures
// defined by the 'texture' & 'hoverTexture' reference.
void GUIImageButton::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture, std::shared_ptr<AtlasRef> hoverTexture) {
void GuiImageButton::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture, std::shared_ptr<AtlasRef> hoverTexture) {
this->hoverTexture = hoverTexture;
GUIRect::create(scale, padding, texture);
GuiRect::create(scale, padding, texture);
setHoverCallback(nullptr);
}
void GUIImageButton::setHoverCallback(const callback& hoverCallback) {
GUIComponent::setHoverCallback([&, hoverCallback](bool nowHovered, glm::ivec2 pos) {
void GuiImageButton::setHoverCallback(const callback& hoverCallback) {
GuiComponent::setHoverCallback([&, hoverCallback](bool nowHovered, glm::ivec2 pos) {
if (hoverCallback) hoverCallback(nowHovered, pos);
if (nowHovered != hovered) this->rebuild(nowHovered);
});
}
void GUIImageButton::rebuild(bool hover) {
void GuiImageButton::rebuild(bool hover) {
auto tex = (hover) ? (hoverTexture != nullptr) ? hoverTexture : texture : texture;
auto mesh = std::make_unique<EntityMesh>();

View File

@ -4,14 +4,14 @@
#pragma once
#include "../basic/GUIRect.h"
#include "../basic/GuiRect.h"
class GUIImageButton : public GUIRect {
class GuiImageButton : public GuiRect {
public:
GUIImageButton() = default;
GUIImageButton(const std::string& key);
GuiImageButton() = default;
GuiImageButton(const std::string& key);
static std::shared_ptr<GUIImageButton> fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds);
static std::shared_ptr<GuiImageButton> fromSerialized(SerialGui::Elem s, ClientGame& game, glm::ivec2 bounds);
void create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture, std::shared_ptr<AtlasRef> hoverTexture);

View File

@ -2,15 +2,15 @@
// Created by aurailus on 2019-10-29.
//
#include "GUIInventoryList.h"
#include "GuiInventoryList.h"
#include "../basic/GUIInventoryItem.h"
#include "../basic/GuiInventoryItem.h"
#include "../../../../def/texture/Font.h"
GUIInventoryList::GUIInventoryList(const std::string &key) : GUIContainer(key) {}
GuiInventoryList::GuiInventoryList(const std::string &key) : GuiContainer(key) {}
std::shared_ptr<GUIInventoryList> GUIInventoryList::fromSerialized(SerialGui::Elem s, ClientGame &game,
glm::ivec2 bounds, Inventory& inventory, InventoryList& hand) {
std::shared_ptr<GuiInventoryList> GuiInventoryList::fromSerialized(SerialGui::Elem s, ClientGame &game,
glm::ivec2 bounds, Inventory& inventory, InventoryList& hand) {
glm::vec2 pos = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position", bounds);
glm::vec2 offset = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position_anchor");
@ -32,7 +32,7 @@ std::shared_ptr<GUIInventoryList> GUIInventoryList::fromSerialized(SerialGui::El
}
auto invList = inventory[list];
auto inv = std::make_shared<GUIInventoryList>(s.key);
auto inv = std::make_shared<GuiInventoryList>(s.key);
inv->create(glm::vec2(SerialGui::SCALE_MODIFIER), padding * SerialGui::SCALE_MODIFIER,
slotspc * SerialGui::SCALE_MODIFIER, *invList, hand, game);
@ -41,7 +41,7 @@ std::shared_ptr<GUIInventoryList> GUIInventoryList::fromSerialized(SerialGui::El
return inv;
}
void GUIInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding, InventoryList &list, InventoryList& hand, ClientGame &defs) {
void GuiInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding, InventoryList &list, InventoryList& hand, ClientGame &defs) {
this->list = &list;
this->hand = &hand;
this->defs = &defs;
@ -55,7 +55,7 @@ void GUIInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 inn
};
drawContents();
list.setGuiCallback(std::bind(&GUIInventoryList::drawContents, this));
list.setGuiCallback(std::bind(&GuiInventoryList::drawContents, this));
hoverRect->create({}, {}, {1, 1, 1, 0.1});
@ -65,28 +65,28 @@ void GUIInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 inn
[=](bool hovered, glm::ivec2 pos){this->hoverEvent(hovered, pos);});
}
void GUIInventoryList::setHoverCallback(const callback& hoverCallback) {
GUIComponent::setHoverCallback([&, hoverCallback](bool hovered, glm::ivec2 pos) {
void GuiInventoryList::setHoverCallback(const callback& hoverCallback) {
GuiComponent::setHoverCallback([&, hoverCallback](bool hovered, glm::ivec2 pos) {
if (hoverCallback) hoverCallback(hovered, pos);
this->hoverEvent(hovered, pos);
});
}
void GUIInventoryList::setLeftClickCallback(const callback& leftClickCallback) {
GUIComponent::setLeftClickCallback([&, leftClickCallback](bool down, glm::ivec2 pos) {
void GuiInventoryList::setLeftClickCallback(const callback& leftClickCallback) {
GuiComponent::setLeftClickCallback([&, leftClickCallback](bool down, glm::ivec2 pos) {
if (leftClickCallback) leftClickCallback(down, pos);
this->leftClick(down, pos);
});
}
void GUIInventoryList::setRightClickCallback(const callback& rightClickCallback) {
GUIComponent::setRightClickCallback([&, rightClickCallback](bool down, glm::ivec2 pos) {
void GuiInventoryList::setRightClickCallback(const callback& rightClickCallback) {
GuiComponent::setRightClickCallback([&, rightClickCallback](bool down, glm::ivec2 pos) {
if (rightClickCallback) rightClickCallback(down, pos);
this->rightClick(down, pos);
});
}
void GUIInventoryList::hoverEvent(bool hovered, glm::ivec2 pos) {
void GuiInventoryList::hoverEvent(bool hovered, glm::ivec2 pos) {
pos += glm::ivec2(glm::vec2(this->padding.x, this->padding.y) * this->scale);
if (hovered) {
@ -102,7 +102,7 @@ void GUIInventoryList::hoverEvent(bool hovered, glm::ivec2 pos) {
else if (this->hovered) hoverRect->setScale({});
}
void GUIInventoryList::leftClick(bool down, glm::ivec2 pos) {
void GuiInventoryList::leftClick(bool down, glm::ivec2 pos) {
if (!down) return;
pos += glm::ivec2(glm::vec2(this->padding.x, this->padding.y) * this->scale);
@ -118,7 +118,7 @@ void GUIInventoryList::leftClick(bool down, glm::ivec2 pos) {
hand->setStack(0, list->placeStack(index, hand->getStack(0), true));
}
void GUIInventoryList::rightClick(bool down, glm::ivec2 pos) {
void GuiInventoryList::rightClick(bool down, glm::ivec2 pos) {
pos += glm::ivec2(glm::vec2(this->padding.x, this->padding.y) * this->scale);
glm::ivec2 slot = pos / (glm::ivec2(this->scale) * this->innerPadding);
@ -151,7 +151,7 @@ void GUIInventoryList::rightClick(bool down, glm::ivec2 pos) {
}
}
void GUIInventoryList::drawContents() {
void GuiInventoryList::drawContents() {
empty();
auto fontRef = defs->textures["font"];
@ -159,7 +159,7 @@ void GUIInventoryList::drawContents() {
for (unsigned short i = 0; i < list->getLength() / list->getWidth(); i++) {
for (unsigned short j = 0; j < list->getWidth(); j++) {
// auto bg = std::make_shared<GUIRect>("background_" + to_string(i) + "_" + to_string(j));
// auto bg = std::make_shared<GuiRect>("background_" + to_string(i) + "_" + to_string(j));
// bg->create(scale * 16.f, {}, {1, 0, 0, 0.3});
// add(bg);
// bg->setPos({padding.x + j * (16*scale.x+innerPadding.x/scale.x), padding.y + i * (16*scale.y+innerPadding.y/scale.y)});
@ -167,7 +167,7 @@ void GUIInventoryList::drawContents() {
auto stack = list->getStack(j + i * list->getWidth());
if (stack.id == 0) continue;
auto item = std::make_shared<GUIInventoryItem>("item_" + std::to_string(i) + "_" + std::to_string(j));
auto item = std::make_shared<GuiInventoryItem>("item_" + std::to_string(i) + "_" + std::to_string(j));
item->create(scale, stack.count, defs->defs.fromId(stack.id), f);
add(item);
item->setPos({padding.x + j * (16*scale.x+innerPadding.x/scale.x), padding.y + i * (16*scale.y+innerPadding.y/scale.y)});
@ -177,6 +177,6 @@ void GUIInventoryList::drawContents() {
add(hoverRect);
}
GUIInventoryList::~GUIInventoryList() {
GuiInventoryList::~GuiInventoryList() {
list->setGuiCallback(nullptr);
}

View File

@ -4,22 +4,22 @@
#pragma once
#include "../basic/GUIContainer.h"
#include "../basic/GuiContainer.h"
#include "../basic/GUIRect.h"
#include "../basic/GuiRect.h"
#include "../../SerialGui.h"
#include "../../../../def/ClientGame.h"
#include "../../../scene/world/Inventory.h"
#include "../../../scene/world/InventoryList.h"
class GUIInventoryList : public GUIContainer {
class GuiInventoryList : public GuiContainer {
public:
GUIInventoryList() = default;
GUIInventoryList(const std::string& key);
~GUIInventoryList() override;
GuiInventoryList() = default;
GuiInventoryList(const std::string& key);
~GuiInventoryList() override;
static std::shared_ptr<GUIInventoryList> fromSerialized(SerialGui::Elem s, ClientGame &game,
glm::ivec2 bounds, Inventory& inventory, InventoryList& hand);
static std::shared_ptr<GuiInventoryList> fromSerialized(SerialGui::Elem s, ClientGame &game,
glm::ivec2 bounds, Inventory& inventory, InventoryList& hand);
void create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding, InventoryList& list, InventoryList& hand, ClientGame& defs);
@ -32,7 +32,7 @@ public:
void rightClick(bool down, glm::ivec2 pos);
void drawContents();
private:
std::shared_ptr<GUIRect> hoverRect = std::make_shared<GUIRect>("hover_rect");
std::shared_ptr<GuiRect> hoverRect = std::make_shared<GuiRect>("hover_rect");
InventoryList* list;
InventoryList* hand;

View File

@ -2,13 +2,13 @@
// Created by aurailus on 28/04/19.
//
#include "GUILabelledGraph.h"
#include "GuiLabelledGraph.h"
GUILabelledGraph::GUILabelledGraph(const std::string &key) : GUIContainer(key) {}
GuiLabelledGraph::GuiLabelledGraph(const std::string &key) : GuiContainer(key) {}
void GUILabelledGraph::create(glm::vec2 scale, glm::vec4 padding, const std::string &title,
unsigned int graphLength, unsigned int graphScale,
std::shared_ptr<AtlasRef> graphTextureRef, Font font) {
void GuiLabelledGraph::create(glm::vec2 scale, glm::vec4 padding, const std::string &title,
unsigned int graphLength, unsigned int graphScale,
std::shared_ptr<AtlasRef> graphTextureRef, Font font) {
const static int GRAPH_PAD_X = 2;
const static int GRAPH_PAD_Y = 62;
@ -21,17 +21,17 @@ void GUILabelledGraph::create(glm::vec2 scale, glm::vec4 padding, const std::str
this->font = std::move(font);
this->graphTextureRef = std::move(graphTextureRef);
auto background = std::make_shared<GUIRect>("background");
auto background = std::make_shared<GuiRect>("background");
background->create(scale, {}, {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});
add(background);
background->setPos({0, 0});
auto graph = std::make_shared<GUIGraph>("graph");
auto graph = std::make_shared<GuiGraph>("graph");
graph->create({scale.x / (graphLength + GRAPH_PAD_X), scale.y * 0.4}, {}, this->graphTextureRef, graphLength, graphScale, true);
add(graph);
graph->setPos({GRAPH_PAD_X, GRAPH_PAD_Y});
auto label = std::make_shared<GUIText>("label");
auto label = std::make_shared<GuiText>("label");
label->create({2, 2}, {}, {}, {1, 1, 1, 1}, this->font);
add(label);
label->setPos({TEXT_PAD_X, TEXT_PAD_Y});
@ -39,8 +39,8 @@ void GUILabelledGraph::create(glm::vec2 scale, glm::vec4 padding, const std::str
for (float &i : history) i = 0;
}
void GUILabelledGraph::pushValue(float value) {
get<GUIGraph>("graph")->pushValue(value);
void GuiLabelledGraph::pushValue(float value) {
get<GuiGraph>("graph")->pushValue(value);
history[ind] = value;
if (++ind >= 5) {
@ -53,6 +53,6 @@ void GUILabelledGraph::pushValue(float value) {
? std::to_string(static_cast<int>(value))
: Util::floatToString(value);
get<GUIText>("label")->setText(title + ": " + stringVal);
get<GuiText>("label")->setText(title + ": " + stringVal);
}
}

View File

@ -6,15 +6,15 @@
#include "../../../entity/Entity.h"
#include "../../../../util/Util.h"
#include "../basic/GUIRect.h"
#include "../basic/GUIGraph.h"
#include "../basic/GUIText.h"
#include "../basic/GUIContainer.h"
#include "../basic/GuiRect.h"
#include "../basic/GuiGraph.h"
#include "../basic/GuiText.h"
#include "../basic/GuiContainer.h"
class GUILabelledGraph : public GUIContainer {
class GuiLabelledGraph : public GuiContainer {
public:
GUILabelledGraph() = default;
GUILabelledGraph(const std::string& key);
GuiLabelledGraph() = default;
GuiLabelledGraph(const std::string& key);
void create(glm::vec2 scale, glm::vec4 padding, const std::string& title,
unsigned int graphLength, unsigned int graphScale,

View File

@ -13,13 +13,13 @@ ConnectScene::ConnectScene(ClientState &state, Address addr) : Scene(state),
Font f(state.defs.textures, state.defs.textures["font"]);
auto statusText = std::make_shared<GUIText>("statusText");
auto statusText = std::make_shared<GuiText>("statusText");
statusText->create({2, 2}, {}, {}, {1, 1, 1, 1}, f);
statusText->setText("Connecting...");
statusText->setPos({32, 24});
components.add(statusText);
auto loadBar = std::make_shared<GUIRect>("loadBar");
auto loadBar = std::make_shared<GuiRect>("loadBar");
loadBar->create({1, 32}, {}, {0.17, 0.75, 0.93, 1});
loadBar->setPos({0, state.renderer.window.getSize().y - 32});
components.add(loadBar);
@ -27,7 +27,7 @@ ConnectScene::ConnectScene(ClientState &state, Address addr) : Scene(state),
connection.attemptConnect(std::move(addr));
state.renderer.window.addResizeCallback("scene", [&](glm::ivec2 win) {
components.get<GUIRect>("loadBar")->setPos({0, win.y - 32});
components.get<GuiRect>("loadBar")->setPos({0, win.y - 32});
});
}
@ -48,7 +48,7 @@ void ConnectScene::update() {
break;
case State::IDENTIFIER_LIST: {
components.get<GUIRect>("loadBar")->setScale({state.renderer.window.getSize().x * 0.2, 32});
components.get<GuiRect>("loadBar")->setScale({state.renderer.window.getSize().x * 0.2, 32});
ENetEvent e;
if (connection.pollEvents(&e) && e.type == ENET_EVENT_TYPE_RECEIVE) {
@ -56,7 +56,7 @@ void ConnectScene::update() {
Deserializer d(p.data);
if (p.type == PacketType::BLOCK_IDENTIFIER_LIST) {
auto statusText = components.get<GUIText>("statusText");
auto statusText = components.get<GuiText>("statusText");
statusText->setText(statusText->getText() + "Received block index-identifier table.\n");
state.defs.defs.setIdentifiers(d.read<std::vector<std::string>>());
@ -65,7 +65,7 @@ void ConnectScene::update() {
resp.sendTo(connection.getPeer(), PacketChannel::CONNECT);
}
else if (p.type == PacketType::BIOME_IDENTIFIER_LIST) {
auto statusText = components.get<GUIText>("statusText");
auto statusText = components.get<GuiText>("statusText");
statusText->setText(statusText->getText() + "Received biome index-identifier table.\nDownloading mods...\n");
state.defs.biomes.setIdentifiers(d.read<std::vector<std::string>>());
@ -79,13 +79,13 @@ void ConnectScene::update() {
}
case State::MODS: {
components.get<GUIRect>("loadBar")->setScale({state.renderer.window.getSize().x * 0.4, 32});
components.get<GuiRect>("loadBar")->setScale({state.renderer.window.getSize().x * 0.4, 32});
ENetEvent e;
if (connection.pollEvents(&e) && e.type == ENET_EVENT_TYPE_RECEIVE) {
Packet p(e.packet);
Deserializer d(p.data);
auto statusText = components.get<GUIText>("statusText");
auto statusText = components.get<GuiText>("statusText");
if (p.type == PacketType::MODS) {
auto luaMod = LuaMod::fromPacket(p);
@ -106,14 +106,14 @@ void ConnectScene::update() {
}
case State::MEDIA: {
components.get<GUIRect>("loadBar")->setScale({state.renderer.window.getSize().x * 0.6, 32});
components.get<GuiRect>("loadBar")->setScale({state.renderer.window.getSize().x * 0.6, 32});
ENetEvent e;
if (connection.pollEvents(&e) && e.type == ENET_EVENT_TYPE_RECEIVE) {
Packet p(e.packet);
Deserializer d(p.data);
auto statusText = components.get<GUIText>("statusText");
auto statusText = components.get<GuiText>("statusText");
if (p.type == PacketType::MEDIA) {
AssetType t = static_cast<AssetType>(d.read<int>());
@ -147,7 +147,7 @@ void ConnectScene::update() {
statusText->setText(statusText->getText() + "Received " + std::to_string(count) + "x media files.\n");
}
else if (p.type == PacketType::MEDIA_DONE) {
components.get<GUIRect>("loadBar")->setScale({state.renderer.window.getSize().x, 32});
components.get<GuiRect>("loadBar")->setScale({state.renderer.window.getSize().x, 32});
statusText->setText(statusText->getText() + "Done downloading media.\nJoining world...\n");
connectState = State::DONE;
@ -161,7 +161,7 @@ void ConnectScene::update() {
void ConnectScene::handleConnecting() {
Packet resp(PacketType::BLOCK_IDENTIFIER_LIST);
auto statusText = components.get<GUIText>("statusText");
auto statusText = components.get<GuiText>("statusText");
switch (connection.getConnectionStatus()) {
default:

View File

@ -7,9 +7,9 @@
#include <utility>
#include "net/ServerConnection.h"
#include "../graph/scene/Scene.h"
#include "../hud/components/basic/GUIText.h"
#include "../hud/components/basic/GUIContainer.h"
#include "../hud/components/basic/GUIRect.h"
#include "../hud/components/basic/GuiText.h"
#include "../hud/components/basic/GuiContainer.h"
#include "../hud/components/basic/GuiRect.h"
#include "../../lua/LuaModFile.h"
#include "../../lua/LuaMod.h"
#include "../../server/asset/AssetType.h"
@ -39,7 +39,7 @@ private:
State connectState = State::CONNECTING;
ServerConnection& connection;
GUIContainer components;
GuiContainer components;
double dotsTime = 0;
};

View File

@ -4,8 +4,8 @@
#include "LuaErrorScene.h"
#include "../../def/texture/Font.h"
#include "../hud/components/basic/GUIRect.h"
#include "../hud/components/basic/GUIText.h"
#include "../hud/components/basic/GuiRect.h"
#include "../hud/components/basic/GuiText.h"
LuaErrorScene::LuaErrorScene(ClientState &state, const std::string &err) : Scene(state), err(err) {
state.renderer.setClearColor(0, 0, 0);
@ -14,25 +14,25 @@ LuaErrorScene::LuaErrorScene(ClientState &state, const std::string &err) : Scene
Font f(state.defs.textures, state.defs.textures["font"]);
glm::ivec2 win = state.renderer.window.getSize();
auto container = std::make_shared<GUIRect>("container");
auto container = std::make_shared<GuiRect>("container");
container->create({800, 500}, {}, {0.05, 0.05, 0.05, 1});
container->setPos({win.x / 2 - 800 / 2, win.y / 2 - 500 / 2});
components.add(container);
auto titleText = std::make_shared<GUIText>("titleText");
auto titleText = std::make_shared<GuiText>("titleText");
titleText->create({3, 3}, {}, {}, {1, 0.4, 0.5, 1}, f);
titleText->setText("The Zepha sandbox has encountered an error.");
titleText->setPos({16, 12});
container->add(titleText);
auto errorText = std::make_shared<GUIText>("errorText");
auto errorText = std::make_shared<GuiText>("errorText");
errorText->create({2, 2}, {}, {}, {0.85, 0.85, 0.85, 1}, f);
errorText->setText(err);
errorText->setPos({16, 48});
container->add(errorText);
state.renderer.window.addResizeCallback("scene", [&](glm::ivec2 win) {
components.get<GUIRect>("container")->setPos({win.x / 2 - 800 / 2, win.y / 2 - 500 / 2});
components.get<GuiRect>("container")->setPos({win.x / 2 - 800 / 2, win.y / 2 - 500 / 2});
});
}

View File

@ -6,7 +6,7 @@
#include <string>
#include "../graph/scene/Scene.h"
#include "../hud/components/basic/GUIContainer.h"
#include "../hud/components/basic/GuiContainer.h"
class LuaErrorScene : public Scene {
public:
@ -17,6 +17,6 @@ public:
void cleanup() override;
private:
GUIContainer components;
GuiContainer components;
const std::string err;
};

View File

@ -17,50 +17,50 @@ MainMenuScene::MainMenuScene(ClientState& state) :
components.add(sandboxContainer);
branding = std::make_shared<GUIContainer>("zephaBranding");
branding = std::make_shared<GuiContainer>("zephaBranding");
components.add(branding);
{
auto zephaText = std::make_shared<GUIText>("zephaText");
auto zephaText = std::make_shared<GuiText>("zephaText");
zephaText->create({GS, GS}, {}, {}, {1, 1, 1, 1}, f);
zephaText->setText("Zepha");
branding->add(zephaText);
auto alphaText = std::make_shared<GUIText>("alphaText");
auto alphaText = std::make_shared<GuiText>("alphaText");
alphaText->create({GS, GS}, {}, {}, {1, 0.5, 0.7, 1}, f);
alphaText->setText("ALPHA");
alphaText->setPos({25*GS, 0});
branding->add(alphaText);
}
navigationBar = std::make_shared<GUIContainer>("navigationBar");
navigationBar->add(std::make_shared<GUIContainer>("navigationBarBg"));
navigationBar->add(std::make_shared<GUIContainer>("navigationBarIcons"));
navigationBar = std::make_shared<GuiContainer>("navigationBar");
navigationBar->add(std::make_shared<GuiContainer>("navigationBarBg"));
navigationBar->add(std::make_shared<GuiContainer>("navigationBarIcons"));
auto navigationBarIcons = navigationBar->get<GUIContainer>("navigationBarIcons");
auto navigationBarIcons = navigationBar->get<GuiContainer>("navigationBarIcons");
components.add(navigationBar);
{
auto settingsButton = std::make_shared<GUIImageButton>("settingsButton");
auto settingsButton = std::make_shared<GuiImageButton>("settingsButton");
settingsButton->create({16 * GS, 16 * GS}, {},
state.defs.textures["crop(0, 0, 16, 16, menu_flag_settings)"],
state.defs.textures["crop(16, 0, 16, 16, menu_flag_settings)"]);
navigationBar->get<GUIContainer>("navigationBarIcons")->add(settingsButton);
navigationBar->get<GuiContainer>("navigationBarIcons")->add(settingsButton);
auto closeButton = std::make_shared<GUIImageButton>("closeButton");
auto closeButton = std::make_shared<GuiImageButton>("closeButton");
closeButton->create({16 * GS, 16 * GS}, {},
state.defs.textures["crop(0, 0, 16, 16, menu_flag_quit)"],
state.defs.textures["crop(16, 0, 16, 16, menu_flag_quit)"]);
closeButton->setLeftClickCallback([](bool down, glm::ivec2) { if (down) exit(0); });
navigationBar->get<GUIContainer>("navigationBarIcons")->add(closeButton);
navigationBar->get<GuiContainer>("navigationBarIcons")->add(closeButton);
auto serversButton = std::make_shared<GUIImageButton>("serversButton");
auto serversButton = std::make_shared<GuiImageButton>("serversButton");
serversButton->create({16 * GS, 16 * GS}, {},
state.defs.textures["crop(0, 0, 16, 16, menu_flag_multiplayer)"],
state.defs.textures["crop(16, 0, 16, 16, menu_flag_multiplayer)"]);
serversButton->setPos({GS, GS});
navigationBarIcons->add(serversButton);
auto contentButton = std::make_shared<GUIImageButton>("contentButton");
auto contentButton = std::make_shared<GuiImageButton>("contentButton");
contentButton->create({16 * GS, 16 * GS}, {},
state.defs.textures["crop(0, 0, 16, 16, menu_flag_content)"],
state.defs.textures["crop(16, 0, 16, 16, menu_flag_content)"]);
@ -68,7 +68,7 @@ MainMenuScene::MainMenuScene(ClientState& state) :
contentButton->setLeftClickCallback([&](bool down, glm::ivec2) { if (down) state.desiredState = "connect"; });
navigationBarIcons->add(contentButton);
auto divider = std::make_shared<GUIRect>("divider");
auto divider = std::make_shared<GuiRect>("divider");
divider->create({GS, GS * 10}, {}, {1, 1, 1, 0.3});
divider->setPos({GS * 2 + GS * 18 * 2, GS * 4});
navigationBarIcons->add(divider);
@ -77,7 +77,7 @@ MainMenuScene::MainMenuScene(ClientState& state) :
for (unsigned int i = 0; i < subgames.size(); i++) {
auto &subgame = subgames[i];
auto button = std::make_shared<GUIImageButton>(subgame.config.name);
auto button = std::make_shared<GuiImageButton>(subgame.config.name);
button->create({16 * GS, 16 * GS}, {},
state.defs.textures["crop(0, 0, 16, 16, " + subgame.iconRef->name + ")"],
state.defs.textures["crop(16, 0, 16, 16, " + subgame.iconRef->name + ")"]);
@ -179,17 +179,17 @@ void MainMenuScene::positionElements() {
navigationBar->setPos({0, win.y - 18*GS});
auto navigationBarBg = navigationBar->get<GUIContainer>("navigationBarBg");
auto navigationBarBg = navigationBar->get<GuiContainer>("navigationBarBg");
for (unsigned int i = 0; i < static_cast<float>(win.x) / 64.f / GS; i++) {
auto segment = std::make_shared<GUIRect>("segment_" + std::to_string(i));
auto segment = std::make_shared<GuiRect>("segment_" + std::to_string(i));
segment->create({64 * GS, 18 * GS}, {}, state.defs.textures["menu_bar_bg"]);
segment->setPos({i * 64 * GS, 0});
navigationBarBg->add(segment);
}
auto navigationBarIcons = navigationBar->get<GUIContainer>("navigationBarIcons");
navigationBarIcons->get<GUIImageButton>("closeButton")->setPos({win.x - 16*GS - GS, GS});
navigationBarIcons->get<GUIImageButton>("settingsButton")->setPos({win.x - 16*GS*2 - GS*3, GS});
auto navigationBarIcons = navigationBar->get<GuiContainer>("navigationBarIcons");
navigationBarIcons->get<GuiImageButton>("closeButton")->setPos({win.x - 16 * GS - GS, GS});
navigationBarIcons->get<GuiImageButton>("settingsButton")->setPos({win.x - 16 * GS * 2 - GS * 3, GS});
}
void MainMenuScene::update() {

View File

@ -7,9 +7,9 @@
#include <json/json.hpp>
#include "../../game/ClientState.h"
#include "../../game/graph/scene/Scene.h"
#include "../hud/components/basic/GUIText.h"
#include "../hud/components/basic/GUIContainer.h"
#include "../hud/components/compound/GUIImageButton.h"
#include "../hud/components/basic/GuiText.h"
#include "../hud/components/basic/GuiContainer.h"
#include "../hud/components/compound/GuiImageButton.h"
#include "menu/Subgame.h"
#include "menu/MenuSandbox.h"
@ -32,10 +32,10 @@ private:
glm::ivec2 win {};
glm::ivec2 sandboxArea {};
GUIContainer components;
std::shared_ptr<GUIContainer> branding = nullptr;
std::shared_ptr<GUIContainer> navigationBar = nullptr;
std::shared_ptr<GUIContainer> sandboxContainer = std::make_shared<GUIContainer>("_sandbox");
GuiContainer components;
std::shared_ptr<GuiContainer> branding = nullptr;
std::shared_ptr<GuiContainer> navigationBar = nullptr;
std::shared_ptr<GuiContainer> sandboxContainer = std::make_shared<GuiContainer>("_sandbox");
MenuSandbox sandbox;

View File

@ -8,7 +8,7 @@
#include "../../../lua/api/menu/mSetGui.h"
#include "../../../lua/api/menu/mStartGame.h"
MenuSandbox::MenuSandbox(glm::ivec2 &win, ClientState& state, std::shared_ptr<GUIContainer> container) :
MenuSandbox::MenuSandbox(glm::ivec2 &win, ClientState& state, std::shared_ptr<GuiContainer> container) :
win(win),
state(state),
container(container),

View File

@ -9,14 +9,14 @@
#include "Subgame.h"
#include "../../ClientState.h"
#include "../../hud/GuiBuilder.h"
#include "../../hud/components/basic/GUIContainer.h"
#include "../../hud/components/basic/GuiContainer.h"
#include "../../../lua/LuaMod.h"
#include "../../../lua/LuaParser.h"
class MenuSandbox : LuaParser {
public:
MenuSandbox(glm::ivec2& win, ClientState& state, std::shared_ptr<GUIContainer> container);
MenuSandbox(glm::ivec2& win, ClientState& state, std::shared_ptr<GuiContainer> container);
void load(const Subgame& subgame);
void windowResized();
@ -30,7 +30,7 @@ private:
LuaMod mod {};
std::vector<std::shared_ptr<AtlasRef>> modAssets {};
std::shared_ptr<GUIContainer> container = nullptr;
std::shared_ptr<GuiContainer> container = nullptr;
ClientState& state;
GuiBuilder builder;
glm::ivec2& win;