AppPlatform Fixes

This commit is contained in:
TheBrokenRail
2023-11-03 17:10:05 -04:00
committed by iProgramInCpp
parent 2356757730
commit 06c69d3cc8
18 changed files with 202 additions and 135 deletions

View File

@@ -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()
{

View File

@@ -59,9 +59,6 @@ public:
virtual void updateFocused(bool focused);
// Also add this to allow proper text input within the game.
virtual bool shiftPressed();
virtual void showKeyboard(bool bShown);
virtual void onHideKeyboard(); // called by the runner, not the game
virtual int getKeyboardUpOffset();
virtual bool hasFileSystemAccess();
// Also add this to allow dynamic patching.
@@ -71,6 +68,9 @@ public:
// On-screen keyboard
virtual void showKeyboard(int x, int y, int w, int h);
virtual void hideKeyboard();
#ifdef USE_NATIVE_ANDROID
virtual int getKeyboardUpOffset();
#endif
#endif
public:

View File

@@ -263,11 +263,12 @@ void Screen::mouseClicked(int xPos, int yPos, int d) // d = clicked?
TextInputBox* textInput = m_textInputs[i];
if (textInput->m_bFocused == handleFocused)
{
textInput->onClick(m_pMinecraft, xPos, yPos);
textInput->onClick(xPos, yPos);
}
}
}
#ifdef USE_NATIVE_ANDROID
// if the keyboard is shown:
if (m_pMinecraft->platform()->getKeyboardUpOffset())
{
@@ -284,9 +285,10 @@ void Screen::mouseClicked(int xPos, int yPos, int d) // d = clicked?
}
if (!areAnyFocused)
m_pMinecraft->platform()->showKeyboard(false);
m_pMinecraft->platform()->hideKeyboard();
}
#endif
#endif
}
void Screen::mouseReleased(int xPos, int yPos, int d)
@@ -361,6 +363,7 @@ void Screen::onRender(int mouseX, int mouseY, float f)
int Screen::getYOffset()
{
#ifdef USE_NATIVE_ANDROID
int keybOffset = m_pMinecraft->platform()->getKeyboardUpOffset();
if (!keybOffset)
return 0;
@@ -395,6 +398,9 @@ int Screen::getYOffset()
}
return offset;
#else
return 0;
#endif
}
void Screen::updateEvents()

View File

@@ -10,7 +10,7 @@
#include "client/app/Minecraft.hpp"
#ifndef ORIGINAL_CODE
#if defined(ANDROID) && !defined(USE_SDL)
#ifdef USE_NATIVE_ANDROID
#define HANDLE_CHARS_SEPARATELY // faked though, see platforms/android/minecraftcpp/minecraftcpp.NativeActivity/main.cpp
#endif
@@ -32,6 +32,11 @@ TextInputBox::TextInputBox(Screen* parent, int id, int x, int y, int width, int
m_pParent = parent;
}
TextInputBox::~TextInputBox()
{
m_pParent->m_pMinecraft->platform()->hideKeyboard();
}
void TextInputBox::init(Font* pFont)
{
m_pFont = pFont;
@@ -179,22 +184,22 @@ void TextInputBox::tick()
}
}
void TextInputBox::setFocused(Minecraft* minecraft, bool b)
void TextInputBox::setFocused(bool b)
{
if (m_bFocused == b)
return;
if (b)
{
int x = m_xPos / Gui::InvGuiScale;
int y = m_yPos / Gui::InvGuiScale;
int w = m_width / Gui::InvGuiScale;
int h = m_height / Gui::InvGuiScale;
minecraft->platform()->showKeyboard(x, y, w, h);
int x = (int) (((float) m_xPos) / Gui::InvGuiScale);
int y = (int) (((float) m_yPos) / Gui::InvGuiScale);
int w = (int) (((float) m_width) / Gui::InvGuiScale);
int h = (int) (((float) m_height) / Gui::InvGuiScale);
m_pParent->m_pMinecraft->platform()->showKeyboard(x, y, w, h);
}
else
{
minecraft->platform()->hideKeyboard();
m_pParent->m_pMinecraft->platform()->hideKeyboard();
}
m_bFocused = b;
@@ -203,17 +208,15 @@ void TextInputBox::setFocused(Minecraft* minecraft, bool b)
m_lastFlashed = getTimeMs();
m_bCursorOn = true;
m_insertHead = int(m_text.size());
m_pParent->m_pMinecraft->platform()->showKeyboard(true);
}
// don't actually hide the keyboard when unfocusing
// - we may be undoing the work of another text box
}
void TextInputBox::onClick(Minecraft* minecraft, int x, int y)
void TextInputBox::onClick(int x, int y)
{
setFocused(minecraft, clicked(x, y));
setFocused(clicked(x, y));
}
void TextInputBox::charPressed(int k)

