Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mateu Tudela committed Mar 22, 2018
2 parents e4ac60f + 9c377e0 commit 61b970a
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 10,827 deletions.
31 changes: 31 additions & 0 deletions LCSEngine/ElementGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ ElementGameUI::ElementGameUI(GameObject* parent, int x, int y, int h, int w, boo
enable = true;
}

ElementGameUI::ElementGameUI(GameObject * parent)
{
gameObject = parent;
if (gameObject != nullptr)
{
UUIDparent = parent->UUID;
}
}

ElementGameUI::~ElementGameUI() {}

void ElementGameUI::startGUI()
Expand All @@ -45,4 +54,26 @@ bool ElementGameUI::isHover()
}
}
return false;
}

void ElementGameUI::load(nlohmann::json& conf)
{
visible = conf.at("visible").get<bool>();
enable = conf.at("enable").get<bool>();
rect.x = conf.at("x").get<int>();
rect.y = conf.at("y").get<int>();
rect.w = conf.at("h").get<int>();
rect.h = conf.at("w").get<int>();
}

void ElementGameUI::save(nlohmann::json& conf)
{
conf["visible"] = visible;
conf["enable"] = enable;
conf["TypeElemeneGametUI"] = type;
conf["x"] = rect.x;
conf["y"] = rect.y;
conf["w"] = rect.w;
conf["h"] = rect.h;

}
4 changes: 4 additions & 0 deletions LCSEngine/ElementGameUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
#define __ELEMENTGAMEUI_H__

#include "Module.h"
#include <json.hpp>
#include <string>

class ElementGameUI
{
public:
ElementGameUI(GameObject* parent, int x, int y, int h, int w, bool isVisible = true);
ElementGameUI(GameObject* parent);
~ElementGameUI();
virtual void drawGUI() = 0;
void startGUI();
void endGUI();
bool isHover();
virtual void load(nlohmann::json& conf);
virtual void save(nlohmann::json& conf);

public:
TypeElemeneGametUI type;
Expand Down
51 changes: 51 additions & 0 deletions LCSEngine/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ void GameObject::save(nlohmann::json& conf) {
SaveLoadManager::convertFloat3ToMyJSON(aabb.minPoint, customJsont);
conf["aabbMin"] = customJsont;

//Save Components
list<nlohmann::json> componentsJson;
for (vector<Component*>::iterator it = components.begin(); it != components.end(); ++it)
{
Expand All @@ -246,6 +247,16 @@ void GameObject::save(nlohmann::json& conf) {
componentsJson.push_back(compJson);
}
conf["components"] = componentsJson;

//Save elementes
list<nlohmann::json> elementsJson;
for (vector<ElementGameUI*>::iterator it = elements.begin(); it != elements.end(); ++it)
{
nlohmann::json compJson;
(*it)->save(compJson);
elementsJson.push_back(compJson);
}
conf["elements"] = elementsJson;
}

void GameObject::load(nlohmann::json& conf) {
Expand Down Expand Up @@ -317,6 +328,46 @@ void GameObject::load(nlohmann::json& conf) {
break;
}
}

list<nlohmann::json> elementsJson = conf["elements"];
for (list<nlohmann::json>::iterator it = elementsJson.begin(); it != elementsJson.end(); ++it)
{
switch ((*it).at("TypeElemeneGametUI").get<int>())
{
case BUTTON:
{
UIButton* butonElem = new UIButton(this);
butonElem->type = BUTTON;
butonElem->load(*it);
addElement(butonElem);
}
break;
case LABEL:
{
UILabel* labelElem = new UILabel(this);
labelElem->type = LABEL;
labelElem->load(*it);
addElement(labelElem);
}
break;
case IMAGE:
{
UIImage * imageElem = new UIImage(this);
imageElem->type = IMAGE;
imageElem->load(*it);
addElement(imageElem);
}
break;
case EDITTEXT:
{
UIEditText* editTextElem = new UIEditText(this);
editTextElem->type = BUTTON;
editTextElem->load(*it);
addElement(editTextElem);
}
break;
}
}
}

void GameObject::drawComponentsElementsGui()
Expand Down
Loading

0 comments on commit 61b970a

Please sign in to comment.