diff --git a/src/Drawer2D.h b/src/Drawer2D.h index e951cf8be..20bda33fb 100644 --- a/src/Drawer2D.h +++ b/src/Drawer2D.h @@ -16,7 +16,7 @@ extern struct IGameComponent Drawer2D_Component; void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, struct FontDesc* font, cc_bool useShadow); void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, cc_bool useShadow); /* Initialises the given font. When Drawer2D_BitmappedText is false, creates native font handle using Font_Make. */ -CC_NOINLINE void Drawer2D_MakeFont(struct FontDesc* desc, int size, int style); +CC_API void Drawer2D_MakeFont(struct FontDesc* desc, int size, int style); /* Whether text should be drawn and measured using the currently set font bitmap. */ /* If false, then text is instead draw using platform/system fonts. */ @@ -93,7 +93,7 @@ void Drawer2D_ReducePadding_Height(int* height, int point, int scale); cc_bool Drawer2D_SetFontBitmap(Bitmap* bmp); /* Gets the list of all supported system font names on this platform. */ -void Font_GetNames(struct StringsBuffer* buffer); +CC_API void Font_GetNames(struct StringsBuffer* buffer); /* Reduces padding for a bitmapped font. */ void Font_ReducePadding(struct FontDesc* desc, int scale); /* Finds the path and face number of the given system font, with closest matching style */ diff --git a/src/Gui.c b/src/Gui.c index 500125035..3896f8d51 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -191,17 +191,12 @@ CC_NOINLINE static void Gui_OnScreensChanged(void) { InputHandler_OnScreensChanged(); } -void Gui_Add(struct Screen* s, int priority) { - Gui_AddCore(s, priority); - Gui_OnScreensChanged(); -} - void Gui_Remove(struct Screen* s) { Gui_RemoveCore(s); Gui_OnScreensChanged(); } -void Gui_Replace(struct Screen* s, int priority) { +void Gui_Add(struct Screen* s, int priority) { int i; Gui_RemoveCore(s); /* Backwards loop since removing changes count and gui_screens */ diff --git a/src/Gui.h b/src/Gui.h index c539e4fa2..119e6f70b 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -130,6 +130,7 @@ int Widget_Contains(void* widget, int x, int y); extern GfxResourceID Gui_GuiTex, Gui_GuiClassicTex, Gui_IconsTex; /* Higher priority handles input first and draws on top */ +/* NOTE: Values are 5 apart to allow plugins to insert custom screens */ enum GuiPriority { GUI_PRIORITY_DISCONNECT = 60, GUI_PRIORITY_OLDLOADING = 55, @@ -164,13 +165,11 @@ int Gui_ContainsPointers(int x, int y, int width, int height); /* Shows HUD and Status screens. */ void Gui_ShowDefault(void); -/* Inserts a screen into the screen lists with the given priority. */ -/* NOTE: You MUST ensure a screen isn't added twice. Or use Gui_Replace. */ -CC_API void Gui_Add(struct Screen* screen, int priority); /* Removes the screen from the screens list. */ CC_API void Gui_Remove(struct Screen* screen); -/* Shorthand for Gui_Remove then Gui_Add. */ -CC_API void Gui_Replace(struct Screen* screen, int priority); +/* Inserts a screen into the screen lists with the given priority. */ +/* NOTE: If there is an existing screen with the same priority, it is removed. */ +CC_API void Gui_Add(struct Screen* screen, int priority); /* Returns highest priority screen that has grabbed input. */ struct Screen* Gui_GetInputGrab(void); diff --git a/src/Menus.c b/src/Menus.c index 6dbd0e0d8..a8119d502 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -444,7 +444,7 @@ void ListScreen_Show(void) { s->grabsInput = true; s->closable = true; s->VTABLE = &ListScreen_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -563,7 +563,7 @@ void PauseScreen_Show(void) { s->grabsInput = true; s->closable = true; s->VTABLE = &PauseScreen_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -681,7 +681,7 @@ void OptionsGroupScreen_Show(void) { s->grabsInput = true; s->closable = true; s->VTABLE = &OptionsGroupScreen_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -930,7 +930,7 @@ void EditHotkeyScreen_Show(struct HotkeyData original) { s->VTABLE = &EditHotkeyScreen_VTABLE; s->origHotkey = original; s->curHotkey = original; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -1123,7 +1123,7 @@ void GenLevelScreen_Show(void) { s->grabsInput = true; s->closable = true; s->VTABLE = &GenLevelScreen_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -1196,7 +1196,7 @@ void ClassicGenScreen_Show(void) { s->grabsInput = true; s->closable = true; s->VTABLE = &ClassicGenScreen_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -1484,7 +1484,7 @@ void SaveLevelScreen_Show(void) { s->grabsInput = true; s->closable = true; s->VTABLE = &SaveLevelScreen_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -1840,7 +1840,7 @@ static void KeyBindingsScreen_Show(int bindsCount, const cc_uint8* binds, const s->binds = binds; s->descs = descs; s->DoInit = doInit; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -2299,7 +2299,7 @@ void MenuOptionsScreen_Show(struct MenuInputDesc* descs, const char** descriptio s->DoInit = init; s->DoRecreateExtra = NULL; s->OnHacksChanged = NULL; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU); + Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU); } @@ -3172,7 +3172,7 @@ void TexIdsOverlay_Show(void) { s->grabsInput = true; s->closable = true; s->VTABLE = &TexIdsOverlay_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_TEXIDS); + Gui_Add((struct Screen*)s, GUI_PRIORITY_TEXIDS); } @@ -3252,7 +3252,7 @@ void UrlWarningOverlay_Show(const String* url) { String_InitArray(s->url, s->_urlBuffer); String_Copy(&s->url, url); - Gui_Replace((struct Screen*)s, GUI_PRIORITY_URLWARNING); + Gui_Add((struct Screen*)s, GUI_PRIORITY_URLWARNING); } @@ -3421,7 +3421,7 @@ void TexPackOverlay_Show(const String* url) { s->url = String_UNSAFE_SubstringAt(&s->identifier, 3); Http_AsyncGetHeaders(url, true, &s->identifier); - Gui_Replace((struct Screen*)s, GUI_PRIORITY_TEXPACK); + Gui_Add((struct Screen*)s, GUI_PRIORITY_TEXPACK); } @@ -3509,6 +3509,6 @@ void TouchMoreScreen_Show(void) { s->closable = true; s->VTABLE = &TouchMoreScreen_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_TOUCHMORE); + Gui_Add((struct Screen*)s, GUI_PRIORITY_TOUCHMORE); } #endif diff --git a/src/Screens.c b/src/Screens.c index 4a616ed84..c8f0604a3 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -348,7 +348,7 @@ void HUDScreen_Show(void) { struct HUDScreen* s = &HUDScreen_Instance; s->VTABLE = &HUDScreen_VTABLE; Gui_HUD = s; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_HUD); + Gui_Add((struct Screen*)s, GUI_PRIORITY_HUD); } struct Widget* HUDScreen_GetHotbar(void) { @@ -1350,7 +1350,7 @@ void ChatScreen_Show(void) { s->VTABLE = &ChatScreen_VTABLE; Gui_Chat = s; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_CHAT); + Gui_Add((struct Screen*)s, GUI_PRIORITY_CHAT); } void ChatScreen_OpenInput(const String* text) { @@ -1526,7 +1526,7 @@ void InventoryScreen_Show(void) { s->closable = true; s->VTABLE = &InventoryScreen_VTABLE; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_INVENTORY); + Gui_Add((struct Screen*)s, GUI_PRIORITY_INVENTORY); } @@ -1677,7 +1677,7 @@ CC_NOINLINE static void LoadingScreen_ShowCommon(const String* title, const Stri s->grabsInput = true; s->blocksWorld = true; - Gui_Replace((struct Screen*)s, + Gui_Add((struct Screen*)s, Game_ClassicMode ? GUI_PRIORITY_OLDLOADING : GUI_PRIORITY_LOADING); } @@ -1924,7 +1924,7 @@ void DisconnectScreen_Show(const String* title, const String* message) { /* Get rid of all other menus instead of just hiding to reduce GPU usage */ while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]); - Gui_Replace((struct Screen*)s, GUI_PRIORITY_DISCONNECT); + Gui_Add((struct Screen*)s, GUI_PRIORITY_DISCONNECT); } @@ -2085,6 +2085,6 @@ void TouchScreen_Show(void) { s->VTABLE = &TouchScreen_VTABLE; if (!Input_TouchMode) return; - Gui_Replace((struct Screen*)s, GUI_PRIORITY_TOUCH); + Gui_Add((struct Screen*)s, GUI_PRIORITY_TOUCH); } #endif