Freeciv-3.3
Loading...
Searching...
No Matches
cma_fe.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2001 - R. Falke, M. Kaufman
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#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* SDL3 */
19#include <SDL3/SDL.h>
20
21/* utility */
22#include "fcintl.h"
23
24/* common */
25#include "game.h"
26
27/* client */
28#include "client_main.h" /* can_client_issue_orders() */
29
30/* gui-sdl3 */
31#include "citydlg.h"
32#include "cityrep.h"
33#include "cma_fec.h"
34#include "colors.h"
35#include "graphics.h"
36#include "gui_id.h"
37#include "gui_main.h"
38#include "gui_tilespec.h"
39#include "mapview.h"
40#include "sprite.h"
41#include "themespec.h"
42#include "widget.h"
43
44#include "cma_fe.h"
45
46struct hmove {
47 struct widget *pscroll_bar;
48 int min, max, base;
49};
50
51static struct cma_dialog {
52 struct city *pcity;
53 struct small_dialog *dlg;
54 struct advanced_dialog *adv;
56} *cma = NULL;
57
61
62static void set_cma_hscrollbars(void);
63
64/* =================================================================== */
65
66/**********************************************************************/
69static int cma_dlg_callback(struct widget *pwindow)
70{
71 return -1;
72}
73
74/**********************************************************************/
77static int exit_cma_dialog_callback(struct widget *pwidget)
78{
82 }
83
84 return -1;
85}
86
87/**********************************************************************/
95
96/**********************************************************************/
100 void *data)
101{
102 struct hmove *motion = (struct hmove *)data;
103 char cbuf[4];
104
106
107 if (motion && motion_event->xrel
108 && (motion_event->x >= motion->min) && (motion_event->x <= motion->max)) {
109 /* draw bcgd */
110 widget_undraw(motion->pscroll_bar);
111 widget_mark_dirty(motion->pscroll_bar);
112
113 if ((motion->pscroll_bar->size.x + motion_event->xrel) >
114 (motion->max - motion->pscroll_bar->size.w)) {
115 motion->pscroll_bar->size.x = motion->max - motion->pscroll_bar->size.w;
116 } else {
117 if ((motion->pscroll_bar->size.x + motion_event->xrel) < motion->min) {
118 motion->pscroll_bar->size.x = motion->min;
119 } else {
120 motion->pscroll_bar->size.x += motion_event->xrel;
121 }
122 }
123
124 *(int *)motion->pscroll_bar->data.ptr =
125 motion->base + (motion->pscroll_bar->size.x - motion->min);
126
127 fc_snprintf(cbuf, sizeof(cbuf), "%d",
128 *(int *)motion->pscroll_bar->data.ptr);
129 copy_chars_to_utf8_str(motion->pscroll_bar->next->string_utf8, cbuf);
130
131 /* redraw label */
132 widget_redraw(motion->pscroll_bar->next);
133 widget_mark_dirty(motion->pscroll_bar->next);
134
135 /* redraw scrollbar */
136 if (get_wflags(motion->pscroll_bar) & WF_RESTORE_BACKGROUND) {
137 refresh_widget_background(motion->pscroll_bar);
138 }
139 widget_redraw(motion->pscroll_bar);
140 widget_mark_dirty(motion->pscroll_bar);
141
142 flush_dirty();
143 }
144
145 return ID_ERROR;
146}
147
148/**********************************************************************/
151static int min_horiz_cma_callback(struct widget *pwidget)
152{
154 struct hmove motion;
155
156 motion.pscroll_bar = pwidget;
157 motion.min = pwidget->next->size.x + pwidget->next->size.w + 5;
158 motion.max = motion.min + 70;
159 motion.base = -20;
160
161 MOVE_STEP_X = 2;
162 MOVE_STEP_Y = 0;
163 /* Filter mouse motion events */
165 gui_event_loop((void *)(&motion), NULL, NULL, NULL, NULL, NULL, NULL,
166 NULL, NULL,
168 /* Turn off Filter mouse motion events */
172
173 selected_widget = pwidget;
174 set_wstate(pwidget, FC_WS_SELECTED);
175 /* save the change */
177 /* refreshes the cma */
181 }
183 }
184
185 return -1;
186}
187
188/**********************************************************************/
191static int factor_horiz_cma_callback(struct widget *pwidget)
192{
194 struct hmove motion;
195
196 motion.pscroll_bar = pwidget;
197 motion.min = pwidget->next->size.x + pwidget->next->size.w + 5;
198 motion.max = motion.min + 54;
199 motion.base = 1;
200
201 MOVE_STEP_X = 2;
202 MOVE_STEP_Y = 0;
203 /* Filter mouse motion events */
205 gui_event_loop((void *)(&motion), NULL, NULL, NULL, NULL, NULL, NULL,
206 NULL, NULL,
208 /* Turn off Filter mouse motion events */
212
213 selected_widget = pwidget;
214 set_wstate(pwidget, FC_WS_SELECTED);
215 /* save the change */
217 /* refreshes the cma */
221 }
223 }
224
225 return -1;
226}
227
228/**********************************************************************/
231static int toggle_cma_celebrating_callback(struct widget *pwidget)
232{
235 /* save the change */
238 }
239
240 return -1;
241}
242
243/* ============================================================= */
244
245/**********************************************************************/
248static int save_cma_window_callback(struct widget *pwindow)
249{
250 return -1;
251}
252
253/**********************************************************************/
256static int ok_save_cma_callback(struct widget *pwidget)
257{
259 if (pwidget && cma && cma->adv) {
260 struct widget *pedit = (struct widget *)pwidget->data.ptr;
261
262 if (pedit->string_utf8->text != NULL) {
264 } else {
265 cmafec_preset_add(_("new preset"), &cma->edited_cm_parm);
266 }
267
270 FC_FREE(cma->adv);
271
273 }
274 }
275
276 return -1;
277}
278
279/**********************************************************************/
282static int cancel_sld_cma_callback(struct widget *pwidget)
283{
285 if (cma && cma->adv) {
289 FC_FREE(cma->adv);
290 flush_dirty();
291 }
292 }
293
294 return -1;
295}
296
297/**********************************************************************/
300static int save_cma_callback(struct widget *pwidget)
301{
303 struct widget *buf, *pwindow;
304 utf8_str *pstr;
305 SDL_Surface *text;
308
309 if (cma->adv) {
310 return 1;
311 }
312
313 cma->adv = fc_calloc(1, sizeof(struct advanced_dialog));
314
315 pstr = create_utf8_from_char_fonto(_("Name new preset"),
317 pstr->style |= TTF_STYLE_BOLD;
318
319 pwindow = create_window_skeleton(NULL, pstr, 0);
320
322 set_wstate(pwindow, FC_WS_NORMAL);
323 cma->adv->end_widget_list = pwindow;
324
325 add_to_gui_list(ID_WINDOW, pwindow);
326
327 area = pwindow->area;
328 area.h = MAX(area.h, 1);
329
330 /* ============================================================= */
331 /* Label */
332 pstr = create_utf8_from_char_fonto(_("What should we name the preset?"),
334 pstr->style |= (TTF_STYLE_BOLD|SF_CENTER);
336
339 area.w = MAX(area.w, text->w);
340 area.h += text->h + adj_size(5);
341 /* ============================================================= */
342
343 buf = create_edit(NULL, pwindow->dst,
344 create_utf8_from_char_fonto(_("new preset"),
346 adj_size(100),
349 area.h += buf->size.h;
350 area.w = MAX(area.w, buf->size.w);
351
353 /* ============================================================= */
354
356 pwindow->dst,
357 _("Yes"),
358 FONTO_ATTENTION, 0);
359
360 buf->action = ok_save_cma_callback;
362 buf->key = SDLK_RETURN;
364 buf->data.ptr = (void *)buf->next;
365
367 pwindow->dst, _("No"),
368 FONTO_ATTENTION, 0);
371 buf->key = SDLK_ESCAPE;
372
374
375 area.h += buf->size.h;
376 buf->size.w = MAX(buf->next->size.w, buf->size.w);
377 buf->next->size.w = buf->size.w;
378 area.w = MAX(area.w, 2 * buf->size.w + adj_size(20));
379
381
382 /* setup window size and start position */
383 area.w += adj_size(20);
384 area.h += adj_size(15);
385
387 (pwindow->size.w - pwindow->area.w) + area.w,
388 (pwindow->size.h - pwindow->area.h) + area.h);
389
390 area = pwindow->area;
391
392 widget_set_position(pwindow,
393 pwidget->size.x - pwindow->size.w / 2,
394 pwidget->size.y - pwindow->size.h);
395
396 /* setup rest of widgets */
397 /* label */
398 dst.x = area.x + (area.w - text->w) / 2;
399 dst.y = area.y + 1;
400 alphablit(text, NULL, pwindow->theme, &dst, 255);
401 dst.y += text->h + adj_size(5);
402 FREESURFACE(text);
403
404 /* edit */
405 buf = pwindow->prev;
406 buf->size.w = area.w - adj_size(10);
407 buf->size.x = area.x + adj_size(5);
408 buf->size.y = dst.y;
409 dst.y += buf->size.h + adj_size(5);
410
411 /* yes */
412 buf = buf->prev;
413 buf->size.x = area.x + (area.w - (2 * buf->size.w + adj_size(20))) / 2;
414 buf->size.y = dst.y;
415
416 /* no */
417 buf = buf->prev;
418 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(20);
419 buf->size.y = buf->next->size.y;
420
421 /* ================================================== */
422 /* redraw */
423 redraw_group(cma->adv->begin_widget_list, pwindow, 0);
424 widget_mark_dirty(pwindow);
425 flush_dirty();
426 }
427
428 return -1;
429}
430
431/* ================================================== */
432
433/**********************************************************************/
436static int ld_cma_callback(struct widget *pwidget)
437{
439 bool load = pwidget->data.ptr != NULL;
440 int index = MAX_ID - pwidget->id;
441
445 FC_FREE(cma->adv);
446
447 if (load) {
451 /* save the change */
453 /* stop the cma */
456 }
457 } else {
459 }
460
462 }
463
464 return -1;
465}
466
467/**********************************************************************/
470static void popup_load_del_presets_dialog(bool load, struct widget *button)
471{
472 int hh, count, i;
473 struct widget *buf, *pwindow;
474 utf8_str *pstr;
476
477 if (cma->adv) {
478 return;
479 }
480
481 count = cmafec_preset_num();
482
483 if (count == 1) {
484 if (load) {
487 /* save the change */
489 /* stop the cma */
492 }
493 } else {
495 }
497 return;
498 }
499
500 cma->adv = fc_calloc(1, sizeof(struct advanced_dialog));
501
503 pstr->style |= TTF_STYLE_BOLD;
504
505 pwindow = create_window_skeleton(NULL, pstr, 0);
506
508 set_wstate(pwindow, FC_WS_NORMAL);
509 cma->adv->end_widget_list = pwindow;
510
511 add_to_gui_list(ID_WINDOW, pwindow);
512
513 area = pwindow->area;
514
515 /* ---------- */
516 /* Create exit button */
517 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
519 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
523 buf->key = SDLK_ESCAPE;
524 area.w += (buf->size.w + adj_size(10));
525
527 /* ---------- */
528
529 for (i = 0; i < count; i++) {
531 pstr->style |= TTF_STYLE_BOLD;
532 buf = create_iconlabel(NULL, pwindow->dst, pstr,
534 buf->string_utf8->bgcol = (SDL_Color) {0, 0, 0, 0};
535 buf->action = ld_cma_callback;
536
537 area.w = MAX(area.w, buf->size.w);
538 area.h += buf->size.h;
540
541 if (load) {
542 buf->data.ptr = (void *)1;
543 } else {
544 buf->data.ptr = NULL;
545 }
546
548
549 if (i > 10) {
551 }
552 }
555 cma->adv->end_active_widget_list = pwindow->prev->prev;
557
558 area.w += adj_size(2);
559 area.h += 1;
560
561 if (count > 11) {
563
564 /* ------- window ------- */
565 area.h = 11 * pwindow->prev->prev->size.h + adj_size(2)
566 + 2 * cma->adv->scroll->up_left_button->size.h;
569 }
570
571 /* ----------------------------------- */
572
573 resize_window(pwindow, NULL, NULL,
574 (pwindow->size.w - pwindow->area.w) + area.w,
575 (pwindow->size.h - pwindow->area.h) + area.h);
576
577 area = pwindow->area;
578
579 widget_set_position(pwindow,
580 button->size.x - (pwindow->size.w / 2),
581 button->size.y - pwindow->size.h);
582
583 /* exit button */
584 buf = pwindow->prev;
585 buf->size.x = area.x + area.w - buf->size.w - 1;
586 buf->size.y = pwindow->size.y + adj_size(2);
587
588 buf = buf->prev;
589 hh = (cma->adv->scroll ? cma->adv->scroll->up_left_button->size.h + 1 : 0);
591 area.y + 1 + hh, area.w - 1, 0,
593
594 if (cma->adv->scroll) {
600 }
601
602 /* ==================================================== */
603 /* redraw */
604 redraw_group(cma->adv->begin_widget_list, pwindow, 0);
605
606 widget_flush(pwindow);
607}
608
609/**********************************************************************/
612static int load_cma_callback(struct widget *pwidget)
613{
616 }
617
618 return -1;
619}
620
621/**********************************************************************/
624static int del_cma_callback(struct widget *pwidget)
625{
628 }
629
630 return -1;
631}
632
633/* ================================================== */
634
635/**********************************************************************/
639static int run_cma_callback(struct widget *pwidget)
640{
644 }
645
646 return -1;
647}
648
649/**********************************************************************/
652static int run_cma_once_callback(struct widget *pwidget)
653{
655 struct cm_result *result;
656
658 /* fill in result label */
659 result = cm_result_new(cma->pcity);
661 cma_apply_result(cma->pcity, result);
662 cm_result_destroy(result);
663 }
664
665 return -1;
666}
667
668/**********************************************************************/
671static int stop_cma_callback(struct widget *pwidget)
672{
676 }
677
678 return -1;
679}
680
681/* ===================================================================== */
682
683/**********************************************************************/
686static void set_cma_hscrollbars(void)
687{
688 struct widget *pbuf;
689 char cbuf[4];
690
691 if (!cma) {
692 return;
693 }
694
695 /* exit button */
698 /* min label */
699 pbuf = pbuf->prev;
700 fc_snprintf(cbuf, sizeof(cbuf), "%d", *(int *)pbuf->prev->data.ptr);
701 copy_chars_to_utf8_str(pbuf->string_utf8, cbuf);
702
703 /* min scrollbar */
704 pbuf = pbuf->prev;
705 pbuf->size.x = pbuf->next->size.x
706 + pbuf->next->size.w + adj_size(5) + adj_size(20) + *(int *)pbuf->data.ptr;
707
708 /* factor label */
709 pbuf = pbuf->prev;
710 fc_snprintf(cbuf, sizeof(cbuf), "%d", *(int *)pbuf->prev->data.ptr);
711 copy_chars_to_utf8_str(pbuf->string_utf8, cbuf);
712
713 /* factor scrollbar*/
714 pbuf = pbuf->prev;
715 pbuf->size.x = pbuf->next->size.x
716 + pbuf->next->size.w + adj_size(5) + *(int *)pbuf->data.ptr - 1;
718
719 /* happy factor label */
720 pbuf = pbuf->prev;
721 fc_snprintf(cbuf, sizeof(cbuf), "%d", *(int *)pbuf->prev->data.ptr);
722 copy_chars_to_utf8_str(pbuf->string_utf8, cbuf);
723
724 /* happy factor scrollbar */
725 pbuf = pbuf->prev;
726 pbuf->size.x = pbuf->next->size.x
727 + pbuf->next->size.w + adj_size(5) + *(int *)pbuf->data.ptr - 1;
728}
729
730/**********************************************************************/
734{
735 SDL_Color bg_color = {255, 255, 255, 136};
736 int count, step, i;
737 struct widget *buf = cma->dlg->end_widget_list; /* pwindow */
738 SDL_Surface *text;
739 utf8_str *pstr;
744 struct cm_result *result = cm_result_new(cma->pcity);
745
746 /* redraw window background and exit button */
747 redraw_group(buf->prev, buf, 0);
748
749 /* fill in result label */
751
752 if (result->found_a_valid) {
753 /* redraw Citizens */
754 count = city_size_get(cma->pcity);
755
757 step = (buf->size.w - adj_size(20)) / text->w;
758 if (count > step) {
759 step = (buf->size.w - adj_size(20) - text->w) / (count - 1);
760 } else {
761 step = text->w;
762 }
763
764 dst.y = buf->area.y + adj_size(4);
765 dst.x = buf->area.x + adj_size(7);
766
767 for (i = 0;
768 i < count - (result->specialists[SP_ELVIS]
769 + result->specialists[SP_SCIENTIST]
770 + result->specialists[SP_TAXMAN]); i++) {
772 alphablit(text, NULL, buf->dst->surface, &dst, 255);
773 dst.x += step;
774 }
775
777 for (i = 0; i < result->specialists[SP_ELVIS]; i++) {
778 alphablit(text, NULL, buf->dst->surface, &dst, 255);
779 dst.x += step;
780 }
781
782 text = get_tax_surface(O_GOLD);
783 for (i = 0; i < result->specialists[SP_TAXMAN]; i++) {
784 alphablit(text, NULL, buf->dst->surface, &dst, 255);
785 dst.x += step;
786 }
787
789 for (i = 0; i < result->specialists[SP_SCIENTIST]; i++) {
790 alphablit(text, NULL, buf->dst->surface, &dst, 255);
791 dst.x += step;
792 }
793 }
794
795 /* Create result text surface */
799
802
803 /* Fill result text background */
804 dst.x = buf->area.x + adj_size(7);
805 dst.y = buf->area.y + adj_size(186);
806 dst.w = text->w + adj_size(10);
807 dst.h = text->h + adj_size(10);
808 fill_rect_alpha(buf->dst->surface, &dst, &bg_color);
809
810 create_frame(buf->dst->surface,
811 dst.x, dst.y, dst.x + dst.w - 1, dst.y + dst.h - 1,
813
814 dst.x += adj_size(5);
815 dst.y += adj_size(5);
816 alphablit(text, NULL, buf->dst->surface, &dst, 255);
817 FREESURFACE(text);
818
819 /* Happy factor scrollbar */
823 } else {
825 }
826
827 /* Save as ... */
828 buf = buf->prev->prev;
831 } else {
833 }
834
835 /* Load */
836 buf = buf->prev;
839 } else {
841 }
842
843 /* Del */
844 buf = buf->prev;
847 } else {
849 }
850
851 /* Run */
852 buf = buf->prev;
853 if (client_under_control && result->found_a_valid && !controlled) {
855 } else {
857 }
858
859 /* Run once */
860 buf = buf->prev;
861 if (client_under_control && result->found_a_valid && !controlled) {
863 } else {
865 }
866
867 /* Stop */
868 buf = buf->prev;
871 } else {
873 }
874
875 /* redraw rest widgets */
878
880
881 cm_result_destroy(result);
882}
883
884/**********************************************************************/
888{
889 SDL_Color bg_color = {255, 255, 255, 136};
890
891 struct widget *pwindow, *buf;
892 SDL_Surface *logo, *text[O_LAST + 1], *minimal, *factor;
894 utf8_str *pstr;
895 char cbuf[128];
896 int w, text_w, x, cs;
898
899 if (cma) {
900 return;
901 }
902
903 cma = fc_calloc(1, sizeof(struct cma_dialog));
904 cma->pcity = pcity;
905 cma->dlg = fc_calloc(1, sizeof(struct small_dialog));
906 cma->adv = NULL;
908
910
911 /* --------------------------- */
912
913 fc_snprintf(cbuf, sizeof(cbuf),
914 _("City of %s (Population %s citizens) : %s"),
917 _("Citizen Governor"));
918
920 pstr->style |= TTF_STYLE_BOLD;
921
922 pwindow = create_window_skeleton(NULL, pstr, 0);
923
924 pwindow->action = cma_dlg_callback;
925 set_wstate(pwindow, FC_WS_NORMAL);
926 add_to_gui_list(ID_WINDOW, pwindow);
927 cma->dlg->end_widget_list = pwindow;
928
929 area = pwindow->area;
930
931 /* ---------- */
932 /* Create exit button */
933 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
935 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
939 buf->key = SDLK_ESCAPE;
940 area.w += (buf->size.w + adj_size(10));
941
943
945 text_w = 0;
946
947 copy_chars_to_utf8_str(pstr, _("Minimal Surplus"));
949
950 copy_chars_to_utf8_str(pstr, _("Factor"));
952
953 /* ---------- */
957 text_w = MAX(text_w, text[i]->w);
958
959 /* Minimal label */
960 buf = create_iconlabel(NULL, pwindow->dst,
963
965
966 /* Minimal scrollbar */
967 buf = create_horizontal(current_theme->horiz, pwindow->dst, adj_size(30),
969
970 buf->action = min_horiz_cma_callback;
971 buf->data.ptr = &cma->edited_cm_parm.minimal_surplus[i];
972
974
976
977 /* Factor label */
978 buf = create_iconlabel(NULL, pwindow->dst,
981
983
984 /* Factor scrollbar */
985 buf = create_horizontal(current_theme->horiz, pwindow->dst, adj_size(30),
987
989 buf->data.ptr = &cma->edited_cm_parm.factor[i];
990
992
995
996 copy_chars_to_utf8_str(pstr, _("Celebrate"));
999
1000 /* Happy factor label */
1001 buf = create_iconlabel(NULL, pwindow->dst,
1004
1006
1007 /* Happy factor scrollbar */
1008 buf = create_horizontal(current_theme->horiz, pwindow->dst, adj_size(30),
1010
1012 buf->data.ptr = &cma->edited_cm_parm.happy_factor;
1013
1015
1017
1018 /* celebrating */
1019 buf = create_checkbox(pwindow->dst,
1022
1026
1027 /* Save as ... */
1028 buf = create_themeicon(current_theme->save_icon, pwindow->dst,
1030 buf->action = save_cma_callback;
1031 buf->info_label = create_utf8_from_char_fonto(_("Save settings as..."),
1033
1035
1036 /* Load settings */
1037 buf = create_themeicon(current_theme->load_icon, pwindow->dst,
1039 buf->action = load_cma_callback;
1040 buf->info_label = create_utf8_from_char_fonto(_("Load settings"),
1042
1044
1045 /* Del settings */
1046 buf = create_themeicon(current_theme->delete_icon, pwindow->dst,
1048 buf->action = del_cma_callback;
1049 buf->info_label = create_utf8_from_char_fonto(_("Delete settings"),
1051
1053
1054 /* Run cma */
1055 buf = create_themeicon(current_theme->qprod_icon, pwindow->dst,
1057 buf->action = run_cma_callback;
1058 buf->info_label = create_utf8_from_char_fonto(_("Control city"), FONTO_DEFAULT);
1059
1061
1062 /* Run cma once */
1063 buf = create_themeicon(current_theme->find_city_icon, pwindow->dst,
1065 buf->action = run_cma_once_callback;
1066 buf->info_label = create_utf8_from_char_fonto(_("Apply once"), FONTO_DEFAULT);
1067
1069
1070 /* Del settings */
1071 buf = create_themeicon(current_theme->support_icon, pwindow->dst,
1073 buf->action = stop_cma_callback;
1074 buf->info_label = create_utf8_from_char_fonto(_("Release city"), FONTO_DEFAULT);
1075
1077
1078 /* -------------------------------- */
1080
1081#ifdef GUI_SDL3_SMALL_SCREEN
1082 area.w = MAX(pcity_map->w + adj_size(220) + text_w + adj_size(10) +
1083 (pwindow->prev->prev->size.w + adj_size(5 + 70 + 5) +
1084 pwindow->prev->prev->size.w + adj_size(5 + 55 + 15)), area.w);
1085 area.h = adj_size(390) - (pwindow->size.w - pwindow->area.w);
1086#else /* GUI_SDL3_SMALL_SCREEN */
1087 area.w = MAX(pcity_map->w + adj_size(150) + text_w + adj_size(10) +
1088 (pwindow->prev->prev->size.w + adj_size(5 + 70 + 5) +
1089 pwindow->prev->prev->size.w + adj_size(5 + 55 + 15)), area.w);
1090 area.h = adj_size(360) - (pwindow->size.w - pwindow->area.w);
1091#endif /* GUI_SDL3_SMALL_SCREEN */
1092
1094 if (resize_window(pwindow, logo, NULL,
1095 (pwindow->size.w - pwindow->area.w) + area.w,
1096 (pwindow->size.w - pwindow->area.w) + area.h)) {
1098 }
1099
1100#if 0
1101 logo = SDL_DisplayFormat(pwindow->theme);
1102 FREESURFACE(pwindow->theme);
1103 pwindow->theme = logo;
1104#endif /* 0 */
1105
1106 area = pwindow->area;
1107
1108 widget_set_position(pwindow,
1109 (main_window_width() - pwindow->size.w) / 2,
1110 (main_window_height() - pwindow->size.h) / 2);
1111
1112 /* exit button */
1113 buf = pwindow->prev;
1114 buf->size.x = area.x + area.w - buf->size.w - 1;
1115 buf->size.y = pwindow->size.y + adj_size(2);
1116
1117 /* ---------- */
1118 dst.x = pcity_map->w + adj_size(80) +
1119 (pwindow->size.w - (pcity_map->w + adj_size(40)) -
1120 (text_w + adj_size(10) + pwindow->prev->prev->size.w + adj_size(5 + 70 + 5) +
1121 pwindow->prev->prev->size.w + adj_size(5 + 55))) / 2;
1122
1123#ifdef GUI_SDL3_SMALL_SCREEN
1124 dst.x += 22;
1125#endif
1126
1127 dst.y = adj_size(75);
1128
1129 x = area.x = dst.x - adj_size(10);
1130 area.y = dst.y - adj_size(20);
1131 w = area.w = adj_size(10) + text_w + adj_size(10) + pwindow->prev->prev->size.w + adj_size(5 + 70 + 5)
1132 + pwindow->prev->prev->size.w + adj_size(5 + 55 + 10);
1133 area.h = (O_LAST + 1) * (text[0]->h + adj_size(6)) + adj_size(20);
1134 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1135
1136 create_frame(pwindow->theme,
1137 area.x, area.y, area.w - 1, area.h - 1,
1139
1140 area.x = dst.x + text_w + adj_size(10);
1141 alphablit(minimal, NULL, pwindow->theme, &area, 255);
1142 area.x += minimal->w + adj_size(10);
1144
1145 alphablit(factor, NULL, pwindow->theme, &area, 255);
1146 FREESURFACE(factor);
1147
1148 area.x = pwindow->area.x + adj_size(22);
1149 area.y = pwindow->area.y + adj_size(31);
1150 alphablit(pcity_map, NULL, pwindow->theme, &area, 255);
1152
1154 /* min label */
1155 buf = buf->prev;
1156 buf->size.x = pwindow->size.x + dst.x + text_w + adj_size(10);
1157 buf->size.y = pwindow->size.y + dst.y + (text[i]->h - buf->size.h) / 2;
1158
1159 /* min sb */
1160 buf = buf->prev;
1161 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(5);
1162 buf->size.y = pwindow->size.y + dst.y + (text[i]->h - buf->size.h) / 2;
1163
1164 area.x = buf->size.x - pwindow->size.x - adj_size(2);
1165 area.y = buf->size.y - pwindow->size.y;
1166 area.w = adj_size(74);
1167 area.h = buf->size.h;
1168 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1169
1170 create_frame(pwindow->theme,
1171 area.x, area.y, area.w - 1, area.h - 1,
1173
1174 /* factor label */
1175 buf = buf->prev;
1176 buf->size.x = buf->next->size.x + adj_size(75);
1177 buf->size.y = pwindow->size.y + dst.y + (text[i]->h - buf->size.h) / 2;
1178
1179 /* factor sb */
1180 buf = buf->prev;
1181 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(5);
1182 buf->size.y = pwindow->size.y + dst.y + (text[i]->h - buf->size.h) / 2;
1183
1184 area.x = buf->size.x - pwindow->size.x - adj_size(2);
1185 area.y = buf->size.y - pwindow->size.y;
1186 area.w = adj_size(58);
1187 area.h = buf->size.h;
1188 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1189
1190 create_frame(pwindow->theme,
1191 area.x, area.y, area.w - 1, area.h - 1,
1193
1194 alphablit(text[i], NULL, pwindow->theme, &dst, 255);
1195 dst.y += text[i]->h + adj_size(6);
1196 FREESURFACE(text[i]);
1198
1199 /* happy factor label */
1200 buf = buf->prev;
1201 buf->size.x = buf->next->next->size.x;
1202 buf->size.y = pwindow->size.y + dst.y + (text[O_LAST]->h - buf->size.h) / 2;
1203
1204 /* happy factor sb */
1205 buf = buf->prev;
1206 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(5);
1207 buf->size.y = pwindow->size.y + dst.y + (text[O_LAST]->h - buf->size.h) / 2;
1208
1209 area.x = buf->size.x - pwindow->size.x - adj_size(2);
1210 area.y = buf->size.y - pwindow->size.y;
1211 area.w = adj_size(58);
1212 area.h = buf->size.h;
1213 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1214
1215 create_frame(pwindow->theme,
1216 area.x, area.y, area.w - 1, area.h - 1,
1218
1219 /* Celebrate cbox */
1220 buf = buf->prev;
1221 buf->size.x = pwindow->size.x + dst.x + adj_size(10);
1222 buf->size.y = pwindow->size.y + dst.y;
1223
1224 /* Celebrate static text */
1225 dst.x += (adj_size(10) + buf->size.w + adj_size(5));
1226 dst.y += (buf->size.h - text[O_LAST]->h) / 2;
1227 alphablit(text[O_LAST], NULL, pwindow->theme, &dst, 255);
1228 FREESURFACE(text[O_LAST]);
1229 /* ------------------------ */
1230
1231 /* Save as */
1232 buf = buf->prev;
1233 buf->size.x = pwindow->size.x + x + (w - (buf->size.w + adj_size(6)) * 6) / 2;
1234 buf->size.y = pwindow->size.y + pwindow->size.h - buf->size.h * 2 - adj_size(10);
1235
1236 area.x = x;
1237 area.y = buf->size.y - pwindow->size.y - adj_size(5);
1238 area.w = w;
1239 area.h = buf->size.h + adj_size(10);
1240 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1241
1242 create_frame(pwindow->theme,
1243 area.x, area.y, area.w - 1, area.h - 1,
1245
1246 /* Load */
1247 buf = buf->prev;
1248 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1249 buf->size.y = buf->next->size.y;
1250
1251 /* Del */
1252 buf = buf->prev;
1253 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1254 buf->size.y = buf->next->size.y;
1255
1256 /* Run */
1257 buf = buf->prev;
1258 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1259 buf->size.y = buf->next->size.y;
1260
1261 /* Run one time */
1262 buf = buf->prev;
1263 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1264 buf->size.y = buf->next->size.y;
1265
1266 /* Del */
1267 buf = buf->prev;
1268 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1269 buf->size.y = buf->next->size.y;
1270
1271 /* ------------------------ */
1272 /* Check if Citizen Icons style was loaded */
1274
1275 if (cs != icons->style) {
1277 }
1278
1281}
1282
1283/**********************************************************************/
1287{
1288 if (cma) {
1291 FC_FREE(cma->dlg);
1292 if (cma->adv) {
1295 FC_FREE(cma->adv->scroll);
1296 FC_FREE(cma->adv);
1297 }
1299 /* enable city dlg */
1302 }
1303
1305 FC_FREE(cma);
1306 }
1307}
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
int city_population(const struct city *pcity)
Definition city.c:1191
const char * get_output_name(Output_type_id output)
Definition city.c:629
static citizens city_size_get(const struct city *pcity)
Definition city.h:566
@ CITIZEN_CONTENT
Definition city.h:266
#define output_type_iterate(output)
Definition city.h:842
#define output_type_iterate_end
Definition city.h:848
void refresh_city_dialog(struct city *pcity)
void city_report_dialog_update(void)
bool can_client_issue_orders(void)
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2174
struct cm_result * cm_result_new(struct city *pcity)
Definition cm.c:345
void cm_result_from_main_map(struct cm_result *result, const struct city *pcity)
Definition cm.c:2261
void cm_result_destroy(struct cm_result *result)
Definition cm.c:368
void cm_query_result(struct city *pcity, const struct cm_parameter *param, struct cm_result *result, bool negative_ok)
Definition cm.c:2122
bool cma_is_city_under_agent(const struct city *pcity, struct cm_parameter *parameter)
Definition cma_core.c:552
void cma_put_city_under_agent(struct city *pcity, const struct cm_parameter *const parameter)
Definition cma_core.c:524
void cma_release_city(struct city *pcity)
Definition cma_core.c:542
bool cma_apply_result(struct city *pcity, const struct cm_result *result)
Definition cma_core.c:510
void cmafec_set_fe_parameter(struct city *pcity, const struct cm_parameter *const parameter)
Definition cma_fec.c:105
char * cmafec_preset_get_descr(int idx)
Definition cma_fec.c:169
const char * cmafec_get_result_descr(struct city *pcity, const struct cm_result *result, const struct cm_parameter *const parameter)
Definition cma_fec.c:322
const struct cm_parameter * cmafec_preset_get_parameter(int idx)
Definition cma_fec.c:182
void cmafec_preset_add(const char *descr_name, struct cm_parameter *pparam)
Definition cma_fec.c:136
void cmafec_preset_remove(int idx)
Definition cma_fec.c:153
int cmafec_preset_num(void)
Definition cma_fec.c:213
void cmafec_get_fe_parameter(struct city *pcity, struct cm_parameter *dest)
Definition cma_fec.c:115
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
QString current_theme
Definition fc_client.cpp:64
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
@ O_LAST
Definition fc_types.h:101
#define _(String)
Definition fcintl.h:67
const char * population_to_text(int thousand_citizen)
Definition game.c:739
bool city_dialog_is_open(struct city *pcity)
Definition citydlg.c:587
void flush_dirty(void)
Definition mapview.c:468
void enable_city_dlg_widgets(void)
Definition citydlg.c:1535
specialist_type
Definition citydlg.c:109
SDL_Surface * get_scaled_city_map(struct city *pcity)
Definition citydlg.c:1620
static int save_cma_callback(struct widget *pwidget)
Definition cma_fe.c:304
static int ld_cma_callback(struct widget *pwidget)
Definition cma_fe.c:440
static int load_cma_callback(struct widget *pwidget)
Definition cma_fe.c:616
static void set_cma_hscrollbars(void)
Definition cma_fe.c:690
static struct cma_dialog * cma
static int toggle_cma_celebrating_callback(struct widget *pwidget)
Definition cma_fe.c:235
static int save_cma_window_callback(struct widget *pwindow)
Definition cma_fe.c:252
static Uint16 scroll_mouse_button_up(SDL_MouseButtonEvent *button_event, void *data)
Definition cma_fe.c:94
static int exit_cma_dialog_callback(struct widget *pwidget)
Definition cma_fe.c:81
static int run_cma_once_callback(struct widget *pwidget)
Definition cma_fe.c:656
static int cma_dlg_callback(struct widget *pwindow)
Definition cma_fe.c:73
static int run_cma_callback(struct widget *pwidget)
Definition cma_fe.c:643
@ SP_SCIENTIST
Definition cma_fe.c:63
@ SP_LAST
Definition cma_fe.c:63
@ SP_ELVIS
Definition cma_fe.c:63
@ SP_TAXMAN
Definition cma_fe.c:63
static int min_horiz_cma_callback(struct widget *pwidget)
Definition cma_fe.c:155
void update_city_cma_dialog(void)
Definition cma_fe.c:737
static Uint16 scroll_mouse_motion_handler(SDL_MouseMotionEvent *motion_event, void *data)
Definition cma_fe.c:103
static int del_cma_callback(struct widget *pwidget)
Definition cma_fe.c:628
void popup_city_cma_dialog(struct city *pcity)
Definition cma_fe.c:891
void popdown_city_cma_dialog(void)
Definition cma_fe.c:1290
static int ok_save_cma_callback(struct widget *pwidget)
Definition cma_fe.c:260
static void popup_load_del_presets_dialog(bool load, struct widget *button)
Definition cma_fe.c:474
static int cancel_sld_cma_callback(struct widget *pwidget)
Definition cma_fe.c:286
static int stop_cma_callback(struct widget *pwidget)
Definition cma_fe.c:675
static int factor_horiz_cma_callback(struct widget *pwidget)
Definition cma_fe.c:195
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
int main_window_width(void)
Definition graphics.c:685
int fill_rect_alpha(SDL_Surface *surf, SDL_Rect *prect, SDL_Color *pcolor)
Definition graphics.c:865
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
struct sdl2_data main_data
Definition graphics.c:57
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 adj_surf(surf)
Definition graphics.h:200
@ ID_ERROR
Definition gui_id.h:26
@ ID_BUTTON
Definition gui_id.h:29
@ ID_EDIT
Definition gui_id.h:34
@ ID_SCROLLBAR
Definition gui_id.h:32
@ ID_ICON
Definition gui_id.h:33
@ ID_LABEL
Definition gui_id.h:27
@ ID_CHECKBOX
Definition gui_id.h:35
@ ID_WINDOW
Definition gui_id.h:30
int FilterMouseMotionEvents(void *data, SDL_Event *event)
Definition gui_main.c:582
Uint16 gui_event_loop(void *data, void(*loop_action)(void *data), Uint16(*key_down_handler)(SDL_Keysym key, void *data), Uint16(*key_up_handler)(SDL_Keysym key, void *data), Uint16(*textinput_handler)(const char *text, void *data), Uint16(*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*finger_motion_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event, void *data), Uint16(*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event, void *data), Uint16(*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event, void *data))
Definition gui_main.c:603
int MOVE_STEP_Y
Definition gui_main.c:106
int MOVE_STEP_X
Definition gui_main.c:105
struct widget * selected_widget
Definition widget.c:48
#define adj_size(size)
Definition gui_main.h:141
#define DEFAULT_MOVE_STEP
Definition gui_main.h:113
#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
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
utf8_str * create_utf8_str_fonto(char *in_text, size_t n_alloc, enum font_origin origin)
Definition gui_string.c:241
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
#define SF_CENTER
Definition gui_string.h:40
@ FONTO_DEFAULT
Definition gui_string.h:65
@ FONTO_ATTENTION
Definition gui_string.h:67
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
struct city_icon * icons
void reload_citizens_icons(int style)
static SDL_Surface * get_citizen_surface(enum citizen_category type, int citizen_index)
static SDL_Surface * get_tax_surface(Output_type_id otype)
SDL_Surface * theme_get_background(const struct theme *t, enum theme_background background)
@ BACKGROUND_CITYGOVDLG
@ COLOR_THEME_BACKGROUND
Definition themecolors.h:24
@ COLOR_THEME_CMA_FRAME
Definition themecolors.h:75
@ COLOR_THEME_CMA_TEXT
Definition themecolors.h:76
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
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
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
@ FC_WS_SELECTED
Definition widget.h:97
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
static void widget_undraw(struct widget *pwidget)
Definition widget.h:296
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
@ WF_FREE_STRING
Definition widget.h:76
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
@ WF_HIDDEN
Definition widget.h:68
@ WF_DRAW_TEXT_LABEL_WITH_SPACE
Definition widget.h:87
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
#define create_themeicon_button_from_chars_fonto(icon_theme, pdest, char_string, fonto, flags)
bool get_checkbox_state(struct widget *cbox)
struct widget * create_checkbox(struct gui_layer *pdest, bool state, Uint32 flags)
struct widget * create_edit(SDL_Surface *background, struct gui_layer *pdest, utf8_str *pstr, int length, Uint32 flags)
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
struct widget * create_iconlabel(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, Uint32 flags)
struct widget * create_horizontal(SDL_Surface *horiz_theme, struct gui_layer *pdest, Uint16 width, Uint32 flags)
Uint32 create_vertical_scrollbar(struct advanced_dialog *dlg, Uint8 step, Uint8 active, bool create_scrollbar, bool create_buttons)
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)
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define MAX(x, y)
Definition shared.h:54
int step
Definition specpq.h:92
struct sprite int x
Definition sprite_g.h:31
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
Definition city.h:317
int factor[O_LAST]
Definition cm.h:47
bool require_happy
Definition cm.h:43
int minimal_surplus[O_LAST]
Definition cm.h:41
int happy_factor
Definition cm.h:48
Definition cm.h:52
bool found_a_valid
Definition cm.h:54
citizens specialists[SP_MAX]
Definition cm.h:60
struct small_dialog * dlg
Definition cma_fe.c:57
struct advanced_dialog * adv
Definition cma_fe.c:58
struct cm_parameter edited_cm_parm
Definition cma_fe.c:59
struct city * pcity
Definition cma_fe.h:32
SDL_Rect dest_rect
Definition graphics.h:228
Definition cma_fe.c:50
int base
Definition cma_fe.c:52
int max
Definition cma_fe.c:52
int min
Definition cma_fe.c:52
struct widget * pscroll_bar
Definition cma_fe.c:51
struct widget * up_left_button
struct widget * down_right_button
SDL_Event event
Definition graphics.h:217
struct widget * begin_widget_list
Definition widget.h:175
struct widget * end_widget_list
Definition widget.h:176
char * text
Definition gui_string.h:60
void * ptr
Definition widget.h:133
SDL_Surface * theme
Definition widget.h:118
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
int(* action)(struct widget *)
Definition widget.h:157
SDL_Rect area
Definition widget.h:149
struct widget * next
Definition widget.h:113
Uint16 id
Definition widget.h:155
SDL_Rect size
Definition widget.h:145
int style_of_city(const struct city *pcity)
Definition style.c:202
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47