Allow Changing Input Mode

This commit is contained in:
TheBrokenRail
2023-11-02 19:21:39 -04:00
committed by iProgramInCpp
parent 7771bc20a7
commit c989ffa721
5 changed files with 36 additions and 5 deletions

View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">

View File

@@ -3,6 +3,7 @@
#include <sstream>
#include <fstream>
#include <sys/stat.h>
#include <cstdlib>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
@@ -31,6 +32,26 @@ void AppPlatform_sdl_base::_init(std::string storageDir, SDL_Window *window)
m_pLogger = new Logger;
m_pSoundSystem = nullptr;
// Default Touchscreen Mode
#ifdef ANDROID
m_bIsTouchscreen = true;
#else
m_bIsTouchscreen = false;
#endif
// Custom Touchscreen Mode
const char *mode = getenv("MCPE_INPUT_MODE");
if (mode)
{
if (strcmp(mode, "touch") == 0)
{
m_bIsTouchscreen = true;
}
else if (strcmp(mode, "mouse") == 0)
{
m_bIsTouchscreen = false;
}
}
}
void AppPlatform_sdl_base::initSoundSystem()
@@ -244,3 +265,7 @@ void AppPlatform_sdl_base::hideKeyboard()
SDL_StopTextInput();
}
}
bool AppPlatform_sdl_base::isTouchscreen() {
return m_bIsTouchscreen;
}

View File

@@ -38,8 +38,6 @@ public:
// Also add these to allow proper text input within the game.
bool shiftPressed() override;
void setShiftPressed(bool b, bool isLeft);
bool isTouchscreen() override { return false; }
static MouseButtonType GetMouseButtonType(SDL_Event event);
static bool GetMouseButtonState(SDL_Event event);
@@ -48,6 +46,9 @@ public:
// On-screen keyboard
void showKeyboard(int x, int y, int w, int h) override;
void hideKeyboard() override;
// Configure Touchscreen
bool isTouchscreen() override;
private:
SDL_Window *_window;
@@ -62,6 +63,8 @@ private:
Logger* m_pLogger;
SoundSystem* m_pSoundSystem;
bool m_bIsTouchscreen;
static SDL_Surface* getSurfaceForTexture(const Texture* const texture);
protected:
std::string _storageDir;

View File

@@ -47,7 +47,11 @@
return canvas;
})(),
arguments: [String(window.innerWidth), String(window.innerHeight)]
arguments: [String(window.innerWidth), String(window.innerHeight)],
preRun: [function () {
const urlParams = new URLSearchParams(window.location.search);
ENV.MCPE_INPUT_MODE = urlParams.get('inputMode');
}]
};
</script>
<script async type="text/javascript" src="reminecraftpe.js"></script>

View File

@@ -295,7 +295,7 @@ void Screen::mouseReleased(int xPos, int yPos, int d)
if (m_pClickedButton)
{
if (m_pMinecraft->isTouchscreen() && button->clicked(m_pMinecraft, xPos, yPos))
if (m_pMinecraft->isTouchscreen() && m_pClickedButton->clicked(m_pMinecraft, xPos, yPos))
{
m_pMinecraft->m_pSoundEngine->play("random.click");
buttonClicked(m_pClickedButton);