Adaptation to be able to play on android
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "../../../gui/Gui.h"
|
||||
#include "../../../renderer/Tesselator.h"
|
||||
#include "../../../../world/entity/player/Player.h"
|
||||
#include "../../../../util/Mth.h"
|
||||
|
||||
#include "../../../Minecraft.h"
|
||||
#include "../../../../platform/log.h"
|
||||
@@ -125,48 +126,80 @@ void TouchscreenInput_TestFps::onConfigChanged(const Config& c) {
|
||||
*/
|
||||
|
||||
// Code for "D-pad with jump in center"
|
||||
float Bw = w * 0.11f;//0.08f;
|
||||
float Bh = Bw;//0.15f;
|
||||
|
||||
// If too large (like playing on Tablet)
|
||||
// Calculate button size so the full 3x3 grid fits on screen with margins
|
||||
const float margin = 12.0f;
|
||||
float availW = w - margin * 2; // horizontal space available
|
||||
float availH = h - margin * 2; // vertical space available
|
||||
// Each button: 3 wide, 3 tall
|
||||
float Bw = availW / 3.0f;
|
||||
float Bh = availH / 3.0f;
|
||||
// Use the smaller of the two to maintain square buttons
|
||||
float btnSize = Mth::Min(Bw, Bh);
|
||||
|
||||
// Scale down to 65% of max available for a more comfortable, non-obtrusive size
|
||||
btnSize *= 0.65f;
|
||||
|
||||
// Clamp to physical millimeters for consistency across DPIs
|
||||
PixelCalc& pc = _minecraft->pixelCalc;
|
||||
if (pc.pixelsToMillimeters(Bw) > 200) { //14
|
||||
Bw = Bh = pc.millimetersToPixels(200); //14
|
||||
}
|
||||
float minBtnPx = pc.millimetersToPixels(35); // minimum touch target
|
||||
float maxBtnPx = pc.millimetersToPixels(90); // maximum
|
||||
if (btnSize < minBtnPx) btnSize = minBtnPx;
|
||||
if (btnSize > maxBtnPx) btnSize = maxBtnPx;
|
||||
|
||||
float Bw2 = btnSize;
|
||||
float Bh2 = btnSize;
|
||||
|
||||
// temp data
|
||||
float xx;
|
||||
float yy;
|
||||
|
||||
const float BaseY = -8 + h - 3.0f * Bh;
|
||||
const float BaseX = _options->getBooleanValue(OPTIONS_IS_LEFT_HANDED)? -8 + w - 3 * Bw
|
||||
: 8 + 0;
|
||||
// Position from top-left (or top-right for left-handed)
|
||||
float dpadTotalW = 3.0f * Bw2;
|
||||
float dpadTotalH = 3.0f * Bh2;
|
||||
|
||||
// Place at top of screen instead of bottom
|
||||
float BaseY = margin;
|
||||
if (BaseY + dpadTotalH > h - margin) BaseY = h - dpadTotalH - margin;
|
||||
|
||||
float BaseX = _options->getBooleanValue(OPTIONS_IS_LEFT_HANDED) ? w - dpadTotalW - margin : margin;
|
||||
if (BaseX < margin) BaseX = margin;
|
||||
if (BaseX + dpadTotalW > w - margin) BaseX = w - dpadTotalW - margin;
|
||||
|
||||
// Setup the bounding rectangle
|
||||
_boundingRectangle = RectangleArea(BaseX, BaseY, BaseX + 3 * Bw, BaseY + 3 * Bh);
|
||||
_boundingRectangle = RectangleArea(BaseX, BaseY, BaseX + dpadTotalW, BaseY + dpadTotalH);
|
||||
|
||||
xx = BaseX + Bw; yy = BaseY;
|
||||
_model.addArea(AREA_DPAD_N, aUp = new RectangleArea(xx, yy, xx+Bw, yy+Bh));
|
||||
xx = BaseX + Bw2; yy = BaseY;
|
||||
_model.addArea(AREA_DPAD_N, aUp = new RectangleArea(xx, yy, xx+Bw2, yy+Bh2));
|
||||
xx = BaseX;
|
||||
aUpLeft = new RectangleArea(xx, yy, xx+Bw, yy+Bh);
|
||||
xx = BaseX + 2 * Bw;
|
||||
aUpRight = new RectangleArea(xx, yy, xx+Bw, yy+Bh);
|
||||
aUpLeft = new RectangleArea(xx, yy, xx+Bw2, yy+Bh2);
|
||||
xx = BaseX + 2 * Bw2;
|
||||
aUpRight = new RectangleArea(xx, yy, xx+Bw2, yy+Bh2);
|
||||
|
||||
xx = BaseX + Bw; yy = BaseY + Bh;
|
||||
_model.addArea(AREA_DPAD_C, aJump = new RectangleArea(xx, yy, xx+Bw, yy+Bh));
|
||||
xx = BaseX + Bw2; yy = BaseY + Bh2;
|
||||
_model.addArea(AREA_DPAD_C, aJump = new RectangleArea(xx, yy, xx+Bw2, yy+Bh2));
|
||||
|
||||
xx = BaseX + Bw; yy = BaseY + 2 * Bh;
|
||||
_model.addArea(AREA_DPAD_S, aDown = new RectangleArea(xx, yy, xx+Bw, yy+Bh));
|
||||
xx = BaseX + Bw2; yy = BaseY + 2 * Bh2;
|
||||
_model.addArea(AREA_DPAD_S, aDown = new RectangleArea(xx, yy, xx+Bw2, yy+Bh2));
|
||||
|
||||
xx = BaseX; yy = BaseY + Bh;
|
||||
_model.addArea(AREA_DPAD_W, aLeft = new RectangleArea(xx, yy, xx+Bw, yy+Bh));
|
||||
xx = BaseX; yy = BaseY + Bh2;
|
||||
_model.addArea(AREA_DPAD_W, aLeft = new RectangleArea(xx, yy, xx+Bw2, yy+Bh2));
|
||||
|
||||
xx = BaseX + 2 * Bw; yy = BaseY + Bh;
|
||||
_model.addArea(AREA_DPAD_E, aRight = new RectangleArea(xx, yy, xx+Bw, yy+Bh));
|
||||
xx = BaseX + 2 * Bw2; yy = BaseY + Bh2;
|
||||
_model.addArea(AREA_DPAD_E, aRight = new RectangleArea(xx, yy, xx+Bw2, yy+Bh2));
|
||||
|
||||
float maxPixels = _minecraft->pixelCalc.millimetersToPixels(10);
|
||||
// float btnSize = Mth::Min(18 * Gui::GuiScale, maxPixels);
|
||||
float btnSize = pc.millimetersToPixels(18 * Gui::GuiScale);
|
||||
_model.addArea(AREA_PAUSE, aPause = new RectangleArea(w - 4 - btnSize, 4, w - 4, 4 + btnSize));
|
||||
_model.addArea(AREA_CHAT, aChat = new RectangleArea(w - 8 - btnSize * 2, 4, w - 8 - btnSize, 4 + btnSize));
|
||||
// Pause and chat buttons - sized relative to D-pad buttons, with bounds checking
|
||||
float actionBtnSize = Bw2 * 0.7f;
|
||||
float actionBtnMargin = 8.0f;
|
||||
// Clamp action button size
|
||||
if (actionBtnSize < pc.millimetersToPixels(30)) actionBtnSize = pc.millimetersToPixels(30);
|
||||
if (actionBtnSize > pc.millimetersToPixels(120)) actionBtnSize = pc.millimetersToPixels(120);
|
||||
|
||||
_model.addArea(AREA_PAUSE, aPause = new RectangleArea(
|
||||
w - actionBtnMargin - actionBtnSize, actionBtnMargin,
|
||||
w - actionBtnMargin, actionBtnMargin + actionBtnSize));
|
||||
_model.addArea(AREA_CHAT, aChat = new RectangleArea(
|
||||
w - actionBtnMargin * 2 - actionBtnSize * 2, actionBtnMargin,
|
||||
w - actionBtnMargin * 2 - actionBtnSize, actionBtnMargin + actionBtnSize));
|
||||
|
||||
//rebuild();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user