(Netplay) Support for customizing chat colors (#14305)

This commit is contained in:
Cthulhu-throwaway 2022-08-08 15:09:06 -03:00 committed by GitHub
parent a9157f975e
commit c030e1c5dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 144 additions and 4 deletions

View File

@ -1215,6 +1215,10 @@ static const bool netplay_start_as_spectator = false;
/* Netplay chat fading toggle */
static const bool netplay_fade_chat = true;
/* Netplay chat colors */
static const unsigned netplay_chat_color_name = 0x008000;
static const unsigned netplay_chat_color_msg = 0xFFFFFF;
/* Allow players to pause */
static const bool netplay_allow_pausing = false;

View File

@ -2268,6 +2268,8 @@ static struct config_uint_setting *populate_settings_uint(
SETTING_OVERRIDE(RARCH_OVERRIDE_SETTING_NETPLAY_IP_PORT);
SETTING_UINT("netplay_max_connections", &settings->uints.netplay_max_connections, true, netplay_max_connections, false);
SETTING_UINT("netplay_max_ping", &settings->uints.netplay_max_ping, true, netplay_max_ping, false);
SETTING_UINT("netplay_chat_color_name", &settings->uints.netplay_chat_color_name, true, netplay_chat_color_name, false);
SETTING_UINT("netplay_chat_color_msg", &settings->uints.netplay_chat_color_msg, true, netplay_chat_color_msg, false);
SETTING_UINT("netplay_input_latency_frames_min",&settings->uints.netplay_input_latency_frames_min, true, 0, false);
SETTING_UINT("netplay_input_latency_frames_range",&settings->uints.netplay_input_latency_frames_range, true, 0, false);
SETTING_UINT("netplay_share_digital", &settings->uints.netplay_share_digital, true, netplay_share_digital, false);

View File

@ -179,6 +179,8 @@ typedef struct settings
unsigned netplay_port;
unsigned netplay_max_connections;
unsigned netplay_max_ping;
unsigned netplay_chat_color_name;
unsigned netplay_chat_color_msg;
unsigned netplay_input_latency_frames_min;
unsigned netplay_input_latency_frames_range;
unsigned netplay_share_digital;

View File

@ -2106,6 +2106,14 @@ MSG_HASH(
MENU_ENUM_LABEL_NETPLAY_FADE_CHAT,
"netplay_fade_chat"
)
MSG_HASH(
MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_NAME,
"netplay_chat_color_name"
)
MSG_HASH(
MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_MSG,
"netplay_chat_color_msg"
)
MSG_HASH(
MENU_ENUM_LABEL_NETPLAY_ALLOW_PAUSING,
"netplay_allow_pausing"

View File

@ -5690,6 +5690,22 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_NETPLAY_FADE_CHAT,
"Fade chat messages over time."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_NETPLAY_CHAT_COLOR_NAME,
"Chat Color (Nickname)"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_NETPLAY_CHAT_COLOR_NAME,
"Format: #RRGGBB or RRGGBB"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_NETPLAY_CHAT_COLOR_MSG,
"Chat Color (Message)"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_NETPLAY_CHAT_COLOR_MSG,
"Format: #RRGGBB or RRGGBB"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_NETPLAY_ALLOW_PAUSING,
"Allow Pausing"

View File

@ -742,6 +742,8 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_password, MENU_
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_spectate_password, MENU_ENUM_SUBLABEL_NETPLAY_SPECTATE_PASSWORD)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_start_as_spectator, MENU_ENUM_SUBLABEL_NETPLAY_START_AS_SPECTATOR)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_fade_chat, MENU_ENUM_SUBLABEL_NETPLAY_FADE_CHAT)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_chat_color_name, MENU_ENUM_SUBLABEL_NETPLAY_CHAT_COLOR_NAME)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_chat_color_msg, MENU_ENUM_SUBLABEL_NETPLAY_CHAT_COLOR_MSG)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_allow_pausing, MENU_ENUM_SUBLABEL_NETPLAY_ALLOW_PAUSING)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_allow_slaves, MENU_ENUM_SUBLABEL_NETPLAY_ALLOW_SLAVES)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_require_slaves, MENU_ENUM_SUBLABEL_NETPLAY_REQUIRE_SLAVES)
@ -3272,6 +3274,12 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_NETPLAY_FADE_CHAT:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_fade_chat);
break;
case MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_NAME:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_chat_color_name);
break;
case MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_MSG:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_chat_color_msg);
break;
case MENU_ENUM_LABEL_NETPLAY_ALLOW_PAUSING:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_allow_pausing);
break;

