Freeciv-3.3
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-4.0 */
35#include "gui_main.h"
36#include "gui_stuff.h"
37#include "sprite.h"
38
39#include "unitselextradlg.h"
40
43 int tp_id;
44};
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, *grid;
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;
133
135 _("Close"), GTK_RESPONSE_NO,
137 NULL);
141
144
147
150 if (spr != NULL) {
152 } else {
153 icon = gtk_image_new();
154 }
156 gtk_box_append(GTK_BOX(box), icon);
157
160
162
165
168
169 grid = gtk_grid_new();
170
171 tcount = 0;
174
176 continue;
177 }
178
180 = fc_malloc(sizeof(struct unit_sel_extra_cb_data));
181
182 cbdata->tp_id = ptgt->id;
183 cbdata->dlg = dlg;
184
188 if (first_option == NULL) {
192 }
193 g_signal_connect(radio, "toggled",
195 g_signal_connect(radio, "destroy",
197 if (ptgt == suggested_tgt_extra) {
200 }
201 gtk_grid_attach(GTK_GRID(grid), radio, 0, tcount, 1, 1);
202
204 if (tubuf != NULL) {
207 } else {
208 icon = gtk_image_new();
209 }
211 gtk_grid_attach(GTK_GRID(grid), icon, 1, tcount, 1, 1);
212
214 gtk_grid_attach(GTK_GRID(grid), lbl, 2, tcount, 1, 1);
215
216 tcount++;
219
222
224 main_box);
225
227 g_object_set_data(G_OBJECT(dlg), "tile", ptile);
228
229 /* This function should never be called so that there would be no extra
230 * to select, and where there is extra to select, one of them gets
231 * selected as the default. */
232 fc_assert(default_extra != nullptr);
233 if (default_extra != nullptr) { /* Compiler still wants this */
234 g_object_set_data(G_OBJECT(dlg), "target",
236 }
237
238 g_signal_connect(dlg, "response", do_callback, actor);
239
242
243 return TRUE;
244}
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
char * incite_cost
Definition comments.c:76
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:1128
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
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:126
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(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#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:140
enum unit_activity activity
Definition unit.h:159
int id
Definition unit.h:147
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#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:148
int tileset_unit_width(const struct tileset *t)
Definition tilespec.c:823
int tileset_unit_height(const struct tileset *t)
Definition tilespec.c:831
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7029
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:779
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:1566