Freeciv-3.1
Loading...
Searching...
No Matches
spaceshipdlg.c
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#include <stdio.h>
19#include <stdlib.h>
20
21#include <gtk/gtk.h>
22
23/* utility */
24#include "fcintl.h"
25#include "log.h"
26#include "mem.h"
27#include "shared.h"
28#include "support.h"
29
30/* common */
31#include "game.h"
32#include "map.h"
33#include "packets.h"
34#include "player.h"
35#include "spaceship.h"
36#include "victory.h"
37
38/* client */
39#include "client_main.h"
40#include "climisc.h"
41#include "colors.h"
42#include "options.h"
43#include "text.h"
44#include "tilespec.h"
45
46/* client/gui-gtk-3.22 */
47#include "dialogs.h"
48#include "graphics.h"
49#include "gui_main.h"
50#include "gui_stuff.h"
51#include "helpdlg.h"
52#include "inputdlg.h"
53#include "mapctrl.h"
54#include "mapview.h"
55#include "repodlgs.h"
56
57#include "spaceshipdlg.h"
58
59struct spaceship_dialog {
60 struct player *pplayer;
61 struct gui_dialog *shell;
62 GtkWidget *main_form;
63 GtkWidget *info_label;
64 GtkWidget *image_canvas;
65};
66
67#define SPECLIST_TAG dialog
68#define SPECLIST_TYPE struct spaceship_dialog
69#include "speclist.h"
70
71#define dialog_list_iterate(dialoglist, pdialog) \
72 TYPED_LIST_ITERATE(struct spaceship_dialog, dialoglist, pdialog)
73#define dialog_list_iterate_end LIST_ITERATE_END
74
75static struct dialog_list *dialog_list;
76
79 *pplayer);
80
81static void spaceship_dialog_update_image(struct spaceship_dialog *pdialog);
82static void spaceship_dialog_update_info(struct spaceship_dialog *pdialog);
83
84/************************************************************************/
88{
89 dialog_list = dialog_list_new();
90}
91
92/************************************************************************/
96{
97 dialog_list_destroy(dialog_list);
98}
99
100/************************************************************************/
104{
106 if (pdialog->pplayer == pplayer) {
107 return pdialog;
108 }
110
111 return NULL;
112}
113
114/************************************************************************/
118{
119 struct spaceship_dialog *pdialog;
120 struct player_spaceship *pship;
121
122 if (!(pdialog = get_spaceship_dialog(pplayer))) {
123 return;
124 }
125
126 pship = &(pdialog->pplayer->spaceship);
127
129 && pplayer == client.conn.playing
130 && pship->state == SSHIP_STARTED
131 && pship->success_rate > 0.0) {
133 GTK_RESPONSE_ACCEPT, TRUE);
134 } else {
136 GTK_RESPONSE_ACCEPT, FALSE);
137 }
138
141}
142
143/************************************************************************/
146void popup_spaceship_dialog(struct player *pplayer)
147{
148 struct spaceship_dialog *pdialog;
149
150 if (!(pdialog = get_spaceship_dialog(pplayer))) {
152 }
153
154 gui_dialog_raise(pdialog->shell);
155}
156
157/************************************************************************/
161{
162 struct spaceship_dialog *pdialog;
163
164 if ((pdialog = get_spaceship_dialog(pplayer))) {
165 gui_dialog_destroy(pdialog->shell);
166 }
167}
168
169/************************************************************************/
172static gboolean spaceship_image_canvas_expose(GtkWidget *widget,
173 cairo_t *cr,
174 gpointer data)
175{
176 struct spaceship_dialog *pdialog = (struct spaceship_dialog *)data;
177 struct canvas store = FC_STATIC_CANVAS_INIT;
178
179 store.drawable = cr;
180
181 put_spaceship(&store, 0, 0, pdialog->pplayer);
182
183 return TRUE;
184}
185
186/************************************************************************/
189static void spaceship_destroy_callback(GtkWidget *w, gpointer data)
190{
191 struct spaceship_dialog *pdialog = (struct spaceship_dialog *)data;
192
193 dialog_list_remove(dialog_list, pdialog);
194
195 free(pdialog);
196}
197
198/************************************************************************/
201static void spaceship_response(struct gui_dialog *dlg, int response,
202 gpointer data)
203{
204 switch (response) {
205 case GTK_RESPONSE_ACCEPT:
207 break;
208
209 default:
211 break;
212 }
213}
214
215/************************************************************************/
219{
220 struct spaceship_dialog *pdialog;
221 GtkWidget *hbox, *frame;
222 int w, h;
223
224 pdialog = fc_malloc(sizeof(struct spaceship_dialog));
225 pdialog->pplayer = pplayer;
226
227 gui_dialog_new(&pdialog->shell, GTK_NOTEBOOK(top_notebook), NULL, TRUE);
229
230 gui_dialog_add_button(pdialog->shell, "window-close", _("_Close"),
231 GTK_RESPONSE_CLOSE);
232 gui_dialog_add_button(pdialog->shell, NULL, _("_Launch"),
233 GTK_RESPONSE_ACCEPT);
234
235 g_signal_connect(pdialog->shell->vbox, "destroy",
236 G_CALLBACK(spaceship_destroy_callback), pdialog);
238
239 hbox = gtk_grid_new();
240 gtk_grid_set_column_spacing(GTK_GRID(hbox), 5);
241 gtk_container_add(GTK_CONTAINER(pdialog->shell->vbox), hbox);
242
243 frame = gtk_frame_new(NULL);
244 gtk_container_add(GTK_CONTAINER(hbox), frame);
245
246 pdialog->image_canvas = gtk_drawing_area_new();
247 gtk_widget_set_can_focus(pdialog->image_canvas, TRUE);
249 gtk_widget_set_size_request(pdialog->image_canvas, w, h);
250
251 gtk_widget_set_events(pdialog->image_canvas, GDK_EXPOSURE_MASK);
252 gtk_container_add(GTK_CONTAINER(frame), pdialog->image_canvas);
253 gtk_widget_realize(pdialog->image_canvas);
254
255 g_signal_connect(pdialog->image_canvas, "draw",
256 G_CALLBACK(spaceship_image_canvas_expose), pdialog);
257
258 pdialog->info_label = gtk_label_new(get_spaceship_descr(NULL));
259
260 gtk_label_set_justify(GTK_LABEL(pdialog->info_label), GTK_JUSTIFY_LEFT);
261 gtk_widget_set_halign(pdialog->info_label, GTK_ALIGN_START);
262 gtk_widget_set_valign(pdialog->info_label, GTK_ALIGN_START);
263
264 gtk_container_add(GTK_CONTAINER(hbox), pdialog->info_label);
265 gtk_widget_set_name(pdialog->info_label, "spaceship_label");
266
267 dialog_list_prepend(dialog_list, pdialog);
268
269 gtk_widget_grab_focus(pdialog->image_canvas);
270
271 gui_dialog_show_all(pdialog->shell);
272
274
275 return pdialog;
276}
277
278/************************************************************************/
282{
283 gtk_label_set_text(GTK_LABEL(pdialog->info_label),
285}
286
287/************************************************************************/
292{
293 gtk_widget_queue_draw(pdialog->image_canvas);
294}
struct civclient client
@ VC_SPACERACE
Definition fc_types.h:1123
#define _(String)
Definition fcintl.h:67
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:27
GtkWidget * top_notebook
Definition gui_main.c:128
void gui_dialog_destroy(struct gui_dialog *dlg)
Definition gui_stuff.c:951
void gui_dialog_raise(struct gui_dialog *dlg)
Definition gui_stuff.c:864
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
Definition gui_stuff.c:504
void gui_dialog_response_set_callback(struct gui_dialog *dlg, GUI_DIALOG_RESPONSE_FUN fun)
Definition gui_stuff.c:985
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *text, int response)
Definition gui_stuff.c:706
void gui_dialog_show_all(struct gui_dialog *dlg)
Definition gui_stuff.c:794
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
Definition gui_stuff.c:932
void gui_dialog_set_response_sensitive(struct gui_dialog *dlg, int response, bool setting)
Definition gui_stuff.c:759
static void spaceship_dialog_update_info(struct spaceship_dialog *pdialog)
static gboolean spaceship_image_canvas_expose(GtkWidget *widget, cairo_t *cr, gpointer data)
static struct spaceship_dialog * get_spaceship_dialog(struct player *pplayer)
void popdown_spaceship_dialog(struct player *pplayer)
static void spaceship_destroy_callback(GtkWidget *w, gpointer data)
#define dialog_list_iterate_end
void spaceship_dialog_init(void)
#define dialog_list_iterate(dialoglist, pdialog)
static struct dialog_list * dialog_list
static void spaceship_dialog_update_image(struct spaceship_dialog *pdialog)
void spaceship_dialog_done(void)
void popup_spaceship_dialog(struct player *pplayer)
void refresh_spaceship_dialog(struct player *pplayer)
static struct spaceship_dialog * create_spaceship_dialog(struct player *pplayer)
static void spaceship_response(struct gui_dialog *dlg, int response, gpointer data)
void get_spaceship_dimensions(int *width, int *height)
void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y, const struct player *pplayer)
#define fc_malloc(sz)
Definition mem.h:34
int send_packet_spaceship_launch(struct connection *pc)
const char * player_name(const struct player *pplayer)
Definition player.c:886
@ SSHIP_STARTED
Definition spaceship.h:84
cairo_t * drawable
Definition canvas.h:23
struct connection conn
Definition client_main.h:96
struct player * playing
Definition connection.h:156
GtkWidget * vbox
Definition gui_stuff.h:71
double success_rate
Definition spaceship.h:115
enum spaceship_state state
Definition spaceship.h:108
struct player_spaceship spaceship
Definition player.h:286
GtkWidget * image_canvas
struct gui_dialog * shell
struct player * pplayer
GtkWidget * info_label
GtkWidget * main_form
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * get_spaceship_descr(struct player_spaceship *pship)
Definition text.c:1533
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26