From a74915b8e13ce45ebf5006358e107e7afaa9a856 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 29 Oct 2022 00:52:31 +0300 Subject: [PATCH 25/25] gtk3(.22): Implement Battle Groups menu To make functionality more discoverable. See osdn #45924 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/gui_main.c | 48 ----------- client/gui-gtk-3.0/menu.c | 150 +++++++++++++++++++++++++++++++++ client/gui-gtk-3.22/gui_main.c | 48 ----------- client/gui-gtk-3.22/menu.c | 150 +++++++++++++++++++++++++++++++++ data/gtk3.22_menus.xml | 44 ++++++++++ data/gtk3_menus.xml | 44 ++++++++++ 6 files changed, 388 insertions(+), 96 deletions(-) diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index 55c3a26ea7..4c2f2cd28f 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -473,54 +473,6 @@ static gboolean key_press_map_canvas(GtkWidget *w, GdkEventKey *ev, return FALSE; } - fc_assert(MAX_NUM_BATTLEGROUPS == 4); - - if ((ev->state & GDK_CONTROL_MASK)) { - switch (ev->keyval) { - - case GDK_KEY_F1: - key_unit_assign_battlegroup(0, (ev->state & GDK_SHIFT_MASK)); - return TRUE; - - case GDK_KEY_F2: - key_unit_assign_battlegroup(1, (ev->state & GDK_SHIFT_MASK)); - return TRUE; - - case GDK_KEY_F3: - key_unit_assign_battlegroup(2, (ev->state & GDK_SHIFT_MASK)); - return TRUE; - - case GDK_KEY_F4: - key_unit_assign_battlegroup(3, (ev->state & GDK_SHIFT_MASK)); - return TRUE; - - default: - break; - }; - } else if ((ev->state & GDK_SHIFT_MASK)) { - switch (ev->keyval) { - - case GDK_KEY_F1: - key_unit_select_battlegroup(0, FALSE); - return TRUE; - - case GDK_KEY_F2: - key_unit_select_battlegroup(1, FALSE); - return TRUE; - - case GDK_KEY_F3: - key_unit_select_battlegroup(2, FALSE); - return TRUE; - - case GDK_KEY_F4: - key_unit_select_battlegroup(3, FALSE); - return TRUE; - - default: - break; - }; - } - switch (ev->keyval) { case GDK_KEY_KP_Up: diff --git a/client/gui-gtk-3.0/menu.c b/client/gui-gtk-3.0/menu.c index 11e02eff01..d37035ad12 100644 --- a/client/gui-gtk-3.0/menu.c +++ b/client/gui-gtk-3.0/menu.c @@ -126,6 +126,18 @@ static void report_wow_callback(GtkMenuItem *item, gpointer data); static void report_top_cities_callback(GtkMenuItem *item, gpointer data); static void report_messages_callback(GtkMenuItem *item, gpointer data); static void report_demographic_callback(GtkMenuItem *item, gpointer data); +static void bg_select0_callback(GtkMenuItem *item, gpointer data); +static void bg_assign0_callback(GtkMenuItem *item, gpointer data); +static void bg_append0_callback(GtkMenuItem *item, gpointer data); +static void bg_select1_callback(GtkMenuItem *item, gpointer data); +static void bg_assign1_callback(GtkMenuItem *item, gpointer data); +static void bg_append1_callback(GtkMenuItem *item, gpointer data); +static void bg_select2_callback(GtkMenuItem *item, gpointer data); +static void bg_assign2_callback(GtkMenuItem *item, gpointer data); +static void bg_append2_callback(GtkMenuItem *item, gpointer data); +static void bg_select3_callback(GtkMenuItem *item, gpointer data); +static void bg_assign3_callback(GtkMenuItem *item, gpointer data); +static void bg_append3_callback(GtkMenuItem *item, gpointer data); static void help_overview_callback(GtkMenuItem *item, gpointer data); static void help_playing_callback(GtkMenuItem *item, gpointer data); static void help_policies_callback(GtkMenuItem *item, gpointer data); @@ -253,6 +265,8 @@ static struct menu_entry_info menu_entries[] = NULL, MGROUP_SAFE }, { "MENU_CIVILIZATION", N_("C_ivilization"), 0, 0, NULL, MGROUP_SAFE }, + { "MENU_BATTLE_GROUPS", N_("_Battle Groups"), 0, 0, + NULL, MGROUP_SAFE }, { "MENU_HELP", N_("_Help"), 0, 0, NULL, MGROUP_SAFE }, { "CLEAR_CHAT_LOGS", N_("_Clear Chat Log"), 0, 0, G_CALLBACK(clear_chat_logs_callback), MGROUP_SAFE }, @@ -302,6 +316,46 @@ static struct menu_entry_info menu_entries[] = G_CALLBACK(report_messages_callback), MGROUP_SAFE }, { "REPORT_DEMOGRAPHIC", N_("_Demographics"), GDK_KEY_F11, 0, G_CALLBACK(report_demographic_callback), MGROUP_SAFE }, + + /* Battle Groups menu */ + /* Note that user view: 1 - 4, internal: 0 - 3 */ + { "BATTLE_GROUP_SELECT_0", N_("Select Battle Group 1"), + GDK_KEY_F1, GDK_SHIFT_MASK, + G_CALLBACK(bg_select0_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_ASSIGN_0", N_("Assign Battle Group 1"), + GDK_KEY_F1, GDK_CONTROL_MASK, + G_CALLBACK(bg_assign0_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_APPEND_0", N_("Append to Battle Group 1"), + GDK_KEY_F1, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + G_CALLBACK(bg_append0_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_SELECT_1", N_("Select Battle Group 2"), + GDK_KEY_F1, GDK_SHIFT_MASK, + G_CALLBACK(bg_select1_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_ASSIGN_1", N_("Assign Battle Group 2"), + GDK_KEY_F1, GDK_CONTROL_MASK, + G_CALLBACK(bg_assign1_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_APPEND_1", N_("Append to Battle Group 2"), + GDK_KEY_F1, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + G_CALLBACK(bg_append1_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_SELECT_2", N_("Select Battle Group 3"), + GDK_KEY_F1, GDK_SHIFT_MASK, + G_CALLBACK(bg_select2_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_ASSIGN_2", N_("Assign Battle Group 3"), + GDK_KEY_F1, GDK_CONTROL_MASK, + G_CALLBACK(bg_assign2_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_APPEND_2", N_("Append to Battle Group 3"), + GDK_KEY_F1, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + G_CALLBACK(bg_append2_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_SELECT_3", N_("Select Battle Group 4"), + GDK_KEY_F1, GDK_SHIFT_MASK, + G_CALLBACK(bg_select3_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_ASSIGN_3", N_("Assign Battle Group 4"), + GDK_KEY_F1, GDK_CONTROL_MASK, + G_CALLBACK(bg_assign3_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_APPEND_3", N_("Append to Battle Group 4"), + GDK_KEY_F1, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + G_CALLBACK(bg_append3_callback), MGROUP_SAFE }, + { "HELP_OVERVIEW", N_("?help:Overview"), 0, 0, G_CALLBACK(help_overview_callback), MGROUP_SAFE }, { "HELP_PLAYING", N_("Strategy and Tactics"), 0, 0, @@ -2555,6 +2609,102 @@ static void menu_unit_goto_and_add_accel(GtkWidget *item, action_id act_id, } } +/************************************************************************//** + Item "BATTLE_GROUP_SELECT_0" callback. +****************************************************************************/ +static void bg_select0_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_select_battlegroup(0, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_ASSIGN_0" callback. +****************************************************************************/ +static void bg_assign0_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(0, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_APPEND_0" callback. +****************************************************************************/ +static void bg_append0_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(0, TRUE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_SELECT_1" callback. +****************************************************************************/ +static void bg_select1_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_select_battlegroup(1, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_ASSIGN_1" callback. +****************************************************************************/ +static void bg_assign1_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(1, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_APPEND_1" callback. +****************************************************************************/ +static void bg_append1_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(1, TRUE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_SELECT_2" callback. +****************************************************************************/ +static void bg_select2_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_select_battlegroup(2, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_ASSIGN_2" callback. +****************************************************************************/ +static void bg_assign2_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(2, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_APPEND_2" callback. +****************************************************************************/ +static void bg_append2_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(2, TRUE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_SELECT_3" callback. +****************************************************************************/ +static void bg_select3_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_select_battlegroup(3, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_ASSIGN_3" callback. +****************************************************************************/ +static void bg_assign3_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(3, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_APPEND_3" callback. +****************************************************************************/ +static void bg_append3_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(3, TRUE); +} + /************************************************************************//** Recursively remove previous entries in a menu and its sub menus. ****************************************************************************/ diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index b79a4b8788..40ba70c102 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -452,54 +452,6 @@ static gboolean key_press_map_canvas(GtkWidget *w, GdkEventKey *ev, return FALSE; } - fc_assert(MAX_NUM_BATTLEGROUPS == 4); - - if ((ev->state & GDK_CONTROL_MASK)) { - switch (ev->keyval) { - - case GDK_KEY_F1: - key_unit_assign_battlegroup(0, (ev->state & GDK_SHIFT_MASK)); - return TRUE; - - case GDK_KEY_F2: - key_unit_assign_battlegroup(1, (ev->state & GDK_SHIFT_MASK)); - return TRUE; - - case GDK_KEY_F3: - key_unit_assign_battlegroup(2, (ev->state & GDK_SHIFT_MASK)); - return TRUE; - - case GDK_KEY_F4: - key_unit_assign_battlegroup(3, (ev->state & GDK_SHIFT_MASK)); - return TRUE; - - default: - break; - }; - } else if ((ev->state & GDK_SHIFT_MASK)) { - switch (ev->keyval) { - - case GDK_KEY_F1: - key_unit_select_battlegroup(0, FALSE); - return TRUE; - - case GDK_KEY_F2: - key_unit_select_battlegroup(1, FALSE); - return TRUE; - - case GDK_KEY_F3: - key_unit_select_battlegroup(2, FALSE); - return TRUE; - - case GDK_KEY_F4: - key_unit_select_battlegroup(3, FALSE); - return TRUE; - - default: - break; - }; - } - switch (ev->keyval) { case GDK_KEY_KP_Up: diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index f98353966f..284416d712 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -125,6 +125,18 @@ static void report_wow_callback(GtkMenuItem *item, gpointer data); static void report_top_cities_callback(GtkMenuItem *item, gpointer data); static void report_messages_callback(GtkMenuItem *item, gpointer data); static void report_demographic_callback(GtkMenuItem *item, gpointer data); +static void bg_select0_callback(GtkMenuItem *item, gpointer data); +static void bg_assign0_callback(GtkMenuItem *item, gpointer data); +static void bg_append0_callback(GtkMenuItem *item, gpointer data); +static void bg_select1_callback(GtkMenuItem *item, gpointer data); +static void bg_assign1_callback(GtkMenuItem *item, gpointer data); +static void bg_append1_callback(GtkMenuItem *item, gpointer data); +static void bg_select2_callback(GtkMenuItem *item, gpointer data); +static void bg_assign2_callback(GtkMenuItem *item, gpointer data); +static void bg_append2_callback(GtkMenuItem *item, gpointer data); +static void bg_select3_callback(GtkMenuItem *item, gpointer data); +static void bg_assign3_callback(GtkMenuItem *item, gpointer data); +static void bg_append3_callback(GtkMenuItem *item, gpointer data); static void help_overview_callback(GtkMenuItem *item, gpointer data); static void help_playing_callback(GtkMenuItem *item, gpointer data); static void help_policies_callback(GtkMenuItem *item, gpointer data); @@ -252,6 +264,8 @@ static struct menu_entry_info menu_entries[] = NULL, MGROUP_SAFE }, { "MENU_CIVILIZATION", N_("C_ivilization"), 0, 0, NULL, MGROUP_SAFE }, + { "MENU_BATTLE_GROUPS", N_("_Battle Groups"), 0, 0, + NULL, MGROUP_SAFE }, { "MENU_HELP", N_("_Help"), 0, 0, NULL, MGROUP_SAFE }, { "CLEAR_CHAT_LOGS", N_("_Clear Chat Log"), 0, 0, G_CALLBACK(clear_chat_logs_callback), MGROUP_SAFE }, @@ -301,6 +315,46 @@ static struct menu_entry_info menu_entries[] = G_CALLBACK(report_messages_callback), MGROUP_SAFE }, { "REPORT_DEMOGRAPHIC", N_("_Demographics"), GDK_KEY_F11, 0, G_CALLBACK(report_demographic_callback), MGROUP_SAFE }, + + /* Battle Groups menu */ + /* Note that user view: 1 - 4, internal: 0 - 3 */ + { "BATTLE_GROUP_SELECT_0", N_("Select Battle Group 1"), + GDK_KEY_F1, GDK_SHIFT_MASK, + G_CALLBACK(bg_select0_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_ASSIGN_0", N_("Assign Battle Group 1"), + GDK_KEY_F1, GDK_CONTROL_MASK, + G_CALLBACK(bg_assign0_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_APPEND_0", N_("Append to Battle Group 1"), + GDK_KEY_F1, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + G_CALLBACK(bg_append0_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_SELECT_1", N_("Select Battle Group 2"), + GDK_KEY_F1, GDK_SHIFT_MASK, + G_CALLBACK(bg_select1_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_ASSIGN_1", N_("Assign Battle Group 2"), + GDK_KEY_F1, GDK_CONTROL_MASK, + G_CALLBACK(bg_assign1_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_APPEND_1", N_("Append to Battle Group 2"), + GDK_KEY_F1, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + G_CALLBACK(bg_append1_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_SELECT_2", N_("Select Battle Group 3"), + GDK_KEY_F1, GDK_SHIFT_MASK, + G_CALLBACK(bg_select2_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_ASSIGN_2", N_("Assign Battle Group 3"), + GDK_KEY_F1, GDK_CONTROL_MASK, + G_CALLBACK(bg_assign2_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_APPEND_2", N_("Append to Battle Group 3"), + GDK_KEY_F1, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + G_CALLBACK(bg_append2_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_SELECT_3", N_("Select Battle Group 4"), + GDK_KEY_F1, GDK_SHIFT_MASK, + G_CALLBACK(bg_select3_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_ASSIGN_3", N_("Assign Battle Group 4"), + GDK_KEY_F1, GDK_CONTROL_MASK, + G_CALLBACK(bg_assign3_callback), MGROUP_SAFE }, + { "BATTLE_GROUP_APPEND_3", N_("Append to Battle Group 4"), + GDK_KEY_F1, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + G_CALLBACK(bg_append3_callback), MGROUP_SAFE }, + { "HELP_OVERVIEW", N_("?help:Overview"), 0, 0, G_CALLBACK(help_overview_callback), MGROUP_SAFE }, { "HELP_PLAYING", N_("Strategy and Tactics"), 0, 0, @@ -2554,6 +2608,102 @@ static void menu_unit_goto_and_add_accel(GtkWidget *item, action_id act_id, } } +/************************************************************************//** + Item "BATTLE_GROUP_SELECT_0" callback. +****************************************************************************/ +static void bg_select0_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_select_battlegroup(0, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_ASSIGN_0" callback. +****************************************************************************/ +static void bg_assign0_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(0, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_APPEND_0" callback. +****************************************************************************/ +static void bg_append0_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(0, TRUE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_SELECT_1" callback. +****************************************************************************/ +static void bg_select1_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_select_battlegroup(1, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_ASSIGN_1" callback. +****************************************************************************/ +static void bg_assign1_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(1, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_APPEND_1" callback. +****************************************************************************/ +static void bg_append1_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(1, TRUE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_SELECT_2" callback. +****************************************************************************/ +static void bg_select2_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_select_battlegroup(2, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_ASSIGN_2" callback. +****************************************************************************/ +static void bg_assign2_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(2, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_APPEND_2" callback. +****************************************************************************/ +static void bg_append2_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(2, TRUE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_SELECT_3" callback. +****************************************************************************/ +static void bg_select3_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_select_battlegroup(3, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_ASSIGN_3" callback. +****************************************************************************/ +static void bg_assign3_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(3, FALSE); +} + +/************************************************************************//** + Item "BATTLE_GROUP_APPEND_3" callback. +****************************************************************************/ +static void bg_append3_callback(GtkMenuItem *item, gpointer data) +{ + key_unit_assign_battlegroup(3, TRUE); +} + /************************************************************************//** Recursively remove previous entries in a menu and its sub menus. ****************************************************************************/ diff --git a/data/gtk3.22_menus.xml b/data/gtk3.22_menus.xml index b7d10e14a9..5e9cdbf47b 100644 --- a/data/gtk3.22_menus.xml +++ b/data/gtk3.22_menus.xml @@ -475,6 +475,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/gtk3_menus.xml b/data/gtk3_menus.xml index 320d60c888..61ab946761 100644 --- a/data/gtk3_menus.xml +++ b/data/gtk3_menus.xml @@ -475,6 +475,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.35.1