Skip to content

Commit ad415b3

Browse files
committed
-Added textures for the sneaking and diagonal movement buttons
-Fixed sneaking button not working properly -Fixed touch area being set in some buttons, causing unintentional hits
1 parent ff8441b commit ad415b3

10 files changed

Lines changed: 48 additions & 32 deletions

File tree

game/assets/gui/touchscreen.png

-2 KB
Loading

source/client/gui/Gui.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,18 @@ int Gui::getNumUsableSlots()
650650
return getNumSlots() - m_pMinecraft->isTouchscreen();
651651
}
652652

653-
RectangleArea Gui::getRectangleArea(bool b)
653+
void Gui::addRectangleArea(std::vector<RectangleArea>& touchArea)
654654
{
655655
float centerX = Minecraft::width / 2;
656656
float hotbarWidthHalf = (10 * getNumSlots() + 5) / InvGuiScale;
657-
return RectangleArea(
658-
b ? (centerX - hotbarWidthHalf) : 0,
657+
touchArea.push_back(RectangleArea(
658+
centerX - hotbarWidthHalf,
659659
Minecraft::height - 24.0f / InvGuiScale,
660660
centerX + hotbarWidthHalf,
661-
Minecraft::height);
661+
Minecraft::height));
662+
touchArea.push_back(RectangleArea(
663+
centerX - 26 / InvGuiScale,
664+
0,
665+
centerX + 10 / InvGuiScale,
666+
16 / InvGuiScale));
662667
}

source/client/gui/Gui.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Gui : public GuiComponent
4747
void renderMessages(bool bShowAll);
4848
int getNumSlots(); // Gets the number of slots in the inventory. Includes the '...' if in touch mode.
4949
int getNumUsableSlots(); // Gets the number of usable slots in the inventory. Does not include the '...' if in touch mode.
50-
RectangleArea getRectangleArea(bool b);
50+
void addRectangleArea(std::vector<RectangleArea>&);
5151

5252
public:
5353
static float InvGuiScale;

source/client/player/input/IMoveInput.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ void IMoveInput::setScreenSize(int width, int height)
3939

4040
void IMoveInput::tick(Player* pPlayer)
4141
{
42+
if (m_bSneaking)
43+
{
44+
m_horzInput = m_horzInput * 0.3f;
45+
m_vertInput = m_vertInput * 0.3f;
46+
}
4247
}

source/client/player/input/KeyboardInput.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,5 @@ void KeyboardInput::tick(Player* pPlayer)
5858
m_bJumping = m_keys[INPUT_JUMP];
5959
m_bSneaking = m_keys[INPUT_SNEAK];
6060

61-
if (m_keys[INPUT_SNEAK])
62-
{
63-
m_horzInput = m_horzInput * 0.3f;
64-
m_vertInput = m_vertInput * 0.3f;
65-
}
61+
IMoveInput::tick(pPlayer);
6662
}

source/client/player/input/TouchInputHolder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ IBuildInput* TouchInputHolder::getBuildInput()
5757
void TouchInputHolder::setScreenSize(int width, int height)
5858
{
5959
m_touchScreenInput.setScreenSize(width, height);
60-
m_unifiedTurnBuild.field_40 = m_touchScreenInput.getRectangleArea();
61-
m_unifiedTurnBuild.field_58 = m_pMinecraft->m_gui.getRectangleArea(false);
60+
m_unifiedTurnBuild.m_touchArea.clear();
61+
m_touchScreenInput.addRectangleArea(m_unifiedTurnBuild.m_touchArea);
62+
m_pMinecraft->m_gui.addRectangleArea(m_unifiedTurnBuild.m_touchArea);
6263
m_unifiedTurnBuild.setScreenSize(width, height);
6364
}

