level selection dev

This commit is contained in:
Alexander Tvorogov 2018-05-29 16:44:55 +05:00
parent 457541edf5
commit 82812eecb0
7 changed files with 120 additions and 37 deletions

BIN
assets/black_square.png Executable file

Binary file not shown.

After

(image error) Size: 923 B

View File

@ -18,6 +18,15 @@
"texture": "star_0_0.png",
"scale": 0.1,
"levels": [
{
"name": "level_0"
},
{
"name": "level_1"
},
{
"name": "level_1"
},
{
"name": "level_1"
}

BIN
assets/red_square.png Executable file

Binary file not shown.

After

(image error) Size: 1.5 KiB

View File

@ -1,6 +1,7 @@
#include "galaxy_menu.h"
#include <algorithm>
#include <math.h>
GalaxyMenu::GalaxyMenu()
{
@ -128,14 +129,18 @@ void GalaxyMenu::UpdateGalaxyMenu(float s_width, float s_height, size_t dt) {
/*..Level list geometry..*/
for (int i = 0; i < galaxies.size(); i++) {
for (int j = 0; j < galaxies[i].Stars.size(); j++) {
float button_x_dim = ((1.f - (galaxies[i].Stars[j].selectionMenu.border_x_offset * 2 + (galaxies[i].Stars[j].selectionMenu.columns - 1)*galaxies[i].Stars[j].selectionMenu.buttons_offset)) / galaxies[i].Stars[j].selectionMenu.columns); // relative size
int rows_count = (int)ceil((float)galaxies[i].Stars[j].selectionMenu.levels.size() / (float)galaxies[i].Stars[j].selectionMenu.columns);
galaxies[i].Stars[j].selectionMenu.params = std::make_pair(
Eigen::Vector2f(
currentMenuPos(0) + (galaxies[i].Stars[j].selectionMenu.offset(0) * gameScreenWidth / 2),
currentMenuPos(1) + (galaxies[i].Stars[j].selectionMenu.offset(1) * gameScreenHeight / 2)
gameScreenCenter(0) + (galaxies[i].Stars[j].selectionMenu.offset(0) * gameScreenWidth / 2),
gameScreenCenter(1) + (galaxies[i].Stars[j].selectionMenu.offset(1) * gameScreenHeight / 2)
),
Eigen::Vector2f(
gameScreenWidth * galaxies[i].Stars[j].selectionMenu.dim(0),
gameScreenHeight * galaxies[i].Stars[j].selectionMenu.dim(1)
//gameScreenHeight * galaxies[i].Stars[j].selectionMenu.dim(1)
//gameScreenHeight * galaxies[i].Stars[j].selectionMenu.dim(1) * (galaxies[i].Stars[j].selectionMenu.border_y_offset * 2 + (ceil(galaxies[i].Stars[j].selectionMenu.levels.size() / galaxies[i].Stars[j].selectionMenu.columns) - 1)*galaxies[i].Stars[j].selectionMenu.buttons_offset) + galaxies[i].Stars[j].selectionMenu.dim(0)*(ceil(galaxies[i].Stars[j].selectionMenu.levels.size() / galaxies[i].Stars[j].selectionMenu.columns)*(button_x_dim / galaxies[i].Stars[j].selectionMenu.buttons_ratio))
gameScreenWidth * galaxies[i].Stars[j].selectionMenu.dim(0) * (galaxies[i].Stars[j].selectionMenu.border_y_offset * 2 + rows_count*(button_x_dim/galaxies[i].Stars[j].selectionMenu.buttons_ratio) + (rows_count-1)*galaxies[i].Stars[j].selectionMenu.border_y_offset)
)
);
/*..buttons plane..*/
@ -149,18 +154,29 @@ void GalaxyMenu::UpdateGalaxyMenu(float s_width, float s_height, size_t dt) {
galaxies[i].Stars[j].selectionMenu.params.second(1) * galaxies[i].Stars[j].selectionMenu.plane_size(1)
)
);
// buttons plane dimensions build, relative to buttons #from here
// buttons
for (int y = 0; y < galaxies[i].Stars[j].selectionMenu.levels.size(); y++) {
galaxies[i].Stars[j].selectionMenu.buttons.push_back(std::make_pair(
Eigen::Vector2f(
// buttons
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> buttons_params;
buttons_params.resize(galaxies[i].Stars[j].selectionMenu.levels.size());
for (int y = 0; y < buttons_params.size(); y++) {
float x_rpos = (galaxies[i].Stars[j].selectionMenu.border_x_offset + (y - floor((float)y / (float)galaxies[i].Stars[j].selectionMenu.columns)*(float)galaxies[i].Stars[j].selectionMenu.columns)*(button_x_dim + galaxies[i].Stars[j].selectionMenu.buttons_offset) + button_x_dim/2);
//float y_rpos = (/**/ galaxies[i].Stars[j].selectionMenu.border_y_offset + (floor((float)y / (float)galaxies[i].Stars[j].selectionMenu.columns))*(/*..*/ galaxies[i].Stars[j].selectionMenu.buttons_offset + button_x_dim / galaxies[i].Stars[j].selectionMenu.buttons_ratio /*..*/) + button_x_dim/galaxies[i].Stars[j].selectionMenu.buttons_ratio/2 /**/);
float y_rpos = (galaxies[i].Stars[j].selectionMenu.border_y_offset + ((int)floor(((float)y)/((float)galaxies[i].Stars[j].selectionMenu.columns)))*(button_x_dim/galaxies[i].Stars[j].selectionMenu.buttons_ratio) + (((int)floor(((float)y) / ((float)galaxies[i].Stars[j].selectionMenu.columns)))-1) * galaxies[i].Stars[j].selectionMenu.border_y_offset + ((button_x_dim/galaxies[i].Stars[j].selectionMenu.buttons_ratio)/2.f));
buttons_params[y] = std::make_pair(
Eigen::Vector2f(
(galaxies[i].Stars[j].selectionMenu.buttons_plane.first(0) - galaxies[i].Stars[j].selectionMenu.buttons_plane.second(0)/2) + galaxies[i].Stars[j].selectionMenu.buttons_plane.second(0)*x_rpos,
(galaxies[i].Stars[j].selectionMenu.buttons_plane.first(1) + galaxies[i].Stars[j].selectionMenu.buttons_plane.second(1)/2) - galaxies[i].Stars[j].selectionMenu.buttons_plane.second(1)*y_rpos
),
Eigen::Vector2f(
button_x_dim*galaxies[i].Stars[j].selectionMenu.buttons_plane.second(0),
(button_x_dim / galaxies[i].Stars[j].selectionMenu.buttons_ratio)*galaxies[i].Stars[j].selectionMenu.buttons_plane.second(1)
)
));
);
}
galaxies[i].Stars[j].selectionMenu.buttons = buttons_params;
}
}
@ -243,6 +259,9 @@ void GalaxyMenu::DrawGalaxyMenu() {
); // DrawRect
}
}
/*..Draw level selection menu..*/
drawSelectionMenu(0);
}
}
@ -477,4 +496,50 @@ void GalaxyMenu::showLevelSelectMenu(int index) {
}
void GalaxyMenu::drawSelectionMenu(int index) {
int i = index;
if (i != -1) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList["red_square"]);
SE::Renderer->DrawRect(
Eigen::Vector2f(
galaxies[0].Stars[i].selectionMenu.buttons_plane.first(0) - galaxies[0].Stars[i].selectionMenu.buttons_plane.second(0) / 2,
galaxies[0].Stars[i].selectionMenu.buttons_plane.first(1) - galaxies[0].Stars[i].selectionMenu.buttons_plane.second(1) / 2
),
Eigen::Vector2f(
galaxies[0].Stars[i].selectionMenu.buttons_plane.first(0) + galaxies[0].Stars[i].selectionMenu.buttons_plane.second(0) / 2,
galaxies[0].Stars[i].selectionMenu.buttons_plane.first(1) + galaxies[0].Stars[i].selectionMenu.buttons_plane.second(1) / 2
)
); // DrawRect
// buttons
for (int j = 0; j < galaxies[0].Stars[i].selectionMenu.buttons.size(); j++) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList["black_square"]);
SE::Renderer->DrawRect(
Eigen::Vector2f(
galaxies[0].Stars[i].selectionMenu.buttons[j].first(0) - galaxies[0].Stars[i].selectionMenu.buttons[j].second(0) / 2,
galaxies[0].Stars[i].selectionMenu.buttons[j].first(1) - galaxies[0].Stars[i].selectionMenu.buttons[j].second(1) / 2
),
Eigen::Vector2f(
galaxies[0].Stars[i].selectionMenu.buttons[j].first(0) + galaxies[0].Stars[i].selectionMenu.buttons[j].second(0) / 2,
galaxies[0].Stars[i].selectionMenu.buttons[j].first(1) + galaxies[0].Stars[i].selectionMenu.buttons[j].second(1) / 2
)
); // DrawRect
}
}
/*
// debug
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList["red_square"]);
SE::Renderer->DrawRect(
Eigen::Vector2f(
galaxies[0].Stars[0].selectionMenu.params.first(0) - galaxies[0].Stars[0].selectionMenu.params.second(0) / 2,
galaxies[0].Stars[0].selectionMenu.params.first(1) - galaxies[0].Stars[0].selectionMenu.params.second(1) / 2
),
Eigen::Vector2f(
galaxies[0].Stars[0].selectionMenu.params.first(0) + galaxies[0].Stars[0].selectionMenu.params.second(0) / 2,
galaxies[0].Stars[0].selectionMenu.params.first(1) + galaxies[0].Stars[0].selectionMenu.params.second(1) / 2
));
*/
}

