double-hit-balls/game/galaxy_menu.cpp

666 lines
20 KiB
C++
Raw Permalink Normal View History

2018-05-22 12:00:30 +00:00
#include "galaxy_menu.h"
2018-05-30 11:21:50 +00:00
#include "main_code.h"
2018-05-23 11:46:02 +00:00
#include <algorithm>
2018-05-29 11:44:55 +00:00
#include <math.h>
2018-05-22 12:00:30 +00:00
2018-12-01 09:47:26 +00:00
std::shared_ptr<WidgetAncestor> modal_background = nullptr;
2018-05-22 12:00:30 +00:00
GalaxyMenu::GalaxyMenu()
{
2018-06-01 11:45:16 +00:00
2018-05-22 12:00:30 +00:00
}
GalaxyMenu::~GalaxyMenu()
{
}
2018-10-04 01:55:37 +00:00
void GalaxyMenu::setTimerActivity(bool value)
{
timer_active = value;
}
2018-05-23 11:46:02 +00:00
bool GalaxyMenu::InitGalaxyMenu(std::string config_json, float scale) {
try
{
/*..Inner Init..*/
menuScale = scale;
2018-05-22 12:00:30 +00:00
/*...Read ptree from config...*/
2018-07-14 10:49:31 +00:00
boost::property_tree::ptree config_pt = SE::ReadJsonFile(ST::PathToResources + config_json);
//boost::property_tree::json_parser::read_json(res_path + config_json, config_pt);
2018-05-23 11:46:02 +00:00
/*..error ptree..*/
boost::property_tree::ptree error_pt;
error_pt.put("error", "something goes wrong at InitGalaxyMenu");
2018-06-09 19:51:32 +00:00
2018-05-23 11:46:02 +00:00
/*..Init Menu..*/
2018-05-25 11:51:26 +00:00
BOOST_FOREACH(auto menu_pt, config_pt.get_child("Space", error_pt)) {
2018-05-23 11:46:02 +00:00
Galaxy galax;
galax.name = menu_pt.second.get<std::string>("name", "error");
galax.scale = menu_pt.second.get<float>("scale", 0.0f);
galax.texture = menu_pt.second.get<std::string>("texture", "error");
galax.position = Eigen::Vector2f(menu_pt.second.get<float>("position.x_coord", 0.0f), menu_pt.second.get<float>("position.y_coord", 0.0f));
//boost::property_tree::ptree stars = menu_pt.second.get<boost::property_tree::ptree>("Stars", error_pt);
int levelStar = 0;
2018-05-23 11:46:02 +00:00
BOOST_FOREACH(auto stars_pt, menu_pt.second.get_child("Stars", error_pt)) {
StarObject star;
star.name = stars_pt.second.get<std::string>("name", "error");
star.scale = stars_pt.second.get<float>("scale", 0.0f);
star.texture = stars_pt.second.get<std::string>("texture", "error");
2018-10-02 17:45:26 +00:00
star.textureName = GetFileName(star.texture);
ResourceManager->TexList.AddTexture(star.texture);
2018-05-23 11:46:02 +00:00
star.position = Eigen::Vector2f(stars_pt.second.get<float>("position.x_coord", 0.0f), stars_pt.second.get<float>("position.y_coord", 0.0f));
int levelIndex = 0;
2018-05-28 11:31:01 +00:00
/*..Levels..*/
2018-05-23 11:46:02 +00:00
BOOST_FOREACH(auto levels_pt, stars_pt.second.get_child("levels")) {
2018-05-28 11:31:01 +00:00
2018-06-01 11:45:16 +00:00
std::string levelName = levels_pt.second.get<std::string>("name", "empty");
std::shared_ptr<TGameLevel> lvl = std::make_shared<TGameLevel>(levelStar, levelIndex);
2018-07-22 20:56:46 +00:00
lvl->FillWithFile(ST::PathToResources + levelName + ".txt");
2018-05-28 11:31:01 +00:00
star.selectionMenu.gameLevels.push_back(lvl);
++levelIndex;
2018-05-23 11:46:02 +00:00
}
galax.Stars.push_back(star);
++levelStar;
2018-05-23 11:46:02 +00:00
}
galaxies.push_back(galax);
}
2018-07-22 20:56:46 +00:00
2018-05-23 11:46:02 +00:00
return true;
}
catch (boost::property_tree::ptree_error) {
return false;
}
}
2018-07-22 20:56:46 +00:00
2018-05-28 11:31:01 +00:00
void GalaxyMenu::UpdateGalaxyMenu(float s_width, float s_height, size_t dt) {
2018-05-24 11:44:58 +00:00
/*..Reset..*/
2018-10-17 03:59:08 +00:00
if (s_width == currentWindowWidth && s_height == currentWindowHeight)
{
return;
}
currentWindowWidth = s_width;
currentWindowHeight = s_height;
2018-05-24 11:44:58 +00:00
galaxies_params.clear();
stars_params.clear();
2018-05-23 11:46:02 +00:00
/*..Menu ancestor geometry..*/
2018-05-25 11:51:26 +00:00
float gameScreenWidth = s_width * anchorSize;
float gameScreenHeight = s_height * anchorSize;
2018-05-23 11:46:02 +00:00
Eigen::Vector2f gameScreenCenter = Eigen::Vector2f(gameScreenWidth/2,gameScreenHeight/2);
2018-05-28 11:31:01 +00:00
/*..coefficients calculation..*/
/*Eigen::Vector2f tap_shift = Eigen::Vector2f(
totalTapShift(0)/gameScreenWidth,
totalTapShift(1)/gameScreenHeight
);
menu_offset = Eigen::Vector2f(
negativeV(tap_shift(0)) * val_clamp(abs(menu_offset(0) + (tap_shift(0) * dt / 1000.f)), 0.f, 0.15f),
negativeV(tap_shift(1)) * val_clamp(abs(menu_offset(1) + (tap_shift(1) * dt / 1000.f)), 0.f, 0.15f)
);*/
2018-05-23 11:46:02 +00:00
/*..Menu geometry..*/
2018-10-17 03:59:08 +00:00
2018-05-23 11:46:02 +00:00
xDimension = menuScale * gameScreenWidth;
yDimension = menuScale * gameScreenHeight;
2018-05-28 11:31:01 +00:00
Eigen::Vector2f currentMenuPos = Eigen::Vector2f(gameScreenCenter(0) + (gameScreenWidth/2/*relative to the screen x-dimension*/)*(menuPosition(0) - menu_offset(0)), gameScreenCenter(1) + (gameScreenHeight/2/*relative to the screen y-dimension*/)*(menuPosition(1) - menu_offset(1)));
2018-05-23 11:46:02 +00:00
/*..Galaxies geometry..*/
for (int i = 0; i < galaxies.size(); i++) {
2018-07-14 11:53:59 +00:00
2018-05-23 11:46:02 +00:00
Eigen::Vector2f tex_size = textureSizeNormalize(
2018-05-24 11:44:58 +00:00
Eigen::Vector2f(
2018-05-31 11:47:18 +00:00
((float)SE::ResourceManager->TexList.GetTextureOriginalWidth("galaxy_" + std::to_string(i))),
((float)SE::ResourceManager->TexList.GetTextureOriginalHeight("galaxy_" + std::to_string(i))))
2018-05-23 11:46:02 +00:00
); // normalized
galaxies_params.push_back(std::make_pair(
Eigen::Vector2f(
2018-05-25 11:51:26 +00:00
currentMenuPos(0) + (xDimension / 2)*galaxies[i].position(0),
2018-05-24 11:44:58 +00:00
currentMenuPos(1) + (yDimension / 2)*galaxies[i].position(1)),
Eigen::Vector2f(
(tex_size(0)*galaxies[i].scale)*menuScale,
(tex_size(1)*galaxies[i].scale)*menuScale
2018-05-23 11:46:02 +00:00
)
));
2018-05-25 11:51:26 +00:00
2018-05-23 11:46:02 +00:00
/*..Stars geometry..*/
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> star_params;
for (int j = 0; j < galaxies[i].Stars.size(); j++) {
2018-07-14 11:53:59 +00:00
2018-05-24 11:44:58 +00:00
tex_size = textureSizeNormalize(
Eigen::Vector2f(
2018-10-02 17:45:26 +00:00
((float)SE::ResourceManager->TexList.GetTextureWidth(galaxies[i].Stars[j].textureName)),
((float)SE::ResourceManager->TexList.GetTextureHeight(galaxies[i].Stars[j].textureName)))
2018-05-24 11:44:58 +00:00
); // normalized
2018-05-23 11:46:02 +00:00
star_params.push_back(std::make_pair(
Eigen::Vector2f(
2018-05-24 11:44:58 +00:00
galaxies_params[i].first(0) + (galaxies_params[i].second(0)/2)*galaxies[i].Stars[j].position(0),
galaxies_params[i].first(1) + (galaxies_params[i].second(1)/2)*galaxies[i].Stars[j].position(1)
2018-05-23 11:46:02 +00:00
),
2018-05-24 11:44:58 +00:00
Eigen::Vector2f(
(tex_size(0)*galaxies[i].Stars[j].scale)*galaxies[i].scale*menuScale,
(tex_size(1)*galaxies[i].Stars[j].scale)*galaxies[i].scale*menuScale
)
2018-05-23 11:46:02 +00:00
));
}
stars_params.push_back(star_params);
}
}
2018-10-17 03:59:08 +00:00
Eigen::Vector2f GalaxyMenu::textureSizeNormalize(Eigen::Vector2f texVec, int t_type)
{
2018-05-23 11:46:02 +00:00
float x_dim, y_dim;
2018-10-17 03:59:08 +00:00
float tex_ratio = texVec(0) / texVec(1);
float screenRatio = SE::Renderer->GetScreenWidth() / (float)SE::Renderer->GetScreenHeight();
if (tex_ratio > screenRatio)
{
y_dim = SE::Renderer->GetScreenHeight();
x_dim = y_dim * tex_ratio;
}
else
{
x_dim = SE::Renderer->GetScreenWidth();
2018-05-23 11:46:02 +00:00
y_dim = x_dim / tex_ratio;
}
2018-07-14 11:53:59 +00:00
2018-05-23 11:46:02 +00:00
return Eigen::Vector2f(x_dim, y_dim);
}
float GalaxyMenu::val_clamp(float val, float min, float max) {
if (val < min)
return min;
else if (val > max)
return max;
else
return val;
2018-05-24 11:44:58 +00:00
}
2018-12-01 09:47:26 +00:00
void GalaxyMenu::DrawGalaxyMenu(bool drawStars) {
2018-05-24 11:44:58 +00:00
2018-10-17 03:59:08 +00:00
Renderer->PushOrthoProjection();
Renderer->PushMatrix();
Renderer->LoadIdentity();
2018-05-24 11:44:58 +00:00
for (int i = 0; i < galaxies_params.size(); i++) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList["galaxy_" + std::to_string(i)]);
SE::Renderer->DrawRect(
Eigen::Vector2f(
galaxies_params[i].first(0) - galaxies_params[i].second(0)/2,
galaxies_params[i].first(1) - galaxies_params[i].second(1)/2
),
Eigen::Vector2f(
galaxies_params[i].first(0) + galaxies_params[i].second(0)/2,
galaxies_params[i].first(1) + galaxies_params[i].second(1)/2
)
); // DrawRect
2018-12-01 09:47:26 +00:00
if (drawStars)
{
/*..Draw stars..*/
Renderer->PushShader("HoverableButtonShader");
if (stars_params.size() >= i) {
for (int j = 0; j < stars_params[i].size(); j++) {
if (planetHoverIndex == j) {
RenderUniform1i("Hover", 1);
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList[galaxies[i].Stars[j].textureName]);
}
else {
RenderUniform1i("Hover", 0);
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList[galaxies[i].Stars[j].textureName]);
}
SE::Renderer->DrawRect(
Eigen::Vector2f(
stars_params[i][j].first(0) - stars_params[i][j].second(0) / 2,
stars_params[i][j].first(1) - stars_params[i][j].second(1) / 2
),
Eigen::Vector2f(
stars_params[i][j].first(0) + stars_params[i][j].second(0) / 2,
stars_params[i][j].first(1) + stars_params[i][j].second(1) / 2
)
); // DrawRect
2018-05-30 11:21:50 +00:00
}
2018-05-24 11:44:58 +00:00
}
2018-12-01 09:47:26 +00:00
Renderer->PopShader();
2018-05-24 11:44:58 +00:00
}
2018-05-29 11:44:55 +00:00
/*..Draw level selection menu..*/
2018-07-22 11:36:06 +00:00
//drawSelectionMenu(starIndex);
2018-05-30 11:21:50 +00:00
2018-05-24 11:44:58 +00:00
}
2018-10-17 03:59:08 +00:00
Renderer->PopMatrix();
Renderer->PopProjectionMatrix();
2018-05-24 11:44:58 +00:00
}
2018-12-01 09:47:26 +00:00
void GalaxyMenu::resetValuesOnGameStart()
{
modal_background = nullptr;
totalTapShift = { 0, 0 };
planetHoverIndex = -1;
timer_active = false;
}
2018-05-25 11:51:26 +00:00
void GalaxyMenu::InteractWithGalaxy(size_t dt) {
2018-10-04 01:55:37 +00:00
2018-12-01 09:47:26 +00:00
if (!modal_background) modal_background = ResourceManager->newGuiManager.findWidgetByName("modal_background");
if (modal_background->visible)
{
return;
}
2018-05-25 11:51:26 +00:00
if (timer_active) {
// ::::::::::::: timer active ::::::::::::::
//if (menuState == 0)
{ // main view
2018-05-30 11:21:50 +00:00
//if (currentTapShift(0) == 0.f && currentTapShift(1) == 0.f) {
if (currentTapShift(0) == totalTapShift(0) && currentTapShift(1) == totalTapShift(1)) {
2018-05-28 11:31:01 +00:00
// OnTapDown->
2018-05-30 11:21:50 +00:00
/*../hover\..*/
int phi = findPlanetByPos(lastTapPos - totalTapShift);
if (phi != -1) {
planetHoverIndex = phi;
}
else {
planetHoverIndex = -1;
}
/*..\hover/..*/
2018-05-28 11:31:01 +00:00
}
else {
// OnTapDown->OnMove->
2018-05-30 11:21:50 +00:00
//totalTapShift = Eigen::Vector2f(totalTapShift(0) + currentTapShift(0), totalTapShift(1) + currentTapShift(1));
/*../hover\..*/
int phi = findPlanetByPos(lastTapPos - totalTapShift);
if (phi != -1) {
planetHoverIndex = phi;
}
else {
planetHoverIndex = -1;
}
/*..\hover/..*/
2018-05-28 11:31:01 +00:00
}
2018-05-25 11:51:26 +00:00
}
2018-07-22 20:56:46 +00:00
/*
2018-05-30 11:21:50 +00:00
else if (menuState == 1) { // zoomed galaxy
2018-05-25 11:51:26 +00:00
}
2018-05-30 11:21:50 +00:00
else if (menuState == 2) { // level select view
//if (currentTapShift(0) == 0.f && currentTapShift(1) == 0.f) {
if (currentTapShift(0) == totalTapShift(0) && currentTapShift(1) == totalTapShift(1)) {
// OnTapDown->
2018-05-25 11:51:26 +00:00
2018-05-30 11:21:50 +00:00
}
else {
// OnTapDown->OnMove->
//totalTapShift = Eigen::Vector2f(totalTapShift(0) + currentTapShift(0), totalTapShift(1) + currentTapShift(1));
}
2018-07-22 20:56:46 +00:00
}*/
2018-05-25 11:51:26 +00:00
// \_/\_/\_/\_/ timer active \_/\_/\_/\_/
}
else {
// ::::::::::::: timer inactive ::::::::::::::
if (lastTapPos != Eigen::Vector2f(-9999.9f, -9999.9f)) {
//if (menuState == 0)
{// main view
2018-07-22 11:36:06 +00:00
2018-05-25 11:51:26 +00:00
// OnTapDown->OnTapUp
2018-05-28 11:31:01 +00:00
2018-05-30 11:21:50 +00:00
/*..level select menu open..*/
2018-12-01 09:47:26 +00:00
starIndex = findPlanetByPos(lastTapPos - totalTapShift);
2018-07-22 20:56:46 +00:00
2018-05-30 11:21:50 +00:00
if (starIndex != -1) {
planetHoverIndex = starIndex;
2018-07-22 20:56:46 +00:00
Application->SetupGalaxyUi(starIndex);
2018-05-30 11:21:50 +00:00
}
2018-07-22 11:36:06 +00:00
2018-05-25 11:51:26 +00:00
2018-07-22 20:56:46 +00:00
}/*
2018-05-30 11:21:50 +00:00
else if (menuState == 1) { // zoomed galaxy
if (totalTapShift(0) == 0.f && totalTapShift(1) == 0.f) {
2018-05-25 11:51:26 +00:00
// OnTapDown->OnTapUp
}
else {
// OnTapDown->OnMove->OnTapUp
}
}
2018-05-30 11:21:50 +00:00
else if (menuState == 2) { // level select view
2018-07-22 20:56:46 +00:00
2018-05-30 11:21:50 +00:00
if (totalTapShift(0) == 0.f && totalTapShift(1) == 0.f) {
2018-05-25 11:51:26 +00:00
// OnTapDown->OnTapUp
auto lvl = findLevelByButtonPos(lastTapPos);
if (lvl != nullptr) {
2018-05-30 11:21:50 +00:00
// then if level is available, load it
starIndex = -1;
menuState = 0;
planetHoverIndex = -1;
Application->GoFromMenuToGame(lvl);
2018-05-30 11:21:50 +00:00
}
else if (!checkMenuBound(lastTapPos)) {
// back to state 0
starIndex = -1;
menuState = 0;
planetHoverIndex = -1;
}
2018-05-25 11:51:26 +00:00
}
else {
// OnTapDown->OnMove->OnTapUp
}
2018-07-22 20:56:46 +00:00
}*/
2018-05-25 11:51:26 +00:00
}
// \_/\_/\_/\_/ timer inactive \_/\_/\_/\_/
}
2018-05-28 11:31:01 +00:00
/*..main reset..*/
2018-05-25 11:51:26 +00:00
if (timer_active) {
interact_timer += (float)dt;
}
else if (interact_timer != 0.f) {
2018-05-28 11:31:01 +00:00
interact_timer = 0.f; // reset
currentTapShift = Eigen::Vector2f(0.f, 0.f); // reset
totalTapShift = Eigen::Vector2f(0.f, 0.f); // reset
lastTapPos = Eigen::Vector2f(-9999.9f, -9999.9f); // reset
2018-05-25 11:51:26 +00:00
}
2018-05-25 11:51:26 +00:00
}
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) {
2018-12-01 09:47:26 +00:00
if (timer_active && modal_background && !modal_background->visible) {
2018-07-14 11:53:59 +00:00
2018-05-30 11:21:50 +00:00
totalTapShift += shift;
2018-05-25 11:51:26 +00:00
}
}
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;
}
2018-05-28 11:31:01 +00:00
void GalaxyMenu::takeInFocus(int g_index, int s_index) {
if (s_index != -1) { /*..galaxy zoom..*/
2018-05-25 11:51:26 +00:00
2018-05-28 11:31:01 +00:00
}
else { /*..star zoom..*/
}
2018-05-25 11:51:26 +00:00
}
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;
}
}
}
2018-05-24 11:44:58 +00:00
2018-05-25 11:51:26 +00:00
return -1;
2018-05-28 11:31:01 +00:00
}
int GalaxyMenu::negativeV(float val) {
if (val >= 0) {
return 1;
}
return -1;
}
int GalaxyMenu::findPlanetByPos(Eigen::Vector2f pos) {
float minimalDistance = std::numeric_limits<float>::max();
int index = -1;
for (int i = 0; i < stars_params.size(); i++)
{
for (int j = 0; j < stars_params[i].size(); j++)
{
if (pos(0) >= (stars_params[i][j].first(0) - stars_params[i][j].second(0) / 2) && pos(0) <= (stars_params[i][j].first(0) + stars_params[i][j].second(0) / 2))
{
if (pos(1) >= (stars_params[i][j].first(1) - stars_params[i][j].second(1) / 2) && pos(1) <= (stars_params[i][j].first(1) + stars_params[i][j].second(1) / 2))
{
float dx = pos(0) - stars_params[i][j].first(0);
float dy = pos(1) - stars_params[i][j].first(1);
float distance = dx * dx + dy * dy;
if (distance < minimalDistance)
{
minimalDistance = distance;
index = j;
}
2018-05-28 11:31:01 +00:00
}
}
}
}
return index;
2018-05-29 11:44:55 +00:00
}
2018-05-30 11:21:50 +00:00
bool GalaxyMenu::checkMenuBound(Eigen::Vector2f pos) {
float x_l = galaxies[galaxyIndex].Stars[starIndex].selectionMenu.buttons_plane.first(0) - galaxies[galaxyIndex].Stars[starIndex].selectionMenu.buttons_plane.second(0)*0.5f;
float x_r = galaxies[galaxyIndex].Stars[starIndex].selectionMenu.buttons_plane.first(0) + galaxies[galaxyIndex].Stars[starIndex].selectionMenu.buttons_plane.second(0)*0.5f;
float y_t = galaxies[galaxyIndex].Stars[starIndex].selectionMenu.buttons_plane.first(1) + galaxies[galaxyIndex].Stars[starIndex].selectionMenu.buttons_plane.second(1)*0.5f;
float y_b = galaxies[galaxyIndex].Stars[starIndex].selectionMenu.buttons_plane.first(1) - galaxies[galaxyIndex].Stars[starIndex].selectionMenu.buttons_plane.second(1)*0.5f;
if (pos(0) >= x_l && pos(0) <= x_r) {
if (pos(1) >= y_b && pos(1) <= y_t) {
return true;
}
}
return false;
}
void GalaxyMenu::drawBorder(Eigen::Vector2f lb_, Eigen::Vector2f rt_, float scale, std::string mode) {
std::string border_tex = "black_square";
float width = rt_(0) - lb_(0);
float height = rt_(1) - lb_(1);
if (mode.compare("inner") == 0) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList[border_tex]);
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0), lb_(1)),
Eigen::Vector2f(lb_(0) + width*scale, rt_(1))
); // left
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0), rt_(1) - width*scale),
Eigen::Vector2f(rt_(0), rt_(1))
); // top
SE::Renderer->DrawRect(
Eigen::Vector2f(rt_(0) - width*scale, lb_(1)),
Eigen::Vector2f(rt_(0), rt_(1))
); // right
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0), lb_(1)),
Eigen::Vector2f(rt_(0), lb_(1) + width*scale)
); // bottom
}
else if (mode.compare("outer") == 0) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList[border_tex]);
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0) - width*scale, lb_(1) - width*scale),
Eigen::Vector2f(lb_(0), rt_(1) + width*scale)
); // left
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0) - width*scale, rt_(1)),
Eigen::Vector2f(rt_(0) + width*scale, rt_(1)+width*scale)
); // top
SE::Renderer->DrawRect(
Eigen::Vector2f(rt_(0), lb_(1) - width*scale),
Eigen::Vector2f(rt_(0)+width*scale, rt_(1) + width*scale)
); // right
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0) - width*scale, lb_(1) - width*scale),
Eigen::Vector2f(rt_(0)+width*scale, lb_(1))
); // bottom
}
else if (mode.compare("center") == 0) {
glBindTexture(GL_TEXTURE_2D, SE::ResourceManager->TexList[border_tex]);
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0) - width*scale*0.5f, lb_(1) - width * scale*0.5f),
Eigen::Vector2f(lb_(0) + width * scale*0.5f, rt_(1) + width * scale*0.5f)
); // left
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0) - width * scale*0.5f, rt_(1) - width * scale*0.5f),
Eigen::Vector2f(rt_(0) + width * scale*0.5f, rt_(1) + width * scale*0.5f)
); // top
SE::Renderer->DrawRect(
Eigen::Vector2f(rt_(0) - width * scale*0.5f, lb_(1) - width * scale*0.5f),
Eigen::Vector2f(rt_(0) + width * scale*0.5f, rt_(1) + width * scale*0.5f)
); // right
SE::Renderer->DrawRect(
Eigen::Vector2f(lb_(0) - width * scale*0.5f, lb_(1) - width * scale*0.5f),
Eigen::Vector2f(rt_(0) + width * scale*0.5f, lb_(1) + width * scale*0.5f)
); // bottom
}
2018-06-01 11:45:16 +00:00
}
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
)
);
}
2018-05-22 12:00:30 +00:00
}