diff --git a/assets/back_btn.png b/assets/back_btn.png deleted file mode 100755 index 4176c8b..0000000 Binary files a/assets/back_btn.png and /dev/null differ diff --git a/assets/gui_game_pause_menu.json b/assets/gui_game_pause_menu.json new file mode 100755 index 0000000..4da31b2 --- /dev/null +++ b/assets/gui_game_pause_menu.json @@ -0,0 +1,53 @@ +{ + "widgets": [ + { + "type": "FrameLayout", + "name": "gameFrame", + "background": "#00000000", + "width": "match_parent", + "height": "match_parent", + "visible": 1, + "touchTransparency": 0, + "marginTop": 20, + "horizontalAlignment": "HA_CENTER", + "verticalAlignment": "VA_TOP", + "children" : [ + { + "type": "Button", + "name": "pauseButton", + "width": 128, + "height": 64, + "background": "back_btn.png" + }] + }, + { + "type": "VerticalLinearLayout", + "name": "buttonList", + "background": "#00000000", + "width": "match_parent", + "height": "match_parent", + "touchTransparency": 0, + "visible": 0, + "zLevel": 10, + "marginTop" : 20, + "marginBottom" : 20, + "marginLeft" : 20, + "marginRight" : 20, + "itemSpacing": 20, + "children" : [ + { + "type": "Button", + "name": "exitButton", + "width": 128, + "height": 128, + "background": "slide_up_btn.png" + }, + { + "type": "Button", + "name": "resumeButton", + "width": 128, + "height": 128, + "background": "tap_to_continue_btn.png" + }] + }] +} \ No newline at end of file diff --git a/assets/slide_up_btn.png b/assets/slide_up_btn.png deleted file mode 100755 index fb26969..0000000 Binary files a/assets/slide_up_btn.png and /dev/null differ diff --git a/assets/tap_to_continue_btn.png b/assets/tap_to_continue_btn.png deleted file mode 100755 index b9b51c1..0000000 Binary files a/assets/tap_to_continue_btn.png and /dev/null differ diff --git a/assets/ui/back_btn.png b/assets/ui/back_btn.png index 4176c8b..d81282f 100755 Binary files a/assets/ui/back_btn.png and b/assets/ui/back_btn.png differ diff --git a/assets/ui/slide_up_btn.png b/assets/ui/slide_up_btn.png new file mode 100755 index 0000000..1de7b75 Binary files /dev/null and b/assets/ui/slide_up_btn.png differ diff --git a/assets/ui/tap_to_continue_btn.png b/assets/ui/tap_to_continue_btn.png new file mode 100755 index 0000000..f4d87d1 Binary files /dev/null and b/assets/ui/tap_to_continue_btn.png differ diff --git a/game/gamecode.cpp b/game/gamecode.cpp index dc4734c..9b27cc1 100755 --- a/game/gamecode.cpp +++ b/game/gamecode.cpp @@ -911,10 +911,10 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i //Renderer->TranslateMatrix(-Vector3f(matrixWidth * 0.5f, matrixHeight * 0.5f, 0)); DrawBuffer(); - if (mustShowButtons) - { - DrawPauseButtons(); - } + //if (mustShowButtons) + //{ + // DrawPauseButtons(); + //} //Renderer->PopMatrix(); CheckGlError(); @@ -1079,12 +1079,12 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i if (!pause && LevelState != CONST_LEVELSTATE_SNAPSHOTTING) { - RenderUniform1f("Transparency", 1.f); - glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_BACK_BTN_TEXTURE]); - const Vector2f BackBtnPos(screenWidth*0.5f, Application->GetGameLevelScreenHeight() - 52.f*(Application->GetGameLevelScreenHeight()/320.f)); - const float const_backBtnWidth = CONST_BACK_BTN_WIDTH * Application->GetGameLevelScreenWidth()/480.f; - const float const_backBtnHeight = CONST_BACK_BTN_HEIGHT * Application->GetGameLevelScreenHeight()/320.f; - Renderer->DrawRect(Vector2f(-const_backBtnWidth*0.5f, -const_backBtnHeight*0.5f)+BackBtnPos, Vector2f(const_backBtnWidth*0.5f, const_backBtnHeight*0.5f)+BackBtnPos); + // RenderUniform1f("Transparency", 1.f); + // glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_BACK_BTN_TEXTURE]); + // const Vector2f BackBtnPos(screenWidth*0.5f, Application->GetGameLevelScreenHeight() - 52.f*(Application->GetGameLevelScreenHeight()/320.f)); + //const float const_backBtnWidth = CONST_BACK_BTN_WIDTH * Application->GetGameLevelScreenWidth()/480.f; + //const float const_backBtnHeight = CONST_BACK_BTN_HEIGHT * Application->GetGameLevelScreenHeight()/320.f; + // 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); @@ -1104,10 +1104,10 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i Renderer->ScaleMatrix(OutScale); Renderer->TranslateMatrix(-Vector3f(matrixWidth * 0.5f, matrixHeight * 0.5f, 0)); DrawBuffer(); - if (mustShowButtons) - { - DrawPauseButtons(); - } + //if (mustShowButtons) + //{ + // DrawPauseButtons(); + //} Renderer->PopMatrix(); RenderBufferReady = true; CheckGlError(); @@ -1200,6 +1200,10 @@ void TGameLevel::DrawBuffer() void TGameLevel::SetPause() { + if (LevelState == CONST_LEVELSTATE_STANDBY) + { + PrevLevelStateIsStandby = true; + } OutScaleVelocity = 0.f; OutScale = 1.f; @@ -1254,7 +1258,7 @@ void TGameLevel::Update(size_t dt) if (LevelState == CONST_LEVELSTATE_PAUSE) { OutScale += OutScaleVelocity * dt; - TryGoToMenu(); + //TryGoToMenu(); CheckGlError(); return; } @@ -1825,37 +1829,20 @@ void TGameLevel::OnTapDown(Vector2f pos) if (LevelState == CONST_LEVELSTATE_STANDBY) { - if (TapInBackBtnArea({ xPos, yPos })) - { - SetPause(); - PrevLevelStateIsStandby = true; - } - else - { - - LevelState = CONST_LEVELSTATE_PLAYING; - BallList.begin()->Go(); - } + LevelState = CONST_LEVELSTATE_PLAYING; + BallList.begin()->Go(); } else if (LevelState == CONST_LEVELSTATE_PLAYING) { - if (TapInBackBtnArea({ xPos, yPos })) - { - SetPause(); - } - else// if (fabs(ReflectorPos(0) - xPos / Application->GetGameLevelScreenWidth()) > 64.f / Application->GetGameLevelScreenWidth()) - { - ReflectorPos(0) = xPos / Application->GetGameLevelScreenWidth(); - } - - } - else if (LevelState == CONST_LEVELSTATE_PAUSE) - { - if (yPos > 128.f) - { - ReleasePause(); - } + ReflectorPos(0) = xPos / Application->GetGameLevelScreenWidth(); } + //else if (LevelState == CONST_LEVELSTATE_PAUSE) + //{ + // if (yPos > 128.f) + // { + // ReleasePause(); + // } + //} } void TGameLevel::OnTapUp(Vector2f pos) @@ -1886,23 +1873,26 @@ void TGameLevel::OnScroll(Vector2f shift) OutScale += shift(1)/320.f; - TryGoToMenu(); + //TryGoToMenu(); } } void TGameLevel::TryGoToMenu() { - if (OutScale < 0.5f) - { - OutScale = 0.5f; - LevelState = CONST_LEVELSTATE_NODRAW; - Application->GoFromGameToMenu(); - } - if (OutScale > 1.f) - { - OutScale = 1.f; - } + LevelState = CONST_LEVELSTATE_NODRAW; + Application->GoFromGameToMenu(); + + //if (OutScale < 0.5f) + //{ + // OutScale = 0.5f; + // LevelState = CONST_LEVELSTATE_NODRAW; + // Application->GoFromGameToMenu(); + //} + //if (OutScale > 1.f) + //{ + // OutScale = 1.f; + //} } bool TBrick::IsAppear() { diff --git a/game/main_code.cpp b/game/main_code.cpp index 3f4157b..1db39c3 100755 --- a/game/main_code.cpp +++ b/game/main_code.cpp @@ -57,6 +57,11 @@ TMyApplication* Application; int currentStar; int currentLevel; +boost::property_tree::ptree gamePauseMenuUi; +boost::property_tree::ptree galaxyMenuUi; + +bool ignoreTapUp = false; + void TMyApplication::LoadUserProgress() { boost::property_tree::ptree userProgressJson; @@ -143,7 +148,7 @@ void TMyApplication::InnerInit() #ifdef TARGET_WIN32 #ifdef NDEBUG ST::PathToResources = "resources/"; - //ST::PathToResources = "../../../assets/"; + ST::PathToResources = "../../../assets/"; #else ST::PathToResources = "../../../assets/"; #endif @@ -203,6 +208,10 @@ void TMyApplication::InnerInit() EffectsInit(); // ------- UI ------- + + boost::property_tree::json_parser::read_json(ST::PathToResources + "gui_game_pause_menu.json", gamePauseMenuUi); + boost::property_tree::json_parser::read_json(ST::PathToResources + "gui_main_menu.json", galaxyMenuUi); + ResourceManager->FontManager.AddFont("arial32", "arial32.png", "arial32.txt"); ResourceManager->FontManager.AddFont("lucon12", "lucon12.png", "lucon12.txt"); ResourceManager->FontManager.PushFont("lucon12"); @@ -253,11 +262,21 @@ void TMyApplication::InnerDeinit() void TMyApplication::InnerOnTapUp(Vector2f p) { + if (ignoreTapUp) + { + return; + } + OnTapUpSignal(Vector2f(p(0), p(1))); } void TMyApplication::InnerOnTapUpAfterMove(Vector2f p) { + if (ignoreTapUp) + { + return; + } + OnTapUpAfterMoveSignal(Vector2f(p(0), p(1))); } @@ -422,9 +441,9 @@ void TMyApplication::LoadResources() TextureNamesToLoad.push_back(std::pair(CONST_WALL_UP_TEXTURE + ".png", CONST_WALL_UP_TEXTURE)); TextureNamesToLoad.push_back(std::pair(CONST_WALL_BONUS_TEXTURE + ".png", CONST_WALL_BONUS_TEXTURE)); TextureNamesToLoad.push_back(std::pair(CONST_REFLECTOR_TEXTURE + ".png", CONST_REFLECTOR_TEXTURE)); - TextureNamesToLoad.push_back(std::pair(CONST_BACK_BTN_TEXTURE + ".png", CONST_BACK_BTN_TEXTURE)); - TextureNamesToLoad.push_back(std::pair(CONST_SLIDE_UP_BTN_TEXTURE + ".png", CONST_SLIDE_UP_BTN_TEXTURE)); - TextureNamesToLoad.push_back(std::pair(CONST_TAP_TO_CONTINUE_BTN_TEXTURE + ".png", CONST_TAP_TO_CONTINUE_BTN_TEXTURE)); + //TextureNamesToLoad.push_back(std::pair(CONST_BACK_BTN_TEXTURE + ".png", CONST_BACK_BTN_TEXTURE)); + //TextureNamesToLoad.push_back(std::pair(CONST_SLIDE_UP_BTN_TEXTURE + ".png", CONST_SLIDE_UP_BTN_TEXTURE)); + //TextureNamesToLoad.push_back(std::pair(CONST_TAP_TO_CONTINUE_BTN_TEXTURE + ".png", CONST_TAP_TO_CONTINUE_BTN_TEXTURE)); TextureNamesToLoad.push_back(std::pair(CONST_CREDITS_TEXTURE + ".png", CONST_CREDITS_TEXTURE)); #ifdef TARGET_IOS @@ -577,6 +596,36 @@ void TMyApplication::InnerUpdate(size_t dt) //CONNECT SLOT DisapplySignalsToMenu(); ApplySignalsToGame(); + + ResourceManager->newGuiManager.LoadFromConfig(gamePauseMenuUi); + + auto pauseButton = (Button*)ResourceManager->newGuiManager.findWidgetByName("pauseButton").get(); + auto resumeButton = (Button*)ResourceManager->newGuiManager.findWidgetByName("resumeButton").get(); + auto exitButton = (Button*)ResourceManager->newGuiManager.findWidgetByName("exitButton").get(); + auto gameFrame = (WidgetAncestor*)ResourceManager->newGuiManager.findWidgetByName("gameFrame").get(); + auto pauseBackground = (WidgetAncestor*)ResourceManager->newGuiManager.findWidgetByName("buttonList").get(); + + pauseButton->onMouseDownSignal.connect([this, gameFrame, pauseBackground](Vector2f, int) { + GameLevel->SetPause(); + + gameFrame->setVisibility(false); + pauseBackground->setVisibility(true); + }); + + resumeButton->onMouseDownSignal.connect([this, gameFrame, pauseBackground](Vector2f, int) { + GameLevel->ReleasePause(); + + gameFrame->setVisibility(true); + pauseBackground->setVisibility(false); + }); + + pauseBackground->onMoveSignal.connect([this](Vector2f, Vector2f shift, int) { + SE::GetConsole() << shift.norm(); + if (shift.norm() > 15) + { + GameLevel->TryGoToMenu(); + } + }); } } else if (GameState == CONST_GAMESTATE_FROM_MENU_TO_CREDITS) @@ -616,7 +665,7 @@ void TMyApplication::InnerUpdate(size_t dt) void TMyApplication::LoadGalaxyUi() { ResourceManager->newGuiManager.Clear(); - ResourceManager->newGuiManager.LoadFromConfig("gui_main_menu.json"); + ResourceManager->newGuiManager.LoadFromConfig(galaxyMenuUi); std::shared_ptr modal_background = ResourceManager->newGuiManager.findWidgetByName("modal_background"); @@ -756,11 +805,21 @@ void TMyApplication::GoFromGameToMenu() //#ifndef TARGET_IOS // ResourceManager->SoundManager.StopMusic("level1ogg.ogg"); //#endif - TrySaveGame(); - DisapplySignalsToGame(); - ApplySignalsToMenu(); - GameState = CONST_GAMESTATE_MENU; - OnDrawSignal.disconnect(boost::bind(&TGameLevel::Draw, boost::ref(GameLevel))); + + PerformInMainThreadAsync([this]() { + TrySaveGame(); + DisapplySignalsToGame(); + + ignoreTapUp = true; + + LoadGalaxyUi(); + + Menu.GalaxMenu.UpdateGalaxyMenu(Renderer->GetMatrixWidth(), Renderer->GetMatrixHeight(), 0); + + ApplySignalsToMenu(); + GameState = CONST_GAMESTATE_MENU; + OnDrawSignal.disconnect(boost::bind(&TGameLevel::Draw, boost::ref(GameLevel))); + }); } void TMyApplication::GoFromMenuToCredits() @@ -835,6 +894,8 @@ float TMyApplication::GetGameLevelScreenHeight() void TMyApplication::InnerOnMouseDown(TMouseState& mouseState) { + ignoreTapUp = false; + OnTapDownSignal(Vector2f(mouseState.X, ((Renderer->GetScreenHeight()) - mouseState.Y))); // Temp mouse down action for WIN32 }