From 8f7c759d7d6f67c50589b02c95bc7bf1799bbdee Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 16 Dec 2018 13:04:24 +1100 Subject: [PATCH] only show missing file dialog when running game (not launcher) and default.zip is missing. Also use '1 hour' instead of '1 hours' in update menu --- src/LScreens.c | 24 +++++++++++++++++------- src/Platform.c | 23 ++++++++++++++--------- src/Program.c | 12 ++++++------ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/LScreens.c b/src/LScreens.c index ffe47f481..b44a84462 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -1232,6 +1232,19 @@ static void UpdatesScreen_Draw(struct LScreen* s) { midX - 160, midY - 5, 320, 1); } +CC_NOINLINE static void UpdatesScreen_FormatTime(String* str, char* type, int delta, int unit) { + delta /= unit; + String_AppendInt(str, delta); + String_Append(str, ' '); + String_AppendConst(str, type); + + if (delta > 1) { + String_AppendConst(str, "s ago"); + } else { + String_AppendConst(str, " ago"); + } +} + static void UpdatesScreen_Format(struct LLabel* lbl, const char* prefix, TimeMS time) { String str; char buffer[STRING_SIZE]; TimeMS now; @@ -1246,16 +1259,13 @@ static void UpdatesScreen_Format(struct LLabel* lbl, const char* prefix, TimeMS int delta = (int)(now - time) / 1000; if (delta < SECS_PER_MIN) { - String_Format1(&str, "%i seconds ago", &delta); + UpdatesScreen_FormatTime(&str, "second", delta, 1); } else if (delta < SECS_PER_HOUR) { - delta /= SECS_PER_MIN; - String_Format1(&str, "%i minutes ago", &delta); + UpdatesScreen_FormatTime(&str, "minute", delta, SECS_PER_MIN); } else if (delta < SECS_PER_DAY) { - delta /= SECS_PER_HOUR; - String_Format1(&str, "%i hours ago", &delta); + UpdatesScreen_FormatTime(&str, "hour", delta, SECS_PER_HOUR); } else { - delta /= SECS_PER_DAY; - String_Format1(&str, "%i days ago", &delta); + UpdatesScreen_FormatTime(&str, "day", delta, SECS_PER_DAY); } } LLabel_SetText(lbl, &str); diff --git a/src/Platform.c b/src/Platform.c index 905493b95..047edc4fa 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -906,7 +906,7 @@ void Font_GetNames(StringsBuffer* buffer) { } } -static String Font_Lookup(const String* fontName, const char type) { +static String Font_LookupOf(const String* fontName, const char type) { String name; char nameBuffer[STRING_SIZE + 2]; String_InitArray(name, nameBuffer); @@ -914,6 +914,17 @@ static String Font_Lookup(const String* fontName, const char type) { return EntryList_UNSAFE_Get(&font_list, &name); } +static String Font_Lookup(const String* fontName, int style) { + String path; + if (!font_list.Entries.Count) Font_Init(); + path = String_Empty; + + if (style & FONT_STYLE_BOLD) path = Font_Lookup(fontName, 'B'); + if (style & FONT_STYLE_ITALIC) path = Font_Lookup(fontName, 'I'); + + return Font_Lookup(fontName, 'R'); +} + void Font_Make(FontDesc* desc, const String* fontName, int size, int style) { String path; FT_Stream stream; @@ -924,13 +935,7 @@ void Font_Make(FontDesc* desc, const String* fontName, int size, int style) { desc->Size = size; desc->Style = style; - if (!font_list.Entries.Count) Font_Init(); - path = String_Empty; - - if (style & FONT_STYLE_BOLD) path = Font_Lookup(fontName, 'B'); - if (style & FONT_STYLE_ITALIC) path = Font_Lookup(fontName, 'I'); - - if (!path.length) path = Font_Lookup(fontName, 'R'); + path = Font_Lookup(fontName, style); if (!path.length) ErrorHandler_Fail("Unknown font"); stream = Mem_AllocCleared(1, sizeof(FT_StreamRec), "leaky font"); /* TODO: LEAKS MEMORY!!! */ @@ -1163,7 +1168,7 @@ static void* FT_ReallocWrapper(FT_Memory memory, long cur_size, long new_size, v #define FONT_CACHE_FILE "fontcache.txt" static void Font_Init(void) { #ifdef CC_BUILD_WIN - const static String dir = String_FromConst("C:\\Windows\\fonts"); + const static String dir = String_FromConst("C:\\Windows\\Fonts"); #endif #ifdef CC_BUILD_NIX const static String dir = String_FromConst("/usr/share/fonts"); diff --git a/src/Program.c b/src/Program.c index 4a5f20d31..8fc0f98d4 100644 --- a/src/Program.c +++ b/src/Program.c @@ -40,10 +40,16 @@ int main_imdct() { #endif static void Program_RunGame(void) { + const static String defPath = String_FromConst("texpacks/default.zip"); String title; char titleBuffer[STRING_SIZE]; struct DisplayDevice device; int width, height; + if (!File_Exists(&defPath)) { + Window_ShowDialog("Missing file", + "default.zip is missing, try running launcher first.\n\nThe game will still run, but without any textures"); + } + device = DisplayDevice_Default; width = Options_GetInt(OPT_WINDOW_WIDTH, 0, device.Bounds.Width, 0); height = Options_GetInt(OPT_WINDOW_HEIGHT, 0, device.Bounds.Height, 0); @@ -60,7 +66,6 @@ static void Program_RunGame(void) { } int main(int argc, char** argv) { - const static String defPath = String_FromConst("texpacks/default.zip"); String args[PROGRAM_MAX_CMDARGS]; int argsCount; uint8_t ip[4]; @@ -82,11 +87,6 @@ int main(int argc, char** argv) { Utils_EnsureDirectory("maps"); Utils_EnsureDirectory("texpacks"); Utils_EnsureDirectory("texturecache"); - - if (!File_Exists(&defPath)) { - Window_ShowDialog("Missing file", - "default.zip is missing, try running launcher first.\n\nThe game will still run, but without any textures"); - } Options_Load(); if (argsCount == 0) {