Removed silencing of gtk warning logs from gtk3.22-client.
[freeciv.git] / client / gui-xaw / pages.c
blobc1f67c6592dbc059924073a3a7a247e5b3e2375e
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)
6 any later version.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
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>
27 /* utility */
28 #include "fcintl.h"
29 #include "log.h"
30 #include "support.h"
32 /* common */
33 #include "game.h"
35 /* client */
36 #include "client_main.h"
37 #include "connectdlg_g.h"
38 #include "dialogs_g.h"
40 #include "chatline.h" /* for send_chat() */
41 #include "gui_main.h"
42 #include "gui_stuff.h" /* for xaw_set_relative_position() */
44 #include "pages.h"
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,
58 XtPointer call_data);
59 void start_page_nation_callback(Widget w, XtPointer client_data,
60 XtPointer call_data);
61 void start_page_take_callback(Widget w, XtPointer client_data,
62 XtPointer call_data);
63 void start_page_start_callback(Widget w, XtPointer client_data,
64 XtPointer call_data);
67 /***************************************************************************
68 Returns current client page
69 ***************************************************************************/
70 enum client_pages get_current_client_page(void)
72 return old_page;
75 /**************************************************************************
76 Sets the "page" that the client should show. See documentation in
77 pages_g.h.
78 **************************************************************************/
79 void real_set_client_page(enum client_pages page)
81 /* PORTME, PORTME, PORTME */
82 switch (page) {
83 case PAGE_MAIN:
84 /* FIXME: call main/intro page rather than falling to network page */
85 server_connect();
86 break;
87 case PAGE_GAME:
88 if (old_page == PAGE_START) {
89 popdown_start_page();
91 break;
92 case PAGE_START:
93 popup_start_page();
94 conn_list_dialog_update();
95 break;
96 case PAGE_SCENARIO:
97 case PAGE_LOAD:
98 case PAGE_NETWORK:
99 break;
102 old_page = page;
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
108 called.
109 ****************************************************************************/
110 void set_rulesets(int num_rulesets, char **rulesets)
112 /* PORTME */
115 /**************************************************************************
116 START PAGE
117 **************************************************************************/
119 /**************************************************************************
120 Popup start page.
121 **************************************************************************/
122 void popup_start_page(void)
124 if (!start_page_shell) {
125 create_start_page();
128 xaw_set_relative_position(toplevel, start_page_shell, 5, 25);
129 XtPopup(start_page_shell, XtGrabNone);
132 /**************************************************************************
133 Close start page.
134 **************************************************************************/
135 void popdown_start_page(void)
137 if (start_page_shell) {
138 XtDestroyWidget(start_page_shell);
139 start_page_shell = 0;
143 /**************************************************************************
144 Create start page.
145 **************************************************************************/
146 void create_start_page(void)
148 start_page_shell =
149 I_IN(I_T(XtCreatePopupShell("startpage",
150 topLevelShellWidgetClass,
151 toplevel, NULL, 0)));
153 start_page_form = XtVaCreateManagedWidget("startpageform",
154 formWidgetClass,
155 start_page_shell, NULL);
157 start_page_label = I_L(XtVaCreateManagedWidget("startpagelabel",
158 labelWidgetClass,
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",
167 listWidgetClass,
168 start_page_viewport,
169 NULL);
171 start_page_cancel_command =
172 I_L(XtVaCreateManagedWidget("startpagecancelcommand",
173 commandWidgetClass,
174 start_page_form, NULL));
176 start_page_nation_command =
177 I_L(XtVaCreateManagedWidget("startpagenationcommand",
178 commandWidgetClass,
179 start_page_form,
180 NULL));
182 start_page_take_command =
183 I_L(XtVaCreateManagedWidget("startpagetakecommand",
184 commandWidgetClass,
185 start_page_form,
186 NULL));
188 start_page_start_command =
189 I_L(XtVaCreateManagedWidget("startpagestartcommand",
190 commandWidgetClass,
191 start_page_form,
192 NULL));
195 XtAddCallback(start_page_players_list, XtNcallback,
196 start_page_players_list_callback,
197 NULL);
199 XtAddCallback(start_page_cancel_command, XtNcallback,
200 start_page_cancel_callback,
201 NULL);
203 XtAddCallback(start_page_nation_command, XtNcallback,
204 start_page_nation_callback,
205 NULL);
207 XtAddCallback(start_page_take_command, XtNcallback,
208 start_page_take_callback,
209 NULL);
211 XtAddCallback(start_page_start_command, XtNcallback,
212 start_page_start_callback,
213 NULL);
215 update_start_page();
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) {
231 return;
233 if ( C_S_PREPARING == client_state()) {
234 bool is_ready;
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];
239 int j;
240 Dimension width, height;
242 j = 0;
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));
249 } else {
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");
255 leader = "";
256 } else {
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 ",
263 name,
264 is_ready ? " Yes " : " No ",
265 leader,
266 nation,
267 player_number(pplayer));
269 namelist_ptrs[j]=namelist_text[j];
270 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);
277 nation = "";
278 leader = "";
280 fc_snprintf(namelist_text[j], sizeof(namelist_text[j]),
281 "%-16s %-5s %-16s %-16s %-4d ",
282 name,
283 " No ",
284 leader,
285 nation,
286 -1);
288 namelist_ptrs[j]=namelist_text[j];
289 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);
299 if (height > 120) {
300 height = 120;
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,
310 XtPointer call_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,
319 XtPointer call_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,
330 XtPointer call_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) {
340 send_chat("/away");
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,
351 XtPointer call_data)
353 /* popdown_start_page(); */
354 send_chat("/start");
357 /**************************************************************************
358 Callback for start page window (x) button
359 **************************************************************************/
360 void start_page_msg_close(Widget w)
362 popdown_start_page();