mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 03:55:11 +00:00
WIP: lobby browser
This commit is contained in:
parent
7fac22c265
commit
1027fdc361
3 changed files with 110 additions and 7 deletions
81
src/pc/djui/djui_lobby_entry.c
Normal file
81
src/pc/djui/djui_lobby_entry.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "djui.h"
|
||||
#include "djui_lobby_entry.h"
|
||||
|
||||
#define VK_ESCAPE 1
|
||||
|
||||
static void djui_lobby_entry_update_style(struct DjuiBase* base) {
|
||||
struct DjuiLobbyEntry* entry = (struct DjuiLobbyEntry*)base;
|
||||
if (!entry->base.enabled) {
|
||||
u8 borderBrightness = 75;
|
||||
u8 rectBrightness = 111;
|
||||
djui_base_set_border_color(base, borderBrightness, borderBrightness, borderBrightness, 255);
|
||||
djui_base_set_color(&entry->base, rectBrightness, rectBrightness, rectBrightness, 255);
|
||||
//djui_base_set_location(&entry->text->base, 0.0f, 0.0f);
|
||||
} else if (gDjuiCursorDownOn == base) {
|
||||
djui_base_set_border_color(base, 0, 84, 153, 255);
|
||||
djui_base_set_color(&entry->base, 204, 228, 247, 255);
|
||||
//djui_base_set_location(&entry->text->base, 1.0f, 1.0f);
|
||||
} else if (gDjuiHovered == base) {
|
||||
djui_base_set_border_color(base, 0, 120, 215, 255);
|
||||
djui_base_set_color(&entry->base, 229, 241, 251, 255);
|
||||
//djui_base_set_location(&entry->text->base, -1.0f, -1.0f);
|
||||
} else {
|
||||
u8 borderBrightness = 150;
|
||||
u8 rectBrightness = 222;
|
||||
djui_base_set_border_color(base, borderBrightness, borderBrightness, borderBrightness, 255);
|
||||
djui_base_set_color(&entry->base, rectBrightness, rectBrightness, rectBrightness, 255);
|
||||
//djui_base_set_location(&entry->text->base, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
static void djui_lobby_entry_destroy(struct DjuiBase* base) {
|
||||
struct DjuiLobbyEntry* lobbyEntry = (struct DjuiLobbyEntry*)base;
|
||||
free(lobbyEntry);
|
||||
}
|
||||
|
||||
struct DjuiLobbyEntry* djui_lobby_entry_create(struct DjuiBase* parent, char* host, char* mode, char* players, void (*on_click)(struct DjuiBase*)) {
|
||||
struct DjuiLobbyEntry* lobbyEntry = calloc(1, sizeof(struct DjuiLobbyEntry));
|
||||
struct DjuiBase* base = &lobbyEntry->base;
|
||||
|
||||
djui_base_init(parent, base, djui_rect_render, djui_lobby_entry_destroy);
|
||||
djui_base_set_size_type(&lobbyEntry->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&lobbyEntry->base, 1.0f, 32);
|
||||
djui_base_set_color(&lobbyEntry->base, 255, 255, 255, 128);
|
||||
djui_base_set_border_color(&lobbyEntry->base, 128, 128, 128, 255);
|
||||
djui_base_set_border_width(&lobbyEntry->base, 2);
|
||||
djui_base_set_border_width_type(&lobbyEntry->base, DJUI_SVT_ABSOLUTE);
|
||||
djui_interactable_create(base, djui_lobby_entry_update_style);
|
||||
djui_interactable_hook_click(base, on_click);
|
||||
|
||||
u8 numColumns = 3;
|
||||
f32 x = 0;
|
||||
for (int i = 0; i < numColumns; i++) {
|
||||
char* msg = NULL;
|
||||
f32 width = 0;
|
||||
switch (i) {
|
||||
case 0: msg = host; width = 0.4f; break;
|
||||
case 1: msg = mode; width = 0.45f; break;
|
||||
case 2: msg = players; width = 0.15f; break;
|
||||
}
|
||||
struct DjuiText* text = djui_text_create(&lobbyEntry->base, msg);
|
||||
|
||||
djui_base_set_alignment(&text->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_CENTER);
|
||||
|
||||
djui_base_set_location_type(&text->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
|
||||
djui_base_set_location(&text->base, x, 0.0f);
|
||||
|
||||
djui_base_set_size_type(&text->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
|
||||
djui_base_set_size(&text->base, width, 1.0f);
|
||||
|
||||
djui_base_set_color(&text->base, 11, 11, 11, 255);
|
||||
djui_text_set_alignment(&text->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
|
||||
djui_text_set_drop_shadow(text, 64, 64, 64, 100);
|
||||
x += width;
|
||||
}
|
||||
|
||||
djui_lobby_entry_update_style(base);
|
||||
|
||||
return lobbyEntry;
|
||||
}
|
8
src/pc/djui/djui_lobby_entry.h
Normal file
8
src/pc/djui/djui_lobby_entry.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
#include "djui.h"
|
||||
|
||||
struct DjuiLobbyEntry {
|
||||
struct DjuiBase base;
|
||||
};
|
||||
|
||||
struct DjuiLobbyEntry* djui_lobby_entry_create(struct DjuiBase* parent, char* host, char* mode, char* players, void (*on_click)(struct DjuiBase*));
|
|
@ -4,6 +4,7 @@
|
|||
#include "djui_panel_menu.h"
|
||||
#include "djui_panel_join_message.h"
|
||||
#include "djui_panel_modlist.h"
|
||||
#include "djui_lobby_entry.h"
|
||||
#include "src/pc/network/network.h"
|
||||
#include "src/pc/network/socket/socket.h"
|
||||
#include "src/pc/network/coopnet/coopnet.h"
|
||||
|
@ -160,15 +161,15 @@ void djui_panel_join_lobby(struct DjuiBase* caller) {
|
|||
}
|
||||
|
||||
void djui_panel_join_query(uint64_t aLobbyId, uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, const char* aGame, const char* aVersion, const char* aTitle) {
|
||||
char text[256];
|
||||
snprintf(text, 255, "%s - %u/%u", aTitle, aConnections, aMaxConnections);
|
||||
char playerText[64];
|
||||
snprintf(playerText, 63, "%u/%u", aConnections, aMaxConnections);
|
||||
|
||||
bool btrue = TRUE;
|
||||
struct DjuiBase* layoutBase = &sLobbyLayout->base;
|
||||
struct DjuiButton* button = djui_button_create(layoutBase, text, DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_lobby);
|
||||
button->base.tag = (s64)aLobbyId;
|
||||
djui_base_set_size_type(&button->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&button->base, 1.0f, 32);
|
||||
struct DjuiLobbyEntry* entry = djui_lobby_entry_create(layoutBase, (char*)aTitle, "Super Mario 64", playerText, djui_panel_join_lobby);
|
||||
entry->base.tag = (s64)aLobbyId;
|
||||
|
||||
struct DjuiPaginated* paginated = (struct DjuiPaginated*)layoutBase->parent;
|
||||
djui_paginated_calculate_height(paginated);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -185,6 +186,19 @@ void djui_panel_join_create(struct DjuiBase* caller) {
|
|||
|
||||
struct DjuiPaginated* paginated = djui_paginated_create(body, 8);
|
||||
sLobbyLayout = paginated->layout;
|
||||
djui_flow_layout_set_margin(sLobbyLayout, 4);
|
||||
|
||||
struct DjuiBase* layoutBase = &sLobbyLayout->base;
|
||||
#if 0
|
||||
for (int i = 0; i < 4; i++) {
|
||||
djui_lobby_entry_create(layoutBase, "MysterD", "Super Mario 64", "15/16");
|
||||
djui_lobby_entry_create(layoutBase, "djoslin0", "Star Road", "1/16");
|
||||
djui_lobby_entry_create(layoutBase, "abcdefghijklmnopqrs", "Snowstorm Avalanche", "16/16");
|
||||
djui_lobby_entry_create(layoutBase, "Prince Frizzy", "Hide and Seek", "4/16");
|
||||
djui_lobby_entry_create(layoutBase, "Sunk", "Super Mario 74 (+EE)", "5/8");
|
||||
}
|
||||
#endif
|
||||
//djui_paginated_calculate_height(paginated);
|
||||
|
||||
/*
|
||||
#ifdef DISCORD_SDK
|
||||
|
|
Loading…
Reference in a new issue