mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 17:17:09 -04:00
Mobile: Now touch controls scale partially works
This commit is contained in:
parent
edae243721
commit
14de95774d
@ -3934,7 +3934,6 @@ static void TouchCtrlsScreen_Init(void* screen) {
|
||||
Menu_InitButtons(s->btns, 195, touchCtrls_btns, 4);
|
||||
Menu_InitButtons(s->btns + 4, 400, touchCtrls_btns + 4, 1);
|
||||
Menu_InitBack(&s->back, TouchCtrls_More);
|
||||
s->btns[3].disabled = true;
|
||||
}
|
||||
|
||||
static const struct ScreenVTABLE TouchCtrlsScreen_VTABLE = {
|
||||
|
@ -229,6 +229,7 @@ static void HUDScreen_Layout(void* screen) {
|
||||
line2->yOffset = posY + s->posAtlas.tex.Height;
|
||||
}
|
||||
|
||||
s->hotbar.scale = Gui_GetHotbarScale();
|
||||
Widget_Layout(&s->hotbar);
|
||||
Widget_Layout(line2);
|
||||
}
|
||||
@ -1396,6 +1397,7 @@ static void InventoryScreen_Render(void* screen, double delta) {
|
||||
|
||||
static void InventoryScreen_Layout(void* screen) {
|
||||
struct InventoryScreen* s = (struct InventoryScreen*)screen;
|
||||
s->table.scale = Gui_GetInventoryScale();
|
||||
Widget_Layout(&s->table);
|
||||
}
|
||||
|
||||
@ -1905,10 +1907,11 @@ void DisconnectScreen_Show(const cc_string* title, const cc_string* message) {
|
||||
*--------------------------------------------------------TouchScreen------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
#define TOUCH_MAX_BTNS (ONSCREEN_MAX_BTNS + 3)
|
||||
#define TOUCH_EXTRA_BTNS 2
|
||||
#define TOUCH_MAX_BTNS (ONSCREEN_MAX_BTNS + TOUCH_EXTRA_BTNS + 1)
|
||||
struct TouchButtonDesc {
|
||||
const char* text;
|
||||
cc_uint8 bind, x, y, size;
|
||||
cc_uint8 bind, x, y;
|
||||
Widget_LeftClick OnClick;
|
||||
cc_bool* enabled;
|
||||
};
|
||||
@ -1921,13 +1924,12 @@ static struct TouchScreen {
|
||||
struct ThumbstickWidget thumbstick;
|
||||
const struct TouchButtonDesc* onscreenDescs[ONSCREEN_MAX_BTNS];
|
||||
struct ButtonWidget onscreen[ONSCREEN_MAX_BTNS];
|
||||
struct ButtonWidget btns[3];
|
||||
struct ButtonWidget btns[TOUCH_EXTRA_BTNS], more;
|
||||
} TouchScreen;
|
||||
|
||||
static struct Widget* touch_widgets[1 + TOUCH_MAX_BTNS] = {
|
||||
NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,
|
||||
NULL,
|
||||
NULL,NULL,NULL, (struct Widget*)&TouchScreen.thumbstick
|
||||
static struct Widget* touch_widgets[ONSCREEN_MAX_BTNS + TOUCH_EXTRA_BTNS + 2] = {
|
||||
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)
|
||||
|
||||
@ -1961,31 +1963,30 @@ static void TouchScreen_BindClick(void* screen, void* widget) {
|
||||
}
|
||||
|
||||
static const struct TouchButtonDesc onscreenDescs[ONSCREEN_MAX_BTNS] = {
|
||||
{ "Chat", 0,0,0,0, TouchScreen_ChatClick },
|
||||
{ "Tablist", 0,0,0,0, TouchScreen_TabClick },
|
||||
{ "Respawn", 0,0,0,0, TouchScreen_RespawnClick, &LocalPlayer_Instance.Hacks.CanRespawn },
|
||||
{ "Set spawn", 0,0,0,0, TouchScreen_SetSpawnClick, &LocalPlayer_Instance.Hacks.CanRespawn },
|
||||
{ "Fly", 0,0,0,0, TouchScreen_FlyClick, &LocalPlayer_Instance.Hacks.CanFly },
|
||||
{ "Noclip", 0,0,0,0, TouchScreen_NoclipClick, &LocalPlayer_Instance.Hacks.CanNoclip },
|
||||
{ "Speed", KEYBIND_SPEED, 0,0,0, TouchScreen_OnscreenClick, &LocalPlayer_Instance.Hacks.CanSpeed },
|
||||
{ "\xabSpeed", KEYBIND_HALF_SPEED, 0,0,0, TouchScreen_OnscreenClick, &LocalPlayer_Instance.Hacks.CanSpeed },
|
||||
{ "Camera", 0,0,0,0, TouchScreen_CameraClick, &LocalPlayer_Instance.Hacks.CanUseThirdPerson }
|
||||
{ "Chat", 0,0,0, TouchScreen_ChatClick },
|
||||
{ "Tablist", 0,0,0, TouchScreen_TabClick },
|
||||
{ "Respawn", 0,0,0, TouchScreen_RespawnClick, &LocalPlayer_Instance.Hacks.CanRespawn },
|
||||
{ "Set spawn", 0,0,0, TouchScreen_SetSpawnClick, &LocalPlayer_Instance.Hacks.CanRespawn },
|
||||
{ "Fly", 0,0,0, TouchScreen_FlyClick, &LocalPlayer_Instance.Hacks.CanFly },
|
||||
{ "Noclip", 0,0,0, TouchScreen_NoclipClick, &LocalPlayer_Instance.Hacks.CanNoclip },
|
||||
{ "Speed", KEYBIND_SPEED, 0,0, TouchScreen_OnscreenClick, &LocalPlayer_Instance.Hacks.CanSpeed },
|
||||
{ "\xabSpeed", KEYBIND_HALF_SPEED, 0,0, TouchScreen_OnscreenClick, &LocalPlayer_Instance.Hacks.CanSpeed },
|
||||
{ "Camera", 0,0,0, TouchScreen_CameraClick, &LocalPlayer_Instance.Hacks.CanUseThirdPerson }
|
||||
};
|
||||
static const struct TouchButtonDesc normDescs[2] = {
|
||||
{ "...", KEYBIND_COUNT, 0, 0, 40, TouchScreen_MoreClick },
|
||||
{ "\x1E", KEYBIND_JUMP, 50, 10, 60, TouchScreen_BindClick }
|
||||
static const struct TouchButtonDesc normDescs[1] = {
|
||||
{ "\x1E", KEYBIND_JUMP, 50, 10, TouchScreen_BindClick }
|
||||
};
|
||||
static const struct TouchButtonDesc hackDescs[3] = {
|
||||
{ "...", KEYBIND_COUNT, 0, 0, 40, TouchScreen_MoreClick },
|
||||
{ "\x1E", KEYBIND_FLY_UP, 50, 70, 60, TouchScreen_BindClick },
|
||||
{ "\x1F", KEYBIND_FLY_DOWN, 50, 10, 60, TouchScreen_BindClick }
|
||||
static const struct TouchButtonDesc hackDescs[2] = {
|
||||
{ "\x1E", KEYBIND_FLY_UP, 50, 70, TouchScreen_BindClick },
|
||||
{ "\x1F", KEYBIND_FLY_DOWN, 50, 10, TouchScreen_BindClick }
|
||||
};
|
||||
|
||||
#define TOUCHSCREEN_BTN_COL PackedCol_Make(255, 255, 255, 220)
|
||||
static void TouchScreen_InitButtons(struct TouchScreen* s) {
|
||||
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
|
||||
const struct TouchButtonDesc* desc;
|
||||
int i, j;
|
||||
for (i = 0; i < TOUCH_MAX_BTNS; i++) s->widgets[i] = NULL;
|
||||
for (i = 0; i < ONSCREEN_MAX_BTNS + TOUCH_EXTRA_BTNS; i++) s->widgets[i] = NULL;
|
||||
|
||||
for (i = 0, j = 0; i < ONSCREEN_MAX_BTNS; i++) {
|
||||
if (!(Gui._onscreenButtons & (1 << i))) continue;
|
||||
@ -2009,11 +2010,8 @@ static void TouchScreen_InitButtons(struct TouchScreen* s) {
|
||||
|
||||
for (i = 0; i < s->numBtns; i++) {
|
||||
s->widgets[i + ONSCREEN_MAX_BTNS] = (struct Widget*)&s->btns[i];
|
||||
desc = &s->descs[i];
|
||||
ButtonWidget_Init(&s->btns[i], desc->size, desc->OnClick);
|
||||
|
||||
s->btns[i].minHeight = Display_ScaleY(desc->size);
|
||||
s->btns[i].col = PackedCol_Make(255, 255, 255, 220);
|
||||
ButtonWidget_Init(&s->btns[i], 60, s->descs[i].OnClick);
|
||||
s->btns[i].col = TOUCHSCREEN_BTN_COL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2048,6 +2046,7 @@ static void TouchScreen_ContextRecreated(void* screen) {
|
||||
desc = &s->descs[i];
|
||||
ButtonWidget_SetConst(&s->btns[i], desc->text, &s->font);
|
||||
}
|
||||
ButtonWidget_SetConst(&s->more, "...", &s->font);
|
||||
}
|
||||
|
||||
static void TouchScreen_Render(void* screen, double delta) {
|
||||
@ -2074,6 +2073,7 @@ static int TouchScreen_PointerUp(void* screen, int id, int x, int y) {
|
||||
int i;
|
||||
//Chat_Add1("POINTER UP: %i", &id);
|
||||
s->thumbstick.active &= ~id;
|
||||
s->more.active &= ~id;
|
||||
|
||||
for (i = 0; i < s->numBtns; i++) {
|
||||
if (!(s->btns[i].active & id)) continue;
|
||||
@ -2090,26 +2090,32 @@ static int TouchScreen_PointerUp(void* screen, int id, int x, int y) {
|
||||
static void TouchScreen_Layout(void* screen) {
|
||||
struct TouchScreen* s = (struct TouchScreen*)screen;
|
||||
const struct TouchButtonDesc* desc;
|
||||
float scale = Gui.RawTouchScale;
|
||||
int i, height;
|
||||
|
||||
for (i = 0; i < s->numOnscreen; i++) {
|
||||
Widget_SetLocation(&s->onscreen[i], ANCHOR_MAX, ANCHOR_MIN, 10, 10 + i * 40);
|
||||
}
|
||||
Widget_SetLocation(&s->btns[0], ANCHOR_CENTRE, ANCHOR_MIN, 0, 10);
|
||||
Widget_SetLocation(&s->more, ANCHOR_CENTRE, ANCHOR_MIN, 0, 10);
|
||||
|
||||
/* Need to align these relative to the hotbar */
|
||||
HUDScreen_Layout(Gui_HUD);
|
||||
height = Gui_HUD->hotbar.height;
|
||||
|
||||
for (i = 1; i < s->numBtns; i++) {
|
||||
for (i = 0; i < s->numBtns; i++) {
|
||||
desc = &s->descs[i];
|
||||
Widget_SetLocation(&s->btns[i], ANCHOR_MAX, ANCHOR_MAX, desc->x, desc->y);
|
||||
s->btns[i].yOffset += height;
|
||||
|
||||
/* TODO: Maybe move scaling to be part of button instead */
|
||||
s->btns[i].minWidth = Display_ScaleX(60 * scale);
|
||||
s->btns[i].minHeight = Display_ScaleY(60 * scale);
|
||||
Widget_Layout(&s->btns[i]);
|
||||
}
|
||||
|
||||
Widget_SetLocation(&s->thumbstick, ANCHOR_MIN, ANCHOR_MAX, 30, 5);
|
||||
s->thumbstick.yOffset += height;
|
||||
s->thumbstick.scale = scale;
|
||||
Widget_Layout(&s->thumbstick);
|
||||
}
|
||||
|
||||
@ -2128,6 +2134,9 @@ static void TouchScreen_Init(void* screen) {
|
||||
Event_Register_(&UserEvents.HackPermsChanged, screen, TouchScreen_HacksChanged);
|
||||
|
||||
TouchScreen_InitButtons(s);
|
||||
ButtonWidget_Init(&s->more, 40, TouchScreen_MoreClick);
|
||||
s->more.col = TOUCHSCREEN_BTN_COL;
|
||||
|
||||
ThumbstickWidget_Init(&s->thumbstick);
|
||||
touchInput.GetMovement = TouchScreen_GetMovement;
|
||||
LocalPlayer_Instance.input.next = &touchInput;
|
||||
|
@ -108,8 +108,10 @@ static void ButtonWidget_Free(void* widget) {
|
||||
|
||||
static void ButtonWidget_Reposition(void* widget) {
|
||||
struct ButtonWidget* w = (struct ButtonWidget*)widget;
|
||||
w->width = max(w->tex.Width, w->minWidth);
|
||||
w->height = max(w->tex.Height, w->minHeight);
|
||||
|
||||
Widget_CalcPosition(w);
|
||||
|
||||
w->tex.X = w->x + (w->width / 2 - w->tex.Width / 2);
|
||||
w->tex.Y = w->y + (w->height / 2 - w->tex.Height / 2);
|
||||
}
|
||||
@ -236,9 +238,6 @@ void ButtonWidget_Set(struct ButtonWidget* w, const cc_string* text, struct Font
|
||||
DrawTextArgs_Make(&args, text, font, true);
|
||||
Drawer2D_MakeTextTexture(&w->tex, &args);
|
||||
}
|
||||
|
||||
w->width = max(w->tex.Width, w->minWidth);
|
||||
w->height = max(w->tex.Height, w->minHeight);
|
||||
Widget_Layout(w);
|
||||
}
|
||||
|
||||
@ -440,9 +439,8 @@ static int HotbarWidget_ScrolledIndex(struct HotbarWidget* w, float delta, int i
|
||||
|
||||
static void HotbarWidget_Reposition(void* widget) {
|
||||
struct HotbarWidget* w = (struct HotbarWidget*)widget;
|
||||
float scale = Gui_GetHotbarScale();
|
||||
float scaleX = scale * DisplayInfo.ScaleX;
|
||||
float scaleY = scale * DisplayInfo.ScaleY;
|
||||
float scaleX = w->scale * DisplayInfo.ScaleX;
|
||||
float scaleY = w->scale * DisplayInfo.ScaleY;
|
||||
int y;
|
||||
|
||||
w->width = (int)(182 * scaleX);
|
||||
@ -571,6 +569,7 @@ void HotbarWidget_Create(struct HotbarWidget* w) {
|
||||
w->VTABLE = &HotbarWidget_VTABLE;
|
||||
w->horAnchor = ANCHOR_CENTRE;
|
||||
w->verAnchor = ANCHOR_MAX;
|
||||
w->scale = 1;
|
||||
}
|
||||
|
||||
void HotbarWidget_SetFont(struct HotbarWidget* w, struct FontDesc* font) {
|
||||
@ -769,7 +768,7 @@ void TableWidget_Recreate(struct TableWidget* w) {
|
||||
|
||||
static void TableWidget_Reposition(void* widget) {
|
||||
struct TableWidget* w = (struct TableWidget*)widget;
|
||||
float scale = Gui_GetInventoryScale();
|
||||
float scale = w->scale;
|
||||
int cellSize;
|
||||
|
||||
cellSize = (int)(50 * Math_SqrtF(scale));
|
||||
@ -914,6 +913,7 @@ void TableWidget_Create(struct TableWidget* w) {
|
||||
w->horAnchor = ANCHOR_CENTRE;
|
||||
w->verAnchor = ANCHOR_CENTRE;
|
||||
w->lastX = -20; w->lastY = -20;
|
||||
w->scale = 1;
|
||||
|
||||
w->paddingX = Display_ScaleX(15);
|
||||
w->paddingTopY = Display_ScaleY(15 + 20);
|
||||
@ -2590,8 +2590,15 @@ static int ThumbstickWidget_Render2(void* widget, int offset) {
|
||||
return offset + THUMBSTICKWIDGET_MAX;
|
||||
}
|
||||
|
||||
static void ThumbstickWidget_Reposition(void* widget) {
|
||||
struct ThumbstickWidget* w = (struct ThumbstickWidget*)widget;
|
||||
w->width = Display_ScaleX(128 * w->scale);
|
||||
w->height = Display_ScaleY(128 * w->scale);
|
||||
Widget_CalcPosition(w);
|
||||
}
|
||||
|
||||
static const struct WidgetVTABLE ThumbstickWidget_VTABLE = {
|
||||
NULL, Screen_NullFunc, Widget_CalcPosition,
|
||||
NULL, Screen_NullFunc, ThumbstickWidget_Reposition,
|
||||
Widget_Key, Widget_Key, Widget_MouseScroll,
|
||||
Widget_Pointer, Widget_Pointer, Widget_PointerMove,
|
||||
ThumbstickWidget_BuildMesh, ThumbstickWidget_Render2
|
||||
@ -2599,8 +2606,7 @@ static const struct WidgetVTABLE ThumbstickWidget_VTABLE = {
|
||||
void ThumbstickWidget_Init(struct ThumbstickWidget* w) {
|
||||
Widget_Reset(w);
|
||||
w->VTABLE = &ThumbstickWidget_VTABLE;
|
||||
w->width = Display_ScaleX(128);
|
||||
w->height = Display_ScaleY(128);
|
||||
w->scale = 1;
|
||||
}
|
||||
|
||||
void ThumbstickWidget_GetMovement(struct ThumbstickWidget* w, float* xMoving, float* zMoving) {
|
||||
|
@ -68,7 +68,7 @@ struct HotbarWidget {
|
||||
struct Texture selTex, backTex;
|
||||
float slotWidth, selWidth;
|
||||
float slotXOffset, elemSize;
|
||||
float scrollAcc;
|
||||
float scrollAcc, scale;
|
||||
cc_bool altHandled;
|
||||
struct Texture ellipsisTex;
|
||||
};
|
||||
@ -87,6 +87,7 @@ struct TableWidget {
|
||||
float selBlockExpand;
|
||||
GfxResourceID vb;
|
||||
cc_bool pendingClose;
|
||||
float scale;
|
||||
|
||||
BlockID blocks[BLOCK_COUNT];
|
||||
struct ScrollbarWidget scroll;
|
||||
@ -284,7 +285,7 @@ CC_NOINLINE void SpecialInputWidget_UpdateCols(struct SpecialInputWidget* w);
|
||||
CC_NOINLINE void SpecialInputWidget_SetActive(struct SpecialInputWidget* w, cc_bool active);
|
||||
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
struct ThumbstickWidget { Widget_Body };
|
||||
struct ThumbstickWidget { Widget_Body; float scale; };
|
||||
#define THUMBSTICKWIDGET_PER (4 * 4)
|
||||
#define THUMBSTICKWIDGET_MAX (THUMBSTICKWIDGET_PER * 2)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user