source/client/player/input/TouchscreenInput_TestFps.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
TouchscreenInput_TestFps::TouchscreenInput_TestFps(Minecraft* pMinecraft, Options* pOptions) :
1616
m_rectArea(0.0f, 0.0f, 1.0f, 1.0f),
17+
m_rightRectArea(0.0f, 0.0f, 1.0f, 1.0f),
1718
m_pOptions(pOptions),
1819
field_40(false),
1920
m_bJumpBeingHeld(false),
@@ -33,7 +34,7 @@ TouchscreenInput_TestFps::TouchscreenInput_TestFps(Minecraft* pMinecraft, Option
3334

3435
// Note! Only the first five button entries are used.
3536
for (int i = 0; i < 8; i++)
36-
field_6C[i] = 0;
37+
m_pressedInputs[i] = 0;
3738

3839
setScreenSize(Minecraft::width, Minecraft::height);
3940
}
@@ -43,7 +44,7 @@ void TouchscreenInput_TestFps::releaseAllKeys()
4344
m_horzInput = 0.0f;
4445
m_vertInput = 0.0f;
4546
for (int i = 0; i < 5; i++)
46-
field_6C[i] = false;
47+
m_pressedInputs[i] = false;
4748
}
4849

4950
void TouchscreenInput_TestFps::setKey(int eventKey, bool eventKeyState)
@@ -109,7 +110,10 @@ void TouchscreenInput_TestFps::setScreenSize(int width, int height)
109110
right = middleX + widthM * 2;
110111
bottom = middleY + heightM * 2;
111112

113+
float rightSideX = scaledWidth - widthM - 8;
114+
112115
m_rectArea = RectangleArea(left / Gui::InvGuiScale, top / Gui::InvGuiScale, right / Gui::InvGuiScale, bottom / Gui::InvGuiScale);
116+
m_rightRectArea = RectangleArea(rightSideX / Gui::InvGuiScale, middleY / Gui::InvGuiScale, (rightSideX + widthM) / Gui::InvGuiScale, (middleY + heightM) / Gui::InvGuiScale);
113117

114118
TransformArray(4, x1, y1, x2, y2, middleX, middleY - heightM, 1.0f, 1.0f);
115119
m_pAreaForward = new PolygonArea(4, x2, y2);
@@ -131,10 +135,9 @@ void TouchscreenInput_TestFps::setScreenSize(int width, int height)
131135
m_pAreaRight = new PolygonArea(4, x2, y2);
132136
m_touchAreaModel.addArea(100 + INPUT_RIGHT, m_pAreaRight);
133137

134-
/*float rightSideX = scaledWidth - widthM - 8;
135138
TransformArray(4, x1, y1, x2, y2, rightSideX, middleY, 1.0f, 1.0f);
136139
m_pAreaSneak = new PolygonArea(4, x2, y2);
137-
m_touchAreaModel.addArea(100 + INPUT_SNEAK, m_pAreaSneak);*/
140+
m_touchAreaModel.addArea(100 + INPUT_SNEAK, m_pAreaSneak);
138141

139142
TransformArray(4, x1, y1, x2, y2, middleX - widthM, middleY - heightM, 1.0f, 1.0f);
140143
m_pAreaForwardLeft = new PolygonArea(4, x2, y2);
@@ -157,8 +160,8 @@ void TouchscreenInput_TestFps::tick(Player* pPlayer)
157160
m_vertInput = 0.0f;
158161
m_bJumping = false;
159162

160-
for (int i = 0; i < 5; i++)
161-
field_6C[i] = false;
163+
for (bool& value : m_pressedInputs)
164+
value = false;
162165

163166
const int* activePointers;
164167
int activePointerCount = Multitouch::getActivePointerIds(&activePointers);
@@ -173,7 +176,7 @@ void TouchscreenInput_TestFps::tick(Player* pPlayer)
173176
int pointerId = m_touchAreaModel.getPointerId(x * Gui::InvGuiScale, y * Gui::InvGuiScale, finger);
174177

175178
if (pointerId > 99)
176-
field_6C[pointerId - 100] = true;
179+
m_pressedInputs[pointerId - 100] = true;
177180

178181
if (pointerId == 100 + INPUT_SNEAK) // sneak
179182
{
@@ -261,7 +264,11 @@ void TouchscreenInput_TestFps::tick(Player* pPlayer)
261264
else
262265
{
263266
m_bSneakBeingHeld = false;
267+
if (pPlayer->getAbilities().m_bFlying)
268+
m_bSneaking = false;
264269
}
270+
271+
IMoveInput::tick(pPlayer);
265272
}
266273

