tFix display of translated stats panel in text mode - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit e2c471ccf83d4958b6c7df7700bb4de35d52e535
 (DIR) parent c796087d647a1366c95d9d59553ae8808caa1430
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Wed,  9 Dec 2020 16:34:34 -0800
       
       Fix display of translated stats panel in text mode
       
       Add a function to display a right-aligned string
       in the curses client, using the true length of the
       string in characters. Use this to correct the alignment
       of the stats panel in the curses client.
       
       Diffstat:
         M po/de.po                            |      10 ++--------
         M po/dopewars.pot                     |       8 +-------
         M po/es.po                            |      10 ++--------
         M po/es_ES.po                         |      10 ++--------
         M po/fr.po                            |      10 ++--------
         M po/fr_CA.po                         |      10 ++--------
         M po/nn.po                            |      10 ++--------
         M po/pl.po                            |       8 +-------
         M po/pt_BR.po                         |      10 ++--------
         M src/curses_client/curses_client.c   |      53 ++++++++++++++++++++++++-------
         M src/gui_client/gtk_client.c         |       5 ++---
       
       11 files changed, 59 insertions(+), 85 deletions(-)
       ---
 (DIR) diff --git a/po/de.po b/po/de.po
       t@@ -1865,12 +1865,6 @@ msgstr ""
        msgid "%-7tde  %3d"
        msgstr "%-7tde  %3d"
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr "%/Stats: Waffen/%Tde"
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2254,8 +2248,8 @@ msgstr "Du"
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       -msgstr "%/GTK Stats: Waffen/%Tde"
       +msgid "%/Stats: Guns/%Tde"
       +msgstr "%Tde"
        
        #. Display of number of bitches in GTK+ client status window
        #. (%Tde="Bitches" by default)
 (DIR) diff --git a/po/dopewars.pot b/po/dopewars.pot
       t@@ -1771,12 +1771,6 @@ msgstr ""
        msgid "%-7tde  %3d"
        msgstr ""
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr ""
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2154,7 +2148,7 @@ msgstr ""
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       +msgid "%/Stats: Guns/%Tde"
        msgstr ""
        
        #. Display of number of bitches in GTK+ client status window
 (DIR) diff --git a/po/es.po b/po/es.po
       t@@ -1911,12 +1911,6 @@ msgstr "%-7tde  %3d a %P"
        msgid "%-7tde  %3d"
        msgstr "%-7tde  %3d"
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr "%/Situación: Armas/%Tde"
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2298,8 +2292,8 @@ msgstr "Usted"
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       -msgstr "%/Estado GTK: Armas/%Tde"
       +msgid "%/Stats: Guns/%Tde"
       +msgstr "%Tde"
        
        #. Display of number of bitches in GTK+ client status window
        #. (%Tde="Bitches" by default)
 (DIR) diff --git a/po/es_ES.po b/po/es_ES.po
       t@@ -1913,12 +1913,6 @@ msgstr "%-7tde  %3d a %P"
        msgid "%-7tde  %3d"
        msgstr "%-7tde  %3d"
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr "%/Situación: Armas/%Tde"
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2300,8 +2294,8 @@ msgstr "Tú"
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       -msgstr "%/Estado GTK: Armas/%Tde"
       +msgid "%/Stats: Guns/%Tde"
       +msgstr "%Tde"
        
        #. Display of number of bitches in GTK+ client status window
        #. (%Tde="Bitches" by default)
 (DIR) diff --git a/po/fr.po b/po/fr.po
       t@@ -1851,12 +1851,6 @@ msgstr "%-7tde  %3d @ %P"
        msgid "%-7tde  %3d"
        msgstr "%-7tde  %3d"
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr "%/Stats: Flingues/%Tde"
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2234,8 +2228,8 @@ msgstr "Vous"
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       -msgstr "%/GTK Stats: Flingues/%Tde"
       +msgid "%/Stats: Guns/%Tde"
       +msgstr "%Tde"
        
        #. Display of number of bitches in GTK+ client status window
        #. (%Tde="Bitches" by default)
 (DIR) diff --git a/po/fr_CA.po b/po/fr_CA.po
       t@@ -1894,12 +1894,6 @@ msgstr "%-7tde  %3d @ %P"
        msgid "%-7tde  %3d"
        msgstr "%-7tde  %3d"
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr "%/Stats: Guns/%Tde"
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2277,8 +2271,8 @@ msgstr "Toi"
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       -msgstr "%/GTK Stats: Guns/%Tde"
       +msgid "%/Stats: Guns/%Tde"
       +msgstr "%Tde"
        
        #. Display of number of bitches in GTK+ client status window
        #. (%Tde="Bitches" by default)
 (DIR) diff --git a/po/nn.po b/po/nn.po
       t@@ -1882,12 +1882,6 @@ msgstr "%-7tde  %3d @ %P"
        msgid "%-7tde  %3d"
        msgstr "%-7tde  %3d"
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr "%/Stats: Våpen/%Tde"
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2269,8 +2263,8 @@ msgstr "Du"
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       -msgstr "%/GTK Status: Våpen/%Tuf"
       +msgid "%/Stats: Guns/%Tde"
       +msgstr "%Tuf"
        
        #. Display of number of bitches in GTK+ client status window
        #. (%Tde="Bitches" by default)
 (DIR) diff --git a/po/pl.po b/po/pl.po
       t@@ -1840,12 +1840,6 @@ msgstr ""
        msgid "%-7tde  %3d"
        msgstr ""
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr ""
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2223,7 +2217,7 @@ msgstr ""
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       +msgid "%/Stats: Guns/%Tde"
        msgstr ""
        
        #. Display of number of bitches in GTK+ client status window
 (DIR) diff --git a/po/pt_BR.po b/po/pt_BR.po
       t@@ -1849,12 +1849,6 @@ msgstr ""
        msgid "%-7tde  %3d"
        msgstr ""
        
       -#. Title of the "guns" window (the only important bit in this string
       -#. is the "%Tde" which is "Guns" by default)
       -#: src/curses_client/curses_client.c:2032
       -msgid "%/Stats: Guns/%Tde"
       -msgstr "%/Estatísticas: Armas/%Tde"
       -
        #. Display of carried guns (%tde="Baretta", etc. by default)
        #: src/curses_client/curses_client.c:2037
        #, c-format
       t@@ -2232,8 +2226,8 @@ msgstr "(Você)"
        #. Display of carried guns in GTK+ client status window (%Tde="Guns" by
        #. default)
        #: src/gui_client/gtk_client.c:1250
       -msgid "%/GTK Stats: Guns/%Tde"
       -msgstr "%/Estatísticas: Armas/%Tde"
       +msgid "%/Stats: Guns/%Tde"
       +msgstr "%Tde"
        
        #. Display of number of bitches in GTK+ client status window
        #. (%Tde="Bitches" by default)
 (DIR) diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_client.c
       t@@ -242,6 +242,23 @@ static int strcharlen(const char *str)
          return LocaleIsUTF8 ? g_utf8_strlen(str, -1) : strlen(str);
        }
        
       +/* Displays a string right-aligned at the given position (the last character
       +   in the string will be at the given row and column)
       + */
       +static void mvaddrightstr(int row, int col, const gchar *str)
       +{
       +  int len = strcharlen(str);
       +  mvaddstr(row, MAX(col - len + 1, 0), str);
       +}
       +
       +/* Append len spaces to the end of text */
       +static void g_string_pad(GString *text, int len)
       +{
       +  int curlen = text->len;
       +  g_string_set_size(text, curlen + len);
       +  memset(text->str + curlen, ' ', len);
       +}
       +
        /*
         * Displays a string, horizontally centred on the given row
         */
       t@@ -1905,6 +1922,7 @@ void print_location(char *text)
        void print_status(Player *Play, gboolean DispDrug)
        {
          int i, c;
       +  char *p;
          GString *text;
        
          text = g_string_new(NULL);
       t@@ -1960,28 +1978,39 @@ void print_status(Player *Play, gboolean DispDrug)
        
          attrset(StatsAttr);
        
       -  /* Display of the player's cash in the stats window (careful to keep the
       -     formatting if you change the length of the "Cash" word) */
       -  dpg_string_printf(text, _("Cash %17P"), Play->Cash);
       -  mvaddstr(3, 9, text->str);
       +  /* Display of the player's cash in the stats window */
       +  mvaddstr(3, 9, _("Cash"));
       +  p = FormatPrice(Play->Cash);
       +  mvaddrightstr(3, 30, p);
       +  g_free(p);
        
          /* Display of the total number of guns carried (%Tde="Guns" by default) */
       -  dpg_string_printf(text, _("%-19Tde%3d"), Names.Guns,
       -                     TotalGunsCarried(Play));
       +  dpg_string_printf(text, _("%/Stats: Guns/%Tde"), Names.Guns);
          mvaddstr(Network ? 4 : 5, 9, text->str);
       +  dpg_string_printf(text, "%d", TotalGunsCarried(Play));
       +  mvaddrightstr(Network ? 4 : 5, 30, text->str);
        
          /* Display of the player's health */
       -  g_string_printf(text, _("Health             %3d"), Play->Health);
       -  mvaddstr(Network ? 5 : 7, 9, text->str);
       +  mvaddstr(Network ? 5 : 7, 9, _("Health"));
       +  dpg_string_printf(text, "%d", Play->Health);
       +  mvaddrightstr(Network ? 5 : 7, 30, text->str);
        
          /* Display of the player's bank balance */
       -  dpg_string_printf(text, _("Bank %17P"), Play->Bank);
       -  mvaddstr(Network ? 6 : 9, 9, text->str);
       +  mvaddstr(Network ? 6 : 9, 9, _("Bank"));
       +  p = FormatPrice(Play->Bank);
       +  mvaddrightstr(Network ? 6 : 9, 30, p);
       +  g_free(p);
        
          if (Play->Debt > 0)
            attrset(DebtAttr);
          /* Display of the player's debt */
       -  dpg_string_printf(text, _("Debt %17P"), Play->Debt);
       +  g_string_assign(text, _("Debt"));
       +  p = FormatPrice(Play->Debt);
       +  /* Put in one big string otherwise the DebtAttr won't be applied to the
       +     space between "Debt" and the price */
       +  g_string_pad(text, 22 - strcharlen(text->str) - strcharlen(p));
       +  g_string_append(text, p);
       +  g_free(p);
          mvaddstr(Network ? 7 : 11, 9, text->str);
          attrset(TitleAttr);
        
       t@@ -1994,7 +2023,7 @@ void print_status(Player *Play, gboolean DispDrug)
            dpg_string_printf(text, _("%Tde %3d  Space %6d"), Names.Bitches,
                               Play->Bitches.Carried, Play->CoatSize);
          }
       -  mvaddstr(0, Width - 2 - strlen(text->str), text->str);
       +  mvaddrightstr(0, Width - 3, text->str);
          dpg_string_printf(text, _("%/Current location/%tde"),
                             Location[Play->IsAt].Name);
          print_location(text->str);
 (DIR) diff --git a/src/gui_client/gtk_client.c b/src/gui_client/gtk_client.c
       t@@ -1245,9 +1245,8 @@ void DisplayStats(Player *Play, struct StatusWidgets *Status)
          gtk_label_set_text(GTK_LABEL(Status->DebtValue), prstr);
          g_free(prstr);
        
       -  /* Display of carried guns in GTK+ client status window (%Tde="Guns" by
       -     default) */
       -  dpg_string_printf(text, _("%/GTK Stats: Guns/%Tde"), Names.Guns);
       +  /* Display of the total number of guns carried (%Tde="Guns" by default) */
       +  dpg_string_printf(text, _("%/Stats: Guns/%Tde"), Names.Guns);
          gtk_label_set_text(GTK_LABEL(Status->GunsName), text->str);
          g_string_printf(text, "%d", TotalGunsCarried(Play));
          gtk_label_set_text(GTK_LABEL(Status->GunsValue), text->str);