From f82541578248b91da0f0780fa095dd67114f0f49 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 2 Jan 2022 05:30:01 +0200 Subject: [PATCH 31/31] gtk: Use common sex module instead of hardcoding strings See osdn #43408 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/dialogs.c | 11 +++++++---- client/gui-gtk-4.0/dialogs.c | 11 +++++++---- common/sex.c | 21 +++++++++++++++++++++ common/sex.h | 1 + 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/client/gui-gtk-3.22/dialogs.c b/client/gui-gtk-3.22/dialogs.c index 5a4298e54d..abbec98922 100644 --- a/client/gui-gtk-3.22/dialogs.c +++ b/client/gui-gtk-3.22/dialogs.c @@ -38,6 +38,7 @@ #include "map.h" #include "packets.h" #include "player.h" +#include "sex.h" /* client */ #include "client_main.h" @@ -1077,13 +1078,15 @@ static void create_races_dialog(struct player *pplayer) gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 2); gtk_grid_attach(GTK_GRID(table), combo, 1, 0, 2, 1); - cmd = gtk_radio_button_new_with_mnemonic(NULL, _("_Female")); + cmd = gtk_radio_button_new_with_mnemonic(NULL, + sex_name_mnemonic(SEX_FEMALE, "_")); gtk_widget_set_margin_bottom(cmd, 6); races_sex[0] = cmd; gtk_grid_attach(GTK_GRID(table), cmd, 1, 1, 1, 1); cmd = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(cmd), - _("_Male")); + sex_name_mnemonic(SEX_MALE, + "_")); gtk_widget_set_margin_bottom(cmd, 6); races_sex[1] = cmd; gtk_grid_attach(GTK_GRID(table), cmd, 2, 1, 1, 1); @@ -1176,9 +1179,9 @@ static void create_races_dialog(struct player *pplayer) G_CALLBACK(races_leader_callback), NULL); g_signal_connect(races_sex[0], "toggled", - G_CALLBACK(races_sex_callback), GINT_TO_POINTER(0)); + G_CALLBACK(races_sex_callback), GINT_TO_POINTER(SEX_FEMALE)); g_signal_connect(races_sex[1], "toggled", - G_CALLBACK(races_sex_callback), GINT_TO_POINTER(1)); + G_CALLBACK(races_sex_callback), GINT_TO_POINTER(SEX_MALE)); /* Finish up. */ gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_CANCEL); diff --git a/client/gui-gtk-4.0/dialogs.c b/client/gui-gtk-4.0/dialogs.c index c536b41e06..1aff1f3d8e 100644 --- a/client/gui-gtk-4.0/dialogs.c +++ b/client/gui-gtk-4.0/dialogs.c @@ -38,6 +38,7 @@ #include "map.h" #include "packets.h" #include "player.h" +#include "sex.h" /* client */ #include "client_main.h" @@ -1087,13 +1088,15 @@ static void create_races_dialog(struct player *pplayer) gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 2); gtk_grid_attach(GTK_GRID(table), combo, 1, 0, 2, 1); - cmd = gtk_check_button_new_with_mnemonic(_("_Female")); + cmd = gtk_check_button_new_with_mnemonic(sex_name_mnemonic(SEX_FEMALE, + "_")); gtk_widget_set_margin_bottom(cmd, 6); races_sex[0] = cmd; gtk_grid_attach(GTK_GRID(table), cmd, 1, 1, 1, 1); group = cmd; - cmd = gtk_check_button_new_with_mnemonic(_("_Male")); + cmd = gtk_check_button_new_with_mnemonic(sex_name_mnemonic(SEX_MALE, + "_")); gtk_check_button_set_group(GTK_CHECK_BUTTON(cmd), GTK_CHECK_BUTTON(group)); gtk_widget_set_margin_bottom(cmd, 6); @@ -1187,9 +1190,9 @@ static void create_races_dialog(struct player *pplayer) G_CALLBACK(races_leader_callback), NULL); g_signal_connect(races_sex[0], "toggled", - G_CALLBACK(races_sex_callback), GINT_TO_POINTER(0)); + G_CALLBACK(races_sex_callback), GINT_TO_POINTER(SEX_FEMALE)); g_signal_connect(races_sex[1], "toggled", - G_CALLBACK(races_sex_callback), GINT_TO_POINTER(1)); + G_CALLBACK(races_sex_callback), GINT_TO_POINTER(SEX_MALE)); /* Finish up. */ gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_CANCEL); diff --git a/common/sex.c b/common/sex.c index 2ff7ceeeab..07e05d4d93 100644 --- a/common/sex.c +++ b/common/sex.c @@ -67,3 +67,24 @@ const char *sex_name_translation(sex_t kind) return _(rule_name); } + +/************************************************************************//** + Return translated name of the sex with a mnemonic placed on it +****************************************************************************/ +const char *sex_name_mnemonic(sex_t kind, const char *mnemonic) +{ + static char buf[128]; + + switch (kind) { + case SEX_MALE: + fc_snprintf(buf, sizeof(buf), _("%sMale"), mnemonic); + return buf; + case SEX_FEMALE: + fc_snprintf(buf, sizeof(buf), _("%sFemale"), mnemonic); + return buf; + case SEX_UNKNOWN: + break; + } + + return NULL; +} diff --git a/common/sex.h b/common/sex.h index 9bcba3ffe0..ea6aa72d8d 100644 --- a/common/sex.h +++ b/common/sex.h @@ -26,6 +26,7 @@ typedef enum { sex_t sex_by_name(const char *name); const char *sex_rule_name(sex_t kind); const char *sex_name_translation(sex_t kind); +const char *sex_name_mnemonic(sex_t kind, const char *mnemonic); #ifdef __cplusplus } -- 2.34.1