Closed StrikerMan780 closed 1 week ago
Use nk_console_render_window() instead and change the title paraameter?
const char* title = "Window Title";
nk_console_render_window(console, title, nk_rect(0, 0, (float)screen->width, (float)screen->height), NK_WINDOW_TITLE);
nk_console_render() is meant to be used within a nk_begin()/end(), where as render_window takes control over the nk_begin stuffs.
I mean, that's what I'm using (I was never using nk_console_render on its own to begin with), but the menu setup is only done once at program init, so I'm wondering how I'm going to make it pass the title to it as it switches between menus. Perhaps an event for when you transition between menus is in order?
nk_console_render_window(console, title, nk_rect(menu_x, menu_y - (scale_y(300, 480) / 2.0f), menu_width, scale_y(300, 480)), NK_WINDOW_TITLE | NK_WINDOW_BORDER);
This is what my Init function looks like:
// Init Console
console = nk_console_init(&ctx);
nk_console_button_onclick(console, "New Game", UIFunc_NewGame);
nk_console_button(console, "Load Game");
nk_console_button(console, "Save Game");
nk_console_button(console, "Multiplayer");
nk_console* options = nk_console_button(console, "Options");
{
nk_console_button(options, "Game Options");
nk_console_button(options, "Video Options");
nk_console_button(options, "Sound Options");
nk_console_button(options, "Controls");
nk_console_button_onclick(options, "Back", nk_console_button_back);
}
nk_console_button(console, "Instructions");
nk_console_button(console, "Editor");
nk_console* quitmenu = nk_console_button(console, "Quit");
{
nk_console_label(quitmenu, "Are you sure?");
nk_console_button_onclick(quitmenu, "Yes", UIFunc_QuitGame);
nk_console_button_onclick(quitmenu, "No", nk_console_button_back);
}
Hmm, I got around it by setting up an onclicked event, which sets the parent menu itself, and sets the title variable to the label of the button. Also wrote a wrapper to the back function that sets the title to the parent menu label.
EDIT: Though, I just realized, that doesn't account for the backspace key or B button on the controller. An event/callback is looking to be even more appealing. One that gives you a pointer to the menu you're switching to. (And some way to differentiate if you're going forwards or back would be nice, so I can use that to play different sounds for those transitions)
EDIT2: Did this, which I call from the menu loop. Hopefully it isn't too slow:
void UI_CheckMenuChange()
{
nk_console* activeParent = nk_console_active_parent(console);
if (activeParent == NULL)
return;
if (activeParent != currentMenu)
{
if (activeParent == currentMenu->parent)
{
playSFX("laser3.wav");
}
else
{
playSFX("beep.wav");
}
currentMenu = activeParent;
tfury_menu_title = activeParent->label;
}
}
pew pew pew pew pew pew pew pew pew BEEP!
Sounds like you got it fixed up. Thanks!
Apologies for asking so many questions, but is there a way to change the window title while you switch between pages in a menu? Wanting to have the title bar change as one switches through the Main Menu, Options, Save/Load, etc.