Author: mir3x Date: Tue Dec 23 19:36:40 2014 New Revision: 27393 URL: http://svn.gna.org/viewcvs/freeciv?rev=27393&view=rev Log: Added unit properties to help dialog.
Patch submitted by Louis Moureaux <louis94> See patch #5546 Modified: branches/S2_5/client/gui-qt/gui_main.cpp branches/S2_5/client/gui-qt/helpdlg.cpp branches/S2_5/client/gui-qt/helpdlg.h branches/S2_5/client/options.c Modified: branches/S2_5/client/gui-qt/gui_main.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/gui_main.cpp?rev=27393&r1=27392&r2=27393&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/gui_main.cpp (original) +++ branches/S2_5/client/gui-qt/gui_main.cpp Tue Dec 23 19:36:40 2014 @@ -181,6 +181,8 @@ apply_help_font); option_var_set_callback(gui_qt_font_help_text, apply_help_font); + option_var_set_callback(gui_qt_font_help_title, + apply_help_font); #undef option_var_set_callback } Modified: branches/S2_5/client/gui-qt/helpdlg.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/helpdlg.cpp?rev=27393&r1=27392&r2=27393&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/helpdlg.cpp (original) +++ branches/S2_5/client/gui-qt/helpdlg.cpp Tue Dec 23 19:36:40 2014 @@ -27,6 +27,7 @@ #include "fcintl.h" // common +#include "movement.h" #include "nation.h" #include "terrain.h" #include "specialist.h" @@ -43,6 +44,7 @@ #include <QApplication> #include <QDialogButtonBox> #include <QGroupBox> +#include <QProgressBar> #include <QPushButton> #include <QSplitter> #include <QStack> @@ -123,9 +125,8 @@ setWindowTitle(_("Freeciv Help Browser")); setWindowFlags(Qt::WindowStaysOnTopHint); - resize(600, 350); + resize(750, 450); layout = new QVBoxLayout(this); - setLayout(layout); splitter = new QSplitter(this); layout->addWidget(splitter); @@ -143,7 +144,7 @@ help_wdg->layout()->setContentsMargins(0, 0, 0, 0); splitter->addWidget(help_wdg); - sizes << 100 << 300; + sizes << 150 << 600; splitter->setSizes(sizes); box = new QDialogButtonBox(QDialogButtonBox::Close); @@ -226,7 +227,8 @@ Creates a new, empty help widget. **************************************************************************/ help_widget::help_widget(QWidget *parent) : - QWidget(parent) + QWidget(parent), + main_widget(NULL) { setup_ui(); } @@ -235,7 +237,8 @@ Creates a new help widget displaying the specified topic. **************************************************************************/ help_widget::help_widget(const help_item *topic, QWidget *parent) : - QWidget(parent) + QWidget(parent), + main_widget(NULL) { setup_ui(); set_topic(topic); @@ -248,14 +251,14 @@ { QVBoxLayout *layout; - QVBoxLayout *group_layout; + QHBoxLayout *group_layout; layout = new QVBoxLayout(); setLayout(layout); box_wdg = new QFrame(this); layout->addWidget(box_wdg); - group_layout = new QVBoxLayout(box_wdg); + group_layout = new QHBoxLayout(box_wdg); box_wdg->setLayout(group_layout); box_wdg->setFrameShape(QFrame::StyledPanel); box_wdg->setFrameShadow(QFrame::Raised); @@ -265,6 +268,8 @@ text_browser = new QTextBrowser(this); layout->addWidget(text_browser); + main_widget = text_browser; + update_fonts(); } @@ -273,13 +278,17 @@ **************************************************************************/ void help_widget::update_fonts() { - QFont *label_font; - QFont *help_font; + QFont *help_font, *label_font, *title_font; + QLabel *label; label_font = gui()->fc_fonts.get_font("gui_qt_font_help_label"); help_font = gui()->fc_fonts.get_font("gui_qt_font_help_text"); - title_label->setFont(*label_font); + title_font = gui()->fc_fonts.get_font("gui_qt_font_help_title"); text_browser->setFont(*help_font); + title_label->setFont(*title_font); + foreach (label, label_list) { + label->setFont(*label_font); + } } /************************************************************************** @@ -287,6 +296,10 @@ **************************************************************************/ void help_widget::set_topic(const help_item *topic) { + // Remove any widget added by set_topic_xxx + set_main_widget(text_browser); + label_list.clear(); + char *title = topic->topic; for ( ; *title == ' '; ++title) { // Do nothing @@ -330,6 +343,72 @@ case HELP_LAST: // Just to avoid warning break; } + update_fonts(); +} + +/************************************************************************** + Sets the main content widget. +**************************************************************************/ +void help_widget::set_main_widget(QWidget *widget) +{ + QLayoutItem *item; + + if (main_widget != widget) { + item = layout()->replaceWidget(main_widget, widget); + delete item; + if (main_widget != text_browser) { + main_widget->deleteLater(); + } + main_widget = widget; + main_widget->setParent(this); + } +} + +/************************************************************************** + Creates a widget indicating a progress, used eg on unit help pages. + Arguments: + text: A descriptive text + progress: The progress to display + [min,max]: The interval progress is in + value: Use this to display a non-numeral value +**************************************************************************/ +QWidget *help_widget::create_progress_widget(const QString &text, + int progress, + int min, int max, + const QString &value) +{ + QGridLayout *layout; + QLabel *label; + QProgressBar *bar; + QWidget *wdg; + + wdg = new QWidget(); + layout = new QGridLayout(wdg); + layout->setMargin(0); + layout->setVerticalSpacing(0); + + label = new QLabel(text, wdg); + label_list << label; + layout->addWidget(label, 0, 0); + + label = new QLabel(wdg); + label_list << label; + if (value.isEmpty()) { + label->setNum(progress); + } else { + label->setText(value); + } + layout->addWidget(label, 0, 1, Qt::AlignRight); + + bar = new QProgressBar(wdg); + bar->setMaximumHeight(4); + bar->setRange(min, max != min ? max : min + 1); + bar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); + bar->setTextVisible(false); + bar->setValue(progress); + layout->addWidget(bar, 1, 0, 1, 2); + + return wdg; } /************************************************************************** @@ -352,11 +431,129 @@ const char *title) { char buffer[MAX_HELP_TEXT_SIZE]; - struct unit_type *utype = unit_type_by_translated_name(title); + int upkeep, max_upkeep; + struct advance *tech; + struct canvas *canvas; + struct unit_type *obsolete, *utype, *max_utype; + QLabel *label; + QList<int> list; + QSplitter *splitter; + QVBoxLayout *vbox; + QWidget *panel; + + utype = unit_type_by_translated_name(title); if (utype) { helptext_unit(buffer, sizeof(buffer), client.conn.playing, topic->text, utype); text_browser->setText(buffer); + + // Create information widget + max_utype = uclass_max_values(utype->uclass); + splitter = new QSplitter(this); + splitter->setSizePolicy(QSizePolicy::Expanding, + QSizePolicy::Expanding); + set_main_widget(splitter); + + panel = new QWidget(splitter); + vbox = new QVBoxLayout(panel); + splitter->addWidget(panel); + splitter->setStretchFactor(0, 25); + splitter->addWidget(text_browser); + splitter->setStretchFactor(1, 75); + list << 200 << 400; + splitter->setSizes(list); + + label = new QLabel(); + // Create unit icon + canvas = qtg_canvas_create( + tileset_full_tile_width(tileset), + tileset_full_tile_height(tileset) + ); + canvas->map_pixmap.fill(Qt::transparent); + put_unittype(utype, canvas, 0, 0); + label->setAlignment(Qt::AlignHCenter); + label->setPixmap(canvas->map_pixmap); + qtg_canvas_free(canvas); + vbox->addWidget(label); + + vbox->addWidget(create_progress_widget( + _("Attack:"), utype->attack_strength, 0, + max_utype->attack_strength)); + vbox->addWidget(create_progress_widget( + _("Defense:"), utype->defense_strength, + 0, max_utype->defense_strength)); + vbox->addWidget(create_progress_widget( + _("Moves:"), utype->move_rate, 0, max_utype->move_rate, + move_points_text(utype->move_rate, true))); + + vbox->addItem(new QSpacerItem(0, 2 * vbox->spacing())); + + vbox->addWidget(create_progress_widget( + _("Hitpoints:"), utype->hp, 0, max_utype->hp)); + vbox->addWidget(create_progress_widget( + _("Cost:"), utype_build_shield_cost(utype), + 0, utype_build_shield_cost(max_utype))); + vbox->addWidget(create_progress_widget( + _("Firepower:"), utype->firepower, 0, + max_utype->firepower)); + + // Upkeep + upkeep = utype->upkeep[O_FOOD] + utype->upkeep[O_GOLD] + + utype->upkeep[O_LUXURY] + utype->upkeep[O_SCIENCE] + + utype->upkeep[O_SHIELD] + utype->upkeep[O_TRADE] + + utype->happy_cost; + max_upkeep = max_utype->upkeep[O_FOOD] + max_utype->upkeep[O_GOLD] + + max_utype->upkeep[O_LUXURY] + max_utype->upkeep[O_SCIENCE] + + max_utype->upkeep[O_SHIELD] + max_utype->upkeep[O_TRADE] + + max_utype->happy_cost; + vbox->addWidget(create_progress_widget( + _("Basic upkeep:"), upkeep, 0, max_upkeep, + helptext_unit_upkeep_str(utype))); + + vbox->addItem(new QSpacerItem(0, 2 * vbox->spacing())); + + // Tech requirement + label = new QLabel(); + label_list << label; + tech = utype->require_advance; + if (tech && tech != advance_by_number(0)) { + // TRANS: Unit requires technology + label->setText(QString(_("Requires %1.")) + .arg(advance_name_translation(tech))); + } else { + label->setText(_("No technology required.")); + } + label->setWordWrap(true); + vbox->addWidget(label); + + // Obsolescence + label = new QLabel(); + label_list << label; + obsolete = utype->obsoleted_by; + if (obsolete) { + tech = obsolete->require_advance; + if (tech && tech != advance_by_number(0)) { + // TRANS: Current unit obsoleted by other unit (technology + // required to build other unit) + label->setText(QString(_("Obsoleted by %1 (%2).")) + .arg(utype_name_translation(obsolete)) + .arg(advance_name_translation(tech))); + } else { + label->setText( + // TRANS: Current unit obsoleted by other unit + QString(_("Obsoleted by %1.")) + .arg(utype_name_translation(obsolete))); + } + } else { + label->setText(_("Never obsolete.")); + } + label->setWordWrap(true); + vbox->addWidget(label); + + vbox->addItem(new QSpacerItem( + 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); + + delete max_utype; } else { set_topic_other(topic, title); } @@ -499,3 +696,63 @@ set_topic_other(topic, title); } } + +/************************************************************************** + Retrieves the maximum values any unit of uclass will ever have. + Supported fields: + attack_strength, bombard_rate, build_cost, city_size, convert_time, + defense_strength, firepower, fuel, happy_cost, hp, move_rate, pop_cost, + upkeep, vision_radius_sq + Other fiels in returned value are undefined. Especially, all pointers are + invalid except uclass. +**************************************************************************/ +struct unit_type *help_widget::uclass_max_values(struct unit_class *uclass) +{ + struct unit_type *max = new struct unit_type; + max->uclass = uclass; + max->attack_strength = 0; + max->bombard_rate = 0; + max->build_cost = 0; + max->city_size = 0; + max->defense_strength = 0; + max->firepower = 0; + max->fuel = 0; + max->happy_cost = 0; + max->hp = 0; + max->move_rate = 0; + max->pop_cost = 0; + max->upkeep[O_FOOD] = 0; + max->upkeep[O_GOLD] = 0; + max->upkeep[O_LUXURY] = 0; + max->upkeep[O_SCIENCE] = 0; + max->upkeep[O_SHIELD] = 0; + max->upkeep[O_TRADE] = 0; + max->vision_radius_sq = 0; + unit_type_iterate(utype) { + if (utype->uclass == uclass) { +#define SET_MAX(v) \ + max->v = max->v > utype->v ? max->v : utype->v + SET_MAX(attack_strength); + SET_MAX(bombard_rate); + SET_MAX(build_cost); + SET_MAX(city_size); + SET_MAX(convert_time); + SET_MAX(defense_strength); + SET_MAX(firepower); + SET_MAX(fuel); + SET_MAX(happy_cost); + SET_MAX(hp); + SET_MAX(move_rate); + SET_MAX(pop_cost); + SET_MAX(upkeep[O_FOOD]); + SET_MAX(upkeep[O_GOLD]); + SET_MAX(upkeep[O_LUXURY]); + SET_MAX(upkeep[O_SCIENCE]); + SET_MAX(upkeep[O_SHIELD]); + SET_MAX(upkeep[O_TRADE]); + SET_MAX(vision_radius_sq); +#undef SET_MAX + } + } unit_type_iterate_end + return max; +} Modified: branches/S2_5/client/gui-qt/helpdlg.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/helpdlg.h?rev=27393&r1=27392&r2=27393&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/helpdlg.h (original) +++ branches/S2_5/client/gui-qt/helpdlg.h Tue Dec 23 19:36:40 2014 @@ -17,6 +17,7 @@ // Qt #include <QDialog> #include <QHash> +#include <QList> extern "C" { #include "helpdlg_g.h" @@ -56,8 +57,16 @@ QTextBrowser *text_browser; QFrame *box_wdg; QLabel *title_label; + QWidget* main_widget; + QList<QLabel *> label_list; void setup_ui(); + void set_main_widget(QWidget *main_widget); + QWidget *create_progress_widget(const QString& label, + int progress, + int min, int max, + const QString& value = QString() + ); void set_topic_other(const help_item *item, const char *title); @@ -81,6 +90,9 @@ public slots: void set_topic(const help_item *item); + +public: + struct unit_type *uclass_max_values(struct unit_class *uclass); }; void update_help_fonts(); Modified: branches/S2_5/client/options.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/options.c?rev=27393&r1=27392&r2=27393&view=diff ============================================================================== --- branches/S2_5/client/options.c (original) +++ branches/S2_5/client/options.c Tue Dec 23 19:36:40 2014 @@ -238,9 +238,10 @@ char gui_qt_font_city_label[512] = "Monospace,8,-1,5,50,0,0,0,0,0"; char gui_qt_font_notify_label[512] = "Monospace,8,-1,5,75,0,0,0,0,0"; char gui_qt_font_spaceship_label[512] = "Monospace,8,-1,5,50,0,0,0,0,0"; -char gui_qt_font_help_label[512] = "Sans Serif,10,-1,5,75,0,0,0,0,0"; +char gui_qt_font_help_label[512] = "Sans Serif,9,-1,5,50,0,0,0,0,0"; char gui_qt_font_help_link[512] = "Sans Serif,9,-1,5,50,0,0,0,0,0"; char gui_qt_font_help_text[512] = "Monospace,8,-1,5,50,0,0,0,0,0"; +char gui_qt_font_help_title[512] = "Sans Serif,10,-1,5,75,0,0,0,0,0"; char gui_qt_font_chatline[512] = "Monospace,8,-1,5,50,0,0,0,0,0"; char gui_qt_font_beta_label[512] = "Sans Serif,10,-1,5,50,1,0,0,0,0"; char gui_qt_font_small[512] = "Sans Serif,9,-1,5,50,0,0,0,0,0"; @@ -2625,10 +2626,10 @@ "Monospace,8,-1,5,50,0,0,0,0,0", font_changed_callback), GEN_FONT_OPTION(gui_qt_font_help_label, "help_label", N_("Help Label"), - N_("This font is used to display the help headers in the " + N_("This font is used to display the help labels in the " "help window."), COC_FONT, GUI_QT, - "Sans Serif,10,-1,5,75,0,0,0,0,0", font_changed_callback), + "Sans Serif,9,-1,5,50,0,0,0,0,0", font_changed_callback), GEN_FONT_OPTION(gui_qt_font_help_link, "help_link", N_("Help Link"), N_("This font is used to display the help links in the " @@ -2641,6 +2642,12 @@ "the help window."), COC_FONT, GUI_QT, "Monospace,8,-1,5,50,0,0,0,0,0", font_changed_callback), + GEN_FONT_OPTION(gui_qt_font_help_title, "help_title", + N_("Help Title"), + N_("This font is used to display the help title in " + "the help window."), + COC_FONT, GUI_QT, + "Sans Serif,10,-1,5,75,0,0,0,0,0", font_changed_callback), GEN_FONT_OPTION(gui_qt_font_chatline, "chatline", N_("Chatline Area"), N_("This font is used to display the text in the " _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits