From: Jordi Albornoz Date: Fri, 3 Jan 2003 16:59:38 +0000 (+0000) Subject: Made the "discard special" key configurable. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=2edacb79061dc96214f84c357cd9b1b9808daca6;p=gtetrinet Made the "discard special" key configurable. Add fields_attdeffmt() and partyline_fmt() and use them to make messages with colours translatable. --- diff --git a/ChangeLog b/ChangeLog index 479e55a..0b7b0c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2002-12-18 Jordi Mallach + + * src/fields.[ch] (fields_attdeffmt): new function, based on + partyline_fmt(). + * src/tetrinet.c (tetrinet_inmessage): replace fields_attdefmsg() + uses that need i18n with fields_attdeffmt(). + +2002-12-16 Jordi Mallach + + * src/config.c: make the "discard special" key configurable. + (config_loadconfig): add "Keys/Discard" to the key list. + (config_saveconfig): save "Keys/Discard". + * src/config.h: define K_DISCARD, bump K_NUM to 8. + * src/dialogs.c (prefdialog_drawkeys): add "Discard Special" action. + + * src/partyline.[ch] (partyline_fmt): new function, api to wrap around + partyline_text() that is gettext friendly. Patch by James Antill. + * src/tetrinet.c: gettextize missing partyline messages, using + partyline_fmt() when needed. + (partylineupdate_timeout): change logic for a message that assumed + that "alone" is both singular and plural for all languages. Patch by + James Antill. + 2002-12-05 Jordi Mallach * src/dialogs.c (prefdialog_themelist): fix memleak, spotted by diff --git a/src/config.c b/src/config.c index ced841f..985a572 100644 --- a/src/config.c +++ b/src/config.c @@ -59,6 +59,7 @@ gint defaultkeys[K_NUM] = { GDK_Control_R, GDK_Down, GDK_space, + GDK_d, GDK_t }; @@ -205,6 +206,8 @@ void config_loadconfig (void) keys[K_DOWN] = k ? k : defaultkeys[K_DOWN]; k = gnome_config_get_int ("Keys/Drop"); keys[K_DROP] = k ? k : defaultkeys[K_DROP]; + k = gnome_config_get_int ("Keys/Discard"); + keys[K_DISCARD] = k ? k : defaultkeys[K_DISCARD]; k = gnome_config_get_int ("Keys/Message"); keys[K_GAMEMSG] = k ? k : defaultkeys[K_GAMEMSG]; @@ -233,6 +236,7 @@ void config_saveconfig (void) gnome_config_set_int ("Keys/RotateLeft", keys[K_ROTLEFT]); gnome_config_set_int ("Keys/Down", keys[K_DOWN]); gnome_config_set_int ("Keys/Drop", keys[K_DROP]); + gnome_config_set_int ("Keys/Discard", keys[K_DISCARD]); gnome_config_set_int ("Keys/Message", keys[K_GAMEMSG]); gnome_config_pop_prefix (); diff --git a/src/config.h b/src/config.h index 5ae0c9f..c20f189 100644 --- a/src/config.h +++ b/src/config.h @@ -18,6 +18,7 @@ extern void config_saveconfig (void); #define K_ROTLEFT 3 #define K_DOWN 4 #define K_DROP 5 -#define K_GAMEMSG 6 +#define K_DISCARD 6 +#define K_GAMEMSG 7 /* not a key but the number of configurable keys */ -#define K_NUM 7 +#define K_NUM 8 diff --git a/src/dialogs.c b/src/dialogs.c index 7619fba..226deab 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -405,6 +405,7 @@ int actionid[K_NUM] = { K_ROTRIGHT, K_ROTLEFT, K_DROP, + K_DISCARD, K_GAMEMSG }; @@ -434,7 +435,8 @@ void prefdialog_drawkeys (void) actions[3] = _("Rotate right"); actions[4] = _("Rotate left"); actions[5] = _("Drop piece"); - actions[6] = _("Send message"); + actions[6] = _("Discard special"); + actions[7] = _("Send message"); for (i = 0; i < K_NUM; i ++) { array[0] = actions[i]; diff --git a/src/fields.c b/src/fields.c index 21a1dd5..bdd199d 100644 --- a/src/fields.c +++ b/src/fields.c @@ -502,6 +502,18 @@ void fields_attdefmsg (char *text) adjust_bottom_text_view (GTK_TEXT_VIEW(attdefwidget)); } +void fields_attdeffmt (const char *fmt, ...) +{ + va_list ap; + char *text = NULL; + + va_start(ap, fmt); + text = g_strdup_vprintf(fmt,ap); + va_end(ap); + + fields_attdefmsg (text); g_free(text); +} + void fields_attdefclear (void) { gtk_text_buffer_set_text(GTK_TEXT_VIEW(attdefwidget)->buffer, "", 0); diff --git a/src/fields.h b/src/fields.h index b723059..f935019 100644 --- a/src/fields.h +++ b/src/fields.h @@ -10,6 +10,7 @@ extern void fields_setspeciallabel (char *label); extern void fields_drawspecials (void); extern void fields_drawnextblock (TETRISBLOCK block); extern void fields_attdefmsg (char *text); +extern void fields_attdeffmt (const char *fmt, ...) G_GNUC_PRINTF (1, 2); extern void fields_attdefclear (void); extern void fields_setlines (int l); extern void fields_setlevel (int l); diff --git a/src/partyline.c b/src/partyline.c index 5d7a5d3..95721be 100644 --- a/src/partyline.c +++ b/src/partyline.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "client.h" #include "tetrinet.h" @@ -173,6 +174,18 @@ void partyline_text (char *text) adjust_bottom_text_view(GTK_TEXT_VIEW(textbox)); } +void partyline_fmt (const char *fmt, ...) +{ + va_list ap; + char *text = NULL; + + va_start(ap, fmt); + text = g_strdup_vprintf(fmt, ap); + va_end(ap); + + partyline_text(text); g_free(text); +} + void partyline_playerlist (int *numbers, char **names, char **teams, int n, char **specs, int sn) { int i; diff --git a/src/partyline.h b/src/partyline.h index 7a39ab1..1f14ef3 100644 --- a/src/partyline.h +++ b/src/partyline.h @@ -4,6 +4,7 @@ extern void partyline_connectstatus (int status); extern void partyline_namelabel (char *nick, char *team); extern void partyline_status (char *status); extern void partyline_text (char *text); +extern void partyline_fmt (const char *text, ...) G_GNUC_PRINTF (1, 2); extern void partyline_playerlist (int *numbers, char **names, char **teams, int n, char **specs, int sn); extern void partyline_entryfocus (void); void partyline_switch_entryfocus (void); diff --git a/src/tetrinet.c b/src/tetrinet.c index 2456665..e953f47 100644 --- a/src/tetrinet.c +++ b/src/tetrinet.c @@ -198,7 +198,8 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) winlist_clear (); fields_attdefclear (); fields_gmsgclear (); - partyline_text ("\014\02*** Disconnected from server"); + partyline_fmt (_("%c*** Disconnected from server"), + TETRI_TB_C_BRIGHT_RED); break; case IN_CONNECTERROR: connecterror: @@ -232,7 +233,8 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) connected = TRUE; ingame = playing = paused = FALSE; playercount = 0; - partyline_text ("\014\02*** Connected to server"); + partyline_fmt (_("%c%c*** Connected to server"), + TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD); commands_checkstate (); connectingdialog_destroy (); connectdialog_connected (); @@ -326,11 +328,11 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) break; if ((pnum == playernum) && !spectating) g_snprintf (buf, sizeof(buf), - "%c%c*** You have been kicked from the game", + _("%c%c*** You have been kicked from the game"), TETRI_TB_C_DARK_GREEN, TETRI_TB_BOLD); else g_snprintf (buf, sizeof(buf), - "%c*** %c%s%c%c has been kicked from the game", + _("%c*** %c%s%c%c has been kicked from the game"), TETRI_TB_C_DARK_GREEN, TETRI_TB_BOLD, playernames[pnum], TETRI_TB_RESET, TETRI_TB_C_DARK_GREEN); @@ -421,13 +423,13 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) break; if (teamnames[pnum][0]) g_snprintf (buf, sizeof(buf), - "%c*** Team %c%s%c%c has won the game", + _("%c*** Team %c%s%c%c has won the game"), TETRI_TB_C_DARK_RED, TETRI_TB_BOLD, teamnames[pnum], TETRI_TB_RESET, TETRI_TB_C_DARK_RED); else g_snprintf (buf, sizeof(buf), - "%c*** %c%s%c%c has won the game", + _("%c*** %c%s%c%c has won the game"), TETRI_TB_C_DARK_RED, TETRI_TB_BOLD, playernames[pnum], TETRI_TB_RESET, TETRI_TB_C_DARK_RED); @@ -487,7 +489,8 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) if (specialfreq[8] < 100) specialfreq[8] = 100; tetrinet_startgame (); commands_checkstate (); - partyline_text ("\024*** The game has \02started"); + partyline_fmt (_("%c*** The game has %cstarted"), + TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD); } break; case IN_INGAME: @@ -509,7 +512,8 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) fields_gmsginput (FALSE); fields_gmsginputclear (); commands_checkstate (); - partyline_text ("\024*** The game is \02in progress"); + partyline_fmt(_("%c*** The game is %cin progress"), + TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD);; } break; case IN_PAUSE: @@ -519,13 +523,17 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) if (! (newstate ^ paused)) break; if (newstate) { tetrinet_pausegame (); - partyline_text ("\024*** The game has \02paused"); - fields_attdefmsg ("The game has \02\014Paused"); + partyline_fmt (_("%c*** The game has %cpaused"), + TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD); + fields_attdeffmt (_("The game has %c%cpaused"), + TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD); } else { tetrinet_resumegame (); - partyline_text ("\024*** The game has \02resumed"); - fields_attdefmsg ("The game has \02\014Resumed"); + partyline_fmt (_("%c*** The game has %cresumed"), + TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD); + fields_attdeffmt (_("The game has %c%cresumed"), + TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD); } commands_checkstate (); break; @@ -533,7 +541,8 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) case IN_ENDGAME: tetrinet_endgame (); commands_checkstate (); - partyline_text ("\024*** The game has \02ended"); + partyline_fmt (_("%c*** The game has %cended"), + TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD); break; case IN_F: { @@ -640,7 +649,7 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) token = strtok (data, " "); if (token == NULL) break; g_snprintf (buf, sizeof(buf), - "%c*** You have joined %c%s", + _("%c*** You have joined %c%s"), TETRI_TB_C_DARK_BLUE, TETRI_TB_BOLD, token); partyline_text (buf); while ((token = strtok (NULL, " ")) != NULL) speclist_add (token); @@ -656,8 +665,8 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) info = strtok (NULL, ""); if (info == NULL) info = ""; g_snprintf (buf, sizeof(buf), - "%c*** %c%s%c%c has joined the spectators" - " %c%c(%c%s%c%c%c)", + _("%c*** %c%s%c%c has joined the spectators" + " %c%c(%c%s%c%c%c)"), TETRI_TB_C_DARK_BLUE, TETRI_TB_BOLD, name, TETRI_TB_RESET, TETRI_TB_C_DARK_BLUE, @@ -677,8 +686,8 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) info = strtok (NULL, ""); if (info == NULL) info = ""; g_snprintf (buf, sizeof(buf), - "%c*** %c%s%c%c has left the spectators" - " %c%c(%c%s%c%c%c)", + _("%c*** %c%s%c%c has left the spectators" + " %c%c(%c%s%c%c%c)"), TETRI_TB_C_DARK_BLUE, TETRI_TB_BOLD, name, TETRI_TB_RESET, TETRI_TB_C_DARK_BLUE, @@ -993,14 +1002,14 @@ void tetrinet_dospecial (int from, int to, int type) if (to) { if (to == playernum) - g_snprintf (buf2, sizeof(buf2), " on %c%c%s%c%c", + g_snprintf (buf2, sizeof(buf2), _(" on %c%c%s%c%c"), TETRI_TB_BOLD, TETRI_TB_C_BRIGHT_BLUE, playernames[to], TETRI_TB_C_BRIGHT_BLUE, TETRI_TB_BOLD); else - g_snprintf (buf2, sizeof(buf2), " on %c%c%s%c%c", + g_snprintf (buf2, sizeof(buf2), _(" on %c%c%s%c%c"), TETRI_TB_BOLD, TETRI_TB_C_DARK_BLUE, playernames[to], @@ -1010,20 +1019,20 @@ void tetrinet_dospecial (int from, int to, int type) } else { - g_snprintf (buf2, sizeof(buf2), " to All"); + g_snprintf (buf2, sizeof(buf2), _(" to All")); GTET_O_STRCAT (buf, buf2); } if (from) { if (from == playernum) - g_snprintf (buf2, sizeof(buf2), " by %c%c%s%c%c", + g_snprintf (buf2, sizeof(buf2), _(" by %c%c%s%c%c"), TETRI_TB_BOLD, TETRI_TB_C_BRIGHT_BLUE, playernames[from], TETRI_TB_C_BRIGHT_BLUE, TETRI_TB_BOLD); else - g_snprintf (buf2, sizeof(buf2), " by %c%c%s%c%c", + g_snprintf (buf2, sizeof(buf2), _(" by %c%c%s%c%c"), TETRI_TB_BOLD, TETRI_TB_C_DARK_BLUE, playernames[from], @@ -1574,6 +1583,9 @@ notfieldkey: tetrinet_sendfield (0); } } + else if (keyval == keys[K_DISCARD]) { + tetrinet_specialkey(-1); + } else switch (keyval) { case GDK_1: tetrinet_specialkey(1); break; case GDK_2: tetrinet_specialkey(2); break; @@ -1581,7 +1593,6 @@ notfieldkey: case GDK_4: tetrinet_specialkey(4); break; case GDK_5: tetrinet_specialkey(5); break; case GDK_6: tetrinet_specialkey(6); break; - case GDK_d: tetrinet_specialkey(-1); break; default: return FALSE; } @@ -1650,7 +1661,7 @@ int moderatorupdate_timeout (void) if (moderatornum) { char buf[256]; g_snprintf (buf, sizeof(buf), - "%c*** %c%s%c%c is the moderator", + _("%c*** %c%s%c%c is the moderator"), TETRI_TB_C_BRIGHT_RED, TETRI_TB_BOLD, playernames[moderatornum], TETRI_TB_RESET, TETRI_TB_C_BRIGHT_RED); @@ -1735,13 +1746,17 @@ int partylineupdate_timeout (void) c ++; } } - if (c == 1) GTET_O_STRCAT (buf, " is "); - else GTET_O_STRCAT (buf, " are "); - if (team[0]) g_snprintf (buf2, sizeof(buf2), "on team %c%s", - TETRI_TB_BOLD, team); - else g_snprintf (buf2, sizeof(buf2), "alone"); - GTET_O_STRCAT (buf, buf2); - partyline_text (buf); + if (0) {} + else if ((c == 1) && team[0]) + partyline_fmt(_("%s is on team %c%s"), + buf, TETRI_TB_BOLD, team); + else if ((c == 1) && !team[0]) + partyline_fmt(_("%s is alone"), buf); + else if ((c != 1) && team[0]) + partyline_fmt(_("%s are on team %c%s"), + buf, TETRI_TB_BOLD, team); + else if ((c != 1) && !team[0]) + partyline_fmt(_("%s are alone"), buf); } pcount = 0; } @@ -1782,14 +1797,14 @@ void partylineupdate_team (char *name, char *team) /* player did not just join - display normally */ if (team[0]) g_snprintf (buf, sizeof(buf), - "%c*** %c%s%c%c is now on team %c%s", + _("%c*** %c%s%c%c is now on team %c%s"), TETRI_TB_C_DARK_RED, TETRI_TB_BOLD, name, TETRI_TB_RESET, TETRI_TB_C_DARK_RED, TETRI_TB_BOLD, team); else g_snprintf (buf, sizeof(buf), - "%c*** %c%s%c%c is now alone", + _("%c*** %c%s%c%c is now alone"), TETRI_TB_C_DARK_RED, TETRI_TB_BOLD, name, TETRI_TB_RESET, TETRI_TB_C_DARK_RED);