menu interact

This commit is contained in:
Alexander Tvorogov 2018-05-25 16:51:26 +05:00
parent c30a2115dc
commit c97c95baa6
13 changed files with 271 additions and 27 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 995 KiB

After

Width:  |  Height:  |  Size: 1000 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 870 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -3,17 +3,17 @@
{
"name": "galaxy_0",
"position":{
"x_coord": 0.0,
"y_coord": 0.0
"x_coord": -0.45,
"y_coord": 0.4
},
"texture": "galaxy_0.png",
"scale": 1.0,
"scale": 0.6,
"Stars": [
{
"name": "star_0_0",
"position": {
"x_coord": -0.45,
"y_coord": 0.18
"y_coord": 0.15
},
"texture": "star_0_0.png",
"scale": 0.06,
@ -38,6 +38,31 @@
]
}
]
},
{
"name": "galaxy_1",
"position":{
"x_coord": 0.4,
"y_coord": 0.05
},
"texture": "galaxy_1.png",
"scale": 0.7,
"Stars": [
{
"name": "star_1_0",
"position": {
"x_coord": -0.15,
"y_coord": 0.15
},
"texture": "star_1_0.png",
"scale": 0.06,
"levels": [
{
"name": "level_1"
}
]
}
]
}
]
}

View File

