~ubuntu-branches/debian/squeeze/freeciv/squeeze

« back to all changes in this revision

Viewing changes to client/gui-gtk-2.0/dialogs.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Adams, Karl Goetz, Clint Adams
  • Date: 2010-02-23 22:09:02 UTC
  • mfrom: (1.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20100223220902-kiyrmr9i4152cka5
Tags: 2.2.0-1
[ Karl Goetz ]
* Remove civserver files in /etc/ggzd/ (Closes: 523772, 517787)
* Adding ${misc:Depends} to all binary packages (lintian warnings)

[ Clint Adams ]
* New upstream version.
  - Drop data_dsc_use_bindir.diff (binary pathnames have changed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <gtk/gtk.h>
25
25
#include <gdk/gdkkeysyms.h>
26
26
 
 
27
/* common & utility */
27
28
#include "fcintl.h"
28
29
#include "game.h"
29
30
#include "government.h"
36
37
#include "support.h"
37
38
#include "unitlist.h"
38
39
 
 
40
/* client */
39
41
#include "chatline.h"
40
42
#include "choice_dialog.h"
41
43
#include "citydlg.h"
42
 
#include "civclient.h"
 
44
#include "client_main.h"
43
45
#include "climisc.h"
44
 
#include "clinet.h"
45
46
#include "connectdlg_common.h"
46
47
#include "control.h"
47
48
#include "goto.h"
56
57
#include "tilespec.h"
57
58
 
58
59
#include "dialogs.h"
 
60
#include "editprop.h"
59
61
#include "wldlg.h"
60
62
 
61
63
/******************************************************************/
62
64
static GtkWidget  *races_shell;
63
 
static char races_player_name[MAX_LEN_NAME];
 
65
struct player *races_player;
64
66
static GtkWidget  *races_nation_list[MAX_NUM_NATION_GROUPS + 1];
65
67
static GtkWidget  *races_leader;
66
68
static GList      *races_leader_list;
71
73
/******************************************************************/
72
74
#define SELECT_UNIT_READY  1
73
75
#define SELECT_UNIT_SENTRY 2
 
76
#define SELECT_UNIT_ALL    3
74
77
 
75
78
static GtkWidget *unit_select_dialog_shell;
76
79
static GtkTreeStore *unit_select_store;
88
91
static gboolean races_selection_func(GtkTreeSelection *select,
89
92
                                     GtkTreeModel *model, GtkTreePath *path,
90
93
                                     gboolean selected, gpointer data);
91
 
static const struct player *get_races_player(void);
92
94
 
93
95
static int selected_nation;
94
96
static int selected_sex;
117
119
 
118
120
  headline_label = gtk_label_new(headline);   
119
121
  gtk_box_pack_start(GTK_BOX(vbox), headline_label, FALSE, FALSE, 0);
120
 
  gtk_widget_set_name(headline_label, "notify label");
 
122
  gtk_widget_set_name(headline_label, "notify_label");
121
123
 
122
124
  gtk_label_set_justify(GTK_LABEL(headline_label), GTK_JUSTIFY_LEFT);
123
125
  gtk_misc_set_alignment(GTK_MISC(headline_label), 0.0, 0.0);
130
132
  label = gtk_label_new(lines);
131
133
  gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), label);
132
134
 
133
 
  gtk_widget_set_name(label, "notify label");
 
135
  gtk_widget_set_name(label, "notify_label");
134
136
  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
135
137
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
136
138
 
157
159
    center_tile_mapcanvas(ptile);
158
160
    break;
159
161
  case 2:
160
 
    pcity = tile_get_city(ptile);
 
162
    pcity = tile_city(ptile);
161
163
 
162
164
    if (center_when_popup_city) {
163
165
      center_tile_mapcanvas(ptile);
171
173
  gtk_widget_destroy(w);
172
174
}
173
175
 
 
176
/****************************************************************
 
177
  User clicked close for connect message dialog
 
178
*****************************************************************/
 
179
static void notify_connect_msg_response(GtkWidget *w, gint response)
 
180
{
 
181
  gtk_widget_destroy(w);
 
182
}
 
183
 
174
184
/**************************************************************************
175
185
  Popup a dialog to display information about an event that has a
176
186
  specific location.  The user should be given the option to goto that
177
187
  location.
178
188
**************************************************************************/
179
189
void popup_notify_goto_dialog(const char *headline, const char *lines,
180
 
                              struct tile *ptile)
 
190
                              const struct text_tag_list *tags,
 
191
                              struct tile *ptile)
181
192
{
182
193
  GtkWidget *shell, *label, *goto_command, *popcity_command;
183
194
  
212
223
  } else {
213
224
    struct city *pcity;
214
225
 
215
 
    pcity = tile_get_city(ptile);
 
226
    pcity = tile_city(ptile);
216
227
    gtk_widget_set_sensitive(popcity_command,
217
 
      (pcity && city_owner(pcity) == game.player_ptr));
 
228
      (NULL != pcity && city_owner(pcity) == client.conn.playing));
