Author: mir3x Date: Thu Aug 21 21:33:15 2014 New Revision: 25990 URL: http://svn.gna.org/viewcvs/freeciv?rev=25990&view=rev Log: Added Spaceship report.
See patch #5060 Modified: branches/S2_5/client/gui-qt/Makefile.am branches/S2_5/client/gui-qt/menu.cpp branches/S2_5/client/gui-qt/menu.h branches/S2_5/client/gui-qt/spaceshipdlg.cpp branches/S2_5/client/gui-qt/spaceshipdlg.h Modified: branches/S2_5/client/gui-qt/Makefile.am URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/Makefile.am?rev=25990&r1=25989&r2=25990&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/Makefile.am (original) +++ branches/S2_5/client/gui-qt/Makefile.am Thu Aug 21 21:33:15 2014 @@ -24,7 +24,8 @@ meta_citydlg.cpp \ meta_cityrep.cpp \ meta_plrdlg.cpp \ - meta_diplodlg.cpp + meta_diplodlg.cpp \ + meta_spaceshipdlg.cpp libgui_qt_la_SOURCES = \ canvas.cpp \ Modified: branches/S2_5/client/gui-qt/menu.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/menu.cpp?rev=25990&r1=25989&r2=25990&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/menu.cpp (original) +++ branches/S2_5/client/gui-qt/menu.cpp Thu Aug 21 21:33:15 2014 @@ -39,6 +39,7 @@ #include "plrdlg.h" #include "ratesdlg.h" #include "repodlgs.h" +#include "spaceshipdlg.h" #include "sprite.h" #include "menu.h" @@ -402,6 +403,10 @@ act->setShortcut(QKeySequence(tr("F11"))); connect(act, SIGNAL(triggered()), this, SLOT(slot_demographics())); + act = menu->addAction(_("Spaceship")); + act->setShortcut(QKeySequence(tr("F12"))); + connect(act, SIGNAL(triggered()), this, SLOT(slot_spaceship())); + /* Help Menu */ menu = this->addMenu(_("Help")); act = menu->addAction(_("Copying")); @@ -884,6 +889,16 @@ } /*************************************************************************** + Slot for showing spaceship +***************************************************************************/ +void mr_menu::slot_spaceship() +{ + if (NULL != client.conn.playing) { + popup_spaceship_dialog(client.conn.playing); + } +} + +/*************************************************************************** Slot for showing economy tab ***************************************************************************/ void mr_menu::slot_show_eco_report() Modified: branches/S2_5/client/gui-qt/menu.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/menu.h?rev=25990&r1=25989&r2=25990&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/menu.h (original) +++ branches/S2_5/client/gui-qt/menu.h Thu Aug 21 21:33:15 2014 @@ -157,6 +157,7 @@ void slot_show_research_tab(); void slot_gov_change(const int &target); void revolution(); + void slot_spaceship(); void slot_demographics(); void slot_top_five(); void slot_traveler(); Modified: branches/S2_5/client/gui-qt/spaceshipdlg.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/spaceshipdlg.cpp?rev=25990&r1=25989&r2=25990&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/spaceshipdlg.cpp (original) +++ branches/S2_5/client/gui-qt/spaceshipdlg.cpp Thu Aug 21 21:33:15 2014 @@ -15,10 +15,94 @@ #include <fc_config.h> #endif +/* common */ +#include "game.h" + // gui-qt +#include "canvas.h" #include "qtg_cxxside.h" +#include "spaceshipdlg.h" -#include "spaceshipdlg.h" + +class QGridLayout; + +/**************************************************************************** + Constructor for spaceship report +****************************************************************************/ +ss_report::ss_report(struct player *pplayer) +{ + int w, h; + QSize size; + + setAttribute(Qt::WA_DeleteOnClose); + player = pplayer; + get_spaceship_dimensions(&w, &h); + can = qtg_canvas_create(w, h); + + QGridLayout *layout = new QGridLayout; + ss_pix_label = new QLabel; + ss_pix_label->setPixmap(can->map_pixmap); + layout->addWidget(ss_pix_label, 0, 0, 3, 3); + ss_label = new QLabel; + layout->addWidget(ss_label, 0, 3, 3, 1); + launch_button = new QPushButton(_("_Launch")); + connect(launch_button, SIGNAL(clicked()), SLOT(launch())); + layout->addWidget(launch_button, 4, 3, 1, 1); + setLayout(layout); + update_report(); +} + +/**************************************************************************** + Destructor for spaceship report +****************************************************************************/ +ss_report::~ss_report() +{ + gui()->remove_repo_dlg("SPS"); +} + +/**************************************************************************** + Initializes widget on game_tab_widget +****************************************************************************/ +void ss_report::init() +{ + int index; + gui()->gimme_place(this, "SPS"); + index = gui()->add_game_tab(this, _("Spaceship")); + gui()->game_tab_widget->setCurrentIndex(index); + update_report(); +} + +/**************************************************************************** + Updates spaceship report +****************************************************************************/ +void ss_report::update_report() +{ + const char *ch; + struct player_spaceship *pship; + + pship = &(player->spaceship); + + if (game.info.spacerace && player == client.conn.playing + && pship->state == SSHIP_STARTED && pship->success_rate > 0.0) { + + launch_button->setEnabled(true); + } else { + launch_button->setEnabled(false); + } + ch = get_spaceship_descr(&player->spaceship); + ss_label->setText(ch); + put_spaceship(can, 0, 0, player); + ss_pix_label->setPixmap(can->map_pixmap); + update(); +} + +/**************************************************************************** + Launch spaceship +****************************************************************************/ +void ss_report::launch() +{ + send_packet_spaceship_launch(&client.conn); +} /************************************************************************** @@ -26,7 +110,26 @@ **************************************************************************/ void popup_spaceship_dialog(struct player *pplayer) { - /* PORTME */ + ss_report *ss_rep; + int i; + QWidget *w; + + if (client_is_global_observer()) { + return; + } + if (!gui()->is_repo_dlg_open("SPS")) { + ss_rep = new ss_report(pplayer); + ss_rep->init(); + } else { + i = gui()->gimme_index_of("SPS"); + fc_assert(i != -1); + if (gui()->game_tab_widget->currentIndex() == i) { + return; + } + w = gui()->game_tab_widget->widget(i); + ss_rep = reinterpret_cast<ss_report *>(w); + gui()->game_tab_widget->setCurrentWidget(ss_rep); + } } /************************************************************************** @@ -42,5 +145,19 @@ **************************************************************************/ void refresh_spaceship_dialog(struct player *pplayer) { - /* PORTME */ + int i; + ss_report *ss_rep; + QWidget *w; + + if (!gui()->is_repo_dlg_open("SPS")) { + return; + } + else { + i = gui()->gimme_index_of("SPS"); + fc_assert(i != -1); + w = gui()->game_tab_widget->widget(i); + ss_rep = reinterpret_cast<ss_report*>(w); + gui()->game_tab_widget->setCurrentWidget(ss_rep); + ss_rep->update_report(); + } } Modified: branches/S2_5/client/gui-qt/spaceshipdlg.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/spaceshipdlg.h?rev=25990&r1=25989&r2=25990&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/spaceshipdlg.h (original) +++ branches/S2_5/client/gui-qt/spaceshipdlg.h Thu Aug 21 21:33:15 2014 @@ -14,8 +14,48 @@ #ifndef FC__SPACESHIPDLG_H #define FC__SPACESHIPDLG_H +#ifdef HAVE_CONFIG_H +#include <fc_config.h> +#endif + extern "C" { #include "spaceshipdlg_g.h" } +/* client */ +#include "text.h" + +// Qt +#include <QWidget> + +class QPixmap; +class QPushButton; +class QLabel; + +/**************************************************************************** + Tab widget to display spaceship report (F12) +****************************************************************************/ +class ss_report: public QWidget +{ + Q_OBJECT + QPushButton *launch_button; + QLabel *ss_pix_label; + QLabel *ss_label; + struct canvas *can; + +public: + ss_report(struct player *pplayer); + ~ss_report(); + void update_report(); + void init(); + +private slots: + void launch(); + +private: + struct player *player; +}; + +void popup_spaceship_dialog(struct player *pplayer); + #endif /* FC__SPACESHIPDLG_H */ _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits