mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-05-10 10:51:39 +00:00
Add in inspect panels, even more polish, just need to do refreshing iirc
This commit is contained in:
parent
c753cfe3f0
commit
65dfee6e9a
7 changed files with 91 additions and 13 deletions
|
|
@ -341,7 +341,7 @@ CONSOLE = "CONSOLE"
|
|||
MODS = "MODS"
|
||||
|
||||
[MODERATION]
|
||||
MODERATOR_MENU_TITLE = "MODERATOR MENU"
|
||||
MODERATOR_MENU_TITLE = "MODERATION"
|
||||
MODERATION_LISTS_TITLE = "MODERATION LISTS"
|
||||
MODERATION_LISTS = "Moderation Lists"
|
||||
NO_PLAYERS_CONNECTED = "No players connected."
|
||||
|
|
@ -368,7 +368,8 @@ INSPECT = "Inspect"
|
|||
INSPECTOR_TITLE = "INSPECTOR"
|
||||
DATE = "Added: @"
|
||||
DISCORD_ID = "Discord ID: @"
|
||||
REASON = "Reason: @"
|
||||
REASON_INFO = "Reason: @"
|
||||
REASON = "Reason"
|
||||
PERMANENT = "Permanent"
|
||||
|
||||
[OPTIONS]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "pc/network/moderation.h"
|
||||
|
||||
static char* sReason = NULL;
|
||||
static bool sPermanent = false;
|
||||
void (*sOnYesClick)(struct DjuiBase*) = NULL;
|
||||
|
||||
static void djui_panel_moderation_call_action(struct DjuiBase* caller) {
|
||||
|
|
@ -20,13 +21,13 @@ static void djui_panel_moderation_call_action(struct DjuiBase* caller) {
|
|||
network_kick_player(player, sReason);
|
||||
break;
|
||||
case MODERATION_ACTION_BAN:
|
||||
network_ban_player(player, sReason, false);
|
||||
network_ban_player(player, sReason, sPermanent);
|
||||
break;
|
||||
case MODERATION_ACTION_UNBAN:
|
||||
network_unban_player(address);
|
||||
break;
|
||||
case MODERATION_ACTION_MOD:
|
||||
network_mod_player(player, sReason, true);
|
||||
network_mod_player(player, sReason, sPermanent);
|
||||
break;
|
||||
case MODERATION_ACTION_UNMOD:
|
||||
network_unmod_player(address);
|
||||
|
|
@ -37,6 +38,7 @@ static void djui_panel_moderation_call_action(struct DjuiBase* caller) {
|
|||
|
||||
free(sReason);
|
||||
sReason = NULL;
|
||||
sPermanent = false;
|
||||
djui_panel_menu_back(caller);
|
||||
|
||||
if (sOnYesClick) sOnYesClick(caller);
|
||||
|
|
@ -76,7 +78,17 @@ static void djui_panel_moderation_confirm_set_title_and_message(u8 action, char*
|
|||
}
|
||||
}
|
||||
|
||||
static void djui_panel_moderation_confirm_destroy(struct DjuiBase* base) {
|
||||
struct DjuiThreePanel* threePanel = (struct DjuiThreePanel*)base;
|
||||
free(threePanel);
|
||||
free(sReason);
|
||||
sReason = NULL;
|
||||
sPermanent = false;
|
||||
}
|
||||
|
||||
void djui_panel_moderation_confirm_create_body(struct DjuiBase* caller, char* title, char* message, u8 localIndex, u8 action, bool permanent, char* address, void (*on_yes_click)(struct DjuiBase*)) {
|
||||
sPermanent = permanent;
|
||||
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(title, false);
|
||||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
{
|
||||
|
|
@ -86,7 +98,7 @@ void djui_panel_moderation_confirm_create_body(struct DjuiBase* caller, char* ti
|
|||
if (action == MODERATION_ACTION_BAN || action == MODERATION_ACTION_MOD) {
|
||||
struct DjuiRect* rect1 = djui_rect_container_create(body, 32);
|
||||
{
|
||||
struct DjuiText* text1 = djui_text_create(&rect1->base, "Reason:");
|
||||
struct DjuiText* text1 = djui_text_create(&rect1->base, DLANG(MODERATION, REASON));
|
||||
djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_color(&text1->base, 220, 220, 220, 255);
|
||||
djui_base_set_size(&text1->base, 0.585f, 64);
|
||||
|
|
@ -99,6 +111,8 @@ void djui_panel_moderation_confirm_create_body(struct DjuiBase* caller, char* ti
|
|||
djui_base_set_alignment(&inputbox1->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
|
||||
djui_interactable_hook_value_change(&inputbox1->base, djui_panel_moderation_confirm_reason_text_change);
|
||||
}
|
||||
|
||||
djui_checkbox_create(body, DLANG(MODERATION, PERMANENT), &sPermanent, NULL);
|
||||
}
|
||||
|
||||
djui_base_set_size(&text->base, 1.0f, 64);
|
||||
|
|
@ -116,17 +130,19 @@ void djui_panel_moderation_confirm_create_body(struct DjuiBase* caller, char* ti
|
|||
struct DjuiButton* yesButton = djui_button_right_create(&rect2->base, DLANG(MENU, YES), DJUI_BUTTON_STYLE_NORMAL, djui_panel_moderation_call_action);
|
||||
yesButton->base.tag = localIndex;
|
||||
yesButton->base.uTag = action;
|
||||
yesButton->base.bTag = permanent;
|
||||
yesButton->base.cTag = strdup(address);
|
||||
sOnYesClick = on_yes_click;
|
||||
}
|
||||
}
|
||||
|
||||
panel->base.destroy = djui_panel_moderation_confirm_destroy;
|
||||
djui_panel_add(caller, panel, NULL);
|
||||
}
|
||||
|
||||
void djui_panel_moderation_confirm_create(struct DjuiBase* caller, u8 action, u8 localIndex, bool permanent, void (*on_yes_click)(struct DjuiBase*)) {
|
||||
if (localIndex >= MAX_PLAYERS) return;
|
||||
struct NetworkPlayer* np = &gNetworkPlayers[localIndex];
|
||||
if (!np->connected) return;
|
||||
char* title = NULL;
|
||||
char message[256] = { 0 };
|
||||
djui_panel_moderation_confirm_set_title_and_message(action, &title, message, (char*)network_get_complete_player_name(localIndex));
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ void djui_panel_moderation_list_inspect_create(struct DjuiBase* caller) {
|
|||
|
||||
if (entry->reason && strcmp(entry->reason, "") != 0) {
|
||||
char reasonStr[512];
|
||||
djui_language_replace(DLANG(MODERATION, REASON), reasonStr, 512, '@', entry->reason);
|
||||
djui_language_replace(DLANG(MODERATION, REASON_INFO), reasonStr, 512, '@', entry->reason);
|
||||
struct DjuiText* reasonText = djui_text_create(body, reasonStr);
|
||||
djui_base_set_color(&reasonText->base, 220, 220, 220, 255);
|
||||
djui_base_set_size_type(&reasonText->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
|
|
@ -81,7 +81,6 @@ void djui_panel_moderation_list_inspect_create(struct DjuiBase* caller) {
|
|||
djui_base_compute_tree(&reasonText->base);
|
||||
u16 reasonLines = djui_text_count_lines(reasonText, 12);
|
||||
f32 reasonHeight = 32 * reasonLines;
|
||||
printf("Reason lines is %u, with reason height being %f\n", reasonLines, reasonHeight);
|
||||
djui_base_set_size(&reasonText->base, 1, reasonHeight);
|
||||
djui_text_set_alignment(reasonText, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
|
||||
djui_text_set_drop_shadow(reasonText, 64, 64, 64, 100);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "djui_panel.h"
|
||||
#include "djui_panel_menu.h"
|
||||
#include "djui_panel_moderator_menu.h"
|
||||
#include "djui_panel_moderator_menu_inspect.h"
|
||||
#include "djui_panel_moderation_list.h"
|
||||
#include "djui_panel_moderation_confirm_action.h"
|
||||
#include "pc/network/network.h"
|
||||
|
|
@ -13,7 +14,7 @@ static struct DjuiFlowLayout* sLayout = NULL;
|
|||
static struct DjuiPaginated* sPaginated = NULL;
|
||||
|
||||
static void djui_panel_moderator_menu_action_button_click(struct DjuiBase* caller) {
|
||||
djui_panel_moderation_confirm_create(caller, caller->uTag, caller->tag, false, djui_panel_moderator_menu_reload);
|
||||
djui_panel_moderation_confirm_create(caller, caller->uTag, caller->tag, caller->bTag, djui_panel_moderator_menu_reload);
|
||||
}
|
||||
|
||||
static void djui_panel_moderator_add_players(struct DjuiBase* layoutBase) {
|
||||
|
|
@ -32,12 +33,13 @@ static void djui_panel_moderator_add_players(struct DjuiBase* layoutBase) {
|
|||
djui_base_set_size_type(&flowLayout->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&flowLayout->base, 1, 32);
|
||||
{
|
||||
struct DjuiButton* playerButton = djui_button_create(&flowLayout->base, np->name, DJUI_BUTTON_STYLE_NORMAL, NULL);
|
||||
struct DjuiButton* playerButton = djui_button_create(&flowLayout->base, np->name, DJUI_BUTTON_STYLE_NORMAL, djui_panel_moderator_menu_inspector_create);
|
||||
u8 playerColor[3];
|
||||
memcpy(playerColor, network_get_player_text_color(i), 3);
|
||||
djui_base_set_color(&playerButton->text->base, playerColor[0], playerColor[1], playerColor[2], 255);
|
||||
djui_base_set_size_type(&playerButton->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&playerButton->base, 0.4, 32);
|
||||
playerButton->base.tag = i;
|
||||
|
||||
struct DjuiButton* kickButton = djui_button_create(&flowLayout->base, DLANG(MODERATION, KICK), DJUI_BUTTON_STYLE_NORMAL, djui_panel_moderator_menu_action_button_click);
|
||||
djui_base_set_size_type(&kickButton->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
|
|
@ -56,6 +58,7 @@ static void djui_panel_moderator_add_players(struct DjuiBase* layoutBase) {
|
|||
djui_base_set_size(&modButton->base, 1.0, 32);
|
||||
djui_base_set_enabled(&modButton->base, gNetworkType == NT_SERVER);
|
||||
modButton->base.uTag = np->moderator ? MODERATION_ACTION_UNMOD : MODERATION_ACTION_MOD;
|
||||
modButton->base.bTag = true;
|
||||
modButton->base.tag = i;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
src/pc/djui/djui_panel_moderator_menu_inspect.c
Normal file
55
src/pc/djui/djui_panel_moderator_menu_inspect.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "djui.h"
|
||||
#include "djui_panel.h"
|
||||
#include "djui_panel_menu.h"
|
||||
#include "djui_panel_moderator_menu.h"
|
||||
#include "djui_panel_moderation_list.h"
|
||||
#include "djui_panel_moderation_confirm_action.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/network/moderation.h"
|
||||
|
||||
static void djui_panel_moderator_menu_action_button_click(struct DjuiBase* caller) {
|
||||
djui_panel_moderation_confirm_create(caller, caller->uTag, caller->tag, caller->bTag, djui_panel_moderator_menu_reload);
|
||||
}
|
||||
|
||||
static void djui_panel_moderator_menu_inspector_destroy(struct DjuiBase* base) {
|
||||
struct DjuiThreePanel* threePanel = (struct DjuiThreePanel*)base;
|
||||
free(threePanel);
|
||||
}
|
||||
|
||||
void djui_panel_moderator_menu_inspector_create(struct DjuiBase* caller) {
|
||||
if (caller->tag <= 0 || caller->tag >= MAX_PLAYERS) return;
|
||||
struct NetworkPlayer* np = &gNetworkPlayers[caller->tag];
|
||||
if (!np->connected) return;
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(MODERATION, MODERATOR_MENU_TITLE), true);
|
||||
|
||||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
{
|
||||
char playerName[MAX_CONFIG_STRING + 128];
|
||||
snprintf(playerName, MAX_CONFIG_STRING + 128, "%s \\#fff982\\- \\#82f9ff\\%s \\#fff982\\- \\#82f9ff\\%u", network_get_complete_player_name(np->localIndex), gNetworkSystem->get_id_str(np->localIndex), np->localIndex);
|
||||
struct DjuiText* playerText = djui_text_create(body, playerName);
|
||||
djui_base_set_size_type(&playerText->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&playerText->base, 1, 32);
|
||||
djui_text_set_alignment(playerText, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
|
||||
djui_text_set_drop_shadow(playerText, 64, 64, 64, 100);
|
||||
|
||||
struct DjuiButton* kickButton = djui_button_create(body, DLANG(MODERATION, KICK), DJUI_BUTTON_STYLE_NORMAL, djui_panel_moderator_menu_action_button_click);
|
||||
kickButton->base.uTag = MODERATION_ACTION_KICK;
|
||||
kickButton->base.tag = np->localIndex;
|
||||
|
||||
struct DjuiButton* banButton = djui_button_create(body, DLANG(MODERATION, BAN), DJUI_BUTTON_STYLE_NORMAL, djui_panel_moderator_menu_action_button_click);
|
||||
banButton->base.uTag = MODERATION_ACTION_BAN;
|
||||
banButton->base.tag = np->localIndex;
|
||||
|
||||
struct DjuiButton* modButton = djui_button_create(body, np->moderator ? DLANG(MODERATION, UNMOD) : DLANG(MODERATION, MOD), DJUI_BUTTON_STYLE_NORMAL, djui_panel_moderator_menu_action_button_click);
|
||||
modButton->base.uTag = np->moderator ? MODERATION_ACTION_UNMOD : MODERATION_ACTION_MOD;
|
||||
modButton->base.bTag = true;
|
||||
modButton->base.tag = np->localIndex;
|
||||
|
||||
djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
|
||||
}
|
||||
|
||||
panel->base.destroy = djui_panel_moderator_menu_inspector_destroy;
|
||||
djui_panel_add(caller, panel, NULL);
|
||||
}
|
||||
4
src/pc/djui/djui_panel_moderator_menu_inspect.h
Normal file
4
src/pc/djui/djui_panel_moderator_menu_inspect.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
#include "djui.h"
|
||||
|
||||
void djui_panel_moderator_menu_inspector_create(struct DjuiBase* caller);
|
||||
|
|
@ -148,7 +148,7 @@ static bool ns_socket_initialize(enum NetworkType networkType, UNUSED bool recon
|
|||
int reuse = 1;
|
||||
if (setsockopt(sCurSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)) < 0) {
|
||||
LOG_ERROR("setsockopt(SO_REUSEADDR) failed");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SO_REUSEPORT
|
||||
if (setsockopt(sCurSocket, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)) < 0) {
|
||||
|
|
@ -157,9 +157,9 @@ static bool ns_socket_initialize(enum NetworkType networkType, UNUSED bool recon
|
|||
#endif
|
||||
// bind the socket to any address and the specified port.
|
||||
int rc = socket_bind(sCurSocket, port);
|
||||
if (rc != NO_ERROR) {
|
||||
if (rc != NO_ERROR) {
|
||||
LOG_ERROR("bind returned an error.");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
LOG_INFO("bound to port %u", port);
|
||||
} else if (networkType == NT_CLIENT) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue