Freeciv-3.1
Loading...
Searching...
No Matches
infradlg.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 <gtk/gtk.h>
19
20/* utility */
21#include "fcintl.h"
22
23/* common */
24#include "extras.h"
25#include "game.h"
26
27/* client */
28#include "client_main.h"
29#include "dialogs_g.h"
30#include "mapview_common.h"
31
32/* client/gui-gtk-3.22 */
33#include "gui_main.h"
34#include "gui_stuff.h"
35
36#include "infradlg.h"
37
38static GtkWidget *infra_list_grid = NULL;
39static GtkWidget *instruction_label = NULL;
40static GtkWidget *points_label = NULL;
41static int infra_rows = 0;
42
44 struct tile *ptile;
46};
47
48/************************************************************************/
51static bool infra_dialog_open(void)
52{
53 return infra_list_grid != NULL;
54}
55
56/************************************************************************/
59static void infra_response_callback(GtkWidget *dlg, gint arg)
60{
61 infra_list_grid = NULL;
62 instruction_label = NULL;
63 points_label = NULL;
64 infra_rows = 0;
65
67
68 gtk_widget_destroy(dlg);
69}
70
71/************************************************************************/
74static void infra_selected_callback(GtkButton *but, gpointer userdata)
75{
76 struct infra_cb_data *cbdata = (struct infra_cb_data *)userdata;
77
79 cbdata->pextra->id);
80}
81
82/************************************************************************/
86{
87 GtkWidget *dlg;
88 GtkWidget *main_box;
89 GtkWidget *sep;
90
91 if (infra_dialog_open()) {
92 /* One infra dialog already open. */
93 return;
94 }
95
96 dlg = gtk_dialog_new_with_buttons(_("Place infrastructure"), NULL, 0,
97 _("Close"), GTK_RESPONSE_NO,
98 NULL);
99
101 gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_NO);
102 gtk_window_set_destroy_with_parent(GTK_WINDOW(dlg), TRUE);
103
104 main_box = gtk_grid_new();
105 gtk_orientable_set_orientation(GTK_ORIENTABLE(main_box),
106 GTK_ORIENTATION_VERTICAL);
107
108 instruction_label = gtk_label_new(_("First click a tile."));
109 gtk_container_add(GTK_CONTAINER(main_box), instruction_label);
110
111 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
112 gtk_container_add(GTK_CONTAINER(main_box), sep);
113
114 points_label = gtk_label_new(_("- infrapoints"));
115 gtk_container_add(GTK_CONTAINER(main_box), points_label);
116
117 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
118 gtk_container_add(GTK_CONTAINER(main_box), sep);
119
120 infra_list_grid = gtk_grid_new();
121 gtk_container_add(GTK_CONTAINER(main_box), infra_list_grid);
122
123 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dlg))),
124 main_box);
125
126 g_signal_connect(dlg, "destroy", G_CALLBACK(infra_response_callback), NULL);
127 g_signal_connect(dlg, "response", G_CALLBACK(infra_response_callback), NULL);
128
129 gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(dlg)));
130 gtk_widget_show(dlg);
131
133}
134
135/************************************************************************/
139{
140 if (infra_dialog_open()) {
141 char buffer[100];
142
143 fc_snprintf(buffer, sizeof(buffer),
144 PL_("%d infrapoint", "%d infrapoints",
147
148 gtk_label_set_text(GTK_LABEL(points_label), buffer);
149 }
150}
151
152/************************************************************************/
156{
157 return infra_list_grid != NULL;
158}
159
160/************************************************************************/
164{
165 while (infra_rows > 0) {
166 gtk_grid_remove_row(GTK_GRID(infra_list_grid), --infra_rows);
167 }
168
170 return;
171 }
172
174
177 GtkWidget *but = gtk_button_new_with_label(extra_name_translation(pextra));
178 struct infra_cb_data *cbdata = fc_malloc(sizeof(struct infra_cb_data));
179
180 cbdata->ptile = ptile;
181 cbdata->pextra = pextra;
182
183 g_signal_connect(but, "clicked",
184 G_CALLBACK(infra_selected_callback), cbdata);
185 gtk_grid_attach(GTK_GRID(infra_list_grid), but, 1, infra_rows++, 1, 1);
186 }
188
189 if (infra_rows <= 0) {
190 gtk_label_set_text(GTK_LABEL(instruction_label),
191 _("No infra possible. Select another tile."));
192 } else {
193 gtk_label_set_text(GTK_LABEL(instruction_label),
194 _("Select infra for the tile, or another tile."));
195 }
196
197 gtk_widget_show_all(infra_list_grid);
198}
bool client_map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
struct civclient client
bool player_can_place_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:462
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
#define extra_type_iterate(_p)
Definition extras.h:291
#define extra_type_iterate_end
Definition extras.h:297
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
GtkWidget * toplevel
Definition gui_main.c:124
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
void update_infra_dialog(void)
Definition infradlg.c:24
static GtkWidget * instruction_label
Definition infradlg.c:39
static void infra_response_callback(GtkWidget *dlg, gint arg)
Definition infradlg.c:59
bool infra_placement_mode(void)
Definition infradlg.c:155
static bool infra_dialog_open(void)
Definition infradlg.c:51
static void infra_selected_callback(GtkButton *but, gpointer userdata)
Definition infradlg.c:74
void infra_placement_set_tile(struct tile *ptile)
Definition infradlg.c:163
static GtkWidget * points_label
Definition infradlg.c:40
static GtkWidget * infra_list_grid
Definition infradlg.c:38
static int infra_rows
Definition infradlg.c:41
void infra_dialog_popup(void)
Definition infradlg.c:85
void client_infratile_set(struct tile *ptile)
#define fc_malloc(sz)
Definition mem.h:34
int dsend_packet_player_place_infra(struct connection *pc, int tile, int extra)
struct connection conn
Definition client_main.h:96
struct player * playing
Definition connection.h:156
int id
Definition extras.h:86
struct extra_type * pextra
Definition infradlg.c:45
struct tile * ptile
Definition infradlg.c:44
int infra_points
Definition player.h:74
struct player_economic economic
Definition player.h:284
Definition tile.h:49
int index
Definition tile.h:50
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
#define TRUE
Definition support.h:46