From 1ec14227a35e4e4528d1b6d7a531955c3902ca81 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 5 Oct 2022 20:26:50 +0300 Subject: [PATCH 31/31] gtk4: Add pact clauses to the treaty menu See osdn #45774 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/diplodlg.c | 116 ++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 55 deletions(-) diff --git a/client/gui-gtk-4.0/diplodlg.c b/client/gui-gtk-4.0/diplodlg.c index 2b4f3e53d2..7aafe8d438 100644 --- a/client/gui-gtk-4.0/diplodlg.c +++ b/client/gui-gtk-4.0/diplodlg.c @@ -107,12 +107,15 @@ static void diplomacy_dialog_embassy_callback(GSimpleAction *action, static void diplomacy_dialog_shared_tiles_callback(GSimpleAction *action, GVariant *parameter, gpointer data); - -#ifdef MENUS_GTK3 -static void diplomacy_dialog_ceasefire_callback(GtkWidget *w, gpointer data); -static void diplomacy_dialog_peace_callback(GtkWidget *w, gpointer data); -static void diplomacy_dialog_alliance_callback(GtkWidget *w, gpointer data); -#endif /* MENUS_GTK3 */ +static void diplomacy_dialog_ceasefire_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data); +static void diplomacy_dialog_peace_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data); +static void diplomacy_dialog_alliance_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data); static void close_diplomacy_dialog(struct Diplomacy_dialog *pdialog); static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog); @@ -403,7 +406,7 @@ static GMenu *create_clause_menu(GActionGroup *group, any cities not visible to plr1. This means that you can only trade cities visible to requesting player. - - Kris Bubendorfer + - Kris Bubendorfer *****************************************************************/ if (clause_enabled(CLAUSE_CITY)) { int i = 0; @@ -500,7 +503,6 @@ static GMenu *create_clause_menu(GActionGroup *group, g_menu_append_item(topmenu, item); } -#if 0 /* Pacts. */ if (pgiver == pdialog->treaty->plr0) { enum diplstate_type ds; @@ -508,45 +510,62 @@ static GMenu *create_clause_menu(GActionGroup *group, ds = player_diplstate_get(pgiver, pother)->type; - menu = gtk_menu_button_new(); + submenu = g_menu_new(); if (clause_enabled(CLAUSE_CEASEFIRE)) { - item = gtk_menu_item_new_with_mnemonic(Q_("?diplomatic_state:Cease-fire")); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); - g_signal_connect(item, "activate", + fc_snprintf(act_name, sizeof(act_name), "ceasefire%s", act_plr_part); + act = g_simple_action_new(act_name, NULL); + g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act)); + g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_ceasefire_callback), pdialog); - gtk_widget_set_sensitive(item, ds != DS_CEASEFIRE && ds != DS_TEAM); - pact_clause++; + + fc_snprintf(act_name, sizeof(act_name), "win.ceasefire%s", act_plr_part); + item = g_menu_item_new(Q_("?diplomatic_state:Cease-fire"), act_name); + g_menu_append_item(submenu, item); + + g_simple_action_set_enabled(G_SIMPLE_ACTION(act), + ds != DS_CEASEFIRE && ds != DS_TEAM); + pact_clauses++; } if (clause_enabled(CLAUSE_PEACE)) { - item = gtk_menu_item_new_with_mnemonic(Q_("?diplomatic_state:Peace")); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - g_signal_connect(item, "activate", + fc_snprintf(act_name, sizeof(act_name), "peace%s", act_plr_part); + act = g_simple_action_new(act_name, NULL); + g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act)); + g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_peace_callback), pdialog); - gtk_widget_set_sensitive(item, ds != DS_PEACE && ds != DS_TEAM); + + fc_snprintf(act_name, sizeof(act_name), "win.peace%s", act_plr_part); + item = g_menu_item_new(Q_("?diplomatic_state:Peace"), act_name); + g_menu_append_item(submenu, item); + + g_simple_action_set_enabled(G_SIMPLE_ACTION(act), + ds != DS_PEACE && ds != DS_TEAM); pact_clauses++; } if (clause_enabled(CLAUSE_ALLIANCE)) { - item = gtk_menu_item_new_with_mnemonic(Q_("?diplomatic_state:Alliance")); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - g_signal_connect(item, "activate", + fc_snprintf(act_name, sizeof(act_name), "alliance%s", act_plr_part); + act = g_simple_action_new(act_name, NULL); + g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act)); + g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_alliance_callback), pdialog); - gtk_widget_set_sensitive(item, ds != DS_ALLIANCE && ds != DS_TEAM); + + fc_snprintf(act_name, sizeof(act_name), "win.alliance%s", act_plr_part); + item = g_menu_item_new(Q_("?diplomatic_state:Alliance"), act_name); + g_menu_append_item(submenu, item); + + g_simple_action_set_enabled(G_SIMPLE_ACTION(act), + ds != DS_ALLIANCE && ds != DS_TEAM); pact_clauses++; } if (pact_clauses > 0) { - item = gtk_menu_item_new_with_mnemonic(_("_Pacts")); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); - gtk_menu_shell_append(GTK_MENU_SHELL(parent), item); - gtk_widget_show(item); + g_menu_append_submenu(topmenu, _("_Pacts"), G_MENU_MODEL(submenu)); } else { - g_object_unref(menu); + g_object_unref(submenu); } } -#endif return topmenu; } @@ -842,14 +861,6 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, menu = create_clause_menu(group, pdialog, plr1, FALSE); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(aux_menu), G_MENU_MODEL(menu)); -#ifdef MENUS_GTK3 - menuitem = gtk_menu_item_new_with_label(_("Add Clause...")); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu); - gtk_menu_shell_append(GTK_MENU_SHELL(aux_menu), menuitem); - g_object_set_data(G_OBJECT(menu), "plr", plr0); - g_signal_connect(menu, "show", G_CALLBACK(popup_add_menu), pdialog); -#endif /* MENUS_GTK3 */ - /* Main table for clauses and (if activated) gold trading: we. */ table = gtk_grid_new(); gtk_widget_set_halign(table, GTK_ALIGN_CENTER); @@ -929,14 +940,6 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, menu = create_clause_menu(group, pdialog, plr1, TRUE); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(aux_menu), G_MENU_MODEL(menu)); -#ifdef MENUS_GTK3 - menuitem = gtk_menu_item_new_with_label(_("Add Clause...")); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu); - gtk_menu_shell_append(GTK_MENU_SHELL(aux_menu), menuitem); - g_object_set_data(G_OBJECT(menu), "plr", plr1); - g_signal_connect(menu, "show", G_CALLBACK(popup_add_menu), pdialog); -#endif /* MENUS_GTK3 */ - /* Main table for clauses and (if activated) gold trading: they. */ table = gtk_grid_new(); gtk_widget_set_halign(table, GTK_ALIGN_CENTER); @@ -1108,7 +1111,7 @@ static void diplomacy_dialog_tech_callback(GSimpleAction *action, /************************************************************************//** Callback for trading cities - - Kris Bubendorfer + - Kris Bubendorfer ****************************************************************************/ static void diplomacy_dialog_city_callback(GSimpleAction *action, GVariant *parameter, @@ -1161,12 +1164,10 @@ static void diplomacy_dialog_seamap_callback(GSimpleAction *action, GVariant *pa 0); } -#ifdef MENUS_GTK3 /************************************************************************//** Adding pact clause ****************************************************************************/ -static void diplomacy_dialog_add_pact_clause(GtkWidget *w, gpointer data, - int type) +static void diplomacy_dialog_add_pact_clause(gpointer data, int type) { struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *)data; @@ -1179,27 +1180,32 @@ static void diplomacy_dialog_add_pact_clause(GtkWidget *w, gpointer data, /************************************************************************//** Ceasefire pact menu item activated ****************************************************************************/ -static void diplomacy_dialog_ceasefire_callback(GtkWidget *w, gpointer data) +static void diplomacy_dialog_ceasefire_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data) { - diplomacy_dialog_add_pact_clause(w, data, CLAUSE_CEASEFIRE); + diplomacy_dialog_add_pact_clause(data, CLAUSE_CEASEFIRE); } /************************************************************************//** Peace pact menu item activated ****************************************************************************/ -static void diplomacy_dialog_peace_callback(GtkWidget *w, gpointer data) +static void diplomacy_dialog_peace_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data) { - diplomacy_dialog_add_pact_clause(w, data, CLAUSE_PEACE); + diplomacy_dialog_add_pact_clause(data, CLAUSE_PEACE); } /************************************************************************//** Alliance pact menu item activated ****************************************************************************/ -static void diplomacy_dialog_alliance_callback(GtkWidget *w, gpointer data) +static void diplomacy_dialog_alliance_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data) { - diplomacy_dialog_add_pact_clause(w, data, CLAUSE_ALLIANCE); + diplomacy_dialog_add_pact_clause(data, CLAUSE_ALLIANCE); } -#endif /* MENUS_GTK3 */ /************************************************************************//** Shared vision menu item activated -- 2.35.1