View File

@@ -23,6 +23,7 @@ class TextInputBox : public GuiComponent
{
public:
TextInputBox(Screen*, int id, int x, int y, int width = 200, int height = 12, const std::string& placeholder = "", const std::string& text = "");
~TextInputBox();
void init(Font* pFont);
void setEnabled(bool bEnabled);
@@ -30,8 +31,8 @@ public:
void charPressed(int chr);
void render();
void tick();
void setFocused(Minecraft*, bool b);
void onClick(Minecraft*, int x, int y);
void setFocused(bool b);
void onClick(int x, int y);
bool clicked(int x, int y);
public:

View File

@@ -35,7 +35,7 @@ void ChatScreen::init()
// set focus directly on the chat text box
m_textChat.init(m_pFont);
m_textChat.setFocused(m_pMinecraft, true);
m_textChat.setFocused(true);
m_buttons.push_back(&m_btnSend);
m_textInputs.push_back(&m_textChat);

View File

@@ -149,7 +149,7 @@ void Options::_initDefaultValues()
KM(KM_FLY_DOWN, SDLVK_x);
KM(KM_CHAT_CMD, SDLVK_SLASH);
#endif
#if defined(ANDROID) && !defined(USE_SDL)
#ifdef USE_NATIVE_ANDROID
// -- Original xperia play controls
//KM(KM_FORWARD, AKEYCODE_DPAD_UP);
//KM(KM_LEFT, AKEYCODE_DPAD_LEFT);

View File

@@ -13,7 +13,7 @@ bool Controller::isTouchedValues[2];
float Controller::stickValuesX[2];
float Controller::stickValuesY[2];
#if !defined(ANDROID) || defined(USE_SDL)
#ifndef USE_NATIVE_ANDROID
const float Controller_unk_1[3] = { 0.0f, 0.64f, -0.64f };
#endif
@@ -52,7 +52,7 @@ void Controller::feed(int stickNo, int touched, float x, float y)
if (!isValidStick(stickNo))
return;
#if defined(ANDROID) && !defined(USE_SDL)
#ifdef USE_NATIVE_ANDROID
int index = stickNo - 1;
#else
int index = (x >= 0.0f) ? 1 : 0;
@@ -61,7 +61,7 @@ void Controller::feed(int stickNo, int touched, float x, float y)
// maybe the 2 'touch sticks' are actually internally 1 single surface??
isTouchedValues[index] = touched != 0;
#if defined(ANDROID) && !defined(USE_SDL)
#ifdef USE_NATIVE_ANDROID
stickValuesX[index] = x;
#else
stickValuesX[index] = linearTransform(x + Controller_unk_1[index + 1], 0.0f, 2.78f, true);

View File

@@ -22,7 +22,7 @@ ControllerTurnInput::ControllerTurnInput()
TurnDelta ControllerTurnInput::getTurnDelta()
{
#if defined(ANDROID) && !defined(USE_SDL)
#ifdef USE_NATIVE_ANDROID
return TurnDelta(Controller::getX(m_stickNo) * 50.f, Controller::getY(m_stickNo) * 60.f);
#endif