From df7c986ab5493c7aace1b0b1bc1eebd1513cf66f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 27 May 2023 09:52:44 +0300 Subject: [PATCH 8/8] gtk: Tell if player is observer in left panel See osdn #48045 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/mapview.c | 61 +++++++++++++++++++++-------------- client/gui-gtk-3.0/mapview.c | 45 +++++++++++++++++--------- client/gui-gtk-3.22/mapview.c | 45 +++++++++++++++++--------- 3 files changed, 95 insertions(+), 56 deletions(-) diff --git a/client/gui-gtk-2.0/mapview.c b/client/gui-gtk-2.0/mapview.c index 9c052b8329..6c9ed2057b 100644 --- a/client/gui-gtk-2.0/mapview.c +++ b/client/gui-gtk-2.0/mapview.c @@ -118,7 +118,7 @@ void update_timeout_label(void) void update_info_label(void) { GtkWidget *label; - const struct player *pplayer = client.conn.playing; + const struct player *pplayer = client_player(); label = gtk_frame_get_label_widget(GTK_FRAME(main_frame_civ_name)); if (pplayer != NULL) { @@ -130,17 +130,30 @@ void update_info_label(void) name = nation_plural_for_player(pplayer); c = g_utf8_get_char_validated(name, -1); if ((gunichar) -1 != c && (gunichar) -2 != c) { - gchar nation[MAX_LEN_NAME]; - gchar *next; - gint len; - - len = g_unichar_to_utf8(g_unichar_toupper(c), nation); - nation[len] = '\0'; - next = g_utf8_find_next_char(name, NULL); - if (NULL != next) { - sz_strlcat(nation, next); + const char *obstext = NULL; + int obstextlen = 0; + + if (client_is_observer()) { + obstext = _(" (observer)"); + obstextlen = strlen(obstext); + } + + { + gchar nation[MAX_LEN_NAME + obstextlen]; + gchar *next; + gint len; + + len = g_unichar_to_utf8(g_unichar_toupper(c), nation); + nation[len] = '\0'; + next = g_utf8_find_next_char(name, NULL); + if (NULL != next) { + sz_strlcat(nation, next); + } + if (obstext != NULL) { + sz_strlcat(nation, obstext); + } + gtk_label_set_text(GTK_LABEL(label), nation); } - gtk_label_set_text(GTK_LABEL(label), nation); } else { gtk_label_set_text(GTK_LABEL(label), name); } @@ -156,38 +169,38 @@ void update_info_label(void) client_cooling_sprite(), client_government_sprite()); - if (NULL != client.conn.playing) { + if (NULL != pplayer) { int d = 0; - for (; d < client.conn.playing->economic.luxury /10; d++) { + for (; d < pplayer->economic.luxury / 10; d++) { struct sprite *sprite = get_tax_sprite(tileset, O_LUXURY); gtk_image_set_from_pixbuf(GTK_IMAGE(econ_label[d]), - sprite_get_pixbuf(sprite)); + sprite_get_pixbuf(sprite)); } - - for (; d < (client.conn.playing->economic.science - + client.conn.playing->economic.luxury) / 10; d++) { + + for (; d < (pplayer->economic.science + + pplayer->economic.luxury) / 10; d++) { struct sprite *sprite = get_tax_sprite(tileset, O_SCIENCE); gtk_image_set_from_pixbuf(GTK_IMAGE(econ_label[d]), - sprite_get_pixbuf(sprite)); + sprite_get_pixbuf(sprite)); } - + for (; d < 10; d++) { struct sprite *sprite = get_tax_sprite(tileset, O_GOLD); gtk_image_set_from_pixbuf(GTK_IMAGE(econ_label[d]), - sprite_get_pixbuf(sprite)); + sprite_get_pixbuf(sprite)); } } - + update_timeout_label(); - /* update tooltips. */ + /* Update tooltips. */ gtk_widget_set_tooltip_text(econ_ebox, - _("Shows your current luxury/science/tax rates; " - "click to toggle them.")); + _("Shows your current luxury/science/tax rates; " + "click to toggle them.")); gtk_widget_set_tooltip_text(bulb_ebox, get_bulb_tooltip()); gtk_widget_set_tooltip_text(sun_ebox, get_global_warming_tooltip()); diff --git a/client/gui-gtk-3.0/mapview.c b/client/gui-gtk-3.0/mapview.c index 87624c6bcb..6176f50ece 100644 --- a/client/gui-gtk-3.0/mapview.c +++ b/client/gui-gtk-3.0/mapview.c @@ -121,7 +121,7 @@ void update_timeout_label(void) void update_info_label(void) { GtkWidget *label; - const struct player *pplayer = client.conn.playing; + const struct player *pplayer = client_player(); label = gtk_frame_get_label_widget(GTK_FRAME(main_frame_civ_name)); if (pplayer != NULL) { @@ -133,17 +133,30 @@ void update_info_label(void) name = nation_plural_for_player(pplayer); c = g_utf8_get_char_validated(name, -1); if ((gunichar) -1 != c && (gunichar) -2 != c) { - gchar nation[MAX_LEN_NAME]; - gchar *next; - gint len; - - len = g_unichar_to_utf8(g_unichar_toupper(c), nation); - nation[len] = '\0'; - next = g_utf8_find_next_char(name, NULL); - if (NULL != next) { - sz_strlcat(nation, next); + const char *obstext = NULL; + int obstextlen = 0; + + if (client_is_observer()) { + obstext = _(" (observer)"); + obstextlen = strlen(obstext); + } + + { + gchar nation[MAX_LEN_NAME + obstextlen]; + gchar *next; + gint len; + + len = g_unichar_to_utf8(g_unichar_toupper(c), nation); + nation[len] = '\0'; + next = g_utf8_find_next_char(name, NULL); + if (NULL != next) { + sz_strlcat(nation, next); + } + if (obstext != NULL) { + sz_strlcat(nation, obstext); + } + gtk_label_set_text(GTK_LABEL(label), nation); } - gtk_label_set_text(GTK_LABEL(label), nation); } else { gtk_label_set_text(GTK_LABEL(label), name); } @@ -159,17 +172,17 @@ void update_info_label(void) client_cooling_sprite(), client_government_sprite()); - if (NULL != client.conn.playing) { + if (NULL != pplayer) { int d = 0; - for (; d < client.conn.playing->economic.luxury /10; d++) { + for (; d < pplayer->economic.luxury / 10; d++) { struct sprite *spr = get_tax_sprite(tileset, O_LUXURY); gtk_image_set_from_surface(GTK_IMAGE(econ_label[d]), spr->surface); } - for (; d < (client.conn.playing->economic.science - + client.conn.playing->economic.luxury) / 10; d++) { + for (; d < (pplayer->economic.science + + pplayer->economic.luxury) / 10; d++) { struct sprite *spr = get_tax_sprite(tileset, O_SCIENCE); gtk_image_set_from_surface(GTK_IMAGE(econ_label[d]), spr->surface); @@ -184,7 +197,7 @@ void update_info_label(void) update_timeout_label(); - /* update tooltips. */ + /* Update tooltips. */ gtk_widget_set_tooltip_text(econ_ebox, _("Shows your current luxury/science/tax rates; " "click to toggle them.")); diff --git a/client/gui-gtk-3.22/mapview.c b/client/gui-gtk-3.22/mapview.c index f018328181..99bd5bb0bb 100644 --- a/client/gui-gtk-3.22/mapview.c +++ b/client/gui-gtk-3.22/mapview.c @@ -137,7 +137,7 @@ void update_timeout_label(void) void update_info_label(void) { GtkWidget *label; - const struct player *pplayer = client.conn.playing; + const struct player *pplayer = client_player(); label = gtk_frame_get_label_widget(GTK_FRAME(main_frame_civ_name)); if (pplayer != NULL) { @@ -149,17 +149,30 @@ void update_info_label(void) name = nation_plural_for_player(pplayer); c = g_utf8_get_char_validated(name, -1); if ((gunichar) -1 != c && (gunichar) -2 != c) { - gchar nation[MAX_LEN_NAME]; - gchar *next; - gint len; - - len = g_unichar_to_utf8(g_unichar_toupper(c), nation); - nation[len] = '\0'; - next = g_utf8_find_next_char(name, NULL); - if (NULL != next) { - sz_strlcat(nation, next); + const char *obstext = NULL; + int obstextlen = 0; + + if (client_is_observer()) { + obstext = _(" (observer)"); + obstextlen = strlen(obstext); + } + + { + gchar nation[MAX_LEN_NAME + obstextlen]; + gchar *next; + gint len; + + len = g_unichar_to_utf8(g_unichar_toupper(c), nation); + nation[len] = '\0'; + next = g_utf8_find_next_char(name, NULL); + if (NULL != next) { + sz_strlcat(nation, next); + } + if (obstext != NULL) { + sz_strlcat(nation, obstext); + } + gtk_label_set_text(GTK_LABEL(label), nation); } - gtk_label_set_text(GTK_LABEL(label), nation); } else { gtk_label_set_text(GTK_LABEL(label), name); } @@ -175,17 +188,17 @@ void update_info_label(void) client_cooling_sprite(), client_government_sprite()); - if (NULL != client.conn.playing) { + if (NULL != pplayer) { int d = 0; - for (; d < client.conn.playing->economic.luxury /10; d++) { + for (; d < pplayer->economic.luxury / 10; d++) { struct sprite *spr = get_tax_sprite(tileset, O_LUXURY); gtk_image_set_from_surface(GTK_IMAGE(econ_label[d]), spr->surface); } - for (; d < (client.conn.playing->economic.science - + client.conn.playing->economic.luxury) / 10; d++) { + for (; d < (pplayer->economic.science + + pplayer->economic.luxury) / 10; d++) { struct sprite *spr = get_tax_sprite(tileset, O_SCIENCE); gtk_image_set_from_surface(GTK_IMAGE(econ_label[d]), spr->surface); @@ -200,7 +213,7 @@ void update_info_label(void) update_timeout_label(); - /* update tooltips. */ + /* Update tooltips. */ gtk_widget_set_tooltip_text(econ_ebox, _("Shows your current luxury/science/tax rates; " "click to toggle them.")); -- 2.39.2