From b38364759d59edc00522a84ed0894e591bbc9adc Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 6 Dec 2022 11:23:11 +0200 Subject: [PATCH 49/49] gtk4: Add AI level entries to connectdlg context menu See osdn #46215 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/pages.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/client/gui-gtk-4.0/pages.c b/client/gui-gtk-4.0/pages.c index b3df9abcbd..45a831eb88 100644 --- a/client/gui-gtk-4.0/pages.c +++ b/client/gui-gtk-4.0/pages.c @@ -1975,29 +1975,32 @@ static GtkWidget *create_conn_menu(struct player *pplayer, } } -#ifdef MENUS_GTK3 if (ALLOW_CTRL <= client.conn.access_level && NULL != pplayer && is_ai(pplayer)) { enum ai_level level; - item = gtk_separator_menu_item_new(); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - for (level = 0; level < AI_LEVEL_COUNT; level++) { if (is_settable_ai_level(level)) { - const char *level_name = ai_level_translated_name(level); - const char *level_cmd = ai_level_cmd(level); - - item = gtk_menu_item_new_with_label(level_name); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - g_object_set_data_full(G_OBJECT(item), "command", - g_strdup(level_cmd), (GDestroyNotify) g_free); - g_signal_connect_swapped(item, "activate", - G_CALLBACK(conn_menu_player_command), menu); + char actbuf[128]; + + buf = g_strdup_printf(_("Difficulty: %s"), ai_level_translated_name(level)); + fc_snprintf(actbuf, sizeof(actbuf), "ailevel_%d", level); + + act = g_simple_action_new(actbuf, NULL); + g_object_set_data_full(G_OBJECT(act), "command", + g_strdup(ai_level_cmd(level)), + (GDestroyNotify) g_free); + g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act)); + g_signal_connect(act, "activate", G_CALLBACK(conn_menu_player_command), menu); + fc_snprintf(actbuf, sizeof(actbuf), "win.ailevel_%d", level); + item = g_menu_item_new(buf, actbuf); + g_free(buf); + g_menu_append_item(menu, item); } } } +#ifdef MENUS_GTK3 if (pplayer && game.info.is_new_game) { const int count = pplayer->team ? player_list_size(team_members(pplayer->team)) : 0; -- 2.35.1