diff --git a/assets/black_square.png b/assets/black_square.png new file mode 100755 index 0000000..9bc56ce Binary files /dev/null and b/assets/black_square.png differ diff --git a/assets/galaxy_ptree.json b/assets/galaxy_ptree.json index c60cc0d..80f1491 100755 --- a/assets/galaxy_ptree.json +++ b/assets/galaxy_ptree.json @@ -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" } diff --git a/assets/red_square.png b/assets/red_square.png new file mode 100755 index 0000000..7b14681 Binary files /dev/null and b/assets/red_square.png differ diff --git a/game/galaxy_menu.cpp b/game/galaxy_menu.cpp index aff396a..3db5477 100755 --- a/game/galaxy_menu.cpp +++ b/game/galaxy_menu.cpp @@ -1,6 +1,7 @@ #include "galaxy_menu.h" #include +#include 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> 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 + )); + */ } \ No newline at end of file diff --git a/game/galaxy_menu.h b/game/galaxy_menu.h index ebc7864..b2d304c 100755 --- a/game/galaxy_menu.h +++ b/game/galaxy_menu.h @@ -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); diff --git a/game/galaxy_objects.h b/game/galaxy_objects.h index 1f0adbc..dd3a903 100755 --- a/game/galaxy_objects.h +++ b/game/galaxy_objects.h @@ -4,6 +4,36 @@ #include "include/Engine.h" #include +class LevelSelection { +public: + + std::vector levels; + + // #params + //float buttons_plane_Yoffset = 0.2f; // relative to the screen + std::pair params; + std::pair buttons_plane; + std::vector> 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 levels; - - // #params - std::pair params; - std::pair buttons_plane; - std::vector> 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 \ No newline at end of file diff --git a/game/main_code.cpp b/game/main_code.cpp index fb69edb..cecbf47 100644 --- a/game/main_code.cpp +++ b/game/main_code.cpp @@ -303,6 +303,11 @@ void TMyApplication::LoadResources() } } + /*..buttons and level list plane textures..*/ + TextureNamesToLoad.push_back(std::pair("red_square.png", "red_square")); + TextureNamesToLoad.push_back(std::pair("black_square.png", "black_square")); + + TextureNamesToLoad.push_back(std::pair("levelshot1.png", "levelshot1")); TextureNamesToLoad.push_back(std::pair("levelshot2.png", "levelshot2")); TextureNamesToLoad.push_back(std::pair("levelshot3.png", "levelshot3"));