From 82812eecb0691ea47f1909945e76897ecf583ff7 Mon Sep 17 00:00:00 2001 From: Alexander Tvorogov Date: Tue, 29 May 2018 16:44:55 +0500 Subject: [PATCH] level selection dev --- assets/black_square.png | Bin 0 -> 923 bytes assets/galaxy_ptree.json | 9 +++++ assets/red_square.png | Bin 0 -> 1573 bytes game/galaxy_menu.cpp | 83 ++++++++++++++++++++++++++++++++++----- game/galaxy_menu.h | 2 + game/galaxy_objects.h | 58 ++++++++++++++------------- game/main_code.cpp | 5 +++ 7 files changed, 120 insertions(+), 37 deletions(-) create mode 100755 assets/black_square.png create mode 100755 assets/red_square.png diff --git a/assets/black_square.png b/assets/black_square.png new file mode 100755 index 0000000000000000000000000000000000000000..9bc56ce47256149aaf9df03cf789557aa09e296a GIT binary patch literal 923 zcmeAS@N?(olHy`uVBq!ia0y~yU;;9k7&t&wwUqN(AjMhW5n0T@z%2~Ij105pNB{-d zOFVsD*&ngWvYQIHGhOik3dv@MM3gw^=jNv7l>oU649-QVi6yBi3gww484B*6z5ywE zsq734%z~aSjv*Dd-X3fOsXDyiXK?&OhEPTjXB3Qvz=#Wh1Nlr_7#RQGUeuupPQSSR|4cRFgO>bCYGe8D3oWGWGJ|M`Ua%v zrLr?Hu+H{$aSW-r_4cYEBZC3QfenWK83*?ZeK_E)w9tR?W;urMHJl7Q3=GT+2N)O( z7|3D{tahNIDRDgI+Ic7lI&g@SAM&sWgVAJ~M4@(|tpl3`cpR7pI1Nyk0!Ne3Kqnz! g7N9T=N!ETta!My_w{-kGH3lH?boFyt=akR{0F-{NJ^%m! literal 0 HcmV?d00001 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"));