From ab1ecf0c094e4e9fcb49e981656fb81e6f392cdd Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 19 Mar 2023 08:18:36 +0200 Subject: [PATCH 10/10] Add tooltip for Turn Done button when fixedlength enabled Affects gtk- and Qt-clients. Requested by Alina Lenk See osdn #45887 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/gui_main.c | 25 ++++++++++++++-- client/gui-gtk-2.0/gui_main.h | 6 ++-- client/gui-gtk-2.0/mapctrl.c | 2 ++ client/gui-gtk-3.0/gui_main.c | 54 ++++++++++++++++++++++------------ client/gui-gtk-3.0/gui_main.h | 8 +++-- client/gui-gtk-3.22/gui_main.c | 41 ++++++++++++++++++-------- client/gui-gtk-3.22/gui_main.h | 6 ++-- client/gui-gtk-3.22/mapctrl.c | 2 ++ client/gui-qt/fc_client.cpp | 1 + client/gui-qt/gui_main.cpp | 2 +- client/gui-qt/mapctrl.cpp | 7 +++-- client/gui-qt/mapview.cpp | 5 ++-- client/gui-qt/sidebar.cpp | 19 ++++++++++++ client/gui-qt/sidebar.h | 3 +- 14 files changed, 132 insertions(+), 49 deletions(-) diff --git a/client/gui-gtk-2.0/gui_main.c b/client/gui-gtk-2.0/gui_main.c index b5c7b29765..4083e11e2d 100644 --- a/client/gui-gtk-2.0/gui_main.c +++ b/client/gui-gtk-2.0/gui_main.c @@ -1003,8 +1003,27 @@ static gboolean right_notebook_button_release(GtkWidget *widget, return FALSE; } +/**********************************************************************//** + Update tooltip of the Turn Done button +**************************************************************************/ +void update_turn_done_tooltip(void) +{ + struct option *opt = optset_option_by_name(server_optset, "fixedlength"); + + if (opt != NULL && option_bool_get(opt)) { + gtk_widget_set_tooltip_text(turn_done_button, + _("Fixed length turns")); + } else { + char buf[256]; + + fc_snprintf(buf, sizeof(buf), "%s:\n%s", + _("Turn Done"), _("Shift+Return")); + gtk_widget_set_tooltip_text(turn_done_button, buf); + } +} + /************************************************************************** - do the heavy lifting for the widget setup. + Do the heavy lifting for the widget setup. **************************************************************************/ static void setup_widgets(void) { @@ -1049,7 +1068,7 @@ static void setup_widgets(void) ingame_votebar = voteinfo_bar_new(FALSE); - /* *** everything in the top *** */ + /* *** Everything in the top *** */ page = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(page), @@ -1094,7 +1113,7 @@ static void setup_widgets(void) vbox = gtk_vbox_new(FALSE, 3); gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); - /* overview canvas */ + /* Overview canvas */ ahbox = detached_widget_new(); gtk_box_pack_start(GTK_BOX(vbox), ahbox, FALSE, FALSE, 0); avbox = detached_widget_fill(ahbox); diff --git a/client/gui-gtk-2.0/gui_main.h b/client/gui-gtk-2.0/gui_main.h index 3ef7e53356..980355088c 100644 --- a/client/gui-gtk-2.0/gui_main.h +++ b/client/gui-gtk-2.0/gui_main.h @@ -23,7 +23,7 @@ #define GUI_GTK_OPTION(optname) gui_options.gui_gtk3_##optname -/* network string charset conversion */ +/* Network string charset conversion */ gchar *ntoh_str(const gchar *netstr); extern GtkStyle *city_names_style; @@ -94,4 +94,6 @@ void refresh_chat_buttons(void); bool is_gui_up(void); -#endif /* FC__GUI_MAIN_H */ +void update_turn_done_tooltip(void); + +#endif /* FC__GUI_MAIN_H */ diff --git a/client/gui-gtk-2.0/mapctrl.c b/client/gui-gtk-2.0/mapctrl.c index 6078a1bd55..e344256480 100644 --- a/client/gui-gtk-2.0/mapctrl.c +++ b/client/gui-gtk-2.0/mapctrl.c @@ -201,6 +201,8 @@ void popup_newcity_dialog(struct unit *punit, const char *suggestname) void set_turn_done_button_state(bool state) { gtk_widget_set_sensitive(turn_done_button, state); + + update_turn_done_tooltip(); } /************************************************************************** diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index 8dbf119a0f..c5a2fe1dbd 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -1028,6 +1028,25 @@ static void setup_canvas_color_for_state(GtkStateFlags state) &get_color(tileset, COLOR_OVERVIEW_UNKNOWN)->color); } +/************************************************************************** + Update tooltip of the Turn Done button +**************************************************************************/ +void update_turn_done_tooltip(void) +{ + struct option *opt = optset_option_by_name(server_optset, "fixedlength"); + + if (opt != NULL && option_bool_get(opt)) { + gtk_widget_set_tooltip_text(turn_done_button, + _("Fixed length turns")); + } else { + char buf[256]; + + fc_snprintf(buf, sizeof(buf), "%s:\n%s", + _("Turn Done"), _("Shift+Return")); + gtk_widget_set_tooltip_text(turn_done_button, buf); + } +} + /************************************************************************** Do the heavy lifting for the widget setup. **************************************************************************/ @@ -1037,7 +1056,6 @@ static void setup_widgets(void) GtkWidget *frame, *table, *table2, *paned, *sw, *text; GtkWidget *button, *view, *vgrid, *right_vbox = NULL; int i; - char buf[256]; struct sprite *spr; GtkWidget *notebook, *statusbar; GtkWidget *dtach_lowbox = NULL; @@ -1046,9 +1064,9 @@ static void setup_widgets(void) notebook = gtk_notebook_new(); - /* stop mouse wheel notebook page switching. */ + /* Stop mouse wheel notebook page switching. */ g_signal_connect(notebook, "scroll_event", - G_CALLBACK(gtk_true), NULL); + G_CALLBACK(gtk_true), NULL); toplevel_tabs = notebook; gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE); @@ -1123,7 +1141,7 @@ static void setup_widgets(void) overview_canvas_store_height = OVERVIEW_CANVAS_STORE_HEIGHT; } - /* this holds the overview canvas, production info, etc. */ + /* This holds the overview canvas, production info, etc. */ vgrid = gtk_grid_new(); gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid), GTK_ORIENTATION_VERTICAL); @@ -1133,7 +1151,7 @@ static void setup_widgets(void) gtk_grid_attach_next_to(GTK_GRID(hgrid), vgrid, right_vbox, GTK_POS_LEFT, 1, 1); - /* overview canvas */ + /* Overview canvas */ ahbox = detached_widget_new(); gtk_widget_set_hexpand(ahbox, FALSE); gtk_widget_set_vexpand(ahbox, FALSE); @@ -1143,15 +1161,15 @@ static void setup_widgets(void) overview_scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_container_set_border_width(GTK_CONTAINER (overview_scrolled_window), 1); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (overview_scrolled_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); overview_canvas = gtk_drawing_area_new(); gtk_widget_set_halign(overview_canvas, GTK_ALIGN_CENTER); gtk_widget_set_valign(overview_canvas, GTK_ALIGN_CENTER); gtk_widget_set_size_request(overview_canvas, overview_canvas_store_width, - overview_canvas_store_height); + overview_canvas_store_height); gtk_widget_set_size_request(overview_scrolled_window, overview_canvas_store_width, - overview_canvas_store_height); + overview_canvas_store_height); gtk_widget_set_hexpand(overview_canvas, TRUE); gtk_widget_set_vexpand(overview_canvas, TRUE); @@ -1164,13 +1182,13 @@ static void setup_widgets(void) overview_canvas); g_signal_connect(overview_canvas, "draw", - G_CALLBACK(overview_canvas_draw), NULL); + G_CALLBACK(overview_canvas_draw), NULL); g_signal_connect(overview_canvas, "motion_notify_event", - G_CALLBACK(move_overviewcanvas), NULL); + G_CALLBACK(move_overviewcanvas), NULL); g_signal_connect(overview_canvas, "button_press_event", - G_CALLBACK(butt_down_overviewcanvas), NULL); + G_CALLBACK(butt_down_overviewcanvas), NULL); /* The rest */ @@ -1216,7 +1234,7 @@ static void setup_widgets(void) gtk_grid_set_column_homogeneous(GTK_GRID(table), TRUE); gtk_container_add(GTK_CONTAINER(avbox), table); - /* citizens for taxrates */ + /* Citizens for taxrates */ ebox = gtk_event_box_new(); gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE); gtk_grid_attach(GTK_GRID(table), ebox, 0, 0, 10, 1); @@ -1240,7 +1258,7 @@ static void setup_widgets(void) gtk_container_add(GTK_CONTAINER(ebox), econ_label[i]); } - /* science, environmental, govt, timeout */ + /* Science, environmental, govt, timeout */ spr = client_research_sprite(); if (spr != NULL) { bulb_label = gtk_image_new_from_surface(spr->surface); @@ -1301,7 +1319,7 @@ static void setup_widgets(void) gtk_container_add(GTK_CONTAINER(frame), timeout_label); - /* turn done */ + /* Turn done */ turn_done_button = gtk_button_new_with_label(_("Turn Done")); gtk_grid_attach(GTK_GRID(table), turn_done_button, 0, 2, 10, 1); @@ -1309,9 +1327,7 @@ static void setup_widgets(void) g_signal_connect(turn_done_button, "clicked", G_CALLBACK(end_turn_callback), NULL); - fc_snprintf(buf, sizeof(buf), "%s:\n%s", - _("Turn Done"), _("Shift+Return")); - gtk_widget_set_tooltip_text(turn_done_button, buf); + update_turn_done_tooltip(); /* Selected unit status */ @@ -2013,8 +2029,8 @@ static gboolean show_info_popup(GtkWidget *w, GdkEventButton *ev, gpointer data) **************************************************************************/ static void end_turn_callback(GtkWidget *w, gpointer data) { - gtk_widget_set_sensitive(turn_done_button, FALSE); - user_ended_turn(); + gtk_widget_set_sensitive(turn_done_button, FALSE); + user_ended_turn(); } /************************************************************************** diff --git a/client/gui-gtk-3.0/gui_main.h b/client/gui-gtk-3.0/gui_main.h index 9991ac8589..68612b7c62 100644 --- a/client/gui-gtk-3.0/gui_main.h +++ b/client/gui-gtk-3.0/gui_main.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** 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 @@ -22,7 +22,7 @@ #define GUI_GTK_OPTION_STR(optname) "gui_gtk3_" #optname #define GUI_GTK_DEFAULT_THEME_NAME FC_GTK3_DEFAULT_THEME_NAME -/* network string charset conversion */ +/* Network string charset conversion */ gchar *ntoh_str(const gchar *netstr); extern PangoFontDescription *city_names_style; @@ -85,4 +85,6 @@ struct video_mode *resolution_request_get(void); bool is_gui_up(void); -#endif /* FC__GUI_MAIN_H */ +void update_turn_done_tooltip(void); + +#endif /* FC__GUI_MAIN_H */ diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index babe4df263..bde3ac62cd 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -1048,6 +1048,25 @@ static void setup_canvas_color_for_state(GtkStateFlags state) } #endif +/************************************************************************** + Update tooltip of the Turn Done button +**************************************************************************/ +void update_turn_done_tooltip(void) +{ + struct option *opt = optset_option_by_name(server_optset, "fixedlength"); + + if (opt != NULL && option_bool_get(opt)) { + gtk_widget_set_tooltip_text(turn_done_button, + _("Fixed length turns")); + } else { + char buf[256]; + + fc_snprintf(buf, sizeof(buf), "%s:\n%s", + _("Turn Done"), _("Shift+Return")); + gtk_widget_set_tooltip_text(turn_done_button, buf); + } +} + /************************************************************************** Do the heavy lifting for the widget setup. **************************************************************************/ @@ -1057,7 +1076,6 @@ static void setup_widgets(void) GtkWidget *frame, *table, *table2, *paned, *sw, *text; GtkWidget *button, *view, *vgrid, *right_vbox = NULL; int i; - char buf[256]; GtkWidget *notebook, *statusbar; GtkWidget *dtach_lowbox = NULL; struct sprite *spr; @@ -1066,9 +1084,9 @@ static void setup_widgets(void) notebook = gtk_notebook_new(); - /* stop mouse wheel notebook page switching. */ + /* Stop mouse wheel notebook page switching. */ g_signal_connect(notebook, "scroll_event", - G_CALLBACK(gtk_true), NULL); + G_CALLBACK(gtk_true), NULL); toplevel_tabs = notebook; gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE); @@ -1153,7 +1171,7 @@ static void setup_widgets(void) gtk_grid_attach_next_to(GTK_GRID(hgrid), vgrid, right_vbox, GTK_POS_LEFT, 1, 1); - /* overview canvas */ + /* Overview canvas */ ahbox = detached_widget_new(); gtk_widget_set_hexpand(ahbox, FALSE); gtk_widget_set_vexpand(ahbox, FALSE); @@ -1236,7 +1254,7 @@ static void setup_widgets(void) gtk_grid_set_column_homogeneous(GTK_GRID(table), TRUE); gtk_container_add(GTK_CONTAINER(avbox), table); - /* citizens for taxrates */ + /* Citizens for taxrates */ ebox = gtk_event_box_new(); gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE); gtk_grid_attach(GTK_GRID(table), ebox, 0, 0, 10, 1); @@ -1260,7 +1278,7 @@ static void setup_widgets(void) gtk_container_add(GTK_CONTAINER(ebox), econ_label[i]); } - /* science, environmental, govt, timeout */ + /* Science, environmental, govt, timeout */ spr = client_research_sprite(); if (spr != NULL) { bulb_label = gtk_image_new_from_surface(spr->surface); @@ -1332,17 +1350,14 @@ static void setup_widgets(void) gtk_container_add(GTK_CONTAINER(frame), timeout_label); - /* turn done */ + /* Turn done */ turn_done_button = gtk_button_new_with_label(_("Turn Done")); gtk_grid_attach(GTK_GRID(table), turn_done_button, 0, 2, 10, 1); g_signal_connect(turn_done_button, "clicked", G_CALLBACK(end_turn_callback), NULL); - - fc_snprintf(buf, sizeof(buf), "%s:\n%s", - _("Turn Done"), _("Shift+Return")); - gtk_widget_set_tooltip_text(turn_done_button, buf); + update_turn_done_tooltip(); /* Selected unit status */ @@ -2099,8 +2114,8 @@ static gboolean show_info_popup(GtkWidget *w, GdkEventButton *ev, gpointer data) **************************************************************************/ static void end_turn_callback(GtkWidget *w, gpointer data) { - gtk_widget_set_sensitive(turn_done_button, FALSE); - user_ended_turn(); + gtk_widget_set_sensitive(turn_done_button, FALSE); + user_ended_turn(); } /************************************************************************** diff --git a/client/gui-gtk-3.22/gui_main.h b/client/gui-gtk-3.22/gui_main.h index 9c107186e7..94fe58367c 100644 --- a/client/gui-gtk-3.22/gui_main.h +++ b/client/gui-gtk-3.22/gui_main.h @@ -22,7 +22,7 @@ #define GUI_GTK_OPTION_STR(optname) "gui_gtk3_22_" #optname #define GUI_GTK_DEFAULT_THEME_NAME FC_GTK3_22_DEFAULT_THEME_NAME -/* network string charset conversion */ +/* Network string charset conversion */ gchar *ntoh_str(const gchar *netstr); extern PangoFontDescription *city_names_style; @@ -85,4 +85,6 @@ struct video_mode *resolution_request_get(void); bool is_gui_up(void); -#endif /* FC__GUI_MAIN_H */ +void update_turn_done_tooltip(void); + +#endif /* FC__GUI_MAIN_H */ diff --git a/client/gui-gtk-3.22/mapctrl.c b/client/gui-gtk-3.22/mapctrl.c index 02c8507dfa..a5cd42c959 100644 --- a/client/gui-gtk-3.22/mapctrl.c +++ b/client/gui-gtk-3.22/mapctrl.c @@ -207,6 +207,8 @@ void popup_newcity_dialog(struct unit *punit, const char *suggestname) void set_turn_done_button_state(bool state) { gtk_widget_set_sensitive(turn_done_button, state); + + update_turn_done_tooltip(); } /************************************************************************** diff --git a/client/gui-qt/fc_client.cpp b/client/gui-qt/fc_client.cpp index f66ad803bb..6abab5fc65 100644 --- a/client/gui-qt/fc_client.cpp +++ b/client/gui-qt/fc_client.cpp @@ -1036,6 +1036,7 @@ QString fc_icons::get_path(const QString &id) void fc_game_tab_widget::resizeEvent(QResizeEvent *event) { QSize size; + size = event->size(); if (C_S_RUNNING <= client_state()) { gui()->sidebar_wdg->resize_me(size.height()); diff --git a/client/gui-qt/gui_main.cpp b/client/gui-qt/gui_main.cpp index 0612ca398f..cbd2dba67c 100644 --- a/client/gui-qt/gui_main.cpp +++ b/client/gui-qt/gui_main.cpp @@ -358,7 +358,7 @@ void qtg_real_focus_units_changed(void) } /**************************************************************************** - Enqueue a callback to be called during an idle moment. The 'callback' + Enqueue a callback to be called during an idle moment. The 'callback' function should be called sometimes soon, and passed the 'data' pointer as its data. ****************************************************************************/ diff --git a/client/gui-qt/mapctrl.cpp b/client/gui-qt/mapctrl.cpp index 7896347485..aac6baff28 100644 --- a/client/gui-qt/mapctrl.cpp +++ b/client/gui-qt/mapctrl.cpp @@ -41,12 +41,13 @@ #include "shortcuts.h" extern void side_disable_endturn(bool do_restore); +extern void update_turn_done_tooltip(void); extern void qload_lua_script(); extern void qreload_lua_script(); extern "C" int city_buy_production(struct city *pcity); /************************************************************************** - Popup a dialog to ask for the name of a new city. The given string + Popup a dialog to ask for the name of a new city. The given string should be used as a suggestion. **************************************************************************/ void popup_newcity_dialog(struct unit *punit, const char *suggestname) @@ -69,12 +70,14 @@ void popup_newcity_dialog(struct unit *punit, const char *suggestname) } /************************************************************************** - A turn done button should be provided for the player. This function + A turn done button should be provided for the player. This function is called to toggle it between active/inactive. **************************************************************************/ void set_turn_done_button_state(bool state) { side_disable_endturn(state); + + update_turn_done_tooltip(); } /************************************************************************** diff --git a/client/gui-qt/mapview.cpp b/client/gui-qt/mapview.cpp index 00a199690a..9e89a843a3 100644 --- a/client/gui-qt/mapview.cpp +++ b/client/gui-qt/mapview.cpp @@ -1090,8 +1090,8 @@ void qtg_update_timeout_label(void) /**************************************************************************** If do_restore is false it should change the turn button style (to - draw the user's attention to it). If called regularly from a timer - this will give a blinking turn done button. If do_restore is true + draw the user's attention to it). If called regularly from a timer + this will give a blinking turn done button. If do_restore is true this should reset the turn done button to the default style. ****************************************************************************/ void update_turn_done_button(bool do_restore) @@ -1100,7 +1100,6 @@ void update_turn_done_button(bool do_restore) return; } side_blink_endturn(do_restore); - } diff --git a/client/gui-qt/sidebar.cpp b/client/gui-qt/sidebar.cpp index 48c86d9632..f3b68212a1 100644 --- a/client/gui-qt/sidebar.cpp +++ b/client/gui-qt/sidebar.cpp @@ -620,6 +620,24 @@ void side_center_unit() request_center_focus_unit(); } +/************************************************************************** + Update tooltip of the Turn Done button +**************************************************************************/ +void update_turn_done_tooltip() +{ + struct option *opt = optset_option_by_name(server_optset, "fixedlength"); + + if (opt != NULL && option_bool_get(opt)) { + gui()->sw_endturn->setToolTip(_("Fixed length turns")); + } else { + char buf[256]; + + fc_snprintf(buf, sizeof(buf), "%s:\n%s", + _("Turn Done"), _("Shift+Return")); + gui()->sw_endturn->setToolTip(buf); + } +} + /*************************************************************************** Disables end turn button if asked ***************************************************************************/ @@ -628,6 +646,7 @@ void side_disable_endturn(bool do_restore) if (gui()->current_page() != PAGE_GAME) { return; } + gui()->sw_endturn->disabled = !do_restore; gui()->sw_endturn->update_final_pixmap(); } diff --git a/client/gui-qt/sidebar.h b/client/gui-qt/sidebar.h index 1d0d8292dc..5e465a46e7 100644 --- a/client/gui-qt/sidebar.h +++ b/client/gui-qt/sidebar.h @@ -26,6 +26,7 @@ typedef void (*pfcn_bool)(bool); typedef void (*pfcn)(void); void side_blink_endturn(bool do_restore); +void update_turn_done_tooltip(); void side_center_unit(); void side_disable_endturn(bool do_restore); void side_finish_turn(bool nothing); @@ -46,7 +47,7 @@ public: int type = SW_STD); ~fc_sidewidget(); int get_priority(); - QPixmap* get_pixmap(); + QPixmap *get_pixmap(); void paint(QPainter *painter, QPaintEvent *event); void resize_pixmap(int width, int height); void set_custom_labels(QString l); -- 2.39.2