267274
static void RenderTouchButton(Tesselator* t, PolygonArea* pArea, int srcX, int srcY)
@@ -324,21 +331,22 @@ void TouchscreenInput_TestFps::render(float f)
324331
t.color(isButtonDown(100 + INPUT_JUMP) ? 0xC0C0C0 : 0xFFFFFF, 0x80);
325332
RenderTouchButton(&t, m_pAreaJump, 0, 176);
326333

327-
/*t.color(isButtonDown(100 + INPUT_SNEAK) ? 0xC0C0C0 : 0xFFFFFF, 0x80);
328-
RenderTouchButton(&t, m_pAreaSneak, 48, 176);*/
334+
t.color(m_bSneaking ? 0xC0C0C0 : 0xFFFFFF, 0x80);
335+
RenderTouchButton(&t, m_pAreaSneak, 48, 176);
329336

330337
t.draw();
331338

332339
glDisable(GL_BLEND);
333340
glEnable(GL_CULL_FACE);
334341
}
335342

336-
RectangleArea TouchscreenInput_TestFps::getRectangleArea()
343+
void TouchscreenInput_TestFps::addRectangleArea(std::vector<RectangleArea>& touchArea)
337344
{
338-
return m_rectArea;
345+
touchArea.push_back(m_rectArea);
346+
touchArea.push_back(m_rightRectArea);
339347
}
340348

341349
bool TouchscreenInput_TestFps::isButtonDown(int key)
342350
{
343-
return field_6C[key - 100];
351+
return m_pressedInputs[key - 100];
344352
}

source/client/player/input/TouchscreenInput_TestFps.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "RectangleArea.hpp"
1414
#include "PolygonArea.hpp"
1515
#include "TouchAreaModel.hpp"
16+
#include <vector>
1617

1718
class Minecraft;
1819
class Options;
@@ -29,11 +30,12 @@ class TouchscreenInput_TestFps : public IMoveInput, public GuiComponent
2930
void tick(Player*) override;
3031
void render(float f) override;
3132

32-
RectangleArea getRectangleArea();
33+
void addRectangleArea(std::vector<RectangleArea>& touchArea);
3334
bool isButtonDown(int key);
3435

3536
private:
3637
RectangleArea m_rectArea;
38+
RectangleArea m_rightRectArea;
3739
bool m_noNeighborUpdate[10];
3840
Options* m_pOptions;
3941
bool field_40;
@@ -49,6 +51,6 @@ class TouchscreenInput_TestFps : public IMoveInput, public GuiComponent
4951
PolygonArea* m_pAreaSneak;
5052
PolygonArea* m_pAreaForwardLeft;
5153
PolygonArea* m_pAreaForwardRight;
52-
bool field_6C[8];
54+
bool m_pressedInputs[8];
5355
};
5456

source/client/player/input/UnifiedTurnBuild.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ UnifiedTurnBuild::UnifiedTurnBuild(int a, int width, int height, float d, float
1616
field_C(a),
1717
field_10(0),
1818
m_screenArea(-1, -1, 0, 0),
19-
field_40(-1, -1, 0, 0),
20-
field_58(-1, -1, 0, 0),
2119
m_pInputHolder(pHolder),
2220
field_78(0.0f),
2321
field_7C(0.0f),
@@ -44,8 +42,10 @@ void UnifiedTurnBuild::setScreenSize(int width, int height)
4442

4543
m_includeExcludeArea.clear();
4644
m_includeExcludeArea.include(&m_screenArea);
47-
m_includeExcludeArea.exclude(&field_40);
48-
m_includeExcludeArea.exclude(&field_58);
45+
for (auto& area : m_touchArea)
46+
{
47+
m_includeExcludeArea.exclude(&area);
48+
}
4949

5050
m_touchAreaModel.clear();
5151
m_touchAreaModel.addArea(100, &m_includeExcludeArea);

source/client/player/input/UnifiedTurnBuild.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ class UnifiedTurnBuild : public ITurnInput, public IBuildInput
4141
SmoothFloat m_smoothFloat;
4242
bool m_bStarted;
4343
RectangleArea m_screenArea;
44-
RectangleArea field_40;
45-
RectangleArea field_58;
44+
std::vector<RectangleArea> m_touchArea;
4645
IInputHolder* m_pInputHolder;
4746
float field_78;
4847
float field_7C;

0 commit comments

Comments
 (0)