Better Back Button Behavior On SDL Android

This commit is contained in:
TheBrokenRail
2023-11-03 13:37:27 -04:00
committed by iProgramInCpp
parent 8af9d4b0c8
commit 2356757730
5 changed files with 39 additions and 12 deletions

13
.gitignore vendored
View File

@@ -163,6 +163,19 @@ xcuserdata/
/game/assets/mob/char.png
/game/assets/particles.png
/game/assets/terrain.png
/game/assets/gui/buynow.png
/game/assets/gui/controls/dpad.png
/game/assets/gui/controls/dpadbutton.png
/game/assets/gui/controls/dpad_jump.png
/game/assets/gui/feedback.png
/game/assets/gui/itemframe.png
/game/assets/gui/menubuttons.png
/game/assets/gui/plusknapp.png
/game/assets/gui/selectworld/add.png
/game/assets/gui/startmenu/sm_play.png
/game/assets/gui/startmenu/sm_multi.png
/game/assets/gui/startmenu/sm_options.png
/game/assets/gui/touchgui.png
# Ignore the panorama textures. Adding them yourself will make the title screen use them.
/game/assets/gui/background/panorama_0.png

View File

@@ -29,7 +29,8 @@ android {
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ''
arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_static'
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
}
@@ -53,4 +54,4 @@ android {
}
dependencies {
}
}

View File

@@ -35,10 +35,6 @@ static void teardown()
static int TranslateSDLKeyCodeToVirtual(int sdlCode)
{
if (sdlCode == SDLK_AC_BACK) {
// Android Back Button
sdlCode = SDLK_ESCAPE;
}
switch (sdlCode) {
#define CODE(x) case SDLK_ ## x: return SDLVK_ ## x;
#include "compat/SDLKeyCodes.h"
@@ -135,7 +131,14 @@ static void handle_events()
break;
}
*/
// Android Back Button
if (event.key.keysym.sym == SDLK_AC_BACK) {
g_pApp->handleBack(event.key.state == SDL_PRESSED);
break;
}
// Normal Key Press
Keyboard::feed(AppPlatform_sdl_base::GetKeyState(event), TranslateSDLKeyCodeToVirtual(event.key.keysym.sym));
if (event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT)
{
@@ -339,6 +342,10 @@ int main(int argc, char *argv[])
// Create Window
int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
#ifdef ANDROID
// Android Immersive Mode
flags |= SDL_WINDOW_FULLSCREEN;
#endif
window = SDL_CreateWindow("ReMinecraftPE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Minecraft::width, Minecraft::height, flags);
if (!window)
{
@@ -368,11 +375,6 @@ int main(int argc, char *argv[])
}
#endif
// Android Immersive Mode
#ifdef ANDROID
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
#endif
// Setup Compatibility Layer If Needed
#ifdef USE_GLES1_COMPATIBILITY_LAYER
init_gles_compatibility_layer();

View File

@@ -546,3 +546,12 @@ std::string StartMenuScreen::getSplashString()
return std::string(gSplashes[m_chosenSplash]);
}
bool StartMenuScreen::handleBackEvent(bool b)
{
if (!b)
{
m_pMinecraft->quit();
}
return true;
}

View File

@@ -26,6 +26,8 @@ public:
std::string getSplashString();
bool handleBackEvent(bool b) override;
private:
Button m_startButton;
Button m_joinButton;