@ -26,7 +26,7 @@ bool GalaxyMenu::InitGalaxyMenu(std::string config_json, float scale) {
error_pt.put("error", "something goes wrong at InitGalaxyMenu");
/*..Init Menu..*/
BOOST_FOREACH(auto menu_pt, config_pt.get_child("Space")) {
BOOST_FOREACH(auto menu_pt, config_pt.get_child("Space", error_pt)) {
Galaxy galax;
galax.name = menu_pt.second.get<std::string>("name", "error");
@ -62,8 +62,8 @@ void GalaxyMenu::UpdateGalaxyMenu(float s_width, float s_height) {
stars_params.clear();
/*..Menu ancestor geometry..*/
float gameScreenWidth = s_width;
float gameScreenHeight = s_height;
float gameScreenWidth = s_width * anchorSize;
float gameScreenHeight = s_height * anchorSize;
Eigen::Vector2f gameScreenCenter = Eigen::Vector2f(gameScreenWidth/2,gameScreenHeight/2);
/*..Menu geometry..*/
@ -81,14 +81,15 @@ void GalaxyMenu::UpdateGalaxyMenu(float s_width, float s_height) {
); // normalized
galaxies_params.push_back(std::make_pair(
Eigen::Vector2f(
currentMenuPos(0) + (xDimension/2)*galaxies[i].position(0),
currentMenuPos(0) + (xDimension / 2)*galaxies[i].position(0),
currentMenuPos(1) + (yDimension / 2)*galaxies[i].position(1)),
Eigen::Vector2f(
(tex_size(0)*galaxies[i].scale)*menuScale,
(tex_size(1)*galaxies[i].scale)*menuScale
)
));
*SE::Console << "dimensions: " << std::to_string(((tex_size(0)*galaxies[i].scale)*menuScale)) << " " << std::to_string(((tex_size(1)*galaxies[i].scale)*menuScale));
/*..Stars geometry..*/
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> star_params;
for (int j = 0; j < galaxies[i].Stars.size(); j++) {
@ -125,16 +126,16 @@ Eigen::Vector2f GalaxyMenu::textureSizeNormalize(Eigen::Vector2f texVec, int t_t
float Ymax; // Max normalized texture height
float Ymin;
if (t_type == 0) {
Xmax = 1280.f;
Xmin = 800.f;
Ymax = 1024.f;
Ymin = 640.f;
Xmax = SE::Renderer->GetScreenWidth();
Xmin = Xmax;
Ymax = SE::Renderer->GetScreenHeight();
Ymin = Ymax;
}
else { // temp for star textures
Xmax = 512.f;
Xmin = 320.f;
Ymax = 512.f;
Ymin = 320.f;
Xmax = (((float)SE::Renderer->GetScreenWidth())/2);
Xmin = Xmax;
Ymax = (((float)SE::Renderer->GetScreenHeight())/2);
Ymin = Ymax;
}
if (texVec(0) > texVec(1)) {
@ -144,10 +145,11 @@ Eigen::Vector2f GalaxyMenu::textureSizeNormalize(Eigen::Vector2f texVec, int t_t
else {
y_dim = val_clamp(texVec(1), Ymin, Ymax);
x_dim = y_dim * tex_ratio;
}
}
*SE::Console << "==============";
*SE::Console << std::to_string(texVec(0));
*SE::Console << std::to_string(texVec(1));
*SE::Console << "if value 0.0000 - must be textures not inited at main_code.cpp or texture-name is wrong";
*SE::Console << "--------------";
return Eigen::Vector2f(x_dim, y_dim);
}
@ -166,11 +168,6 @@ 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,
@ -202,6 +199,193 @@ void GalaxyMenu::DrawGalaxyMenu() {
}
void GalaxyMenu::InteractWithGalaxy() {
void GalaxyMenu::InteractWithGalaxy(size_t dt) {
if (timer_active) {
// ::::::::::::: timer active ::::::::::::::
if (menuState == 0) { // main view
//std::pair<Eigen::Vector2f, Eigen::Vector2f> spacePlane = std::make_pair(findCorner(0, 0), findCorner(1, 1));
}
if (menuState == 1) { // zoomed galaxy
}
if (menuState == 2) { // level select view
}
// \_/\_/\_/\_/ timer active \_/\_/\_/\_/
}
else {
// ::::::::::::: timer inactive ::::::::::::::
if (lastTapPos != Eigen::Vector2f(-9999.9f, -9999.9f)) {
if (menuState == 0) {// main view
//if ((currentTapShift(0) <= 0.01f && currentTapShift(0) >= -0.01f) && (currentTapShift(1) <= 0.01f && currentTapShift(1) >= -0.01f)) {
if (currentTapShift(0) == 0.f && currentTapShift(1) == 0.f){
// OnTapDown->OnTapUp
//int y = findGalaxyByPos(Eigen::Vector2f());
Eigen::Vector2f t = currentTapShift;
*SE::Console << "DU vec(" + std::to_string(t(0)) + ", " + std::to_string(t(1)) + ") ";
}
else {
// OnTapDown->OnMove->OnTapUp
Eigen::Vector2f t = currentTapShift;
*SE::Console << "DMU vec(" + std::to_string(t(0)) + ", " + std::to_string(t(1)) + ") ";
}
}
if (menuState == 1) { // zoomed galaxy
if ((currentTapShift(0) <= 0.01f && currentTapShift(0) >= -0.01f) && (currentTapShift(1) <= 0.01f && currentTapShift(1) >= -0.01f)) {
// OnTapDown->OnTapUp
}
else {
// OnTapDown->OnMove->OnTapUp
}
}
if (menuState == 2) { // level select view
if ((currentTapShift(0) <= 0.01f && currentTapShift(0) >= -0.01f) && (currentTapShift(1) <= 0.01f && currentTapShift(1) >= -0.01f)) {
// OnTapDown->OnTapUp
}
else {
// OnTapDown->OnMove->OnTapUp
}
}
lastTapPos = Eigen::Vector2f(-9999.9f, -9999.9f); // tap position reset
}
// \_/\_/\_/\_/ timer inactive \_/\_/\_/\_/
}
// timer reset
if (timer_active) {
interact_timer += (float)dt;
}
else if (interact_timer != 0.f) {
interact_timer = 0.f;
currentTapShift = Eigen::Vector2f(0.f, 0.f);
}
}
void GalaxyMenu::tapDown(Eigen::Vector2f pos) {
if (!timer_active) {
timer_active = true;
lastTapPos = pos;
}
}
void GalaxyMenu::tapUp(Eigen::Vector2f pos) {
if (timer_active) {
timer_active = false;
// lastTapPos = vec(0,0) useless for now
}
}
void GalaxyMenu::tapMove(Eigen::Vector2f shift) {
if (timer_active) {
currentTapShift = shift; // shift need to be fixed
}
}
Eigen::Vector2f GalaxyMenu::findCorner(int x_c, int y_c) {
float x_pos = 0.f;
float y_pos = 0.f;
float x_p, y_p;
if (x_c > 0) { // ===
if (y_c > 0) { // ---
for (int i = 0; i < galaxies_params.size(); i++) {
x_p = galaxies_params[i].first(0) + (galaxies_params[i].second(0) / 2);
y_p = galaxies_params[i].first(1) + (galaxies_params[i].second(1) / 2);
x_pos = graterV(x_pos, x_p);
y_pos = graterV(y_pos, y_p);
for (int j = 0; j < stars_params[i].size(); j++) {
x_p = stars_params[i][j].first(0) + (stars_params[i][j].second(0));
y_p = stars_params[i][j].first(1) + (stars_params[i][j].second(1));
x_pos = graterV(x_pos, x_p);
y_pos = graterV(y_pos, y_p);
}
}
}
else {// ---
for (int i = 0; i < galaxies_params.size(); i++) {
x_p = galaxies_params[i].first(0) + (galaxies_params[i].second(0) / 2);
y_p = galaxies_params[i].first(1) - (galaxies_params[i].second(1) / 2);
x_pos = graterV(x_pos, x_p);
y_pos = lowerV(y_pos, y_p);
for (int j = 0; j < stars_params[i].size(); j++) {
x_p = stars_params[i][j].first(0) + (stars_params[i][j].second(0));
y_p = stars_params[i][j].first(1) - (stars_params[i][j].second(1));
x_pos = graterV(x_pos, x_p);
y_pos = lowerV(y_pos, y_p);
}
}
}// ---
}
else { // ===
if (y_c > 0) { // ---
for (int i = 0; i < galaxies_params.size(); i++) {
x_p = galaxies_params[i].first(0) - (galaxies_params[i].second(0) / 2);
y_p = galaxies_params[i].first(1) + (galaxies_params[i].second(1) / 2);
x_pos = lowerV(x_pos, x_p);
y_pos = graterV(y_pos, y_p);
for (int j = 0; j < stars_params[i].size(); j++) {
x_p = stars_params[i][j].first(0) - (stars_params[i][j].second(0));
y_p = stars_params[i][j].first(1) + (stars_params[i][j].second(1));
x_pos = lowerV(x_pos, x_p);
y_pos = graterV(y_pos, y_p);
}
}
}
else { // ---
for (int i = 0; i < galaxies_params.size(); i++) {
x_p = galaxies_params[i].first(0) - (galaxies_params[i].second(0) / 2);
y_p = galaxies_params[i].first(1) - (galaxies_params[i].second(1) / 2);
x_pos = lowerV(x_pos, x_p);
y_pos = lowerV(y_pos, y_p);
for (int j = 0; j < stars_params[i].size(); j++) {
x_p = stars_params[i][j].first(0) - (stars_params[i][j].second(0));
y_p = stars_params[i][j].first(1) - (stars_params[i][j].second(1));
x_pos = lowerV(x_pos, x_p);
y_pos = lowerV(y_pos, y_p);
}
}
} // ---
} // ===
return Eigen::Vector2f(x_pos, y_pos);
}
float GalaxyMenu::graterV(float first_val, float second_val) {
if (first_val > second_val)
return first_val;
else
return second_val;
}
float GalaxyMenu::lowerV(float first_val, float second_val) {
if (first_val < second_val)
return first_val;
else
return second_val;
}
void GalaxyMenu::galaxyFocus(int index) {
}
int GalaxyMenu::findGalaxyByPos(Eigen::Vector2f pos) {
for (int i = 0; i < galaxies_params.size(); i++) {
if (pos(0) >= (galaxies_params[i].first(0) - galaxies_params[i].second(0)/2) && pos(0) <= (galaxies_params[i].first(0) + galaxies_params[i].second(0)/2)) {
if (pos(1) >= (galaxies_params[i].first(1) - galaxies_params[i].second(1) / 2) && pos(1) <= (galaxies_params[i].first(1) + galaxies_params[i].second(1)/2)) {
return i;
}
}
}
return -1;
}

View File

@ -28,22 +28,44 @@ public:
void UpdateGalaxyMenu(float s_width, float s_height);
// ======== Main Methods ========
void InteractWithGalaxy(/*..Vector/Vector/Int..*/); // Prototype for mouse/tap events
void InteractWithGalaxy(size_t dt); // Prototype for mouse/tap events
// ::#Params#::
Eigen::Vector2f menuPosition = Eigen::Vector2f(0.f, 0.f); // relative to the screen center(0.f,0.f means center) (not const!!)
float menuScale = 1.f; // (not const!!)
float xDimension;
float yDimension;
float anchorSize = 1.f;
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> galaxies_params; // ::position/dimensions::
std::vector<std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>>> stars_params;
/*..Outer Interact..*/
void tapDown(Eigen::Vector2f pos);
void tapUp(Eigen::Vector2f pos);
void tapMove(Eigen::Vector2f shift);
private:
void readSaveData(); // inner init method
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);
float graterV(float first_v, float second_v);
float lowerV(float first_v, float second_v);
int menuState = 0; // 0 - all galaxies are visible, 1 - zoomed to current galaxy , 2 - level select menu
/*..Interact params..*/
bool timer_active = false;
float interact_timer = 0.f;
Eigen::Vector2f lastTapPos = Eigen::Vector2f(-9999.9f, -9999.9f);
Eigen::Vector2f currentTapShift;
/*..Interact methods..*/
void galaxyFocus(int index);
int findGalaxyByPos(Eigen::Vector2f pos);
};

View File

@ -193,7 +193,12 @@ void TMyApplication::ApplySignalsToMenu()
OnFlingSignal.connect(boost::bind(&TGameMenu::OnFling, boost::ref(Menu), _1));
OnScrollSignal.connect(boost::bind(&TGameMenu::OnScroll, boost::ref(Menu), _1));
OnTapDownSignal.connect(boost::bind(&TGameMenu::OnTapDown, boost::ref(Menu), _1));
/*..Galaxy Menu..*/ // Can be replaced to "Menu" OnTap(events)
OnTapDownSignal.connect(boost::bind(&GalaxyMenu::tapDown, boost::ref(Menu.GalaxMenu), _1));
OnTapUpSignal.connect(boost::bind(&GalaxyMenu::tapUp, boost::ref(Menu.GalaxMenu), _1));
OnScrollSignal.connect(boost::bind(&GalaxyMenu::tapMove, boost::ref(Menu.GalaxMenu), _1));
}
@ -204,6 +209,12 @@ void TMyApplication::DisapplySignalsToMenu()
OnFlingSignal.disconnect(boost::bind(&TGameMenu::OnFling, boost::ref(Menu), _1));
OnScrollSignal.disconnect(boost::bind(&TGameMenu::OnScroll, boost::ref(Menu), _1));
OnTapDownSignal.disconnect(boost::bind(&TGameMenu::OnTapDown, boost::ref(Menu), _1));
/*..Galaxy Menu..*/ // Can be replaced to "Menu" OnTap(events)
OnTapDownSignal.disconnect(boost::bind(&GalaxyMenu::tapDown, boost::ref(Menu.GalaxMenu), _1));
OnTapUpSignal.disconnect(boost::bind(&GalaxyMenu::tapUp, boost::ref(Menu.GalaxMenu), _1));
OnScrollSignal.disconnect(boost::bind(&GalaxyMenu::tapMove, boost::ref(Menu.GalaxMenu), _1));
}
void TMyApplication::ApplySignalsToGame()
@ -281,8 +292,9 @@ void TMyApplication::LoadResources()
/*..galaxies and stars/planets Init..*/ // tmp
std::vector<int> galaxies;
galaxies.resize(1);
galaxies.resize(2);
galaxies[0] = 2;
galaxies[1] = 1;
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++) {

View File

@ -82,6 +82,7 @@ void TGameMenu::Draw()
void TGameMenu::Update(size_t dt)
{
/*..Galaxy Menu..*/
GalaxMenu.InteractWithGalaxy(dt);
GalaxMenu.UpdateGalaxyMenu((float)SE::Renderer->GetScreenWidth(), (float)SE::Renderer->GetScreenHeight());
if (HoldToTap)