Freeciv-3.2
Loading...
Searching...
No Matches
unitselextradlg.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#include "movement.h"
27#include "nation.h"
28#include "unit.h"
29
30/* client */
31#include "control.h"
32#include "tilespec.h"
33
34/* client/gui-gtk-3.22 */
35#include "gui_main.h"
36#include "gui_stuff.h"
37#include "sprite.h"
38
39#include "unitselextradlg.h"
40
45
46/***********************************************************************/
50static const char *tgt_extra_descr(const struct extra_type *tgt_extra,
51 const struct tile *tgt_tile)
52{
53 static char buf[248] = "";
54 static char buf2[248] = "";
55
57 if (extra_owner(tgt_tile)) {
58 /* TRANS: nation adjective for extra owner used below if the target
59 * tile has the target extra and it has an owner. */
60 fc_snprintf(buf2, sizeof(buf2), Q_("?eowner:%s"),
62 } else {
63 /* TRANS: used below if the target tile has the target extra but it
64 * doesn't have an owner. */
65 sz_strlcpy(buf2, _("target"));
66 }
67 } else {
68 /* TRANS: used below if the target tile doesn't have the target
69 * extra (so it is assumed that it will be created). */
70 sz_strlcpy(buf2, _("create"));
71 }
72
73 /* TRANS: extra name ... one of the above strings depending on if the
74 * target extra currently exists at the target tile and if it has an
75 * owner. */
76 fc_snprintf(buf, sizeof(buf), _("%s\n(%s)"),
78
79 return buf;
80}
81
82/************************************************************************/
95
96/************************************************************************/
103
104/************************************************************************/
107bool select_tgt_extra(struct unit *actor, struct tile *ptile,
110 const gchar *dlg_title,
111 const gchar *actor_label,
112 const gchar *tgt_label,
113 const gchar *do_label,
115{
116 GtkWidget *dlg;
118 GtkWidget *box;
119 GtkWidget *icon;
120 GtkWidget *lbl;
121 GtkWidget *sep;
125 struct sprite *spr;
126 const struct unit_type *actor_type = unit_type_get(actor);
127 int tcount;
128 const struct extra_type *default_extra = NULL;
129
131 _("Close"), GTK_RESPONSE_NO,
133 NULL);
137
141 box = gtk_grid_new();
144
146 gtk_grid_attach(GTK_GRID(box), lbl, 0, 0, 1, 1);
147
150 if (spr != NULL) {
152 } else {
153 icon = gtk_image_new();
154 }
155 gtk_grid_attach(GTK_GRID(box), icon, 1, 0, 1, 1);
156
158 gtk_grid_attach(GTK_GRID(box), lbl, 2, 0, 1, 1);
159
161
164
167
168 box = gtk_grid_new();
169
170 tcount = 0;
173
175 continue;
176 }
177
179 = fc_malloc(sizeof(struct unit_sel_extra_cb_data));
180
181 cbdata->tp_id = ptgt->id;
182 cbdata->dlg = dlg;
183
186 if (first_option == NULL) {
190 }
191 /* The lists must be the same length if they contain the same
192 * elements. */
197 "The radio button for '%s' is broken.",
199 g_signal_connect(radio, "toggled",
201 g_signal_connect(radio, "destroy",
203 if (ptgt == suggested_tgt_extra) {
206 }
207 gtk_grid_attach(GTK_GRID(box), radio, 0, tcount, 1, 1);
208
210 if (tubuf != NULL) {
213 } else {
214 icon = gtk_image_new();
215 }
216 gtk_grid_attach(GTK_GRID(box), icon, 1, tcount, 1, 1);
217
219 gtk_grid_attach(GTK_GRID(box), lbl, 2, tcount, 1, 1);
220
221 tcount++;
224
227
230 main_box);
231
233 g_object_set_data(G_OBJECT(dlg), "tile", ptile);
234
235 /* This function should never be called so that there would be no extra to select,
236 * and where there is extra to select, one of them gets selected as the default. */
238 if (default_extra != NULL) { /* Compiler still wants this */
240 }
241
242 g_signal_connect(dlg, "response", do_callback, actor);
243
246
247 return TRUE;
248}
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
char * incite_cost
Definition comments.c:75
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1114
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_type_re_active_iterate_end
Definition extras.h:329
#define extra_type_re_active_iterate(_p)
Definition extras.h:325
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
GtkWidget * toplevel
Definition gui_main.c:125
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
Definition sprite.c:402
GdkPixbuf * create_extra_pixbuf(const struct extra_type *pextra)
Definition sprite.c:494
static void unit_sel_extra_toggled(GtkToggleButton *tb, gpointer userdata)
bool select_tgt_extra(struct unit *actor, struct tile *ptile, bv_extras potential_tgt_extras, struct extra_type *suggested_tgt_extra, const gchar *dlg_title, const gchar *actor_label, const gchar *tgt_label, const gchar *do_label, GCallback do_callback)
static void unit_sel_extra_destroyed(GtkWidget *radio, gpointer userdata)
static const char * tgt_extra_descr(const struct extra_type *tgt_extra, const struct tile *tgt_tile)
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_malloc(sz)
Definition mem.h:34
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
Definition tile.h:50
Definition unit.h:138
enum unit_activity activity
Definition unit.h:157
int id
Definition unit.h:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:6805
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560