mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
List menus show page number, fixes #411
This commit is contained in:
parent
90f15bc994
commit
dc98bd64be
@ -21,6 +21,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override void Init() {
|
||||
font = new Font(game.FontName, 16, FontStyle.Bold);
|
||||
Keyboard.KeyRepeat = true;
|
||||
ContextRecreated();
|
||||
game.Graphics.ContextLost += ContextLost;
|
||||
game.Graphics.ContextRecreated += ContextRecreated;
|
||||
@ -35,6 +36,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override void Dispose() {
|
||||
font.Dispose();
|
||||
Keyboard.KeyRepeat = false;
|
||||
ContextLost();
|
||||
game.Graphics.ContextLost -= ContextLost;
|
||||
game.Graphics.ContextRecreated -= ContextRecreated;
|
||||
@ -53,8 +55,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
MakeBack(false, font, SwitchPause),
|
||||
TextWidget.Create(game, titleText, font)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -155),
|
||||
TextWidget.Create(game, "", font)
|
||||
.SetLocation(Anchor.Centre, Anchor.Max, 0, 75),
|
||||
};
|
||||
UpdateArrows();
|
||||
UpdatePage();
|
||||
}
|
||||
|
||||
void MoveBackwards(Game g, Widget w) { PageClick(false); }
|
||||
@ -93,20 +97,24 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
for (int i = 0; i < items; i++) {
|
||||
UpdateText((ButtonWidget)widgets[i], Get(currentIndex + i));
|
||||
}
|
||||
UpdateArrows();
|
||||
UpdatePage();
|
||||
}
|
||||
|
||||
protected virtual void UpdateText(ButtonWidget widget, string text) {
|
||||
widget.SetText(text);
|
||||
}
|
||||
|
||||
void UpdateArrows() {
|
||||
widgets[5].Disabled = false;
|
||||
widgets[6].Disabled = false;
|
||||
if (currentIndex < items)
|
||||
widgets[5].Disabled = true;
|
||||
if (currentIndex >= entries.Length - items)
|
||||
widgets[6].Disabled = true;
|
||||
void UpdatePage() {
|
||||
int start = items, end = entries.Length - items;
|
||||
widgets[5].Disabled = currentIndex < start;
|
||||
widgets[6].Disabled = currentIndex >= end;
|
||||
if (game.ClassicMode) return;
|
||||
|
||||
TextWidget page = (TextWidget)widgets[9];
|
||||
int num = (currentIndex / items) + 1;
|
||||
int pages = Utils.CeilDiv(entries.Length, items);
|
||||
if (pages == 0) pages = 1;
|
||||
page.SetText("&7Page " + num + " of " + pages);
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown(Key key) {
|
||||
|
@ -40,8 +40,8 @@ struct ListScreen {
|
||||
Widget_LeftClick EntryClick;
|
||||
String TitleText;
|
||||
struct ButtonWidget Buttons[LIST_SCREEN_BUTTONS];
|
||||
struct TextWidget Title;
|
||||
struct Widget* Widgets[LIST_SCREEN_BUTTONS + 1];
|
||||
struct TextWidget Title, Page;
|
||||
struct Widget* Widgets[LIST_SCREEN_BUTTONS + 2];
|
||||
StringsBuffer Entries; /* NOTE: this is the last member so we can avoid memsetting it to 0 */
|
||||
};
|
||||
|
||||
@ -327,10 +327,20 @@ static void ListScreen_Make(struct ListScreen* screen, Int32 i, Int32 x, STRING_
|
||||
Widget_SetLocation((struct Widget*)btn, ANCHOR_CENTRE, ANCHOR_CENTRE, x, 0);
|
||||
}
|
||||
|
||||
static void ListScreen_UpdateArrows(struct ListScreen* screen) {
|
||||
static void ListScreen_UpdatePage(struct ListScreen* screen) {
|
||||
Int32 start = LIST_SCREEN_ITEMS, end = screen->Entries.Count - LIST_SCREEN_ITEMS;
|
||||
screen->Buttons[5].Disabled = screen->CurrentIndex < start;
|
||||
screen->Buttons[6].Disabled = screen->CurrentIndex >= end;
|
||||
if (Game_ClassicMode) return;
|
||||
|
||||
UInt8 pageBuffer[String_BufferSize(STRING_SIZE)];
|
||||
String page = String_InitAndClearArray(pageBuffer);
|
||||
Int32 num = (screen->CurrentIndex / LIST_SCREEN_ITEMS) + 1;
|
||||
Int32 pages = Math_CeilDiv(screen->Entries.Count, LIST_SCREEN_ITEMS);
|
||||
if (pages == 0) pages = 1;
|
||||
|
||||
String_Format2(&page, "&7Page %i of %i", &num, &pages);
|
||||
TextWidget_SetText(&screen->Page, &page);
|
||||
}
|
||||
|
||||
static void ListScreen_SetCurrentIndex(struct ListScreen* screen, Int32 index) {
|
||||
@ -344,7 +354,7 @@ static void ListScreen_SetCurrentIndex(struct ListScreen* screen, Int32 index) {
|
||||
}
|
||||
|
||||
screen->CurrentIndex = index;
|
||||
ListScreen_UpdateArrows(screen);
|
||||
ListScreen_UpdatePage(screen);
|
||||
}
|
||||
|
||||
static void ListScreen_PageClick(struct ListScreen* screen, bool forward) {
|
||||
@ -379,11 +389,17 @@ static void ListScreen_ContextRecreated(void* obj) {
|
||||
|
||||
Menu_MakeDefaultBack(&screen->Buttons[7], false, &screen->Font, Menu_SwitchPause);
|
||||
screen->Widgets[7] = (struct Widget*)(&screen->Buttons[7]);
|
||||
ListScreen_UpdateArrows(screen);
|
||||
|
||||
TextWidget_Create(&screen->Title, &screen->TitleText, &screen->Font);
|
||||
Widget_SetLocation((struct Widget*)(&screen->Title), ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -155);
|
||||
screen->Widgets[8] = (struct Widget*)(&screen->Title);
|
||||
|
||||
String text = String_MakeNull();
|
||||
TextWidget_Create(&screen->Page, &text, &screen->Font);
|
||||
Widget_SetLocation((struct Widget*)(&screen->Page), ANCHOR_CENTRE, ANCHOR_MAX, 0, 75);
|
||||
screen->Widgets[9] = (struct Widget*)(&screen->Page);
|
||||
|
||||
ListScreen_UpdatePage(screen);
|
||||
}
|
||||
|
||||
static void ListScreen_QuickSort(Int32 left, Int32 right) {
|
||||
@ -412,6 +428,7 @@ static String ListScreen_UNSAFE_GetCur(struct ListScreen* screen, struct GuiElem
|
||||
static void ListScreen_Init(struct GuiElem* elem) {
|
||||
struct ListScreen* screen = (struct ListScreen*)elem;
|
||||
Platform_FontMake(&screen->Font, &Game_FontName, 16, FONT_STYLE_BOLD);
|
||||
Key_KeyRepeat = true;
|
||||
screen->WheelAcc = 0.0f;
|
||||
ListScreen_ContextRecreated(screen);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, screen, ListScreen_ContextLost);
|
||||
@ -429,6 +446,7 @@ static void ListScreen_Render(struct GuiElem* elem, Real64 delta) {
|
||||
static void ListScreen_Free(struct GuiElem* elem) {
|
||||
struct ListScreen* screen = (struct ListScreen*)elem;
|
||||
Platform_FontFree(&screen->Font);
|
||||
Key_KeyRepeat = false;
|
||||
ListScreen_ContextLost(screen);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, screen, ListScreen_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, screen, ListScreen_ContextRecreated);
|
||||
|
Loading…
x
Reference in New Issue
Block a user