From a9d5681464885e034766b67494d2cb01edb16538 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 2 Sep 2023 16:46:59 +0300 Subject: [PATCH 15/15] gtk4: Add "About Current Musicset" menu entry See osdn #48566 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/menu.c | 18 ++++++++ client/gui-qt/helpdlg.cpp | 7 +-- client/helpdata.c | 94 +++++++++++++++++++++++++++++++++++++- client/include/helpdlg_g.h | 5 +- client/music.c | 16 +++++++ client/music.h | 2 + tools/manual/fc_manual.c | 17 +++++++ 7 files changed, 152 insertions(+), 7 deletions(-) diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c index 2b53c360b4..d770e00a40 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -233,6 +233,9 @@ static void help_ruleset_callback(GSimpleAction *action, static void help_tileset_callback(GSimpleAction *action, GVariant *parameter, gpointer data); +static void help_musicset_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data); static void help_nations_callback(GSimpleAction *action, GVariant *parameter, gpointer data); @@ -977,6 +980,9 @@ static struct menu_entry_info menu_entries[] = { "HELP_TILESET", N_("About Current Tileset"), "help_tileset", NULL, MGROUP_SAFE, NULL, FALSE }, + { "HELP_MUSICSET", N_("About Current Musicset"), + "help_musicset", NULL, MGROUP_SAFE, + NULL, FALSE }, { "HELP_NATIONS", N_("About Nations"), "help_nations", NULL, MGROUP_SAFE, NULL, FALSE }, @@ -1153,6 +1159,7 @@ const GActionEntry acts[] = { { "help_space_race", help_space_race_callback }, { "help_ruleset", help_ruleset_callback }, { "help_tileset", help_tileset_callback }, + { "help_musicset", help_musicset_callback }, { "help_nations", help_nations_callback }, { "help_connecting", help_connecting_callback }, { "help_controls", help_controls_callback }, @@ -1608,6 +1615,16 @@ static void help_tileset_callback(GSimpleAction *action, popup_help_dialog_string(HELP_TILESET_ITEM); } +/************************************************************************//** + Item "HELP_MUSICSET" callback. +****************************************************************************/ +static void help_musicset_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data) +{ + popup_help_dialog_string(HELP_MUSICSET_ITEM); +} + /************************************************************************//** Item "HELP_NATIONS" callback. ****************************************************************************/ @@ -3255,6 +3272,7 @@ static GMenu *setup_menus(GtkApplication *app) menu_entry_init(topmenu, "HELP_SPACE_RACE"); menu_entry_init(topmenu, "HELP_RULESET"); menu_entry_init(topmenu, "HELP_TILESET"); + menu_entry_init(topmenu, "HELP_MUSICSET"); menu_entry_init(topmenu, "HELP_NATIONS"); menu_entry_init(topmenu, "HELP_CONNECTING"); menu_entry_init(topmenu, "HELP_CONTROLS"); diff --git a/client/gui-qt/helpdlg.cpp b/client/gui-qt/helpdlg.cpp index ff238b289d..fbb5a812f3 100644 --- a/client/gui-qt/helpdlg.cpp +++ b/client/gui-qt/helpdlg.cpp @@ -59,9 +59,9 @@ static canvas *terrain_canvas(struct terrain *terrain, enum extra_cause cause = EC_COUNT); /**********************************************************************//** - Popup the help dialog to get help on the given string topic. Note - that the topic may appear in multiple sections of the help (it may - be both an improvement and a unit, for example). + Popup the help dialog to get help on the given string topic. + Note that the topic may appear in multiple sections of the help + (it may be both an improvement and a unit, for example). The given string should be untranslated. **************************************************************************/ @@ -810,6 +810,7 @@ void help_widget::set_topic(const help_item *topic) case HELP_MULTIPLIER: case HELP_RULESET: case HELP_TILESET: + case HELP_MUSICSET: case HELP_TEXT: set_topic_other(topic, title); break; diff --git a/client/helpdata.c b/client/helpdata.c index 11ff6ae1eb..49c2374bc7 100644 --- a/client/helpdata.c +++ b/client/helpdata.c @@ -12,8 +12,8 @@ ***********************************************************************/ /*********************************************************************** - This module is for generic handling of help data, independent - of gui considerations. + This module is for generic handling of help data, independent + of gui considerations. ***********************************************************************/ #ifdef HAVE_CONFIG_H @@ -54,6 +54,7 @@ #include "client_main.h" #include "climisc.h" #include "gui_main_g.h" /* client_string */ +#include "music.h" #include "helpdata.h" @@ -1022,6 +1023,95 @@ void boot_help_texts(void) help_list_append(help_nodes, pitem); } break; + case HELP_MUSICSET: + { + /* TODO: Parts related to musicset name and version + * currently commented out, untile the musicspec + * format supports them. */ + int desc_len; + int len; + // const char *ms_name = musicset_name_get(tileset); + // const char *version = musicset_version(tileset); + const char *summary = current_musicset_summary(); + const char *description = current_musicset_description(); + + pitem = new_help_item(HELP_MUSICSET); + fc_snprintf(name, sizeof(name), "%*s%s", level, "", + Q_(HELP_MUSICSET_ITEM)); + pitem->topic = fc_strdup(name); + if (description != NULL) { + desc_len = strlen("\n\n") + strlen(description); + } else { + desc_len = 0; + } + if (summary != NULL) { +#if 0 + if (version[0] != '\0') { + len = strlen(_(ts_name)) + + strlen(" ") + + strlen(version) + + strlen("\n\n") + + strlen(_(summary)) + + 1; + + pitem->text = fc_malloc(len + desc_len); + fc_snprintf(pitem->text, len, "%s %s\n\n%s", + _(ts_name), version, _(summary)); + } else { + len = strlen(_(ms_name)) + + strlen("\n\n") + + strlen(_(summary)) + + 1; + + pitem->text = fc_malloc(len + desc_len); + fc_snprintf(pitem->text, len, "%s\n\n%s", + _(ms_name), _(summary)); + } +#else + len = strlen(_(summary)) + 1; + pitem->text = fc_malloc(len + desc_len); + fc_snprintf(pitem->text, len, "%s", _(summary)); +#endif + } else { + const char *nodesc = _("Current musicset contains no summary."); + +#if 0 + if (version[0] != '\0') { + len = strlen(_(ms_name)) + + strlen(" ") + + strlen(version) + + strlen("\n\n") + + strlen(nodesc) + + 1; + + pitem->text = fc_malloc(len + desc_len); + fc_snprintf(pitem->text, len, "%s %s\n\n%s", + _(ms_name), version, + nodesc); + } else { + len = strlen(_(ms_name)) + + strlen("\n\n") + + strlen(nodesc) + + 1; + + pitem->text = fc_malloc(len + desc_len); + fc_snprintf(pitem->text, len, "%s\n\n%s", + _(ms_name), + nodesc); + } +#else + len = strlen(nodesc) + 1; + pitem->text = fc_malloc(len + desc_len); + fc_snprintf(pitem->text, len, "%s", nodesc); +#endif + } + if (description != NULL) { + fc_strlcat(pitem->text, "\n\n", len + desc_len); + fc_strlcat(pitem->text, description, len + desc_len); + } + help_list_append(help_nodes, pitem); + } + break; case HELP_NATIONS: nations_iterate(pnation) { if (client_state() < C_S_RUNNING diff --git a/client/include/helpdlg_g.h b/client/include/helpdlg_g.h index e6038ad82f..1c0db32227 100644 --- a/client/include/helpdlg_g.h +++ b/client/include/helpdlg_g.h @@ -20,8 +20,8 @@ enum help_page_type { HELP_ANY, HELP_TEXT, HELP_UNIT, HELP_IMPROVEMENT, HELP_WONDER, HELP_TECH, HELP_TERRAIN, HELP_EXTRA, HELP_GOODS, HELP_SPECIALIST, HELP_GOVERNMENT, - HELP_RULESET, HELP_TILESET, HELP_NATIONS, - HELP_MULTIPLIER, HELP_LAST }; + HELP_RULESET, HELP_TILESET, HELP_MUSICSET, + HELP_NATIONS, HELP_MULTIPLIER, HELP_LAST }; GUI_FUNC_PROTO(void, popup_help_dialog_string, const char *item) GUI_FUNC_PROTO(void, popup_help_dialog_typed, const char *item, @@ -39,6 +39,7 @@ GUI_FUNC_PROTO(void, popdown_help_dialog, void) #define HELP_CONTROLS_ITEM N_("Controls") #define HELP_RULESET_ITEM N_("About Current Ruleset") #define HELP_TILESET_ITEM N_("About Current Tileset") +#define HELP_MUSICSET_ITEM N_("About Current Musicset") #define HELP_NATIONS_ITEM N_("About Nations") #define HELP_ECONOMY_ITEM N_("Economy") #define HELP_CITIES_ITEM N_("Cities") diff --git a/client/music.c b/client/music.c index 544489aefe..afcf7310e0 100644 --- a/client/music.c +++ b/client/music.c @@ -202,3 +202,19 @@ void musicspec_close(struct section_file *tagfile) secfile_destroy(tagfile); } } + +/**********************************************************************//** + Return summary of the current musicset. Can be NULL. +**************************************************************************/ +const char *current_musicset_summary(void) +{ + return ms_summary; +} + +/**********************************************************************//** + Return description of the current musicset. Can be NULL. +**************************************************************************/ +const char *current_musicset_description(void) +{ + return ms_description; +} diff --git a/client/music.h b/client/music.h index 1790dede98..c5a2b09f2d 100644 --- a/client/music.h +++ b/client/music.h @@ -30,6 +30,8 @@ void musicspec_reread_callback(struct option *poption); struct section_file *musicspec_load(const char *ms_filename); void musicspec_close(struct section_file *tagfile); +const char *current_musicset_summary(void); +const char *current_musicset_description(void); #ifdef __cplusplus } diff --git a/tools/manual/fc_manual.c b/tools/manual/fc_manual.c index fe7240153c..09e75c575b 100644 --- a/tools/manual/fc_manual.c +++ b/tools/manual/fc_manual.c @@ -54,6 +54,7 @@ #include "climisc.h" #include "helpdata.h" #include "helpdlg_g.h" +#include "music.h" #include "tilespec.h" /* server */ @@ -270,6 +271,22 @@ const char *tileset_description(struct tileset *t) return NULL; } +/**********************************************************************//** + Client stub +**************************************************************************/ +const char *current_musicset_summary(void) +{ + return NULL; +} + +/**********************************************************************//** + Client stub +**************************************************************************/ +const char *current_musicset_description(void) +{ + return NULL; +} + /**********************************************************************//** Mostly a client stub. **************************************************************************/ -- 2.40.1