GUI: Fix mobile controls

This commit is contained in:
Er2
2023-12-09 21:14:41 +03:00
parent b6bf9d616a
commit bb11bf0825
8 changed files with 37 additions and 25 deletions

View File

@@ -38,8 +38,14 @@ 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; }
bool isTouchscreen() override {
#ifdef MOBILE
return true;
#else
return false;
#endif
}
static MouseButtonType GetMouseButtonType(SDL_Event event);
static bool GetMouseButtonState(SDL_Event event);

View File

@@ -34,6 +34,7 @@
#include "client/newui/Gui.hpp"
#else
#include "client/gui/Gui.hpp"
#include "client/gui/input/TouchscreenInput_TestFps.hpp"
#endif
int Minecraft::width = C_DEFAULT_SCREEN_WIDTH;
@@ -644,7 +645,11 @@ void Minecraft::_reloadInput()
if (isTouchscreen())
{
m_pInputHolder = new TouchInputHolder(this, m_options);
TouchInputHolder *holder = new TouchInputHolder(this, m_options);
#ifndef NEWUI
holder->m_touchScreenInput = new TouchscreenInput_TestFps(this, m_options);
#endif
m_pInputHolder = holder;
}
else
{

View File

@@ -527,7 +527,12 @@ void Gui::renderChatMessages(bool bShowAll)
int Gui::getNumSlots()
{
if (m_pMinecraft->isTouchscreen())
return 4;
{
if (scale < 0.5)
return 4;
else
return 10;
}
return 9;
}

View File

@@ -13,11 +13,12 @@
#include "world/entity/Player.hpp"
TouchscreenInput_TestFps::TouchscreenInput_TestFps(Minecraft* pMinecraft, Options* pOptions) :
m_rectArea(0.0f, 0.0f, 1.0f, 1.0f),
m_pOptions(pOptions),
TouchInput(pMinecraft, pOptions),
//m_rectArea(0.0f, 0.0f, 1.0f, 1.0f),
//m_pOptions(pOptions),
field_40(false),
m_bJumpBeingHeld(false),
m_pMinecraft(pMinecraft),
//m_pMinecraft(pMinecraft),
m_pAreaLeft(nullptr),
m_pAreaRight(nullptr),
m_pAreaForward(nullptr),
@@ -279,11 +280,6 @@ void TouchscreenInput_TestFps::onRender(float f)
glEnable(GL_CULL_FACE);
}
RectangleArea TouchscreenInput_TestFps::getRectangleArea()
{
return m_rectArea;
}
bool TouchscreenInput_TestFps::isButtonDown(int key)
{
return field_6C[key - 100];

View File

@@ -9,15 +9,15 @@
#pragma once
#include "client/gui/GuiComponent.hpp"
#include "client/player/input/IMoveInput.hpp"
#include "client/player/input/RectangleArea.hpp"
#include "client/player/input/PolygonArea.hpp"
#include "client/player/input/TouchAreaModel.hpp"
#include "client/player/input/TouchInputHolder.hpp"
class Minecraft;
class Options;
class TouchscreenInput_TestFps : public IMoveInput, public GuiComponent
class TouchscreenInput_TestFps : public TouchInput, public GuiComponent
{
public:
TouchscreenInput_TestFps(Minecraft*, Options*);
@@ -29,17 +29,13 @@ public:
void onTick(Player*) override;
void onRender(float f) override;
RectangleArea getRectangleArea();
bool isButtonDown(int key);
private:
RectangleArea m_rectArea;
bool field_30[10];
Options* m_pOptions;
bool field_40;
bool m_bJumpBeingHeld;
TouchAreaModel m_touchAreaModel;
Minecraft* m_pMinecraft;
PolygonArea* m_pAreaLeft;
PolygonArea* m_pAreaRight;
PolygonArea* m_pAreaForward;

View File

@@ -12,7 +12,7 @@
#include "client/options/Options.hpp"
TouchInputHolder::TouchInputHolder(Minecraft* pMinecraft, Options* pOptions) :
m_touchScreenInput(pMinecraft, pOptions),
m_touchScreenInput(nullptr),
m_unifiedTurnBuild(2, Minecraft::width, Minecraft::height, 200.0f, 1.05f, this),
m_pMinecraft(pMinecraft)
{
@@ -41,7 +41,7 @@ bool TouchInputHolder::allowPicking()
IMoveInput* TouchInputHolder::getMoveInput()
{
return &m_touchScreenInput;
return m_touchScreenInput;
}
ITurnInput* TouchInputHolder::getTurnInput()
@@ -56,8 +56,8 @@ IBuildInput* TouchInputHolder::getBuildInput()
void TouchInputHolder::setScreenSize(int width, int height)
{
m_touchScreenInput.setScreenSize(width, height);
m_unifiedTurnBuild.field_40 = m_touchScreenInput.getRectangleArea();
m_touchScreenInput->setScreenSize(width, height);
m_unifiedTurnBuild.field_40 = m_touchScreenInput->getRectangleArea();
m_unifiedTurnBuild.field_58 = getRectangleArea(m_pMinecraft->m_pGui, false);
m_unifiedTurnBuild.setScreenSize(width, height);
}

View File

@@ -41,7 +41,7 @@ public:
return m_rectArea;
}
private:
protected:
Minecraft* m_pMinecraft;
Options* m_pOptions;
RectangleArea m_rectArea;
@@ -58,7 +58,7 @@ public:
void setScreenSize(int width, int height) override;
public:
TouchInput m_touchScreenInput;
TouchInput *m_touchScreenInput;
UnifiedTurnBuild m_unifiedTurnBuild;
Minecraft* m_pMinecraft;
};

View File

@@ -1,5 +1,5 @@
set(RENDER GL CACHE STRING "Active renderer")
set_property(CACHE RENDER PROPERTY STRINGS GL)
set_property(CACHE RENDER PROPERTY STRINGS GL GLES)
#add_library(reminecraftpe-renderer STATIC)
if (RENDER STREQUAL GL)
@@ -12,6 +12,10 @@ if (RENDER STREQUAL GL)
else()
set(USE_GLES1_COMPATIBILITY_LAYER TRUE)
endif()
elseif (RENDER STREQUAL GLES)
# OpenGL ES
# nothing?
set(SOURCES GL/GL.cpp GL/GL.hpp)
else()
message(FATAL_ERROR "Unknown renderer!")
endif()