218
229
  }
219
230
 
220
231
  g_object_set_data(G_OBJECT(shell), "tile", ptile);
223
234
  gtk_widget_show(shell);
224
235
}
225
236
 
 
237
/**************************************************************************
 
238
  Popup a dialog to display connection message from server.
 
239
**************************************************************************/
 
240
void popup_connect_msg(const char *headline, const char *message)
 
241
{
 
242
  GtkWidget *shell, *label;
 
243
  
 
244
  shell = gtk_dialog_new_with_buttons(headline,
 
245
        NULL,
 
246
        0,
 
247
        NULL);
 
248
  setup_dialog(shell, toplevel);
 
249
  gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_CLOSE);
 
250
  gtk_window_set_position(GTK_WINDOW(shell), GTK_WIN_POS_CENTER_ON_PARENT);
 
251
 
 
252
  label = gtk_label_new(message);
 
253
  gtk_label_set_selectable(GTK_LABEL(label), 1);
 
254
 
 
255
  gtk_container_add(GTK_CONTAINER(GTK_DIALOG(shell)->vbox), label);
 
256
  gtk_widget_show(label);
 
257
 
 
258
  gtk_dialog_add_button(GTK_DIALOG(shell), GTK_STOCK_CLOSE,
 
259
                        GTK_RESPONSE_CLOSE);
 
260
 
 
261
  g_signal_connect(shell, "response", G_CALLBACK(notify_connect_msg_response),
 
262
                   NULL);
 
263
  gtk_widget_show(shell);
 
264
}
 
265
 