View File

@ -49,6 +49,8 @@ private:
void readSaveData(); // inner init method
void drawSelectionMenu(int index);
Eigen::Vector2f textureSizeNormalize(Eigen::Vector2f texVec, int t_type = 0/*0-galaxy, 1-stars*/);
float val_clamp(float v, float min, float max);
Eigen::Vector2f findCorner(int x_c, int y_c);

View File

@ -4,6 +4,36 @@
#include "include/Engine.h"
#include <string>
class LevelSelection {
public:
std::vector<std::string> levels;
// #params
//float buttons_plane_Yoffset = 0.2f; // relative to the screen
std::pair<Eigen::Vector2f, Eigen::Vector2f> params;
std::pair<Eigen::Vector2f, Eigen::Vector2f> buttons_plane;
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> buttons;
Eigen::Vector2f offset = Eigen::Vector2f(0.f, 0.f); // offset
Eigen::Vector2f dim = Eigen::Vector2f(0.7f, 0.9f); // dimensions, y - is not const, relative to the levels count
/*..buttons plane params..*/
Eigen::Vector2f plane_size = Eigen::Vector2f(1.f, 1.f); // y- is not const, relative to the levels count
Eigen::Vector2f plane_pos = Eigen::Vector2f(0.f, 0.f); // relative to center
/*..buttons params..*/
int columns = 3;
float border_y_offset = 0.03f;
float border_x_offset = 0.03f;
float buttons_offset = 0.03f;
float buttons_ratio = 1.6f;
private:
};
class StarObject {
public:
@ -28,33 +58,5 @@ private:
};
class LevelSelection {
public:
std::vector<std::string> levels;
// #params
std::pair<Eigen::Vector2f, Eigen::Vector2f> params;
std::pair<Eigen::Vector2f, Eigen::Vector2f> buttons_plane;
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> buttons;
Eigen::Vector2f offset = Eigen::Vector2f(0.f,0.f); // offset
Eigen::Vector2f dim = Eigen::Vector2f(0.7f, 0.7f); // dimensions
/*..buttons plane params..*/
Eigen::Vector2f plane_size = Eigen::Vector2f(1.f, 1.f);
Eigen::Vector2f plane_pos = Eigen::Vector2f(0.f, 0.f); // relative to center
/*..buttons params..*/
int columns = 3;
//float col_size = 1.f;
float border_y_offset = 0.f;
float border_x_offset = 0.1f;
float buttons_offset = 0.1f;
private:
};
#endif

View File

@ -303,6 +303,11 @@ void TMyApplication::LoadResources()
}
}
/*..buttons and level list plane textures..*/
TextureNamesToLoad.push_back(std::pair<std::string, std::string>("red_square.png", "red_square"));
TextureNamesToLoad.push_back(std::pair<std::string, std::string>("black_square.png", "black_square"));
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>("levelshot3.png", "levelshot3"));