View File

@ -7884,6 +7884,8 @@ unsigned menu_displaylist_build_list(
{MENU_ENUM_LABEL_NETPLAY_SPECTATE_PASSWORD, PARSE_ONLY_STRING, true},
{MENU_ENUM_LABEL_NETPLAY_START_AS_SPECTATOR, PARSE_ONLY_BOOL, true},
{MENU_ENUM_LABEL_NETPLAY_FADE_CHAT, PARSE_ONLY_BOOL, true},
{MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_NAME, PARSE_ONLY_UINT, true},
{MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_MSG, PARSE_ONLY_UINT, true},
{MENU_ENUM_LABEL_NETPLAY_ALLOW_PAUSING, PARSE_ONLY_BOOL, true},
{MENU_ENUM_LABEL_NETPLAY_ALLOW_SLAVES, PARSE_ONLY_BOOL, true},
{MENU_ENUM_LABEL_NETPLAY_REQUIRE_SLAVES, PARSE_ONLY_BOOL, false},

View File

@ -707,6 +707,14 @@ void setting_get_string_representation_uint(rarch_setting_t *setting,
*setting->value.target.unsigned_integer);
}
void setting_get_string_representation_color_rgb(rarch_setting_t *setting,
char *s, size_t len)
{
if (setting)
snprintf(s, len, "#%06X",
*setting->value.target.unsigned_integer & 0xFFFFFF);
}
void setting_get_string_representation_size(
rarch_setting_t *setting, char *s, size_t len)
{
@ -2843,6 +2851,51 @@ static int setting_action_ok_uint(
return 1;
}
static void setting_action_ok_color_rgb_cb(void *userdata, const char *line)
{
if (!string_is_empty(line))
{
rarch_setting_t *setting =
menu_setting_find(menu_input_dialog_get_label_setting_buffer());
if (setting)
{
unsigned rgb;
char *rgb_end = NULL;
if (*line == '#')
line++;
rgb = (unsigned)strtoul(line, &rgb_end, 16);
if (!(*rgb_end) && (rgb_end - line) == STRLEN_CONST("RRGGBB"))
*setting->value.target.unsigned_integer = rgb;
}
}
menu_input_dialog_end();
}
static int setting_action_ok_color_rgb(rarch_setting_t *setting, size_t idx,
bool wraparound)
{
menu_input_ctx_line_t line;
if (!setting)
return -1;
line.label = setting->short_description;
line.label_setting = setting->name;
line.type = 0;
line.idx = 0;
line.cb = setting_action_ok_color_rgb_cb;
if (!menu_input_dialog_start(&line))
return -1;
return 0;
}
static int setting_action_ok_libretro_device_type(
rarch_setting_t *setting, size_t idx, bool wraparound)
{
@ -19920,6 +19973,42 @@ static bool setting_append_list(
general_read_handler,
SD_FLAG_NONE);
CONFIG_UINT(
list, list_info,
&settings->uints.netplay_chat_color_name,
MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_NAME,
MENU_ENUM_LABEL_VALUE_NETPLAY_CHAT_COLOR_NAME,
netplay_chat_color_name,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
(*list)[list_info->index - 1].action_ok = &setting_action_ok_color_rgb;
(*list)[list_info->index - 1].action_select = &setting_action_ok_color_rgb;
(*list)[list_info->index - 1].action_left = NULL;
(*list)[list_info->index - 1].action_right = NULL;
(*list)[list_info->index - 1].get_string_representation =
&setting_get_string_representation_color_rgb;
CONFIG_UINT(
list, list_info,
&settings->uints.netplay_chat_color_msg,
MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_MSG,
MENU_ENUM_LABEL_VALUE_NETPLAY_CHAT_COLOR_MSG,
netplay_chat_color_msg,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
(*list)[list_info->index - 1].action_ok = &setting_action_ok_color_rgb;
(*list)[list_info->index - 1].action_select = &setting_action_ok_color_rgb;
(*list)[list_info->index - 1].action_left = NULL;
(*list)[list_info->index - 1].action_right = NULL;
(*list)[list_info->index - 1].get_string_representation =
&setting_get_string_representation_color_rgb;
CONFIG_BOOL(
list, list_info,
&settings->bools.netplay_allow_pausing,

View File

@ -2012,6 +2012,8 @@ enum msg_hash_enums
MENU_LABEL(NETPLAY_PUBLIC_ANNOUNCE),
MENU_LABEL(NETPLAY_START_AS_SPECTATOR),
MENU_LABEL(NETPLAY_FADE_CHAT),
MENU_LABEL(NETPLAY_CHAT_COLOR_NAME),
MENU_LABEL(NETPLAY_CHAT_COLOR_MSG),
MENU_LABEL(NETPLAY_ALLOW_PAUSING),
MENU_LABEL(NETPLAY_ALLOW_SLAVES),
MENU_LABEL(NETPLAY_REQUIRE_SLAVES),

View File

@ -49,8 +49,6 @@
#define NETPLAY_CHAT_MAX_MESSAGES 5
#define NETPLAY_CHAT_MAX_SIZE 96
#define NETPLAY_CHAT_FRAME_TIME 900
#define NETPLAY_CHAT_NICKNAME_COLOR 0x00800000
#define NETPLAY_CHAT_MESSAGE_COLOR 0xFFFFFF00
enum rarch_netplay_ctl_state
{
@ -239,6 +237,8 @@ struct netplay_chat_buffer
char nick[NETPLAY_NICK_LEN];
char msg[NETPLAY_CHAT_MAX_SIZE];
} messages[NETPLAY_CHAT_MAX_MESSAGES];
uint32_t color_name;
uint32_t color_msg;
};
typedef struct

View File

@ -9336,6 +9336,11 @@ static void gfx_widget_netplay_chat_iterate(void *user_data,
/* Move the messages to a thread-safe buffer
before drawing them. */
chat_buffer->color_name =
(uint32_t)settings->uints.netplay_chat_color_name << 8;
chat_buffer->color_msg =
(uint32_t)settings->uints.netplay_chat_color_msg << 8;
for (i = 0; i < ARRAY_SIZE(chat->messages); i++)
{
uint32_t *frames = &chat->messages[i].frames;
@ -9399,6 +9404,8 @@ static void gfx_widget_netplay_chat_frame(void *data, void *userdata)
int line_height =
font->line_height + p_dispwidget->simple_widget_padding / 3.0f;
int height = video_info->height - line_height;
uint32_t color_name = chat_buffer->color_name;
uint32_t color_msg = chat_buffer->color_msg;
for (i = 0; i < ARRAY_SIZE(chat_buffer->messages); i++)
{
@ -9425,7 +9432,7 @@ static void gfx_widget_netplay_chat_frame(void *data, void *userdata)
height,
video_info->width,
video_info->height,
(unsigned)alpha | NETPLAY_CHAT_NICKNAME_COLOR,
color_name | (uint32_t)alpha,
TEXT_ALIGN_LEFT,
true);
/* Now draw the message. */
@ -9436,7 +9443,7 @@ static void gfx_widget_netplay_chat_frame(void *data, void *userdata)
height,
video_info->width,
video_info->height,
(unsigned)alpha | NETPLAY_CHAT_MESSAGE_COLOR,
color_msg | (uint32_t)alpha,
TEXT_ALIGN_LEFT,
true);