226
266
/****************************************************************
227
267
...
228
268
*****************************************************************/
249
289
{
250
290
  static GtkWidget *shell = NULL;
251
291
 
252
 
  if (game.player_ptr->revolution_finishes < 0) {
 
292
  if (0 > client.conn.playing->revolution_finishes) {
253
293
    if (!shell) {
254
294
      shell = gtk_message_dialog_new(NULL,
255
295
          0,
272
312
}
273
313
 
274
314
 
275
 
/****************************************************************
276
 
...
277
 
*****************************************************************/
 
315
/***********************************************************************
 
316
  NB: 'data' is a value of enum tile_special_type casted to a pointer.
 
317
***********************************************************************/
278
318
static void pillage_callback(GtkWidget *w, gpointer data)
279
319
{
280
 
  if (data) {
281
 
    struct unit *punit = game_find_unit_by_number(unit_to_use_to_pillage);
282
 
    if (punit) {
283
 
      request_new_unit_activity_targeted(punit,
284
 
                                         ACTIVITY_PILLAGE,
285
 
                                         GPOINTER_TO_INT(data));
 
320
  struct unit *punit;
 
321
  int what = GPOINTER_TO_INT(data);
 
322
 
 
323
  punit = game_find_unit_by_number(unit_to_use_to_pillage);
 
324
  if (punit) {
 
325
    Base_type_id pillage_base = -1;
 
326
 
 
327
    if (what > S_LAST) {
 
328
      pillage_base = what - S_LAST - 1;
 
329
      what = S_LAST;
286
330
    }
 
331
 
 
332
    request_new_unit_activity_targeted(punit, ACTIVITY_PILLAGE,
 
333
                                       what, pillage_base);
287
334
  }
288
335
}
289
336
 
296
343
}
297
344
 
298
345
/****************************************************************
299
 
...
 
346
  Opens pillage dialog listing possible pillage targets.
300
347
*****************************************************************/
301
348
void popup_pillage_dialog(struct unit *punit,
302
 
                          bv_special may_pillage)
 
349
                          bv_special may_pillage,
 
350
                          bv_bases bases)
303
351
{
304
352
  GtkWidget *shl;
305
 
  enum tile_special_type what, prereq;
 
353
  int what;
 
354
  enum tile_special_type prereq;
306
355
 
307
356
  if (!is_showing_pillage_dialog) {
308
357
    is_showing_pillage_dialog = TRUE;
312
361
                               _("What To Pillage"),
313
362
                               _("Select what to pillage:"));
314
363
 
315
 
    while ((what = get_preferred_pillage(may_pillage)) != S_LAST) {
 
364
    while ((what = get_preferred_pillage(may_pillage, bases)) != S_LAST) {
316
365
      bv_special what_bv;
 
366
      bv_bases what_base;
317
367
 
318
368
      BV_CLR_ALL(what_bv);
319
 
      BV_SET(what_bv, what);
320
 
      choice_dialog_add(shl, get_infrastructure_text(what_bv),
321
 
                        G_CALLBACK(pillage_callback), GINT_TO_POINTER(what));
322
 
 
323
 
      clear_special(&may_pillage, what);
324
 
      prereq = get_infrastructure_prereq(what);
325
 
      if (prereq != S_LAST) {
326
 
        clear_special(&may_pillage, prereq);
 
369
      BV_CLR_ALL(what_base);
 
370
 
 
371
      if (what > S_LAST) {
 
372
        BV_SET(what_base, what - S_LAST - 1);
 
373
      } else {
 
374
        BV_SET(what_bv, what);
 
375
      }
 
376
 
 
377
      choice_dialog_add(shl, get_infrastructure_text(what_bv, what_base),
 
378
                        G_CALLBACK(pillage_callback), GINT_TO_POINTER(what));
 
379
 
 
380
      if (what > S_LAST) {
 
381
        BV_CLR(bases, what - S_LAST - 1);
 
382
      } else {
 
383
        clear_special(&may_pillage, what);
 
384
        prereq = get_infrastructure_prereq(what);
 
385
        if (prereq != S_LAST) {
 
386
          clear_special(&may_pillage, prereq);
 
387
        }
327
388
      }
328
389
    }
329
390
 
348
409
  gtk_tree_model_get_iter(GTK_TREE_MODEL(unit_select_store), &it, path);
349
410
  gtk_tree_model_get(GTK_TREE_MODEL(unit_select_store), &it, 0, &id, -1);
350
411
 
351
 
  if ((punit = player_find_unit_by_id(game.player_ptr, id))) {
 
412
  if ((punit = player_find_unit_by_id(client.conn.playing, id))) {
352
413
    set_unit_focus(punit);
353
414
  }
354
415
 
448
509
      struct unit *pmyunit = NULL;
449
510
 
450
511
      unit_list_iterate(ptile->units, punit) {
451
 
        if (game.player_ptr == unit_owner(punit)) {
 
512
        if (unit_owner(punit) == client.conn.playing) {
452
513
          pmyunit = punit;
453
514
 
454
515
          /* Activate this unit. */
473
534
  case SELECT_UNIT_SENTRY:
474
535
    {
475
536
      unit_list_iterate(ptile->units, punit) {
476
 
        if (game.player_ptr == unit_owner(punit)) {
 
537
        if (unit_owner(punit) == client.conn.playing) {
477
538
          if ((punit->activity == ACTIVITY_IDLE) &&
478
539
              !punit->ai.control &&
479
540
              can_unit_do_activity(punit, ACTIVITY_SENTRY)) {
484
545
    }
485
546
    break;
486
547
 
 
548
  case SELECT_UNIT_ALL:
 
549
    {
 
550
      unit_list_iterate(ptile->units, punit) {
 
551
        if (unit_owner(punit) == client.conn.playing) {
 
552
          if (punit->activity == ACTIVITY_IDLE &&
 
553
              !punit->ai.control) {
 
554
            /* Give focus to it */
 
555
            add_unit_focus(punit);
 
556
          }
 
557
        }
 
558
      } unit_list_iterate_end;
 
559
    }
 
560
    break;
 
561
 
487
562
  default:
488
563
    break;
489
564
  }
501
576
  if (!unit_select_dialog_shell) {
502
577
    GtkTreeStore *store;
503
578
    GtkWidget *shell, *view, *sw, *hbox;
504
 
    GtkWidget *ready_cmd, *sentry_cmd, *close_cmd;
 
579
    GtkWidget *ready_cmd, *sentry_cmd, *select_all_cmd, *close_cmd;
505
580
 
506
581
    static const char *titles[NUM_UNIT_SELECT_COLUMNS] = {
507
582
      N_("Unit"),
594
669
      GTK_BUTTON_BOX(GTK_DIALOG(shell)->action_area),
595
670
      sentry_cmd, TRUE);
596
671
 
 
672
    select_all_cmd =
 
673
    gtk_dialog_add_button(GTK_DIALOG(shell),
 
674
      _("Select _all"), SELECT_UNIT_ALL);
 
675
 
 
676
    gtk_button_box_set_child_secondary(
 
677
      GTK_BUTTON_BOX(GTK_DIALOG(shell)->action_area),
 
678
      select_all_cmd, TRUE);
 
679
 
597
680
    close_cmd =
598
681
    gtk_dialog_add_button(GTK_DIALOG(shell),
599
682
      GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
626
709
  GtkTreeSelection *select;
627
710
  GtkCellRenderer *render;
628
711
  GtkTreeViewColumn *column;
629
 
  const struct player *races_player = get_races_player();
630
712
 
631
713
  store = gtk_list_store_new(5, G_TYPE_INT, G_TYPE_BOOLEAN,
632
714
      GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
685
767
      gtk_list_store_set(store, &it, 2, img, -1);
686
768
      g_object_unref(img);
687
769
    }
688
 
 
689
770
    if (pnation->player == races_player) {
690
771
      /* FIXME: should select this one by default. */
691
772
    }
762
843
  int i;
763
844
  char *title;
764
845
 
765
 
  if (pplayer && pplayer == game.player_ptr) {
 
846
  if (C_S_RUNNING == client_state()) {
 
847
    title = _("Edit Nation");
 
848
  } else if (NULL != pplayer && pplayer == client.conn.playing) {
766
849
    title = _("What Nation Will You Be?");
767
850
  } else {
768
851
    title = _("Pick Nation");
779
862
                                      GTK_RESPONSE_ACCEPT,
780
863
                                      NULL);
781
864
  races_shell = shell;
782
 
  if (pplayer) {
783
 
    sz_strlcpy(races_player_name, player_name(pplayer));
784
 
  } else {
785
 
    races_player_name[0] = '\0';
786
 
  }
 
865
  races_player = pplayer;
787
866
  setup_dialog(shell, toplevel);
788
867
 
789
868
  gtk_window_set_position(GTK_WINDOW(shell), GTK_WIN_POS_CENTER_ON_PARENT);
1239
1318
**************************************************************************/
1240
1319
static void races_response(GtkWidget *w, gint response, gpointer data)
1241
1320
{
1242
 
  const struct player *races_player;
1243
 
  int plrno;
1244
 
 
1245
 
  races_player = get_races_player();
1246
 
  if (!races_player) {
1247
 
    popdown_races_dialog();
1248
 
    return;
1249
 
  }
1250
 
  plrno = player_number(races_player);
1251
 
 
1252
1321
  if (response == GTK_RESPONSE_ACCEPT) {
1253
1322
    const char *s;
1254
1323
 
 
1324
    /* This shouldn't be possible but... */
1255
1325
    if (selected_nation == -1) {
1256
 
      dsend_packet_nation_select_req(&aconnection, plrno,
1257
 
                                     -1, FALSE, "", 0);
1258
 
      popdown_races_dialog();
1259
1326
      return;
1260
1327
    }
1261
1328
 
1262
1329
    if (selected_sex == -1) {
1263
 
      append_output_window(_("You must select your sex."));
 
1330
      output_window_append(ftc_client, _("You must select your sex."));
1264
1331
      return;
1265
1332
    }
1266
1333
 
1267
1334
    if (selected_city_style == -1) {
1268
 
      append_output_window(_("You must select your city style."));
 
1335
      output_window_append(ftc_client, _("You must select your city style."));
1269
1336
      return;
1270
1337
    }
1271
1338
 
1274
1341
    /* Perform a minimum of sanity test on the name. */
1275
1342
    /* This could call is_allowed_player_name if it were available. */
1276
1343
    if (strlen(s) == 0) {
1277
 
      append_output_window(_("You must type a legal name."));
 
1344
      output_window_append(ftc_client, _("You must type a legal name."));
1278
1345
      return;
1279
1346
    }
1280
1347
 
1281
 
    dsend_packet_nation_select_req(&aconnection, plrno, selected_nation,
1282
 
                                   selected_sex, s, selected_city_style);
 
1348
    dsend_packet_nation_select_req(&client.conn,
 
1349
                                   player_number(races_player), selected_nation,
 
1350
                                   selected_sex, s, selected_city_style);
1283
1351
  } else if (response == GTK_RESPONSE_NO) {
1284
 
    dsend_packet_nation_select_req(&aconnection, plrno, -1, FALSE, "", 0);
1285
 
  } else if (response == GTK_RESPONSE_CANCEL) {
1286
 
    /* Nothing - this allows the player to keep his currently selected
1287
 
     * nation. */
 
1352
    dsend_packet_nation_select_req(&client.conn,
 
1353
                                   player_number(races_player),
 
1354
                                   -1, FALSE, "", 0);
1288
1355
  }
 
1356
 
1289
1357
  popdown_races_dialog();
1290
1358
}
1291
1359
 
1344
1412
void popdown_all_game_dialogs(void)
1345
1413
{
1346
1414
  gui_dialog_destroy_all();
1347
 
}
1348
 
 
1349
 
/**************************************************************************
1350
 
  Helper function to work-around the fact that players may be renumbered
1351
 
  over the life-time of the nation selection dialog. It uses player names
1352
 
  ('races_player_name') to try to uniquely determine the player that the
1353
 
  user wants to modify.
1354
 
 
1355
 
  NB: May return NULL.
1356
 
**************************************************************************/
1357
 
static const struct player *get_races_player(void)
1358
 
{
1359
 
  return find_player_by_name(races_player_name);
1360
 
}
1361
 
 
 
1415
  property_editor_popdown(editprop_get_property_editor());
 
1416
}