Skip to content

Commit

Permalink
[LCS-135] and [LCS-128]
Browse files Browse the repository at this point in the history
The GameUI manager and element class has been created and now u can draw an element form GameUI
  • Loading branch information
ferran coma rosell committed Mar 7, 2018
1 parent fb01722 commit 949e250
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 6 deletions.
4 changes: 3 additions & 1 deletion LCSEngine/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ModuleSceneMain.h"
#include "ModuleCamera.h"
#include "ModuleAnimation.h"
#include "ModuleGameUI.h"

using namespace std;

Expand All @@ -28,7 +29,8 @@ Application::Application()
modules.push_back(fade = new ModuleFadeToBlack());
modules.push_back(animations = new ModuleAnimation());
modules.push_back(sceneMain = new ModuleSceneMain(false));

modules.push_back(gameUI = new ModuleGameUI());

timer = 0;
deltaTime = 0;
}
Expand Down
2 changes: 2 additions & 0 deletions LCSEngine/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ModuleSceneMain;
class ModuleGUI;
class ModuleCamera;
class ModuleAnimation;
class ModuleGameUI;

class Application
{
Expand All @@ -40,6 +41,7 @@ class Application
ModuleGUI* gui;
ModuleCamera* camera;
ModuleAnimation* animations;
ModuleGameUI* gameUI;

private:
std::list<Module*> modules;
Expand Down
15 changes: 15 additions & 0 deletions LCSEngine/ElementGameUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Globals.h"
#include "Application.h"
#include "ElementGameUI.h"

ElementGameUI::ElementGameUI(TypeElemeneGametUI typeElement, int x, int y, int h, int w, bool isVisible)
{
type = typeElement;
visible = isVisible;
rect.x = x;
rect.y = y;
rect.h = h;
rect.w = w;
}

ElementGameUI::~ElementGameUI() {}
19 changes: 19 additions & 0 deletions LCSEngine/ElementGameUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __ELEMENTGAMEUI_H__
#define __ELEMENTGAMEUI_H__

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

class ElementGameUI
{
public:
ElementGameUI(TypeElemeneGametUI typeElement, int x, int y, int h, int w, bool isVisible = true);
~ElementGameUI();

public:
TypeElemeneGametUI type;
SDL_Rect rect;
bool visible;
};

#endif // __ELEMENTGAMEUI_H__
4 changes: 3 additions & 1 deletion LCSEngine/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ void GameObject::addComponent(Component* component)

vector<Component*>::iterator GameObject::deleteComponent(Component* component)
{
for (vector<Component*>::iterator it = components.begin(); it != components.end();)
vector<Component*>::iterator it = components.begin();
for (it; it != components.end();)
{
if (*it == component)
{
Expand Down Expand Up @@ -247,6 +248,7 @@ vector<Component*>::iterator GameObject::deleteComponent(Component* component)
++it;
}
}
return it;
}

void GameObject::addGameObject(GameObject* gameObject)
Expand Down
8 changes: 8 additions & 0 deletions LCSEngine/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ enum TypeComponent
AUDIOSOURCE
};

enum TypeElemeneGametUI
{
IMAGE,
LABEL,
BUTTON,
EDITTEXT
};

