mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Make code depending on HUD hotbar layout a bit less hacky
This commit is contained in:
parent
0f36cc9a57
commit
d0f21a24b8
@ -832,13 +832,11 @@ static void SysFonts_Update(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void SysFonts_Load(void) {
|
static void SysFonts_Load(void) {
|
||||||
static const cc_string cachePath = String_FromConst(FONT_CACHE_FILE);
|
|
||||||
if (!File_Exists(&cachePath)) {
|
|
||||||
Window_ShowDialog("One time load", "Initialising font cache, this can take several seconds.");
|
|
||||||
}
|
|
||||||
|
|
||||||
EntryList_UNSAFE_Load(&font_list, FONT_CACHE_FILE);
|
EntryList_UNSAFE_Load(&font_list, FONT_CACHE_FILE);
|
||||||
if (!font_list.count) SysFonts_Update();
|
if (font_list.count) return;
|
||||||
|
|
||||||
|
Window_ShowDialog("One time load", "Initialising font cache, this can take several seconds.");
|
||||||
|
SysFonts_Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Some language-specific fonts don't support English letters */
|
/* Some language-specific fonts don't support English letters */
|
||||||
|
@ -148,13 +148,13 @@ static int Program_Run(int argc, char** argv) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOTE: This is used when compiling with MingW without linking to startup files. */
|
/* NOTE: main_real is used for when compiling with MingW without linking to startup files. */
|
||||||
/* The final code produced for "main" is our "main" combined with crt's main. (mingw-w64-crt/crt/gccmain.c) */
|
/* Normally, the final code produced for "main" is our "main" combined with crt's main */
|
||||||
/* This immediately crashes the game on startup. */
|
/* (mingw-w64-crt/crt/gccmain.c)) - alas this immediately crashes the game on startup. */
|
||||||
/* Using main_real instead and setting main_real as the entrypoint fixes the crash. */
|
/* Using main_real instead and setting main_real as the entrypoint fixes the crash. */
|
||||||
#ifdef CC_NOMAIN
|
#ifdef CC_NOMAIN
|
||||||
int main_real(int argc, char** argv) {
|
int main_real(int argc, char** argv) {
|
||||||
#else
|
#else
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
#endif
|
#endif
|
||||||
static char ipBuffer[STRING_SIZE];
|
static char ipBuffer[STRING_SIZE];
|
||||||
@ -178,10 +178,10 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ClassiCube is just a native library on android, */
|
/* ClassiCube is just a native library on android, */
|
||||||
/* unlike other platforms where it is the executable. */
|
/* unlike other platforms where it is the executable. */
|
||||||
/* As such, we have to hook into the java-side activity, */
|
/* As such, we have to hook into the java-side activity, */
|
||||||
/* which in its onCreate() calls runGameAsync to */
|
/* which in its onCreate() calls runGameAsync to */
|
||||||
/* actually run the game on a separate thread. */
|
/* actually run the game on a separate thread. */
|
||||||
#ifdef CC_BUILD_ANDROID
|
#ifdef CC_BUILD_ANDROID
|
||||||
static void android_main(void) {
|
static void android_main(void) {
|
||||||
Platform_LogConst("Main loop started!");
|
Platform_LogConst("Main loop started!");
|
||||||
|
@ -205,6 +205,13 @@ static void HUDScreen_ContextRecreated(void* screen) {
|
|||||||
|
|
||||||
static void HUDScreen_BuildMesh(void* screen) { }
|
static void HUDScreen_BuildMesh(void* screen) { }
|
||||||
|
|
||||||
|
static int HUDScreen_LayoutHotbar(void) {
|
||||||
|
struct HUDScreen* s = &HUDScreen_Instance;
|
||||||
|
s->hotbar.scale = Gui_GetHotbarScale();
|
||||||
|
Widget_Layout(&s->hotbar);
|
||||||
|
return s->hotbar.height;
|
||||||
|
}
|
||||||
|
|
||||||
static void HUDScreen_Layout(void* screen) {
|
static void HUDScreen_Layout(void* screen) {
|
||||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||||
struct TextWidget* line1 = &s->line1;
|
struct TextWidget* line1 = &s->line1;
|
||||||
@ -226,8 +233,7 @@ static void HUDScreen_Layout(void* screen) {
|
|||||||
line2->yOffset = posY + s->posAtlas.tex.Height;
|
line2->yOffset = posY + s->posAtlas.tex.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->hotbar.scale = Gui_GetHotbarScale();
|
HUDScreen_LayoutHotbar();
|
||||||
Widget_Layout(&s->hotbar);
|
|
||||||
Widget_Layout(line2);
|
Widget_Layout(line2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,11 +759,8 @@ static struct ChatScreen {
|
|||||||
|
|
||||||
static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) {
|
static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) {
|
||||||
int pad, y;
|
int pad, y;
|
||||||
|
|
||||||
/* Determining chat Y requires us to know hotbar's position */
|
/* Determining chat Y requires us to know hotbar's position */
|
||||||
/* But HUD is lower priority, so it gets laid out AFTER chat */
|
HUDScreen_LayoutHotbar();
|
||||||
/* Hence use this hack to resize HUD first */
|
|
||||||
HUDScreen_Layout(Gui_HUD);
|
|
||||||
|
|
||||||
y = min(s->input.base.y, Gui_HUD->hotbar.y);
|
y = min(s->input.base.y, Gui_HUD->hotbar.y);
|
||||||
y -= s->input.base.yOffset; /* add some padding */
|
y -= s->input.base.yOffset; /* add some padding */
|
||||||
@ -1043,8 +1046,6 @@ static void ChatScreen_BuildMesh(void* screen) { }
|
|||||||
|
|
||||||
static void ChatScreen_Layout(void* screen) {
|
static void ChatScreen_Layout(void* screen) {
|
||||||
struct ChatScreen* s = (struct ChatScreen*)screen;
|
struct ChatScreen* s = (struct ChatScreen*)screen;
|
||||||
/* See comment in ChatScreen_UpdateChatYOffsets */
|
|
||||||
HUDScreen_Layout(Gui_HUD);
|
|
||||||
if (ChatScreen_ChatUpdateFont(s)) ChatScreen_Redraw(s);
|
if (ChatScreen_ChatUpdateFont(s)) ChatScreen_Redraw(s);
|
||||||
|
|
||||||
s->paddingX = Display_ScaleX(5);
|
s->paddingX = Display_ScaleX(5);
|
||||||
@ -1059,7 +1060,7 @@ static void ChatScreen_Layout(void* screen) {
|
|||||||
ChatScreen_UpdateChatYOffsets(s);
|
ChatScreen_UpdateChatYOffsets(s);
|
||||||
|
|
||||||
/* Can't use Widget_SetLocation because it DPI scales input */
|
/* Can't use Widget_SetLocation because it DPI scales input */
|
||||||
s->bottomRight.yOffset = Gui_HUD->hotbar.height + Display_ScaleY(15);
|
s->bottomRight.yOffset = HUDScreen_LayoutHotbar() + Display_ScaleY(15);
|
||||||
Widget_Layout(&s->bottomRight);
|
Widget_Layout(&s->bottomRight);
|
||||||
|
|
||||||
Widget_SetLocation(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
|
Widget_SetLocation(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
|
||||||
@ -2127,10 +2128,8 @@ static void TouchScreen_Layout(void* screen) {
|
|||||||
Widget_SetLocation(&s->onscreen[i], ANCHOR_MAX, ANCHOR_MIN, 10, 10 + i * 40);
|
Widget_SetLocation(&s->onscreen[i], ANCHOR_MAX, ANCHOR_MIN, 10, 10 + i * 40);
|
||||||
}
|
}
|
||||||
Widget_SetLocation(&s->more, ANCHOR_CENTRE, ANCHOR_MIN, 0, 10);
|
Widget_SetLocation(&s->more, ANCHOR_CENTRE, ANCHOR_MIN, 0, 10);
|
||||||
|
|
||||||
/* Need to align these relative to the hotbar */
|
/* Need to align these relative to the hotbar */
|
||||||
HUDScreen_Layout(Gui_HUD);
|
height = HUDScreen_LayoutHotbar();
|
||||||
height = Gui_HUD->hotbar.height;
|
|
||||||
|
|
||||||
for (i = 0; i < s->numBtns; i++) {
|
for (i = 0; i < s->numBtns; i++) {
|
||||||
desc = &s->descs[i];
|
desc = &s->descs[i];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user