From 04e94fe8301504b0a5bb0a2a2d8d87e6203d2f41 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 11 Mar 2023 16:18:29 +0200 Subject: [PATCH 28/28] gtk: Fix trading cities between high id players See osdn #45678 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/diplodlg.c | 35 ++++++++++++++++++++++------------ client/gui-gtk-4.0/diplodlg.c | 33 +++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/client/gui-gtk-3.22/diplodlg.c b/client/gui-gtk-3.22/diplodlg.c index f6bc6418ce..57adbb94bd 100644 --- a/client/gui-gtk-3.22/diplodlg.c +++ b/client/gui-gtk-3.22/diplodlg.c @@ -68,6 +68,12 @@ struct Diplomacy_notebook { GtkWidget *notebook; }; +struct city_deal { + int giver; + int receiver; + int id; +}; + #define SPECLIST_TAG dialog #define SPECLIST_TYPE struct Diplomacy_dialog #include "speclist.h" @@ -390,14 +396,18 @@ static void popup_add_menu(GtkMenuShell *parent, gpointer data) qsort(city_list_ptrs, i, sizeof(struct city *), city_name_compare); for (j = 0; j < i; j++) { + struct city_deal *deal = fc_malloc(sizeof(struct city_deal)); + item = gtk_menu_item_new_with_label(city_name_get(city_list_ptrs[j])); + deal->giver = player_number(pgiver); + deal->receiver = player_number(pother); + deal->id = city_list_ptrs[j]->id; + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect(item, "activate", G_CALLBACK(diplomacy_dialog_city_callback), - GINT_TO_POINTER((player_number(pgiver) << 24) | - (player_number(pother) << 16) | - city_list_ptrs[j]->id)); + (gpointer)deal); } } @@ -1046,20 +1056,21 @@ static void diplomacy_dialog_tech_callback(GtkWidget *w, gpointer data) Callback for trading cities - Kris Bubendorfer ****************************************************************************/ -static void diplomacy_dialog_city_callback(GtkWidget * w, gpointer data) +static void diplomacy_dialog_city_callback(GtkWidget *w, gpointer data) { - size_t choice = GPOINTER_TO_UINT(data); - int giver = (choice >> 24) & 0xff, dest = (choice >> 16) & 0xff, other; - int city = choice & 0xffff; + struct city_deal *deal_data = (struct city_deal *)data; + int other; - if (player_by_number(giver) == client.conn.playing) { - other = dest; + if (player_by_number(deal_data->giver) == client_player()) { + other = deal_data->receiver; } else { - other = giver; + other = deal_data->giver; } - dsend_packet_diplomacy_create_clause_req(&client.conn, other, giver, - CLAUSE_CITY, city); + dsend_packet_diplomacy_create_clause_req(&client.conn, other, deal_data->giver, + CLAUSE_CITY, deal_data->id); + + free(deal_data); } /************************************************************************//** diff --git a/client/gui-gtk-4.0/diplodlg.c b/client/gui-gtk-4.0/diplodlg.c index 5e4091af55..fb460ac170 100644 --- a/client/gui-gtk-4.0/diplodlg.c +++ b/client/gui-gtk-4.0/diplodlg.c @@ -65,6 +65,12 @@ struct Diplomacy_notebook { GtkWidget *notebook; }; +struct city_deal { + int giver; + int receiver; + int id; +}; + #define SPECLIST_TAG dialog #define SPECLIST_TYPE struct Diplomacy_dialog #include "speclist.h" @@ -427,15 +433,19 @@ static GMenu *create_clause_menu(GActionGroup *group, qsort(city_list_ptrs, i, sizeof(struct city *), city_name_compare); for (j = 0; j < i; j++) { + struct city_deal *deal = fc_malloc(sizeof(struct city_deal)); + fc_snprintf(act_name, sizeof(act_name), "city%s%d", act_plr_part, i); act = g_simple_action_new(act_name, NULL); + deal->giver = player_number(pgiver); + deal->receiver = player_number(pother); + deal->id = city_list_ptrs[j]->id; + g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act)); g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_city_callback), - GINT_TO_POINTER((player_number(pgiver) << 24) | - (player_number(pother) << 16) | - city_list_ptrs[j]->id)); + (gpointer)deal); fc_snprintf(act_name, sizeof(act_name), "win.city%s%d", act_plr_part, i); @@ -1113,18 +1123,19 @@ static void diplomacy_dialog_city_callback(GSimpleAction *action, GVariant *parameter, gpointer data) { - size_t choice = GPOINTER_TO_UINT(data); - int giver = (choice >> 24) & 0xff, dest = (choice >> 16) & 0xff, other; - int city = choice & 0xffff; + struct city_deal *deal_data = (struct city_deal *)data; + int other; - if (player_by_number(giver) == client.conn.playing) { - other = dest; + if (player_by_number(deal_data->giver) == client.conn.playing) { + other = deal_data->receiver; } else { - other = giver; + other = deal_data->giver; } - dsend_packet_diplomacy_create_clause_req(&client.conn, other, giver, - CLAUSE_CITY, city); + dsend_packet_diplomacy_create_clause_req(&client.conn, other, deal_data->giver, + CLAUSE_CITY, deal_data->id); + + free(deal_data); } /************************************************************************//** -- 2.39.2