From edca2efbc2a0d1b1bfecdd608444051e3867b45e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 28 Apr 2023 16:45:46 +0300 Subject: [PATCH 28/28] 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 | 10 +++++++++- client/gui-qt/mapctrl.cpp | 4 ++-- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/client/goto.c b/client/goto.c index 618824e573..4255df8f5d 100644 --- a/client/goto.c +++ b/client/goto.c @@ -1506,6 +1506,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) { @@ -1514,6 +1515,7 @@ static void send_rally_path_orders(struct city *pcity, struct unit *punit, memset(&p, 0, sizeof(p)); p.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); @@ -1536,10 +1538,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); } @@ -1571,11 +1574,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; @@ -1588,10 +1590,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); @@ -1601,12 +1604,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 bf9c72298e..4ee7a5b219 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; @@ -89,6 +90,12 @@ void rally_dialog_popup(void) sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); 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 +174,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 ef5db727b4..d857a27edb 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