mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -04:00
Initial commit
This commit is contained in:
parent
002d9497cb
commit
c784280e81
@ -256,6 +256,18 @@ static int HUDscreen_PointerDown(void* screen, int id, int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void HUDScreen_PointerUp(void *screen, int id, int x, int y) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
if(!Input_TouchMode) return;
|
||||
Elem_OnPointerUp(&s->hotbar, id, x, y);
|
||||
}
|
||||
|
||||
static int HUDScreen_PointerMove(void *screen, int id, int x, int y) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
if(!Input_TouchMode) return false;
|
||||
return Elem_HandlesPointerMove(&s->hotbar, id, x, y);
|
||||
}
|
||||
|
||||
static int HUDscreen_MouseScroll(void* screen, float delta) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
/* The default scrolling behaviour (e.g. camera, zoom) needs to be checked */
|
||||
@ -307,7 +319,7 @@ static const struct ScreenVTABLE HUDScreen_VTABLE = {
|
||||
HUDScreen_Init, HUDScreen_Update, HUDScreen_Free,
|
||||
HUDScreen_Render, HUDScreen_BuildMesh,
|
||||
HUDScreen_KeyDown, HUDScreen_InputUp, Screen_FKeyPress, Screen_FText,
|
||||
HUDscreen_PointerDown, Screen_PointerUp, Screen_FPointer, HUDscreen_MouseScroll,
|
||||
HUDscreen_PointerDown, HUDScreen_PointerUp, HUDScreen_PointerMove, HUDscreen_MouseScroll,
|
||||
HUDScreen_Layout, HUDScreen_ContextLost, HUDScreen_ContextRecreated
|
||||
};
|
||||
void HUDScreen_Show(void) {
|
||||
|
@ -470,6 +470,17 @@ static void HotbarWidget_Render(void* widget, double delta) {
|
||||
w->ellipsisTex.X = HotbarWidget_TileX(w, HOTBAR_MAX_INDEX) - w->ellipsisTex.Width / 2;
|
||||
w->ellipsisTex.Y = w->y + (w->height / 2) - w->ellipsisTex.Height / 2;
|
||||
Texture_Render(&w->ellipsisTex);
|
||||
int i;
|
||||
for (i = 0; i < HOTBAR_MAX_INDEX; i++) {
|
||||
if(w->touchId[i] != -1) {
|
||||
w->touchTime[i] += delta;
|
||||
if(w->touchTime[i] > 1) {
|
||||
w->touchId[i] = -1;
|
||||
w->touchTime[i] = 0;
|
||||
Inventory_Set(i, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -517,8 +528,13 @@ static int HotbarWidget_PointerDown(void* widget, int id, int x, int y) {
|
||||
if (!Gui_Contains(cellX, cellY, width, height, x, y)) continue;
|
||||
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
if (i == HOTBAR_MAX_INDEX && Input_TouchMode) {
|
||||
InventoryScreen_Show(); return TOUCH_TYPE_GUI;
|
||||
if(Input_TouchMode) {
|
||||
if (i == HOTBAR_MAX_INDEX) {
|
||||
InventoryScreen_Show(); return TOUCH_TYPE_GUI;
|
||||
} else {
|
||||
w->touchId[i] = id;
|
||||
w->touchTime[i] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Inventory_SetSelectedIndex(i);
|
||||
@ -527,6 +543,38 @@ static int HotbarWidget_PointerDown(void* widget, int id, int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void HotbarWidget_PointerUp(void* widget, int id, int x, int y) {
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
struct HotbarWidget* w = (struct HotbarWidget*)widget;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < HOTBAR_MAX_INDEX; i++) {
|
||||
if (w->touchId[i] == id) {
|
||||
w->touchId[i] = -1;
|
||||
w->touchTime[i] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int HotbarWidget_PointerMove(void* widget, int id, int x, int y) {
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
struct HotbarWidget* w = (struct HotbarWidget*)widget;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < HOTBAR_MAX_INDEX; i++) {
|
||||
if (w->touchId[i] == id) {
|
||||
if (!Widget_Contains(w, x, y)) {
|
||||
w->touchId[i] = -1;
|
||||
w->touchTime[i] = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
static int HotbarWidget_MouseScroll(void* widget, float delta) {
|
||||
struct HotbarWidget* w = (struct HotbarWidget*)widget;
|
||||
int index;
|
||||
@ -553,9 +601,9 @@ static void HotbarWidget_Free(void* widget) {
|
||||
}
|
||||
|
||||
static const struct WidgetVTABLE HotbarWidget_VTABLE = {
|
||||
HotbarWidget_Render, HotbarWidget_Free, HotbarWidget_Reposition,
|
||||
HotbarWidget_KeyDown, HotbarWidget_InputUp, HotbarWidget_MouseScroll,
|
||||
HotbarWidget_PointerDown, Widget_PointerUp, Widget_PointerMove
|
||||
HotbarWidget_Render, HotbarWidget_Free, HotbarWidget_Reposition,
|
||||
HotbarWidget_KeyDown, HotbarWidget_InputUp, HotbarWidget_MouseScroll,
|
||||
HotbarWidget_PointerDown, HotbarWidget_PointerUp, HotbarWidget_PointerMove
|
||||
};
|
||||
void HotbarWidget_Create(struct HotbarWidget* w) {
|
||||
Widget_Reset(w);
|
||||
@ -563,6 +611,12 @@ void HotbarWidget_Create(struct HotbarWidget* w) {
|
||||
w->horAnchor = ANCHOR_CENTRE;
|
||||
w->verAnchor = ANCHOR_MAX;
|
||||
w->scale = 1;
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
int i;
|
||||
for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR - 1; i++) {
|
||||
w->touchId[i] = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void HotbarWidget_SetFont(struct HotbarWidget* w, struct FontDesc* font) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "BlockID.h"
|
||||
#include "Constants.h"
|
||||
#include "Entity.h"
|
||||
#include "Inventory.h"
|
||||
/* Contains all 2D widget implementations.
|
||||
Copyright 2014-2021 ClassiCube | Licensed under BSD-3
|
||||
*/
|
||||
@ -71,6 +72,10 @@ struct HotbarWidget {
|
||||
float scrollAcc, scale;
|
||||
cc_bool altHandled;
|
||||
struct Texture ellipsisTex;
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
int touchId[HOTBAR_MAX_INDEX];
|
||||
double touchTime[HOTBAR_MAX_INDEX];
|
||||
#endif
|
||||
};
|
||||
/* Resets state of the given hotbar widget to default. */
|
||||
CC_NOINLINE void HotbarWidget_Create(struct HotbarWidget* w);
|
||||
|
Loading…
x
Reference in New Issue
Block a user