interface fixes

This commit is contained in:
Emil Kabirov 2018-12-01 14:47:26 +05:00
parent cee9693119
commit 3d0bbe7ca8
7 changed files with 138 additions and 43 deletions

View File

@ -4,6 +4,8 @@
#include <algorithm>
#include <math.h>
std::shared_ptr<WidgetAncestor> modal_background = nullptr;
GalaxyMenu::GalaxyMenu()
{
@ -199,7 +201,7 @@ float GalaxyMenu::val_clamp(float val, float min, float max) {
return val;
}
void GalaxyMenu::DrawGalaxyMenu() {
void GalaxyMenu::DrawGalaxyMenu(bool drawStars) {
Renderer->PushOrthoProjection();
Renderer->PushMatrix();
@ -219,31 +221,34 @@ void GalaxyMenu::DrawGalaxyMenu() {
)
); // DrawRect
/*..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]);
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
}
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
}
Renderer->PopShader();
}
Renderer->PopShader();
/*..Draw level selection menu..*/
//drawSelectionMenu(starIndex);
@ -255,8 +260,24 @@ void GalaxyMenu::DrawGalaxyMenu() {
}
void GalaxyMenu::resetValuesOnGameStart()
{
modal_background = nullptr;
totalTapShift = { 0, 0 };
planetHoverIndex = -1;
timer_active = false;
}
void GalaxyMenu::InteractWithGalaxy(size_t dt) {
if (!modal_background) modal_background = ResourceManager->newGuiManager.findWidgetByName("modal_background");
if (modal_background->visible)
{
return;
}
if (timer_active) {
// ::::::::::::: timer active ::::::::::::::
//if (menuState == 0)
@ -266,6 +287,7 @@ void GalaxyMenu::InteractWithGalaxy(size_t dt) {
// OnTapDown->
/*../hover\..*/
GetConsole() << std::to_string(lastTapPos[0]) + " | " + std::to_string(lastTapPos[1]) + " | " + std::to_string(totalTapShift[0]) + " | " + std::to_string(totalTapShift[1]);
int phi = findPlanetByPos(lastTapPos - totalTapShift);
if (phi != -1) {
planetHoverIndex = phi;
@ -280,6 +302,7 @@ void GalaxyMenu::InteractWithGalaxy(size_t dt) {
//totalTapShift = Eigen::Vector2f(totalTapShift(0) + currentTapShift(0), totalTapShift(1) + currentTapShift(1));
/*../hover\..*/
GetConsole() << std::to_string(lastTapPos[0]) + " | " + std::to_string(lastTapPos[1]) + " | " + std::to_string(totalTapShift[0]) + " | " + std::to_string(totalTapShift[1]);
int phi = findPlanetByPos(lastTapPos - totalTapShift);
if (phi != -1) {
planetHoverIndex = phi;
@ -319,7 +342,8 @@ void GalaxyMenu::InteractWithGalaxy(size_t dt) {
// OnTapDown->OnTapUp
/*..level select menu open..*/
starIndex = findPlanetByPos(lastTapPos);
GetConsole() << std::to_string(lastTapPos[0]) + " | " + std::to_string(lastTapPos[1]) + " | " + std::to_string(totalTapShift[0]) + " | " + std::to_string(totalTapShift[1]);
starIndex = findPlanetByPos(lastTapPos - totalTapShift);
if (starIndex != -1) {
@ -402,7 +426,7 @@ void GalaxyMenu::tapUp(Eigen::Vector2f pos) {
}
void GalaxyMenu::tapMove(Eigen::Vector2f shift) {
if (timer_active) {
if (timer_active && modal_background && !modal_background->visible) {
totalTapShift += shift;
}

View File

@ -25,7 +25,7 @@ public:
// ======== Main Methods ========
bool InitGalaxyMenu(std::string config_json, float scale = 1.f);
void DrawGalaxyMenu();
void DrawGalaxyMenu(bool drawStars);
void UpdateGalaxyMenu(float s_width, float s_height, size_t dt);
@ -41,6 +41,7 @@ public:
float xDimension;
float yDimension;
float anchorSize = 1.f;
int planetHoverIndex = -1;
std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>> galaxies_params; // ::position/dimensions::
std::vector<std::vector<std::pair<Eigen::Vector2f, Eigen::Vector2f>>> stars_params;
@ -51,6 +52,7 @@ public:
void setTimerActivity(bool value);
void resetValuesOnGameStart();
private:
@ -69,14 +71,13 @@ private:
int menuState = 0; // 0 - all galaxies are visible, 1 - zoomed to current galaxy(reserved) , 2 - level select menu
int starIndex = -1;
int galaxyIndex = 0; // zoomed galaxy
int planetHoverIndex = -1;
/*..Interact params..*/
bool timer_active = false;
float interact_timer = 0.f; // reset
Eigen::Vector2f lastTapPos = Eigen::Vector2f(-9999.9f, -9999.9f); // reset
Eigen::Vector2f currentTapShift; // reset
Eigen::Vector2f totalTapShift; // reset
Eigen::Vector2f currentTapShift = Eigen::Vector2f(0.f, 0.f); // reset
Eigen::Vector2f totalTapShift = Eigen::Vector2f(0.f, 0.f); // reset
/*..coefficients..*/
Eigen::Vector2f menu_offset = Eigen::Vector2f(0, 0);

View File

@ -469,7 +469,7 @@ void TBall::Update(size_t dt)
//===========================================
//===========================================
//===========================================
bool TGameLevel::XXX = true;
TGameLevel::TGameLevel(int levelStar, int levelIndex)
@ -845,7 +845,6 @@ void TGameLevel::Draw()
InnerDraw(Renderer->GetScreenWidth(), Renderer->GetScreenHeight(), Renderer->GetMatrixWidth(), Renderer->GetMatrixHeight(), false);
}
void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, int matrixHeight, bool blackAndWhite)
{
@ -918,7 +917,7 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i
//Renderer->PopMatrix();
CheckGlError();
drawOutline(screenWidth, screenHeight);
//drawOutline(screenWidth, screenHeight);
Renderer->PopMatrix();
Renderer->PopProjectionMatrix();
@ -960,7 +959,10 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i
// :::::::::::
glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[BkgTexture]);
//Renderer->DrawRect(Vector2f(xlOffset, ylOffset), Vector2f(xlOffset+tSW, ylOffset+tSH),Vector2f(0.f, 0.f), Vector2f(1.f, 1.f));
Renderer->DrawRect(Vector2f(bkgSWO, bkgSHO), Vector2f(bkgSWO + bkgSW, bkgSHO + bkgSH), Vector2f(0.f, 0.f), Vector2f(1.f, 1.f));
float backgroundHorOffset = (xlOffset - bkgSWO) / screenWidth;
Renderer->DrawRect(Vector2f(xlOffset, bkgSHO), Vector2f(xlOffset + tSW, bkgSHO + bkgSH), Vector2f(backgroundHorOffset, 0.f), Vector2f(1.f - backgroundHorOffset, 1.f));
//Renderer->DrawRect(Vector2f(0,0), Vector2f(100,100), Vector2f(0.f, 0.f), Vector2f(1.f, 1.f));
@ -1087,7 +1089,7 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i
// Renderer->DrawRect(Vector2f(-const_backBtnWidth*0.5f, -const_backBtnHeight*0.5f)+BackBtnPos, Vector2f(const_backBtnWidth*0.5f, const_backBtnHeight*0.5f)+BackBtnPos);
}
drawOutline(screenWidth, screenHeight);
//drawOutline(screenWidth, screenHeight);
if (pause && !renderBufferReady)
@ -1111,6 +1113,12 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i
Renderer->PopMatrix();
RenderBufferReady = true;
CheckGlError();
//Renderer->DrawRect(Vector2f(bkgSWO, bkgSHO), Vector2f(bkgSWO + bkgSW, bkgSHO + bkgSH), Vector2f(0.f, 0.f), Vector2f(1.f, 1.f));
//Renderer->DrawRect(Vector2f(xlOffset, bkgSHO), Vector2f(xlOffset + tSW, bkgSHO + bkgSH), Vector2f(0.f, 0.f), Vector2f(1.f, 1.f));
horOffset = xlOffset / screenWidth;
verOffset = bkgSH / screenHeight;
}
@ -1210,7 +1218,43 @@ void TGameLevel::DrawBuffer()
Vector2f RectPos = Vector2f(x_levelScreenCenter, y_levelScreenCenter);
Vector2f RectSize = Vector2f(x_levelScreenSize, y_levelScreenSize);
Renderer->DrawRect(RectPos-RectSize, RectPos+RectSize);
//Renderer->DrawRect(RectPos-RectSize, RectPos+RectSize);
// Scaling math
float tSW = Application->GetGameLevelScreenWidth(); // Screen Width
float tSH = Application->GetGameLevelScreenHeight(); // Screen Height
float xlOffset = (Renderer->GetScreenWidth() - tSW)*0.5f; // Level Screen x-offset
float ylOffset = 0.f;
float lrFBO = 4 * tSH / 320.f; // Left/Right Wall Textures offset from bottom
float uWTW = tSW * (static_cast<float>(ResourceManager->TexList.GetTextureOriginalHeight(CONST_WALL_UP_TEXTURE)) / static_cast<float>(ResourceManager->TexList.GetTextureOriginalWidth(CONST_WALL_UP_TEXTURE))); // up Wall Texture Width
float lWTW = (static_cast<float>(ResourceManager->TexList.GetTextureOriginalWidth(CONST_WALL_LEFT_TEXTURE)) / static_cast<float>(ResourceManager->TexList.GetTextureOriginalHeight(CONST_WALL_LEFT_TEXTURE))) * (tSH - uWTW - lrFBO); // left Wall Texture Width
float rWTW = lWTW; // right Wall Texture Width
float bWTO = (lWTW + rWTW) * 0.5f; // bonus Wall x-Offset
float bWTW = (tSW - bWTO) * (static_cast<float>(ResourceManager->TexList.GetTextureOriginalHeight(CONST_WALL_BONUS_TEXTURE)) / static_cast<float>(ResourceManager->TexList.GetTextureOriginalWidth(CONST_WALL_BONUS_TEXTURE))); // bonus Wall Texture Width
float bkgTW = (float)ResourceManager->TexList.GetTextureOriginalWidth(BkgTexture);
float bkgTH = (float)ResourceManager->TexList.GetTextureOriginalHeight(BkgTexture);
float bkgSW; // Background Secreen Width
float bkgSH; // Background Secreen Height
float bkgSWO; // Background Secreen Width Offset
float bkgSHO; // Background Secreen Height Offset
if ((bkgTW / bkgTH) >= 1.6f/*screen ratio*/) {
bkgSW = (tSH / bkgTH) * bkgTW;
bkgSH = tSH;
bkgSWO = (((float)Renderer->GetScreenWidth()) - bkgSW) * 0.5f;
bkgSHO = ylOffset;
}
else {
bkgSH = (tSW / bkgTW) * bkgTH;
bkgSW = tSW;
bkgSWO = xlOffset;
bkgSHO = ylOffset;
}
//Renderer->DrawRect(Vector2f(bkgSWO, bkgSHO), Vector2f(bkgSWO + bkgSW, bkgSHO + bkgSH), Vector2f(horOffset, 0.f), Vector2f(1.f - horOffset, verOffset));
Renderer->DrawRect(Vector2f(xlOffset, bkgSHO), Vector2f(xlOffset + tSW, bkgSHO + bkgSH), Vector2f(horOffset, 0.f), Vector2f(1.f - horOffset, verOffset));
Renderer->PopShader();

View File

@ -125,7 +125,11 @@ class TGameLevel : public TGameAreaAncestor
friend class GalaxyMenu;
protected:
float lvlWidth;
float lvlHeight;
float lvlHeight;
float verOffset;
float horOffset;
std::string BkgTexture;
//std::string LevelScreenTexture;
std::string LevelFileName;

View File

@ -183,6 +183,7 @@ void TMyApplication::InnerInit()
srand (static_cast<size_t>(time(NULL)));
GameState = CONST_GAMESTATE_PRELOADING;
Menu.SetGameState(GameState);
StateTimer = 0.f;
ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/gui_transparent.vertex", "shaders/gui_transparent.fragment");
@ -530,11 +531,11 @@ void TMyApplication::InnerUpdate(size_t dt)
if (StateTimer >= 1.f)
{
StateTimer -= 1.f;
skipUpdateToUpdateScreen = false;
}
if (skipUpdateToUpdateScreen)
{
skipUpdateToUpdateScreen = false;
return;
}
@ -568,10 +569,10 @@ void TMyApplication::InnerUpdate(size_t dt)
std::cout << "menu error" << std::endl;
}
RenderLevelSnapshots();
LoadResources();
GameState = CONST_GAMESTATE_LOADING;
Menu.SetGameState(GameState);
}
else if (GameState == CONST_GAMESTATE_LOADING)
{
@ -613,7 +614,10 @@ void TMyApplication::InnerUpdate(size_t dt)
//
// Renderer->SetOrthoProjection();
RenderLevelSnapshots();
GameState = CONST_GAMESTATE_MENU;
Menu.SetGameState(GameState);
ApplySignalsToMenu();
LoadGalaxyUi();
@ -643,7 +647,8 @@ void TMyApplication::InnerUpdate(size_t dt)
{
//*SE::Console << "5CONST_GAMESTATE_FROM_MENU_TO_LEVEL";
GameState = CONST_GAMESTATE_LEVEL;
OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu)));
Menu.SetGameState(GameState);
//OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu)));
//CONNECT SLOT
DisapplySignalsToMenu();
ApplySignalsToGame();
@ -700,6 +705,7 @@ void TMyApplication::InnerUpdate(size_t dt)
if (StateTimer <= 0.f)
{
GameState = CONST_GAMESTATE_CREDITS;
Menu.SetGameState(GameState);
OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu)));
ApplySignalsToCredits();
StateTimer = 0.f;
@ -737,6 +743,7 @@ void TMyApplication::LoadGalaxyUi()
[modal_background, this](Vector2f v, int i) {
PerformInMainThreadAsync([modal_background, this]() {
modal_background->setVisibility(false);
Menu.GalaxMenu.planetHoverIndex = -1;
Menu.GalaxMenu.setTimerActivity(false);
});
});
@ -818,6 +825,7 @@ void TMyApplication::SetupGalaxyUi(size_t levelStar)
[this, modal_background, levelStar, levelIndex](Vector2f v, int i) {
PerformInMainThreadAsync([this, modal_background, levelStar, levelIndex]() {
modal_background->setVisibility(false);
Menu.GalaxMenu.planetHoverIndex = -1;
std::shared_ptr<TGameLevel> lvl = this->Menu.GalaxMenu.galaxies[0].Stars[levelStar].selectionMenu.gameLevels[levelIndex];
lvl->ReloadLevel();
@ -858,7 +866,10 @@ void TMyApplication::GoFromMenuToGame(std::shared_ptr<TGameLevel> level)
GameLevel = level;
GameLevel->SetLoading();
GameState = CONST_GAMESTATE_FROM_MENU_TO_LEVEL;
Menu.SetGameState(GameState);
OnDrawSignal.connect(1, boost::bind(&TGameLevel::Draw, boost::ref(*GameLevel)));
Menu.GalaxMenu.resetValuesOnGameStart();
DisapplySignalsToMenu();
@ -882,6 +893,7 @@ void TMyApplication::GoFromGameToMenu()
ApplySignalsToMenu();
GameState = CONST_GAMESTATE_MENU;
Menu.SetGameState(GameState);
OnDrawSignal.disconnect(boost::bind(&TGameLevel::Draw, boost::ref(GameLevel)));
});
}
@ -889,6 +901,7 @@ void TMyApplication::GoFromGameToMenu()
void TMyApplication::GoFromMenuToCredits()
{
GameState = CONST_GAMESTATE_FROM_MENU_TO_CREDITS;
Menu.SetGameState(GameState);
StateTimer = CONST_CREDITS_SHOW_TIME;
GameCredits.StartAppear();
OnDrawSignal.connect(1, boost::bind(&TGameCredits::Draw, boost::ref(GameCredits)));
@ -900,6 +913,7 @@ void TMyApplication::GoFromCreditsToMenu()
{
GameState = CONST_GAMESTATE_FROM_CREDITS_TO_MENU;
Menu.SetGameState(GameState);
StateTimer = CONST_CREDITS_SHOW_TIME;
GameCredits.StartDisappear();
OnDrawSignal.connect(0, boost::bind(&TGameMenu::Draw, boost::ref(Menu)));
@ -909,12 +923,12 @@ void TMyApplication::GoFromCreditsToMenu()
void TMyApplication::MarkSetGameLevelPause()
{
OnDrawSignal.connect(0, boost::bind(&TGameMenu::Draw, boost::ref(Menu)));
//OnDrawSignal.connect(0, boost::bind(&TGameMenu::Draw, boost::ref(Menu)));
}
void TMyApplication::MarkReleaseGameLevelPause()
{
OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu)));
//OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu)));
}

View File

@ -45,7 +45,7 @@ void TGameMenu::Draw()
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
/*..GalaxMenu draw..*/
GalaxMenu.DrawGalaxyMenu();
GalaxMenu.DrawGalaxyMenu(GameState == CONST_GAMESTATE_MENU);
#endif
#ifndef GALAX_MENU_DRAW
@ -247,3 +247,8 @@ void TGameMenu::SetMenuItemCount(int menuItemCount)
{
MenuItemCount = menuItemCount;
}
void TGameMenu::SetGameState(int gameState)
{
GameState = gameState;
}

3
game/menucode.h Normal file → Executable file
View File

@ -19,6 +19,8 @@ protected:
int MenuItemCount;
int SelectedGame;
int GameState;
public:
@ -34,6 +36,7 @@ public:
void OpenNextLevel();
int GetMenuItemCount();
void SetMenuItemCount(int menuItemCount);
void SetGameState(int gameState);
/*..Galaxy Menu..*/
GalaxyMenu GalaxMenu;