Skip to content

Commit

Permalink
AppPlatform Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBrokenRail authored and iProgramMC committed Dec 19, 2023
1 parent 2356757 commit 06c69d3
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 133 deletions.
17 changes: 11 additions & 6 deletions platforms/android/AppPlatform_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,17 @@ void AppPlatform_android::setShiftPressed(bool b)
m_bShiftPressed = b;
}

void AppPlatform_android::showKeyboard(bool bShown)
void AppPlatform_android::showKeyboard(int x, int y, int w, int h)
{
changeKeyboardVisibility(true);
}

void AppPlatform_android::hideKeyboard()
{
changeKeyboardVisibility(false);
}

void AppPlatform_android::changeKeyboardVisibility(bool bShown)
{
JavaVM* pVM = m_app->activity->vm;
JNIEnv* pEnv = m_app->activity->env;
Expand Down Expand Up @@ -340,11 +350,6 @@ void AppPlatform_android::showKeyboard(bool bShown)
pVM->DetachCurrentThread();
}

void AppPlatform_android::onHideKeyboard()
{
m_bIsKeyboardShown = false;
}

int AppPlatform_android::getKeyboardUpOffset()
{
// @TODO
Expand Down
6 changes: 4 additions & 2 deletions platforms/android/AppPlatform_android.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class AppPlatform_android : public AppPlatform
// Also add these to allow proper text input within the game.
bool shiftPressed() override;
void setShiftPressed(bool b);
void showKeyboard(bool bShown) override;
void onHideKeyboard() override; // This is an event
void showKeyboard(int x, int y, int w, int h) override;
void hideKeyboard() override;
int getKeyboardUpOffset() override;

// Also add these to allow saving options.
Expand All @@ -63,6 +63,8 @@ class AppPlatform_android : public AppPlatform
void setExternalStoragePath(const std::string& path);

private:
void changeKeyboardVisibility(bool bShown);

int m_ScreenWidth;
int m_ScreenHeight;

Expand Down
78 changes: 27 additions & 51 deletions platforms/android/project/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,35 @@

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-android)

# Project Root
set(MC_ROOT ../../../../../../..)

# Build
add_compile_definitions(USE_NATIVE_ANDROID)
add_library(reminecraftpe SHARED
"${MC_ROOT}/platforms/android/android_native_app_glue.c"
"${MC_ROOT}/platforms/android/AppPlatform_android.cpp"
"${MC_ROOT}/platforms/android/main.cpp"
"${MC_ROOT}/thirdparty/stb_image_impl.c"
)

# Core
add_subdirectory("${MC_ROOT}/source" source)
target_link_libraries(reminecraftpe reminecraftpe-core)

# Declares and names the project.

project("reminecraftpe")

# The root of the project
SET(MC_ROOT ../../../../../../..)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
reminecraftpe

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
${MC_ROOT}/platforms/android/android_native_app_glue.c
${MC_ROOT}/platforms/android/AppPlatform_android.cpp
${MC_ROOT}/platforms/android/main.cpp
${MC_ROOT}/thirdparty/stb_image_impl.c)
# Extra Dependencies
target_link_libraries(reminecraftpe android)

# Check for the presence of some optional asset based features.
if(NOT EXISTS "${MC_ROOT}/game/assets/gui/background/panorama_0.png")
target_compile_definitions(reminecraftpe PUBLIC FEATURE_MENU_BACKGROUND)
if(EXISTS "${MC_ROOT}/game/assets/gui/background/panorama_0.png")
target_compile_definitions(reminecraftpe PUBLIC FEATURE_MENU_BACKGROUND)
endif()

if(NOT EXISTS "${MC_ROOT}/game/assets/environment/clouds.png")
target_compile_definitions(reminecraftpe PUBLIC FEATURE_CLOUDS)
if(EXISTS "${MC_ROOT}/game/assets/environment/clouds.png")
target_compile_definitions(reminecraftpe PUBLIC FEATURE_CLOUDS)
endif()

if(NOT EXISTS "${MC_ROOT}/game/assets/misc/grasscolor.png")
target_compile_definitions(reminecraftpe PUBLIC FEATURE_GRASS_COLOR)
if(EXISTS "${MC_ROOT}/game/assets/misc/grasscolor.png")
target_compile_definitions(reminecraftpe PUBLIC FEATURE_GRASS_COLOR)
endif()

if(NOT EXISTS "${MC_ROOT}/game/assets/misc/foliagecolor.png")
target_compile_definitions(reminecraftpe PUBLIC FEATURE_FOLIAGE_COLOR)
if(EXISTS "${MC_ROOT}/game/assets/misc/foliagecolor.png")
target_compile_definitions(reminecraftpe PUBLIC FEATURE_FOLIAGE_COLOR)
endif()

# Add the core as part of the library.
add_subdirectory(${MC_ROOT}/source source)
target_link_libraries(reminecraftpe reminecraftpe-core)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
reminecraftpe android )
17 changes: 17 additions & 0 deletions platforms/sdl/android/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.WindowManager;

import org.libsdl.app.SDLActivity;
import org.libsdl.app.LimitedSDLActivity;

