From 86b5359dd09321e259ced35d64087024f1c99230 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 28 Apr 2023 16:45:46 +0300 Subject: [PATCH 34/34] gtk4: Support setting persistent rally points See osdn #47936 Signed-off-by: Marko Lindqvist --- client/goto.c | 23 ++++++++++++++--------- client/goto.h | 6 +++--- client/gui-gtk-3.22/rallypointdlg.c | 2 +- client/gui-gtk-4.0/rallypointdlg.c | 19 ++++++++++++------- client/gui-qt/mapctrl.cpp | 4 ++-- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/client/goto.c b/client/goto.c index 4f91896df2..b27b2661fb 100644 --- a/client/goto.c +++ b/client/goto.c @@ -1503,6 +1503,7 @@ static void send_path_orders(struct unit *punit, struct pf_path *path, ****************************************************************************/ static void send_rally_path_orders(struct city *pcity, struct unit *punit, struct pf_path *path, bool vigilant, + bool persistent, enum unit_orders orders, struct unit_order *final_order) { @@ -1511,6 +1512,7 @@ static void send_rally_path_orders(struct city *pcity, struct unit *punit, memset(&p, 0, sizeof(p)); p.city_id = pcity->id; p.vigilant = vigilant; + p.persistent = persistent; log_goto_packet("Rally orders for city %d:", pcity->id); log_goto_packet(" Vigilant: %d.", p.vigilant); @@ -1533,10 +1535,11 @@ void send_goto_path(struct unit *punit, struct pf_path *path, /************************************************************************//** Send an arbitrary rally path for the city to the server. ****************************************************************************/ -void send_rally_path(struct city *pcity, struct unit *punit, - struct pf_path *path, struct unit_order *final_order) +static void send_rally_path(struct city *pcity, struct unit *punit, + bool persistent, struct pf_path *path, + struct unit_order *final_order) { - send_rally_path_orders(pcity, punit, path, FALSE, + send_rally_path_orders(pcity, punit, path, FALSE, persistent, ORDER_MOVE, final_order); } @@ -1568,11 +1571,10 @@ bool send_goto_tile(struct unit *punit, struct tile *ptile) Send rally orders for the city to move new units to the arbitrary tile. Returns FALSE if no path is found for the currently produced unit type. ****************************************************************************/ -bool send_rally_tile(struct city *pcity, struct tile *ptile) +bool send_rally_tile(struct city *pcity, struct tile *ptile, bool persistent) { const struct unit_type *putype; struct unit *punit; - struct pf_parameter parameter; struct pf_map *pfm; struct pf_path *path; @@ -1585,10 +1587,11 @@ bool send_rally_tile(struct city *pcity, struct tile *ptile) /* Can only give orders to units. */ return FALSE; } + putype = pcity->production.value.utype; - punit = unit_virtual_create( - client_player(), pcity, putype, - city_production_unit_veteran_level(pcity, putype)); + punit = unit_virtual_create(client_player(), pcity, putype, + city_production_unit_veteran_level(pcity, + putype)); /* Use the unit to find a path to the destination tile. */ goto_fill_parameter_base(¶meter, punit); @@ -1598,12 +1601,14 @@ bool send_rally_tile(struct city *pcity, struct tile *ptile) if (path) { /* Send orders to server. */ - send_rally_path(pcity, punit, path, NULL); + send_rally_path(pcity, punit, persistent, path, NULL); unit_virtual_destroy(punit); pf_path_destroy(path); + return TRUE; } else { unit_virtual_destroy(punit); + return FALSE; } } diff --git a/client/goto.h b/client/goto.h index 925beeb800..23ec7fcfd5 100644 --- a/client/goto.h +++ b/client/goto.h @@ -51,10 +51,10 @@ bool is_valid_goto_draw_line(struct tile *dest_tile); void request_orders_cleared(struct unit *punit); void send_goto_path(struct unit *punit, struct pf_path *path, struct unit_order *last_order); -void send_rally_path(struct city *pcity, struct unit *punit, - struct pf_path *path, struct unit_order *final_order); + //void send_rally_path(struct city *pcity, struct unit *punit, + // struct pf_path *path, struct unit_order *final_order); bool send_goto_tile(struct unit *punit, struct tile *ptile); -bool send_rally_tile(struct city *pcity, struct tile *ptile); +bool send_rally_tile(struct city *pcity, struct tile *ptile, bool persistent); bool send_attack_tile(struct unit *punit, struct tile *ptile); void send_patrol_route(void); void send_goto_route(void); diff --git a/client/gui-gtk-3.22/rallypointdlg.c b/client/gui-gtk-3.22/rallypointdlg.c index a827de0ca4..1ddf19e657 100644 --- a/client/gui-gtk-3.22/rallypointdlg.c +++ b/client/gui-gtk-3.22/rallypointdlg.c @@ -171,7 +171,7 @@ bool rally_set_tile(struct tile *ptile) rally_city_id = -1; - if (send_rally_tile(pcity, ptile)) { + if (send_rally_tile(pcity, ptile, FALSE)) { fc_snprintf(buffer, sizeof(buffer), _("%s rally point set. Select another city."), city_name_get(pcity)); diff --git a/client/gui-gtk-4.0/rallypointdlg.c b/client/gui-gtk-4.0/rallypointdlg.c index ab6a201569..96c8098c0a 100644 --- a/client/gui-gtk-4.0/rallypointdlg.c +++ b/client/gui-gtk-4.0/rallypointdlg.c @@ -37,6 +37,7 @@ bool rally_dialog = FALSE; static GtkWidget *instruction_label = NULL; +static GtkWidget *persistent; static int rally_city_id = -1; @@ -67,7 +68,6 @@ void rally_dialog_popup(void) GtkWidget *dlg; GtkWidget *main_box; GtkWidget *sep; - int grid_row = 0; if (rally_dialog_open()) { /* One rally point dialog already open. */ @@ -82,15 +82,19 @@ void rally_dialog_popup(void) gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_NO); gtk_window_set_destroy_with_parent(GTK_WINDOW(dlg), TRUE); - main_box = gtk_grid_new(); - gtk_orientable_set_orientation(GTK_ORIENTABLE(main_box), - GTK_ORIENTATION_VERTICAL); + main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); instruction_label = gtk_label_new(_("First click a city.")); - gtk_grid_attach(GTK_GRID(main_box), instruction_label, 0, grid_row++, 1, 1); + gtk_box_append(GTK_BOX(main_box), instruction_label); sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); - gtk_grid_attach(GTK_GRID(main_box), sep, 0, grid_row++, 1, 1); + gtk_box_append(GTK_BOX(main_box), sep); + + persistent = gtk_check_button_new_with_label(_("Persistent rallypoint")); + gtk_box_append(GTK_BOX(main_box), persistent); + + sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); + gtk_box_append(GTK_BOX(main_box), sep); gtk_box_append(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))), main_box); @@ -167,12 +171,13 @@ bool rally_set_tile(struct tile *ptile) gtk_label_set_text(GTK_LABEL(instruction_label), buffer); } else { char buffer[100]; + bool psist = gtk_check_button_get_active(GTK_CHECK_BUTTON(persistent)); fc_assert(pcity != NULL); rally_city_id = -1; - if (send_rally_tile(pcity, ptile)) { + if (send_rally_tile(pcity, ptile, psist)) { fc_snprintf(buffer, sizeof(buffer), _("%s rally point set. Select another city."), city_name_get(pcity)); diff --git a/client/gui-qt/mapctrl.cpp b/client/gui-qt/mapctrl.cpp index fe1086b276..b9ff0af1ac 100644 --- a/client/gui-qt/mapctrl.cpp +++ b/client/gui-qt/mapctrl.cpp @@ -269,11 +269,11 @@ void map_view::shortcut_pressed(int key) /* Rally point - select tile - skip */ if (bt == Qt::LeftButton && gui()->rallies.hover_tile && ctile != NULL) { char text[1024]; - struct city *rcity = gui()->rallies.rally_city; + fc_assert_ret(rcity != NULL); - if (send_rally_tile(rcity, ctile)) { + if (send_rally_tile(rcity, ctile, FALSE)) { fc_snprintf(text, sizeof(text), _("Tile %s set as rally point from city %s."), tile_link(ctile), city_link(rcity)); -- 2.39.2