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/* SDL2 */
19#ifdef SDL2_PLAIN_INCLUDE
20#include <SDL.h>
21#else /* SDL2_PLAIN_INCLUDE */
22#include <SDL2/SDL.h>
23#endif /* SDL2_PLAIN_INCLUDE */
24
25/* utility */
26#include "fcintl.h"
27
28/* common */
29#include "game.h"
30
31/* client */
32#include "client_main.h" /* can_client_issue_orders() */
33
34/* gui-sdl2 */
35#include "citydlg.h"
36#include "cityrep.h"
37#include "cma_fec.h"
38#include "colors.h"
39#include "graphics.h"
40#include "gui_id.h"
41#include "gui_main.h"
42#include "gui_tilespec.h"
43#include "mapview.h"
44#include "sprite.h"
45#include "themespec.h"
46#include "widget.h"
47
48#include "cma_fe.h"
49
50struct hmove {
52 int min, max, base;
53};
54
55static struct cma_dialog {
56 struct city *pcity;
60} *cma = NULL;
61
65
66static void set_cma_hscrollbars(void);
67
68/* =================================================================== */
69
70/**********************************************************************/
73static int cma_dlg_callback(struct widget *pwindow)
74{
75 return -1;
76}
77
78/**********************************************************************/
81static int exit_cma_dialog_callback(struct widget *pwidget)
82{
86 }
87
88 return -1;
89}
90
91/**********************************************************************/
99
100/**********************************************************************/
104 void *data)
105{
106 struct hmove *motion = (struct hmove *)data;
107 char cbuf[4];
108
110
111 if (motion && motion_event->xrel
112 && (motion_event->x >= motion->min) && (motion_event->x <= motion->max)) {
113 /* draw bcgd */
114 widget_undraw(motion->pscroll_bar);
115 widget_mark_dirty(motion->pscroll_bar);
116
117 if ((motion->pscroll_bar->size.x + motion_event->xrel) >
118 (motion->max - motion->pscroll_bar->size.w)) {
119 motion->pscroll_bar->size.x = motion->max - motion->pscroll_bar->size.w;
120 } else {
121 if ((motion->pscroll_bar->size.x + motion_event->xrel) < motion->min) {
122 motion->pscroll_bar->size.x = motion->min;
123 } else {
124 motion->pscroll_bar->size.x += motion_event->xrel;
125 }
126 }
127
128 *(int *)motion->pscroll_bar->data.ptr =
129 motion->base + (motion->pscroll_bar->size.x - motion->min);
130
131 fc_snprintf(cbuf, sizeof(cbuf), "%d",
132 *(int *)motion->pscroll_bar->data.ptr);
133 copy_chars_to_utf8_str(motion->pscroll_bar->next->string_utf8, cbuf);
134
135 /* redraw label */
136 widget_redraw(motion->pscroll_bar->next);
137 widget_mark_dirty(motion->pscroll_bar->next);
138
139 /* redraw scrollbar */
140 if (get_wflags(motion->pscroll_bar) & WF_RESTORE_BACKGROUND) {
141 refresh_widget_background(motion->pscroll_bar);
142 }
143 widget_redraw(motion->pscroll_bar);
144 widget_mark_dirty(motion->pscroll_bar);
145
146 flush_dirty();
147 }
148
149 return ID_ERROR;
150}
151
152/**********************************************************************/
155static int min_horiz_cma_callback(struct widget *pwidget)
156{
158 struct hmove motion;
159
160 motion.pscroll_bar = pwidget;
161 motion.min = pwidget->next->size.x + pwidget->next->size.w + 5;
162 motion.max = motion.min + 70;
163 motion.base = -20;
164
165 MOVE_STEP_X = 2;
166 MOVE_STEP_Y = 0;
167 /* Filter mouse motion events */
169 gui_event_loop((void *)(&motion), NULL, NULL, NULL, NULL, NULL, NULL,
170 NULL, NULL,
172 /* Turn off Filter mouse motion events */
176
177 selected_widget = pwidget;
178 set_wstate(pwidget, FC_WS_SELECTED);
179 /* save the change */
181 /* refreshes the cma */
185 }
187 }
188
189 return -1;
190}
191
192/**********************************************************************/
195static int factor_horiz_cma_callback(struct widget *pwidget)
196{
198 struct hmove motion;
199
200 motion.pscroll_bar = pwidget;
201 motion.min = pwidget->next->size.x + pwidget->next->size.w + 5;
202 motion.max = motion.min + 54;
203 motion.base = 1;
204
205 MOVE_STEP_X = 2;
206 MOVE_STEP_Y = 0;
207 /* Filter mouse motion events */
209 gui_event_loop((void *)(&motion), NULL, NULL, NULL, NULL, NULL, NULL,
210 NULL, NULL,
212 /* Turn off Filter mouse motion events */
216
217 selected_widget = pwidget;
218 set_wstate(pwidget, FC_WS_SELECTED);
219 /* save the change */
221 /* refreshes the cma */
225 }
227 }
228
229 return -1;
230}
231
232/**********************************************************************/
235static int toggle_cma_celebrating_callback(struct widget *pwidget)
236{
239 /* save the change */
242 }
243
244 return -1;
245}
246
247/* ============================================================= */
248
249/**********************************************************************/
252static int save_cma_window_callback(struct widget *pwindow)
253{
254 return -1;
255}
256
257/**********************************************************************/
260static int ok_save_cma_callback(struct widget *pwidget)
261{
263 if (pwidget && cma && cma->adv) {
264 struct widget *pedit = (struct widget *)pwidget->data.ptr;
265
266 if (pedit->string_utf8->text != NULL) {
268 } else {
269 cmafec_preset_add(_("new preset"), &cma->edited_cm_parm);
270 }
271
274 FC_FREE(cma->adv);
275
277 }
278 }
279
280 return -1;
281}
282
283/**********************************************************************/
286static int cancel_sld_cma_callback(struct widget *pwidget)
287{
289 if (cma && cma->adv) {
293 FC_FREE(cma->adv);
294 flush_dirty();
295 }
296 }
297
298 return -1;
299}
300
301/**********************************************************************/
304static int save_cma_callback(struct widget *pwidget)
305{
307 struct widget *buf, *pwindow;
308 utf8_str *pstr;
309 SDL_Surface *text;
312
313 if (cma->adv) {
314 return 1;
315 }
316
317 cma->adv = fc_calloc(1, sizeof(struct advanced_dialog));
318
319 pstr = create_utf8_from_char_fonto(_("Name new preset"),
321 pstr->style |= TTF_STYLE_BOLD;
322
323 pwindow = create_window_skeleton(NULL, pstr, 0);
324
326 set_wstate(pwindow, FC_WS_NORMAL);
327 cma->adv->end_widget_list = pwindow;
328
329 add_to_gui_list(ID_WINDOW, pwindow);
330
331 area = pwindow->area;
332 area.h = MAX(area.h, 1);
333
334 /* ============================================================= */
335 /* Label */
336 pstr = create_utf8_from_char_fonto(_("What should we name the preset?"),
338 pstr->style |= (TTF_STYLE_BOLD|SF_CENTER);
340
343 area.w = MAX(area.w, text->w);
344 area.h += text->h + adj_size(5);
345 /* ============================================================= */
346
347 buf = create_edit(NULL, pwindow->dst,
348 create_utf8_from_char_fonto(_("new preset"),
350 adj_size(100),
353 area.h += buf->size.h;
354 area.w = MAX(area.w, buf->size.w);
355
357 /* ============================================================= */
358
360 pwindow->dst,
361 _("Yes"),
362 FONTO_ATTENTION, 0);
363
364 buf->action = ok_save_cma_callback;
366 buf->key = SDLK_RETURN;
368 buf->data.ptr = (void *)buf->next;
369
371 pwindow->dst, _("No"),
372 FONTO_ATTENTION, 0);
375 buf->key = SDLK_ESCAPE;
376
378
379 area.h += buf->size.h;
380 buf->size.w = MAX(buf->next->size.w, buf->size.w);
381 buf->next->size.w = buf->size.w;
382 area.w = MAX(area.w, 2 * buf->size.w + adj_size(20));
383
385
386 /* setup window size and start position */
387 area.w += adj_size(20);
388 area.h += adj_size(15);
389
391 (pwindow->size.w - pwindow->area.w) + area.w,
392 (pwindow->size.h - pwindow->area.h) + area.h);
393
394 area = pwindow->area;
395
396 widget_set_position(pwindow,
397 pwidget->size.x - pwindow->size.w / 2,
398 pwidget->size.y - pwindow->size.h);
399
400 /* setup rest of widgets */
401 /* label */
402 dst.x = area.x + (area.w - text->w) / 2;
403 dst.y = area.y + 1;
404 alphablit(text, NULL, pwindow->theme, &dst, 255);
405 dst.y += text->h + adj_size(5);
406 FREESURFACE(text);
407
408 /* edit */
409 buf = pwindow->prev;
410 buf->size.w = area.w - adj_size(10);
411 buf->size.x = area.x + adj_size(5);
412 buf->size.y = dst.y;
413 dst.y += buf->size.h + adj_size(5);
414
415 /* yes */
416 buf = buf->prev;
417 buf->size.x = area.x + (area.w - (2 * buf->size.w + adj_size(20))) / 2;
418 buf->size.y = dst.y;
419
420 /* no */
421 buf = buf->prev;
422 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(20);
423 buf->size.y = buf->next->size.y;
424
425 /* ================================================== */
426 /* redraw */
427 redraw_group(cma->adv->begin_widget_list, pwindow, 0);
428 widget_mark_dirty(pwindow);
429 flush_dirty();
430 }
431
432 return -1;
433}
434
435/* ================================================== */
436
437/**********************************************************************/
440static int ld_cma_callback(struct widget *pwidget)
441{
443 bool load = pwidget->data.ptr != NULL;
444 int index = MAX_ID - pwidget->id;
445
449 FC_FREE(cma->adv);
450
451 if (load) {
455 /* save the change */
457 /* stop the cma */
460 }
461 } else {
463 }
464
466 }
467
468 return -1;
469}
470
471/**********************************************************************/
474static void popup_load_del_presets_dialog(bool load, struct widget *button)
475{
476 int hh, count, i;
477 struct widget *buf, *pwindow;
478 utf8_str *pstr;
480
481 if (cma->adv) {
482 return;
483 }
484
485 count = cmafec_preset_num();
486
487 if (count == 1) {
488 if (load) {
491 /* save the change */
493 /* stop the cma */
496 }
497 } else {
499 }
501 return;
502 }
503
504 cma->adv = fc_calloc(1, sizeof(struct advanced_dialog));
505
507 pstr->style |= TTF_STYLE_BOLD;
508
509 pwindow = create_window_skeleton(NULL, pstr, 0);
510
512 set_wstate(pwindow, FC_WS_NORMAL);
513 cma->adv->end_widget_list = pwindow;
514
515 add_to_gui_list(ID_WINDOW, pwindow);
516
517 area = pwindow->area;
518
519 /* ---------- */
520 /* Create exit button */
521 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
523 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
527 buf->key = SDLK_ESCAPE;
528 area.w += (buf->size.w + adj_size(10));
529
531 /* ---------- */
532
533 for (i = 0; i < count; i++) {
535 pstr->style |= TTF_STYLE_BOLD;
536 buf = create_iconlabel(NULL, pwindow->dst, pstr,
538 buf->string_utf8->bgcol = (SDL_Color) {0, 0, 0, 0};
539 buf->action = ld_cma_callback;
540
541 area.w = MAX(area.w, buf->size.w);
542 area.h += buf->size.h;
544
545 if (load) {
546 buf->data.ptr = (void *)1;
547 } else {
548 buf->data.ptr = NULL;
549 }
550
552
553 if (i > 10) {
555 }
556 }
559 cma->adv->end_active_widget_list = pwindow->prev->prev;
561
562 area.w += adj_size(2);
563 area.h += 1;
564
565 if (count > 11) {
567
568 /* ------- window ------- */
569 area.h = 11 * pwindow->prev->prev->size.h + adj_size(2)
570 + 2 * cma->adv->scroll->up_left_button->size.h;
573 }
574
575 /* ----------------------------------- */
576
577 resize_window(pwindow, NULL, NULL,
578 (pwindow->size.w - pwindow->area.w) + area.w,
579 (pwindow->size.h - pwindow->area.h) + area.h);
580
581 area = pwindow->area;
582
583 widget_set_position(pwindow,
584 button->size.x - (pwindow->size.w / 2),
585 button->size.y - pwindow->size.h);
586
587 /* exit button */
588 buf = pwindow->prev;
589 buf->size.x = area.x + area.w - buf->size.w - 1;
590 buf->size.y = pwindow->size.y + adj_size(2);
591
592 buf = buf->prev;
593 hh = (cma->adv->scroll ? cma->adv->scroll->up_left_button->size.h + 1 : 0);
595 area.y + 1 + hh, area.w - 1, 0,
597
598 if (cma->adv->scroll) {
604 }
605
606 /* ==================================================== */
607 /* redraw */
608 redraw_group(cma->adv->begin_widget_list, pwindow, 0);
609
610 widget_flush(pwindow);
611}
612
613/**********************************************************************/
616static int load_cma_callback(struct widget *pwidget)
617{
620 }
621
622 return -1;
623}
624
625/**********************************************************************/
628static int del_cma_callback(struct widget *pwidget)
629{
632 }
633
634 return -1;
635}
636
637/* ================================================== */
638
639/**********************************************************************/
643static int run_cma_callback(struct widget *pwidget)
644{
648 }
649
650 return -1;
651}
652
653/**********************************************************************/
656static int run_cma_once_callback(struct widget *pwidget)
657{
659 struct cm_result *result;
660
662 /* fill in result label */
663 result = cm_result_new(cma->pcity);
665 cma_apply_result(cma->pcity, result);
666 cm_result_destroy(result);
667 }
668
669 return -1;
670}
671
672/**********************************************************************/
675static int stop_cma_callback(struct widget *pwidget)
676{
680 }
681
682 return -1;
683}
684
685/* ===================================================================== */
686
687/**********************************************************************/
690static void set_cma_hscrollbars(void)
691{
692 struct widget *pbuf;
693 char cbuf[4];
694
695 if (!cma) {
696 return;
697 }
698
699 /* exit button */
702 /* min label */
703 pbuf = pbuf->prev;
704 fc_snprintf(cbuf, sizeof(cbuf), "%d", *(int *)pbuf->prev->data.ptr);
705 copy_chars_to_utf8_str(pbuf->string_utf8, cbuf);
706
707 /* min scrollbar */
708 pbuf = pbuf->prev;
709 pbuf->size.x = pbuf->next->size.x
710 + pbuf->next->size.w + adj_size(5) + adj_size(20) + *(int *)pbuf->data.ptr;
711
712 /* factor label */
713 pbuf = pbuf->prev;
714 fc_snprintf(cbuf, sizeof(cbuf), "%d", *(int *)pbuf->prev->data.ptr);
715 copy_chars_to_utf8_str(pbuf->string_utf8, cbuf);
716
717 /* factor scrollbar*/
718 pbuf = pbuf->prev;
719 pbuf->size.x = pbuf->next->size.x
720 + pbuf->next->size.w + adj_size(5) + *(int *)pbuf->data.ptr - 1;
722
723 /* happy factor label */
724 pbuf = pbuf->prev;
725 fc_snprintf(cbuf, sizeof(cbuf), "%d", *(int *)pbuf->prev->data.ptr);
726 copy_chars_to_utf8_str(pbuf->string_utf8, cbuf);
727
728 /* happy factor scrollbar */
729 pbuf = pbuf->prev;
730 pbuf->size.x = pbuf->next->size.x
731 + pbuf->next->size.w + adj_size(5) + *(int *)pbuf->data.ptr - 1;
732}
733
734/**********************************************************************/
738{
739 SDL_Color bg_color = {255, 255, 255, 136};
740 int count, step, i;
741 struct widget *buf = cma->dlg->end_widget_list; /* pwindow */
742 SDL_Surface *text;
743 utf8_str *pstr;
748 struct cm_result *result = cm_result_new(cma->pcity);
749
750 /* redraw window background and exit button */
751 redraw_group(buf->prev, buf, 0);
752
753 /* fill in result label */
755
756 if (result->found_a_valid) {
757 /* redraw Citizens */
758 count = city_size_get(cma->pcity);
759
761 step = (buf->size.w - adj_size(20)) / text->w;
762 if (count > step) {
763 step = (buf->size.w - adj_size(20) - text->w) / (count - 1);
764 } else {
765 step = text->w;
766 }
767
768 dst.y = buf->area.y + adj_size(4);
769 dst.x = buf->area.x + adj_size(7);
770
771 for (i = 0;
772 i < count - (result->specialists[SP_ELVIS]
773 + result->specialists[SP_SCIENTIST]
774 + result->specialists[SP_TAXMAN]); i++) {
776 alphablit(text, NULL, buf->dst->surface, &dst, 255);
777 dst.x += step;
778 }
779
781 for (i = 0; i < result->specialists[SP_ELVIS]; i++) {
782 alphablit(text, NULL, buf->dst->surface, &dst, 255);
783 dst.x += step;
784 }
785
786 text = get_tax_surface(O_GOLD);
787 for (i = 0; i < result->specialists[SP_TAXMAN]; i++) {
788 alphablit(text, NULL, buf->dst->surface, &dst, 255);
789 dst.x += step;
790 }
791
793 for (i = 0; i < result->specialists[SP_SCIENTIST]; i++) {
794 alphablit(text, NULL, buf->dst->surface, &dst, 255);
795 dst.x += step;
796 }
797 }
798
799 /* Create result text surface */
803
806
807 /* Fill result text background */
808 dst.x = buf->area.x + adj_size(7);
809 dst.y = buf->area.y + adj_size(186);
810 dst.w = text->w + adj_size(10);
811 dst.h = text->h + adj_size(10);
812 fill_rect_alpha(buf->dst->surface, &dst, &bg_color);
813
814 create_frame(buf->dst->surface,
815 dst.x, dst.y, dst.x + dst.w - 1, dst.y + dst.h - 1,
817
818 dst.x += adj_size(5);
819 dst.y += adj_size(5);
820 alphablit(text, NULL, buf->dst->surface, &dst, 255);
821 FREESURFACE(text);
822
823 /* Happy factor scrollbar */
827 } else {
829 }
830
831 /* Save as ... */
832 buf = buf->prev->prev;
835 } else {
837 }
838
839 /* Load */
840 buf = buf->prev;
843 } else {
845 }
846
847 /* Del */
848 buf = buf->prev;
851 } else {
853 }
854
855 /* Run */
856 buf = buf->prev;
857 if (client_under_control && result->found_a_valid && !controlled) {
859 } else {
861 }
862
863 /* Run once */
864 buf = buf->prev;
865 if (client_under_control && result->found_a_valid && !controlled) {
867 } else {
869 }
870
871 /* Stop */
872 buf = buf->prev;
875 } else {
877 }
878
879 /* redraw rest widgets */
882
884
885 cm_result_destroy(result);
886}
887
888/**********************************************************************/
892{
893 SDL_Color bg_color = {255, 255, 255, 136};
894
895 struct widget *pwindow, *buf;
896 SDL_Surface *logo, *text[O_LAST + 1], *minimal, *factor;
898 utf8_str *pstr;
899 char cbuf[128];
900 int w, text_w, x, cs;
902
903 if (cma) {
904 return;
905 }
906
907 cma = fc_calloc(1, sizeof(struct cma_dialog));
908 cma->pcity = pcity;
909 cma->dlg = fc_calloc(1, sizeof(struct small_dialog));
910 cma->adv = NULL;
912
914
915 /* --------------------------- */
916
917 fc_snprintf(cbuf, sizeof(cbuf),
918 _("City of %s (Population %s citizens) : %s"),
921 _("Citizen Governor"));
922
924 pstr->style |= TTF_STYLE_BOLD;
925
926 pwindow = create_window_skeleton(NULL, pstr, 0);
927
928 pwindow->action = cma_dlg_callback;
929 set_wstate(pwindow, FC_WS_NORMAL);
930 add_to_gui_list(ID_WINDOW, pwindow);
931 cma->dlg->end_widget_list = pwindow;
932
933 area = pwindow->area;
934
935 /* ---------- */
936 /* Create exit button */
937 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
939 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
943 buf->key = SDLK_ESCAPE;
944 area.w += (buf->size.w + adj_size(10));
945
947
949 text_w = 0;
950
951 copy_chars_to_utf8_str(pstr, _("Minimal Surplus"));
953
954 copy_chars_to_utf8_str(pstr, _("Factor"));
956
957 /* ---------- */
961 text_w = MAX(text_w, text[i]->w);
962
963 /* Minimal label */
964 buf = create_iconlabel(NULL, pwindow->dst,
967
969
970 /* Minimal scrollbar */
971 buf = create_horizontal(current_theme->horiz, pwindow->dst, adj_size(30),
973
974 buf->action = min_horiz_cma_callback;
975 buf->data.ptr = &cma->edited_cm_parm.minimal_surplus[i];
976
978
980
981 /* Factor label */
982 buf = create_iconlabel(NULL, pwindow->dst,
985
987
988 /* Factor scrollbar */
989 buf = create_horizontal(current_theme->horiz, pwindow->dst, adj_size(30),
991
993 buf->data.ptr = &cma->edited_cm_parm.factor[i];
994
996
999
1000 copy_chars_to_utf8_str(pstr, _("Celebrate"));
1003
1004 /* Happy factor label */
1005 buf = create_iconlabel(NULL, pwindow->dst,
1008
1010
1011 /* Happy factor scrollbar */
1012 buf = create_horizontal(current_theme->horiz, pwindow->dst, adj_size(30),
1014
1016 buf->data.ptr = &cma->edited_cm_parm.happy_factor;
1017
1019
1021
1022 /* celebrating */
1023 buf = create_checkbox(pwindow->dst,
1026
1030
1031 /* Save as ... */
1032 buf = create_themeicon(current_theme->save_icon, pwindow->dst,
1034 buf->action = save_cma_callback;
1035 buf->info_label = create_utf8_from_char_fonto(_("Save settings as..."),
1037
1039
1040 /* Load settings */
1041 buf = create_themeicon(current_theme->load_icon, pwindow->dst,
1043 buf->action = load_cma_callback;
1044 buf->info_label = create_utf8_from_char_fonto(_("Load settings"),
1046
1048
1049 /* Del settings */
1050 buf = create_themeicon(current_theme->delete_icon, pwindow->dst,
1052 buf->action = del_cma_callback;
1053 buf->info_label = create_utf8_from_char_fonto(_("Delete settings"),
1055
1057
1058 /* Run cma */
1059 buf = create_themeicon(current_theme->qprod_icon, pwindow->dst,
1061 buf->action = run_cma_callback;
1062 buf->info_label = create_utf8_from_char_fonto(_("Control city"), FONTO_DEFAULT);
1063
1065
1066 /* Run cma once */
1067 buf = create_themeicon(current_theme->find_city_icon, pwindow->dst,
1069 buf->action = run_cma_once_callback;
1070 buf->info_label = create_utf8_from_char_fonto(_("Apply once"), FONTO_DEFAULT);
1071
1073
1074 /* Del settings */
1075 buf = create_themeicon(current_theme->support_icon, pwindow->dst,
1077 buf->action = stop_cma_callback;
1078 buf->info_label = create_utf8_from_char_fonto(_("Release city"), FONTO_DEFAULT);
1079
1081
1082 /* -------------------------------- */
1084
1085#ifdef GUI_SDL2_SMALL_SCREEN
1086 area.w = MAX(pcity_map->w + adj_size(220) + text_w + adj_size(10) +
1087 (pwindow->prev->prev->size.w + adj_size(5 + 70 + 5) +
1088 pwindow->prev->prev->size.w + adj_size(5 + 55 + 15)), area.w);
1089 area.h = adj_size(390) - (pwindow->size.w - pwindow->area.w);
1090#else /* GUI_SDL2_SMALL_SCREEN */
1091 area.w = MAX(pcity_map->w + adj_size(150) + text_w + adj_size(10) +
1092 (pwindow->prev->prev->size.w + adj_size(5 + 70 + 5) +
1093 pwindow->prev->prev->size.w + adj_size(5 + 55 + 15)), area.w);
1094 area.h = adj_size(360) - (pwindow->size.w - pwindow->area.w);
1095#endif /* GUI_SDL2_SMALL_SCREEN */
1096
1098 if (resize_window(pwindow, logo, NULL,
1099 (pwindow->size.w - pwindow->area.w) + area.w,
1100 (pwindow->size.w - pwindow->area.w) + area.h)) {
1102 }
1103
1104#if 0
1105 logo = SDL_DisplayFormat(pwindow->theme);
1106 FREESURFACE(pwindow->theme);
1107 pwindow->theme = logo;
1108#endif /* 0 */
1109
1110 area = pwindow->area;
1111
1112 widget_set_position(pwindow,
1113 (main_window_width() - pwindow->size.w) / 2,
1114 (main_window_height() - pwindow->size.h) / 2);
1115
1116 /* exit button */
1117 buf = pwindow->prev;
1118 buf->size.x = area.x + area.w - buf->size.w - 1;
1119 buf->size.y = pwindow->size.y + adj_size(2);
1120
1121 /* ---------- */
1122 dst.x = pcity_map->w + adj_size(80) +
1123 (pwindow->size.w - (pcity_map->w + adj_size(40)) -
1124 (text_w + adj_size(10) + pwindow->prev->prev->size.w + adj_size(5 + 70 + 5) +
1125 pwindow->prev->prev->size.w + adj_size(5 + 55))) / 2;
1126
1127#ifdef GUI_SDL2_SMALL_SCREEN
1128 dst.x += 22;
1129#endif
1130
1131 dst.y = adj_size(75);
1132
1133 x = area.x = dst.x - adj_size(10);
1134 area.y = dst.y - adj_size(20);
1135 w = area.w = adj_size(10) + text_w + adj_size(10) + pwindow->prev->prev->size.w + adj_size(5 + 70 + 5)
1136 + pwindow->prev->prev->size.w + adj_size(5 + 55 + 10);
1137 area.h = (O_LAST + 1) * (text[0]->h + adj_size(6)) + adj_size(20);
1138 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1139
1140 create_frame(pwindow->theme,
1141 area.x, area.y, area.w - 1, area.h - 1,
1143
1144 area.x = dst.x + text_w + adj_size(10);
1145 alphablit(minimal, NULL, pwindow->theme, &area, 255);
1146 area.x += minimal->w + adj_size(10);
1148
1149 alphablit(factor, NULL, pwindow->theme, &area, 255);
1150 FREESURFACE(factor);
1151
1152 area.x = pwindow->area.x + adj_size(22);
1153 area.y = pwindow->area.y + adj_size(31);
1154 alphablit(pcity_map, NULL, pwindow->theme, &area, 255);
1156
1158 /* min label */
1159 buf = buf->prev;
1160 buf->size.x = pwindow->size.x + dst.x + text_w + adj_size(10);
1161 buf->size.y = pwindow->size.y + dst.y + (text[i]->h - buf->size.h) / 2;
1162
1163 /* min sb */
1164 buf = buf->prev;
1165 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(5);
1166 buf->size.y = pwindow->size.y + dst.y + (text[i]->h - buf->size.h) / 2;
1167
1168 area.x = buf->size.x - pwindow->size.x - adj_size(2);
1169 area.y = buf->size.y - pwindow->size.y;
1170 area.w = adj_size(74);
1171 area.h = buf->size.h;
1172 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1173
1174 create_frame(pwindow->theme,
1175 area.x, area.y, area.w - 1, area.h - 1,
1177
1178 /* factor label */
1179 buf = buf->prev;
1180 buf->size.x = buf->next->size.x + adj_size(75);
1181 buf->size.y = pwindow->size.y + dst.y + (text[i]->h - buf->size.h) / 2;
1182
1183 /* factor sb */
1184 buf = buf->prev;
1185 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(5);
1186 buf->size.y = pwindow->size.y + dst.y + (text[i]->h - buf->size.h) / 2;
1187
1188 area.x = buf->size.x - pwindow->size.x - adj_size(2);
1189 area.y = buf->size.y - pwindow->size.y;
1190 area.w = adj_size(58);
1191 area.h = buf->size.h;
1192 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1193
1194 create_frame(pwindow->theme,
1195 area.x, area.y, area.w - 1, area.h - 1,
1197
1198 alphablit(text[i], NULL, pwindow->theme, &dst, 255);
1199 dst.y += text[i]->h + adj_size(6);
1200 FREESURFACE(text[i]);
1202
1203 /* happy factor label */
1204 buf = buf->prev;
1205 buf->size.x = buf->next->next->size.x;
1206 buf->size.y = pwindow->size.y + dst.y + (text[O_LAST]->h - buf->size.h) / 2;
1207
1208 /* happy factor sb */
1209 buf = buf->prev;
1210 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(5);
1211 buf->size.y = pwindow->size.y + dst.y + (text[O_LAST]->h - buf->size.h) / 2;
1212
1213 area.x = buf->size.x - pwindow->size.x - adj_size(2);
1214 area.y = buf->size.y - pwindow->size.y;
1215 area.w = adj_size(58);
1216 area.h = buf->size.h;
1217 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1218
1219 create_frame(pwindow->theme,
1220 area.x, area.y, area.w - 1, area.h - 1,
1222
1223 /* Celebrate cbox */
1224 buf = buf->prev;
1225 buf->size.x = pwindow->size.x + dst.x + adj_size(10);
1226 buf->size.y = pwindow->size.y + dst.y;
1227
1228 /* Celebrate static text */
1229 dst.x += (adj_size(10) + buf->size.w + adj_size(5));
1230 dst.y += (buf->size.h - text[O_LAST]->h) / 2;
1231 alphablit(text[O_LAST], NULL, pwindow->theme, &dst, 255);
1232 FREESURFACE(text[O_LAST]);
1233 /* ------------------------ */
1234
1235 /* Save as */
1236 buf = buf->prev;
1237 buf->size.x = pwindow->size.x + x + (w - (buf->size.w + adj_size(6)) * 6) / 2;
1238 buf->size.y = pwindow->size.y + pwindow->size.h - buf->size.h * 2 - adj_size(10);
1239
1240 area.x = x;
1241 area.y = buf->size.y - pwindow->size.y - adj_size(5);
1242 area.w = w;
1243 area.h = buf->size.h + adj_size(10);
1244 fill_rect_alpha(pwindow->theme, &area, &bg_color);
1245
1246 create_frame(pwindow->theme,
1247 area.x, area.y, area.w - 1, area.h - 1,
1249
1250 /* Load */
1251 buf = buf->prev;
1252 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1253 buf->size.y = buf->next->size.y;
1254
1255 /* Del */
1256 buf = buf->prev;
1257 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1258 buf->size.y = buf->next->size.y;
1259
1260 /* Run */
1261 buf = buf->prev;
1262 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1263 buf->size.y = buf->next->size.y;
1264
1265 /* Run one time */
1266 buf = buf->prev;
1267 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1268 buf->size.y = buf->next->size.y;
1269
1270 /* Del */
1271 buf = buf->prev;
1272 buf->size.x = buf->next->size.x + buf->next->size.w + adj_size(4);
1273 buf->size.y = buf->next->size.y;
1274
1275 /* ------------------------ */
1276 /* Check if Citizen Icons style was loaded */
1278
1279 if (cs != icons->style) {
1281 }
1282
1285}
1286
1287/**********************************************************************/
1291{
1292 if (cma) {
1295 FC_FREE(cma->dlg);
1296 if (cma->adv) {
1299 FC_FREE(cma->adv->scroll);
1300 FC_FREE(cma->adv);
1301 }
1303 /* enable city dlg */
1306 }
1307
1309 FC_FREE(cma);
1310 }
1311}
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