Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/gui-qt/spaceshipdlg.cpp Source File

Freeciv-3.2

Loading...
Searching...
No Matches
spaceshipdlg.cpp
Go to the documentation of this file.
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)
6 any later version.
7
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***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18// Qt
19#include <QGridLayout>
20#include <QLabel>
21
22// common
23#include "game.h"
24#include "victory.h"
25
26// client
27#include "client_main.h"
28
29// gui-qt
30#include "canvas.h"
31#include "fc_client.h"
32#include "qtg_cxxside.h"
33#include "spaceshipdlg.h"
34
35
36class QGridLayout;
37
38/************************************************************************/
41ss_report::ss_report(struct player *pplayer)
42{
43 int w, h;
44
45 setAttribute(Qt::WA_DeleteOnClose);
46 player = pplayer;
47 get_spaceship_dimensions(&w, &h);
48 can = qtg_canvas_create(w, h);
49
50 QGridLayout *layout = new QGridLayout;
51 ss_pix_label = new QLabel;
52 ss_pix_label->setPixmap(can->map_pixmap);
53 layout->addWidget(ss_pix_label, 0, 0, 3, 3);
54 ss_label = new QLabel;
55 layout->addWidget(ss_label, 0, 3, 3, 1);
56 launch_button = new QPushButton(_("Launch"));
57 connect(launch_button, &QAbstractButton::clicked, this, &ss_report::launch);
58 layout->addWidget(launch_button, 4, 3, 1, 1);
59 setLayout(layout);
60 update_report();
61}
62
63/************************************************************************/
66ss_report::~ss_report()
67{
68 gui()->remove_repo_dlg("SPS");
69 qtg_canvas_free(can);
70}
71
72/************************************************************************/
75 void ss_report::init()
76{
77 int index;
78 gui()->gimme_place(this, "SPS");
79 index = gui()->add_game_tab(this);
80 gui()->game_tab_widget->setCurrentIndex(index);
81 update_report();
82}
83
84/************************************************************************/
87 void ss_report::update_report()
88{
89 const char *ch;
90 struct player_spaceship *pship;
91
92 pship = &(player->spaceship);
93
94 if (victory_enabled(VC_SPACERACE) && player == client.conn.playing
95 && pship->state == SSHIP_STARTED && pship->success_rate > 0.0) {
96 launch_button->setEnabled(true);
97 } else {
98 launch_button->setEnabled(false);
99 }
100 ch = get_spaceship_descr(&player->spaceship);
101 ss_label->setText(ch);
102 put_spaceship(can, 0, 0, player);
103 ss_pix_label->setPixmap(can->map_pixmap);
104 update();
105}
106
107/************************************************************************/
110 void ss_report::launch()
111{
112 send_packet_spaceship_launch(&client.conn);
113}
114
115/************************************************************************/
118 void popup_spaceship_dialog(struct player *pplayer)
119{
120 ss_report *ss_rep;
121 int i;
122 QWidget *w;
123
124 if (client_is_global_observer()) {
125 return;
126 }
127 if (!gui()->is_repo_dlg_open("SPS")) {
128 ss_rep = new ss_report(pplayer);
129 ss_rep->init();
130 } else {
131 i = gui()->gimme_index_of("SPS");
132 fc_assert(i != -1);
133 if (gui()->game_tab_widget->currentIndex() == i) {
134 return;
135 }
136 w = gui()->game_tab_widget->widget(i);
137 ss_rep = reinterpret_cast< ss_report *>(w);
138 gui()->game_tab_widget->setCurrentWidget(ss_rep);
139 }
140}
141
142/************************************************************************/
145 void popdown_spaceship_dialog(struct player *pplayer)
146{
147 // PORTME
148}
149
150/************************************************************************/
153 void refresh_spaceship_dialog(struct player *pplayer)
154{
155 int i;
156 ss_report *ss_rep;
157 QWidget *w;
158
159 if (!gui()->is_repo_dlg_open("SPS")) {
160 return;
161 } else {
162 i = gui()->gimme_index_of("SPS");
163 fc_assert(i != -1);
164 w = gui()->game_tab_widget->widget(i);
165 ss_rep = reinterpret_cast< ss_report*>(w);
166 gui()->game_tab_widget->setCurrentWidget(ss_rep);
167 ss_rep->update_report();
168 }
169}
170
171/************************************************************************/
174 void popdown_all_spaceships_dialogs()
175{
176 int i;
177 ss_report *ss_rep;
178 QWidget *w;
179
180 if (!gui()->is_repo_dlg_open("SPS")) {
181 return;
182 }
183 else {
184 i = gui()->gimme_index_of("SPS");
185 fc_assert(i != -1);
186 w = gui()->game_tab_widget->widget(i);
187 ss_rep = reinterpret_cast< ss_report*>(w);
188 ss_rep->deleteLater();
189 }
190}
qtg_canvas_free
void qtg_canvas_free(struct canvas *store)
Definition canvas.cpp:48
qtg_canvas_create
struct canvas * qtg_canvas_create(int width, int height)
Definition canvas.cpp:36
ss_report
Definition spaceshipdlg.h:39
ss_report::ss_pix_label
QLabel * ss_pix_label
Definition spaceshipdlg.h:42
ss_report::ss_label
QLabel * ss_label
Definition spaceshipdlg.h:43
ss_report::can
struct canvas * can
Definition spaceshipdlg.h:44
ss_report::launch
void launch()
Definition spaceshipdlg.cpp:110
ss_report::launch_button
QPushButton * launch_button
Definition spaceshipdlg.h:41
ss_report::~ss_report
~ss_report()
Definition spaceshipdlg.cpp:66
ss_report::update_report
void update_report()
Definition spaceshipdlg.cpp:87
ss_report::ss_report
ss_report(struct player *pplayer)
Definition spaceshipdlg.cpp:41
ss_report::init
void init()
Definition spaceshipdlg.cpp:75
client_is_global_observer
bool client_is_global_observer(void)
Definition client_main.c:1345
client
struct civclient client
Definition client_main.c:150
client_main.h
incite_cost
char * incite_cost
Definition comments.c:74
fc_client.h
VC_SPACERACE
@ VC_SPACERACE
Definition fc_types.h:1272
_
#define _(String)
Definition fcintl.h:67
game.h
layout
static PangoLayout * layout
Definition canvas.c:325
canvas.h
spaceshipdlg.h
fc_assert
#define fc_assert(condition)
Definition log.h:176
get_spaceship_dimensions
void get_spaceship_dimensions(int *width, int *height)
Definition mapview_common.c:3716
put_spaceship
void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y, const struct player *pplayer)
Definition mapview_common.c:3729
gui
static mpgui * gui
Definition mpgui_qt.cpp:52
send_packet_spaceship_launch
int send_packet_spaceship_launch(struct connection *pc)
Definition packets_gen.c:38944
qtg_cxxside.h
SSHIP_STARTED
@ SSHIP_STARTED
Definition spaceship.h:84
popdown_spaceship_dialog
void popdown_spaceship_dialog(struct player *pplayer)
Definition spaceshipdlg.cpp:145
popdown_all_spaceships_dialogs
void popdown_all_spaceships_dialogs()
Definition spaceshipdlg.cpp:174
popup_spaceship_dialog
void popup_spaceship_dialog(struct player *pplayer)
Definition spaceshipdlg.cpp:118
refresh_spaceship_dialog
void refresh_spaceship_dialog(struct player *pplayer)
Definition spaceshipdlg.cpp:153
canvas::map_pixmap
QPixmap map_pixmap
Definition canvas.h:25
civclient::conn
struct connection conn
Definition client_main.h:96
connection::playing
struct player * playing
Definition connection.h:151
player_spaceship
Definition spaceship.h:94
player
Definition player.h:247
player::spaceship
struct player_spaceship spaceship
Definition player.h:284
get_spaceship_descr
const char * get_spaceship_descr(struct player_spaceship *pship)
Definition text.c:1500
victory_enabled
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26
victory.h