From 39477b2f852081d1167760f39929d1684e59b128 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 11 Mar 2023 16:18:29 +0200 Subject: [PATCH 14/14] gtk: Fix trading cities between high id players See osdn #45678 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/diplodlg.c | 33 +++++++++++++++++++++----------- client/gui-gtk-3.22/diplodlg.c | 35 ++++++++++++++++++++++------------ client/gui-gtk-4.0/diplodlg.c | 33 +++++++++++++++++++++----------- 3 files changed, 67 insertions(+), 34 deletions(-) diff --git a/client/gui-gtk-3.0/diplodlg.c b/client/gui-gtk-3.0/diplodlg.c index c980e3ce84..80e250aa66 100644 --- a/client/gui-gtk-3.0/diplodlg.c +++ b/client/gui-gtk-3.0/diplodlg.c @@ -67,6 +67,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" @@ -380,14 +386,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); } } @@ -1031,18 +1041,19 @@ static void diplomacy_dialog_tech_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-3.22/diplodlg.c b/client/gui-gtk-3.22/diplodlg.c index 6fe44839e1..2196a30e87 100644 --- a/client/gui-gtk-3.22/diplodlg.c +++ b/client/gui-gtk-3.22/diplodlg.c @@ -67,6 +67,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" @@ -380,14 +386,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); } } @@ -1023,20 +1033,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 fef66773a9..8d4c162f0d 100644 --- a/client/gui-gtk-4.0/diplodlg.c +++ b/client/gui-gtk-4.0/diplodlg.c @@ -64,6 +64,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" @@ -414,15 +420,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); @@ -1085,18 +1095,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