public class MainActivity extends SDLActivity {
public class MainActivity extends LimitedSDLActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -16,4 +19,32 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
}

@Override
@SuppressWarnings("deprecation")
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);

// Fullscreen
if (hasFocus) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().setDecorFitsSystemWindows(false);
WindowInsetsController controller = getWindow().getInsetsController();
if (controller != null) {
controller.hide(WindowInsets.Type.systemBars());
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
} else {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.INVISIBLE
);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.libsdl.app;

// Prevent SDL From Controlling Immersive Mode
public class LimitedSDLActivity extends SDLActivity {
@Override
boolean sendCommand(int command, Object data) {
if (command == COMMAND_CHANGE_WINDOW_STYLE) {
return true;
} else {
return super.sendCommand(command, data);
}
}

@Override
public void onSystemUiVisibilityChange(int visibility) {
}
}
88 changes: 53 additions & 35 deletions platforms/sdl/base/AppPlatform_sdl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ void AppPlatform_sdl_base::initSoundSystem()
}
}

std::string AppPlatform_sdl_base::getDateString(int time)
{
time_t tt = time;
struct tm t;
#ifdef _WIN32
gmtime_s(&t, &tt);
#else
gmtime_r(&tt, &t);
#endif

// Format String
char buf[2048];
strftime(buf, sizeof buf, "%b %d %Y %H:%M:%S", &t);

// Return
return std::string(buf);
}

void AppPlatform_sdl_base::setIcon(const Texture& icon)
{
if (!icon.m_pixels)
Expand Down Expand Up @@ -185,14 +203,14 @@ MouseButtonType AppPlatform_sdl_base::GetMouseButtonType(SDL_Event event)
{
switch (event.button.button)
{
case SDL_BUTTON_LEFT:
return BUTTON_LEFT;
case SDL_BUTTON_RIGHT:
return BUTTON_RIGHT;
case SDL_BUTTON_MIDDLE:
return BUTTON_MIDDLE;
default:
return BUTTON_NONE;
case SDL_BUTTON_LEFT:
return BUTTON_LEFT;
case SDL_BUTTON_RIGHT:
return BUTTON_RIGHT;
case SDL_BUTTON_MIDDLE:
return BUTTON_MIDDLE;
default:
return BUTTON_NONE;
}
}

Expand All @@ -202,30 +220,30 @@ bool AppPlatform_sdl_base::GetMouseButtonState(SDL_Event event)

switch (event.type)
{
case SDL_MOUSEBUTTONDOWN:
result = true;
break;
case SDL_MOUSEBUTTONUP:
result = false;
break;
case SDL_MOUSEWHEEL:
{
short wheelDelta = event.wheel.y;
if (wheelDelta > 0)
{
// "A positive value indicates that the wheel was rotated forward, away from the user."
case SDL_MOUSEBUTTONDOWN:
result = true;
break;
case SDL_MOUSEBUTTONUP:
result = false;
}
else
break;
case SDL_MOUSEWHEEL:
{
// "A negative value indicates that the wheel was rotated backward, toward the user."
result = true;
short wheelDelta = event.wheel.y;
if (wheelDelta > 0)
{
// "A positive value indicates that the wheel was rotated forward, away from the user."
result = false;
}
else
{
// "A negative value indicates that the wheel was rotated backward, toward the user."
result = true;
}
break;
}
break;
}
default:
result = false;
break;
default:
result = false;
break;
}

return result;
Expand All @@ -235,19 +253,19 @@ Keyboard::KeyState AppPlatform_sdl_base::GetKeyState(SDL_Event event)
{
switch (event.key.state)
{
case SDL_RELEASED:
return Keyboard::UP;
case SDL_PRESSED:
default:
return Keyboard::DOWN;
case SDL_RELEASED:
return Keyboard::UP;
case SDL_PRESSED:
default:
return Keyboard::DOWN;
}
}

void AppPlatform_sdl_base::showKeyboard(int x, int y, int w, int h)
{
if (SDL_IsTextInputActive())
{
SDL_StopTextInput();
hideKeyboard();
}
SDL_Rect rect;
rect.x = x;
Expand Down
1 change: 1 addition & 0 deletions platforms/sdl/base/AppPlatform_sdl_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AppPlatform_sdl_base : public AppPlatform
Texture loadTexture(const std::string& path, bool b = false) override = 0;
int getUserInputStatus() override;
SoundSystem* const getSoundSystem() const override { return m_pSoundSystem; }
std::string getDateString(int time) override;

// Also add these to allow proper turning within the game.
void setMouseGrabbed(bool b) override;
Expand Down
4 changes: 0 additions & 4 deletions platforms/sdl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,6 @@ 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)
{
Expand Down
10 changes: 2 additions & 8 deletions source/client/app/AppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,12 @@ bool AppPlatform::shiftPressed()
return false;
}

void AppPlatform::showKeyboard(bool bShown)
{
}

void AppPlatform::onHideKeyboard()
{
}

#ifdef USE_NATIVE_ANDROID
int AppPlatform::getKeyboardUpOffset()
{
return 0;
}
#endif

bool AppPlatform::hasFileSystemAccess()
{
Expand Down
Loading

0 comments on commit 06c69d3

Please sign in to comment.