Mobile: Add hotbar switching as an on-screen control

This commit is contained in:
UnknownShadow200 2020-12-20 14:45:50 +11:00
parent c18fde0ef0
commit 5801e7888d
10 changed files with 40 additions and 37 deletions

View File

@ -294,7 +294,7 @@ static void DrawName(struct Entity* e) {
if (Entities.NamesMode == NAME_MODE_ALL_UNSCALED && LocalPlayer_Instance.Hacks.CanSeeAllNames) {
Matrix_Mul(&mat, &Gfx.View, &Gfx.Projection); /* TODO: This mul is slow, avoid it */
/* Get W component of transformed position */
scale = pos.X * mat.Row0.W + pos.Y * mat.row2.W + pos.Z * mat.row3.W + mat.row4.W;
scale = pos.X * mat.row1.W + pos.Y * mat.row2.W + pos.Z * mat.row3.W + mat.row4.W;
size.X *= scale * 0.2f; size.Y *= scale * 0.2f;
}

View File

@ -176,5 +176,6 @@ void InputHandler_OnScreensChanged(void);
#define ONSCREEN_BTN_DELETE (1 << 9)
#define ONSCREEN_BTN_PICK (1 << 10)
#define ONSCREEN_BTN_PLACE (1 << 11)
#define ONSCREEN_MAX_BTNS 12
#define ONSCREEN_BTN_SWITCH (1 << 12)
#define ONSCREEN_MAX_BTNS 13
#endif

View File

@ -27,6 +27,11 @@ void Inventory_SetHotbarIndex(int index) {
Event_RaiseVoid(&UserEvents.HeldBlockChanged);
}
void Inventory_SwitchHotbar(void) {
int index = Inventory.Offset == 0 ? 1 : 0;
Inventory_SetHotbarIndex(index);
}
void Inventory_SetSelectedBlock(BlockID block) {
int i;
if (!Inventory_CheckChangeSelected()) return;

View File

@ -44,6 +44,7 @@ cc_bool Inventory_CheckChangeSelected(void);
void Inventory_SetSelectedIndex(int index);
/* Attempts to set the currently active hotbar. */
void Inventory_SetHotbarIndex(int index);
void Inventory_SwitchHotbar(void);
/* Attempts to set the block for the selected index in the current hotbar. */
/* NOTE: If another slot is already this block, the selected index is instead changed. */
void Inventory_SetSelectedBlock(BlockID block);

View File

@ -3708,9 +3708,9 @@ static const struct SimpleButtonDesc touchOnscreen_page1[ONSCREEN_PAGE_BTNS] = {
{ -120, 100, "Speed", TouchOnscreen_Any }, { 120, 100, "Half speed", TouchOnscreen_Any }
};
static const struct SimpleButtonDesc touchOnscreen_page2[ONSCREEN_PAGE_BTNS] = {
{ -120, -50, "3rd person", TouchOnscreen_Any }, { 120, -50, "Delete", TouchOnscreen_Any },
{ -120, -50, "Third person", TouchOnscreen_Any }, { 120, -50, "Delete", TouchOnscreen_Any },
{ -120, 0, "Pick", TouchOnscreen_Any }, { 120, 0, "Place", TouchOnscreen_Any },
{ -120, 50, "---", TouchOnscreen_Any }, { 120, 50, "---", TouchOnscreen_Any },
{ -120, 50, "Switch hotbar", TouchOnscreen_Any }, { 120, 50, "---", TouchOnscreen_Any },
{ -120, 100, "---", TouchOnscreen_Any }, { 120, 100, "---", TouchOnscreen_Any }
};

View File

@ -30,8 +30,8 @@ void Particle_DoRender(const Vec2* size, const Vec3* pos, const TextureRec* rec,
centre = *pos; centre.Y += sY;
view = &Gfx.View;
aX = view->Row0.X * sX; aY = view->row2.X * sX; aZ = view->row3.X * sX; /* right * size.X * 0.5f */
bX = view->Row0.Y * sY; bY = view->row2.Y * sY; bZ = view->row3.Y * sY; /* up * size.Y * 0.5f */
aX = view->row1.X * sX; aY = view->row2.X * sX; aZ = view->row3.X * sX; /* right * size.X * 0.5f */
bX = view->row1.Y * sY; bY = view->row2.Y * sY; bZ = view->row3.Y * sY; /* up * size.Y * 0.5f */
v->X = centre.X - aX - bX; v->Y = centre.Y - aY - bY; v->Z = centre.Z - aZ - bZ; v->Col = col; v->U = rec->U1; v->V = rec->V2; v++;
v->X = centre.X - aX + bX; v->Y = centre.Y - aY + bY; v->Z = centre.Z - aZ + bZ; v->Col = col; v->U = rec->U1; v->V = rec->V1; v++;

View File

@ -1928,7 +1928,7 @@ static struct TouchScreen {
} TouchScreen;
static struct Widget* touch_widgets[ONSCREEN_MAX_BTNS + TOUCH_EXTRA_BTNS + 2] = {
NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL, NULL,
NULL,NULL, (struct Widget*)&TouchScreen.thumbstick, (struct Widget*)&TouchScreen.more
};
#define TOUCH_MAX_VERTICES (THUMBSTICKWIDGET_MAX + TOUCH_MAX_BTNS * BUTTONWIDGET_MAX)
@ -1947,6 +1947,7 @@ static void TouchScreen_FlyClick(void* s, void* w) { LocalPlayer_HandleFly(
static void TouchScreen_NoclipClick(void* s, void* w) { LocalPlayer_HandleNoclip(); }
static void TouchScreen_CameraClick(void* s, void* w) { Camera_CycleActive(); }
static void TouchScreen_MoreClick(void* s, void* w) { TouchMoreScreen_Show(); }
static void TouchScreen_SwitchClick(void* s, void* w) { Inventory_SwitchHotbar(); }
static void TouchScreen_TabClick(void* s, void* w) {
if (TabListOverlay_Instance.active) {
@ -1974,7 +1975,8 @@ static const struct TouchButtonDesc onscreenDescs[ONSCREEN_MAX_BTNS] = {
{ "Camera", 0,0,0, TouchScreen_CameraClick, &LocalPlayer_Instance.Hacks.CanUseThirdPerson },
{ "Delete", KEYBIND_DELETE_BLOCK, 0,0, TouchScreen_OnscreenClick },
{ "Pick", KEYBIND_PICK_BLOCK, 0,0, TouchScreen_OnscreenClick },
{ "Place", KEYBIND_PLACE_BLOCK, 0,0, TouchScreen_OnscreenClick }
{ "Place", KEYBIND_PLACE_BLOCK, 0,0, TouchScreen_OnscreenClick },
{ "Hotbar", 0,0,0, TouchScreen_SwitchClick }
};
static const struct TouchButtonDesc normDescs[1] = {
{ "\x1E", KEYBIND_JUMP, 50, 10, TouchScreen_BindClick }

View File

@ -20,9 +20,9 @@ void Vec3_Normalize(Vec3* result, const Vec3* a) {
void Vec3_Transform(Vec3* result, const Vec3* a, const struct Matrix* mat) {
/* a could be pointing to result - therefore can't directly assign X/Y/Z */
float x = a->X * mat->Row0.X + a->Y * mat->row2.X + a->Z * mat->row3.X + mat->row4.X;
float y = a->X * mat->Row0.Y + a->Y * mat->row2.Y + a->Z * mat->row3.Y + mat->row4.Y;
float z = a->X * mat->Row0.Z + a->Y * mat->row2.Z + a->Z * mat->row3.Z + mat->row4.Z;
float x = a->X * mat->row1.X + a->Y * mat->row2.X + a->Z * mat->row3.X + mat->row4.X;
float y = a->X * mat->row1.Y + a->Y * mat->row2.Y + a->Z * mat->row3.Y + mat->row4.Y;
float z = a->X * mat->row1.Z + a->Y * mat->row2.Z + a->Z * mat->row3.Z + mat->row4.Z;
result->X = x; result->Y = y; result->Z = z;
}
@ -110,7 +110,7 @@ void Matrix_RotateY(struct Matrix* result, float angle) {
float sinA = (float)Math_Sin(angle);
*result = Matrix_Identity;
result->Row0.X = cosA; result->Row0.Z = -sinA;
result->row1.X = cosA; result->row1.Z = -sinA;
result->row3.X = sinA; result->row3.Z = cosA;
}
@ -119,7 +119,7 @@ void Matrix_RotateZ(struct Matrix* result, float angle) {
float sinA = (float)Math_Sin(angle);
*result = Matrix_Identity;
result->Row0.X = cosA; result->Row0.Y = sinA;
result->row1.X = cosA; result->row1.Y = sinA;
result->row2.X = -sinA; result->row2.Y = cosA;
}
@ -130,26 +130,26 @@ void Matrix_Translate(struct Matrix* result, float x, float y, float z) {
void Matrix_Scale(struct Matrix* result, float x, float y, float z) {
*result = Matrix_Identity;
result->Row0.X = x; result->row2.Y = y; result->row3.Z = z;
result->row1.X = x; result->row2.Y = y; result->row3.Z = z;
}
void Matrix_Mul(struct Matrix* result, const struct Matrix* left, const struct Matrix* right) {
/* Originally from http://www.edais.co.uk/blog/?p=27 */
float
lM11 = left->Row0.X, lM12 = left->Row0.Y, lM13 = left->Row0.Z, lM14 = left->Row0.W,
lM11 = left->row1.X, lM12 = left->row1.Y, lM13 = left->row1.Z, lM14 = left->row1.W,
lM21 = left->row2.X, lM22 = left->row2.Y, lM23 = left->row2.Z, lM24 = left->row2.W,
lM31 = left->row3.X, lM32 = left->row3.Y, lM33 = left->row3.Z, lM34 = left->row3.W,
lM41 = left->row4.X, lM42 = left->row4.Y, lM43 = left->row4.Z, lM44 = left->row4.W,
rM11 = right->Row0.X, rM12 = right->Row0.Y, rM13 = right->Row0.Z, rM14 = right->Row0.W,
rM11 = right->row1.X, rM12 = right->row1.Y, rM13 = right->row1.Z, rM14 = right->row1.W,
rM21 = right->row2.X, rM22 = right->row2.Y, rM23 = right->row2.Z, rM24 = right->row2.W,
rM31 = right->row3.X, rM32 = right->row3.Y, rM33 = right->row3.Z, rM34 = right->row3.W,
rM41 = right->row4.X, rM42 = right->row4.Y, rM43 = right->row4.Z, rM44 = right->row4.W;
result->Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
result->Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
result->Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
result->Row0.W = (((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34)) + (lM14 * rM44);
result->row1.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
result->row1.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
result->row1.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
result->row1.W = (((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34)) + (lM14 * rM44);
result->row2.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
result->row2.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
@ -171,7 +171,7 @@ void Matrix_Orthographic(struct Matrix* result, float left, float right, float t
/* Transposed, source https://msdn.microsoft.com/en-us/library/dd373965(v=vs.85).aspx */
*result = Matrix_Identity;
result->Row0.X = 2.0f / (right - left);
result->row1.X = 2.0f / (right - left);
result->row2.Y = 2.0f / (top - bottom);
result->row3.Z = -2.0f / (zFar - zNear);
@ -191,7 +191,7 @@ void Matrix_PerspectiveFieldOfView(struct Matrix* result, float fovy, float aspe
*result = Matrix_Identity;
result->row4.W = 0.0f;
result->Row0.X = zNear / (c * aspect);
result->row1.X = zNear / (c * aspect);
result->row2.Y = zNear / c;
result->row4.Z = -(2.0f * zFar * zNear) / (zFar - zNear);
result->row3.Z = -(zFar + zNear) / (zFar - zNear);

View File

@ -16,7 +16,7 @@ typedef struct IVec3_ { int X, Y, Z; } IVec3;
/* 4 component vector */
struct Vec4 { float X, Y, Z, W; };
/* 4x4 matrix. (for vertex transformations) */
struct Matrix { struct Vec4 Row0, row2, row3, row4; };
struct Matrix { struct Vec4 row1, row2, row3, row4; };
/* Identity matrix. (A * Identity = A) */
extern const struct Matrix Matrix_Identity;

View File

@ -491,8 +491,6 @@ static int HotbarWidget_KeyDown(void* widget, int key) {
static int HotbarWidget_KeyUp(void* widget, int key) {
struct HotbarWidget* w = (struct HotbarWidget*)widget;
int index;
/* Need to handle these cases:
a) user presses alt then number
b) user presses alt
@ -500,12 +498,8 @@ static int HotbarWidget_KeyUp(void* widget, int key) {
if (key != KeyBinds[KEYBIND_HOTBAR_SWITCH]) return false;
if (w->altHandled) { w->altHandled = false; return true; } /* handled already */
/* Don't switch hotbar when alt+tab */
if (!WindowInfo.Focused) return true;
/* Alternate between first and second row */
index = Inventory.Offset == 0 ? 1 : 0;
Inventory_SetHotbarIndex(index);
/* Don't switch hotbar when alt+tabbing to another window */
if (WindowInfo.Focused) Inventory_SwitchHotbar();
return true;
}