Freeciv-3.3
Loading...
Searching...
No Matches
optiondlg.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 optiondlg.c - description
16 -------------------
17 begin : Sun Aug 11 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#include <stdarg.h>
27#include <stdlib.h>
28
29/* SDL2 */
30#ifdef SDL2_PLAIN_INCLUDE
31#include <SDL.h>
32#else /* SDL2_PLAIN_INCLUDE */
33#include <SDL2/SDL.h>
34#endif /* SDL2_PLAIN_INCLUDE */
35
36/* utility */
37#include "fcintl.h"
38#include "log.h"
39#include "string_vector.h"
40
41/* common */
42#include "fc_types.h"
43#include "game.h"
44
45/* client */
46#include "client_main.h"
47#include "climisc.h"
48#include "clinet.h"
49#include "connectdlg_common.h"
50#include "global_worklist.h"
51#include "pages_g.h"
52
53/* gui-sdl2 */
54#include "colors.h"
55#include "connectdlg.h"
56#include "dialogs.h"
57#include "graphics.h"
58#include "gui_id.h"
59#include "gui_main.h"
60#include "gui_tilespec.h"
61#include "helpdlg.h"
62#include "mapctrl.h"
63#include "mapview.h"
64#include "menu.h"
65#include "messagewin.h"
66#include "themespec.h"
67#include "widget.h"
68#include "wldlg.h"
69
70#include "optiondlg.h"
71
77
83
87
88struct option_dialog {
95 union {
96 struct option_dialog_optset optset;
98 };
99};
100
101
105
106
107static struct widget *option_widget_new(struct option *poption,
108 struct widget *window,
109 bool hide);
110static void option_widget_update(struct option *poption);
111static void option_widget_apply(struct option *poption);
112
113static struct option_dialog *option_dialog_new(void);
114static void option_dialog_destroy(struct option_dialog *pdialog);
115
116static void option_dialog_optset(struct option_dialog *pdialog,
117 const struct option_set *poptset);
118static void option_dialog_optset_category(struct option_dialog *pdialog,
119 int category);
120
121static void option_dialog_worklist(struct option_dialog *pdialog);
122
123/************************************************************************/
127static void arrange_widgets(struct widget *window, int widgets_per_row,
128 int rows_shown, struct widget *begin,
129 struct widget *end, ...)
130{
131 struct widget *widget;
135 int w, h, i, j;
136 va_list args;
137
138 fc_assert_ret(NULL != window);
139 fc_assert_ret(NULL != begin);
140 fc_assert_ret(NULL != end);
142
143 /* Get window dimensions. */
144 memset(longest, 0, sizeof(longest));
145 for (widget = begin, i = 0; widget != end; widget = widget->next, i++) {
146 j = i % widgets_per_row;
147 longest[j] = MAX(longest[j], widget->size.w);
148 }
149
150 fc_assert(0 == (i % widgets_per_row));
151
152 if (-1 == rows_shown) {
153 h = 30 * (i / widgets_per_row);
154 } else {
155 h = 30 * MIN((i / widgets_per_row), rows_shown);
156 }
157
158 w = (1 - widgets_per_row) * adj_size(20);
159 for (j = 0; j < widgets_per_row; j++) {
160 w += longest[j];
161 }
162 if (-1 != rows_shown) {
163 w += adj_size(20);
164 }
165
166 /* Clear former area. */
167 area = window->area;
168 area.w += window->size.x;
169 area.h += window->size.y;
171
172 /* Resize window. */
174 if (resize_window(window, logo, NULL,
175 adj_size(w + 80), adj_size(h + 80))) {
177 }
178
179 /* Set window position. */
180 widget_set_position(window, (main_window_width() - window->size.w) / 2,
181 (main_window_height() - window->size.h) / 2);
182
183 area = window->area;
184
185 /* Set icons position. */
186 va_start(args, end);
187 w = 0;
188 while ((widget = va_arg(args, struct widget *))) {
189 w += widget->size.w;
190 widget_set_position(widget, area.x + area.w - w - 1,
191 window->size.y + adj_size(2));
192 }
193 va_end(args);
194
195 if (1 < widgets_per_row) {
196 xpos[widgets_per_row - 1] = area.x + adj_size(20);
197 for (j = widgets_per_row - 2; j >= 0; j--) {
198 xpos[j] = xpos[j + 1] + adj_size(20) + longest[j + 1];
199 }
200 }
201
202 /* Set button position. */
203 h = 30 * (i / widgets_per_row + 1);
204 for (widget = begin, i = 0; widget != end; widget = widget->next, i++) {
205 j = i % widgets_per_row;
206 if (0 == j) {
207 h -= 30;
208 }
210 if (1 == widgets_per_row) {
211 widget_set_position(widget, area.x + (area.w - widget->size.w) / 2,
212 area.y + adj_size(h));
213 } else {
215 }
216 }
217
218 redraw_group(begin, window, 0);
219 widget_mark_dirty(window);
220 flush_all();
221}
222
223/************************************************************************/
226static int main_optiondlg_callback(struct widget *pwindow)
227{
231 }
232
233 return -1;
234}
235
236/************************************************************************/
239static int back_callback(struct widget *pwidget)
240{
242 return -1;
243 }
244
245 if (ODM_MAIN == option_dialog->mode) {
246 if (client.conn.established) {
247 /* Back to game. */
252 flush_dirty();
253 } else {
254 /* Back to main page. */
257 }
258 return -1;
259 }
260
262 && -1 != option_dialog->optset.category) {
263 /* Back to option set category menu. */
267 }
272
275
277
280
285 return -1;
286 }
287
289 && NULL != option_dialog->advanced) {
293 }
294
295 /* Back to main options menu. */
298
300
308
309 return -1;
310}
311
312/************************************************************************/
315static int client_options_callback(struct widget *pwidget)
316{
318 option_dialog_popup(_("Local Options"), client_optset);
319 }
320
321 return -1;
322}
323
324/************************************************************************/
327static int server_options_callback(struct widget *pwidget)
328{
330 option_dialog_popup(_("Server options"), server_optset);
331 }
332
333 return -1;
334}
335
336/************************************************************************/
340{
343 }
344
345 return -1;
346}
347
348/************************************************************************/
351static int save_client_options_callback(struct widget *pwidget)
352{
355 }
356
357 return -1;
358}
359
360/************************************************************************/
363static int save_game_callback(struct widget *pwidget)
364{
368 }
369
370 return -1;
371}
372
373/************************************************************************/
376static int help_browser_callback(struct widget *pwidget)
377{
380 }
381
382 return -1;
383}
384
385/************************************************************************/
388static int disconnect_callback(struct widget *pwidget)
389{
394 }
395
396 return -1;
397}
398
399/************************************************************************/
402static int exit_callback(struct widget *pwidget)
403{
408 }
409
410 return 0;
411}
412
413/************************************************************************/
417{
420 }
421
422 return -1;
423}
424
425/************************************************************************/
443
444/************************************************************************/
447static int none_callback(struct widget *widget)
448{
449 return -1;
450}
451
452/************************************************************************/
455static struct strvec *video_mode_list(void)
456{
457 struct strvec *video_modes = strvec_new();
458 int active_display = 0; /* TODO: Support multiple displays */
459 int mode_count;
460 int i;
461
463 for (i = 0; i < mode_count; i++) {
464 SDL_DisplayMode mode;
465
466 if (!SDL_GetDisplayMode(active_display, i, &mode)) {
467 char buf[64];
468 struct video_mode vmod = { .width = mode.w, .height = mode.h };
469
470 if (video_mode_to_string(buf, sizeof(buf), &vmod)) {
472 }
473 }
474 }
475
476 return video_modes;
477}
478
479/************************************************************************/
483{
485}
486
487/************************************************************************/
491{
494}
495
496/************************************************************************/
499static struct widget *option_widget_new(struct option *poption,
500 struct widget *window,
501 bool hide)
502{
503 struct widget *widget;
504 char *help_text;
507
509 fc_assert_ret_val(NULL != window, NULL);
510
513
525
526 widget = NULL;
527 switch (option_type(poption)) {
528 case OT_BOOLEAN:
531 break;
532
533 case OT_INTEGER:
534 {
535 char buf[64];
536
537 fc_snprintf(buf, sizeof(buf), "%d", option_int_get(poption));
540 adj_size(25),
542 }
543 break;
544
545 case OT_STRING:
546 {
547 const struct strvec *values = option_str_values(poption);
548
549 if (NULL != values) {
552 option_str_get(poption), values,
553 adj_size(25),
555 } else {
559 adj_size(25),
561 }
562 }
563 break;
564
565 case OT_ENUM:
566 {
567 const struct strvec *values = option_enum_values(poption);
569 int i;
570
572 for (i = 0; i < strvec_size(values); i++) {
574 }
575
582 }
583 break;
584
585 case OT_VIDEO_MODE:
586 {
587 char buf[64];
588 struct video_mode vmod;
589
591 if (!video_mode_to_string(buf, sizeof(buf), &vmod)) {
592 /* Always fails. */
594 }
595
601 }
602 break;
603
604 case OT_FONT:
605 {
609 adj_size(25),
611 }
612 break;
613
614 case OT_BITWISE:
615 case OT_COLOR:
616 log_error("Option type %s (%d) not supported yet.",
619 break;
620 }
621
622 if (NULL == widget) {
623 /* Not implemented. */
625 FONTO_ATTENTION, flags);
626 } else {
632 }
633 }
634
637
639
640 return widget;
641}
642
643/************************************************************************/
647{
648 struct widget *widget;
649
653
657
658 switch (option_type(poption)) {
659 case OT_BOOLEAN:
662 }
663 break;
664
665 case OT_INTEGER:
666 {
667 char buf[64];
668
669 fc_snprintf(buf, sizeof(buf), "%d", option_int_get(poption));
671 }
672 break;
673
674 case OT_STRING:
676 break;
677
678 case OT_ENUM:
681 break;
682
683 case OT_VIDEO_MODE:
684 {
685 char buf[64];
686 struct video_mode vmod;
687
689 if (video_mode_to_string(buf, sizeof(buf), &vmod)) {
691 } else {
692 /* Always fails. */
694 }
695 }
696 break;
697
698 case OT_FONT:
700 break;
701
702 case OT_BITWISE:
703 case OT_COLOR:
704 log_error("Option type %s (%d) not supported yet.",
707 break;
708 }
709
712}
713
714/************************************************************************/
718{
719 struct widget *widget;
720
724
725 switch (option_type(poption)) {
726 case OT_BOOLEAN:
728 break;
729
730 case OT_INTEGER:
731 {
732 int value;
733
734 if (str_to_int(widget->string_utf8->text, &value)) {
735 (void) option_int_set(poption, value);
736 }
737 }
738 break;
739
740 case OT_STRING:
742 break;
743
744 case OT_ENUM:
745 {
746 int i;
747
748 /* 'str' is translated, so we cannot use directly
749 * option_enum_set_str(). */
750 for (i = 0; i < strvec_size(widget->data.vector); i++) {
753 break;
754 }
755 }
756 }
757 break;
758
759 case OT_VIDEO_MODE:
760 {
761 struct video_mode mode;
762
765 } else {
766 /* Always fails. */
768 }
769 }
770 break;
771
772 case OT_FONT:
774 break;
775
776 case OT_BITWISE:
777 case OT_COLOR:
778 log_error("Option type %s (%d) not supported yet.",
781 break;
782 }
783}
784
785/************************************************************************/
789{
790 struct option_dialog *pdialog = fc_calloc(1, sizeof(*pdialog));
791 struct widget *window, *close_button, *widget;
792 utf8_str *str;
793
794 pdialog->mode = ODM_MAIN;
795
796 /* Create window widget. */
798 str->style |= TTF_STYLE_BOLD;
799
800 window = create_window_skeleton(NULL, str, 0);
802
803 set_wstate(window, FC_WS_NORMAL);
805 pdialog->end_widget_list = window;
806
807 /* Create close button widget. */
808 close_button = create_themeicon(current_theme->small_cancel_icon,
809 window->dst,
812 close_button->info_label
813 = create_utf8_from_char_fonto(_("Close Dialog (Esc)"), FONTO_ATTENTION);
814 close_button->action = back_callback;
815 set_wstate(close_button, FC_WS_NORMAL);
816 close_button->key = SDLK_ESCAPE;
818 pdialog->core_widget_list = close_button;
819
820 /* Create client options button widget. */
822 _("Local options"),
823 FONTO_ATTENTION, 0);
828
829 /* Create server options button widget. */
831 _("Server options"),
832 FONTO_ATTENTION, 0);
834 if (client.conn.established) {
836 }
839
840 /* Create global worklists button widget. */
842 _("Worklists"),
843 FONTO_ATTENTION, 0);
845 if (C_S_RUNNING == client_state()) {
847 }
850
851 /* Create save game button widget. */
853 _("Save Local Options"),
854 FONTO_ATTENTION, 0);
859
860 /* Create save game button widget. */
862 _("Save Game"),
863 FONTO_ATTENTION, 0);
865 if (C_S_RUNNING == client_state()) {
867 }
870
871 /* Create help browser button widget. */
873 _("Help Browser"),
874 FONTO_ATTENTION, 0);
876 widget->key = SDLK_h;
877 if (client.conn.established) {
879 }
882
883 /* Create leave game button widget. */
885 _("Leave Game"),
886 FONTO_ATTENTION, 0);
888 widget->key = SDLK_q;
889 if (client.conn.established) {
891 }
894
895 /* Create quit widget button. */
897 _("Quit"),
898 FONTO_ATTENTION, 0);
900 widget->key = SDLK_q;
904
905 pdialog->begin_widget_list = widget;
906 pdialog->main_widget_list = widget;
907
908 arrange_widgets(window, 1, -1, widget, pdialog->core_widget_list,
909 pdialog->core_widget_list, NULL);
910
911 return pdialog;
912}
913
914/************************************************************************/
917static void option_dialog_destroy(struct option_dialog *pdialog)
918{
919 fc_assert_ret(NULL != pdialog);
920
921 if (ODM_OPTSET == pdialog->mode && -1 != pdialog->optset.category) {
923 if (pdialog->optset.category == option_category(poption)) {
925 }
927 }
928
929 if (NULL != pdialog->advanced) {
930 free(pdialog->advanced->scroll);
931 free(pdialog->advanced);
932 }
933
935 pdialog->end_widget_list);
936
937 free(pdialog);
938}
939
940/************************************************************************/
943static int optset_category_option_count(const struct option_set *poptset,
944 int category)
945{
946 int count = 0;
947
948 options_iterate(poptset, poption) {
949 if (category == option_category(poption)) {
950 count++;
951 }
953
954 return count;
955}
956
957/************************************************************************/
960static void option_dialog_optset(struct option_dialog *pdialog,
961 const struct option_set *poptset)
962{
964 struct widget *window;
965 struct widget *widget = NULL;
966 int i, category_num;
967
968 fc_assert_ret(NULL != pdialog);
969 fc_assert_ret(NULL != poptset);
970 category_num = optset_category_number(poptset);
971 fc_assert_ret(0 < category_num);
972
973 poptset_dialog = &pdialog->optset;
974 pdialog->mode = ODM_OPTSET;
975 poptset_dialog->poptset = poptset;
976 poptset_dialog->category = -1;
977
978 window = pdialog->end_widget_list;
979
980 /* Hide ODM_MAIN widget group. */
982
983 /* Otherwise we don't enter next loop at all, and widget will remain NULL */
984 fc_assert(category_num > 0);
985
986 /* Make the category buttons. */
987 for (i = 0; i < category_num; i++) {
988 if (0 == optset_category_option_count(poptset, i)) {
989 continue;
990 }
991
993 optset_category_name(poptset, i),
994 FONTO_ATTENTION, 0);
999 }
1000
1001 poptset_dialog->widget_list = widget;
1002 pdialog->begin_widget_list = widget;
1003
1004 arrange_widgets(window, 1, -1, widget, pdialog->main_widget_list,
1005 pdialog->core_widget_list, NULL);
1006}
1007
1008/************************************************************************/
1012 int category)
1013{
1015 const struct option_set *poptset;
1016 struct widget *window, *widget = NULL, *apply_button;
1017 const int MAX_SHOWN = 10;
1018 SDL_Rect area;
1019 int i;
1020
1021 fc_assert_ret(NULL != pdialog);
1022 fc_assert_ret(ODM_OPTSET == pdialog->mode);
1023 fc_assert_ret(NULL == pdialog->advanced);
1024 poptset_dialog = &pdialog->optset;
1025 poptset = poptset_dialog->poptset;
1026 fc_assert_ret(0 < optset_category_option_count(poptset, category));
1027
1028 /* Hide ODM_OPTSET widget group. */
1029 hide_group(poptset_dialog->widget_list, pdialog->main_widget_list->prev);
1030
1031 poptset_dialog->category = category;
1032 window = pdialog->end_widget_list;
1033
1034 /* Create the apply button. */
1035 apply_button = create_themeicon(current_theme->small_ok_icon, window->dst,
1038 apply_button->info_label = create_utf8_from_char_fonto(_("Apply changes"),
1040 apply_button->action = apply_callback;
1043
1044 /* Create the option widgets. */
1045 i = 0;
1046 options_iterate(poptset, poption) {
1047 if (category != option_category(poption)) {
1048 continue;
1049 }
1050
1052 i++;
1054
1055 /* Scrollbar. */
1056 pdialog->advanced = fc_calloc(1, sizeof(*pdialog->advanced));
1057 pdialog->advanced->end_widget_list = pdialog->end_widget_list;
1059 pdialog->advanced->begin_widget_list = widget;
1061
1063
1064 if (i >= MAX_SHOWN) {
1065 pdialog->advanced->active_widget_list =
1067 } else {
1068 hide_scrollbar(pdialog->advanced->scroll);
1069 }
1070
1071 pdialog->begin_widget_list = pdialog->advanced->begin_widget_list;
1072
1073 arrange_widgets(window, 2, MAX_SHOWN,
1077
1078 area = window->area;
1080 area.x + area.w - 1, area.y + 1,
1081 area.h - adj_size(32), TRUE);
1082
1084 pdialog->advanced->active_widget_list, 0);
1085 widget_flush(window);
1086}
1087
1088
1089/************************************************************************/
1093{
1095
1096 if (NULL == option_dialog
1098 || NULL == pgwl) {
1099 return -1;
1100 }
1101
1102 if (main_data.event.type == SDL_MOUSEBUTTONDOWN) {
1103 switch (main_data.event.button.button) {
1104 case SDL_BUTTON_LEFT:
1105 /* Edit. */
1108 break;
1109
1110 case SDL_BUTTON_RIGHT:
1111 {
1112 /* Delete. */
1113 struct advanced_dialog *advanced = option_dialog->advanced;
1114 bool scroll = (NULL != advanced->active_widget_list);
1115
1118
1119 /* Find if there was scrollbar hide. */
1120 if (scroll && advanced->active_widget_list == NULL) {
1121 int len = advanced->scroll->up_left_button->size.w;
1122
1123 widget = advanced->end_active_widget_list->next;
1124 do {
1125 widget = widget->prev;
1126 widget->size.w += len;
1128 } while (widget != advanced->begin_active_widget_list);
1129 }
1130
1134 flush_dirty();
1135 }
1136 break;
1137 }
1138 } else if (PRESSED_EVENT(main_data.event)) {
1139 /* Edit. */
1142 }
1143
1144 return -1;
1145}
1146
1147/************************************************************************/
1151{
1154 struct widget *window = option_dialog->end_widget_list;
1155 struct global_worklist *pgwl = global_worklist_new(_("empty worklist"));
1156 struct advanced_dialog *advanced = option_dialog->advanced;
1157 bool scroll = advanced->active_widget_list == NULL;
1158 bool redraw_all = FALSE;
1159
1162
1163 /* Create list element. */
1170 new_worklist_widget->string_utf8->style |= SF_CENTER;
1172 new_worklist_widget->size.w = widget->size.w;
1174
1175 /* Add to widget list. */
1178 window->area.x + adj_size(17),
1179 window->area.y + adj_size(17));
1180
1181 /* Find if there was scrollbar shown. */
1182 if (scroll && advanced->active_widget_list != NULL) {
1183 int len = advanced->scroll->up_left_button->size.w;
1184
1185 window = advanced->end_active_widget_list->next;
1186 do {
1187 window = window->prev;
1188 window->size.w -= len;
1189 window->area.w -= len;
1190 FREESURFACE(window->gfx);
1191 } while (window != advanced->begin_active_widget_list);
1192 }
1193
1194 if (redraw_all) {
1198 } else {
1199 /* Redraw only new widget and dock widget. */
1202 }
1205
1206 if (!new_worklist_widget->gfx
1209 }
1212 }
1213 flush_dirty();
1214 }
1215
1216 return -1;
1217}
1218
1219/************************************************************************/
1223static void option_dialog_worklist(struct option_dialog *pdialog)
1224{
1225 SDL_Color bg_color = {255, 255, 255, 128};
1226 struct widget *widget, *window, *background;
1227 int count = 0, scrollbar_width = 0, longest = 0;
1228 SDL_Rect area;
1229
1230 pdialog->mode = ODM_WORKLIST;
1231 pdialog->worklist.edited_name = NULL;
1232 window = pdialog->end_widget_list;
1233
1234 /* Hide main widget group. */
1235 hide_group(pdialog->main_widget_list, pdialog->core_widget_list->prev);
1236
1237 /* Create white background. */
1238 background = create_iconlabel(NULL, window->dst, NULL, WF_FREE_THEME);
1239 add_to_gui_list(ID_LABEL, background);
1240
1241 /* Build the global worklists list. */
1251 longest = MAX(longest, widget->size.w);
1252 count++;
1253
1254 if (count > 13) {
1256 }
1258
1259 /* Create the adding item. */
1261 _("Add new worklist"),
1268 longest = MAX(longest, widget->size.w);
1269 count++;
1270
1271 if (count > 13) {
1273 }
1274
1275 /* Advanced dialog. */
1276 pdialog->advanced = fc_calloc(1, sizeof(*pdialog->advanced));
1277 pdialog->advanced->end_widget_list = pdialog->end_widget_list;
1279 pdialog->main_widget_list->prev->prev;
1280 pdialog->advanced->begin_widget_list = widget;
1282
1283 /* Clear former area. */
1284 area = window->area;
1285 area.w += window->size.x;
1286 area.h += window->size.y;
1288
1289 /* Resize window. */
1290 resize_window(window, NULL, NULL,
1291 adj_size(longest + 40), window->size.h);
1292 area = window->area;
1293
1294 /* Move close button. */
1295 widget = pdialog->core_widget_list;
1297 window->size.y + adj_size(2));
1298
1299 /* Resize white background. */
1300 area.x += adj_size(12);
1301 area.y += adj_size(12);
1302 area.w -= adj_size(12) + adj_size(12);
1303 area.h -= adj_size(12) + adj_size(12);
1304 background->theme = create_surf(area.w, area.h, SDL_SWSURFACE);
1305 widget_set_area(background, area);
1306 widget_set_position(background, area.x, area.y);
1307 SDL_FillRect(background->theme, NULL,
1308 map_rgba(background->theme->format, bg_color));
1309
1310 create_frame(background->theme,
1311 0, 0, background->theme->w - 1, background->theme->h - 1,
1313
1314 /* Create the Scrollbar. */
1316 1, 13, TRUE, TRUE);
1318 area.x + area.w - 1, area.y + 1,
1319 area.h - adj_size(32), TRUE);
1320
1321 if (count > 13) {
1322 pdialog->advanced->active_widget_list =
1324 } else {
1325 hide_scrollbar(pdialog->advanced->scroll);
1326 scrollbar_width = 0;
1327 }
1328
1329 /* Draw! */
1331 area.y + adj_size(5),
1332 area.w - adj_size(10) - scrollbar_width, 0,
1335
1336 pdialog->begin_widget_list = pdialog->advanced->begin_widget_list;
1337
1338 redraw_group(pdialog->begin_widget_list, pdialog->end_widget_list, 0);
1339 widget_flush(window);
1340}
1341
1342/************************************************************************/
1346{
1349 clear_surface(pbutton->dst->surface, &pbutton->size);
1352
1354 }
1355
1356 return -1;
1357}
1358
1359/* ======================================================================= */
1360/* =================================== Public ============================ */
1361/* ======================================================================= */
1362
1363/************************************************************************/
1370
1371/************************************************************************/
1378
1379/************************************************************************/
1383{
1384 char buf[256];
1385
1390 fc_snprintf(buf, sizeof(buf), "%s (%s)", _("Options"), "Esc");
1396
1397#ifndef GUI_SDL2_SMALL_SCREEN
1399#endif
1400
1402}
1403
1404/************************************************************************/
1428
1429/************************************************************************/
1433{
1434 if (NULL != option_dialog) {
1435 return;
1436 }
1437
1440 flush_dirty();
1441
1443
1445 flush_dirty();
1446}
1447
1448/************************************************************************/
1452{
1453 if (NULL == option_dialog) {
1454 return;
1455 }
1456
1459
1460 if (!leave_game) {
1462 }
1463
1466 }
1467}
1468
1469/************************************************************************/
1472void option_dialog_popup(const char *name, const struct option_set *poptset)
1473{
1474 if (NULL == option_dialog) {
1476 } else if (ODM_OPTSET == option_dialog->mode
1477 && poptset == option_dialog->optset.poptset) {
1478 /* Already in use. */
1479 return;
1480 } else {
1481 while (ODM_MAIN != option_dialog->mode) {
1483 }
1484 }
1485
1487}
1488
1489/************************************************************************/
1492void option_dialog_popdown(const struct option_set *poptset)
1493{
1494 while (NULL != option_dialog
1496 && poptset == option_dialog->optset.poptset) {
1498 }
1499}
1500
1501/************************************************************************/
1505{
1506 if (NULL != option_dialog
1511 }
1512
1513 if (!strcmp(option_name(poption), "nationset")) {
1515 }
1516}
1517
1518/************************************************************************/
1531
1532/************************************************************************/
#define str
Definition astring.c:76
struct civclient client
enum client_states client_state(void)
@ C_S_RUNNING
Definition client_main.h:47
void disconnect_from_server(bool leaving_sound)
Definition clinet.c:306
char * incite_cost
Definition comments.c:76
void send_save_game(const char *filename)
QString current_theme
Definition fc_client.cpp:64
#define _(String)
Definition fcintl.h:67
struct global_worklist * global_worklist_by_id(int id)
const char * global_worklist_name(const struct global_worklist *pgwl)
int global_worklist_id(const struct global_worklist *pgwl)
void global_worklist_destroy(struct global_worklist *pgwl)
struct global_worklist * global_worklist_new(const char *name)
#define global_worklists_iterate(pgwl)
#define global_worklists_iterate_end
void popdown_all_game_dialogs(void)
Definition dialogs.c:1514
static GtkTextBuffer * help_text
Definition helpdlg.c:70
void flush_dirty(void)
Definition mapview.c:468
void meswin_dialog_popup(bool raise)
Definition messagewin.c:417
bool meswin_dialog_is_open(void)
Definition messagewin.c:443
void option_gui_remove(struct option *poption)
Definition optiondlg.c:1041
void option_dialog_popdown(const struct option_set *poptset)
Definition optiondlg.c:986
static void option_dialog_destroy(struct option_dialog *pdialog)
Definition optiondlg.c:405
void option_gui_add(struct option *poption)
Definition optiondlg.c:1027
void option_gui_update(struct option *poption)
Definition optiondlg.c:1013
void option_dialog_popup(const char *name, const struct option_set *poptset)
Definition optiondlg.c:972
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
void nationset_changed(void)
Definition dialogs.c:3565
int main_window_width(void)
Definition graphics.c:685
struct sdl2_data main_data
Definition graphics.c:57
SDL_Surface * create_surf(int width, int height, Uint32 flags)
Definition graphics.c:351
int clear_surface(SDL_Surface *surf, SDL_Rect *dstrect)
Definition graphics.c:400
void create_frame(SDL_Surface *dest, Sint16 left, Sint16 top, Sint16 width, Sint16 height, SDL_Color *pcolor)
Definition graphics.c:1350
int main_window_height(void)
Definition graphics.c:693
#define FREESURFACE(ptr)
Definition graphics.h:322
#define map_rgba(format, color)
Definition graphics.h:315
@ ID_OPTIONS_DISC_BUTTON
Definition gui_id.h:78
@ ID_OPTIONS_SAVE_BUTTON
Definition gui_id.h:75
@ ID_OPTIONS_APPLY_BUTTON
Definition gui_id.h:80
@ ID_CLIENT_OPTIONS
Definition gui_id.h:38
@ ID_OPTIONS_CLIENT_BUTTON
Definition gui_id.h:72
@ ID_OPTIONS_WORKLIST_BUTTON
Definition gui_id.h:74
@ ID_ADD_NEW_WORKLIST
Definition gui_id.h:214
@ ID_OPTIONS_SAVE_GAME_BUTTON
Definition gui_id.h:76
@ ID_OPTIONS_HELP_BROWSER_BUTTON
Definition gui_id.h:77
@ ID_OPTIONS_BACK_BUTTON
Definition gui_id.h:79
@ ID_OPTIONS_WINDOW
Definition gui_id.h:71
@ ID_LABEL
Definition gui_id.h:27
@ ID_OPTIONS_SERVER_BUTTON
Definition gui_id.h:73
@ ID_OPTIONS_EXIT_BUTTON
Definition gui_id.h:81
void force_exit_from_event_loop(void)
Definition gui_main.c:566
struct widget * selected_widget
Definition widget.c:48
#define adj_size(size)
Definition gui_main.h:141
#define PRESSED_EVENT(event)
Definition gui_main.h:71
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
#define SF_CENTER
Definition gui_string.h:40
@ FONTO_ATTENTION
Definition gui_string.h:67
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
void popup_help_browser(void)
Definition helpdlg.c:77
void enable_main_widgets(void)
Definition mapctrl.c:2180
void disable_main_widgets(void)
Definition mapctrl.c:2102
void dirty_sdl_rect(SDL_Rect *Rect)
Definition mapview.c:181
void flush_all(void)
Definition mapview.c:201
struct widget * options_button
Definition optiondlg.c:103
static int disconnect_callback(struct widget *pwidget)
Definition optiondlg.c:388
void update_worklist_report_dialog(void)
Definition optiondlg.c:1409
static int save_game_callback(struct widget *pwidget)
Definition optiondlg.c:363
static int optset_category_option_count(const struct option_set *poptset, int category)
Definition optiondlg.c:943
static int work_lists_callback(struct widget *widget)
Definition optiondlg.c:339
static void option_widget_apply(struct option *poption)
Definition optiondlg.c:717
static int server_options_callback(struct widget *pwidget)
Definition optiondlg.c:327
static struct option_dialog * option_dialog_new(void)
Definition optiondlg.c:788
static bool restore_meswin_dialog
Definition optiondlg.c:104
void enable_options_button(void)
Definition optiondlg.c:1366
void popdown_optiondlg(bool leave_game)
Definition optiondlg.c:1451
static int main_optiondlg_callback(struct widget *pwindow)
Definition optiondlg.c:226
static void enum_widget_destroy(struct widget *widget)
Definition optiondlg.c:482
static int edit_worklist_callback(struct widget *widget)
Definition optiondlg.c:1092
static int exit_callback(struct widget *pwidget)
Definition optiondlg.c:402
static int client_options_callback(struct widget *pwidget)
Definition optiondlg.c:315
static void video_mode_widget_destroy(struct widget *widget)
Definition optiondlg.c:490
void init_options_button(void)
Definition optiondlg.c:1382
static int save_client_options_callback(struct widget *pwidget)
Definition optiondlg.c:351
void disable_options_button(void)
Definition optiondlg.c:1374
static int add_new_worklist_callback(struct widget *widget)
Definition optiondlg.c:1150
option_dialog_mode
Definition optiondlg.c:72
@ ODM_MAIN
Definition optiondlg.c:73
@ ODM_WORKLIST
Definition optiondlg.c:75
@ ODM_OPTSET
Definition optiondlg.c:74
static int back_callback(struct widget *pwidget)
Definition optiondlg.c:239
static int none_callback(struct widget *widget)
Definition optiondlg.c:447
void popup_optiondlg(void)
Definition optiondlg.c:1432
static struct widget * option_widget_new(struct option *poption, struct widget *window, bool hide)
Definition optiondlg.c:499
static int help_browser_callback(struct widget *pwidget)
Definition optiondlg.c:376
static int apply_callback(struct widget *widget)
Definition optiondlg.c:428
static void arrange_widgets(struct widget *window, int widgets_per_row, int rows_shown, struct widget *begin, struct widget *end,...)
Definition optiondlg.c:127
static void option_dialog_optset_category(struct option_dialog *pdialog, int category)
Definition optiondlg.c:1011
static void option_widget_update(struct option *poption)
Definition optiondlg.c:646
int optiondlg_callback(struct widget *pbutton)
Definition optiondlg.c:1345
static int option_category_callback(struct widget *widget)
Definition optiondlg.c:416
static struct strvec * video_mode_list(void)
Definition optiondlg.c:455
SDL_Surface * theme_get_background(const struct theme *t, enum theme_background background)
@ BACKGROUND_OPTIONDLG
@ COLOR_THEME_OPTIONDLG_WORKLISTLIST_FRAME
struct theme * active_theme
Definition themespec.c:154
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
void del_group_of_widgets_from_gui_list(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:863
void refresh_widget_background(struct widget *pwidget)
Definition widget.c:1151
void show_group(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:934
void hide_group(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:915
int setup_vertical_widgets_position(int step, Sint16 start_x, Sint16 start_y, Uint16 w, Uint16 h, struct widget *begin, struct widget *end)
Definition widget.c:1051
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
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:983
void move_window_group(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:1039
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
#define MAX_ID
Definition widget.h:38
@ FC_WS_DISABLED
Definition widget.h:99
@ FC_WS_NORMAL
Definition widget.h:96
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)))
bool del_widget_from_vertical_scroll_widget_list(struct advanced_dialog *dlg, struct widget *pwidget) fc__attribute((nonnull(2)))
static void widget_mark_dirty(struct widget *pwidget)
Definition widget.h:286
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
enum widget_flag get_wflags(const struct widget *pwidget)
Definition widget_core.c:86
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
@ WF_HIDDEN
Definition widget.h:68
@ WF_FREE_THEME
Definition widget.h:72
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
static void widget_resize(struct widget *pwidget, int w, int h)
Definition widget.h:271
static void widget_set_area(struct widget *pwidget, SDL_Rect area)
Definition widget.h:261
#define hide(id)
Definition widget.h:238
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
#define create_icon_button_from_chars_fonto(icon, pdest, char_string, fonto, flags)
void toggle_checkbox(struct widget *cbox)
bool get_checkbox_state(struct widget *cbox)
struct widget * create_checkbox(struct gui_layer *pdest, bool state, Uint32 flags)
void combo_popdown(struct widget *combo)
#define combo_new_from_chars_fonto(background, dest, fonto, char_string, vector, length, flags)
#define create_edit_from_chars_fonto(background, pdest, char_string, fonto, length, flags)
Definition widget_edit.h:29
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
void remake_label_size(struct widget *label)
struct widget * create_iconlabel(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, Uint32 flags)
#define create_iconlabel_from_chars_fonto(picon, pdest, chars, fonto, flags)
void setup_vertical_scrollbar_area(struct scroll_bar *scroll, Sint16 start_x, Sint16 start_y, Uint16 height, bool swap_start_x)
Uint32 create_vertical_scrollbar(struct advanced_dialog *dlg, Uint8 step, Uint8 active, bool create_scrollbar, bool create_buttons)
#define hide_scrollbar(scrollbar)
bool resize_window(struct widget *pwindow, SDL_Surface *bcgd, SDL_Color *pcolor, Uint16 new_w, Uint16 new_h)
struct widget * create_window_skeleton(struct gui_layer *pdest, utf8_str *title, Uint32 flags)
void popup_worklist_editor(struct city *pcity, struct global_worklist *gwl)
Definition wldlg.c:1061
option_dialog_mode
Definition optiondlg.c:68
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_error(message,...)
Definition log.h:104
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
const struct strvec * option_str_values(const struct option *poption)
Definition options.c:951
const struct option_set * server_optset
Definition options.c:4278
const char * option_description(const struct option *poption)
Definition options.c:674
const char * option_help_text(const struct option *poption)
Definition options.c:684
const char * option_enum_get_str(const struct option *poption)
Definition options.c:1028
int option_number(const struct option *poption)
Definition options.c:654
int option_category(const struct option *poption)
Definition options.c:704
bool option_str_set(struct option *poption, const char *str)
Definition options.c:962
const struct option_set * client_optset
Definition options.c:1316
const char * option_name(const struct option *poption)
Definition options.c:664
int option_int_get(const struct option *poption)
Definition options.c:870
bool option_bool_set(struct option *poption, bool val)
Definition options.c:855
bool option_is_changeable(const struct option *poption)
Definition options.c:725
bool option_video_mode_set(struct option *poption, struct video_mode mode)
Definition options.c:1289
void option_set_gui_data(struct option *poption, void *data)
Definition options.c:803
const char * option_str_get(const struct option *poption)
Definition options.c:929
void * option_get_gui_data(const struct option *poption)
Definition options.c:813
const struct strvec * option_enum_values(const struct option *poption)
Definition options.c:1065
bool option_enum_set_int(struct option *poption, int val)
Definition options.c:1076
bool option_bool_get(const struct option *poption)
Definition options.c:833
int optset_category_number(const struct option_set *poptset)
Definition options.c:493
enum option_type option_type(const struct option *poption)
Definition options.c:694
bool video_mode_to_string(char *buf, size_t buf_len, struct video_mode *mode)
Definition options.c:6752
const struct option_set * option_optset(const struct option *poption)
Definition options.c:644
struct video_mode option_video_mode_get(const struct option *poption)
Definition options.c:1264
const char * optset_category_name(const struct option_set *poptset, int category)
Definition options.c:503
bool option_font_set(struct option *poption, const char *font)
Definition options.c:1210
void options_save(option_save_log_callback log_cb)
Definition options.c:6340
bool string_to_video_mode(const char *buf, struct video_mode *mode)
Definition options.c:6760
const char * option_font_get(const struct option *poption)
Definition options.c:1177
bool option_int_set(struct option *poption, int val)
Definition options.c:914
#define options_iterate(poptset, poption)
Definition options.h:587
#define options_iterate_end
Definition options.h:592
int len
Definition packhand.c:127
bool str_to_int(const char *str, int *pint)
Definition shared.c:515
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
void strvec_destroy(struct strvec *psv)
bool strvec_set(struct strvec *psv, size_t svindex, const char *string)
void strvec_append(struct strvec *psv, const char *string)
void strvec_reserve(struct strvec *psv, size_t reserve)
const char * strvec_get(const struct strvec *psv, size_t svindex)
struct strvec * strvec_new(void)
size_t strvec_size(const struct strvec *psv)
struct widget * begin_active_widget_list
Definition widget.h:184
struct widget * end_widget_list
Definition widget.h:182
struct widget * end_active_widget_list
Definition widget.h:185
struct widget * active_widget_list
Definition widget.h:186
struct scroll_bar * scroll
Definition widget.h:187
struct widget * begin_widget_list
Definition widget.h:181
struct connection conn
Definition client_main.h:96
bool established
Definition connection.h:140
const struct option_set * poptset
Definition optiondlg.c:79
struct widget * widget_list
Definition optiondlg.c:80
struct widget * edited_name
Definition optiondlg.c:85
struct option_dialog_optset optset
Definition optiondlg.c:96
enum option_dialog_mode mode
Definition optiondlg.c:94
struct widget * main_widget_list
Definition optiondlg.c:91
struct option_dialog_worklist worklist
Definition optiondlg.c:97
struct widget * core_widget_list
Definition optiondlg.c:90
struct advanced_dialog * advanced
Definition optiondlg.c:93
struct widget * begin_widget_list
Definition optiondlg.c:92
const struct option_set * poptset
Definition optiondlg.c:42
struct widget * end_widget_list
Definition optiondlg.c:89
struct widget * up_left_button
struct gui_layer * gui
Definition graphics.h:215
SDL_Event event
Definition graphics.h:217
Uint8 style
Definition gui_string.h:53
char * text
Definition gui_string.h:60
int width
Definition options.h:47
SDL_Keycode key
Definition widget.h:153
SDL_Surface * theme
Definition widget.h:118
struct widget * widget
Definition widget.h:132
union widget::@223 data
struct widget * prev
Definition widget.h:114
struct gui_layer * dst
Definition widget.h:116
utf8_str * string_utf8
Definition widget.h:121
const struct strvec * vector
Definition widget.h:126
int(* action)(struct widget *)
Definition widget.h:157
SDL_Rect area
Definition widget.h:149
SDL_Surface * gfx
Definition widget.h:120
struct widget * next
Definition widget.h:113
void(* destroy)(struct widget *pwidget)
Definition widget.h:170
utf8_str * info_label
Definition widget.h:122
Uint16 id
Definition widget.h:155
SDL_Rect size
Definition widget.h:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
int fc_break_lines(char *str, size_t desired_len)
Definition support.c:1135
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void set_client_page(enum client_pages page)