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)
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 ***********************************************************************/
15 #include <fc_config.h>
21 #include <X11/Intrinsic.h>
22 #include <X11/StringDefs.h>
23 #include <X11/Xaw/Form.h>
24 #include <X11/Xaw/Label.h>
25 #include <X11/Xaw/Command.h>
26 #include <X11/Xaw/SimpleMenu.h>
27 #include <X11/Xaw/List.h>
36 #include "government.h"
42 #include "client_main.h"
46 #include "gui_stuff.h"
48 #include "optiondlg.h"
52 /******************************************************************/
54 struct player
*pplayer
;
56 Widget intel_dialog_shell
;
59 Widget intel_close_command
;
60 Widget intel_diplo_command
;
61 bool intel_dialog_shell_is_raised
;
63 Widget intel_diplo_dialog_shell
;
64 Widget intel_diplo_form
;
65 Widget intel_diplo_label
;
66 Widget intel_diplo_list
;
67 Widget intel_diplo_close_command
;
68 bool intel_diplo_dialog_shell_is_raised
;
71 #define SPECLIST_TAG dialog
72 #define SPECLIST_TYPE struct intel_dialog
75 #define dialog_list_iterate(dialoglist, pdialog) \
76 TYPED_LIST_ITERATE(struct intel_dialog, dialoglist, pdialog)
77 #define dialog_list_iterate_end LIST_ITERATE_END
79 static struct dialog_list
*dialog_list
= NULL
;
80 static bool dialog_list_has_been_initialised
= FALSE
;
82 /******************************************************************/
84 struct intel_dialog
*get_intel_dialog(struct player
*pplayer
);
85 void popdown_intel_dialog(struct intel_dialog
*pdialog
);
86 void create_intel_dialog(struct intel_dialog
*pdialog
, bool raise
);
88 void intel_close_callback(Widget w
, XtPointer client_data
,
90 void intel_diplo_callback(Widget w
, XtPointer client_data
,
93 void popup_intel_diplo_dialog(struct player
*pplayer
, bool raise
);
94 void popdown_intel_diplo_dialog(struct intel_dialog
*pdialog
);
95 void create_intel_diplo_dialog(struct intel_dialog
*pdialog
, bool raise
);
96 void update_intel_diplo_dialog(struct intel_dialog
*pdialog
);
97 void intel_diplo_close_callback(Widget w
, XtPointer client_data
,
100 /****************************************************************
101 Get an intelligence dialog for the given player.
102 *****************************************************************/
103 struct intel_dialog
*get_intel_dialog(struct player
*pplayer
)
105 if (!dialog_list_has_been_initialised
) {
106 dialog_list
= dialog_list_new();
107 dialog_list_has_been_initialised
= TRUE
;
110 dialog_list_iterate(dialog_list
, pdialog
) {
111 if (pdialog
->pplayer
== pplayer
) {
114 } dialog_list_iterate_end
;
119 /****************************************************************
120 Popup an intelligence dialog for the given player.
121 *****************************************************************/
122 void popup_intel_dialog(struct player
*pplayer
)
124 struct intel_dialog
*pdialog
;
125 bool raise
= FALSE
; /* Drop when we'll have raise-parametered popup */
127 if (!(pdialog
= get_intel_dialog(pplayer
))) {
128 pdialog
= fc_malloc(sizeof(struct intel_dialog
));
129 pdialog
->pplayer
= pplayer
;
130 pdialog
->intel_dialog_shell
= 0;
131 pdialog
->intel_diplo_dialog_shell
= 0;
132 dialog_list_prepend(dialog_list
, pdialog
);
135 if (!(pdialog
->intel_dialog_shell
)) {
136 create_intel_dialog(pdialog
, raise
);
139 xaw_set_relative_position(toplevel
, pdialog
->intel_dialog_shell
, 25, 25);
140 XtPopup(pdialog
->intel_dialog_shell
, XtGrabNone
);
141 if (pdialog
->intel_dialog_shell_is_raised
) {
142 XtSetSensitive(main_form
, FALSE
);
146 /****************************************************************
147 Close an intelligence dialog.
148 *****************************************************************/
149 void popdown_intel_dialog(struct intel_dialog
*pdialog
)
151 if (pdialog
->intel_dialog_shell_is_raised
) {
152 XtSetSensitive(main_form
, TRUE
);
154 XtDestroyWidget(pdialog
->intel_dialog_shell
);
155 pdialog
->intel_dialog_shell
= 0;
157 if (!(pdialog
->intel_diplo_dialog_shell
)) {
158 dialog_list_remove(dialog_list
, pdialog
);
163 /**************************************************************************
164 Close an intelligence dialog for the given player.
165 **************************************************************************/
166 void close_intel_dialog(struct player
*p
)
168 struct intel_dialog
*pdialog
= get_intel_dialog(p
);
169 popdown_intel_dialog(pdialog
);
172 /****************************************************************
174 *****************************************************************/
175 void create_intel_dialog(struct intel_dialog
*pdialog
, bool raise
)
177 char buf
[4 * MAX_LEN_NAME
], plr_buf
[4 * MAX_LEN_NAME
];
179 const struct research
*presearch
= research_get(pdialog
->pplayer
);
181 static char *tech_list_names_ptrs
[A_LAST
+1];
182 static char tech_list_names
[A_LAST
+1][200];
185 pdialog
->intel_dialog_shell_is_raised
= raise
;
187 I_T(pdialog
->intel_dialog_shell
=
188 XtCreatePopupShell("intelpopup",
189 raise
? transientShellWidgetClass
190 : topLevelShellWidgetClass
,
193 pdialog
->intel_form
= XtVaCreateManagedWidget("intelform",
195 pdialog
->intel_dialog_shell
,
198 fc_snprintf(buf
, sizeof(buf
),
199 _("Intelligence Information for the %s Empire"),
200 nation_adjective_for_player(pdialog
->pplayer
));
202 pdialog
->intel_label
= I_L(XtVaCreateManagedWidget("inteltitlelabel",
208 fc_snprintf(buf
, sizeof(buf
), _("Ruler: %s"),
209 ruler_title_for_player(pdialog
->pplayer
,
210 plr_buf
, sizeof(plr_buf
)));
211 XtVaCreateManagedWidget("intelnamelabel",
217 fc_snprintf(buf
, sizeof(buf
), _("Government: %s"),
218 government_name_for_player(pdialog
->pplayer
));
219 XtVaCreateManagedWidget("intelgovlabel",
225 fc_snprintf(buf
, sizeof(buf
), _("Gold: %d"),
226 pdialog
->pplayer
->economic
.gold
);
227 XtVaCreateManagedWidget("intelgoldlabel",
233 fc_snprintf(buf
, sizeof(buf
), _("Tax: %d%%"),
234 pdialog
->pplayer
->economic
.tax
);
235 XtVaCreateManagedWidget("inteltaxlabel",
241 fc_snprintf(buf
, sizeof(buf
), _("Science: %d%%"),
242 pdialog
->pplayer
->economic
.science
);
243 XtVaCreateManagedWidget("intelscilabel",
249 fc_snprintf(buf
, sizeof(buf
), _("Luxury: %d%%"),
250 pdialog
->pplayer
->economic
.luxury
);
251 XtVaCreateManagedWidget("intelluxlabel",
257 switch (presearch
->researching
) {
259 fc_snprintf(buf
, sizeof(buf
), _("Researching: (Unknown)"));
262 fc_snprintf(buf
, sizeof(buf
), _("Researching: Unknown(%d/-)"),
263 presearch
->bulbs_researched
);
266 fc_snprintf(buf
, sizeof(buf
), _("Researching: %s(%d/%d)"),
267 research_advance_name_translation(presearch
,
268 presearch
->researching
),
269 presearch
->bulbs_researched
,
270 presearch
->client
.researching_cost
);
274 XtVaCreateManagedWidget("intelreslabel",
280 pcity
= player_capital(pdialog
->pplayer
);
281 fc_snprintf(buf
, sizeof(buf
), _("Capital: %s"),
282 /* TRANS: "unknown" location */
283 (!pcity
) ? _("(unknown)") : city_name_get(pcity
));
284 XtVaCreateManagedWidget("intelcapitallabel",
290 advance_index_iterate(A_FIRST
, i
) {
291 if (research_invention_state(presearch
, i
)
293 if (research_invention_state(research_get(client_player()), i
)
295 sz_strlcpy(tech_list_names
[j
], advance_name_translation(advance_by_number(i
)));
297 fc_snprintf(tech_list_names
[j
], sizeof(tech_list_names
[j
]),
298 "%s*", advance_name_translation(advance_by_number(i
)));
300 tech_list_names_ptrs
[j
]=tech_list_names
[j
];
303 } advance_index_iterate_end
;
304 tech_list_names_ptrs
[j
]=0;
306 XtVaCreateManagedWidget("inteltechlist",
309 XtNlist
, tech_list_names_ptrs
,
312 pdialog
->intel_close_command
=
313 I_L(XtVaCreateManagedWidget("intelclosecommand",
315 pdialog
->intel_form
, NULL
));
317 pdialog
->intel_diplo_command
=
318 I_L(XtVaCreateManagedWidget("inteldiplocommand",
320 pdialog
->intel_form
, NULL
));
322 XtAddCallback(pdialog
->intel_close_command
, XtNcallback
,
323 intel_close_callback
, (XtPointer
)pdialog
);
324 XtAddCallback(pdialog
->intel_diplo_command
, XtNcallback
,
325 intel_diplo_callback
,
326 INT_TO_XTPOINTER(player_number(pdialog
->pplayer
)));
327 XtRealizeWidget(pdialog
->intel_dialog_shell
);
329 xaw_horiz_center(pdialog
->intel_label
);
331 XSetWMProtocols(display
, XtWindow(pdialog
->intel_dialog_shell
),
332 &wm_delete_window
, 1);
333 XtOverrideTranslations(pdialog
->intel_dialog_shell
,
334 XtParseTranslationTable("<Message>WM_PROTOCOLS: msg-close-intel()"));
337 /****************************************************************************
338 Update the intelligence dialog for the given player. This is called by
339 the core client code when that player's information changes.
340 ****************************************************************************/
341 void update_intel_dialog(struct player
*p
)
346 /**************************************************************************
348 **************************************************************************/
349 void intel_close_callback(Widget w
, XtPointer client_data
,
352 popdown_intel_dialog((struct intel_dialog
*)client_data
);
355 /**************************************************************************
357 **************************************************************************/
358 void intel_diplo_callback(Widget w
, XtPointer client_data
,
361 popup_intel_diplo_dialog(player_by_number(XTPOINTER_TO_INT(client_data
)),
365 /**************************************************************************
367 **************************************************************************/
368 void intel_dialog_msg_close(Widget w
)
370 dialog_list_iterate(dialog_list
, pdialog
) {
371 if (pdialog
->intel_dialog_shell
== w
) {
372 popdown_intel_dialog(pdialog
);
375 } dialog_list_iterate_end
;
378 /****************************************************************
379 Popup a player's relations dialog for the given player.
380 *****************************************************************/
381 void popup_intel_diplo_dialog(struct player
*pplayer
, bool raise
)
383 struct intel_dialog
*pdialog
;
385 if (!(pdialog
= get_intel_dialog(pplayer
))) {
386 pdialog
= fc_malloc(sizeof(struct intel_dialog
));
387 pdialog
->pplayer
= pplayer
;
388 pdialog
->intel_dialog_shell
= 0;
389 pdialog
->intel_diplo_dialog_shell
= 0;
390 dialog_list_prepend(dialog_list
, pdialog
);
393 if (!(pdialog
->intel_diplo_dialog_shell
)) {
394 create_intel_diplo_dialog(pdialog
, raise
);
397 xaw_set_relative_position(toplevel
,
398 pdialog
->intel_diplo_dialog_shell
, 25, 25);
399 XtPopup(pdialog
->intel_diplo_dialog_shell
, XtGrabNone
);
400 if (pdialog
->intel_diplo_dialog_shell_is_raised
) {
401 XtSetSensitive(main_form
, FALSE
);
405 /****************************************************************
406 Close a player's relations dialog.
407 *****************************************************************/
408 void popdown_intel_diplo_dialog(struct intel_dialog
*pdialog
)
410 if (pdialog
->intel_diplo_dialog_shell_is_raised
) {
411 XtSetSensitive(main_form
, TRUE
);
413 XtDestroyWidget(pdialog
->intel_diplo_dialog_shell
);
414 pdialog
->intel_diplo_dialog_shell
= 0;
416 if (!(pdialog
->intel_dialog_shell
)) {
417 dialog_list_remove(dialog_list
, pdialog
);
422 /****************************************************************
423 Create a player's relations dialog for the given player.
424 *****************************************************************/
425 void create_intel_diplo_dialog(struct intel_dialog
*pdialog
, bool raise
)
427 char buf
[4 * MAX_LEN_NAME
], plr_buf
[4 * MAX_LEN_NAME
];
429 pdialog
->intel_diplo_dialog_shell_is_raised
= raise
;
431 pdialog
->intel_diplo_dialog_shell
=
432 I_IN(I_T(XtCreatePopupShell("inteldiplopopup",
433 raise
? transientShellWidgetClass
434 : topLevelShellWidgetClass
,
435 toplevel
, NULL
, 0)));
437 pdialog
->intel_diplo_form
=
438 XtVaCreateManagedWidget("inteldiploform",
440 pdialog
->intel_diplo_dialog_shell
,
443 fc_snprintf(buf
, sizeof(buf
),
444 _("Intelligence Diplomacy Information for the %s Empire"),
445 nation_adjective_for_player(pdialog
->pplayer
));
447 pdialog
->intel_diplo_label
=
448 I_L(XtVaCreateManagedWidget("inteldiplolabel",
450 pdialog
->intel_diplo_form
,
454 fc_snprintf(buf
, sizeof(buf
), _("Ruler: %s"),
455 ruler_title_for_player(pdialog
->pplayer
,
456 plr_buf
, sizeof(plr_buf
)));
457 XtVaCreateManagedWidget("inteldiplonamelabel",
459 pdialog
->intel_diplo_form
,
463 pdialog
->intel_diplo_list
=
464 XtVaCreateManagedWidget("inteldiplolist",
466 pdialog
->intel_diplo_form
,
469 pdialog
->intel_diplo_close_command
=
470 I_L(XtVaCreateManagedWidget("inteldiploclosecommand",
472 pdialog
->intel_diplo_form
,
475 XtAddCallback(pdialog
->intel_diplo_close_command
, XtNcallback
,
476 intel_diplo_close_callback
, (XtPointer
)pdialog
);
478 update_intel_diplo_dialog(pdialog
);
480 XtRealizeWidget(pdialog
->intel_diplo_dialog_shell
);
482 XSetWMProtocols(display
, XtWindow(pdialog
->intel_diplo_dialog_shell
),
483 &wm_delete_window
, 1);
484 XtOverrideTranslations(pdialog
->intel_diplo_dialog_shell
,
485 XtParseTranslationTable("<Message>WM_PROTOCOLS: msg-close-intel-diplo()"));
488 /****************************************************************
489 Update a player's relations dialog for the given player.
490 *****************************************************************/
491 void update_intel_diplo_dialog(struct intel_dialog
*pdialog
)
495 static char *namelist_ptrs
[MAX_NUM_PLAYERS
];
496 static char namelist_text
[MAX_NUM_PLAYERS
][72];
497 const struct player_diplstate
*state
;
499 if (pdialog
->intel_diplo_dialog_shell
) {
501 players_iterate(other
) {
502 if (other
== pdialog
->pplayer
) {
505 state
= player_diplstate_get(pdialog
->pplayer
, other
);
506 fc_snprintf(namelist_text
[i
], sizeof(namelist_text
[i
]),
509 nation_adjective_for_player(other
),
510 diplstate_type_translated_name(state
->type
));
511 namelist_ptrs
[i
] = namelist_text
[i
];
513 } players_iterate_end
;
515 XawListChange(pdialog
->intel_diplo_list
, namelist_ptrs
, i
, 0, True
);
517 XtVaGetValues(pdialog
->intel_diplo_list
, XtNwidth
, &width
, NULL
);
518 XtVaSetValues(pdialog
->intel_diplo_label
, XtNwidth
, width
, NULL
);
522 /**************************************************************************
524 **************************************************************************/
525 void intel_diplo_close_callback(Widget w
, XtPointer client_data
,
528 popdown_intel_diplo_dialog((struct intel_dialog
*)client_data
);
531 /**************************************************************************
533 **************************************************************************/
534 void intel_diplo_dialog_msg_close(Widget w
)
536 dialog_list_iterate(dialog_list
, pdialog
) {
537 if (pdialog
->intel_diplo_dialog_shell
== w
) {
538 popdown_intel_diplo_dialog(pdialog
);
541 } dialog_list_iterate_end
;