mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-12-31 20:11:27 +00:00
Added menus for public and private lobbies
This commit is contained in:
parent
4d3e150e2d
commit
fe2bb479ca
8 changed files with 355 additions and 235 deletions
|
@ -196,6 +196,9 @@ JOIN_TITLE = "JOIN"
|
|||
JOIN_DISCORD = "To join a \\#d0d0ff\\Discord\\#c8c8c8\\ lobby:\n\nKeep the game open and click the join button on the invite.\n\nIf the invite says that the game has ended, click the name of the person that sent the invite to refresh it."
|
||||
JOIN_SOCKET = "Enter \\#d0d0ff\\direct connection\\#c8c8c8\\ IP and port:"
|
||||
JOIN = "Join"
|
||||
PUBLIC_LOBBIES = "Public Lobbies"
|
||||
PRIVATE_LOBBIES = "Private Lobbies"
|
||||
DIRECT = "Direct Connection"
|
||||
|
||||
[MAIN]
|
||||
QUIT_TITLE = "QUIT"
|
||||
|
@ -323,3 +326,10 @@ ENV_VOLUME = "Env Volume"
|
|||
|
||||
[LANGUAGE]
|
||||
LANGUAGE = "LANGUAGE"
|
||||
|
||||
[LOBBIES]
|
||||
PUBLIC_LOBBIES = "PUBLIC LOBBIES"
|
||||
PRIVATE_LOBBIES = "PRIVATE LOBBIES"
|
||||
REFRESH = "Refresh"
|
||||
ENTER_PASSWORD = "Enter the private lobby's password:"
|
||||
SEARCH = "Search"
|
|
@ -1,250 +1,31 @@
|
|||
#include <stdio.h>
|
||||
#include "djui.h"
|
||||
#include "djui_panel.h"
|
||||
#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"
|
||||
#include "src/pc/network/socket/domain_res.h"
|
||||
#include "src/pc/utils/misc.h"
|
||||
#include "src/pc/configfile.h"
|
||||
#include "src/pc/debuglog.h"
|
||||
#include "macros.h"
|
||||
|
||||
static struct DjuiFlowLayout* sLobbyLayout = NULL;
|
||||
static struct DjuiInputbox* sInputboxIp = NULL;
|
||||
|
||||
static bool djui_panel_join_ip_parse_numbers(char** msg) {
|
||||
int num = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
char c = **msg;
|
||||
if (c >= '0' && c <= '9') {
|
||||
// is number
|
||||
num *= 10;
|
||||
num += (c - '0');
|
||||
*msg = *msg + 1;
|
||||
} else if (i == 0) {
|
||||
return false;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return num >= 0 && num <= 255;
|
||||
}
|
||||
|
||||
static bool djui_panel_join_ip_parse_period(char** msg) {
|
||||
char c = **msg;
|
||||
bool isPeriod = (c == '.');
|
||||
if (isPeriod) { *msg = *msg + 1; }
|
||||
return isPeriod;
|
||||
}
|
||||
|
||||
static bool djui_panel_join_ip_parse_spacer(char** msg) {
|
||||
char c = **msg;
|
||||
bool isSpacer = (c == ':' || c == ' ');
|
||||
if (isSpacer) { *msg = *msg + 1; }
|
||||
return isSpacer;
|
||||
}
|
||||
|
||||
static bool djui_panel_join_ip_parse_port(char** msg) {
|
||||
int port = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
char c = **msg;
|
||||
if (c >= '0' && c <= '9') {
|
||||
// is number
|
||||
port *= 10;
|
||||
port += (c - '0');
|
||||
*msg = *msg + 1;
|
||||
} else if (i == 0) {
|
||||
return false;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return port <= 65535;
|
||||
}
|
||||
|
||||
static bool djui_panel_join_ip_valid(char* buffer) {
|
||||
char** msg = &buffer;
|
||||
|
||||
if (!djui_panel_join_ip_parse_numbers(msg)) { return false; }
|
||||
if (!djui_panel_join_ip_parse_period(msg)) { return false; }
|
||||
if (!djui_panel_join_ip_parse_numbers(msg)) { return false; }
|
||||
if (!djui_panel_join_ip_parse_period(msg)) { return false; }
|
||||
if (!djui_panel_join_ip_parse_numbers(msg)) { return false; }
|
||||
if (!djui_panel_join_ip_parse_period(msg)) { return false; }
|
||||
if (!djui_panel_join_ip_parse_numbers(msg)) { return false; }
|
||||
if (djui_panel_join_ip_parse_spacer(msg)) {
|
||||
if (!djui_panel_join_ip_parse_port(msg)) { return false; }
|
||||
}
|
||||
|
||||
return (**msg == '\0');
|
||||
}
|
||||
|
||||
static void djui_panel_join_ip_text_change(struct DjuiBase* caller) {
|
||||
struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller;
|
||||
if (strlen(inputbox1->buffer) > 2) {
|
||||
djui_inputbox_set_text_color(inputbox1, 0, 0, 0, 255);
|
||||
} else {
|
||||
djui_inputbox_set_text_color(inputbox1, 255, 0, 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
static void djui_panel_join_ip_text_set_new(void) {
|
||||
char buffer[256] = { 0 };
|
||||
if (snprintf(buffer, 256, "%s", sInputboxIp->buffer) < 0) {
|
||||
LOG_INFO("truncating IP");
|
||||
}
|
||||
|
||||
bool afterSpacer = false;
|
||||
int port = 0;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
if (buffer[i] == ' ' || buffer[i] == ':') {
|
||||
buffer[i] = '\0';
|
||||
afterSpacer = true;
|
||||
} else if (buffer[i] == '\0') {
|
||||
break;
|
||||
} else if (afterSpacer && buffer[i] >= '0' && buffer[i] <= '9') {
|
||||
port *= 10;
|
||||
port += buffer[i] - '0';
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", buffer);
|
||||
if (snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", buffer) < 0) {
|
||||
LOG_INFO("truncating IP");
|
||||
}
|
||||
if (port >= 1 && port <= 65535) {
|
||||
configJoinPort = port;
|
||||
} else {
|
||||
configJoinPort = DEFAULT_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
static void djui_panel_join_ip_text_set(struct DjuiInputbox* inputbox1) {
|
||||
char buffer[256] = { 0 };
|
||||
if (strlen(configJoinIp) > 0 && configJoinPort != DEFAULT_PORT) {
|
||||
if (snprintf(buffer, 256, "%s:%d", configJoinIp, configJoinPort) < 0) { LOG_INFO("truncating IP"); }
|
||||
} else if (strlen(configJoinIp) > 0) {
|
||||
if (snprintf(buffer, 256, "%s", configJoinIp) < 0) { LOG_INFO("truncating IP"); }
|
||||
} else {
|
||||
if (snprintf(buffer, 256, "localhost") < 0) { LOG_INFO("truncating IP"); }
|
||||
}
|
||||
|
||||
djui_inputbox_set_text(inputbox1, buffer);
|
||||
}
|
||||
|
||||
void djui_panel_join_do_join(struct DjuiBase* caller) {
|
||||
if (!(strlen(sInputboxIp->buffer) > 2)) {
|
||||
djui_interactable_set_input_focus(&sInputboxIp->base);
|
||||
djui_inputbox_select_all(sInputboxIp);
|
||||
return;
|
||||
}
|
||||
network_reset_reconnect_and_rehost();
|
||||
djui_panel_join_ip_text_set_new();
|
||||
network_set_system(NS_SOCKET);
|
||||
network_init(NT_CLIENT);
|
||||
djui_panel_join_message_create(caller);
|
||||
}
|
||||
#include "djui_panel_join_lobbies.h"
|
||||
#include "djui_panel_join_private.h"
|
||||
#include "djui_panel_join_direct.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/utils/misc.h"
|
||||
|
||||
#ifdef COOPNET
|
||||
void djui_panel_join_lobby(struct DjuiBase* caller) {
|
||||
gCoopNetDesiredLobby = (uint64_t)caller->tag;
|
||||
network_reset_reconnect_and_rehost();
|
||||
network_set_system(NS_COOPNET);
|
||||
network_init(NT_CLIENT);
|
||||
djui_panel_join_message_create(caller);
|
||||
}
|
||||
|
||||
void djui_panel_join_query(uint64_t aLobbyId, UNUSED uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, UNUSED const char* aGame, UNUSED const char* aVersion, const char* aHostName, const char* aMode) {
|
||||
char playerText[64];
|
||||
snprintf(playerText, 63, "%u/%u", aConnections, aMaxConnections);
|
||||
|
||||
struct DjuiBase* layoutBase = &sLobbyLayout->base;
|
||||
struct DjuiLobbyEntry* entry = djui_lobby_entry_create(layoutBase, (char*)aHostName, (char*)aMode, playerText, djui_panel_join_lobby);
|
||||
entry->base.tag = (s64)aLobbyId;
|
||||
|
||||
/*struct DjuiPaginated* paginated = (struct DjuiPaginated*)layoutBase->parent;
|
||||
djui_paginated_calculate_height(paginated);*/
|
||||
static void djui_panel_join_public_lobbies(struct DjuiBase* caller) {
|
||||
djui_panel_join_lobbies_create(caller, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
void djui_panel_join_create(struct DjuiBase* caller) {
|
||||
|
||||
#ifdef COOPNET
|
||||
ns_coopnet_query(djui_panel_join_query, "");
|
||||
#endif
|
||||
|
||||
struct DjuiBase* defaultBase = NULL;
|
||||
#ifndef COOPNET
|
||||
djui_panel_join_direct_create(caller);
|
||||
#else
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(JOIN, JOIN_TITLE));
|
||||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
{
|
||||
|
||||
struct DjuiPaginated* paginated = djui_paginated_create(body, 8);
|
||||
sLobbyLayout = paginated->layout;
|
||||
djui_flow_layout_set_margin(sLobbyLayout, 4);
|
||||
|
||||
#if 0
|
||||
struct DjuiBase* layoutBase = &sLobbyLayout->base;
|
||||
for (int i = 0; i < 1; i++) {
|
||||
djui_lobby_entry_create(layoutBase, "MysterD", "Super Mario 64", "15/16", NULL);
|
||||
djui_lobby_entry_create(layoutBase, "djoslin0", "Star Road", "1/16", NULL);
|
||||
djui_lobby_entry_create(layoutBase, "abcdefghijklmnopqrs", "Snowstorm Avalanche", "16/16", NULL);
|
||||
djui_lobby_entry_create(layoutBase, "Prince Frizzy", "Hide and Seek", "4/16", NULL);
|
||||
djui_lobby_entry_create(layoutBase, "Sunk", "Super Mario 74 (+EE)", "5/8", NULL);
|
||||
}
|
||||
djui_paginated_calculate_height(paginated);
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifdef DISCORD_SDK
|
||||
struct DjuiText* text1 = djui_text_create(body, DLANG(JOIN, JOIN_DISCORD));
|
||||
djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&text1->base, 1.0f, 100);
|
||||
djui_base_compute_tree(&text1->base);
|
||||
u16 discordLines = djui_text_count_lines(text1, 12);
|
||||
f32 discordTextHeight = 32 * 0.8125f * discordLines + 8;
|
||||
djui_base_set_size(&text1->base, 1.0f, discordTextHeight);
|
||||
djui_base_set_color(&text1->base, 200, 200, 200, 255);
|
||||
#endif
|
||||
struct DjuiRect* rect1 = djui_rect_create(body);
|
||||
djui_base_set_size_type(&rect1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&rect1->base, 1.0f, 2);
|
||||
djui_base_set_color(&rect1->base, 150, 150, 150, 255);
|
||||
|
||||
struct DjuiText* text2 = djui_text_create(body, DLANG(JOIN, JOIN_SOCKET));
|
||||
djui_base_set_size_type(&text2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&text2->base, 1.0f, 100);
|
||||
djui_base_compute_tree(&text2->base);
|
||||
u16 directLines = djui_text_count_lines(text2, 12);
|
||||
f32 directTextHeight = 32 * 0.8125f * directLines + 8;
|
||||
djui_base_set_size(&text2->base, 1.0f, directTextHeight);
|
||||
djui_base_set_color(&text2->base, 200, 200, 200, 255);*/
|
||||
|
||||
struct DjuiInputbox* inputbox1 = djui_inputbox_create(body, 256);
|
||||
djui_base_set_size_type(&inputbox1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&inputbox1->base, 1.0f, 32.0f);
|
||||
djui_interactable_hook_value_change(&inputbox1->base, djui_panel_join_ip_text_change);
|
||||
sInputboxIp = inputbox1;
|
||||
djui_panel_join_ip_text_set(inputbox1);
|
||||
|
||||
struct DjuiRect* rect2 = djui_rect_container_create(body, 64);
|
||||
{
|
||||
struct DjuiButton* button1 = djui_button_create(&rect2->base, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
|
||||
djui_base_set_size(&button1->base, 0.485f, 64);
|
||||
djui_base_set_alignment(&button1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
|
||||
|
||||
struct DjuiButton* button2 = djui_button_create(&rect2->base, DLANG(JOIN, JOIN), DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_do_join);
|
||||
djui_base_set_size(&button2->base, 0.485f, 64);
|
||||
djui_base_set_alignment(&button2->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
|
||||
defaultBase = &button2->base;
|
||||
}
|
||||
djui_button_create(body, DLANG(JOIN, PUBLIC_LOBBIES), DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_public_lobbies);
|
||||
djui_button_create(body, DLANG(JOIN, PRIVATE_LOBBIES), DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_private_create);
|
||||
djui_button_create(body, DLANG(JOIN, DIRECT), DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_direct_create);
|
||||
djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
|
||||
}
|
||||
|
||||
djui_panel_add(caller, panel, defaultBase);
|
||||
djui_panel_add(caller, panel, NULL);
|
||||
#endif
|
||||
}
|
||||
|
|
189
src/pc/djui/djui_panel_join_direct.c
Normal file
189
src/pc/djui/djui_panel_join_direct.c
Normal file
|
@ -0,0 +1,189 @@
|
|||
#include <stdio.h>
|
||||
#include "djui.h"
|
||||
#include "djui_panel.h"
|
||||
#include "djui_panel_menu.h"
|
||||
#include "djui_panel_modlist.h"
|
||||
#include "djui_panel_join_message.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"
|
||||
#include "src/pc/network/socket/domain_res.h"
|
||||
#include "src/pc/utils/misc.h"
|
||||
#include "src/pc/configfile.h"
|
||||
#include "src/pc/debuglog.h"
|
||||
#include "macros.h"
|
||||
|
||||
static struct DjuiInputbox* sInputboxIp = NULL;
|
||||
|
||||
static bool djui_panel_join_direct_ip_parse_numbers(char** msg) {
|
||||
int num = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
char c = **msg;
|
||||
if (c >= '0' && c <= '9') {
|
||||
// is number
|
||||
num *= 10;
|
||||
num += (c - '0');
|
||||
*msg = *msg + 1;
|
||||
} else if (i == 0) {
|
||||
return false;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return num >= 0 && num <= 255;
|
||||
}
|
||||
|
||||
static bool djui_panel_join_direct_ip_parse_period(char** msg) {
|
||||
char c = **msg;
|
||||
bool isPeriod = (c == '.');
|
||||
if (isPeriod) { *msg = *msg + 1; }
|
||||
return isPeriod;
|
||||
}
|
||||
|
||||
static bool djui_panel_join_direct_ip_parse_spacer(char** msg) {
|
||||
char c = **msg;
|
||||
bool isSpacer = (c == ':' || c == ' ');
|
||||
if (isSpacer) { *msg = *msg + 1; }
|
||||
return isSpacer;
|
||||
}
|
||||
|
||||
static bool djui_panel_join_direct_ip_parse_port(char** msg) {
|
||||
int port = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
char c = **msg;
|
||||
if (c >= '0' && c <= '9') {
|
||||
// is number
|
||||
port *= 10;
|
||||
port += (c - '0');
|
||||
*msg = *msg + 1;
|
||||
} else if (i == 0) {
|
||||
return false;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return port <= 65535;
|
||||
}
|
||||
|
||||
static bool djui_panel_join_direct_ip_valid(char* buffer) {
|
||||
char** msg = &buffer;
|
||||
|
||||
if (!djui_panel_join_direct_ip_parse_numbers(msg)) { return false; }
|
||||
if (!djui_panel_join_direct_ip_parse_period(msg)) { return false; }
|
||||
if (!djui_panel_join_direct_ip_parse_numbers(msg)) { return false; }
|
||||
if (!djui_panel_join_direct_ip_parse_period(msg)) { return false; }
|
||||
if (!djui_panel_join_direct_ip_parse_numbers(msg)) { return false; }
|
||||
if (!djui_panel_join_direct_ip_parse_period(msg)) { return false; }
|
||||
if (!djui_panel_join_direct_ip_parse_numbers(msg)) { return false; }
|
||||
if (djui_panel_join_direct_ip_parse_spacer(msg)) {
|
||||
if (!djui_panel_join_direct_ip_parse_port(msg)) { return false; }
|
||||
}
|
||||
|
||||
return (**msg == '\0');
|
||||
}
|
||||
|
||||
static void djui_panel_join_direct_ip_text_change(struct DjuiBase* caller) {
|
||||
struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller;
|
||||
if (strlen(inputbox1->buffer) > 2) {
|
||||
djui_inputbox_set_text_color(inputbox1, 0, 0, 0, 255);
|
||||
} else {
|
||||
djui_inputbox_set_text_color(inputbox1, 255, 0, 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
static void djui_panel_join_direct_ip_text_set_new(void) {
|
||||
char buffer[256] = { 0 };
|
||||
if (snprintf(buffer, 256, "%s", sInputboxIp->buffer) < 0) {
|
||||
LOG_INFO("truncating IP");
|
||||
}
|
||||
|
||||
bool afterSpacer = false;
|
||||
int port = 0;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
if (buffer[i] == ' ' || buffer[i] == ':') {
|
||||
buffer[i] = '\0';
|
||||
afterSpacer = true;
|
||||
} else if (buffer[i] == '\0') {
|
||||
break;
|
||||
} else if (afterSpacer && buffer[i] >= '0' && buffer[i] <= '9') {
|
||||
port *= 10;
|
||||
port += buffer[i] - '0';
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", buffer);
|
||||
if (snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", buffer) < 0) {
|
||||
LOG_INFO("truncating IP");
|
||||
}
|
||||
if (port >= 1 && port <= 65535) {
|
||||
configJoinPort = port;
|
||||
} else {
|
||||
configJoinPort = DEFAULT_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
static void djui_panel_join_direct_ip_text_set(struct DjuiInputbox* inputbox1) {
|
||||
char buffer[256] = { 0 };
|
||||
if (strlen(configJoinIp) > 0 && configJoinPort != DEFAULT_PORT) {
|
||||
if (snprintf(buffer, 256, "%s:%d", configJoinIp, configJoinPort) < 0) { LOG_INFO("truncating IP"); }
|
||||
} else if (strlen(configJoinIp) > 0) {
|
||||
if (snprintf(buffer, 256, "%s", configJoinIp) < 0) { LOG_INFO("truncating IP"); }
|
||||
} else {
|
||||
if (snprintf(buffer, 256, "localhost") < 0) { LOG_INFO("truncating IP"); }
|
||||
}
|
||||
|
||||
djui_inputbox_set_text(inputbox1, buffer);
|
||||
}
|
||||
|
||||
void djui_panel_join_direct_do_join(struct DjuiBase* caller) {
|
||||
if (!(strlen(sInputboxIp->buffer) > 2)) {
|
||||
djui_interactable_set_input_focus(&sInputboxIp->base);
|
||||
djui_inputbox_select_all(sInputboxIp);
|
||||
return;
|
||||
}
|
||||
network_reset_reconnect_and_rehost();
|
||||
djui_panel_join_direct_ip_text_set_new();
|
||||
network_set_system(NS_SOCKET);
|
||||
network_init(NT_CLIENT);
|
||||
djui_panel_join_message_create(caller);
|
||||
}
|
||||
|
||||
void djui_panel_join_direct_create(struct DjuiBase* caller) {
|
||||
struct DjuiBase* defaultBase = NULL;
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(JOIN, JOIN_TITLE));
|
||||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
{
|
||||
struct DjuiText* text1 = djui_text_create(body, DLANG(JOIN, JOIN_SOCKET));
|
||||
djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&text1->base, 1.0f, 100);
|
||||
djui_base_compute_tree(&text1->base);
|
||||
u16 directLines = djui_text_count_lines(text1, 12);
|
||||
f32 directTextHeight = 32 * 0.8125f * directLines + 8;
|
||||
djui_base_set_size(&text1->base, 1.0f, directTextHeight);
|
||||
djui_base_set_color(&text1->base, 200, 200, 200, 255);
|
||||
|
||||
struct DjuiInputbox* inputbox1 = djui_inputbox_create(body, 256);
|
||||
djui_base_set_size_type(&inputbox1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&inputbox1->base, 1.0f, 32.0f);
|
||||
djui_interactable_hook_value_change(&inputbox1->base, djui_panel_join_direct_ip_text_change);
|
||||
sInputboxIp = inputbox1;
|
||||
djui_panel_join_direct_ip_text_set(inputbox1);
|
||||
|
||||
struct DjuiRect* rect2 = djui_rect_container_create(body, 64);
|
||||
{
|
||||
struct DjuiButton* button1 = djui_button_create(&rect2->base, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
|
||||
djui_base_set_size(&button1->base, 0.485f, 64);
|
||||
djui_base_set_alignment(&button1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
|
||||
|
||||
struct DjuiButton* button2 = djui_button_create(&rect2->base, DLANG(JOIN, JOIN), DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_direct_do_join);
|
||||
djui_base_set_size(&button2->base, 0.485f, 64);
|
||||
djui_base_set_alignment(&button2->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
|
||||
defaultBase = &button2->base;
|
||||
}
|
||||
}
|
||||
|
||||
djui_panel_add(caller, panel, defaultBase);
|
||||
}
|
3
src/pc/djui/djui_panel_join_direct.h
Normal file
3
src/pc/djui/djui_panel_join_direct.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void djui_panel_join_direct_create(struct DjuiBase* caller);
|
78
src/pc/djui/djui_panel_join_lobbies.c
Normal file
78
src/pc/djui/djui_panel_join_lobbies.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include <stdio.h>
|
||||
#include "djui.h"
|
||||
#include "djui_panel.h"
|
||||
#include "djui_panel_menu.h"
|
||||
#include "djui_panel_join_message.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"
|
||||
#include "src/pc/utils/misc.h"
|
||||
#include "src/pc/configfile.h"
|
||||
#include "src/pc/debuglog.h"
|
||||
#include "macros.h"
|
||||
|
||||
#ifdef COOPNET
|
||||
|
||||
static struct DjuiFlowLayout* sLobbyLayout = NULL;
|
||||
|
||||
void djui_panel_join_lobby(struct DjuiBase* caller) {
|
||||
gCoopNetDesiredLobby = (uint64_t)caller->tag;
|
||||
network_reset_reconnect_and_rehost();
|
||||
network_set_system(NS_COOPNET);
|
||||
network_init(NT_CLIENT);
|
||||
djui_panel_join_message_create(caller);
|
||||
}
|
||||
|
||||
void djui_panel_join_query(uint64_t aLobbyId, UNUSED uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, UNUSED const char* aGame, UNUSED const char* aVersion, const char* aHostName, const char* aMode) {
|
||||
char playerText[64];
|
||||
snprintf(playerText, 63, "%u/%u", aConnections, aMaxConnections);
|
||||
|
||||
struct DjuiBase* layoutBase = &sLobbyLayout->base;
|
||||
struct DjuiLobbyEntry* entry = djui_lobby_entry_create(layoutBase, (char*)aHostName, (char*)aMode, playerText, djui_panel_join_lobby);
|
||||
entry->base.tag = (s64)aLobbyId;
|
||||
}
|
||||
|
||||
void djui_panel_join_lobbies_create(struct DjuiBase* caller, const char* password) {
|
||||
|
||||
bool private = (strlen(password) > 0);
|
||||
ns_coopnet_query(djui_panel_join_query, password);
|
||||
|
||||
struct DjuiBase* defaultBase = NULL;
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(private ? DLANG(LOBBIES, PRIVATE_LOBBIES) : DLANG(LOBBIES, PUBLIC_LOBBIES));
|
||||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
{
|
||||
|
||||
struct DjuiPaginated* paginated = djui_paginated_create(body, 8);
|
||||
sLobbyLayout = paginated->layout;
|
||||
djui_flow_layout_set_margin(sLobbyLayout, 4);
|
||||
|
||||
#if 0
|
||||
struct DjuiBase* layoutBase = &sLobbyLayout->base;
|
||||
for (int i = 0; i < 1; i++) {
|
||||
djui_lobby_entry_create(layoutBase, "MysterD", "Super Mario 64", "15/16", NULL);
|
||||
djui_lobby_entry_create(layoutBase, "djoslin0", "Star Road", "1/16", NULL);
|
||||
djui_lobby_entry_create(layoutBase, "abcdefghijklmnopqrs", "Snowstorm Avalanche", "16/16", NULL);
|
||||
djui_lobby_entry_create(layoutBase, "Prince Frizzy", "Hide and Seek", "4/16", NULL);
|
||||
djui_lobby_entry_create(layoutBase, "Sunk", "Super Mario 74 (+EE)", "5/8", NULL);
|
||||
}
|
||||
djui_paginated_calculate_height(paginated);
|
||||
#endif
|
||||
|
||||
struct DjuiRect* rect2 = djui_rect_container_create(body, 64);
|
||||
{
|
||||
struct DjuiButton* button1 = djui_button_create(&rect2->base, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
|
||||
djui_base_set_size(&button1->base, 0.485f, 64);
|
||||
djui_base_set_alignment(&button1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
|
||||
|
||||
struct DjuiButton* button2 = djui_button_create(&rect2->base, DLANG(LOBBIES, REFRESH), DJUI_BUTTON_STYLE_NORMAL, NULL);
|
||||
djui_base_set_size(&button2->base, 0.485f, 64);
|
||||
djui_base_set_alignment(&button2->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
|
||||
defaultBase = &button2->base;
|
||||
}
|
||||
}
|
||||
|
||||
djui_panel_add(caller, panel, defaultBase);
|
||||
}
|
||||
|
||||
#endif
|
3
src/pc/djui/djui_panel_join_lobbies.h
Normal file
3
src/pc/djui/djui_panel_join_lobbies.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void djui_panel_join_lobbies_create(struct DjuiBase* caller, const char* password);
|
53
src/pc/djui/djui_panel_join_private.c
Normal file
53
src/pc/djui/djui_panel_join_private.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "djui.h"
|
||||
#include "djui_panel.h"
|
||||
#include "djui_panel_menu.h"
|
||||
#include "djui_panel_join_lobbies.h"
|
||||
#include "djui_panel_join_private.h"
|
||||
#include "djui_panel_join_direct.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/utils/misc.h"
|
||||
|
||||
#ifdef COOPNET
|
||||
|
||||
static struct DjuiInputbox* sInputboxPassword = NULL;
|
||||
|
||||
static void djui_panel_join_private_lobbies(struct DjuiBase* caller) {
|
||||
djui_panel_join_lobbies_create(caller, sInputboxPassword->buffer);
|
||||
}
|
||||
|
||||
void djui_panel_join_private_create(struct DjuiBase* caller) {
|
||||
struct DjuiBase* defaultBase = NULL;
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(LOBBIES, PRIVATE_LOBBIES));
|
||||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
{
|
||||
struct DjuiText* text1 = djui_text_create(body, DLANG(LOBBIES, ENTER_PASSWORD));
|
||||
djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&text1->base, 1.0f, 100);
|
||||
djui_base_compute_tree(&text1->base);
|
||||
u16 directLines = djui_text_count_lines(text1, 12);
|
||||
f32 directTextHeight = 32 * 0.8125f * directLines + 8;
|
||||
djui_base_set_size(&text1->base, 1.0f, directTextHeight);
|
||||
djui_base_set_color(&text1->base, 200, 200, 200, 255);
|
||||
|
||||
struct DjuiInputbox* inputbox1 = djui_inputbox_create(body, 256);
|
||||
djui_base_set_size_type(&inputbox1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&inputbox1->base, 1.0f, 32.0f);
|
||||
sInputboxPassword = inputbox1;
|
||||
|
||||
struct DjuiRect* rect2 = djui_rect_container_create(body, 64);
|
||||
{
|
||||
struct DjuiButton* button1 = djui_button_create(&rect2->base, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
|
||||
djui_base_set_size(&button1->base, 0.485f, 64);
|
||||
djui_base_set_alignment(&button1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
|
||||
|
||||
struct DjuiButton* button2 = djui_button_create(&rect2->base, DLANG(LOBBIES, SEARCH), DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_private_lobbies);
|
||||
djui_base_set_size(&button2->base, 0.485f, 64);
|
||||
djui_base_set_alignment(&button2->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
|
||||
defaultBase = &button2->base;
|
||||
}
|
||||
}
|
||||
|
||||
djui_panel_add(caller, panel, defaultBase);
|
||||
}
|
||||
|
||||
#endif
|
3
src/pc/djui/djui_panel_join_private.h
Normal file
3
src/pc/djui/djui_panel_join_private.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void djui_panel_join_private_create(struct DjuiBase* caller);
|
Loading…
Reference in a new issue