1 /**********************************************************************
2 Freeciv - Copyright (C) 1996-2004 - The Freeciv Team
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>
18 #include <X11/Intrinsic.h>
19 #include <X11/StringDefs.h>
20 #include <X11/Xaw/Command.h>
21 #include <X11/Xaw/Form.h>
22 #include <X11/Xaw/Label.h>
23 #include <X11/Xaw/List.h>
24 #include <X11/Xaw/SimpleMenu.h>
25 #include <X11/Xaw/Viewport.h>
36 #include "client_main.h"
37 #include "connectdlg_g.h"
38 #include "dialogs_g.h"
40 #include "chatline.h" /* for send_chat() */
42 #include "gui_stuff.h" /* for xaw_set_relative_position() */
46 static enum client_pages old_page
;
48 static Widget start_page_shell
;
49 static Widget start_page_form
;
50 static Widget start_page_label
;
51 static Widget start_page_viewport
;
52 static Widget start_page_players_list
;
53 static Widget start_page_cancel_command
;
54 static Widget start_page_nation_command
;
55 static Widget start_page_take_command
;
56 static Widget start_page_start_command
;
57 void start_page_cancel_callback(Widget w
, XtPointer client_data
,
59 void start_page_nation_callback(Widget w
, XtPointer client_data
,
61 void start_page_take_callback(Widget w
, XtPointer client_data
,
63 void start_page_start_callback(Widget w
, XtPointer client_data
,
67 /***************************************************************************
68 Returns current client page
69 ***************************************************************************/
70 enum client_pages
get_current_client_page(void)
75 /**************************************************************************
76 Sets the "page" that the client should show. See documentation in
78 **************************************************************************/
79 void real_set_client_page(enum client_pages page
)
81 /* PORTME, PORTME, PORTME */
84 /* FIXME: call main/intro page rather than falling to network page */
88 if (old_page
== PAGE_START
) {
94 conn_list_dialog_update();
105 /****************************************************************************
106 Set the list of available rulesets. The default ruleset should be
107 "default", and if the user changes this then set_ruleset() should be
109 ****************************************************************************/
110 void set_rulesets(int num_rulesets
, char **rulesets
)
115 /**************************************************************************
117 **************************************************************************/
119 /**************************************************************************
121 **************************************************************************/
122 void popup_start_page(void)
124 if (!start_page_shell
) {
128 xaw_set_relative_position(toplevel
, start_page_shell
, 5, 25);
129 XtPopup(start_page_shell
, XtGrabNone
);
132 /**************************************************************************
134 **************************************************************************/
135 void popdown_start_page(void)
137 if (start_page_shell
) {
138 XtDestroyWidget(start_page_shell
);
139 start_page_shell
= 0;
143 /**************************************************************************
145 **************************************************************************/
146 void create_start_page(void)
149 I_IN(I_T(XtCreatePopupShell("startpage",
150 topLevelShellWidgetClass
,
151 toplevel
, NULL
, 0)));
153 start_page_form
= XtVaCreateManagedWidget("startpageform",
155 start_page_shell
, NULL
);
157 start_page_label
= I_L(XtVaCreateManagedWidget("startpagelabel",
159 start_page_form
, NULL
));
161 start_page_viewport
=
162 XtVaCreateManagedWidget("startpageviewport", viewportWidgetClass
,
163 start_page_form
, NULL
);
165 start_page_players_list
=
166 XtVaCreateManagedWidget("startpageplayerslist",
171 start_page_cancel_command
=
172 I_L(XtVaCreateManagedWidget("startpagecancelcommand",
174 start_page_form
, NULL
));
176 start_page_nation_command
=
177 I_L(XtVaCreateManagedWidget("startpagenationcommand",
182 start_page_take_command
=
183 I_L(XtVaCreateManagedWidget("startpagetakecommand",
188 start_page_start_command
=
189 I_L(XtVaCreateManagedWidget("startpagestartcommand",
195 XtAddCallback(start_page_players_list, XtNcallback,
196 start_page_players_list_callback,
199 XtAddCallback(start_page_cancel_command
, XtNcallback
,
200 start_page_cancel_callback
,
203 XtAddCallback(start_page_nation_command
, XtNcallback
,
204 start_page_nation_callback
,
207 XtAddCallback(start_page_take_command
, XtNcallback
,
208 start_page_take_callback
,
211 XtAddCallback(start_page_start_command
, XtNcallback
,
212 start_page_start_callback
,
217 XtRealizeWidget(start_page_shell
);
219 XSetWMProtocols(display
, XtWindow(start_page_shell
),
220 &wm_delete_window
, 1);
221 XtOverrideTranslations(start_page_shell
,
222 XtParseTranslationTable("<Message>WM_PROTOCOLS: msg-close-start-page()"));
225 /**************************************************************************
226 Update start page players list.
227 **************************************************************************/
228 void update_start_page(void)
230 if (!start_page_shell
) {
233 if ( C_S_PREPARING
== client_state()) {
235 const char *nation
, *leader
;
236 char name
[MAX_LEN_NAME
+ 8];
237 static char *namelist_ptrs
[MAX_NUM_PLAYERS
];
238 static char namelist_text
[MAX_NUM_PLAYERS
][256];
240 Dimension width
, height
;
244 players_iterate(pplayer
) {
245 if (pplayer
->ai_controlled
&& !pplayer
->was_created
246 && !pplayer
->is_connected
) {
247 fc_snprintf(name
, sizeof(name
), _("<%s AI>"),
248 ai_level_translated_name(pplayer
->ai_common
.skill_level
));
250 sz_strlcpy(name
, pplayer
->username
);
252 is_ready
= pplayer
->ai_controlled
? TRUE
: pplayer
->is_ready
;
253 if (pplayer
->nation
== NO_NATION_SELECTED
) {
254 nation
= _("Random");
257 nation
= nation_adjective_for_player(pplayer
);
258 leader
= player_name(pplayer
);
261 fc_snprintf(namelist_text
[j
], sizeof(namelist_text
[j
]),
262 "%-16s %-5s %-16s %-16s %-4d ",
264 is_ready
? " Yes " : " No ",
267 player_number(pplayer
));
269 namelist_ptrs
[j
]=namelist_text
[j
];
271 } players_iterate_end
;
272 conn_list_iterate(game
.est_connections
, pconn
) {
273 if (NULL
!= pconn
->playing
&& !pconn
->observer
) {
274 continue; /* Already listed above. */
276 sz_strlcpy(name
, pconn
->username
);
280 fc_snprintf(namelist_text
[j
], sizeof(namelist_text
[j
]),
281 "%-16s %-5s %-16s %-16s %-4d ",
288 namelist_ptrs
[j
]=namelist_text
[j
];
290 } conn_list_iterate_end
;
291 XawFormDoLayout(start_page_form
, False
);
292 XawListChange(start_page_players_list
, namelist_ptrs
, j
, 0, True
);
294 XtVaGetValues(start_page_players_list
, XtNlongest
, &width
, NULL
);
295 XtVaGetValues(start_page_players_list
, XtNheight
, &height
, NULL
);
296 XtVaSetValues(start_page_viewport
, XtNwidth
, width
+ 15, NULL
);
297 XtVaSetValues(start_page_label
, XtNwidth
, width
+ 15, NULL
);
298 XawFormDoLayout(start_page_form
, True
);
302 XtVaSetValues(start_page_viewport
, XtNheight
, height
, NULL
);
306 /**************************************************************************
307 Callback for start page "Cancel" button
308 **************************************************************************/
309 void start_page_cancel_callback(Widget w
, XtPointer client_data
,
312 popdown_start_page();
315 /**************************************************************************
316 Called when "Pick Nation" is clicked.
317 **************************************************************************/
318 void start_page_nation_callback(Widget w
, XtPointer client_data
,
321 if (NULL
!= client
.conn
.playing
) {
322 popup_races_dialog(client
.conn
.playing
);
326 /**************************************************************************
327 Callback for start page "Take" button
328 **************************************************************************/
329 void start_page_take_callback(Widget w
, XtPointer client_data
,
332 XawListReturnStruct
*ret
;
333 struct player
*selected_plr
;
334 ret
=XawListShowCurrent(start_page_players_list
);
335 if(ret
->list_index
!=XAW_LIST_NONE
) {
336 selected_plr
=player_by_number(ret
->list_index
);
337 if(NULL
!= selected_plr
) {
338 send_chat_printf("/take \"%s\"", player_name(selected_plr
));
339 if(selected_plr
!= client_player() && selected_plr
->ai_controlled
) {
341 send_chat_printf("/%s", ai_level_cmd(selected_plr
->ai_common
.skill_level
));
347 /**************************************************************************
348 Callback for start page "Start" button
349 **************************************************************************/
350 void start_page_start_callback(Widget w
, XtPointer client_data
,
353 /* popdown_start_page(); */
357 /**************************************************************************
358 Callback for start page window (x) button
359 **************************************************************************/
360 void start_page_msg_close(Widget w
)
362 popdown_start_page();