mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 01:21:57 -05:00
more cleanup of screen/menu
This commit is contained in:
parent
bea6e546c1
commit
25d6518931
6 changed files with 87 additions and 72 deletions
85
src/Menus.c
85
src/Menus.c
|
@ -126,6 +126,7 @@ struct MenuOptionDesc {
|
|||
Widget_LeftClick OnClick;
|
||||
Button_Get GetValue; Button_Set SetValue;
|
||||
};
|
||||
struct SimpleButtonDesc { int x, y; const char* title; Widget_LeftClick onClick; };
|
||||
|
||||
struct TexIdsOverlay {
|
||||
MenuScreen_Layout
|
||||
|
@ -592,17 +593,6 @@ static void MenuScreen_Free(void* screen) {
|
|||
*-------------------------------------------------------PauseScreen-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static struct PauseScreen PauseScreen_Instance;
|
||||
static void PauseScreen_Make(struct PauseScreen* s, int i, int dir, int y, const char* title, Widget_LeftClick onClick) {
|
||||
String text = String_FromReadonly(title);
|
||||
Menu_Button(s, i, &s->buttons[i], 300, &text, &s->titleFont, onClick,
|
||||
ANCHOR_CENTRE, ANCHOR_CENTRE, dir * 160, y);
|
||||
}
|
||||
|
||||
static void PauseScreen_MakeClassic(struct PauseScreen* s, int i, int y, const char* title, Widget_LeftClick onClick) {
|
||||
String text = String_FromReadonly(title);
|
||||
Menu_Button(s, i, &s->buttons[i], 400, &text, &s->titleFont, onClick,
|
||||
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, y);
|
||||
}
|
||||
|
||||
static void PauseScreen_Quit(void* a, void* b) { Window_Close(); }
|
||||
static void PauseScreen_Game(void* a, void* b) { Gui_CloseActive(); }
|
||||
|
@ -613,17 +603,37 @@ static void PauseScreen_CheckHacksAllowed(void* screen) {
|
|||
s->buttons[4].disabled = !LocalPlayer_Instance.Hacks.CanAnyHacks; /* select texture pack */
|
||||
}
|
||||
|
||||
static void PauseScreen_MakeButtons(struct PauseScreen* s, int width, const struct SimpleButtonDesc* descs, int count) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
String text = String_FromReadonly(descs[i].title);
|
||||
Menu_Button(s, i, &s->buttons[i], width, &text, &s->titleFont, descs[i].onClick,
|
||||
ANCHOR_CENTRE, ANCHOR_CENTRE, descs[i].x, descs[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
static void PauseScreen_ContextRecreated(void* screen) {
|
||||
static const String quitMsg = String_FromConst("Quit game");
|
||||
struct PauseScreen* s = (struct PauseScreen*)screen;
|
||||
|
||||
if (Gui_ClassicMenu) {
|
||||
PauseScreen_MakeClassic(s, 0, -100, "Options...", Menu_SwitchClassicOptions);
|
||||
PauseScreen_MakeClassic(s, 1, -50, "Generate new level...", Menu_SwitchClassicGenLevel);
|
||||
PauseScreen_MakeClassic(s, 2, 0, "Load level...", Menu_SwitchLoadLevel);
|
||||
PauseScreen_MakeClassic(s, 3, 50, "Save level...", Menu_SwitchSaveLevel);
|
||||
PauseScreen_MakeClassic(s, 4, 150, "Nostalgia options...", Menu_SwitchNostalgia);
|
||||
static const struct SimpleButtonDesc classicDescs[5] = {
|
||||
{ 0, -100, "Options...", Menu_SwitchClassicOptions },
|
||||
{ 0, -50, "Generate new level...", Menu_SwitchClassicGenLevel },
|
||||
{ 0, 0, "Load level...", Menu_SwitchLoadLevel },
|
||||
{ 0, 50, "Save level...", Menu_SwitchSaveLevel },
|
||||
{ 0, 150, "Nostalgia options...", Menu_SwitchNostalgia }
|
||||
};
|
||||
static const struct SimpleButtonDesc modernDescs[6] = {
|
||||
{ -160, -50, "Options...", Menu_SwitchOptions },
|
||||
{ 160, -50, "Generate new level...", Menu_SwitchGenLevel },
|
||||
{ 160, 0, "Load level...", Menu_SwitchLoadLevel },
|
||||
{ 160, 50, "Save level...", Menu_SwitchSaveLevel },
|
||||
{ -160, 0, "Change texture pack...", Menu_SwitchTexPacks },
|
||||
{ -160, 50, "Hotkeys...", Menu_SwitchHotkeys }
|
||||
};
|
||||
|
||||
if (Gui_ClassicMenu) {
|
||||
PauseScreen_MakeButtons(s, 400, classicDescs, 5);
|
||||
Menu_Back(s, 5, &s->buttons[5], "Back to game", &s->titleFont, PauseScreen_Game);
|
||||
|
||||
/* Disable nostalgia options in classic mode */
|
||||
|
@ -631,13 +641,7 @@ static void PauseScreen_ContextRecreated(void* screen) {
|
|||
s->widgets[6] = NULL;
|
||||
s->widgets[7] = NULL;
|
||||
} else {
|
||||
PauseScreen_Make(s, 0, -1, -50, "Options...", Menu_SwitchOptions);
|
||||
PauseScreen_Make(s, 1, 1, -50, "Generate new level...", Menu_SwitchGenLevel);
|
||||
PauseScreen_Make(s, 2, 1, 0, "Load level...", Menu_SwitchLoadLevel);
|
||||
PauseScreen_Make(s, 3, 1, 50, "Save level...", Menu_SwitchSaveLevel);
|
||||
PauseScreen_Make(s, 4, -1, 0, "Change texture pack...", Menu_SwitchTexPacks);
|
||||
PauseScreen_Make(s, 5, -1, 50, "Hotkeys...", Menu_SwitchHotkeys);
|
||||
|
||||
PauseScreen_MakeButtons(s, 300, modernDescs, 6);
|
||||
Menu_Button(s, 6, &s->buttons[6], 120, &quitMsg, &s->titleFont, PauseScreen_Quit,
|
||||
ANCHOR_MAX, ANCHOR_MAX, 5, 5);
|
||||
Menu_Back(s, 7, &s->buttons[7], "Back to game",&s->titleFont, PauseScreen_Game);
|
||||
|
@ -701,10 +705,23 @@ static void OptionsGroupScreen_CheckHacksAllowed(void* screen) {
|
|||
s->buttons[5].disabled = !LocalPlayer_Instance.Hacks.CanAnyHacks; /* env settings */
|
||||
}
|
||||
|
||||
static void OptionsGroupScreen_Make(struct OptionsGroupScreen* s, int i, int dir, int y, const char* title, Widget_LeftClick onClick) {
|
||||
String text = String_FromReadonly(title);
|
||||
Menu_Button(s, i, &s->buttons[i], 300, &text, &s->titleFont, onClick,
|
||||
ANCHOR_CENTRE, ANCHOR_CENTRE, dir * 160, y);
|
||||
static void OptionsGroupScreen_MakeButtons(struct OptionsGroupScreen* s) {
|
||||
static const struct SimpleButtonDesc descs[7] = {
|
||||
{ -160, -100, "Misc options...", Menu_SwitchMisc },
|
||||
{ -160, -50, "Gui options...", Menu_SwitchGui },
|
||||
{ -160, 0, "Graphics options...", Menu_SwitchGfx },
|
||||
{ -160, 50, "Controls...", Menu_SwitchKeysNormal },
|
||||
{ 160, -50, "Hacks settings...", Menu_SwitchHacks },
|
||||
{ 160, 0, "Env settings...", Menu_SwitchEnv },
|
||||
{ 160, 50, "Nostalgia options...", Menu_SwitchNostalgia }
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < Array_Elems(descs); i++) {
|
||||
String text = String_FromReadonly(descs[i].title);
|
||||
Menu_Button(s, i, &s->buttons[i], 300, &text, &s->titleFont, descs[i].onClick,
|
||||
ANCHOR_CENTRE, ANCHOR_CENTRE, descs[i].x, descs[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
static void OptionsGroupScreen_MakeDesc(struct OptionsGroupScreen* s) {
|
||||
|
@ -715,18 +732,12 @@ static void OptionsGroupScreen_MakeDesc(struct OptionsGroupScreen* s) {
|
|||
|
||||
static void OptionsGroupScreen_ContextRecreated(void* screen) {
|
||||
struct OptionsGroupScreen* s = (struct OptionsGroupScreen*)screen;
|
||||
OptionsGroupScreen_Make(s, 0, -1, -100, "Misc options...", Menu_SwitchMisc);
|
||||
OptionsGroupScreen_Make(s, 1, -1, -50, "Gui options...", Menu_SwitchGui);
|
||||
OptionsGroupScreen_Make(s, 2, -1, 0, "Graphics options...", Menu_SwitchGfx);
|
||||
OptionsGroupScreen_Make(s, 3, -1, 50, "Controls...", Menu_SwitchKeysNormal);
|
||||
OptionsGroupScreen_Make(s, 4, 1, -50, "Hacks settings...", Menu_SwitchHacks);
|
||||
OptionsGroupScreen_Make(s, 5, 1, 0, "Env settings...", Menu_SwitchEnv);
|
||||
OptionsGroupScreen_Make(s, 6, 1, 50, "Nostalgia options...", Menu_SwitchNostalgia);
|
||||
OptionsGroupScreen_MakeButtons(s);
|
||||
|
||||
Menu_Back(s, 7, &s->buttons[7], "Done", &s->titleFont, Menu_SwitchPause);
|
||||
s->widgets[8] = NULL; /* Description text widget placeholder */
|
||||
|
||||
if (s->selectedI >= 0) { OptionsGroupScreen_MakeDesc(s); }
|
||||
if (s->selectedI >= 0) OptionsGroupScreen_MakeDesc(s);
|
||||
OptionsGroupScreen_CheckHacksAllowed(s);
|
||||
}
|
||||
|
||||
|
@ -1019,7 +1030,7 @@ static void GenLevelScreen_Begin(int width, int height, int length) {
|
|||
World_Reset();
|
||||
World_SetDimensions(width, height, length);
|
||||
Gui_FreeActive();
|
||||
Gui_SetActive(GeneratingScreen_MakeInstance());
|
||||
GeneratingScreen_Show();
|
||||
}
|
||||
|
||||
static void GenLevelScreen_Gen(void* screen, bool vanilla) {
|
||||
|
|
|
@ -431,7 +431,7 @@ static void Classic_StartLoading(void) {
|
|||
classic_prevScreen = NULL;
|
||||
}
|
||||
|
||||
Gui_SetActive(LoadingScreen_MakeInstance(&Server.Name, &Server.MOTD));
|
||||
LoadingScreen_Show(&Server.Name, &Server.MOTD);
|
||||
WoM_CheckMotd();
|
||||
classic_receivedFirstPos = false;
|
||||
|
||||
|
|
|
@ -96,13 +96,13 @@ static void InventoryScreen_Init(void* screen) {
|
|||
Drawer2D_MakeFont(&s->font, 16, FONT_STYLE_NORMAL);
|
||||
|
||||
TableWidget_Create(&s->table);
|
||||
s->table.font = &s->font;
|
||||
s->table.font = &s->font;
|
||||
s->table.elementsPerRow = Game_PureClassic ? 9 : 10;
|
||||
Elem_Init(&s->table);
|
||||
|
||||
/* Can't immediately move to selected here, because cursor visibility
|
||||
might be toggled after Init() is called. This causes the cursor to
|
||||
be moved back to the middle of the window. */
|
||||
/* Can't immediately move to selected here, because cursor grabbed */
|
||||
/* status might be toggled after InventoryScreen_Init() is called. */
|
||||
/* That causes the cursor to be moved back to the middle of the window. */
|
||||
s->deferredSelect = true;
|
||||
Screen_CommonInit(s);
|
||||
|
||||
|
@ -439,15 +439,10 @@ static struct LoadingScreen {
|
|||
} LoadingScreen_Instance;
|
||||
|
||||
static void LoadingScreen_SetTitle(struct LoadingScreen* s) {
|
||||
Elem_TryFree(&s->title);
|
||||
TextWidget_Create(&s->title, &s->titleStr, &s->font);
|
||||
Widget_SetLocation(&s->title, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -31);
|
||||
TextWidget_Set(&s->title, &s->titleStr, &s->font);
|
||||
}
|
||||
|
||||
static void LoadingScreen_SetMessage(struct LoadingScreen* s) {
|
||||
Elem_TryFree(&s->message);
|
||||
TextWidget_Create(&s->message, &s->messageStr, &s->font);
|
||||
Widget_SetLocation(&s->message, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 17);
|
||||
TextWidget_Set(&s->message, &s->messageStr, &s->font);
|
||||
}
|
||||
|
||||
static void LoadingScreen_MapLoading(void* screen, float progress) {
|
||||
|
@ -544,8 +539,13 @@ static void LoadingScreen_DrawBackground(void) {
|
|||
static void LoadingScreen_Init(void* screen) {
|
||||
struct LoadingScreen* s = (struct LoadingScreen*)screen;
|
||||
Drawer2D_MakeFont(&s->font, 16, FONT_STYLE_NORMAL);
|
||||
Screen_CommonInit(s);
|
||||
|
||||
TextWidget_Make(&s->title);
|
||||
Widget_SetLocation(&s->title, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -31);
|
||||
TextWidget_Make(&s->message);
|
||||
Widget_SetLocation(&s->message, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 17);
|
||||
|
||||
Screen_CommonInit(s);
|
||||
Gfx_SetFog(false);
|
||||
Event_RegisterFloat(&WorldEvents.Loading, s, LoadingScreen_MapLoading);
|
||||
}
|
||||
|
@ -562,7 +562,7 @@ static void LoadingScreen_Render(void* screen, double delta) {
|
|||
Gfx_SetTexturing(true);
|
||||
LoadingScreen_DrawBackground();
|
||||
|
||||
Elem_Render(&s->title, delta);
|
||||
Elem_Render(&s->title, delta);
|
||||
Elem_Render(&s->message, delta);
|
||||
Gfx_SetTexturing(false);
|
||||
|
||||
|
@ -581,27 +581,31 @@ static void LoadingScreen_Free(void* screen) {
|
|||
Event_UnregisterFloat(&WorldEvents.Loading, s, LoadingScreen_MapLoading);
|
||||
}
|
||||
|
||||
static struct ScreenVTABLE LoadingScreen_VTABLE = {
|
||||
LoadingScreen_Init, LoadingScreen_Render, LoadingScreen_Free, Gui_DefaultRecreate,
|
||||
LoadingScreen_KeyDown, LoadingScreen_KeyUp, LoadingScreen_KeyPress,
|
||||
LoadingScreen_MouseDown, LoadingScreen_MouseUp, LoadingScreen_MouseMove, LoadingScreen_MouseScroll,
|
||||
LoadingScreen_OnResize, LoadingScreen_ContextLost, LoadingScreen_ContextRecreated,
|
||||
};
|
||||
struct Screen* LoadingScreen_MakeInstance(const String* title, const String* message) {
|
||||
CC_NOINLINE static void LoadingScreen_Reset(const String* title, const String* message) {
|
||||
struct LoadingScreen* s = &LoadingScreen_Instance;
|
||||
s->lastState = NULL;
|
||||
s->VTABLE = &LoadingScreen_VTABLE;
|
||||
s->progress = 0.0f;
|
||||
|
||||
String_InitArray(s->titleStr, s->_titleBuffer);
|
||||
String_AppendString(&s->titleStr, title);
|
||||
String_InitArray(s->titleStr, s->_titleBuffer);
|
||||
String_AppendString(&s->titleStr, title);
|
||||
String_InitArray(s->messageStr, s->_messageBuffer);
|
||||
String_AppendString(&s->messageStr, message);
|
||||
|
||||
s->handlesAllInput = true;
|
||||
s->blocksWorld = true;
|
||||
s->renderHUDOver = true;
|
||||
return (struct Screen*)s;
|
||||
}
|
||||
|
||||
static struct ScreenVTABLE LoadingScreen_VTABLE = {
|
||||
LoadingScreen_Init, LoadingScreen_Render, LoadingScreen_Free, Gui_DefaultRecreate,
|
||||
LoadingScreen_KeyDown, LoadingScreen_KeyUp, LoadingScreen_KeyPress,
|
||||
LoadingScreen_MouseDown, LoadingScreen_MouseUp, LoadingScreen_MouseMove, LoadingScreen_MouseScroll,
|
||||
LoadingScreen_OnResize, LoadingScreen_ContextLost, LoadingScreen_ContextRecreated,
|
||||
};
|
||||
void LoadingScreen_Show(const String* title, const String* message) {
|
||||
LoadingScreen_Reset(title, message);
|
||||
LoadingScreen_Instance.VTABLE = &LoadingScreen_VTABLE;
|
||||
Gui_SetActive((struct Screen*)&LoadingScreen_Instance);
|
||||
}
|
||||
struct Screen* LoadingScreen_UNSAFE_RawPointer = (struct Screen*)&LoadingScreen_Instance;
|
||||
|
||||
|
@ -617,7 +621,7 @@ static void GeneratingScreen_Init(void* screen) {
|
|||
Gen_Blocks = (BlockRaw*)Mem_TryAlloc(World.Volume, 1);
|
||||
if (!Gen_Blocks) {
|
||||
Window_ShowDialog("Out of memory", "Not enough free memory to generate a map that large.\nTry a smaller size.");
|
||||
Gui_CloseActive();
|
||||
Gen_Done = true;
|
||||
} else if (Gen_Vanilla) {
|
||||
Thread_Start(NotchyGen_Generate, true);
|
||||
} else {
|
||||
|
@ -669,13 +673,13 @@ static struct ScreenVTABLE GeneratingScreen_VTABLE = {
|
|||
LoadingScreen_MouseDown, LoadingScreen_MouseUp, LoadingScreen_MouseMove, LoadingScreen_MouseScroll,
|
||||
LoadingScreen_OnResize, LoadingScreen_ContextLost, LoadingScreen_ContextRecreated,
|
||||
};
|
||||
struct Screen* GeneratingScreen_MakeInstance(void) {
|
||||
void GeneratingScreen_Show(void) {
|
||||
static const String title = String_FromConst("Generating level");
|
||||
static const String message = String_FromConst("Generating..");
|
||||
|
||||
struct Screen* s = LoadingScreen_MakeInstance(&title, &message);
|
||||
s->VTABLE = &GeneratingScreen_VTABLE;
|
||||
return s;
|
||||
LoadingScreen_Reset(&title, &message);
|
||||
LoadingScreen_Instance.VTABLE = &GeneratingScreen_VTABLE;
|
||||
Gui_SetActive((struct Screen*)&LoadingScreen_Instance);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ struct Widget;
|
|||
|
||||
void InventoryScreen_Show(void);
|
||||
void StatusScreen_Show(void);
|
||||
struct Screen* LoadingScreen_MakeInstance(const String* title, const String* message);
|
||||
struct Screen* GeneratingScreen_MakeInstance(void);
|
||||
void LoadingScreen_Show(const String* title, const String* message);
|
||||
void GeneratingScreen_Show(void);
|
||||
void HUDScreen_Show(void);
|
||||
void DisconnectScreen_Show(const String* title, const String* message);
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ static void SPConnection_BeginConnect(void) {
|
|||
Gen_Seed = Random_Next(&rnd, Int32_MaxValue);
|
||||
|
||||
Gui_FreeActive();
|
||||
Gui_SetActive(GeneratingScreen_MakeInstance());
|
||||
GeneratingScreen_Show();
|
||||
}
|
||||
|
||||
static char SPConnection_LastCol = '\0';
|
||||
|
@ -317,7 +317,7 @@ static void MPConnection_BeginConnect(void) {
|
|||
} else {
|
||||
String_Format2(&title, "Connecting to %s:%i..", &Server.IP, &Server.Port);
|
||||
Gui_FreeActive();
|
||||
Gui_SetActive(LoadingScreen_MakeInstance(&title, &String_Empty));
|
||||
LoadingScreen_Show(&title, &String_Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -313,7 +313,7 @@ void ScrollbarWidget_Create(struct ScrollbarWidget* w) {
|
|||
w->VTABLE = &ScrollbarWidget_VTABLE;
|
||||
w->width = SCROLL_WIDTH;
|
||||
w->totalRows = 0;
|
||||
w->topRow = 0;
|
||||
w->topRow = 0;
|
||||
w->scrollingAcc = 0.0f;
|
||||
w->draggingMouse = false;
|
||||
w->mouseOffset = 0;
|
||||
|
|
Loading…
Reference in a new issue