diff --git a/config.def.h b/config.def.h index adb6ef9a4f..4c65e867ab 100644 --- a/config.def.h +++ b/config.def.h @@ -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; diff --git a/configuration.c b/configuration.c index 57e1ff0f50..3729d2f2ce 100644 --- a/configuration.c +++ b/configuration.c @@ -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); diff --git a/configuration.h b/configuration.h index 13f19cf8e7..57198d3ae3 100644 --- a/configuration.h +++ b/configuration.h @@ -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; diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 63c7b02d27..f0f1b58144 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -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" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 0bb48c3ae7..7cd6d831bf 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -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" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index b253d5d126..e59250518f 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -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; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 698702cf7a..24fdbd7b8b 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -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}, diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 275b06e35c..886873642c 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -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, diff --git a/msg_hash.h b/msg_hash.h index 77fd2a747d..ceebac26ec 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -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), diff --git a/network/netplay/netplay.h b/network/netplay/netplay.h index cb7f349b24..b9dbd3348b 100644 --- a/network/netplay/netplay.h +++ b/network/netplay/netplay.h @@ -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 diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 5697a1f2c5..32cd8d0266 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -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);