Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl3/chatline.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
chatline.c
Go to the documentation of this file.
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)
6 any later version.
7
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***********************************************************************/
13
14/***********************************************************************
15 chatline.c - description
16 -------------------
17 begin : Sun Jun 30 2002
18 copyright : (C) 2002 by Rafał Bursig
19 email : Rafał Bursig <bursig@poczta.fm>
20***********************************************************************/
21
22#ifdef HAVE_CONFIG_H
23#include <fc_config.h>
24#endif
25
26/* SDL3 */
27#include <SDL3/SDL.h>
28
29/* utility */
30#include "fcintl.h"
31#include "log.h"
32
33/* common */
34#include "game.h"
35#include "packets.h"
36
37/* client */
38#include "client_main.h"
39#include "clinet.h"
40#include "connectdlg_common.h"
41#include "ratesdlg_g.h"
42#include "update_queue.h"
43
44/* gui-sdl3 */
45#include "colors.h"
46#include "dialogs.h"
47#include "graphics.h"
48#include "gui_id.h"
49#include "gui_main.h"
50#include "gui_tilespec.h"
51#include "mapview.h"
52#include "messagewin.h"
53#include "themespec.h"
54#include "utf8string.h"
55#include "widget.h"
56
57#include "chatline.h"
58
59struct CONNLIST {
60 struct advanced_dialog *users_dlg;
61 struct advanced_dialog *chat_dlg;
62 struct widget *begin_widget_list;
63 struct widget *end_widget_list;
64 struct widget *start_button;
65 struct widget *select_nation_button;
66 struct widget *load_game_button;
67 struct widget *configure;
68 struct widget *back_button;
69 struct widget *pedit;
70 int text_width;
71 int active;
72} *conn_dlg = NULL;
73
74static void popup_conn_list_dialog(void);
75static void add_to_chat_list(char *msg, size_t n_alloc);
76
77/**************************************************************************
78 LOAD GAME
79**************************************************************************/
80
81 struct advanced_dialog *load_dialog;
82
83/**********************************************************************/
86 static int move_load_game_dlg_callback(struct widget *pwindow)
87{
88 if (PRESSED_EVENT(main_data.event)) {
89 move_window_group(load_dialog->begin_widget_list, pwindow);
90 }
91
92 return -1;
93}
94
95/**********************************************************************/
98 void popdown_load_game_dialog(void)
99{
100 if (load_dialog) {
101 popdown_window_group_dialog(load_dialog->begin_widget_list,
102 load_dialog->end_widget_list);
103 FC_FREE(load_dialog->scroll);
104 FC_FREE(load_dialog);
105
106 /* enable buttons */
107 set_wstate(conn_dlg->back_button, FC_WS_NORMAL);
108 widget_redraw(conn_dlg->back_button);
109 widget_mark_dirty(conn_dlg->back_button);
110 set_wstate(conn_dlg->load_game_button, FC_WS_NORMAL);
111 widget_redraw(conn_dlg->load_game_button);
112 widget_mark_dirty(conn_dlg->load_game_button);
113 set_wstate(conn_dlg->start_button, FC_WS_NORMAL);
114 widget_redraw(conn_dlg->start_button);
115 widget_mark_dirty(conn_dlg->start_button);
116
117 flush_dirty();
118 }
119}
120
121/**********************************************************************/
124 static int exit_load_dlg_callback(struct widget *pwidget)
125{
126 if (PRESSED_EVENT(main_data.event)) {
127 if (get_client_page() == PAGE_LOAD) {
128 set_client_page(PAGE_START);
129 } else {
130 popdown_load_game_dialog();
131 }
132 }
133
134 return -1;
135}
136
137/**********************************************************************/
140 static int load_selected_game_callback(struct widget *pwidget)
141{
142 if (PRESSED_EVENT(main_data.event)) {
143 char *filename = (char*)pwidget->data.ptr;
144
145 if (is_server_running()) {
146 send_chat_printf("/load %s", filename);
147
148 if (get_client_page() == PAGE_LOAD) {
149 set_client_page(PAGE_START);
150 } else if (get_client_page() == PAGE_START) {
151 popdown_load_game_dialog();
152 }
153 } else {
154 set_client_page(PAGE_MAIN);
155 }
156 }
157
158 return -1;
159}
160
161/**********************************************************************/
164 static void popup_load_game_dialog(void)
165{
166 struct widget *pwindow;
167 struct widget *close_button;
168 struct widget *filename_label = NULL;
169 struct widget *first_label = NULL;
170 struct widget *last_label = NULL;
171 struct widget *next_label = NULL;
172 utf8_str *title, *filename;
173 SDL_Rect area;
174 struct fileinfo_list *files;
175 int count = 0;
176 int scrollbar_width = 0;
177 int max_label_width = 0;
178
179 if (load_dialog) {
180 return;
181 }
182
183 /* Disable buttons */
184 set_wstate(conn_dlg->back_button, FC_WS_DISABLED);
185 widget_redraw(conn_dlg->back_button);
186 widget_mark_dirty(conn_dlg->back_button);
187 set_wstate(conn_dlg->load_game_button, FC_WS_DISABLED);
188 widget_redraw(conn_dlg->load_game_button);
189 widget_mark_dirty(conn_dlg->load_game_button);
190 set_wstate(conn_dlg->select_nation_button, FC_WS_DISABLED);
191 widget_redraw(conn_dlg->select_nation_button);
192 widget_mark_dirty(conn_dlg->select_nation_button);
193 set_wstate(conn_dlg->start_button, FC_WS_DISABLED);
194 widget_redraw(conn_dlg->start_button);
195 widget_mark_dirty(conn_dlg->start_button);
196
197 /* Create dialog */
198 load_dialog = fc_calloc(1, sizeof(struct advanced_dialog));
199
200 title = create_utf8_from_char_fonto(_("Choose Saved Game to Load"),
201 FONTO_ATTENTION);
202 title->style |= TTF_STYLE_BOLD;
203
204 pwindow = create_window_skeleton(NULL, title, 0);
205 pwindow->action = move_load_game_dlg_callback;
206 set_wstate(pwindow, FC_WS_NORMAL);
207
208 add_to_gui_list(ID_WINDOW, pwindow);
209
210 load_dialog->end_widget_list = pwindow;
211
212 area = pwindow->area;
213
214 /* Close button */
215 close_button = create_themeicon(current_theme->small_cancel_icon,
216 pwindow->dst,
217 WF_WIDGET_HAS_INFO_LABEL
218 | WF_RESTORE_BACKGROUND);
219 close_button->info_label
220 = create_utf8_from_char_fonto(_("Close Dialog (Esc)"), FONTO_ATTENTION);
221 close_button->action = exit_load_dlg_callback;
222 set_wstate(close_button, FC_WS_NORMAL);
223 close_button->key = SDLK_ESCAPE;
224
225 add_to_gui_list(ID_BUTTON, close_button);
226
227 area.w += close_button->size.w;
228
229 load_dialog->begin_widget_list = close_button;
230
231 /* Create scrollbar */
232 scrollbar_width = create_vertical_scrollbar(load_dialog, 1, 20, TRUE, TRUE);
233 hide_scrollbar(load_dialog->scroll);
234
235 /* Search for user saved games. */
236 files = fileinfolist_infix(get_save_dirs(), ".sav", FALSE);
237 fileinfo_list_iterate(files, pfile) {
238 count++;
239
240 filename = create_utf8_from_char_fonto(pfile->name, FONTO_ATTENTION_PLUS);
241 filename->style |= SF_CENTER;
242 filename_label = create_iconlabel(NULL, pwindow->dst, filename,
243 (WF_FREE_DATA | WF_SELECT_WITHOUT_BAR | WF_RESTORE_BACKGROUND));
244
245 /* Store filename */
246 filename_label->data.ptr = fc_calloc(1, strlen(pfile->fullname) + 1);
247 fc_strlcpy((char*)filename_label->data.ptr, pfile->fullname,
248 strlen(pfile->fullname) + 1);
249
250 filename_label->action = load_selected_game_callback;
251
252 set_wstate(filename_label, FC_WS_NORMAL);
253
254 /* FIXME: This was supposed to be add_widget_to_vertical_scroll_widget_list(), but
255 * add_widget_to_vertical_scroll_widget_list() needs the scrollbar area to be defined
256 * for updating the scrollbar position, but the area is not known yet (depends on
257 * maximum label width) */
258 add_to_gui_list(ID_LABEL, filename_label);
259
260 if (count == 1) {
261 first_label = filename_label;
262 }
263
264 max_label_width = MAX(max_label_width, filename_label->size.w);
265 } fileinfo_list_iterate_end;
266 fileinfo_list_destroy(files);
267
268 last_label = filename_label;
269
270 area.w = MAX(area.w, max_label_width + scrollbar_width + 1);
271
272 if (count > 0) {
273 area.h = (load_dialog->scroll->active * filename_label->size.h) + adj_size(5);
274 }
275
276 resize_window(pwindow, theme_get_background(active_theme,
277 BACKGROUND_LOADGAMEDLG),
278 NULL,
279 (pwindow->size.w - pwindow->area.w) + area.w,
280 (pwindow->size.h - pwindow->area.h) + area.h);
281
282 area = pwindow->area;
283
284 setup_vertical_scrollbar_area(load_dialog->scroll,
285 area.x + area.w - 1,
286 area.y + 1,
287 area.h - adj_size(2), TRUE);
288
289 /* Add filename labels to list */
290 filename_label = first_label;
291 while (filename_label) {
292 filename_label->size.w = area.w - scrollbar_width - 3;
293
294 next_label = filename_label->prev;
295
296 del_widget_pointer_from_gui_list(filename_label);
297 if (filename_label == first_label) {
298 add_widget_to_vertical_scroll_widget_list(load_dialog,
299 filename_label, close_button,
300 FALSE,
301 area.x + 1,
302 area.y + adj_size(2));
303 } else {
304 add_widget_to_vertical_scroll_widget_list(load_dialog,
305 filename_label,
306 load_dialog->begin_active_widget_list,
307 FALSE,
308 area.x + 1,
309 area.y + adj_size(2));
310 }
311
312 if (filename_label == last_label) {
313 break;
314 }
315
316 filename_label = next_label;
317 }
318
319 widget_set_position(pwindow,
320 (main_window_width() - pwindow->size.w) / 2,
321 (main_window_height() - pwindow->size.h) / 2);
322
323 widget_set_position(close_button,
324 area.x + area.w - close_button->size.w - 1,
325 pwindow->size.y + adj_size(2));
326
327 /* FIXME: The scrollbar already got a background saved in
328 * add_widget_to_vertical_scroll_widget_list(), but the window
329 * is not drawn yet, so this saved background is wrong.
330 * Deleting it here as a workaround. */
331 FREESURFACE(load_dialog->scroll->pscroll_bar->gfx);
332
333 redraw_group(load_dialog->begin_widget_list, pwindow, 1);
334 flush_dirty();
335}
336
337/**********************************************************************/
340 static int inputline_return_callback(struct widget *pwidget)
341{
342 if (pwidget->string_utf8->text != NULL
343 && pwidget->string_utf8->text[0] != '\0') {
344 send_chat(pwidget->string_utf8->text);
345
346 output_window_append(ftc_any, pwidget->string_utf8->text);
347 }
348
349 return -1;
350}
351
352/**********************************************************************/
355 void popup_input_line(void)
356{
357 struct widget *input_edit;
358
359 input_edit = create_edit_from_chars_fonto(NULL, main_data.gui, "",
360 FONTO_ATTENTION,
361 adj_size(400), 0);
362
363 input_edit->size.x = (main_window_width() - input_edit->size.w) / 2;
364 input_edit->size.y = (main_window_height() - input_edit->size.h) / 2;
365
366 if (edit(input_edit) != ED_ESC) {
367 inputline_return_callback(input_edit);
368 }
369
370 widget_undraw(input_edit);
371 widget_mark_dirty(input_edit);
372 FREEWIDGET(input_edit);
373
374 flush_dirty();
375}
376
377/**********************************************************************/
381 void real_output_window_append(const char *astring,
382 const struct text_tag_list *tags,
383 int conn_id)
384{
385 /* Currently this is a wrapper to the message subsystem. */
386 if (conn_dlg) {
387 size_t n = strlen(astring);
388 char *buffer = fc_strdup(astring);
389
390 add_to_chat_list(buffer, n);
391 } else {
392 meswin_add(astring, tags, NULL, E_CHAT_MSG,
393 game.info.turn, game.info.phase);
394 }
395}
396
397/**********************************************************************/
401 void log_output_window(void)
402{
403 /* TODO */
404}
405
406/**********************************************************************/
409 void clear_output_window(void)
410{
411 /* TODO */
412}
413
414/* ====================================================================== */
415
416/**********************************************************************/
419 static int conn_dlg_callback(struct widget *pwindow)
420{
421 return -1;
422}
423
424/**********************************************************************/
427 static int disconnect_conn_callback(struct widget *pwidget)
428{
429 if (PRESSED_EVENT(main_data.event)) {
430 popdown_conn_list_dialog();
431 flush_dirty();
432 disconnect_from_server(TRUE);
433 }
434
435 return -1;
436}
437
438/**********************************************************************/
441 static void add_to_chat_list(char *msg, size_t n_alloc)
442{
443 utf8_str *pstr;
444 struct widget *buf, *pwindow = conn_dlg->end_widget_list;
445
446 fc_assert_ret(msg != NULL);
447 fc_assert_ret(n_alloc != 0);
448
449 pstr = create_utf8_str_fonto(msg, n_alloc, FONTO_ATTENTION);
450
451 if (convert_utf8_str_to_const_surface_width(pstr,
452 conn_dlg->text_width - adj_size(5))) {
453 utf8_str *pstr2;
454 int count = 0;
455 char **utf8_texts = create_new_line_utf8strs(pstr->text);
456
457 while (utf8_texts[count] != NULL) {
458 pstr2 = create_utf8_str_fonto(utf8_texts[count],
459 strlen(utf8_texts[count]) + 1,
460 FONTO_ATTENTION);
461 pstr2->bgcol = (SDL_Color) {0, 0, 0, 0};
462 buf = create_themelabel2(NULL, pwindow->dst,
463 pstr2, conn_dlg->text_width, 0,
464 (WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE));
465
466 buf->size.w = conn_dlg->text_width;
467 add_widget_to_vertical_scroll_widget_list(conn_dlg->chat_dlg, buf,
468 conn_dlg->chat_dlg->begin_active_widget_list, FALSE,
469 pwindow->size.x + adj_size(10 + 60 + 10),
470 pwindow->size.y + adj_size(14));
471 count++;
472 }
473 redraw_group(conn_dlg->chat_dlg->begin_widget_list,
474 conn_dlg->chat_dlg->end_widget_list, TRUE);
475 FREEUTF8STR(pstr);
476 } else {
477 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
478 buf = create_themelabel2(NULL, pwindow->dst,
479 pstr, conn_dlg->text_width, 0,
480 (WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE));
481
482 buf->size.w = conn_dlg->text_width;
483
484 if (add_widget_to_vertical_scroll_widget_list(conn_dlg->chat_dlg, buf,
485 conn_dlg->chat_dlg->begin_active_widget_list, FALSE,
486 pwindow->size.x + adj_size(10 + 60 + 10),
487 pwindow->size.y + adj_size(14))) {
488 redraw_group(conn_dlg->chat_dlg->begin_widget_list,
489 conn_dlg->chat_dlg->end_widget_list, TRUE);
490 } else {
491 widget_redraw(buf);
492 widget_mark_dirty(buf);
493 }
494 }
495
496 flush_dirty();
497}
498
499/**********************************************************************/
502 static int input_edit_conn_callback(struct widget *pwidget)
503{
504 if (pwidget->string_utf8->text != NULL) {
505 if (pwidget->string_utf8->text[0] != '\0') {
506 send_chat(pwidget->string_utf8->text);
507 }
508
509 free(pwidget->string_utf8->text);
510 pwidget->string_utf8->text = fc_malloc(1);
511 pwidget->string_utf8->text[0] = '\0';
512 pwidget->string_utf8->n_alloc = 0;
513 }
514
515 return -1;
516}
517
518/**********************************************************************/
521 static int start_game_callback(struct widget *pwidget)
522{
523 if (PRESSED_EVENT(main_data.event)) {
524 send_chat("/start");
525 }
526
527 return -1;
528}
529
530/**********************************************************************/
533 static int select_nation_callback(struct widget *pwidget)
534{
535 if (PRESSED_EVENT(main_data.event)) {
536 popup_races_dialog(client.conn.playing);
537 }
538
539 return -1;
540}
541
542/* not implemented yet */
543#if 0
544/**********************************************************************/
547static int server_config_callback(struct widget *pwidget)
548{
549 return -1;
550}
551#endif /* 0 */
552
553/**********************************************************************/
556 static int load_game_callback(struct widget *pwidget)
557{
558 if (PRESSED_EVENT(main_data.event)) {
559 /* set_wstate(conn_dlg->load_game_button, FC_WS_NORMAL);
560 * widget_redraw(conn_dlg->load_game_button);
561 * flush_dirty(); */
562 popup_load_game_dialog();
563 }
564
565 return -1;
566}
567
568/**********************************************************************/
571 void real_conn_list_dialog_update(void *unused)
572{
573 if (C_S_PREPARING == client_state()) {
574 if (conn_dlg) {
575 struct widget *buf = NULL, *pwindow = conn_dlg->end_widget_list;
576 utf8_str *pstr = create_utf8_str_fonto(NULL, 0, FONTO_ATTENTION);
577 bool create;
578
579 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
580
581 if (conn_dlg->users_dlg) {
582 del_group(conn_dlg->users_dlg->begin_active_widget_list,
583 conn_dlg->users_dlg->end_active_widget_list);
584 conn_dlg->users_dlg->active_widget_list = NULL;
585 conn_dlg->users_dlg->begin_widget_list =
586 conn_dlg->users_dlg->scroll->pscroll_bar;
587 conn_dlg->users_dlg->scroll->count = 0;
588 } else {
589 conn_dlg->users_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
590 conn_dlg->users_dlg->end_widget_list = conn_dlg->begin_widget_list;
591 conn_dlg->users_dlg->begin_widget_list = conn_dlg->begin_widget_list;
592
593 create_vertical_scrollbar(conn_dlg->users_dlg, 1,
594 conn_dlg->active, TRUE, TRUE);
595 conn_dlg->users_dlg->end_widget_list =
596 conn_dlg->users_dlg->end_widget_list->prev;
597 setup_vertical_scrollbar_area(conn_dlg->users_dlg->scroll,
598 pwindow->size.x + pwindow->size.w - adj_size(30),
599 pwindow->size.y + adj_size(14),
600 pwindow->size.h - adj_size(44) - adj_size(40), FALSE);
601 }
602
603 hide_scrollbar(conn_dlg->users_dlg->scroll);
604 create = TRUE;
605 conn_list_iterate(game.est_connections, pconn) {
606 copy_chars_to_utf8_str(pstr, pconn->username);
607
608 buf = create_themelabel2(NULL, pwindow->dst, pstr, adj_size(100), 0,
609 (WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE));
610 clear_wflag(buf, WF_FREE_STRING);
611
612 buf->id = ID_LABEL;
613
614 /* add to widget list */
615 if (create) {
616 add_widget_to_vertical_scroll_widget_list(conn_dlg->users_dlg,
617 buf, conn_dlg->users_dlg->begin_widget_list, FALSE,
618 pwindow->area.x + pwindow->area.w - adj_size(130),
619 pwindow->size.y + adj_size(14));
620 create = FALSE;
621 } else {
622 add_widget_to_vertical_scroll_widget_list(conn_dlg->users_dlg,
623 buf, conn_dlg->users_dlg->begin_active_widget_list, FALSE,
624 pwindow->area.x + pwindow->area.w - adj_size(130),
625 pwindow->size.y + adj_size(14));
626 }
627 } conn_list_iterate_end;
628
629 conn_dlg->begin_widget_list = conn_dlg->users_dlg->begin_widget_list;
630 FREEUTF8STR(pstr);
631
632/* FIXME: implement the server settings dialog and then reactivate this part */
633#if 0
634 if (ALLOW_CTRL == client.conn.access_level
635 || ALLOW_HACK == client.conn.access_level) {
636 set_wstate(conn_dlg->configure, FC_WS_NORMAL);
637 } else {
638 set_wstate(conn_dlg->configure, FC_WS_DISABLED);
639 }
640#endif /* 0 */
641
642 /* redraw */
643 redraw_group(conn_dlg->begin_widget_list, conn_dlg->end_widget_list, 0);
644
645 widget_flush(conn_dlg->end_widget_list);
646 } else {
647 popup_conn_list_dialog();
648 }
649
650 /* PAGE_LOAD -> the server was started from the main page to load a game */
651 if (get_client_page() == PAGE_LOAD) {
652 popup_load_game_dialog();
653 }
654 } else {
655 if (popdown_conn_list_dialog()) {
656 flush_dirty();
657 }
658 }
659}
660
661/**********************************************************************/
664 static void popup_conn_list_dialog(void)
665{
666 SDL_Color window_bg_color = {255, 255, 255, 96};
667
668 struct widget *pwindow = NULL, *buf = NULL, *label = NULL;
669 struct widget* back_button = NULL;
670 struct widget *start_game_button = NULL;
671 struct widget *select_nation_button = NULL;
672/* struct widget *server_settings_button = NULL; */
673 utf8_str *pstr = NULL;
674 int n;
675 SDL_Rect area;
676 SDL_Surface *surf;
677
678 if (conn_dlg || !client.conn.established) {
679 return;
680 }
681
682 meswin_dialog_popdown();
683
684 conn_dlg = fc_calloc(1, sizeof(struct CONNLIST));
685
686 pwindow = create_window_skeleton(NULL, NULL, 0);
687 pwindow->action = conn_dlg_callback;
688 set_wstate(pwindow, FC_WS_NORMAL);
689 clear_wflag(pwindow, WF_DRAW_FRAME_AROUND_WIDGET);
690
691 conn_dlg->end_widget_list = pwindow;
692 add_to_gui_list(ID_WINDOW, pwindow);
693
694 widget_set_position(pwindow, 0, 0);
695
696 /* Create window background */
697 surf = theme_get_background(active_theme, BACKGROUND_CONNLISTDLG);
698 if (resize_window(pwindow, surf, NULL, main_window_width(),
699 main_window_height())) {
700 FREESURFACE(surf);
701 }
702
703 conn_dlg->text_width
704 = pwindow->size.w - adj_size(130) - adj_size(20) - adj_size(20);
705
706 /* Chat area background */
707 area.x = adj_size(10);
708 area.y = adj_size(14);
709 area.w = conn_dlg->text_width + adj_size(20);
710 area.h = pwindow->size.h - adj_size(44) - adj_size(40);
711 fill_rect_alpha(pwindow->theme, &area, &window_bg_color);
712
713 create_frame(pwindow->theme,
714 area.x - 1, area.y - 1, area.w + 1, area.h + 1,
715 get_theme_color(COLOR_THEME_CONNLISTDLG_FRAME));
716
717 /* User list background */
718 area.x = pwindow->size.w - adj_size(130);
719 area.y = adj_size(14);
720 area.w = adj_size(120);
721 area.h = pwindow->size.h - adj_size(44) - adj_size(40);
722 fill_rect_alpha(pwindow->theme, &area, &window_bg_color);
723
724 create_frame(pwindow->theme,
725 area.x - 1, area.y - 1, area.w + 1, area.h + 1,
726 get_theme_color(COLOR_THEME_CONNLISTDLG_FRAME));
727
728 draw_frame(pwindow->theme, 0, 0, pwindow->theme->w, pwindow->theme->h);
729
730 /* -------------------------------- */
731
732 /* Chat area */
733
734 conn_dlg->chat_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
735
736 n = conn_list_size(game.est_connections);
737
738 {
739 char cbuf[256];
740
741 fc_snprintf(cbuf, sizeof(cbuf), _("Total users logged in : %d"), n);
742 pstr = create_utf8_from_char_fonto(cbuf, FONTO_ATTENTION);
743 }
744
745 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
746
747 label = create_themelabel2(NULL, pwindow->dst,
748 pstr, conn_dlg->text_width, 0,
749 (WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE));
750
751 widget_set_position(label, adj_size(10), adj_size(14));
752
753 add_to_gui_list(ID_LABEL, label);
754
755 conn_dlg->chat_dlg->begin_widget_list = label;
756 conn_dlg->chat_dlg->end_widget_list = label;
757 conn_dlg->chat_dlg->begin_active_widget_list = conn_dlg->chat_dlg->begin_widget_list;
758 conn_dlg->chat_dlg->end_active_widget_list = conn_dlg->chat_dlg->end_widget_list;
759
760 n = (pwindow->size.h - adj_size(44) - adj_size(40)) / label->size.h;
761 conn_dlg->active = n;
762
763 create_vertical_scrollbar(conn_dlg->chat_dlg, 1,
764 conn_dlg->active, TRUE, TRUE);
765
766 setup_vertical_scrollbar_area(conn_dlg->chat_dlg->scroll,
767 adj_size(10) + conn_dlg->text_width + 1,
768 adj_size(14), pwindow->size.h - adj_size(44) - adj_size(40), FALSE);
769 hide_scrollbar(conn_dlg->chat_dlg->scroll);
770
771 /* -------------------------------- */
772
773 /* Input field */
774
775 buf = create_edit_from_chars_fonto(NULL, pwindow->dst, "",
776 FONTO_ATTENTION,
777 pwindow->size.w - adj_size(10) - adj_size(10),
778 (WF_RESTORE_BACKGROUND|WF_EDIT_LOOP));
779
780 buf->size.x = adj_size(10);
781 buf->size.y = pwindow->size.h - adj_size(40) - adj_size(5) - buf->size.h;
782 buf->action = input_edit_conn_callback;
783 set_wstate(buf, FC_WS_NORMAL);
784 conn_dlg->pedit = buf;
785 add_to_gui_list(ID_EDIT, buf);
786
787 /* Buttons */
788
789 buf = create_themeicon_button_from_chars_fonto(current_theme->back_icon,
790 pwindow->dst,
791 _("Back"), FONTO_ATTENTION, 0);
792 buf->size.x = adj_size(10);
793 buf->size.y = pwindow->size.h - adj_size(10) - buf->size.h;
794 conn_dlg->back_button = buf;
795 buf->action = disconnect_conn_callback;
796 set_wstate(buf, FC_WS_NORMAL);
797 buf->key = SDLK_ESCAPE;
798 add_to_gui_list(ID_BUTTON, buf);
799 back_button = buf;
800
801 buf = create_themeicon_button_from_chars_fonto(current_theme->ok_icon,
802 pwindow->dst,
803 _("Start"),
804 FONTO_ATTENTION, 0);
805 buf->size.x = pwindow->size.w - adj_size(10) - buf->size.w;
806 buf->size.y = back_button->size.y;
807 conn_dlg->start_button = buf;
808 buf->action = start_game_callback;
809 set_wstate(buf, FC_WS_NORMAL);
810 add_to_gui_list(ID_BUTTON, buf);
811 start_game_button = buf;
812
813 buf = create_themeicon_button_from_chars_fonto(NULL, pwindow->dst,
814 _("Pick Nation"),
815 FONTO_ATTENTION, 0);
816 buf->size.h = start_game_button->size.h;
817 buf->size.x = start_game_button->size.x - adj_size(10) - buf->size.w;
818 buf->size.y = start_game_button->size.y;
819 conn_dlg->select_nation_button = buf;
820 buf->action = select_nation_callback;
821 set_wstate(buf, FC_WS_NORMAL);
822 add_to_gui_list(ID_BUTTON, buf);
823 select_nation_button = buf;
824
825 buf = create_themeicon_button_from_chars_fonto(NULL, pwindow->dst,
826 _("Load Game"),
827 FONTO_ATTENTION, 0);
828 buf->size.h = select_nation_button->size.h;
829 buf->size.x = select_nation_button->size.x - adj_size(10) - buf->size.w;
830 buf->size.y = select_nation_button->size.y;
831 conn_dlg->load_game_button = buf;
832 buf->action = load_game_callback;
833 set_wstate(buf, FC_WS_NORMAL);
834 add_to_gui_list(ID_BUTTON, buf);
835
836 /* Not implemented yet */
837#if 0
838 buf = create_themeicon_button_from_chars_fonto(NULL, pwindow->dst,
839 _("Server Settings"),
840 FONTO_ATTENTION, 0);
841 buf->size.h = select_nation_button->size.h;
842 buf->size.x = select_nation_button->size.x - adj_size(10) - buf->size.w;
843 buf->size.y = select_nation_button->size.y;
844 conn_dlg->configure = buf;
845 buf->action = server_config_callback;
846 set_wstate(buf, FC_WS_DISABLED);
847 add_to_gui_list(ID_BUTTON, buf);
848 server_settings_button = buf;
849#endif /* 0 */
850
851 /* Not implemented yet */
852#if 0
853 buf = create_themeicon_button_from_chars_fonto(NULL, pwindow->dst->surface,
854 "?", FONTO_ATTENTION, 0);
855 buf->size.y = pwindow->size.y + pwindow->size.h - (buf->size.h + 7);
856 buf->size.x = pwindow->size.x + pwindow->size.w - (buf->size.w + 10) - 5;
857
858 buf->action = client_config_callback;
859 set_wstate(buf, FC_WS_NORMAL);
860 add_to_gui_list(ID_BUTTON, buf);
861#endif /* 0 */
862
863 conn_dlg->begin_widget_list = buf;
864 /* ------------------------------------------------------------ */
865
866 conn_list_dialog_update();
867}
868
869/**********************************************************************/
872 bool popdown_conn_list_dialog(void)
873{
874 if (conn_dlg) {
875 if (get_wstate(conn_dlg->pedit) == FC_WS_PRESSED) {
876 force_exit_from_event_loop();
877 }
878
879 popdown_window_group_dialog(conn_dlg->begin_widget_list,
880 conn_dlg->end_widget_list);
881 if (conn_dlg->users_dlg) {
882 FC_FREE(conn_dlg->users_dlg->scroll);
883 FC_FREE(conn_dlg->users_dlg);
884 }
885
886 if (conn_dlg->chat_dlg) {
887 FC_FREE(conn_dlg->chat_dlg->scroll);
888 FC_FREE(conn_dlg->chat_dlg);
889 }
890
891 FC_FREE(conn_dlg);
892
893 return TRUE;
894 }
895
896 return FALSE;
897}
898
899/**********************************************************************/
902 void version_message(const char *vertext)
903{
904 output_window_append(ftc_client, vertext);
905}
n_alloc
#define n_alloc
Definition astring.c:78
n
#define n
Definition astring.c:77
send_chat_printf
int send_chat_printf(const char *format,...)
Definition chatline_common.c:55
send_chat
int send_chat(const char *message)
Definition chatline_common.c:46
output_window_append
void output_window_append(const struct ft_color color, const char *featured_text)
Definition chatline_common.c:104
client
struct civclient client
Definition client_main.c:150
client_state
enum client_states client_state(void)
Definition client_main.c:1026
client_main.h
C_S_PREPARING
@ C_S_PREPARING
Definition client_main.h:46
disconnect_from_server
void disconnect_from_server(bool leaving_sound)
Definition clinet.c:306
clinet.h
incite_cost
char * incite_cost
Definition comments.c:74
is_server_running
bool is_server_running(void)
Definition connectdlg_common.c:124
connectdlg_common.h
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:110
current_theme
QString current_theme
Definition fc_client.cpp:64
fcintl.h
_
#define _(String)
Definition fcintl.h:67
ftc_client
const struct ft_color ftc_client
Definition featured_text.c:78
ftc_any
const struct ft_color ftc_any
Definition featured_text.c:73
game
struct civ_game game
Definition game.c:62
game.h
version_message
void version_message(const char *vertext)
Definition chatline.c:1478
log_output_window
void log_output_window(void)
Definition chatline.c:929
clear_output_window
void clear_output_window(void)
Definition chatline.c:944
real_output_window_append
void real_output_window_append(const char *astring, const struct text_tag_list *tags, int conn_id)
Definition chatline.c:875
popup_races_dialog
void popup_races_dialog(struct player *pplayer)
Definition dialogs.c:1215
flush_dirty
void flush_dirty(void)
Definition mapview.c:468
meswin_dialog_popdown
void meswin_dialog_popdown(void)
Definition messagewin.c:432
title
const char * title
Definition repodlgs.c:1314
popdown_conn_list_dialog
bool popdown_conn_list_dialog(void)
Definition chatline.c:876
load_dialog
struct advanced_dialog * load_dialog
Definition chatline.c:85
load_selected_game_callback
static int load_selected_game_callback(struct widget *pwidget)
Definition chatline.c:144
popdown_load_game_dialog
void popdown_load_game_dialog(void)
Definition chatline.c:102
popup_conn_list_dialog
static void popup_conn_list_dialog(void)
Definition chatline.c:668
disconnect_conn_callback
static int disconnect_conn_callback(struct widget *pwidget)
Definition chatline.c:431
select_nation_callback
static int select_nation_callback(struct widget *pwidget)
Definition chatline.c:537
start_game_callback
static int start_game_callback(struct widget *pwidget)
Definition chatline.c:525
real_conn_list_dialog_update
void real_conn_list_dialog_update(void *unused)
Definition chatline.c:575
popup_load_game_dialog
static void popup_load_game_dialog(void)
Definition chatline.c:168
conn_dlg_callback
static int conn_dlg_callback(struct widget *pwindow)
Definition chatline.c:423
popup_input_line
void popup_input_line(void)
Definition chatline.c:359
add_to_chat_list
static void add_to_chat_list(char *msg, size_t n_alloc)
Definition chatline.c:445
exit_load_dlg_callback
static int exit_load_dlg_callback(struct widget *pwidget)
Definition chatline.c:128
load_game_callback
static int load_game_callback(struct widget *pwidget)
Definition chatline.c:560
conn_dlg
struct CONNLIST * conn_dlg
input_edit_conn_callback
static int input_edit_conn_callback(struct widget *pwidget)
Definition chatline.c:506
move_load_game_dlg_callback
static int move_load_game_dlg_callback(struct widget *pwindow)
Definition chatline.c:90
inputline_return_callback
static int inputline_return_callback(struct widget *pwidget)
Definition chatline.c:344
get_theme_color
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
main_window_width
int main_window_width(void)
Definition graphics.c:685
fill_rect_alpha
int fill_rect_alpha(SDL_Surface *surf, SDL_Rect *prect, SDL_Color *pcolor)
Definition graphics.c:865
main_data
struct sdl2_data main_data
Definition graphics.c:57
create_frame
void create_frame(SDL_Surface *dest, Sint16 left, Sint16 top, Sint16 width, Sint16 height, SDL_Color *pcolor)
Definition graphics.c:1350
main_window_height
int main_window_height(void)
Definition graphics.c:693
FREESURFACE
#define FREESURFACE(ptr)
Definition graphics.h:322
ID_BUTTON
@ ID_BUTTON
Definition gui_id.h:29
ID_EDIT
@ ID_EDIT
Definition gui_id.h:34
ID_LABEL
@ ID_LABEL
Definition gui_id.h:27
ID_WINDOW
@ ID_WINDOW
Definition gui_id.h:30
force_exit_from_event_loop
void force_exit_from_event_loop(void)
Definition gui_main.c:561
adj_size
#define adj_size(size)
Definition gui_main.h:141
PRESSED_EVENT
#define PRESSED_EVENT(event)
Definition gui_main.h:71
copy_chars_to_utf8_str
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
create_utf8_str_fonto
utf8_str * create_utf8_str_fonto(char *in_text, size_t n_alloc, enum font_origin origin)
Definition gui_string.c:241
convert_utf8_str_to_const_surface_width
bool convert_utf8_str_to_const_surface_width(utf8_str *pstr, int width)
Definition gui_string.c:449
FREEUTF8STR
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
SF_CENTER
#define SF_CENTER
Definition gui_string.h:40
FONTO_ATTENTION
@ FONTO_ATTENTION
Definition gui_string.h:67
FONTO_ATTENTION_PLUS
@ FONTO_ATTENTION_PLUS
Definition gui_string.h:68
create_utf8_from_char_fonto
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
theme_get_background
SDL_Surface * theme_get_background(const struct theme *t, enum theme_background background)
Definition themebackgrounds.c:94
BACKGROUND_LOADGAMEDLG
@ BACKGROUND_LOADGAMEDLG
Definition themebackgrounds.h:38
BACKGROUND_CONNLISTDLG
@ BACKGROUND_CONNLISTDLG
Definition themebackgrounds.h:34
COLOR_THEME_CONNLISTDLG_FRAME
@ COLOR_THEME_CONNLISTDLG_FRAME
Definition themecolors.h:80
active_theme
struct theme * active_theme
Definition themespec.c:154
create_new_line_utf8strs
char ** create_new_line_utf8strs(const char *pstr)
Definition utf8string.c:35
del_widget_pointer_from_gui_list
void del_widget_pointer_from_gui_list(struct widget *gui)
Definition widget.c:622
add_to_gui_list
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
draw_frame
void draw_frame(SDL_Surface *pdest, Sint16 start_x, Sint16 start_y, Uint16 w, Uint16 h)
Definition widget.c:1114
redraw_group
Uint16 redraw_group(const struct widget *begin_group_widget_list, const struct widget *end_group_widget_list, int add_to_update)
Definition widget.c:720
popdown_window_group_dialog
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:983
move_window_group
void move_window_group(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:1039
widget_set_position
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
FC_WS_DISABLED
@ FC_WS_DISABLED
Definition widget.h:99
FC_WS_NORMAL
@ FC_WS_NORMAL
Definition widget.h:96
FC_WS_PRESSED
@ FC_WS_PRESSED
Definition widget.h:98
clear_wflag
void clear_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:62
add_widget_to_vertical_scroll_widget_list
bool add_widget_to_vertical_scroll_widget_list(struct advanced_dialog *dlg, struct widget *new_widget, struct widget *add_dock, bool dir, Sint16 start_x, Sint16 start_y) fc__attribute((nonnull(2)))
Definition widget_scrollbar.c:1146
widget_mark_dirty
static void widget_mark_dirty(struct widget *pwidget)
Definition widget.h:286
widget_flush
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
FREEWIDGET
#define FREEWIDGET(pwidget)
Definition widget.h:305
set_wstate
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
get_wstate
enum widget_state get_wstate(const struct widget *pwidget)
Definition widget_core.c:70
widget_undraw
static void widget_undraw(struct widget *pwidget)
Definition widget.h:296
WF_EDIT_LOOP
@ WF_EDIT_LOOP
Definition widget.h:91
WF_WIDGET_HAS_INFO_LABEL
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
WF_DRAW_FRAME_AROUND_WIDGET
@ WF_DRAW_FRAME_AROUND_WIDGET
Definition widget.h:86
WF_FREE_DATA
@ WF_FREE_DATA
Definition widget.h:78
WF_FREE_STRING
@ WF_FREE_STRING
Definition widget.h:76
WF_SELECT_WITHOUT_BAR
@ WF_SELECT_WITHOUT_BAR
Definition widget.h:89
WF_RESTORE_BACKGROUND
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
WF_DRAW_TEXT_LABEL_WITH_SPACE
@ WF_DRAW_TEXT_LABEL_WITH_SPACE
Definition widget.h:87
widget_redraw
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
del_group
#define del_group(begin_group_widget_list, end_group_widget_list)
Definition widget.h:389
create_themeicon_button_from_chars_fonto
#define create_themeicon_button_from_chars_fonto(icon_theme, pdest, char_string, fonto, flags)
Definition widget_button.h:36
create_edit_from_chars_fonto
#define create_edit_from_chars_fonto(background, pdest, char_string, fonto, length, flags)
Definition widget_edit.h:29
ED_ESC
@ ED_ESC
Definition widget_edit.h:19
edit
#define edit(pedit)
Definition widget_edit.h:34
create_themeicon
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
Definition widget_icon.c:212
create_themelabel2
struct widget * create_themelabel2(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, Uint16 w, Uint16 h, Uint32 flags)
Definition widget_label.c:241
create_iconlabel
struct widget * create_iconlabel(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, Uint32 flags)
Definition widget_label.c:215
setup_vertical_scrollbar_area
void setup_vertical_scrollbar_area(struct scroll_bar *scroll, Sint16 start_x, Sint16 start_y, Uint16 height, bool swap_start_x)
Definition widget_scrollbar.c:567
create_vertical_scrollbar
Uint32 create_vertical_scrollbar(struct advanced_dialog *dlg, Uint8 step, Uint8 active, bool create_scrollbar, bool create_buttons)
Definition widget_scrollbar.c:486
hide_scrollbar
#define hide_scrollbar(scrollbar)
Definition widget_scrollbar.h:36
resize_window
bool resize_window(struct widget *pwindow, SDL_Surface *bcgd, SDL_Color *pcolor, Uint16 new_w, Uint16 new_h)
Definition widget_window.c:255
create_window_skeleton
struct widget * create_window_skeleton(struct gui_layer *pdest, utf8_str *title, Uint32 flags)
Definition widget_window.c:180
gui_id.h
gui_tilespec.h
themespec.h
utf8string.h
widget.h
chatline.h
colors.h
dialogs.h
graphics.h
gui_main.h
mapview.h
messagewin.h
conn_list_dialog_update
void conn_list_dialog_update(void)
Definition update_queue.c:650
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
max_label_width
static int max_label_width
Definition mapview_common.c:1875
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
meswin_add
void meswin_add(const char *message, const struct text_tag_list *tags, struct tile *ptile, enum event_type event, int turn, int phase)
Definition messagewin_common.c:100
packets.h
ratesdlg_g.h
get_save_dirs
const struct strvec * get_save_dirs(void)
Definition shared.c:941
fileinfolist_infix
struct fileinfo_list * fileinfolist_infix(const struct strvec *dirs, const char *infix, bool nodups)
Definition shared.c:1211
MAX
#define MAX(x, y)
Definition shared.h:54
fileinfo_list_iterate
#define fileinfo_list_iterate(list, pnode)
Definition shared.h:176
fileinfo_list_iterate_end
#define fileinfo_list_iterate_end
Definition shared.h:178
CONNLIST
Definition chatline.c:63
CONNLIST::configure
struct widget * configure
Definition chatline.c:71
CONNLIST::pedit
struct widget * pedit
Definition chatline.c:73
CONNLIST::select_nation_button
struct widget * select_nation_button
Definition chatline.c:69
CONNLIST::load_game_button
struct widget * load_game_button
Definition chatline.c:70
CONNLIST::start_button
struct widget * start_button
Definition chatline.c:68
CONNLIST::text_width
int text_width
Definition chatline.c:74
CONNLIST::chat_dlg
struct advanced_dialog * chat_dlg
Definition chatline.c:65
CONNLIST::users_dlg
struct advanced_dialog * users_dlg
Definition chatline.c:64
CONNLIST::end_widget_list
struct widget * end_widget_list
Definition chatline.c:67
CONNLIST::active
int active
Definition chatline.c:75
CONNLIST::begin_widget_list
struct widget * begin_widget_list
Definition chatline.c:66
CONNLIST::back_button
struct widget * back_button
Definition chatline.c:72
advanced_dialog
Definition widget.h:180
advanced_dialog::begin_active_widget_list
struct widget * begin_active_widget_list
Definition widget.h:184
advanced_dialog::end_widget_list
struct widget * end_widget_list
Definition widget.h:182
advanced_dialog::end_active_widget_list
struct widget * end_active_widget_list
Definition widget.h:185
advanced_dialog::active_widget_list
struct widget * active_widget_list
Definition widget.h:186
advanced_dialog::scroll
struct scroll_bar * scroll
Definition widget.h:187
advanced_dialog::begin_widget_list
struct widget * begin_widget_list
Definition widget.h:181
astring
Definition astring.h:36
civ_game::est_connections
struct conn_list * est_connections
Definition game.h:97
civ_game::info
struct packet_game_info info
Definition game.h:89
civclient::conn
struct connection conn
Definition client_main.h:96
connection::established
bool established
Definition connection.h:140
connection::playing
struct player * playing
Definition connection.h:151
connection::access_level
enum cmdlevel access_level
Definition connection.h:177
gui_layer::surface
SDL_Surface * surface
Definition graphics.h:229
packet_game_info::turn
int turn
Definition packets_gen.h:247
packet_game_info::phase
int phase
Definition packets_gen.h:212
scroll_bar::active
Uint8 active
Definition widget_scrollbar.h:24
scroll_bar::count
Uint16 count
Definition widget_scrollbar.h:27
scroll_bar::pscroll_bar
struct widget * pscroll_bar
Definition widget_scrollbar.h:22
sdl2_data::gui
struct gui_layer * gui
Definition graphics.h:215
sdl2_data::event
SDL_Event event
Definition graphics.h:217
utf8_str
Definition gui_string.h:52
utf8_str::style
Uint8 style
Definition gui_string.h:53
utf8_str::n_alloc
size_t n_alloc
Definition gui_string.h:56
utf8_str::text
char * text
Definition gui_string.h:60
widget
Definition widget.h:112
widget::data
union widget::@216 data
widget::ptr
void * ptr
Definition widget.h:133
widget::key
SDL_Keycode key
Definition widget.h:153
widget::theme
SDL_Surface * theme
Definition widget.h:118
widget::prev
struct widget * prev
Definition widget.h:114
widget::dst
struct gui_layer * dst
Definition widget.h:116
widget::string_utf8
utf8_str * string_utf8
Definition widget.h:121
widget::action
int(* action)(struct widget *)
Definition widget.h:157
widget::area
SDL_Rect area
Definition widget.h:149
widget::gfx
SDL_Surface * gfx
Definition widget.h:120
widget::info_label
utf8_str * info_label
Definition widget.h:122
widget::size
SDL_Rect size
Definition widget.h:145
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
fc_strlcpy
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
set_client_page
void set_client_page(enum client_pages page)
Definition update_queue.c:496
get_client_page
enum client_pages get_client_page(void)
Definition update_queue.c:520
update_queue.h