Freeciv-3.3
Loading...
Searching...
No Matches
wldlg.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 wldlg.c - description
15 -------------------
16 begin : Wed Sep 18 2002
17 copyright : (C) 2002 by Rafał Bursig
18 email : Rafał Bursig <bursig@poczta.fm>
19***********************************************************************/
20
21#ifdef HAVE_CONFIG_H
22#include <fc_config.h>
23#endif
24
25#include <stdlib.h>
26
27/* SDL3 */
28#include <SDL3/SDL.h>
29
30/* utility */
31#include "fcintl.h"
32#include "log.h"
33
34/* common */
35#include "game.h"
36#include "movement.h"
37#include "unit.h"
38
39/* client */
40#include "client_main.h"
41#include "climisc.h"
42#include "global_worklist.h"
43
44/* gui-sdl3 */
45#include "citydlg.h"
46#include "colors.h"
47#include "graphics.h"
48#include "gui_id.h"
49#include "gui_main.h"
50#include "gui_tilespec.h"
51#include "helpdlg.h"
52#include "mapview.h"
53#include "sprite.h"
54#include "themespec.h"
55#include "widget.h"
56
57#include "wldlg.h"
58
59#define TARGETS_COL 4
60#define TARGETS_ROW 4
61
62struct wl_editor {
64 struct widget *end_widget_list; /* window */
65
67 struct advanced_dialog *work;
68 struct advanced_dialog *global;
69
70 struct city *pcity;
74
75 /* shortcuts */
76 struct widget *dock;
78
79 struct widget *production_name;
81
82 int stock;
85
86
87static int worklist_editor_item_callback(struct widget *pwidget);
88static SDL_Surface *get_progress_icon(int stock, int cost, int *progress);
89static const char *get_production_name(struct city *pcity,
90 struct universal prod, int *cost);
91static void refresh_worklist_count_label(void);
92static void refresh_production_label(int stock);
93
94/* =========================================================== */
95
96/**********************************************************************/
99static int window_worklist_editor_callback(struct widget *pwidget)
100{
101 return -1;
102}
103
104/**********************************************************************/
107static int popdown_worklist_editor_callback(struct widget *pwidget)
108{
111 }
112
113 return -1;
114}
115
116/**********************************************************************/
120static int ok_worklist_editor_callback(struct widget *pwidget)
121{
123 int i, j;
124 struct city *pcity = editor->pcity;
125
126 /* remove duplicate entry of impv./wonder target from worklist */
127 for (i = 0; i < worklist_length(&editor->worklist_copy); i++) {
128 if (VUT_IMPROVEMENT == editor->worklist_copy.entries[i].kind) {
129 for (j = i + 1; j < worklist_length(&editor->worklist_copy); j++) {
130 if (VUT_IMPROVEMENT == editor->worklist_copy.entries[j].kind
131 && editor->worklist_copy.entries[i].value.building ==
132 editor->worklist_copy.entries[j].value.building) {
133 worklist_remove(&editor->worklist_copy, j);
134 }
135 }
136 }
137 }
138
139 if (pcity) {
140 /* remove duplicate entry of currently building impv./wonder from worklist */
141 if (VUT_IMPROVEMENT == editor->currently_building.kind) {
142 for (i = 0; i < worklist_length(&editor->worklist_copy); i++) {
143 if (VUT_IMPROVEMENT == editor->worklist_copy.entries[i].kind
144 && editor->worklist_copy.entries[i].value.building ==
145 editor->currently_building.value.building) {
146 worklist_remove(&editor->worklist_copy, i);
147 }
148 }
149 }
150
151 /* change production */
152 if (!are_universals_equal(&pcity->production, &editor->currently_building)) {
153 city_change_production(pcity, &editor->currently_building);
154 }
155
156 /* commit new city worklist */
157 city_set_worklist(pcity, &editor->worklist_copy);
158 } else {
159 /* commit global worklist */
160 struct global_worklist *gwl = global_worklist_by_id(editor->global_worklist_id);
161
162 if (gwl) {
163 global_worklist_set(gwl, &editor->worklist_copy);
164 global_worklist_set_name(gwl, editor->worklist_name);
166 }
167 }
168
169 /* popdown dialog */
171 }
172
173 return -1;
174}
175
176/**********************************************************************/
179static int rename_worklist_editor_callback(struct widget *pwidget)
180{
182 if (pwidget->string_utf8->text != NULL) {
183 fc_snprintf(editor->worklist_name, MAX_LEN_NAME, "%s",
184 pwidget->string_utf8->text);
185 } else {
186 /* empty input -> restore previous content */
187 copy_chars_to_utf8_str(pwidget->string_utf8, editor->worklist_name);
188 widget_redraw(pwidget);
189 widget_mark_dirty(pwidget);
190 flush_dirty();
191 }
192 }
193
194 return -1;
195}
196
197/* ====================================================================== */
198
199/**********************************************************************/
202static void add_target_to_worklist(struct widget *target)
203{
204 struct widget *buf = NULL, *dock = NULL;
205 utf8_str *pstr = NULL;
206 int i;
207 struct universal prod = cid_decode(MAX_ID - target->id);
208
209 set_wstate(target, FC_WS_SELECTED);
210 widget_redraw(target);
211 widget_flush(target);
212
213 /* Deny adding currently building Impr/Wonder Target */
214 if (editor->pcity
215 && VUT_IMPROVEMENT == prod.kind
216 && are_universals_equal(&prod, &editor->currently_building)) {
217 return;
218 }
219
220 if (worklist_length(&editor->worklist_copy) >= MAX_LEN_WORKLIST - 1) {
221 return;
222 }
223
224 for (i = 0; i < worklist_length(&editor->worklist_copy); i++) {
225 if (VUT_IMPROVEMENT == prod.kind
226 && are_universals_equal(&prod, &editor->worklist_copy.entries[i])) {
227 return;
228 }
229 }
230
231 worklist_append(&editor->worklist_copy, &prod);
232
233 /* Create widget entry */
234 if (VUT_UTYPE == prod.kind) {
237 } else {
239 prod.value.building),
241 }
242
243 pstr->style |= SF_CENTER;
244 buf = create_iconlabel(NULL, target->dst, pstr,
246
249
250 buf->data.ptr = fc_calloc(1, sizeof(int));
251 *((int *)buf->data.ptr) = worklist_length(&editor->worklist_copy) - 1;
252
253 buf->id = MAX_ID - cid_encode(prod);
254
255 if (editor->work->begin_active_widget_list) {
256 dock = editor->work->begin_active_widget_list;
257 } else {
258 dock = editor->dock;
259 }
260
261/* FIXME */
262#if 0
263 if (worklist_length(&editor->worklist_copy) > editor->work->scroll->active + 1) {
264
266 editor->end_widget_list->area.x + adj_size(2),
268 editor->work->scroll->up_left_button->size.h + 1,
269 adj_size(126), 0, editor->work->begin_widget_list,
270 editor->work->end_widget_list);
271
273 editor->end_widget_list->area.x + adj_size(2),
275 adj_size(225), FALSE);
276
277 show_scrollbar(editor->work->scroll);
278 }
279#endif /* 0 */
280
282 dock, FALSE,
283 editor->end_widget_list->area.x + adj_size(2),
284 editor->end_widget_list->area.y + adj_size(152));
285
286 buf->size.w = adj_size(126);
287
289 redraw_group(editor->work->begin_widget_list,
290 editor->work->end_widget_list, TRUE);
291 flush_dirty();
292}
293
294/**********************************************************************/
299static bool are_prods_same_class(const struct universal *one,
300 const struct universal *two)
301{
302 if (one->kind != two->kind) {
303 return FALSE;
304 }
305
306 if (VUT_IMPROVEMENT == one->kind) {
307 if (is_wonder(one->value.building)) {
308 return is_wonder(two->value.building);
309 } else {
310 return !is_wonder(two->value.building);
311 }
312 }
313
314 return FALSE;
315}
316
317/**********************************************************************/
321static void change_production(struct universal *prod)
322{
323 if (!are_prods_same_class(&editor->currently_building, prod)) {
324 if (editor->stock != editor->pcity->shield_stock) {
325 if (are_prods_same_class(&editor->pcity->production, prod)) {
326 editor->stock = editor->pcity->shield_stock;
327 }
328 } else {
329 editor->stock =
331 }
332 }
333
334 editor->currently_building = *prod;
336}
337
338/**********************************************************************/
346static void add_target_to_production(struct widget *target)
347{
348 int dummy;
349 struct universal prod;
350
351 fc_assert_ret(target != NULL);
352
353 /* redraw Target Icon */
354 set_wstate(target, FC_WS_SELECTED);
355 widget_redraw(target);
356 widget_flush(target);
357
358 prod = cid_decode(MAX_ID - target->id);
359
360 /* check if we change to the same target */
361 if (are_universals_equal(&prod, &editor->currently_building)) {
362 /* comit changes and exit - double click detection */
364 return;
365 }
366
367 change_production(&prod);
368
369 /* change Production Text Label in Worklist Widget list */
370 copy_chars_to_utf8_str(editor->work->end_active_widget_list->string_utf8,
371 get_production_name(editor->pcity, prod, &dummy));
372
373 editor->work->end_active_widget_list->id = MAX_ID - cid_encode(prod);
374
375 widget_redraw(editor->work->end_active_widget_list);
376 widget_mark_dirty(editor->work->end_active_widget_list);
377
378 flush_dirty();
379}
380
381/**********************************************************************/
384static void get_target_help_data(struct widget *target)
385{
386 struct universal prod;
387
388 fc_assert_ret(target != NULL);
389
390 /* redraw Target Icon */
391 set_wstate(target, FC_WS_SELECTED);
392 widget_redraw(target);
393 /*widget_flush(target);*/
394
395 prod = cid_decode(MAX_ID - target->id);
396
397 if (VUT_UTYPE == prod.kind) {
399 } else {
401 }
402}
403
404/**********************************************************************/
411static int worklist_editor_targets_callback(struct widget *pwidget)
412{
414 switch (main_data.event.button.button) {
415 case SDL_BUTTON_LEFT:
416 if (editor->pcity) {
418 } else {
419 add_target_to_worklist(pwidget);
420 }
421 break;
423 get_target_help_data(pwidget);
424 break;
425 case SDL_BUTTON_RIGHT:
426 add_target_to_worklist(pwidget);
427 break;
428 default:
429 /* do nothing */
430 break;
431 }
432 } else if (PRESSED_EVENT(main_data.event)) {
433 if (editor->pcity) {
435 } else {
436 add_target_to_worklist(pwidget);
437 }
438 }
439
440 return -1;
441}
442
443/* ====================================================================== */
444
445/**********************************************************************/
451{
452 /* only one item (production) is left */
453 if (worklist_is_empty(&editor->worklist_copy)) {
454 return;
455 }
456
457 if (item->data.ptr) {
458 /* correct "data" widget fields */
459 struct widget *buf = item;
460
461 if (buf != editor->work->begin_active_widget_list) {
462 do {
463 buf = buf->prev;
464 *((int *)buf->data.ptr) = *((int *)buf->data.ptr) - 1;
465 } while (buf != editor->work->begin_active_widget_list);
466 }
467
468 /* remove element from worklist */
469 worklist_remove(&editor->worklist_copy, *((int *)item->data.ptr));
470
471 /* remove widget from widget list */
473 } else {
474 /* change productions to first worklist element */
475 struct widget *buf = item->prev;
476
477 change_production(&editor->worklist_copy.entries[0]);
478 worklist_advance(&editor->worklist_copy);
480 FC_FREE(buf->data.ptr);
481 if (buf != editor->work->begin_active_widget_list) {
482 do {
483 buf = buf->prev;
484 *((int *)buf->data.ptr) = *((int *)buf->data.ptr) - 1;
485 } while (buf != editor->work->begin_active_widget_list);
486 }
487 }
488
489/* FIXME: fix scrollbar code */
490#if 0
491 /* worklist_length(&editor->worklist_copy): without production */
492 if (worklist_length(&editor->worklist_copy) <= editor->work->scroll->active + 1) {
493
495 editor->end_widget_list->area.x + adj_size(2),
497 adj_size(126), 0, editor->work->begin_widget_list,
498 editor->work->end_widget_list);
499#if 0
501 editor->end_widget_list->area.x + adj_size(2),
503 adj_size(225), FALSE);*/
504#endif /* 0 */
505 hide_scrollbar(editor->work->scroll);
506 }
507#endif /* 0 */
508
510 redraw_group(editor->work->begin_widget_list,
511 editor->work->end_widget_list, TRUE);
512 flush_dirty();
513}
514
515/**********************************************************************/
527{
528 char *text;
529 Uint16 id;
530 bool changed = FALSE;
531 struct universal tmp;
532
533 if (item == editor->work->begin_active_widget_list) {
535 return;
536 }
537
538 text = item->string_utf8->text;
539 id = item->id;
540
541 /* second item or higher was clicked */
542 if (item->data.ptr) {
543 /* worklist operations -> swap down */
544 int row = *((int *)item->data.ptr);
545
546 tmp = editor->worklist_copy.entries[row];
547 editor->worklist_copy.entries[row] = editor->worklist_copy.entries[row + 1];
548 editor->worklist_copy.entries[row + 1] = tmp;
549
550 changed = TRUE;
551 } else {
552 /* first item was clicked -> change production */
553 change_production(&editor->worklist_copy.entries[0]);
554 editor->worklist_copy.entries[0] = cid_decode(MAX_ID - id);
555 changed = TRUE;
556 }
557
558 if (changed) {
559 item->string_utf8->text = item->prev->string_utf8->text;
560 item->id = item->prev->id;
561
562 item->prev->string_utf8->text = text;
563 item->prev->id = id;
564
565 redraw_group(editor->work->begin_widget_list,
566 editor->work->end_widget_list, TRUE);
567 flush_dirty();
568 }
569}
570
571/**********************************************************************/
584{
585 char *text = item->string_utf8->text;
586 Uint16 id = item->id;
587 bool changed = FALSE;
588 struct universal tmp;
589
590 /* first item was clicked -> remove */
591 if (item == editor->work->end_active_widget_list) {
593
594 return;
595 }
596
597 /* third item or higher was clicked */
598 if (item->data.ptr && *((int *)item->data.ptr) > 0) {
599 /* worklist operations -> swap up */
600 int row = *((int *)item->data.ptr);
601
602 tmp = editor->worklist_copy.entries[row];
603 editor->worklist_copy.entries[row] = editor->worklist_copy.entries[row - 1];
604 editor->worklist_copy.entries[row - 1] = tmp;
605
606 changed = TRUE;
607 } else {
608 /* second item was clicked -> change production ... */
609 tmp = editor->currently_building;
610 change_production(&editor->worklist_copy.entries[0]);
611 editor->worklist_copy.entries[0] = tmp;
612
613 changed = TRUE;
614 }
615
616 if (changed) {
617 item->string_utf8->text = item->next->string_utf8->text;
618 item->id = item->next->id;
619
620 item->next->string_utf8->text = text;
621 item->next->id = id;
622
623 redraw_group(editor->work->begin_widget_list,
624 editor->work->end_widget_list, TRUE);
625 flush_dirty();
626 }
627}
628
629/**********************************************************************/
635static int worklist_editor_item_callback(struct widget *pwidget)
636{
638 switch (main_data.event.button.button) {
639 case SDL_BUTTON_LEFT:
641 break;
644 break;
645 case SDL_BUTTON_RIGHT:
647 break;
648 default:
649 ;/* do nothing */
650 break;
651 }
652 } else if (PRESSED_EVENT(main_data.event)) {
654 }
655
656 return -1;
657}
658/* ======================================================= */
659
660/**********************************************************************/
666static void add_global_worklist(struct widget *pwidget)
667{
668 struct global_worklist *gwl = global_worklist_by_id(MAX_ID - pwidget->id);
669 const struct worklist *pworklist;
670 int count, firstfree;
671
672 if (!gwl
675 return;
676 }
677
678 if (worklist_length(&editor->worklist_copy) >= MAX_LEN_WORKLIST - 1) {
679 /* Worklist is full */
680 return;
681 }
682
683 firstfree = worklist_length(&editor->worklist_copy);
684 /* Copy global worklist to city worklist */
685 for (count = 0 ; count < worklist_length(pworklist); count++) {
686 struct widget *buf;
687
688 /* Global worklist can have targets unavilable in current state of game
689 then we must remove those targets from new city worklist */
690 if (!can_city_build_later(&(wld.map), editor->pcity, &pworklist->entries[count])) {
691 continue;
692 }
693
694 worklist_append(&editor->worklist_copy, &pworklist->entries[count]);
695
696 /* Create widget */
697 if (VUT_UTYPE == pworklist->entries[count].kind) {
698 buf = create_iconlabel(NULL, pwidget->dst,
700 utype_name_translation(pworklist->entries[count].value.utype),
703 buf->id = MAX_ID - cid_encode_unit(pworklist->entries[count].value.utype);
704 } else {
705 buf = create_iconlabel(NULL, pwidget->dst,
708 pworklist->entries[count].value.building),
711 buf->id = MAX_ID - cid_encode_building(pworklist->entries[count].value.building);
712 }
713
714 buf->string_utf8->style |= SF_CENTER;
717 buf->size.w = adj_size(126);
718 buf->data.ptr = fc_calloc(1, sizeof(int));
719 *((int *)buf->data.ptr) = firstfree;
720
722 buf, editor->work->begin_active_widget_list,
723 FALSE,
724 editor->end_widget_list->area.x + adj_size(2),
725 editor->end_widget_list->area.y + adj_size(152));
726
727 firstfree++;
728 if (firstfree == MAX_LEN_WORKLIST - 1) {
729 break;
730 }
731 }
732
734 redraw_group(editor->work->begin_widget_list,
735 editor->work->end_widget_list, TRUE);
736
737 flush_dirty();
738}
739
740/**********************************************************************/
745static void set_global_worklist(struct widget *pwidget)
746{
747 struct global_worklist *gwl = global_worklist_by_id(MAX_ID - pwidget->id);
748 struct widget *buf = editor->work->end_active_widget_list;
749 const struct worklist *pworklist;
750 struct worklist wl;
751 int count, wl_count;
752 struct universal target;
753
754 if (!gwl
757 return;
758 }
759
760 /* clear tmp worklist */
762
763 wl_count = 0;
764 /* copy global worklist to city worklist */
765 for (count = 0; count < worklist_length(pworklist); count++) {
766 /* global worklist can have targets unavilable in current state of game
767 then we must remove those targets from new city worklist */
768 if (!can_city_build_later(&(wld.map), editor->pcity, &pworklist->entries[count])) {
769 continue;
770 }
771
772 wl.entries[wl_count] = pworklist->entries[count];
773 wl_count++;
774 }
775 /* --------------------------------- */
776
777 if (!worklist_is_empty(&wl)) {
778 /* free old widget list */
779 if (buf != editor->work->begin_active_widget_list) {
780 buf = buf->prev;
781 if (buf != editor->work->begin_active_widget_list) {
782 do {
783 buf = buf->prev;
785 } while (buf != editor->work->begin_active_widget_list);
786 }
788 }
789 /* --------------------------------- */
790
791 worklist_copy(&editor->worklist_copy, &wl);
792
793 /* --------------------------------- */
794 /* Create new widget list */
795 for (count = 0; count < MAX_LEN_WORKLIST; count++) {
796 /* End of list */
797 if (!worklist_peek_ith(&editor->worklist_copy, &target, count)) {
798 break;
799 }
800
801 if (VUT_UTYPE == target.kind) {
802 buf = create_iconlabel(NULL, pwidget->dst,
806 buf->id = MAX_ID - B_LAST - utype_number(target.value.utype);
807 } else {
808 buf = create_iconlabel(NULL, pwidget->dst,
810 target.value.building),
814 }
815 buf->string_utf8->style |= SF_CENTER;
818 buf->size.w = adj_size(126);
819 buf->data.ptr = fc_calloc(1, sizeof(int));
820 *((int *)buf->data.ptr) = count;
821
823 buf, editor->work->begin_active_widget_list, FALSE,
824 editor->end_widget_list->area.x + adj_size(2),
825 editor->end_widget_list->area.y + adj_size(152));
826 }
827
829 redraw_group(editor->work->begin_widget_list,
830 editor->work->end_widget_list, TRUE);
831
832 flush_dirty();
833 }
834}
835
836/**********************************************************************/
847static int global_worklist_callback(struct widget *pwidget)
848{
850 switch (main_data.event.button.button) {
851 case SDL_BUTTON_LEFT:
852 add_global_worklist(pwidget);
853 break;
855 /* nothing */
856 break;
857 case SDL_BUTTON_RIGHT:
858 set_global_worklist(pwidget);
859 break;
860 default:
861 /* do nothing */
862 break;
863 }
864 } else if (PRESSED_EVENT(main_data.event)) {
865 add_global_worklist(pwidget);
866 }
867
868 return -1;
869}
870
871/* ======================================================= */
872
873/**********************************************************************/
876static const char *get_production_name(struct city *pcity,
877 struct universal prod, int *cost)
878{
880
882
883 if (VUT_UTYPE == prod.kind) {
885 } else {
887 }
888}
889
890/**********************************************************************/
896static SDL_Surface *get_progress_icon(int stock, int cost, int *progress)
897{
898 SDL_Surface *icon = NULL;
899 int width;
900
901 fc_assert_ret_val(progress != NULL, NULL);
902
903 if (stock < cost) {
904 width = ((float)stock / cost) * adj_size(116.0);
905 *progress = ((float)stock / cost) * 100.0;
906 if (!width && stock) {
907 *progress = 1;
908 width = 1;
909 }
910 } else {
911 width = adj_size(116);
912 *progress = 100;
913 }
914
916
917 if (width) {
918 SDL_Rect dst = {2,1,0,0};
920 adj_size(28));
921
922 alphablit(buf, NULL, icon, &dst, 255);
924 }
925
926 return icon;
927}
928
929/**********************************************************************/
933static void refresh_production_label(int stock)
934{
935 int cost, turns;
936 char cbuf[64];
937 SDL_Rect area;
938 bool convert_prod = (VUT_IMPROVEMENT == editor->currently_building.kind)
939 && is_convert_improvement(editor->currently_building.value.building);
940 const char *name = get_production_name(editor->pcity,
941 editor->currently_building, &cost);
942
943 if (convert_prod) {
944 int output = MAX(0, editor->pcity->surplus[O_SHIELD]);
945
946 if (improvement_has_flag(editor->currently_building.value.building,
947 IF_GOLD)) {
948 fc_snprintf(cbuf, sizeof(cbuf),
949 PL_("%s\n%d gold per turn",
950 "%s\n%d gold per turn", output),
951 name, output);
952 } else if (improvement_has_flag(editor->currently_building.value.building,
953 IF_INFRA)) {
954 fc_snprintf(cbuf, sizeof(cbuf),
955 PL_("%s\n%d infrapoint per turn",
956 "%s\n%d infrapoints per turn", output),
957 name, output);
958 } else {
959 fc_snprintf(cbuf, sizeof(cbuf), "%s\n-", name);
960 }
961 } else {
962 if (stock < cost) {
963 turns = city_turns_to_build(editor->pcity,
964 &editor->currently_building, TRUE);
965 if (turns == 999) {
966 fc_snprintf(cbuf, sizeof(cbuf), _("%s\nblocked!"), name);
967 } else {
968 fc_snprintf(cbuf, sizeof(cbuf), _("%s\n%d %s"),
969 name, turns, PL_("turn", "turns", turns));
970 }
971 } else {
972 fc_snprintf(cbuf, sizeof(cbuf), _("%s\nfinished!"), name);
973 }
974 }
975 copy_chars_to_utf8_str(editor->production_name->string_utf8, cbuf);
976
977 widget_undraw(editor->production_name);
978 remake_label_size(editor->production_name);
979
980 editor->production_name->size.x = editor->end_widget_list->area.x +
981 (adj_size(130) - editor->production_name->size.w)/2;
982
983 /* Can't just widget_mark_dirty(), as it may have reduced in size */
984 area.x = editor->end_widget_list->area.x; /* left edge of client area */
985 area.y = editor->production_name->size.y;
986 area.w = adj_size(130);
987 area.h = editor->production_name->size.h;
988 layer_rect_to_screen_rect(editor->end_widget_list->dst, &area);
989
990 if (get_wflags(editor->production_name) & WF_RESTORE_BACKGROUND) {
991 refresh_widget_background(editor->production_name);
992 }
993
994 widget_redraw(editor->production_name);
995 dirty_sdl_rect(&area);
996
997 FREESURFACE(editor->production_progress->theme);
998 editor->production_progress->theme =
999 get_progress_icon(stock, cost, &cost);
1000
1001 if (!convert_prod) {
1002 fc_snprintf(cbuf, sizeof(cbuf), "%d%%" , cost);
1003 } else {
1004 fc_snprintf(cbuf, sizeof(cbuf), "-");
1005 }
1006 copy_chars_to_utf8_str(editor->production_progress->string_utf8, cbuf);
1007 widget_redraw(editor->production_progress);
1008 widget_mark_dirty(editor->production_progress);
1009}
1010
1011/**********************************************************************/
1015{
1016 char cbuf[64];
1017 SDL_Rect area;
1018 int len = worklist_length(&editor->worklist_copy);
1019
1020 if (editor->pcity != NULL) {
1021 len += 1; /* External entry from current production */
1022 }
1023
1024 fc_snprintf(cbuf, sizeof(cbuf),
1025 /* TRANS: length of worklist */
1026 PL_("( %d entry )", "( %d entries )", len), len);
1027 copy_chars_to_utf8_str(editor->worklist_counter->string_utf8, cbuf);
1028
1029 widget_undraw(editor->worklist_counter);
1030 remake_label_size(editor->worklist_counter);
1031
1032 editor->worklist_counter->size.x = editor->end_widget_list->area.x +
1033 (adj_size(130) - editor->worklist_counter->size.w)/2;
1034
1035 if (get_wflags(editor->worklist_counter) & WF_RESTORE_BACKGROUND) {
1036 refresh_widget_background(editor->worklist_counter);
1037 }
1038
1039 widget_redraw(editor->worklist_counter);
1040
1041 /* Can't just widget_mark_dirty(), as it may have reduced in size */
1042 area.x = editor->end_widget_list->area.x; /* left edge of client area */
1043 area.y = editor->worklist_counter->size.y;
1044 area.w = adj_size(130);
1045 area.h = editor->worklist_counter->size.h;
1046 layer_rect_to_screen_rect(editor->end_widget_list->dst, &area);
1047 dirty_sdl_rect(&area);
1048}
1049
1050/* ====================================================================== */
1051
1052/**********************************************************************/
1058{
1059 SDL_Color bg_color = {255,255,255,128};
1060 SDL_Color bg_color2 = {255,255,255,136};
1061 int count = 0, turns;
1062 int widget_w = 0, widget_h = 0;
1063 utf8_str *pstr = NULL;
1064 struct widget *buf = NULL, *pwindow, *last;
1065 SDL_Surface *text = NULL, *text_name = NULL, *zoomed = NULL;
1067 SDL_Surface *icon;
1068 SDL_Rect dst;
1069 char cbuf[128];
1070 struct unit_type *punittype = NULL;
1071 char *state = NULL;
1072 bool advanced_tech;
1074 SDL_Rect area;
1075 int len;
1076 const struct civ_map *nmap = &(wld.map);
1077
1078 if (editor) {
1079 return;
1080 }
1081
1082 editor = fc_calloc(1, sizeof(struct wl_editor));
1083
1084 if (pcity) {
1085 editor->pcity = pcity;
1086 editor->global_worklist_id = -1;
1087 editor->currently_building = pcity->production;
1088 editor->stock = pcity->shield_stock;
1089 worklist_copy(&editor->worklist_copy, &pcity->worklist);
1090 fc_snprintf(editor->worklist_name, sizeof(editor->worklist_name),
1091 "%s worklist", city_name_get(pcity));
1092 } else if (gwl != NULL) {
1093 editor->pcity = NULL;
1094 editor->global_worklist_id = global_worklist_id(gwl);
1095 worklist_copy(&editor->worklist_copy, global_worklist_get(gwl));
1096 sz_strlcpy(editor->worklist_name, global_worklist_name(gwl));
1097 } else {
1098 /* Not valid variant! */
1099 return;
1100 }
1101
1102 len = worklist_length(&editor->worklist_copy);
1103 advanced_tech = (pcity == NULL);
1104
1105 /* --------------- */
1106 /* Create Target Background Icon */
1107 main_surf = create_surf(adj_size(116), adj_size(116));
1109
1111 0, 0, main_surf->w - 1, main_surf->h - 1,
1113
1114 /* ---------------- */
1115 /* Create Main Window */
1116 pwindow = create_window_skeleton(NULL, NULL, 0);
1117 pwindow->action = window_worklist_editor_callback;
1118 set_wstate(pwindow, FC_WS_NORMAL);
1119
1120 add_to_gui_list(ID_WINDOW, pwindow);
1121 editor->end_widget_list = pwindow;
1122
1123 area = pwindow->area;
1124
1125 /* ---------------- */
1126 if (pcity) {
1127 fc_snprintf(cbuf, sizeof(cbuf), _("Worklist of\n%s"), city_name_get(pcity));
1128 len += 1; /* External entry from current production */
1129 } else {
1130 fc_snprintf(cbuf, sizeof(cbuf), "%s", global_worklist_name(gwl));
1131 }
1132
1134 pstr->style |= (TTF_STYLE_BOLD|SF_CENTER);
1135
1137
1139 /* --------------------------- */
1140
1141 fc_snprintf(cbuf, sizeof(cbuf),
1142 /* TRANS: Length of worklist */
1143 PL_("( %d entry )", "( %d entries )", len), len);
1145 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
1147 editor->worklist_counter = buf;
1149 /* --------------------------- */
1150
1151 /* Create production progress label or rename worklist edit */
1152 if (pcity) {
1153 /* count == cost */
1154 /* turns == progress */
1157
1159
1160 if (convert_prod) {
1161 int output = MAX(0, pcity->surplus[O_SHIELD]);
1162
1164 fc_snprintf(cbuf, sizeof(cbuf),
1165 PL_("%s\n%d gold per turn",
1166 "%s\n%d gold per turn", output),
1167 name, output);
1169 fc_snprintf(cbuf, sizeof(cbuf),
1170 PL_("%s\n%d infrapoint per turn",
1171 "%s\n%d infrapoints per turn", output),
1172 name, output);
1173 } else {
1174 fc_snprintf(cbuf, sizeof(cbuf), "%s\n-", name);
1175 }
1176 } else {
1177 if (pcity->shield_stock < count) {
1179 if (turns == 999) {
1180 fc_snprintf(cbuf, sizeof(cbuf), _("%s\nblocked!"), name);
1181 } else {
1182 fc_snprintf(cbuf, sizeof(cbuf), _("%s\n%d %s"),
1183 name, turns, PL_("turn", "turns", turns));
1184 }
1185 } else {
1186 fc_snprintf(cbuf, sizeof(cbuf), _("%s\nfinished!"), name);
1187 }
1188 }
1190 pstr->style |= SF_CENTER;
1192
1193 editor->production_name = buf;
1195
1196 icon = get_progress_icon(pcity->shield_stock, count, &turns);
1197
1198 if (!convert_prod) {
1199 fc_snprintf(cbuf, sizeof(cbuf), "%d%%" , turns);
1200 } else {
1201 fc_snprintf(cbuf, sizeof(cbuf), "-");
1202 }
1204 pstr->style |= (TTF_STYLE_BOLD|SF_CENTER);
1205
1206 buf = create_iconlabel(icon, pwindow->dst, pstr,
1208
1209 icon = NULL;
1210 turns = 0;
1211 editor->production_progress = buf;
1213 } else {
1214 buf = create_edit_from_chars_fonto(NULL, pwindow->dst,
1219
1221 }
1222
1223 /* --------------------------- */
1224 /* Commit Widget */
1225 buf = create_themeicon(current_theme->ok_icon, pwindow->dst, WF_RESTORE_BACKGROUND);
1226
1229 buf->key = SDLK_RETURN;
1230
1232 /* --------------------------- */
1233 /* Cancel Widget */
1234 buf = create_themeicon(current_theme->cancel_icon, pwindow->dst,
1236
1239 buf->key = SDLK_ESCAPE;
1240
1242 /* --------------------------- */
1243 /* work list */
1244
1245 /*
1246 pwidget->data filed will contains position of target in worklist all
1247 action on worklist (swap/romove/add) must correct this fields
1248
1249 Production Widget Label in worklist Widget list
1250 will have this field NULL
1251 */
1252
1253 editor->work = fc_calloc(1, sizeof(struct advanced_dialog));
1254
1255 editor->work->scroll = fc_calloc(1, sizeof(struct scroll_bar));
1256 editor->work->scroll->count = 0;
1257 editor->work->scroll->active = MAX_LEN_WORKLIST;
1258 editor->work->scroll->step = 1;
1259
1260/* FIXME: this should replace the 4 lines above, but
1261 * editor->work->end_widget_list is not set yet */
1262#if 0
1264#endif /* 0 */
1265
1266 if (pcity) {
1267 /* Production Widget Label */
1271 pstr->style |= SF_CENTER;
1273
1276
1277 add_to_gui_list(MAX_ID - cid_encode(pcity->production), buf);
1278
1279 editor->work->end_widget_list = buf;
1280 editor->work->begin_widget_list = buf;
1281 editor->work->end_active_widget_list = editor->work->end_widget_list;
1282 editor->work->begin_active_widget_list = editor->work->begin_widget_list;
1283 editor->work->scroll->count++;
1284 }
1285
1286 last = buf;
1287 editor->dock = buf;
1288
1289 /* Create Widget Labels of worklist entries */
1290
1291 count = 0;
1292
1293 worklist_iterate(&editor->worklist_copy, prod) {
1294 if (VUT_UTYPE == prod.kind) {
1297 } else {
1299 prod.value.building),
1301 }
1302 pstr->style |= SF_CENTER;
1303 buf = create_iconlabel(NULL, pwindow->dst, pstr,
1305
1308
1309 buf->data.ptr = fc_calloc(1, sizeof(int));
1310 *((int *)buf->data.ptr) = count;
1311
1313
1314 count++;
1315
1316 if (count > editor->work->scroll->active - 1) {
1318 }
1319
1321
1322 if (count) {
1323 if (!pcity) {
1324 editor->work->end_widget_list = last->prev;
1325 editor->work->end_active_widget_list = editor->work->end_widget_list;
1326 }
1327 editor->work->begin_widget_list = buf;
1328 editor->work->begin_active_widget_list = editor->work->begin_widget_list;
1329 } else {
1330 if (!pcity) {
1331 editor->work->end_widget_list = last;
1332 }
1333 editor->work->begin_widget_list = last;
1334 }
1335
1336/* FIXME */
1337#if 0
1338 editor->work->active_widget_list = editor->work->end_active_widget_list;
1340 editor->work->scroll->active, FALSE, TRUE);
1341 editor->work->scroll->up_left_button->size.w = adj_size(122);
1342 editor->work->scroll->down_right_button->size.w = adj_size(122);
1343
1344 /* count: without production */
1345 if (count <= editor->work->scroll->active + 1) {
1346 if (count > 0) {
1347 struct widget *tmp = last;
1348
1349 do {
1350 tmp = tmp->prev;
1352 } while (tmp != buf);
1353 }
1354 hide_scrollbar(editor->work->scroll);
1355 }
1356#endif /* 0 */
1357
1358 editor->work->scroll->count += count;
1359 last = editor->work->begin_widget_list;
1360
1361 /* --------------------------- */
1362 /* Global worklists */
1363 if (pcity) {
1364 count = 0;
1365
1373 buf->string_utf8->style |= SF_CENTER;
1374 buf->action = global_worklist_callback;
1375 buf->string_utf8->fgcol = bg_color;
1376
1377 count++;
1378
1379 if (count > 4) {
1381 }
1383
1384 if (count) {
1385 editor->global = fc_calloc(1, sizeof(struct advanced_dialog));
1386 editor->global->end_widget_list = last->prev;
1387 editor->global->end_active_widget_list = editor->global->end_widget_list;
1388 editor->global->begin_widget_list = buf;
1389 editor->global->begin_active_widget_list = editor->global->begin_widget_list;
1390
1391 if (count > 6) {
1392 editor->global->active_widget_list = editor->global->end_active_widget_list;
1393
1394 create_vertical_scrollbar(editor->global, 1, 4, FALSE, TRUE);
1395 editor->global->scroll->up_left_button->size.w = adj_size(122);
1396 editor->global->scroll->down_right_button->size.w = adj_size(122);
1397 } else {
1398 struct widget *tmp = last;
1399
1400 do {
1401 tmp = tmp->prev;
1403 } while (tmp != buf);
1404 }
1405
1406 last = editor->global->begin_widget_list;
1407 }
1408 }
1409 /* ----------------------------- */
1410 count = 0;
1411 /* Targets units and imprv. to build */
1413 pstr->style |= (SF_CENTER|TTF_STYLE_BOLD);
1414 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
1415
1416 improvement_iterate(pimprove) {
1420
1421 /* If there's a city, can the city build the improvement? */
1422 if (pcity) {
1426 }
1427
1429 || (!advanced_tech && can_build)) {
1430
1432
1433 fc_snprintf(cbuf, sizeof(cbuf), "%s", improvement_name_translation(pimprove));
1435 pstr->style |= TTF_STYLE_BOLD;
1436
1437 if (pcity && is_improvement_redundant(pcity, pimprove)) {
1438 pstr->style |= TTF_STYLE_STRIKETHROUGH;
1439 }
1440
1442
1443 if (is_wonder(pimprove)) {
1444 if (improvement_obsolete(client.conn.playing, pimprove, pcity)) {
1445 state = _("Obsolete");
1446 } else if (is_great_wonder(pimprove)) {
1447 if (great_wonder_is_built(pimprove)) {
1448 state = _("Built");
1449 } else if (great_wonder_is_destroyed(pimprove)) {
1450 state = _("Destroyed");
1451 } else {
1452 state = _("Great Wonder");
1453 }
1454 } else if (is_small_wonder(pimprove)) {
1455 if (small_wonder_is_built(client.conn.playing, pimprove)) {
1456 state = _("Built");
1457 } else {
1458 state = _("Small Wonder");
1459 }
1460 }
1461 } else {
1462 state = NULL;
1463 }
1464
1465 if (pcity) {
1466 if (!is_convert_improvement(pimprove)) {
1467 struct universal univ = cid_production(cid_encode_building(pimprove));
1468 int cost = impr_build_shield_cost(pcity, pimprove);
1469
1470 turns = city_turns_to_build(pcity, &univ, TRUE);
1471
1472 if (turns == FC_INFINITY) {
1473 if (state) {
1474 fc_snprintf(cbuf, sizeof(cbuf), _("(%s)\n%d/%d %s\n%s"),
1475 state, pcity->shield_stock, cost,
1476 PL_("shield", "shields", cost),
1477 _("never"));
1478 } else {
1479 fc_snprintf(cbuf, sizeof(cbuf), _("%d/%d %s\n%s"),
1480 pcity->shield_stock, cost,
1481 PL_("shield", "shields", cost), _("never"));
1482 }
1483 } else {
1484 if (state) {
1485 fc_snprintf(cbuf, sizeof(cbuf), _("(%s)\n%d/%d %s\n%d %s"),
1486 state, pcity->shield_stock, cost,
1487 PL_("shield", "shields", cost),
1488 turns, PL_("turn", "turns", turns));
1489 } else {
1490 fc_snprintf(cbuf, sizeof(cbuf), _("%d/%d %s\n%d %s"),
1491 pcity->shield_stock, cost,
1492 PL_("shield", "shields", cost),
1493 turns, PL_("turn", "turns", turns));
1494 }
1495 }
1496 } else {
1497 int output = MAX(0, pcity->surplus[O_SHIELD]);
1498
1499 /* Coinage-like */
1500 if (improvement_has_flag(pimprove, IF_GOLD)) {
1501 fc_snprintf(cbuf, sizeof(cbuf), PL_("%d gold per turn",
1502 "%d gold per turn", output),
1503 output);
1504 } else if (improvement_has_flag(pimprove, IF_INFRA)) {
1505 fc_snprintf(cbuf, sizeof(cbuf), PL_("%d infrapoint per turn",
1506 "%d infrapoints per turn", output),
1507 output);
1508 } else {
1509 fc_strlcpy(cbuf, "-", sizeof(cbuf));
1510 }
1511 }
1512 } else {
1513 /* Non city mode */
1514 if (!is_convert_improvement(pimprove)) {
1515 int cost = impr_build_shield_cost(NULL, pimprove);
1516
1517 if (state) {
1518 fc_snprintf(cbuf, sizeof(cbuf), _("(%s)\n%d %s"),
1519 state, cost,
1520 PL_("shield", "shields", cost));
1521 } else {
1522 fc_snprintf(cbuf, sizeof(cbuf), _("%d %s"),
1523 cost,
1524 PL_("shield", "shields", cost));
1525 }
1526 } else {
1527 if (improvement_has_flag(pimprove, IF_GOLD)) {
1528 fc_strlcpy(cbuf, _("shields into gold"), sizeof(cbuf));
1529 } else if (improvement_has_flag(pimprove, IF_INFRA)) {
1530 fc_strlcpy(cbuf, _("shields into infrapoints"), sizeof(cbuf));
1531 } else {
1532 fc_strlcpy(cbuf, "-", sizeof(cbuf));
1533 }
1534 }
1535 }
1536
1538 pstr->style &= ~TTF_STYLE_BOLD;
1540
1542
1543 /*-----------------*/
1544
1545 zoomed = get_building_surface(pimprove);
1546 zoomed = zoomSurface(zoomed, DEFAULT_ZOOM * ((float)54 / zoomed->w),
1547 DEFAULT_ZOOM * ((float)54 / zoomed->w), 1);
1548 dst.x = (icon->w - zoomed->w) / 2;
1549 dst.y = (icon->h/2 - zoomed->h) / 2;
1550 alphablit(zoomed, NULL, icon, &dst, 255);
1551 dst.y += zoomed->h;
1553
1554 dst.x = (icon->w - text_name->w) / 2;
1555 dst.y += ((icon->h - dst.y) - (text_name->h + text->h)) / 2;
1556 alphablit(text_name, NULL, icon, &dst, 255);
1557
1558 dst.x = (icon->w - text->w) / 2;
1559 dst.y += text_name->h;
1560 alphablit(text, NULL, icon, &dst, 255);
1561
1562 FREESURFACE(text);
1564
1565 buf = create_icon2(icon, pwindow->dst,
1568
1569 widget_w = MAX(widget_w, buf->size.w);
1570 widget_h = MAX(widget_h, buf->size.h);
1571
1572 buf->data.city = pcity;
1575
1576 if (count > (TARGETS_ROW * TARGETS_COL - 1)) {
1578 }
1579 count++;
1580 }
1582
1583 /* ------------------------------ */
1584
1589
1590 /* If there's a city, can the city build the unit? */
1591 if (pcity) {
1595 }
1596
1598 || (!advanced_tech && can_build)) {
1599
1600 punittype = un;
1601
1603
1604 fc_snprintf(cbuf, sizeof(cbuf), "%s", utype_name_translation(un));
1605
1607 pstr->style |= TTF_STYLE_BOLD;
1609
1610 if (pcity) {
1613
1614 turns = city_turns_to_build(pcity, &univ, TRUE);
1615
1616 if (turns == FC_INFINITY) {
1617 fc_snprintf(cbuf, sizeof(cbuf),
1618 _("(%d/%d/%s)\n%d/%d %s\nnever"),
1619 punittype->attack_strength,
1620 punittype->defense_strength,
1621 move_points_text(punittype->move_rate, TRUE),
1622 pcity->shield_stock, cost,
1623 PL_("shield", "shields", cost));
1624 } else {
1625 fc_snprintf(cbuf, sizeof(cbuf),
1626 _("(%d/%d/%s)\n%d/%d %s\n%d %s"),
1627 punittype->attack_strength,
1628 punittype->defense_strength,
1629 move_points_text(punittype->move_rate, TRUE),
1630 pcity->shield_stock, cost,
1631 PL_("shield", "shields", cost),
1632 turns, PL_("turn", "turns", turns));
1633 }
1634 } else {
1636
1637 fc_snprintf(cbuf, sizeof(cbuf),
1638 _("(%d/%d/%s)\n%d %s"),
1639 punittype->attack_strength,
1640 punittype->defense_strength,
1641 move_points_text(punittype->move_rate, TRUE),
1642 cost,
1643 PL_("shield", "shields", cost));
1644 }
1645
1647 pstr->style &= ~TTF_STYLE_BOLD;
1648
1650
1652 dst.x = (icon->w - zoomed->w) / 2;
1653 dst.y = (icon->h / 2 - zoomed->h) / 2;
1654 alphablit(zoomed, NULL, icon, &dst, 255);
1656
1657 dst.x = (icon->w - text_name->w) / 2;
1658 dst.y = icon->h / 2 + (icon->h / 2 - (text_name->h + text->h)) / 2;
1659 alphablit(text_name, NULL, icon, &dst, 255);
1660
1661 dst.x = (icon->w - text->w) / 2;
1662 dst.y += text_name->h;
1663 alphablit(text, NULL, icon, &dst, 255);
1664
1665 FREESURFACE(text);
1667
1668 buf = create_icon2(icon, pwindow->dst,
1671
1672 widget_w = MAX(widget_w, buf->size.w);
1673 widget_h = MAX(widget_h, buf->size.h);
1674
1675 buf->data.city = pcity;
1678
1679 if (count > (TARGETS_ROW * TARGETS_COL - 1)) {
1681 }
1682 count++;
1683
1684 }
1686
1687 editor->targets = fc_calloc(1, sizeof(struct advanced_dialog));
1688
1689 editor->targets->end_widget_list = last->prev;
1690 editor->targets->begin_widget_list = buf;
1691 editor->targets->end_active_widget_list = editor->targets->end_widget_list;
1692 editor->targets->begin_active_widget_list = editor->targets->begin_widget_list;
1693 editor->targets->active_widget_list = editor->targets->end_active_widget_list;
1694
1695 /* --------------- */
1696 if (count > (TARGETS_ROW * TARGETS_COL - 1)) {
1697 count = create_vertical_scrollbar(editor->targets,
1699 } else {
1700 count = 0;
1701 }
1702 /* --------------- */
1703
1704 editor->begin_widget_list = editor->targets->begin_widget_list;
1705
1706 /* Window */
1707 area.w = MAX(area.w, widget_w * TARGETS_COL + count + adj_size(130));
1708 area.h = MAX(area.h, widget_h * TARGETS_ROW);
1709
1711 if (resize_window(pwindow, icon, NULL,
1712 (pwindow->size.w - pwindow->area.w) + area.w,
1713 (pwindow->size.h - pwindow->area.h) + area.h)) {
1714 FREESURFACE(icon);
1715 }
1716
1717 area = pwindow->area;
1718
1719 /* Backgrounds */
1720 dst.x = area.x;
1721 dst.y = area.y;
1722 dst.w = adj_size(130);
1723 dst.h = adj_size(145);
1724
1725 SDL_FillSurfaceRect(pwindow->theme, &dst,
1726 map_rgba(pwindow->theme->format,
1728
1729 create_frame(pwindow->theme,
1730 dst.x, dst.y, dst.w - 1, dst.h - 1,
1732 create_frame(pwindow->theme,
1733 dst.x + 2, dst.y + 2, dst.w - 5, dst.h - 5,
1735
1736 dst.x = area.x;
1737 dst.y += dst.h + adj_size(2);
1738 dst.w = adj_size(130);
1739 dst.h = adj_size(228);
1740 fill_rect_alpha(pwindow->theme, &dst, &bg_color2);
1741
1742 create_frame(pwindow->theme,
1743 dst.x, dst.y, dst.w - 1, dst.h - 1,
1745
1746 if (editor->global) {
1747 dst.x = area.x;
1748 dst.y += dst.h + adj_size(2);
1749 dst.w = adj_size(130);
1750 dst.h = pwindow->size.h - dst.y - adj_size(4);
1751
1752 SDL_FillSurfaceRect(pwindow->theme, &dst,
1753 map_rgba(pwindow->theme->format,
1755
1756 create_frame(pwindow->theme,
1757 dst.x, dst.y, dst.w - 1, dst.h - 1,
1759 create_frame(pwindow->theme,
1760 dst.x + adj_size(2), dst.y + adj_size(2),
1761 dst.w - adj_size(5), dst.h - adj_size(5),
1763 }
1764
1765 widget_set_position(pwindow,
1766 (main_window_width() - pwindow->size.w) / 2,
1767 (main_window_height() - pwindow->size.h) / 2);
1768
1769 /* Name */
1770 buf = pwindow->prev;
1771 buf->size.x = area.x + (adj_size(130) - buf->size.w) / 2;
1772 buf->size.y = area.y + adj_size(4);
1773
1774 /* Size of worklist (without production) */
1775 buf = buf->prev;
1776 buf->size.x = area.x + (adj_size(130) - buf->size.w) / 2;
1777 buf->size.y = buf->next->size.y + buf->next->size.h;
1778
1779 if (pcity) {
1780 /* Current build and progress bar */
1781 buf = buf->prev;
1782 buf->size.x = area.x + (adj_size(130) - buf->size.w) / 2;
1783 buf->size.y = buf->next->size.y + buf->next->size.h + adj_size(5);
1784
1785 buf = buf->prev;
1786 buf->size.x = area.x + (adj_size(130) - buf->size.w) / 2;
1787 buf->size.y = buf->next->size.y + buf->next->size.h;
1788 } else {
1789 /* Rename worklist */
1790 buf = buf->prev;
1791 buf->size.x = area.x + (adj_size(130) - buf->size.w) / 2;
1792 buf->size.y = area.y + 1 + (adj_size(145) - buf->size.h) / 2;
1793 }
1794
1795 /* Ok button */
1796 buf = buf->prev;
1797 buf->size.x = area.x + (adj_size(65) - buf->size.w) / 2;
1798 buf->size.y = area.y + adj_size(135) - buf->size.h;
1799
1800 /* Exit button */
1801 buf = buf->prev;
1802 buf->size.x = area.x + adj_size(65) + (adj_size(65) - buf->size.w) / 2;
1803 buf->size.y = area.y + adj_size(135) - buf->size.h;
1804
1805 /* Worklist */
1806 /* editor->work->scroll->count: including production */
1807 if (len > 0) {
1808 /* FIXME */
1810 area.x + adj_size(2), area.y + adj_size(152)
1811 /* + ((editor->work->scroll->count > editor->work->scroll->active + 2) ?
1812 editor->work->scroll->up_left_button->size.h + 1 : 0)*/,
1813 adj_size(126), 0, editor->work->begin_widget_list,
1814 editor->work->end_widget_list);
1815
1817 area.x + adj_size(2),
1818 area.y + adj_size(152),
1819 adj_size(225), FALSE);
1820 }
1821
1822 /* Global worklists */
1823 if (editor->global) {
1825 area.x + adj_size(4),
1826 area.y + adj_size(384) +
1827 (editor->global->scroll ?
1828 editor->global->scroll->up_left_button->size.h + 1 : 0),
1829 adj_size(122), 0, editor->global->begin_widget_list,
1830 editor->global->end_widget_list);
1831
1832 if (editor->global->scroll) {
1833 setup_vertical_scrollbar_area(editor->global->scroll,
1834 area.x + adj_size(4),
1835 area.y + adj_size(384),
1836 adj_size(93), FALSE);
1837 }
1838
1839 }
1840
1841 /* Targets */
1843 area.x + adj_size(130), area.y,
1844 0, 0, editor->targets->begin_widget_list,
1845 editor->targets->end_widget_list);
1846
1847 if (editor->targets->scroll) {
1848 setup_vertical_scrollbar_area(editor->targets->scroll,
1849 area.x + area.w,
1850 area.y + 1,
1851 area.h - 1, TRUE);
1852
1853 }
1854
1855 /* ----------------------------------- */
1858
1859 redraw_group(editor->begin_widget_list, pwindow, 0);
1860 widget_flush(pwindow);
1861}
1862
1863/**********************************************************************/
1867{
1868 if (editor) {
1869 popdown_window_group_dialog(editor->begin_widget_list,
1870 editor->end_widget_list);
1871 FC_FREE(editor->targets->scroll);
1872 FC_FREE(editor->targets);
1873
1874 FC_FREE(editor->work->scroll);
1875 FC_FREE(editor->work);
1876
1877 if (editor->global) {
1878 FC_FREE(editor->global->scroll);
1879 FC_FREE(editor->global);
1880 }
1881
1882 if (city_dialog_is_open(editor->pcity)) {
1884 }
1885
1886 FC_FREE(editor);
1887
1888 flush_dirty();
1889 }
1890}
SDL_Surface * zoomSurface(SDL_Surface *src, double zoomx, double zoomy, int smooth)
Zoom a surface by independent horizontal and vertical factors with optional smoothing.
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:1965
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:663
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:737
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1031
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:727
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:820
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1886
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:947
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:717
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:871
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:970
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:700
int city_set_worklist(struct city *pcity, const struct worklist *pworklist)
int city_change_production(struct city *pcity, struct universal *target)
struct civclient client
#define client_player()
cid cid_encode_building(const struct impr_type *pimprove)
Definition climisc.c:505
cid cid_encode(struct universal target)
Definition climisc.c:483
struct universal cid_decode(cid id)
Definition climisc.c:526
cid cid_encode_unit(const struct unit_type *punittype)
Definition climisc.c:493
#define cid_production
Definition climisc.h:71
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
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 cost
Definition dialogs_g.h:74
int int id
Definition editgui_g.h:28
static struct editor_state * editor
Definition editor.c:100
QString current_theme
Definition fc_client.cpp:64
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_SHIELD
Definition fc_types.h:101
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
struct world wld
Definition game.c:62
struct global_worklist * global_worklist_by_id(int id)
bool global_worklist_set(struct global_worklist *pgwl, const struct worklist *pwl)
const char * global_worklist_name(const struct global_worklist *pgwl)
int global_worklist_id(const struct global_worklist *pgwl)
const struct worklist * global_worklist_get(const struct global_worklist *pgwl)
void global_worklist_set_name(struct global_worklist *pgwl, const char *name)
#define global_worklists_iterate(pgwl)
#define global_worklists_iterate_end
bool city_dialog_is_open(struct city *pcity)
Definition citydlg.c:587
void flush_dirty(void)
Definition mapview.c:468
void update_worklist_report_dialog(void)
Definition wldlg.c:116
void enable_city_dlg_widgets(void)
Definition citydlg.c:1535
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
int main_window_width(void)
Definition graphics.c:685
void layer_rect_to_screen_rect(struct gui_layer *gui_layer, SDL_Rect *dest_rect)
Definition graphics.c:185
int fill_rect_alpha(SDL_Surface *surf, SDL_Rect *prect, SDL_Color *pcolor)
Definition graphics.c:865
SDL_Surface * crop_rect_from_surface(SDL_Surface *psource, SDL_Rect *prect)
Definition graphics.c:236
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
SDL_Surface * create_surf(int width, int height, Uint32 flags)
Definition graphics.c:351
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 DEFAULT_ZOOM
Definition graphics.h:198
#define FREESURFACE(ptr)
Definition graphics.h:322
#define adj_surf(surf)
Definition graphics.h:200
#define map_rgba(format, color)
Definition graphics.h:315
@ ID_BUTTON
Definition gui_id.h:29
@ ID_EDIT
Definition gui_id.h:34
@ ID_LABEL
Definition gui_id.h:27
@ ID_WINDOW
Definition gui_id.h:30
#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
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
SDL_Surface * create_text_surf_smaller_than_w(utf8_str *pstr, int w)
Definition gui_string.c:539
#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
static SDL_Surface * get_building_surface(const struct impr_type *pimprove)
static SDL_Surface * get_unittype_surface(const struct unit_type *punittype, enum direction8 facing)
void popup_impr_info(Impr_type_id impr)
Definition helpdlg.c:202
void popup_unit_info(Unit_type_id type_id)
Definition helpdlg.c:630
void dirty_sdl_rect(SDL_Rect *Rect)
Definition mapview.c:181
SDL_Surface * theme_get_background(const struct theme *t, enum theme_background background)
@ BACKGROUND_WLDLG
@ COLOR_THEME_BACKGROUND
Definition themecolors.h:24
@ COLOR_THEME_WLDLG_FRAME
struct theme * active_theme
Definition themespec.c:154
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
struct widget * get_widget_pointer_from_main_list(Uint16 id)
Definition widget.c:578
void refresh_widget_background(struct widget *pwidget)
Definition widget.c:1151
SDL_Surface * create_bcgnd_surf(SDL_Surface *ptheme, enum widget_state state, Uint16 width, Uint16 height)
Definition widget.c:78
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
void clear_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:62
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
static void widget_undraw(struct widget *pwidget)
Definition widget.h:296
@ WF_ICON_CENTER
Definition widget.h:83
@ WF_FREE_DATA
Definition widget.h:78
@ 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
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
#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)
struct widget * create_icon2(SDL_Surface *icon, 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)
#define show_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)
static void get_target_help_data(struct widget *target)
Definition wldlg.c:388
static void add_target_to_worklist(struct widget *target)
Definition wldlg.c:206
static void set_global_worklist(struct widget *pwidget)
Definition wldlg.c:749
static bool are_prods_same_class(const struct universal *one, const struct universal *two)
Definition wldlg.c:303
static const char * get_production_name(struct city *pcity, struct universal prod, int *cost)
Definition wldlg.c:880
static int window_worklist_editor_callback(struct widget *pwidget)
Definition wldlg.c:103
static void add_target_to_production(struct widget *target)
Definition wldlg.c:350
static void swap_item_down_from_worklist(struct widget *item)
Definition wldlg.c:530
static int popdown_worklist_editor_callback(struct widget *pwidget)
Definition wldlg.c:111
static int ok_worklist_editor_callback(struct widget *pwidget)
Definition wldlg.c:124
static SDL_Surface * get_progress_icon(int stock, int cost, int *progress)
Definition wldlg.c:900
void popup_worklist_editor(struct city *pcity, struct global_worklist *gwl)
Definition wldlg.c:1061
#define TARGETS_ROW
Definition wldlg.c:64
static void remove_item_from_worklist(struct widget *item)
Definition wldlg.c:454
static void refresh_worklist_count_label(void)
Definition wldlg.c:1018
static int worklist_editor_item_callback(struct widget *pwidget)
Definition wldlg.c:639
static int global_worklist_callback(struct widget *pwidget)
Definition wldlg.c:851
void popdown_worklist_editor(void)
Definition wldlg.c:1870
static int worklist_editor_targets_callback(struct widget *pwidget)
Definition wldlg.c:415
#define TARGETS_COL
Definition wldlg.c:63
static void add_global_worklist(struct widget *pwidget)
Definition wldlg.c:670
static void swap_item_up_from_worklist(struct widget *item)
Definition wldlg.c:587
static int rename_worklist_editor_callback(struct widget *pwidget)
Definition wldlg.c:183
static void change_production(struct universal *prod)
Definition wldlg.c:325
static void refresh_production_label(int stock)
Definition wldlg.c:937
bool great_wonder_is_built(const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
bool can_player_build_improvement_now(const struct player *p, struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
bool small_wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
bool is_convert_improvement(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1016
int len
Definition packhand.c:127
int universal_build_shield_cost(const struct city *pcity, const struct universal *target)
bool are_universals_equal(const struct universal *psource1, const struct universal *psource2)
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
Definition city.h:317
struct connection conn
Definition client_main.h:96
struct player * playing
Definition connection.h:151
Definition climisc.h:82
SDL_Event event
Definition graphics.h:217
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
char * text
Definition gui_string.h:60
struct widget * prev
Definition widget.h:114
struct gui_layer * dst
Definition widget.h:116
utf8_str * string_utf8
Definition widget.h:121
SDL_Rect area
Definition widget.h:149
Uint16 id
Definition widget.h:155
struct widget * worklist_counter
Definition wldlg.c:81
struct worklist worklist_copy
Definition wldlg.c:76
int global_worklist_id
Definition wldlg.c:75
struct widget * production_name
Definition wldlg.c:83
int stock
Definition wldlg.c:86
struct advanced_dialog * global
Definition wldlg.c:72
char worklist_name[MAX_LEN_NAME]
Definition wldlg.c:77
struct universal currently_building
Definition wldlg.c:87
struct widget * production_progress
Definition wldlg.c:84
struct widget * dock
Definition wldlg.c:80
struct advanced_dialog * targets
Definition wldlg.c:70
struct advanced_dialog * work
Definition wldlg.c:71
struct widget * begin_widget_list
Definition wldlg.c:67
struct widget * end_widget_list
Definition wldlg.c:68
struct city * pcity
Definition wldlg.c:74
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const struct unit_type * utype
Definition fc_types.h:553
const struct impr_type * building
Definition fc_types.h:546
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:100
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2105
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1444
bool can_player_build_unit_now(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2084
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1566
#define unit_type_iterate(_p)
Definition unittype.h:862
#define unit_type_iterate_end
Definition unittype.h:869
void worklist_advance(struct worklist *pwl)
Definition worklist.c:104
void worklist_copy(struct worklist *dst, const struct worklist *src)
Definition worklist.c:112
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
bool worklist_is_empty(const struct worklist *pwl)
Definition worklist.c:66
bool worklist_append(struct worklist *pwl, const struct universal *prod)
Definition worklist.c:147
void worklist_remove(struct worklist *pwl, int idx)
Definition worklist.c:122
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57
#define worklist_iterate_end
Definition worklist.h:59
#define worklist_iterate(_list, _p)
Definition worklist.h:51
#define MAX_LEN_WORKLIST
Definition worklist.h:24