]> hydra-www.ietfng.org Git - gtetrinet/commitdiff
Made the "discard special" key configurable.
authorJordi Albornoz <jordi@src.gnome.org>
Fri, 3 Jan 2003 16:59:38 +0000 (16:59 +0000)
committerJordi Albornoz <jordi@src.gnome.org>
Fri, 3 Jan 2003 16:59:38 +0000 (16:59 +0000)
Add fields_attdeffmt() and partyline_fmt() and use them to make messages with colours translatable.

ChangeLog
src/config.c
src/config.h
src/dialogs.c
src/fields.c
src/fields.h
src/partyline.c
src/partyline.h
src/tetrinet.c

index 479e55abe44740e6e0863337cd2b27cb96076bcc..0b7b0c78573a04d2b0e9d9b11e9a8a59e618b611 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2002-12-18  Jordi Mallach  <jordi@sindominio.net>
+
+       * 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  <jordi@sindominio.net>
+
+       * 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  <jordi@sindominio.net>
 
        * src/dialogs.c (prefdialog_themelist): fix memleak, spotted by
index ced841f1d47e0b27a297ceca6a1f6f0129f76217..985a57261c36d3b6ceb515df8c3f82beff41b273 100644 (file)
@@ -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 ();
index 5ae0c9f6f4ca16e663adb889de2dddcc87ff64c8..c20f1894a8b7946011dabd3cc7121febb91db369 100644 (file)
@@ -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
index 7619fba78247b35034930404a3a0795517bf3da1..226deabbf17e1b6acc451277c7c2a715582df5e2 100644 (file)
@@ -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];
index 21a1dd59d53b7dcccd011c0b9801461258c668c1..bdd199d197835652bfcf317197f8f72b3344b231 100644 (file)
@@ -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);
index b723059655d9aedb63f5c5d8be9ef270a8c5108b..f935019b551f1cf861c344814d62eee9245773af 100644 (file)
@@ -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);
index 5d7a5d3f58c828dfa63e7a2399b8751fda88a1e1..95721bebe499a35255b799fb2a741861c2d6d741 100644 (file)
@@ -25,6 +25,7 @@
 #include <gnome.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdarg.h>
 
 #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;
index 7a39ab1ae8a43c709dd9ce9368b57c8bf29b2731..1f14ef32434821c81c26f85cfba65a8c0cbbce24 100644 (file)
@@ -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);
index 24566653367840f0ae406cb624b6e8ea8e4af087..e953f4702ad1bf94b9c969f0c75497e7a2e08ffd 100644 (file)
@@ -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);