From f8170c406414df5cd4211dbcf82e40d55138080b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 1 Oct 2021 02:13:33 +0300 Subject: [PATCH 44/44] Qt: Show default ruler title for a player whose government is not known Intelligence was showing ruler title as if the nation was in Anarchy when it doesn't know player's actual government. Make it to show default "Mr"/"Ms" instead in that case. See osdn #42938 Signed-off-by: Marko Lindqvist --- client/client_main.c | 19 +++++++++++++++++-- client/client_main.h | 2 ++ client/gui-qt/plrdlg.cpp | 2 +- common/government.c | 20 +++++++++++++++----- common/government.h | 2 ++ 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index 8d5fb73540..33f4c7b704 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -1266,8 +1266,23 @@ bool can_meet_with_player(const struct player *pplayer) bool can_intel_with_player(const struct player *pplayer) { return (client_is_observer() - || (NULL != client.conn.playing - && could_intel_with_player(client.conn.playing, pplayer))); + || (NULL != client.conn.playing + && could_intel_with_player(client_player(), pplayer))); +} + +/**********************************************************************//** + Fill best possible title for the player to the given buffer, and + return that buffer. +**************************************************************************/ +const char *title_for_player(const struct player *pplayer, + char *buf, size_t buf_len) +{ + if (client_player() == pplayer || can_intel_with_player(pplayer)) { + /* Knows the government to construct correct title */ + return ruler_title_for_player(pplayer, buf, buf_len); + } + + return default_title_for_player(pplayer, buf, buf_len); } /**********************************************************************//** diff --git a/client/client_main.h b/client/client_main.h index adba91d2a7..b82d5b1bd6 100644 --- a/client/client_main.h +++ b/client/client_main.h @@ -119,6 +119,8 @@ bool can_client_issue_orders(void); bool can_client_change_view(void); bool can_meet_with_player(const struct player *pplayer); bool can_intel_with_player(const struct player *pplayer); +const char *title_for_player(const struct player *pplayer, + char *buf, size_t buf_len); void client_exit(void); diff --git a/client/gui-qt/plrdlg.cpp b/client/gui-qt/plrdlg.cpp index 9a37b91dcc..883521d207 100644 --- a/client/gui-qt/plrdlg.cpp +++ b/client/gui-qt/plrdlg.cpp @@ -524,7 +524,7 @@ void plr_widget::nation_selected(const QItemSelection &sl, QString("
") + _("Nation") + QString("") + QString(nation_adjective_for_player(pplayer)).toHtmlEscaped() + QString("
") + _("Ruler:") + QString("") - + QString(ruler_title_for_player(pplayer, tbuf, sizeof(tbuf))) + + QString(title_for_player(pplayer, tbuf, sizeof(tbuf))) .toHtmlEscaped() + QString("
") + _("Government:") + QString("") + egov.toHtmlEscaped() diff --git a/common/government.c b/common/government.c index 8bb964ddf0..e1d001d2bb 100644 --- a/common/government.c +++ b/common/government.c @@ -407,11 +407,7 @@ const char *ruler_title_for_player(const struct player *pplayer, "nation \"%s\" (nb %d).", government_rule_name(pgovern), government_number(pgovern), nation_rule_name(pnation), nation_number(pnation)); - if (pplayer->is_male) { - fc_snprintf(buf, buf_len, _("Mr. %s"), player_name(pplayer)); - } else { - fc_snprintf(buf, buf_len, _("Ms. %s"), player_name(pplayer)); - } + default_title_for_player(pplayer, buf, buf_len); } else { fc_snprintf(buf, buf_len, name_translation_get(pplayer->is_male @@ -423,6 +419,20 @@ const char *ruler_title_for_player(const struct player *pplayer, return buf; } +/**********************************************************************//** + Return default ruler title of the player (translated). +**************************************************************************/ +const char *default_title_for_player(const struct player *pplayer, + char *buf, size_t buf_len) +{ + if (pplayer->is_male) { + fc_snprintf(buf, buf_len, _("Mr. %s"), player_name(pplayer)); + } else { + fc_snprintf(buf, buf_len, _("Ms. %s"), player_name(pplayer)); + } + + return buf; +} /************************************************************************** Government iterator. diff --git a/common/government.h b/common/government.h index ca364b576a..47f0321b22 100644 --- a/common/government.h +++ b/common/government.h @@ -101,6 +101,8 @@ ruler_title_female_untranslated_name(const struct ruler_title *pruler_title); const char *ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len); +const char *default_title_for_player(const struct player *pplayer, + char *buf, size_t buf_len); /* Ancillary routines */ bool can_change_to_government(struct player *pplayer, -- 2.33.0