mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 17:47:12 -04:00
Merge pull request #618 from UnknownShadow200/GUIRE5
Improvements to hotbar on mobile
This commit is contained in:
commit
31b22f2e37
@ -137,9 +137,9 @@ enum GuiPriority {
|
||||
GUI_PRIORITY_TEXIDS = 30,
|
||||
GUI_PRIORITY_TOUCH = 25,
|
||||
GUI_PRIORITY_INVENTORY = 20,
|
||||
GUI_PRIORITY_STATUS = 15,
|
||||
GUI_PRIORITY_CHAT = 15,
|
||||
GUI_PRIORITY_HUD = 10,
|
||||
GUI_PRIORITY_LOADING = 5,
|
||||
GUI_PRIORITY_LOADING = 5
|
||||
};
|
||||
|
||||
struct HUDScreen;
|
||||
|
@ -952,7 +952,7 @@ static void HandleMouseWheel(void* obj, float delta) {
|
||||
if (!hotbar && Camera.Active->Zoom(delta)) return;
|
||||
if (InputHandler_DoFovZoom(delta) || !Inventory.CanChangeSelected) return;
|
||||
|
||||
widget = ChatScreen_GetHotbar();
|
||||
widget = HUDScreen_GetHotbar();
|
||||
Elem_HandlesMouseScroll(widget, delta);
|
||||
((struct Screen*)Gui_Chat)->dirty = true;
|
||||
}
|
||||
|
@ -59,11 +59,12 @@ const cc_result ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK;
|
||||
#include <sys/time.h>
|
||||
#include <utime.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define Platform_DecodeString(dst, src, len) String_AppendUtf8(dst, (cc_uint8*)(src), len)
|
||||
#define Socket__Error() errno
|
||||
|
||||
static const char *Platform_DefaultDirectory = NULL;
|
||||
static char* defaultDirectory;
|
||||
const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */
|
||||
const cc_result ReturnCode_FileNotFound = ENOENT;
|
||||
const cc_result ReturnCode_SocketInProgess = EINPROGRESS;
|
||||
@ -1151,9 +1152,8 @@ cc_result Process_StartGame(const String* args) {
|
||||
raw[i] = '\0';
|
||||
argv[j++] = &raw[i + 1];
|
||||
}
|
||||
if (Platform_DefaultDirectory) {
|
||||
argv[j++] = Platform_DefaultDirectory;
|
||||
}
|
||||
|
||||
if (defaultDirectory) { argv[j++] = defaultDirectory; }
|
||||
argv[j] = NULL;
|
||||
return Process_RawStart(path, argv);
|
||||
}
|
||||
@ -1787,7 +1787,7 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, String* args)
|
||||
|
||||
count = min(argc, GAME_MAX_CMDARGS);
|
||||
for (i = 0; i < count; i++) {
|
||||
if (strlen(argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] == 'd') {
|
||||
if (argv[i][0] == '-' && argv[i][1] == 'd' && argv[i][2]) {
|
||||
--count;
|
||||
continue;
|
||||
}
|
||||
@ -1803,14 +1803,14 @@ cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
|
||||
cc_result res;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (strlen(argv[i]) > 2 && argv[i][0] == '-' && argv[i][1] == 'd') {
|
||||
Platform_DefaultDirectory = argv[i];
|
||||
if (argv[i][0] == '-' && argv[i][1] == 'd' && argv[i][2]) {
|
||||
defaultDirectory = argv[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Platform_DefaultDirectory) {
|
||||
return chdir(Platform_DefaultDirectory + 2) == -1 ? errno : 0;
|
||||
if (defaultDirectory) {
|
||||
return chdir(defaultDirectory + 2) == -1 ? errno : 0;
|
||||
}
|
||||
|
||||
res = Process_RawGetExePath(path, &len);
|
||||
|
121
src/Screens.c
121
src/Screens.c
@ -124,6 +124,7 @@ static struct HUDScreen {
|
||||
int frames, fps;
|
||||
cc_bool speed, halfSpeed, noclip, fly, canSpeed;
|
||||
int lastFov;
|
||||
struct HotbarWidget hotbar;
|
||||
} HUDScreen_Instance;
|
||||
|
||||
static void HUDScreen_MakeText(struct HUDScreen* s, String* status) {
|
||||
@ -239,6 +240,8 @@ static void HUDScreen_ContextRecreated(void* screen) {
|
||||
struct TextWidget* line1 = &s->line1;
|
||||
struct TextWidget* line2 = &s->line2;
|
||||
int y;
|
||||
|
||||
Widget_Layout(&s->hotbar);
|
||||
Drawer2D_MakeFont(&s->font, 16, FONT_STYLE_NORMAL);
|
||||
Font_ReducePadding(&s->font, 4);
|
||||
|
||||
@ -270,6 +273,38 @@ static void HUDScreen_ContextRecreated(void* screen) {
|
||||
|
||||
static void HUDScreen_BuildMesh(void* screen) { }
|
||||
|
||||
static void HUDScreen_Layout(void* screen) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
Widget_Layout(&s->hotbar);
|
||||
}
|
||||
|
||||
static int HUDScreen_KeyDown(void* screen, int key) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
return Elem_HandlesKeyDown(&s->hotbar, key);
|
||||
}
|
||||
|
||||
static int HUDScreen_KeyUp(void* screen, int key) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
return Elem_HandlesKeyUp(&s->hotbar, key);
|
||||
}
|
||||
|
||||
static int HUDscreen_PointerDown(void* screen, int id, int x, int y) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
if (Input_TouchMode || Gui_GetInputGrab()) {
|
||||
return Elem_HandlesPointerDown(&s->hotbar, id, x, y);
|
||||
}
|
||||
#else
|
||||
if (Gui_GetInputGrab()) return Elem_HandlesPointerDown(&s->hotbar, id, x, y);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
static void HUDScreen_Init(void* screen) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
HotbarWidget_Create(&s->hotbar);
|
||||
}
|
||||
|
||||
static void HUDScreen_Render(void* screen, double delta) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
HUDScreen_Update(s, delta);
|
||||
@ -286,21 +321,27 @@ static void HUDScreen_Render(void* screen, double delta) {
|
||||
HUDScreen_DrawPosition(s);
|
||||
Elem_Render(&s->line2, delta);
|
||||
}
|
||||
|
||||
if (!Gui_GetBlocksWorld()) Elem_Render(&s->hotbar, delta);
|
||||
Gfx_SetTexturing(false);
|
||||
}
|
||||
|
||||
static const struct ScreenVTABLE HUDScreen_VTABLE = {
|
||||
Screen_NullFunc, Screen_NullUpdate, Screen_NullFunc,
|
||||
HUDScreen_Init, Screen_NullUpdate, Screen_NullFunc,
|
||||
HUDScreen_Render, HUDScreen_BuildMesh,
|
||||
Screen_FInput, Screen_FInput, Screen_FKeyPress, Screen_FText,
|
||||
Screen_FPointer, Screen_FPointer, Screen_FPointer, Screen_FMouseScroll,
|
||||
HUDScreen_KeyDown, HUDScreen_KeyUp, Screen_FKeyPress, Screen_FText,
|
||||
HUDscreen_PointerDown, Screen_FPointer, Screen_FPointer, Screen_FMouseScroll,
|
||||
Screen_NullFunc, HUDScreen_ContextLost, HUDScreen_ContextRecreated
|
||||
};
|
||||
void HUDScreen_Show(void) {
|
||||
struct HUDScreen* s = &HUDScreen_Instance;
|
||||
s->VTABLE = &HUDScreen_VTABLE;
|
||||
Gui_HUD = s;
|
||||
Gui_Replace((struct Screen*)s, GUI_PRIORITY_STATUS);
|
||||
Gui_Replace((struct Screen*)s, GUI_PRIORITY_HUD);
|
||||
}
|
||||
|
||||
struct Widget* HUDScreen_GetHotbar(void) {
|
||||
return (struct Widget*)&HUDScreen_Instance.hotbar;
|
||||
}
|
||||
|
||||
|
||||
@ -309,7 +350,6 @@ void HUDScreen_Show(void) {
|
||||
*#########################################################################################################################*/
|
||||
static struct ChatScreen {
|
||||
Screen_Body
|
||||
struct HotbarWidget hotbar;
|
||||
/* player list state */
|
||||
struct PlayerListWidget playerList;
|
||||
struct FontDesc playerFont;
|
||||
@ -338,7 +378,7 @@ static struct ChatScreen {
|
||||
static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) {
|
||||
int pad, y;
|
||||
|
||||
y = min(s->input.base.y, s->hotbar.y);
|
||||
y = min(s->input.base.y, Gui_HUD->hotbar.y);
|
||||
y -= s->input.base.yOffset; /* add some padding */
|
||||
s->altText.yOffset = Window_Height - y;
|
||||
Widget_Layout(&s->altText);
|
||||
@ -390,7 +430,7 @@ static cc_bool ChatScreen_ChatUpdateFont(struct ChatScreen* s) {
|
||||
}
|
||||
|
||||
static void ChatScreen_ChatUpdateLayout(struct ChatScreen* s) {
|
||||
int yOffset = s->hotbar.height + 15;
|
||||
int yOffset = Gui_HUD->hotbar.height + 15;
|
||||
Widget_SetLocation(&s->input.base, ANCHOR_MIN, ANCHOR_MAX, 5, 5);
|
||||
Widget_SetLocation(&s->altText, ANCHOR_MIN, ANCHOR_MAX, 5, 5);
|
||||
Widget_SetLocation(&s->status, ANCHOR_MAX, ANCHOR_MIN, 0, 0);
|
||||
@ -400,28 +440,6 @@ static void ChatScreen_ChatUpdateLayout(struct ChatScreen* s) {
|
||||
ChatScreen_UpdateChatYOffsets(s);
|
||||
}
|
||||
|
||||
static void ChatScreen_ChatInit(struct ChatScreen* s) {
|
||||
ChatInputWidget_Create(&s->input);
|
||||
SpecialInputWidget_Create(&s->altText, &s->chatFont, &s->input.base);
|
||||
|
||||
TextGroupWidget_Create(&s->status, CHAT_MAX_STATUS,
|
||||
s->statusTextures, ChatScreen_GetStatus);
|
||||
TextGroupWidget_Create(&s->bottomRight, CHAT_MAX_BOTTOMRIGHT,
|
||||
s->bottomRightTextures, ChatScreen_GetBottomRight);
|
||||
TextGroupWidget_Create(&s->chat, Gui_Chatlines,
|
||||
s->chatTextures, ChatScreen_GetChat);
|
||||
TextGroupWidget_Create(&s->clientStatus, CHAT_MAX_CLIENTSTATUS,
|
||||
s->clientStatusTextures, ChatScreen_GetClientStatus);
|
||||
TextWidget_Make(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -Window_Height / 4);
|
||||
|
||||
s->status.collapsible[0] = true; /* Texture pack download status */
|
||||
s->clientStatus.collapsible[0] = true;
|
||||
s->clientStatus.collapsible[1] = true;
|
||||
|
||||
s->chat.underlineUrls = !Game_ClassicMode;
|
||||
s->chatIndex = Chat_Log.count - Gui_Chatlines;
|
||||
}
|
||||
|
||||
static void ChatScreen_Redraw(struct ChatScreen* s) {
|
||||
TextGroupWidget_RedrawAll(&s->chat);
|
||||
TextWidget_Set(&s->announcement, &Chat_Announcement, &s->announcementFont);
|
||||
@ -678,7 +696,6 @@ static void ChatScreen_ContextRecreated(void* screen) {
|
||||
ChatScreen_ChatUpdateFont(s);
|
||||
|
||||
ChatScreen_Redraw(s);
|
||||
Widget_Layout(&s->hotbar);
|
||||
ChatScreen_ChatUpdateLayout(s);
|
||||
if (s->showingList) ChatScreen_RemakePlayerList(s);
|
||||
|
||||
@ -695,7 +712,6 @@ static void ChatScreen_BuildMesh(void* screen) { }
|
||||
|
||||
static void ChatScreen_Layout(void* screen) {
|
||||
struct ChatScreen* s = (struct ChatScreen*)screen;
|
||||
Widget_Layout(&s->hotbar);
|
||||
|
||||
if (ChatScreen_ChatUpdateFont(s)) ChatScreen_Redraw(s);
|
||||
ChatScreen_ChatUpdateLayout(s);
|
||||
@ -775,7 +791,7 @@ static int ChatScreen_KeyDown(void* screen, int key) {
|
||||
} else if (key == KeyBinds[KEYBIND_INVENTORY]) {
|
||||
InventoryScreen_Show();
|
||||
} else {
|
||||
return Elem_HandlesKeyDown(&s->hotbar, key);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -788,7 +804,7 @@ static int ChatScreen_KeyUp(void* screen, int key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!s->grabsInput) return Elem_HandlesKeyUp(&s->hotbar, key);
|
||||
if (!s->grabsInput) return false;
|
||||
#ifdef CC_BUILD_WEB
|
||||
/* See reason for this in HandleInputUp */
|
||||
if (key == KEY_ESCAPE) ChatScreen_EnterChatInput(s, true);
|
||||
@ -871,8 +887,25 @@ static int ChatScreen_PointerDown(void* screen, int id, int x, int y) {
|
||||
|
||||
static void ChatScreen_Init(void* screen) {
|
||||
struct ChatScreen* s = (struct ChatScreen*)screen;
|
||||
HotbarWidget_Create(&s->hotbar);
|
||||
ChatScreen_ChatInit(s);
|
||||
ChatInputWidget_Create(&s->input);
|
||||
SpecialInputWidget_Create(&s->altText, &s->chatFont, &s->input.base);
|
||||
|
||||
TextGroupWidget_Create(&s->status, CHAT_MAX_STATUS,
|
||||
s->statusTextures, ChatScreen_GetStatus);
|
||||
TextGroupWidget_Create(&s->bottomRight, CHAT_MAX_BOTTOMRIGHT,
|
||||
s->bottomRightTextures, ChatScreen_GetBottomRight);
|
||||
TextGroupWidget_Create(&s->chat, Gui_Chatlines,
|
||||
s->chatTextures, ChatScreen_GetChat);
|
||||
TextGroupWidget_Create(&s->clientStatus, CHAT_MAX_CLIENTSTATUS,
|
||||
s->clientStatusTextures, ChatScreen_GetClientStatus);
|
||||
TextWidget_Make(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -Window_Height / 4);
|
||||
|
||||
s->status.collapsible[0] = true; /* Texture pack download status */
|
||||
s->clientStatus.collapsible[0] = true;
|
||||
s->clientStatus.collapsible[1] = true;
|
||||
|
||||
s->chat.underlineUrls = !Game_ClassicMode;
|
||||
s->chatIndex = Chat_Log.count - Gui_Chatlines;
|
||||
|
||||
Event_RegisterChat(&ChatEvents.ChatReceived, s, ChatScreen_ChatReceived);
|
||||
Event_RegisterInt(&ChatEvents.ColCodeChanged, s, ChatScreen_ColCodeChanged);
|
||||
@ -889,7 +922,6 @@ static void ChatScreen_Init(void* screen) {
|
||||
|
||||
static void ChatScreen_Render(void* screen, double delta) {
|
||||
struct ChatScreen* s = (struct ChatScreen*)screen;
|
||||
cc_bool showMinimal;
|
||||
|
||||
if (Game_HideGui && s->grabsInput) {
|
||||
Gfx_SetTexturing(true);
|
||||
@ -897,9 +929,8 @@ static void ChatScreen_Render(void* screen, double delta) {
|
||||
Gfx_SetTexturing(false);
|
||||
}
|
||||
if (Game_HideGui) return;
|
||||
showMinimal = Gui_GetBlocksWorld() != NULL;
|
||||
|
||||
if (!s->showingList && !showMinimal) {
|
||||
if (!s->showingList && !Gui_GetBlocksWorld()) {
|
||||
Gfx_SetTexturing(true);
|
||||
ChatScreen_DrawCrosshairs();
|
||||
Gfx_SetTexturing(false);
|
||||
@ -909,7 +940,6 @@ static void ChatScreen_Render(void* screen, double delta) {
|
||||
}
|
||||
|
||||
Gfx_SetTexturing(true);
|
||||
if (!showMinimal) { Elem_Render(&s->hotbar, delta); }
|
||||
ChatScreen_DrawChat(s, delta);
|
||||
|
||||
if (s->showingList && IsOnlyHudActive()) {
|
||||
@ -948,7 +978,7 @@ void ChatScreen_Show(void) {
|
||||
|
||||
s->VTABLE = &ChatScreen_VTABLE;
|
||||
Gui_Chat = s;
|
||||
Gui_Replace((struct Screen*)s, GUI_PRIORITY_HUD);
|
||||
Gui_Replace((struct Screen*)s, GUI_PRIORITY_CHAT);
|
||||
}
|
||||
|
||||
void ChatScreen_OpenInput(const String* text) {
|
||||
@ -977,10 +1007,6 @@ void ChatScreen_SetChatlines(int lines) {
|
||||
TextGroupWidget_RedrawAll(&s->chat);
|
||||
}
|
||||
|
||||
struct Widget* ChatScreen_GetHotbar(void) {
|
||||
return (struct Widget*)&ChatScreen_Instance.hotbar;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------InventoryScreen-----------------------------------------------------*
|
||||
@ -1068,7 +1094,7 @@ static int InventoryScreen_KeyDown(void* screen, int key) {
|
||||
Gui_Remove((struct Screen*)s);
|
||||
} else if (Elem_HandlesKeyDown(table, key)) {
|
||||
} else {
|
||||
return Elem_HandlesKeyDown(&Gui_Chat->hotbar, key);
|
||||
return Elem_HandlesKeyDown(&Gui_HUD->hotbar, key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1079,7 +1105,7 @@ static int InventoryScreen_KeyUp(void* screen, int key) {
|
||||
if (key == KeyBinds[KEYBIND_INVENTORY]) {
|
||||
s->releasedInv = true; return true;
|
||||
}
|
||||
return Elem_HandlesKeyUp(&Gui_Chat->hotbar, key);
|
||||
return Elem_HandlesKeyUp(&Gui_HUD->hotbar, key);
|
||||
}
|
||||
|
||||
static int InventoryScreen_PointerDown(void* screen, int id, int x, int y) {
|
||||
@ -1088,7 +1114,7 @@ static int InventoryScreen_PointerDown(void* screen, int id, int x, int y) {
|
||||
cc_bool handled, hotbar;
|
||||
|
||||
if (table->scroll.draggingId == id) return true;
|
||||
if (Elem_HandlesPointerDown(&Gui_Chat->hotbar, id, x, y)) return true;
|
||||
if (HUDscreen_PointerDown(Gui_HUD, id, x, y)) return true;
|
||||
handled = Elem_HandlesPointerDown(table, id, x, y);
|
||||
|
||||
if (!handled || table->pendingClose) {
|
||||
@ -1611,7 +1637,6 @@ static void TouchScreen_ContextRecreated(void* screen) {
|
||||
ButtonWidget_SetConst(&s->btns[i], desc->text, &s->font);
|
||||
}
|
||||
TouchScreen_UpdateModeText(s);
|
||||
/* TODO: Mode should display 'Place' or 'Delete' */
|
||||
/* TODO: this is pretty nasty hacky. rewrite! */
|
||||
}
|
||||
|
||||
|
@ -55,5 +55,5 @@ void ChatScreen_OpenInput(const String* text);
|
||||
void ChatScreen_AppendInput(const String* text);
|
||||
/* Sets number of visible lines in the main chat widget. */
|
||||
void ChatScreen_SetChatlines(int lines);
|
||||
struct Widget* ChatScreen_GetHotbar(void);
|
||||
struct Widget* HUDScreen_GetHotbar(void);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user