From fedc2285efaa5937c236e876fa82ff3931252b55 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 23 Nov 2022 01:30:27 +0200 Subject: [PATCH 22/22] Client: Add "Connect Maglev" Implemented for gtk3(.22)- and qt-clients Requested by alain_bkr See osdn #41990 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/menu.c | 40 +++++++++++++++++++++++++++++++++++++- client/gui-gtk-3.22/menu.c | 40 +++++++++++++++++++++++++++++++++++++- client/gui-qt/menu.cpp | 31 +++++++++++++++++++++++++++++ client/gui-qt/menu.h | 2 ++ data/gtk3.22_menus.xml | 3 +++ data/gtk3_menus.xml | 3 +++ data/helpdata.txt | 1 + 7 files changed, 118 insertions(+), 2 deletions(-) diff --git a/client/gui-gtk-3.0/menu.c b/client/gui-gtk-3.0/menu.c index 2150984ec6..d2ea1d45dc 100644 --- a/client/gui-gtk-3.0/menu.c +++ b/client/gui-gtk-3.0/menu.c @@ -247,6 +247,7 @@ static void build_mine_callback(GtkMenuItem *item, gpointer data); static void plant_callback(GtkMenuItem *item, gpointer data); static void connect_road_callback(GtkMenuItem *item, gpointer data); static void connect_rail_callback(GtkMenuItem *item, gpointer data); +static void connect_maglev_callback(GtkMenuItem *item, gpointer data); static void connect_irrigation_callback(GtkMenuItem *item, gpointer data); static void transform_terrain_callback(GtkMenuItem *item, gpointer data); static void clean_pollution_callback(GtkMenuItem *item, gpointer data); @@ -566,6 +567,8 @@ static struct menu_entry_info menu_entries[] = G_CALLBACK(connect_road_callback), MGROUP_UNIT }, { "CONNECT_RAIL", N_("Connect With Rai_l"), GDK_KEY_l, GDK_CONTROL_MASK, G_CALLBACK(connect_rail_callback), MGROUP_UNIT }, + { "CONNECT_MAGLEV", N_("Connect With _Maglev"), GDK_KEY_m, GDK_CONTROL_MASK, + G_CALLBACK(connect_maglev_callback), MGROUP_UNIT }, { "CONNECT_IRRIGATION", N_("Connect With Irri_gation"), GDK_KEY_i, GDK_CONTROL_MASK, G_CALLBACK(connect_irrigation_callback), MGROUP_UNIT }, @@ -1819,6 +1822,22 @@ static void connect_rail_callback(GtkMenuItem *action, gpointer data) } } +/************************************************************************//** + Action "CONNECT_MAGLEV" callback. +****************************************************************************/ +static void connect_maglev_callback(GtkMenuItem *action, gpointer data) +{ + struct road_type *pmaglev = road_by_gui_type(ROAD_GUI_MAGLEV); + + if (pmaglev != NULL) { + struct extra_type *tgt; + + tgt = road_extra_get(pmaglev); + + key_unit_connect(ACTIVITY_GEN_ROAD, tgt); + } +} + /************************************************************************//** Action "CONNECT_IRRIGATION" callback. ****************************************************************************/ @@ -2344,6 +2363,13 @@ void real_menus_update(void) extra_name_translation(road_extra_get(proad))); menus_rename("CONNECT_RAIL", road_buf); } + + proad = road_by_gui_type(ROAD_GUI_MAGLEV); + if (proad != NULL) { + snprintf(road_buf, sizeof(road_buf), _("Connect With %s"), + extra_name_translation(road_extra_get(proad))); + menus_rename("CONNECT_MAGLEV", road_buf); + } } if (!can_client_issue_orders()) { @@ -2529,6 +2555,18 @@ void real_menus_update(void) } menu_entry_set_sensitive("CONNECT_RAIL", conn_possible); + proad = road_by_gui_type(ROAD_GUI_MAGLEV); + if (proad != NULL) { + struct extra_type *tgt; + + tgt = road_extra_get(proad); + + conn_possible = can_units_do_connect(punits, ACTIVITY_GEN_ROAD, tgt); + } else { + conn_possible = FALSE; + } + menu_entry_set_sensitive("CONNECT_MAGLEV", conn_possible); + extras = extra_type_list_by_cause(EC_IRRIGATION); if (extra_type_list_size(extras) > 0) { @@ -2588,7 +2626,7 @@ void real_menus_update(void) } unit_list_iterate_end; if (pextra != NULL) { - /* TRANS: Build road of specific type (Road/Railroad) */ + /* TRANS: Build road of specific type (Road/Railroad/Maglev) */ snprintf(road_item, sizeof(road_item), _("Build %s"), extra_name_translation(pextra)); menus_rename("BUILD_ROAD", road_item); diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index 6cf9b7c902..931a65b9ed 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -250,6 +250,7 @@ static void build_mine_callback(GtkMenuItem *item, gpointer data); static void plant_callback(GtkMenuItem *item, gpointer data); static void connect_road_callback(GtkMenuItem *item, gpointer data); static void connect_rail_callback(GtkMenuItem *item, gpointer data); +static void connect_maglev_callback(GtkMenuItem *item, gpointer data); static void connect_irrigation_callback(GtkMenuItem *item, gpointer data); static void transform_terrain_callback(GtkMenuItem *item, gpointer data); static void clean_pollution_callback(GtkMenuItem *item, gpointer data); @@ -573,6 +574,8 @@ static struct menu_entry_info menu_entries[] = G_CALLBACK(connect_road_callback), MGROUP_UNIT }, { "CONNECT_RAIL", N_("Connect With Rai_l"), GDK_KEY_l, GDK_CONTROL_MASK, G_CALLBACK(connect_rail_callback), MGROUP_UNIT }, + { "CONNECT_MAGLEV", N_("Connect With _Maglev"), GDK_KEY_m, GDK_CONTROL_MASK, + G_CALLBACK(connect_maglev_callback), MGROUP_UNIT }, { "CONNECT_IRRIGATION", N_("Connect With Irri_gation"), GDK_KEY_i, GDK_CONTROL_MASK, G_CALLBACK(connect_irrigation_callback), MGROUP_UNIT }, @@ -1842,6 +1845,22 @@ static void connect_rail_callback(GtkMenuItem *action, gpointer data) } } +/************************************************************************//** + Action "CONNECT_MAGLEV" callback. +****************************************************************************/ +static void connect_maglev_callback(GtkMenuItem *action, gpointer data) +{ + struct road_type *pmaglev = road_by_gui_type(ROAD_GUI_MAGLEV); + + if (pmaglev != NULL) { + struct extra_type *tgt; + + tgt = road_extra_get(pmaglev); + + key_unit_connect(ACTIVITY_GEN_ROAD, tgt); + } +} + /************************************************************************//** Action "CONNECT_IRRIGATION" callback. ****************************************************************************/ @@ -2369,6 +2388,13 @@ void real_menus_update(void) extra_name_translation(road_extra_get(proad))); menus_rename("CONNECT_RAIL", road_buf); } + + proad = road_by_gui_type(ROAD_GUI_MAGLEV); + if (proad != NULL) { + snprintf(road_buf, sizeof(road_buf), _("Connect With %s"), + extra_name_translation(road_extra_get(proad))); + menus_rename("CONNECT_MAGLEV", road_buf); + } } if (!can_client_issue_orders()) { @@ -2554,6 +2580,18 @@ void real_menus_update(void) } menu_entry_set_sensitive("CONNECT_RAIL", conn_possible); + proad = road_by_gui_type(ROAD_GUI_MAGLEV); + if (proad != NULL) { + struct extra_type *tgt; + + tgt = road_extra_get(proad); + + conn_possible = can_units_do_connect(punits, ACTIVITY_GEN_ROAD, tgt); + } else { + conn_possible = FALSE; + } + menu_entry_set_sensitive("CONNECT_MAGLEV", conn_possible); + extras = extra_type_list_by_cause(EC_IRRIGATION); if (extra_type_list_size(extras) > 0) { @@ -2613,7 +2651,7 @@ void real_menus_update(void) } unit_list_iterate_end; if (pextra != NULL) { - /* TRANS: Build road of specific type (Road/Railroad) */ + /* TRANS: Build road of specific type (Road/Railroad/Maglev) */ snprintf(road_item, sizeof(road_item), _("Build %s"), extra_name_translation(pextra)); menus_rename("BUILD_ROAD", road_item); diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 4a8e5d72d9..c3c092f211 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -1360,6 +1360,10 @@ void mr_menu::setup_menus() menu_list.insert(CONNECT_RAIL, act); act->setShortcut(QKeySequence(tr("ctrl+l"))); connect(act, &QAction::triggered, this, &mr_menu::slot_conn_rail); + act = menu->addAction(_("Connect With Maglev")); + menu_list.insert(CONNECT_MAGLEV, act); + act->setShortcut(QKeySequence(tr("ctrl+m"))); + connect(act, &QAction::triggered, this, &mr_menu::slot_conn_maglev); act = menu->addAction(_("Connect With Irrigation")); menu_list.insert(CONNECT_IRRIGATION, act); act->setShortcut(QKeySequence(tr("ctrl+i"))); @@ -2427,6 +2431,18 @@ void mr_menu::menus_sensitive() } break; + case CONNECT_MAGLEV: + proad = road_by_gui_type(ROAD_GUI_MAGLEV); + if (proad != NULL) { + tgt = road_extra_get(proad); + } else { + break; + } + if (can_units_do_connect(punits, ACTIVITY_GEN_ROAD, tgt)) { + i.value()->setEnabled(true); + } + break; + case CONNECT_IRRIGATION: { struct extra_type_list *extras = extra_type_list_by_cause(EC_IRRIGATION); @@ -2635,6 +2651,21 @@ void mr_menu::slot_conn_rail() } } +/**********************************************************************//** + Action "CONNECT WITH MAGLEV" +**************************************************************************/ +void mr_menu::slot_conn_maglev() +{ + struct road_type *pmaglev = road_by_gui_type(ROAD_GUI_MAGLEV); + + if (pmaglev != NULL) { + struct extra_type *tgt; + + tgt = road_extra_get(pmaglev); + key_unit_connect(ACTIVITY_GEN_ROAD, tgt); + } +} + /**********************************************************************//** Action "BUILD FORTRESS" **************************************************************************/ diff --git a/client/gui-qt/menu.h b/client/gui-qt/menu.h index 053c40509c..3917c26d8d 100644 --- a/client/gui-qt/menu.h +++ b/client/gui-qt/menu.h @@ -63,6 +63,7 @@ enum munit { AUTOSETTLER, CONNECT_ROAD, CONNECT_RAIL, + CONNECT_MAGLEV, CONNECT_IRRIGATION, GOTO_CITY, AIRLIFT, @@ -320,6 +321,7 @@ private slots: void slot_plant(); void slot_conn_road(); void slot_conn_rail(); + void slot_conn_maglev(); void slot_conn_irrigation(); void slot_transform(); void slot_clean_pollution(); diff --git a/data/gtk3.22_menus.xml b/data/gtk3.22_menus.xml index 47b8d5e966..d8886cfc81 100644 --- a/data/gtk3.22_menus.xml +++ b/data/gtk3.22_menus.xml @@ -371,6 +371,9 @@ + + + diff --git a/data/gtk3_menus.xml b/data/gtk3_menus.xml index 56bf51dcab..5b01670295 100644 --- a/data/gtk3_menus.xml +++ b/data/gtk3_menus.xml @@ -365,6 +365,9 @@ + + + diff --git a/data/helpdata.txt b/data/helpdata.txt index 737127bf61..af13fdf46d 100644 --- a/data/helpdata.txt +++ b/data/helpdata.txt @@ -1657,6 +1657,7 @@ Unit Orders:\n\ Ctrl+L: set a rai(L) waypoint (when connecting with rail)\n\ m: build (m)ine or convert terrain (settler/worker units)\n\ M: change terrain by planting\n\ + Ctrl+M: connect current and target tile with M)aglev\n\ n: clean (n)uclear fallout\n\ N: explode (N)uclear\n\ o: transf(o)rm terrain (engineer unit)\n\ -- 2.35.1