wip notifications + manager

efd/v1
Dominik Madarász 2023-01-16 14:05:15 +01:00
parent 847289c6de
commit 82a8bbdaf8
2 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,99 @@
#define MAX_NOTIFICATIONS_ON_SCREEN 5
typedef struct {
const char *title;
const char *text;
} notification;
static notification *notifications = 0;
static bool show_notification_list = 0;
void notification_push(const char* title, const char* text) {
if (!notifications) {
zpl_array_init(notifications, zpl_heap());
}
zpl_array_append(notifications, ((notification) { title, text }));
}
void notification_clear(void) {
zpl_array_clear(notifications);
}
void notification_draw(void) {
float height = (float)GetScreenHeight();
float width = (float)GetScreenWidth();
// draw ctrl panel
if (nk_begin(game_ui, "Notifications", nk_rect(width - 220, 20, 200, 80),
NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_TITLE | NK_WINDOW_DYNAMIC)) {
{
nk_layout_row_dynamic(game_ui, 0, 2);
if (nk_button_label(game_ui, "Clear All")) {
notification_clear();
}
if (nk_button_label(game_ui, show_notification_list ? "Hide Manager" : "Show All")) {
show_notification_list ^= 1;
}
}
nk_end(game_ui);
}
float ypos = 100;
zpl_isize cnt = zpl_min(zpl_array_count(notifications), MAX_NOTIFICATIONS_ON_SCREEN)-1;
for (zpl_isize i = cnt; i >= 0; --i) {
notification *notif = (notifications + i);
if (nk_begin_titled(game_ui, zpl_bprintf("%dnotif%s", i, notif->title), notif->title, nk_rect(width - 220, ypos, 200, 120),
NK_WINDOW_BORDER | NK_WINDOW_TITLE)) {
{
nk_layout_row_dynamic(game_ui, 0, 1);
nk_label_wrap(game_ui, notif->text);
if (nk_button_label(game_ui, "OK")) {
zpl_array_remove_at(notifications, i);
}
}
ypos += nk_window_get_height(game_ui) + 5;
nk_end(game_ui);
}
}
if (show_notification_list) {
if (nk_begin(game_ui, "Notifications Manager", nk_rect(width/2.0f - 320, height/2.0f - 240, 640, 480),
NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_TITLE | NK_WINDOW_MOVABLE | NK_WINDOW_DYNAMIC )) {
{
nk_layout_row_dynamic(game_ui, 5 , 1);
{
for (zpl_isize i = 0; i < zpl_array_count(notifications); ++i) {
notification *notif = (notifications + i);
if (nk_tree_push_id(game_ui, NK_TREE_TAB, notif->title, NK_MINIMIZED, (int)i)) {
{
nk_label_wrap(game_ui, notif->text);
if (nk_button_label(game_ui, "OK")) {
zpl_array_remove_at(notifications, i); --i;
}
}
nk_tree_pop(game_ui);
}
}
}
nk_layout_row_dynamic(game_ui, 0, 2);
if (nk_button_label(game_ui, "Clear All")) {
notification_clear();
}
if (nk_button_label(game_ui, "Hide Manager")) {
show_notification_list = 0 ;
}
}
nk_end(game_ui);
}
}
}

View File

@ -27,6 +27,7 @@ ZPL_DIAGNOSTIC_POP
// NOTE(zaklaus): add-ins
#include "gui/tooltip.c"
#include "gui/notifications.c"
#include "gui/build_mode.c"
#include "gui/inventory.c"
@ -49,6 +50,15 @@ void platform_init() {
tooltip_show("ASSET_FURNACE", mpos.x, mpos.y);
}
#endif
#if 1
// TEST
{
notification_push("test1", "Hello World!");
notification_push("test2", "Hello World! 2x");
notification_push("New connection", "A new player has joined the world!");
}
#endif
}
inline static
@ -205,6 +215,7 @@ void platform_render() {
inventory_draw();
// goes last
notification_draw();
tooltip_draw();
}
display_conn_status();