1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
15 #include <fc_config.h>
24 #include "qtg_cxxside.h"
25 #include "spaceshipdlg.h"
30 /****************************************************************************
31 Constructor for spaceship report
32 ****************************************************************************/
33 ss_report::ss_report(struct player
*pplayer
)
38 setAttribute(Qt::WA_DeleteOnClose
);
40 get_spaceship_dimensions(&w
, &h
);
41 can
= qtg_canvas_create(w
, h
);
43 QGridLayout
*layout
= new QGridLayout
;
44 ss_pix_label
= new QLabel
;
45 ss_pix_label
->setPixmap(can
->map_pixmap
);
46 layout
->addWidget(ss_pix_label
, 0, 0, 3, 3);
47 ss_label
= new QLabel
;
48 layout
->addWidget(ss_label
, 0, 3, 3, 1);
49 launch_button
= new QPushButton(_("Launch"));
50 connect(launch_button
, SIGNAL(clicked()), SLOT(launch()));
51 layout
->addWidget(launch_button
, 4, 3, 1, 1);
56 /****************************************************************************
57 Destructor for spaceship report
58 ****************************************************************************/
59 ss_report::~ss_report()
61 gui()->remove_repo_dlg("SPS");
65 /****************************************************************************
66 Initializes widget on game_tab_widget
67 ****************************************************************************/
68 void ss_report::init()
71 gui()->gimme_place(this, "SPS");
72 index
= gui()->add_game_tab(this);
73 gui()->game_tab_widget
->setCurrentIndex(index
);
77 /****************************************************************************
78 Updates spaceship report
79 ****************************************************************************/
80 void ss_report::update_report()
83 struct player_spaceship
*pship
;
85 pship
= &(player
->spaceship
);
87 if (victory_enabled(VC_SPACERACE
) && player
== client
.conn
.playing
88 && pship
->state
== SSHIP_STARTED
&& pship
->success_rate
> 0.0) {
89 launch_button
->setEnabled(true);
91 launch_button
->setEnabled(false);
93 ch
= get_spaceship_descr(&player
->spaceship
);
94 ss_label
->setText(ch
);
95 put_spaceship(can
, 0, 0, player
);
96 ss_pix_label
->setPixmap(can
->map_pixmap
);
100 /****************************************************************************
102 ****************************************************************************/
103 void ss_report::launch()
105 send_packet_spaceship_launch(&client
.conn
);
109 /**************************************************************************
110 Popup (or raise) the spaceship dialog for the given player.
111 **************************************************************************/
112 void popup_spaceship_dialog(struct player
*pplayer
)
118 if (client_is_global_observer()) {
121 if (!gui()->is_repo_dlg_open("SPS")) {
122 ss_rep
= new ss_report(pplayer
);
125 i
= gui()->gimme_index_of("SPS");
127 if (gui()->game_tab_widget
->currentIndex() == i
) {
130 w
= gui()->game_tab_widget
->widget(i
);
131 ss_rep
= reinterpret_cast<ss_report
*>(w
);
132 gui()->game_tab_widget
->setCurrentWidget(ss_rep
);
136 /**************************************************************************
137 Close the spaceship dialog for the given player.
138 **************************************************************************/
139 void popdown_spaceship_dialog(struct player
*pplayer
)
144 /**************************************************************************
145 Refresh (update) the spaceship dialog for the given player.
146 **************************************************************************/
147 void refresh_spaceship_dialog(struct player
*pplayer
)
153 if (!gui()->is_repo_dlg_open("SPS")) {
157 i
= gui()->gimme_index_of("SPS");
159 w
= gui()->game_tab_widget
->widget(i
);
160 ss_rep
= reinterpret_cast<ss_report
*>(w
);
161 gui()->game_tab_widget
->setCurrentWidget(ss_rep
);
162 ss_rep
->update_report();
166 /**************************************************************************
167 Close all spaceships dialogs
168 **************************************************************************/
169 void popdown_all_spaceships_dialogs()
175 if (!gui()->is_repo_dlg_open("SPS")) {
179 i
= gui()->gimme_index_of("SPS");
181 w
= gui()->game_tab_widget
->widget(i
);
182 ss_rep
= reinterpret_cast<ss_report
*>(w
);
183 ss_rep
->deleteLater();