// Deletes a buffer
#define RELEASE( x ) \
{\
Expand Down
4 changes: 4 additions & 0 deletions LCSEngine/LCSEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<ClInclude Include="Component.h" />
<ClInclude Include="ComponentFactory.h" />
<ClInclude Include="CubeShape.h" />
<ClInclude Include="ElementGameUI.h" />
<ClInclude Include="GameObject.h" />
<ClInclude Include="Globals.h" />
<ClInclude Include="ImGuizmo.h" />
Expand Down Expand Up @@ -232,6 +233,7 @@
<ClInclude Include="ModuleAudio.h" />
<ClInclude Include="ModuleCamera.h" />
<ClInclude Include="ModuleFadeToBlack.h" />
<ClInclude Include="ModuleGameUI.h" />
<ClInclude Include="ModuleGUI.h" />
<ClInclude Include="ModuleInput.h" />
<ClInclude Include="ModuleSceneMain.h" />
Expand All @@ -258,6 +260,7 @@
<ClCompile Include="Component.cpp" />
<ClCompile Include="ComponentFactory.cpp" />
<ClCompile Include="CubeShape.cpp" />
<ClCompile Include="ElementGameUI.cpp" />
<ClCompile Include="GameObject.cpp" />
<ClCompile Include="ImGuizmo.cpp" />
<ClCompile Include="Imgui\imgui.cpp" />
Expand Down Expand Up @@ -305,6 +308,7 @@
<ClCompile Include="ModuleAudio.cpp" />
<ClCompile Include="ModuleCamera.cpp" />
<ClCompile Include="ModuleFadeToBlack.cpp" />
<ClCompile Include="ModuleGameUI.cpp" />
<ClCompile Include="ModuleGUI.cpp" />
<ClCompile Include="ModuleInput.cpp" />
<ClCompile Include="ModuleSceneMain.cpp" />
Expand Down
15 changes: 15 additions & 0 deletions LCSEngine/LCSEngine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<Filter Include="Physics">
<UniqueIdentifier>{10a460ff-d374-4d42-aafd-62e7a830c645}</UniqueIdentifier>
</Filter>
<Filter Include="Components\GameUIComponents">
<UniqueIdentifier>{501161e4-a8a6-4c95-b4cd-f20186decc93}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Animation.h">
Expand Down Expand Up @@ -354,6 +357,12 @@
<ClInclude Include="AudioListenerComponent.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="ModuleGameUI.h">
<Filter>Core</Filter>
</ClInclude>
<ClInclude Include="ElementGameUI.h">
<Filter>Components\GameUIComponents</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Log.cpp">
Expand Down Expand Up @@ -563,6 +572,12 @@
<ClCompile Include="AudioListenerComponent.cpp">
<Filter>Components</Filter>
</ClCompile>
<ClCompile Include="ModuleGameUI.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="ElementGameUI.cpp">
<Filter>Components\GameUIComponents</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="MathGeoLib\src\Geometry\KDTree.inl">
Expand Down
4 changes: 2 additions & 2 deletions LCSEngine/ModuleAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ struct Bone

struct Animation
{
unsigned int duration = 0;
double duration = 0;
std::vector<Bone*> bones;
};

struct AnimationInstance
{
Animation* animation = nullptr;
unsigned int localTime = 0; //ms
double localTime = 0; //ms
bool loop = true;
};

Expand Down
68 changes: 68 additions & 0 deletions LCSEngine/ModuleGameUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "Globals.h"
#include "Application.h"
#include "ModuleSceneMain.h"
#include "ModuleWindow.h"
#include "ModuleGameUI.h"
#include "ModuleCamera.h"
#include "CameraComponent.h"
#include "ElementGameUI.h"
#include "Shader.h"
#include "Glew/include/glew.h"
#include "MathGeoLib/src/Math/float4x4.h"

ModuleGameUI::ModuleGameUI()
{
//TO_DEBUG
ElementGameUI* element = new ElementGameUI(BUTTON, 0, 0, 200, 200);
elements.push_back(element);
//END_DEBUG
}

ModuleGameUI::~ModuleGameUI() {}

update_status ModuleGameUI::update(float deltaTime)
{
printGameUI();
return UPDATE_CONTINUE;
}

void ModuleGameUI::printGameUI()
{
//TODO: Not working yet
glOrtho(-1.0, 1.0, -1.0, 1.0, 5, 100);
glMatrixMode(GL_MODELVIEW);

for (vector<ElementGameUI*>::iterator it = elements.begin(); it != elements.end(); ++it)
{
if ((*it)->visible)
{
/*GLuint program = App->sceneMain->shader->programs[App->sceneMain->shader->defaultShaders[DEFAULTSHADER]];
glUseProgram(program);
float4x4 identity = float4x4::identity;
GLint modelLoc = glGetUniformLocation(program, "model_matrix");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, &identity[0][0]);
GLint viewLoc = glGetUniformLocation(program, "view");
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, App->camera->getViewMatrix());
GLint projectLoc = glGetUniformLocation(program, "projection");
glUniformMatrix4fv(projectLoc, 1, GL_FALSE, App->camera->getProjectMatrix());
float3 cameraPos = App->camera->currentCamera->frustum.pos;*/

float x1 = (float)((*it)->rect.x);
float x2 = (float)((*it)->rect.x + (*it)->rect.w);
float y1 = (float)((*it)->rect.y);
float y2 = (float)((*it)->rect.y + (*it)->rect.h);

glBegin(GL_POLYGON);
glVertex2f(x1, y1);
glVertex2f(x2, y1);
glVertex2f(x2, y2);
glVertex2f(x1, y2);
glEnd();
}
}
}
28 changes: 28 additions & 0 deletions LCSEngine/ModuleGameUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef __MODULEGAMEUI_H__
#define __MODULEGAMEUI_H__

#include "Module.h"
#include <vector>

using namespace std;

class ElementGameUI;

class ModuleGameUI : public Module
{
public:
ModuleGameUI();
~ModuleGameUI();
update_status update(float deltaTime) override;


public:
vector<ElementGameUI*> elements;

private:
void printGameUI();


};

#endif // __MODULEGAMEUI_H__
3 changes: 1 addition & 2 deletions LCSEngine/SceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ GameObject* SceneManager::createObject(GameObject* parent, aiNode* node)

if (node->mNumMeshes > 0)
{
for (int i = 0; i < node->mNumMeshes; ++i)
for (unsigned int i = 0; i < node->mNumMeshes; ++i)
{
GameObject* gameObjectMesh = new GameObject(gameObject, node->mName.C_Str());

Expand Down Expand Up @@ -88,7 +88,6 @@ GameObject* SceneManager::createObject(GameObject* parent, aiNode* node)
//Create texture
MaterialComponent* material = (MaterialComponent*)(factory->getComponent(MATERIAL, gameObjectMesh));
aiMaterial* currentMaterial = scene->mMaterials[currentMesh->mMaterialIndex];
unsigned int index;
aiString path;
currentMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &path);
material->textureChanged = true;
Expand Down

0 comments on commit 949e250

Please sign in to comment.