From 14da8557d36293771fe319601fafbad11674cedd Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 15 Oct 2021 18:36:22 +0300 Subject: [PATCH 44/44] gtk3.22: Add rally point dialog See osdn #43030 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/Makefile.am | 2 + client/gui-gtk-3.22/mapctrl.c | 3 + client/gui-gtk-3.22/menu.c | 13 ++ client/gui-gtk-3.22/rallypointdlg.c | 188 ++++++++++++++++++++++++++++ client/gui-gtk-3.22/rallypointdlg.h | 22 ++++ data/gtk3.22_menus.xml | 3 + meson.build | 1 + translations/core/POTFILES.in | 1 + 8 files changed, 233 insertions(+) create mode 100644 client/gui-gtk-3.22/rallypointdlg.c create mode 100644 client/gui-gtk-3.22/rallypointdlg.h diff --git a/client/gui-gtk-3.22/Makefile.am b/client/gui-gtk-3.22/Makefile.am index 28725fac75..57586f973e 100644 --- a/client/gui-gtk-3.22/Makefile.am +++ b/client/gui-gtk-3.22/Makefile.am @@ -82,6 +82,8 @@ libgui_gtk3_22_la_SOURCES = \ pages.h \ plrdlg.c \ plrdlg.h \ + rallypointdlg.c \ + rallypointdlg.h \ ratesdlg.h \ repodlgs.c \ repodlgs.h \ diff --git a/client/gui-gtk-3.22/mapctrl.c b/client/gui-gtk-3.22/mapctrl.c index 362b6bc669..268f39abc4 100644 --- a/client/gui-gtk-3.22/mapctrl.c +++ b/client/gui-gtk-3.22/mapctrl.c @@ -54,6 +54,7 @@ #include "inputdlg.h" #include "mapview.h" #include "menu.h" +#include "rallypointdlg.h" #include "mapctrl.h" @@ -275,6 +276,8 @@ gboolean butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer data) if (ptile) { toggle_tile_hilite(ptile); } + } else if (rally_set_tile(ptile)) { + /* Nothing here, rally_set_tile() already did what we wanted */ } else if (infra_placement_mode()) { infra_placement_set_tile(ptile); } else { diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index acdf04d22b..f74b8c3dc3 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -60,6 +60,7 @@ #include "optiondlg.h" #include "pages.h" #include "plrdlg.h" +#include "rallypointdlg.h" #include "ratesdlg.h" #include "repodlgs.h" #include "sprite.h" @@ -209,6 +210,7 @@ static void select_same_type_tile_callback(GtkMenuItem *item, gpointer data); static void select_same_type_cont_callback(GtkMenuItem *item, gpointer data); static void select_same_type_callback(GtkMenuItem *item, gpointer data); static void select_dialog_callback(GtkMenuItem *item, gpointer data); +static void rally_dialog_callback(GtkMenuItem *item, gpointer data); static void infra_dialog_callback(GtkMenuItem *item, gpointer data); static void unit_wait_callback(GtkMenuItem *item, gpointer data); static void unit_done_callback(GtkMenuItem *item, gpointer data); @@ -287,6 +289,8 @@ static struct menu_entry_info menu_entries[] = G_CALLBACK(find_city_callback), MGROUP_SAFE }, { "WORKLISTS", N_("Work_lists"), GDK_KEY_l, GDK_CONTROL_MASK, G_CALLBACK(worklists_callback), MGROUP_SAFE }, + { "RALLY_DLG", N_("Rally point dialog"), GDK_KEY_r, GDK_CONTROL_MASK, + G_CALLBACK(rally_dialog_callback), MGROUP_SAFE }, { "INFRA_DLG", N_("Infra dialog"), GDK_KEY_i, GDK_CONTROL_MASK, G_CALLBACK(infra_dialog_callback), MGROUP_SAFE }, { "CLIENT_LUA_SCRIPT", N_("Client _Lua Script"), 0, 0, @@ -1366,6 +1370,14 @@ static void select_dialog_callback(GtkMenuItem *item, gpointer data) unit_select_dialog_popup(NULL); } +/************************************************************************//** + Open rally point dialog. +****************************************************************************/ +static void rally_dialog_callback(GtkMenuItem *item, gpointer data) +{ + rally_dialog_popup(); +} + /************************************************************************//** Open infra placement dialog. ****************************************************************************/ @@ -2183,6 +2195,7 @@ void real_menus_update(void) menu_entry_set_sensitive("EDIT_MODE", can_conn_enable_editing(&client.conn)); editgui_refresh(); + menu_entry_set_sensitive("RALLY_DLG", can_client_issue_orders()); menu_entry_set_sensitive("INFRA_DLG", terrain_control.infrapoints); { diff --git a/client/gui-gtk-3.22/rallypointdlg.c b/client/gui-gtk-3.22/rallypointdlg.c new file mode 100644 index 0000000000..a827de0ca4 --- /dev/null +++ b/client/gui-gtk-3.22/rallypointdlg.c @@ -0,0 +1,188 @@ +/*********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +/* utility */ +#include "fcintl.h" + +/* common */ +#include "city.h" +#include "game.h" +#include "tile.h" + +/* client */ +#include "client_main.h" +#include "goto.h" + +/* client/gui-gtk-3.22 */ +#include "gui_main.h" +#include "gui_stuff.h" + +#include "rallypointdlg.h" + +bool rally_dialog = FALSE; +static GtkWidget *instruction_label = NULL; + +static int rally_city_id = -1; + +/************************************************************************//** + Is rally point dialog currently open? +****************************************************************************/ +static bool rally_dialog_open(void) +{ + return rally_dialog; +} + +/************************************************************************//** + Handle rally point dialog closing. +****************************************************************************/ +static void rally_response_callback(GtkWidget *dlg, gint arg) +{ + rally_dialog = FALSE; + instruction_label = NULL; + + gtk_widget_destroy(dlg); +} + +/************************************************************************//** + Open rally point placement dialog +****************************************************************************/ +void rally_dialog_popup(void) +{ + GtkWidget *dlg; + GtkWidget *main_box; + GtkWidget *sep; + + if (rally_dialog_open()) { + /* One rally point dialog already open. */ + return; + } + + dlg = gtk_dialog_new_with_buttons(_("Place Rally Point"), NULL, 0, + _("Close"), GTK_RESPONSE_NO, + NULL); + + setup_dialog(dlg, toplevel); + 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); + + instruction_label = gtk_label_new(_("First click a city.")); + gtk_container_add(GTK_CONTAINER(main_box), instruction_label); + + sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); + gtk_container_add(GTK_CONTAINER(main_box), sep); + + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dlg))), + main_box); + + g_signal_connect(dlg, "destroy", G_CALLBACK(rally_response_callback), NULL); + g_signal_connect(dlg, "response", G_CALLBACK(rally_response_callback), NULL); + + gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(dlg))); + gtk_widget_show(dlg); + + rally_dialog = TRUE; +} + +/************************************************************************//** + Which rally point placement phace we are at the moment. +****************************************************************************/ +enum rally_phase rally_placement_phase(void) +{ + if (!rally_dialog) { + return RALLY_NONE; + } + + if (rally_city_id > 0) { + return RALLY_TILE; + } + + return RALLY_CITY; +} + +/************************************************************************//** + Set city or tile for the infra placement. + Returns whether the click was considered to be one for rally dialog. +****************************************************************************/ +bool rally_set_tile(struct tile *ptile) +{ + struct city *pcity = NULL; + enum rally_phase phase = rally_placement_phase(); + + if (phase == RALLY_NONE) { + return FALSE; + } + + if (ptile == NULL) { + return TRUE; + } + + if (rally_city_id > 0) { + pcity = game_city_by_number(rally_city_id); + + if (pcity == NULL || city_owner(pcity) != client_player()) { + /* City destroyed or captured while we've + * been setting the rally point? */ + rally_city_id = -1; + phase = RALLY_CITY; + + gtk_label_set_text(GTK_LABEL(instruction_label), + _("Select another city.")); + } + } + + if (phase == RALLY_CITY) { + char buffer[100]; + + pcity = tile_city(ptile); + + if (pcity == NULL || city_owner(pcity) != client_player()) { + return TRUE; + } + + rally_city_id = pcity->id; + + fc_snprintf(buffer, sizeof(buffer), _("Now select rally point for %s"), + city_name_get(pcity)); + gtk_label_set_text(GTK_LABEL(instruction_label), buffer); + } else { + char buffer[100]; + + fc_assert(pcity != NULL); + + rally_city_id = -1; + + if (send_rally_tile(pcity, ptile)) { + fc_snprintf(buffer, sizeof(buffer), + _("%s rally point set. Select another city."), + city_name_get(pcity)); + } else { + fc_snprintf(buffer, sizeof(buffer), + _("%s rally point setting failed. Select next city."), + city_name_get(pcity)); + } + + gtk_label_set_text(GTK_LABEL(instruction_label), buffer); + } + + return TRUE; +} diff --git a/client/gui-gtk-3.22/rallypointdlg.h b/client/gui-gtk-3.22/rallypointdlg.h new file mode 100644 index 0000000000..73ab6fe7ce --- /dev/null +++ b/client/gui-gtk-3.22/rallypointdlg.h @@ -0,0 +1,22 @@ +/*********************************************************************** + Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ +#ifndef FC__RALLYPOINTDLG_H +#define FC__RALLYPOINTDLG_H + +enum rally_phase { RALLY_NONE, RALLY_CITY, RALLY_TILE }; + +void rally_dialog_popup(void); +enum rally_phase rally_placement_phase(void); +bool rally_set_tile(struct tile *ptile); + +#endif /* FC__RALLYPOINTDLG_H */ diff --git a/data/gtk3.22_menus.xml b/data/gtk3.22_menus.xml index 01529d74c2..075125f691 100644 --- a/data/gtk3.22_menus.xml +++ b/data/gtk3.22_menus.xml @@ -74,6 +74,9 @@ + + + diff --git a/meson.build b/meson.build index f0d54ac7d8..479d40b49e 100644 --- a/meson.build +++ b/meson.build @@ -2184,6 +2184,7 @@ executable('freeciv-gtk3.22', 'client/gui-gtk-3.22/optiondlg.c', 'client/gui-gtk-3.22/pages.c', 'client/gui-gtk-3.22/plrdlg.c', + 'client/gui-gtk-3.22/rallypointdlg.c', 'client/gui-gtk-3.22/repodlgs.c', 'client/gui-gtk-3.22/soundset_dlg.c', 'client/gui-gtk-3.22/spaceshipdlg.c', diff --git a/translations/core/POTFILES.in b/translations/core/POTFILES.in index bf7c614a82..fd57ec0c13 100644 --- a/translations/core/POTFILES.in +++ b/translations/core/POTFILES.in @@ -49,6 +49,7 @@ client/gui-gtk-3.22/messagewin.c client/gui-gtk-3.22/optiondlg.c client/gui-gtk-3.22/pages.c client/gui-gtk-3.22/plrdlg.c +client/gui-gtk-3.22/rallypointdlg.c client/gui-gtk-3.22/repodlgs.c client/gui-gtk-3.22/soundset_dlg.c client/gui-gtk-3.22/spaceshipdlg.c -- 2.33.0