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/SimpleMenu.h>
26 #include <X11/Xaw/Command.h>
27 #include <X11/Xaw/List.h>
29 /* common & utility */
30 #include "diptreaty.h"
38 #include "client_main.h"
42 #include "gui_stuff.h"
44 #include "spaceshipdlg.h"
48 static Widget players_dialog_shell
;
49 static Widget players_form
;
50 static Widget players_label
;
51 static Widget players_list
;
52 static Widget players_close_command
;
53 static Widget players_int_command
;
54 static Widget players_meet_command
;
55 static Widget players_war_command
;
56 static Widget players_vision_command
;
57 static Widget players_sship_command
;
58 static bool players_dialog_shell_is_raised
;
60 static int list_index_to_player_index
[MAX_NUM_PLAYERS
];
63 static void create_players_dialog(bool raise
);
64 static void players_close_callback(Widget w
, XtPointer client_data
,
66 static void players_meet_callback(Widget w
, XtPointer client_data
,
68 static void players_intel_callback(Widget w
, XtPointer client_data
,
70 static void players_list_callback(Widget w
, XtPointer client_data
,
72 static void players_war_callback(Widget w
, XtPointer client_data
,
74 static void players_vision_callback(Widget w
, XtPointer client_data
,
76 static void players_sship_callback(Widget w
, XtPointer client_data
,
80 /******************************************************************/
82 /****************************************************************
83 popup the dialog somewhat inside the main-window
84 *****************************************************************/
85 void popup_players_dialog(bool raise
)
87 players_dialog_shell_is_raised
= raise
;
89 if(!players_dialog_shell
)
90 create_players_dialog(raise
);
93 XtSetSensitive(main_form
, FALSE
);
96 xaw_set_relative_position(toplevel
, players_dialog_shell
, 5, 25);
97 XtPopup(players_dialog_shell
, XtGrabNone
);
100 /****************************************************************
101 Closes the player list dialog.
102 *****************************************************************/
103 void popdown_players_dialog(void)
105 if (players_dialog_shell
) {
106 if (players_dialog_shell_is_raised
) {
107 XtSetSensitive(main_form
, TRUE
);
109 XtDestroyWidget(players_dialog_shell
);
110 players_dialog_shell
= 0;
114 /****************************************************************
116 *****************************************************************/
117 void create_players_dialog(bool raise
)
119 players_dialog_shell
=
120 I_IN(I_T(XtCreatePopupShell("playerspopup",
121 raise
? transientShellWidgetClass
122 : topLevelShellWidgetClass
,
123 toplevel
, NULL
, 0)));
125 players_form
= XtVaCreateManagedWidget("playersform",
127 players_dialog_shell
, NULL
);
129 players_label
= I_L(XtVaCreateManagedWidget("playerslabel",
131 players_form
, NULL
));
134 players_list
= XtVaCreateManagedWidget("playerslist",
139 players_close_command
=
140 I_L(XtVaCreateManagedWidget("playersclosecommand", commandWidgetClass
,
141 players_form
, NULL
));
143 players_int_command
=
144 I_L(XtVaCreateManagedWidget("playersintcommand", commandWidgetClass
,
149 players_meet_command
=
150 I_L(XtVaCreateManagedWidget("playersmeetcommand", commandWidgetClass
,
155 players_war_command
=
156 I_L(XtVaCreateManagedWidget("playerswarcommand", commandWidgetClass
,
161 players_vision_command
=
162 I_L(XtVaCreateManagedWidget("playersvisioncommand", commandWidgetClass
,
167 players_sship_command
=
168 I_L(XtVaCreateManagedWidget("playerssshipcommand", commandWidgetClass
,
173 XtAddCallback(players_list
, XtNcallback
, players_list_callback
,
176 XtAddCallback(players_close_command
, XtNcallback
, players_close_callback
,
179 XtAddCallback(players_meet_command
, XtNcallback
, players_meet_callback
,
182 XtAddCallback(players_int_command
, XtNcallback
, players_intel_callback
,
185 XtAddCallback(players_war_command
, XtNcallback
, players_war_callback
,
188 XtAddCallback(players_vision_command
, XtNcallback
, players_vision_callback
,
191 XtAddCallback(players_sship_command
, XtNcallback
, players_sship_callback
,
194 players_dialog_update();
196 XtRealizeWidget(players_dialog_shell
);
198 XSetWMProtocols(display
, XtWindow(players_dialog_shell
),
199 &wm_delete_window
, 1);
200 XtOverrideTranslations(players_dialog_shell
,
201 XtParseTranslationTable("<Message>WM_PROTOCOLS: msg-close-players()"));
205 /**************************************************************************
206 Updates the player list dialog.
208 FIXME: use plrdlg_common.c
209 **************************************************************************/
210 void real_players_dialog_update(void)
212 if (players_dialog_shell
) {
215 static char *namelist_ptrs
[MAX_NUM_PLAYERS
];
216 static char namelist_text
[MAX_NUM_PLAYERS
][256];
217 const struct player_diplstate
*pds
;
219 players_iterate(pplayer
) {
220 char idlebuf
[32], statebuf
[32], namebuf
[32], dsbuf
[32];
222 /* skip barbarians */
223 if(is_barbarian(pplayer
))
227 sz_strlcpy(statebuf
, plrdlg_col_state(pplayer
));
229 /* text for idleness */
230 if(pplayer
->nturns_idle
>3) {
231 fc_snprintf(idlebuf
, sizeof(idlebuf
),
232 PL_("(idle %d turn)",
234 pplayer
->nturns_idle
- 1),
235 pplayer
->nturns_idle
- 1);
240 /* text for name, plus AI marker */
241 if (pplayer
->ai_controlled
) {
242 fc_snprintf(namebuf
, sizeof(namebuf
), "*%-15s",player_name(pplayer
));
244 fc_snprintf(namebuf
, sizeof(namebuf
), "%-16s",player_name(pplayer
));
248 /* text for diplstate type and turns -- not applicable if this is me */
249 if (NULL
== client
.conn
.playing
250 || pplayer
== client
.conn
.playing
) {
253 pds
= player_diplstate_get(client
.conn
.playing
, pplayer
);
254 if (pds
->type
== DS_CEASEFIRE
) {
255 fc_snprintf(dsbuf
, sizeof(dsbuf
), "%s (%d)",
256 diplstate_type_translated_name(pds
->type
),
259 fc_snprintf(dsbuf
, sizeof(dsbuf
), "%s",
260 diplstate_type_translated_name(pds
->type
));
264 /* assemble the whole lot */
265 fc_snprintf(namelist_text
[j
], sizeof(namelist_text
[j
]),
266 "%-16s %-12s %-8s %-15s %-8s %-6s %-15s%s",
268 nation_adjective_for_player(pplayer
),
269 get_embassy_status(client
.conn
.playing
, pplayer
),
271 get_vision_status(client
.conn
.playing
, pplayer
),
273 player_addr_hack(pplayer
), /* Fixme for multi-conn */
276 namelist_ptrs
[j
]=namelist_text
[j
];
277 list_index_to_player_index
[j
] = player_number(pplayer
);
279 } players_iterate_end
;
281 XawListChange(players_list
, namelist_ptrs
, j
, 0, True
);
283 XtVaGetValues(players_list
, XtNwidth
, &width
, NULL
);
284 XtVaSetValues(players_label
, XtNwidth
, width
, NULL
);
288 /**************************************************************************
290 **************************************************************************/
291 void players_list_callback(Widget w
, XtPointer client_data
,
295 XawListReturnStruct
*ret
;
297 ret
= XawListShowCurrent(players_list
);
299 XtSetSensitive(players_meet_command
, FALSE
);
300 XtSetSensitive(players_int_command
, FALSE
);
301 if (ret
->list_index
!= XAW_LIST_NONE
) {
302 struct player
*pplayer
=
303 player_by_number(list_index_to_player_index
[ret
->list_index
]);
305 if (pplayer
->spaceship
.state
!= SSHIP_NONE
)
306 XtSetSensitive(players_sship_command
, TRUE
);
308 XtSetSensitive(players_sship_command
, FALSE
);
310 if (NULL
!= client
.conn
.playing
&& pplayer
->is_alive
) {
311 XtSetSensitive(players_war_command
,
312 client
.conn
.playing
!= pplayer
313 && !pplayers_at_war(client
.conn
.playing
, pplayer
));
316 if (NULL
!= client
.conn
.playing
) {
317 XtSetSensitive(players_vision_command
,
318 gives_shared_vision(client
.conn
.playing
, pplayer
));
320 XtSetSensitive(players_meet_command
, can_meet_with_player(pplayer
));
322 XtSetSensitive(players_int_command
, can_intel_with_player(pplayer
));
327 /**************************************************************************
329 **************************************************************************/
330 void players_close_callback(Widget w
, XtPointer client_data
,
333 popdown_players_dialog();
336 /****************************************************************
338 *****************************************************************/
339 void plrdlg_msg_close(Widget w
)
341 players_close_callback(w
, NULL
, NULL
);
344 /**************************************************************************
346 **************************************************************************/
347 void players_meet_callback(Widget w
, XtPointer client_data
,
350 XawListReturnStruct
*ret
= XawListShowCurrent(players_list
);
352 if (ret
->list_index
!= XAW_LIST_NONE
) {
353 int player_index
= list_index_to_player_index
[ret
->list_index
];
354 struct player
*pplayer
= player_by_number(player_index
);
356 if (can_meet_with_player(pplayer
)) {
357 dsend_packet_diplomacy_init_meeting_req(&client
.conn
, player_index
);
359 output_window_append(ftc_client
,
360 _("You need an embassy to establish"
361 " a diplomatic meeting."));
366 /**************************************************************************
368 **************************************************************************/
369 void players_intel_callback(Widget w
, XtPointer client_data
,
372 XawListReturnStruct
*ret
= XawListShowCurrent(players_list
);
374 if (ret
->list_index
!= XAW_LIST_NONE
) {
375 int player_index
= list_index_to_player_index
[ret
->list_index
];
376 struct player
*pplayer
= player_by_number(player_index
);
378 if (can_intel_with_player(pplayer
)) {
379 popup_intel_dialog(pplayer
);
384 /**************************************************************************
386 **************************************************************************/
387 void players_war_callback(Widget w
, XtPointer client_data
,
390 XawListReturnStruct
*ret
= XawListShowCurrent(players_list
);
392 if (ret
->list_index
!= XAW_LIST_NONE
) {
393 int player_index
= list_index_to_player_index
[ret
->list_index
];
395 /* can be any pact clause */
396 dsend_packet_diplomacy_cancel_pact(&client
.conn
, player_index
,
401 /**************************************************************************
403 **************************************************************************/
404 void players_vision_callback(Widget w
, XtPointer client_data
,
407 XawListReturnStruct
*ret
= XawListShowCurrent(players_list
);
409 if (ret
->list_index
!= XAW_LIST_NONE
) {
410 int player_index
= list_index_to_player_index
[ret
->list_index
];
412 dsend_packet_diplomacy_cancel_pact(&client
.conn
, player_index
,
417 /**************************************************************************
419 **************************************************************************/
420 void players_sship_callback(Widget w
, XtPointer client_data
,
423 XawListReturnStruct
*ret
= XawListShowCurrent(players_list
);
425 if (ret
->list_index
!= XAW_LIST_NONE
) {
426 int player_index
= list_index_to_player_index
[ret
->list_index
];
427 struct player
*pplayer
= player_by_number(player_index
);
429 popup_spaceship_dialog(pplayer
);