menu proc

This commit is contained in:
Alexander Tvorogov 2018-05-24 16:44:58 +05:00
parent 95bf02bd36
commit c30a2115dc
13 changed files with 126 additions and 32 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 995 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 870 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 MiB

View File

@ -1,22 +1,22 @@
{ {
"Space":[ "Space":[
{ {
"name": "galaxy_1", "name": "galaxy_0",
"position":{ "position":{
"x_coord": 0.5, "x_coord": 0.0,
"y_coord": 0.5 "y_coord": 0.0
}, },
"texture": "galaxy_1.png", "texture": "galaxy_0.png",
"scale": 1.0, "scale": 1.0,
"Stars": [ "Stars": [
{ {
"name": "star_1", "name": "star_0_0",
"position": { "position": {
"x_coord": 0.2, "x_coord": -0.45,
"y_coord": 0.3 "y_coord": 0.18
}, },
"texture": "star_1.png", "texture": "star_0_0.png",
"scale": 1.0, "scale": 0.06,
"levels": [ "levels": [
{ {
"name": "level_1" "name": "level_1"
@ -24,13 +24,13 @@
] ]
}, },
{ {
"name": "star_2", "name": "star_0_1",
"position": { "position": {
"x_coord": 0.2, "x_coord": 0.25,
"y_coord": 0.3 "y_coord": -0.15
}, },
"texture": "star_2.png", "texture": "star_0_1.png",
"scale": 1.0, "scale": 0.07,
"levels": [ "levels": [
{ {
"name": "level_1" "name": "level_1"

View File

@ -56,10 +56,14 @@ bool GalaxyMenu::InitGalaxyMenu(std::string config_json, float scale) {
} }
} }
void GalaxyMenu::UpdateGalaxyMenu() { void GalaxyMenu::UpdateGalaxyMenu(float s_width, float s_height) {
/*..Reset..*/
galaxies_params.clear();
stars_params.clear();
/*..Menu ancestor geometry..*/ /*..Menu ancestor geometry..*/
float gameScreenWidth = 800.f; float gameScreenWidth = s_width;
float gameScreenHeight = 480.f; float gameScreenHeight = s_height;
Eigen::Vector2f gameScreenCenter = Eigen::Vector2f(gameScreenWidth/2,gameScreenHeight/2); Eigen::Vector2f gameScreenCenter = Eigen::Vector2f(gameScreenWidth/2,gameScreenHeight/2);
/*..Menu geometry..*/ /*..Menu geometry..*/
@ -68,30 +72,41 @@ void GalaxyMenu::UpdateGalaxyMenu() {
Eigen::Vector2f currentMenuPos = Eigen::Vector2f(gameScreenCenter(0) + (gameScreenWidth/2/*relative to the screen x-dimension*/)*menuPosition(0), gameScreenCenter(1) + (gameScreenHeight/2/*relative to the screen y-dimension*/)*menuPosition(1)); Eigen::Vector2f currentMenuPos = Eigen::Vector2f(gameScreenCenter(0) + (gameScreenWidth/2/*relative to the screen x-dimension*/)*menuPosition(0), gameScreenCenter(1) + (gameScreenHeight/2/*relative to the screen y-dimension*/)*menuPosition(1));
/*..Galaxies geometry..*/ /*..Galaxies geometry..*/
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> galaxies_params; // ::position/dimensions::
std::vector<std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>>> stars_params;
for (int i = 0; i < galaxies.size(); i++) { for (int i = 0; i < galaxies.size(); i++) {
*SE::Console << "galaxy_" + std::to_string(i);
Eigen::Vector2f tex_size = textureSizeNormalize( Eigen::Vector2f tex_size = textureSizeNormalize(
Eigen::Vector2f(((float)SE::ResourceManager->TexList.GetTextureWidth("galaxy_texture_" + i)), ((float)SE::ResourceManager->TexList.GetTextureHeight("galaxy_texture_" + i))) Eigen::Vector2f(
((float)SE::ResourceManager->TexList.GetTextureWidth("galaxy_" + std::to_string(i))),
((float)SE::ResourceManager->TexList.GetTextureHeight("galaxy_" + std::to_string(i))))
); // normalized ); // normalized
galaxies_params.push_back(std::make_pair( galaxies_params.push_back(std::make_pair(
Eigen::Vector2f(currentMenuPos(0) + (xDimension/2)*galaxies[i].position(0), currentMenuPos(1) + (yDimension / 2)*galaxies[i].position(1)),
Eigen::Vector2f( Eigen::Vector2f(
tex_size(0)*galaxies[i].scale, currentMenuPos(0) + (xDimension/2)*galaxies[i].position(0),
tex_size(1)*galaxies[i].scale currentMenuPos(1) + (yDimension / 2)*galaxies[i].position(1)),
Eigen::Vector2f(
(tex_size(0)*galaxies[i].scale)*menuScale,
(tex_size(1)*galaxies[i].scale)*menuScale
) )
)); ));
/*..Stars geometry..*/ /*..Stars geometry..*/
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> star_params; std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> star_params;
for (int j = 0; j < galaxies[i].Stars.size(); j++) { for (int j = 0; j < galaxies[i].Stars.size(); j++) {
*SE::Console << "star_" + std::to_string(i) + "_" + std::to_string(j);
tex_size = textureSizeNormalize(
Eigen::Vector2f(
((float)SE::ResourceManager->TexList.GetTextureWidth("star_" + std::to_string(i) + "_" + std::to_string(j))),
((float)SE::ResourceManager->TexList.GetTextureHeight("star_" + std::to_string(i) + "_" + std::to_string(j))))
); // normalized
star_params.push_back(std::make_pair( star_params.push_back(std::make_pair(
Eigen::Vector2f( Eigen::Vector2f(
galaxies_params[i].first(0) + (galaxies_params[i].second(0)/2)*galaxies[i].Stars[j].scale, galaxies_params[i].first(0) + (galaxies_params[i].second(0)/2)*galaxies[i].Stars[j].position(0),
galaxies_params[i].first(1) + (galaxies_params[i].second(1)/2)*galaxies[i].Stars[j].scale galaxies_params[i].first(1) + (galaxies_params[i].second(1)/2)*galaxies[i].Stars[j].position(1)
), ),
Eigen::Vector2f() // #from here Eigen::Vector2f(
(tex_size(0)*galaxies[i].Stars[j].scale)*galaxies[i].scale*menuScale,
(tex_size(1)*galaxies[i].Stars[j].scale)*galaxies[i].scale*menuScale
)
)); ));
} }
stars_params.push_back(star_params); stars_params.push_back(star_params);
@ -130,6 +145,10 @@ Eigen::Vector2f GalaxyMenu::textureSizeNormalize(Eigen::Vector2f texVec, int t_t
y_dim = val_clamp(texVec(1), Ymin, Ymax); y_dim = val_clamp(texVec(1), Ymin, Ymax);
x_dim = y_dim * tex_ratio; x_dim = y_dim * tex_ratio;
} }
*SE::Console << "==============";
*SE::Console << std::to_string(texVec(0));
*SE::Console << std::to_string(texVec(1));
*SE::Console << "--------------";
return Eigen::Vector2f(x_dim, y_dim); return Eigen::Vector2f(x_dim, y_dim);
} }
@ -141,3 +160,48 @@ float GalaxyMenu::val_clamp(float val, float min, float max) {
else else
return val; return val;
} }
void GalaxyMenu::DrawGalaxyMenu() {
for (int i = 0; i < galaxies_params.size(); i++) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList["galaxy_" + std::to_string(i)]);
/*SE::Console << "c_out::";
*SE::Console << std::to_string((galaxies_params[i].second(0)));
*SE::Console << std::to_string((galaxies_params[i].first(1) - galaxies_params[i].second(1) / 2));
*SE::Console << std::to_string((galaxies_params[i].first(0) + galaxies_params[i].second(0) / 2));
*SE::Console << std::to_string((galaxies_params[i].first(1) + galaxies_params[i].second(1) / 2));*/
SE::Renderer->DrawRect(
Eigen::Vector2f(
galaxies_params[i].first(0) - galaxies_params[i].second(0)/2,
galaxies_params[i].first(1) - galaxies_params[i].second(1)/2
),
Eigen::Vector2f(
galaxies_params[i].first(0) + galaxies_params[i].second(0)/2,
galaxies_params[i].first(1) + galaxies_params[i].second(1)/2
)
); // DrawRect
/*..Draw stars..*/
if (stars_params.size() >= i) {
for (int j = 0; j < stars_params[i].size(); j++) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList["star_" + std::to_string(i) + "_" + std::to_string(j)]);
SE::Renderer->DrawRect(
Eigen::Vector2f(
stars_params[i][j].first(0) - stars_params[i][j].second(0) / 2,
stars_params[i][j].first(1) - stars_params[i][j].second(1) / 2
),
Eigen::Vector2f(
stars_params[i][j].first(0) + stars_params[i][j].second(0) / 2,
stars_params[i][j].first(1) + stars_params[i][j].second(1) / 2
)
); // DrawRect
}
}
}
}
void GalaxyMenu::InteractWithGalaxy() {
}

View File

@ -25,7 +25,7 @@ public:
// ======== Main Methods ======== // ======== Main Methods ========
bool InitGalaxyMenu(std::string config_json, float scale = 1.f); bool InitGalaxyMenu(std::string config_json, float scale = 1.f);
void DrawGalaxyMenu(); void DrawGalaxyMenu();
void UpdateGalaxyMenu(); void UpdateGalaxyMenu(float s_width, float s_height);
// ======== Main Methods ======== // ======== Main Methods ========
void InteractWithGalaxy(/*..Vector/Vector/Int..*/); // Prototype for mouse/tap events void InteractWithGalaxy(/*..Vector/Vector/Int..*/); // Prototype for mouse/tap events
@ -35,6 +35,8 @@ public:
float menuScale = 1.f; // (not const!!) float menuScale = 1.f; // (not const!!)
float xDimension; float xDimension;
float yDimension; float yDimension;
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> galaxies_params; // ::position/dimensions::
std::vector<std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>>> stars_params;
private: private:

View File

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include <string>
#include "include/Engine.h" #include "include/Engine.h"
@ -116,13 +117,12 @@ void TMyApplication::InnerInit()
ResourceManager->FontManager.AddFont("arial32", "arial32.png", "arial32.txt"); ResourceManager->FontManager.AddFont("arial32", "arial32.png", "arial32.txt");
ResourceManager->FontManager.AddFont("lucon12", "lucon12.png", "lucon12.txt"); ResourceManager->FontManager.AddFont("lucon12", "lucon12.png", "lucon12.txt");
ResourceManager->FontManager.PushFont("lucon12"); ResourceManager->FontManager.PushFont("lucon12");
ResourceManager->newGuiManager.LoadFromConfig("gui_main_menu.json"); //ResourceManager->newGuiManager.LoadFromConfig("gui_main_menu.json");
SetButtonsAction(); //SetButtonsAction();
// ------- UI ------- // ------- UI -------
// TESTS of menu // TESTS of menu
GalaxyMenu menu_ms; if (Menu.GalaxMenu.InitGalaxyMenu("galaxy_ptree.json")) {
if (menu_ms.InitGalaxyMenu("galaxy_ptree.json")) {
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;
} }
else { else {
@ -279,6 +279,16 @@ void TMyApplication::LoadResources()
TextureNamesToLoad.push_back(std::pair<std::string, std::string>("level_background/" + Textures_pt.get<std::string>("TextureList.bg_1") + bg_ext, "shutterstock11")); TextureNamesToLoad.push_back(std::pair<std::string, std::string>("level_background/" + Textures_pt.get<std::string>("TextureList.bg_1") + bg_ext, "shutterstock11"));
TextureNamesToLoad.push_back(std::pair<std::string, std::string>("level_background/" + Textures_pt.get<std::string>("TextureList.bg_1") + bg_ext, "shutterstock12")); TextureNamesToLoad.push_back(std::pair<std::string, std::string>("level_background/" + Textures_pt.get<std::string>("TextureList.bg_1") + bg_ext, "shutterstock12"));
/*..galaxies and stars/planets Init..*/ // tmp
std::vector<int> galaxies;
galaxies.resize(1);
galaxies[0] = 2;
for (int i = 0; i < galaxies.size(); i++) {
TextureNamesToLoad.push_back(std::pair<std::string, std::string>("/galax_menu/galaxies/galaxy_" + std::to_string(i) + ".png", "galaxy_" + std::to_string(i)));
for (int j = 0; j < galaxies[i]; j++) {
TextureNamesToLoad.push_back(std::pair<std::string, std::string>("/galax_menu/planets/star_" + std::to_string(i) + "_" + std::to_string(j) + ".png", "star_" + std::to_string(i) + "_" + std::to_string(j)));
}
}
TextureNamesToLoad.push_back(std::pair<std::string, std::string>("levelshot1.png", "levelshot1")); TextureNamesToLoad.push_back(std::pair<std::string, std::string>("levelshot1.png", "levelshot1"));
TextureNamesToLoad.push_back(std::pair<std::string, std::string>("levelshot2.png", "levelshot2")); TextureNamesToLoad.push_back(std::pair<std::string, std::string>("levelshot2.png", "levelshot2"));

View File

@ -22,17 +22,27 @@ TGameMenu::TGameMenu()
void TGameMenu::Draw() void TGameMenu::Draw()
{ {
#define NEW_MENU_DRAW
// *SE::Console << "TGameMenu::Draw"; // *SE::Console << "TGameMenu::Draw";
CheckGlError("Draw TGameMenu"); CheckGlError("Draw TGameMenu");
RenderUniform1i("sel", 0); RenderUniform1i("sel", 0);
RenderUniform1f("Transparency", 1.f); RenderUniform1f("Transparency", 1.f);
float bkgShift = MenuPos*0.1f - 100.f; float bkgShift = MenuPos*0.1f - 100.f;
#ifndef NEW_MENU_DRAW
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["main_menu_bkg_left"]); glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["main_menu_bkg_left"]);
Renderer->DrawRect(Vector2f(bkgShift,0.f), Vector2f(Renderer->GetScreenWidth()+bkgShift,Renderer->GetScreenHeight())); Renderer->DrawRect(Vector2f(bkgShift,0.f), Vector2f(Renderer->GetScreenWidth()+bkgShift,Renderer->GetScreenHeight()));
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["main_menu_bkg_right"]); glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["main_menu_bkg_right"]);
Renderer->DrawRect(Vector2f(Renderer->GetScreenWidth()+bkgShift,0.f), Vector2f(960.f+bkgShift,Renderer->GetScreenHeight())); Renderer->DrawRect(Vector2f(Renderer->GetScreenWidth()+bkgShift,0.f), Vector2f(960.f+bkgShift,Renderer->GetScreenHeight()));
#else
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
/*..GalaxMenu draw..*/
GalaxMenu.DrawGalaxyMenu();
#endif
#ifndef NEW_MENU_DRAW
if (SelectedGame == 0) if (SelectedGame == 0)
{ {
RenderUniform1i("sel", 1); RenderUniform1i("sel", 1);
@ -62,6 +72,7 @@ void TGameMenu::Draw()
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["logo_small"]); glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["logo_small"]);
Renderer->DrawRect(Vector2f(240.f-128.f+15.f, 0.f), Vector2f(240.f+128.f+15.f, 64.f)); Renderer->DrawRect(Vector2f(240.f-128.f+15.f, 0.f), Vector2f(240.f+128.f+15.f, 64.f));
#endif
CheckGlError("Draw TGameMenu 2"); CheckGlError("Draw TGameMenu 2");
@ -70,6 +81,9 @@ void TGameMenu::Draw()
void TGameMenu::Update(size_t dt) void TGameMenu::Update(size_t dt)
{ {
/*..Galaxy Menu..*/
GalaxMenu.UpdateGalaxyMenu((float)SE::Renderer->GetScreenWidth(), (float)SE::Renderer->GetScreenHeight());
if (HoldToTap) if (HoldToTap)
return; return;
// åñëè êíîïêà íå íàæàòà // åñëè êíîïêà íå íàæàòà

View File

@ -3,6 +3,7 @@
#include "include/Engine.h" #include "include/Engine.h"
#include "game_area_interface.h" #include "game_area_interface.h"
#include "galaxy_menu.h"
using namespace SE; using namespace SE;
@ -34,6 +35,9 @@ public:
int GetMenuItemCount(); int GetMenuItemCount();
void SetMenuItemCount(int menuItemCount); void SetMenuItemCount(int menuItemCount);
/*..Galaxy Menu..*/
GalaxyMenu GalaxMenu;
}; };