need fix at galaxy_menu.cpp #222

This commit is contained in:
Alexander Tvorogov 2018-06-01 16:45:16 +05:00
parent 1abfa608b2
commit e25f4e3237
9 changed files with 1874 additions and 1751 deletions

View File

@ -6,6 +6,7 @@
GalaxyMenu::GalaxyMenu()
{
}
GalaxyMenu::~GalaxyMenu()
@ -46,7 +47,12 @@ bool GalaxyMenu::InitGalaxyMenu(std::string config_json, float scale) {
/*..Levels..*/
BOOST_FOREACH(auto levels_pt, stars_pt.second.get_child("levels")) {
star.selectionMenu.levels.push_back(levels_pt.second.get<std::string>("name", "empty"));
std::string levelName = levels_pt.second.get<std::string>("name", "empty");
star.selectionMenu.levels.push_back(levelName);
TGameLevel lvl;
lvl.FillWithFile(ST::PathToResources + "level" + levelName.substr(levelName.find("_") + 1) + ".txt");
star.selectionMenu.gameLevels.push_back(lvl);
}
galax.Stars.push_back(star);
@ -158,8 +164,15 @@ void GalaxyMenu::UpdateGalaxyMenu(float s_width, float s_height, size_t dt) {
// 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++) {
std::vector<std::vector<GameLevelInterior>> interior_params;
int levelsCount = galaxies[i].Stars[j].selectionMenu.levels.size();
buttons_params.resize(levelsCount);
interior_params.resize(levelsCount);
for (int v = 0; v < interior_params.size(); v++) {
interior_params[v].resize(CONST_BRICKMATRIX_HEIGHT*CONST_BRICKMATRIX_WIDTH);
}
for (int y = 0; y < levelsCount; y++) {
GameLevelInterior levelInter;
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 /**/);
@ -176,7 +189,46 @@ void GalaxyMenu::UpdateGalaxyMenu(float s_width, float s_height, size_t dt) {
)
);
/*..Interior params..*/
/*.matrix init.*/
int brickMatr[CONST_BRICKMATRIX_WIDTH][CONST_BRICKMATRIX_HEIGHT];
for (int w = 0; w < CONST_BRICKMATRIX_WIDTH; w++)
{
for (int h = 0; h < CONST_BRICKMATRIX_HEIGHT; h++)
{
if (galaxies[i].Stars[j].selectionMenu.gameLevels[y].BlockMatrix[w][h].IsAppear()) {
brickMatr[w][h] = 1;
}
else {
brickMatr[w][h] = 0;
}
}
}
/*.params init.*/
float brick_w = 0.06f;
float brick_ratio = 1.6f;
float brick_h = brick_w / brick_ratio;
float xb_offset = 0.01f; // x border offset * 0.5
float yb_offset = 0.01f; // offset from top
int loop_itr = 0;
for (int w = 0; w < CONST_BRICKMATRIX_WIDTH; w++) {
for (int h = 0; h < CONST_BRICKMATRIX_HEIGHT; h++) {
levelInter.position = Eigen::Vector2f(
(buttons_params[y].first(0) - buttons_params[y].second(0)*0.5f) + (xb_offset + brick_w * w + brick_w * 0.5f) * buttons_params[y].second(0),
(buttons_params[y].first(1) + buttons_params[y].second(1)*0.5f) - (yb_offset + brick_h * h + brick_h * 0.5f)*buttons_params[y].second(1)
);
levelInter.dimensions = Eigen::Vector2f(
buttons_params[y].second(0)*brick_w/* * brickMatr[w][h]*/, //drawable block coefficient - #NOW NEED TO BE FIXED AT (matrix init) sections#
buttons_params[y].second(1)*brick_h/* * brickMatr[w][h]*/
);
//inited
interior_params[y][loop_itr++] = levelInter;
}
}
}
galaxies[i].Stars[j].selectionMenu.levelInterior = interior_params;
galaxies[i].Stars[j].selectionMenu.buttons = buttons_params;
}
}
@ -618,6 +670,18 @@ void GalaxyMenu::drawSelectionMenu(int index) {
galaxies[0].Stars[i].selectionMenu.buttons[j].first(1) + galaxies[0].Stars[i].selectionMenu.buttons[j].second(1) / 2
)
); // DrawRect
/*..draw level interior..*/
drawLevelInterior(i,j);
/*std::list<std::pair<PairColorTexture, TTriangleList>>::iterator colorBlockIterator;
for (colorBlockIterator = galaxies[0].Stars[i].selectionMenu.levelInterior[j].BlockInstansingList.ColorBlockList.begin(); colorBlockIterator != galaxies[0].Stars[i].selectionMenu.levelInterior[j].BlockInstansingList.ColorBlockList.end(); ++colorBlockIterator)
{
RenderUniform4fv("BrickColor", colorBlockIterator->first.first.data());
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList[colorBlockIterator->first.second]);
Renderer->DrawTriangleList(colorBlockIterator->second);
}*/
}
}
@ -723,3 +787,20 @@ void GalaxyMenu::drawBorder(Eigen::Vector2f lb_, Eigen::Vector2f rt_, float scal
); // bottom
}
}
void GalaxyMenu::drawLevelInterior(int star, int button) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList[CONST_BLOCK_TEXTURE1]);
for (int i = 0; i < galaxies[0].Stars[star].selectionMenu.levelInterior[button].size(); i++) {
Renderer->DrawRect(
Eigen::Vector2f(
galaxies[0].Stars[star].selectionMenu.levelInterior[button][i].position(0) - galaxies[0].Stars[star].selectionMenu.levelInterior[button][i].dimensions(0)*0.5f,
galaxies[0].Stars[star].selectionMenu.levelInterior[button][i].position(1) - galaxies[0].Stars[star].selectionMenu.levelInterior[button][i].dimensions(1)*0.5f
),
Eigen::Vector2f(
galaxies[0].Stars[star].selectionMenu.levelInterior[button][i].position(0) + galaxies[0].Stars[star].selectionMenu.levelInterior[button][i].dimensions(0)*0.5f,
galaxies[0].Stars[star].selectionMenu.levelInterior[button][i].position(1) + galaxies[0].Stars[star].selectionMenu.levelInterior[button][i].dimensions(1)*0.5f
)
);
}
}

View File

@ -5,6 +5,7 @@
#include <string>
#include "galaxy.h"
#include "level_interior.h"
#include "include/Engine.h"
@ -47,6 +48,7 @@ public:
private:
void readSaveData(); // inner init method
/*..calc methodes..*/
@ -83,6 +85,7 @@ private:
/*..draw methodes..*/
void drawSelectionMenu(int index);
void drawBorder(Eigen::Vector2f lb_, Eigen::Vector2f rt_, float scale, std::string mode);
void drawLevelInterior(int star = -1, int button = -1);
};

View File

@ -4,10 +4,17 @@
#include "include/Engine.h"
#include <string>
#include "gamecode.h" // tmp
#include "level_interior.h"
class LevelSelection {
public:
std::vector<std::string> levels;
/*..LEVELS..*/
std::vector<std::string> levels; // levels names, uses gameLevels init
/*..levels interior info..*/
std::vector<TGameLevel> gameLevels;
std::vector<std::vector<GameLevelInterior>> levelInterior;
// #params
//float buttons_plane_Yoffset = 0.2f; // relative to the screen
@ -53,6 +60,7 @@ public:
Eigen::Vector2f position;
float scale;
private:

View File

@ -1744,3 +1744,13 @@ void TGameLevel::TryGoToMenu()
}
}
bool TBrick::IsAppear() {
if (State == CONST_BRICKSTATE_DISAPPEAR)
{
return true;
}
else
{
return false;
}
}

View File

@ -3,6 +3,7 @@
#include "include/Engine.h"
#include "game_area_interface.h"
//#include "galaxy_menu.h"
#include <list>
@ -60,6 +61,7 @@ public:
void Disappear();
int GetLocked();
bool CanReact();
bool IsAppear();
};
class TBonusFalling
@ -120,6 +122,7 @@ struct TBallInstancingList
class TGameLevel : public TGameAreaAncestor
{
friend class TMyApplication;
friend class GalaxyMenu;
protected:
float lvlWidth;
float lvlHeight;

13
game/level_interior.h Executable file
View File

@ -0,0 +1,13 @@
#ifndef LEVEL_INTERIOR_H
#define LEVEL_INTERIOR_H
#include "include/Engine.h"
#include "gamecode.h"
struct GameLevelInterior {
Eigen::Vector2f position;
Eigen::Vector2f dimensions;
//reserved
};
#endif

View File

@ -81,7 +81,8 @@ void TMyApplication::InnerInit()
StateTimer = 0.f;
/*
ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt");
ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex
", "shader1fragment.txt");
ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt");
ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt");
Renderer->PushShader("DefaultShader");
@ -511,7 +512,7 @@ void TMyApplication::GoFromMenuToGame(int level)
//#endif
GameLevel.FillWithFile(ST::PathToResources + "level"+tostr(level+1)+".txt");
GameLevel.SetLoading("shutterstock" + tostr(level+1), "levelshot"+tostr(level+1));
GameLevel.SetLoading("shutterstock" + tostr(level+1), "shutterstock" + tostr(level + 1));
GameState = CONST_GAMESTATE_FROM_MENU_TO_LEVEL;
OnDrawSignal.connect(1, boost::bind(&TGameLevel::Draw, boost::ref(GameLevel)));

View File

@ -182,6 +182,7 @@
<ClInclude Include="..\..\..\game\galaxy_objects.h" />
<ClInclude Include="..\..\..\game\gamecode.h" />
<ClInclude Include="..\..\..\game\game_area_interface.h" />
<ClInclude Include="..\..\..\game\level_interior.h" />
<ClInclude Include="..\..\..\game\loadingcode.h" />
<ClInclude Include="..\..\..\game\main_code.h" />
<ClInclude Include="..\..\..\game\menucode.h" />

View File

@ -74,5 +74,8 @@
<ClInclude Include="..\..\..\game\galaxy_menu.h">
<Filter>Заголовочные файлы</Filter>
</ClInclude>
<ClInclude Include="..\..\..\game\level_interior.h">
<Filter>Заголовочные файлы</Filter>
</ClInclude>
</ItemGroup>
</Project>