1 /***********************************************************************
2 Freeciv - Copyright (C) 2003 - The Freeciv Project
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)
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 ***********************************************************************/
15 #include <fc_config.h>
21 #include <X11/Intrinsic.h>
22 #include <X11/StringDefs.h>
23 #include <X11/Xaw/Form.h>
24 #include <X11/Xaw/Label.h>
25 #include <X11/Xaw/Command.h>
26 #include <X11/Xaw/MenuButton.h>
27 #include <X11/Xaw/Scrollbar.h>
28 #include <X11/Xaw/SimpleMenu.h>
29 #include <X11/Xaw/SmeBSB.h>
30 #include <X11/Xaw/List.h>
31 #include <X11/Xaw/Viewport.h>
32 #include <X11/Xaw/AsciiText.h>
33 #include <X11/Xaw/Toggle.h>
34 #include <X11/IntrinsicP.h>
55 #include "client_main.h"
66 #include "gui_stuff.h"
71 #include "optiondlg.h"
75 Widget
*stat_surplus_label
, *stat_factor_label
;
76 Widget control_button
, change_button
, preset_list
, cma_dialog
;
77 Widget celebrate_toggle
, result_label
, release_button
;
78 Widget surplus_slider
[O_LAST
], factor_slider
[O_LAST
+ 1];
80 int minimal_surplus
[O_LAST
], factors
[O_LAST
+ 1];
81 struct city
*current_city
;
82 char *initial_preset_list
[] = {
83 N_("For information on\n"
84 "the citizen governor and governor presets,\n"
85 "including sample presets,\n"
86 "see README.governor."),
90 static void update_cma_preset_list(void);
91 static void control_city(Widget w
, XtPointer client_data
,
93 static void release_city(Widget w
, XtPointer client_data
,
96 static void add_preset(Widget w
, XtPointer client_data
,
98 static void remove_preset(Widget w
, XtPointer client_data
,
100 static void remove_preset_yes(Widget w
, XtPointer client_data
,
101 XtPointer call_data
);
102 static void remove_preset_no(Widget w
, XtPointer client_data
,
103 XtPointer call_data
);
104 static void select_preset(Widget w
, XtPointer client_data
,
105 XtPointer call_data
);
106 static void cma_help(Widget w
, XtPointer client_data
,
107 XtPointer call_data
);
108 static void set_slider_values(void);
109 static void sliders_jump_callback(Widget w
, XtPointer client_data
,
110 XtPointer position_val
);
111 static void sliders_scroll_callback(Widget w
, XtPointer client_data
,
112 XtPointer position_val
);
113 static void update_stat_labels(bool is_valid
);
114 static void new_preset_callback(Widget w
, XtPointer client_data
,
115 XtPointer call_data
);
116 static void celebrate_callback(Widget w
, XtPointer client_data
,
117 XtPointer position_val
);
118 static void close_callback(Widget w
, XtPointer client_data
,
119 XtPointer call_data
);
120 static void change_callback(Widget w
, XtPointer client_data
,
121 XtPointer call_data
);
124 /**************************************************************************
125 Show the Citizen Management Agent Dialog for the current city.
126 **************************************************************************/
127 void show_cma_dialog(struct city
*pcity
, Widget citydlg
)
129 Widget add_button
, remove_button
, help_button
;
130 Widget form
, preset_viewport
, close_button
;
131 Widget surplus_header
, factor_header
, prev
;
132 struct cm_parameter parameter
;
133 struct cm_result
*result
= cm_result_new(pcity
);
136 current_city
= pcity
;
137 stat_surplus_label
= fc_malloc((O_LAST
+ 1) * sizeof(Widget
));
138 stat_factor_label
= fc_malloc((O_LAST
+ 1) * sizeof(Widget
));
141 I_T(XtCreatePopupShell("cmapopup",
142 topLevelShellWidgetClass
,
146 XtVaCreateManagedWidget("cmaform",
151 XtVaCreateManagedWidget("cmapresetviewport",
152 viewportWidgetClass
, form
,
156 XtVaCreateManagedWidget("cmapresetlist",
157 listWidgetClass
, preset_viewport
,
158 XtNlist
, (XtArgVal
)initial_preset_list
,
162 I_L(XtVaCreateManagedWidget("cmaresultlabel",
163 labelWidgetClass
, form
,
164 XtNfromHoriz
, preset_viewport
,
168 I_L(XtVaCreateManagedWidget("cmasurpluslabel",
169 labelWidgetClass
, form
,
170 XtNfromHoriz
, preset_viewport
,
171 XtNfromVert
, result_label
,
174 /* Create labels in the minimal surplus column. */
175 prev
= surplus_header
;
176 for (i
= 0; i
< (O_LAST
+ 1); i
++) {
177 I_L(stat_surplus_label
[i
] =
178 XtVaCreateManagedWidget("cmastatlabel",
179 labelWidgetClass
, form
,
180 XtNfromHoriz
, preset_viewport
,
183 XtNlabel
, (i
== O_LAST
) ?
184 _("Celebrate") : get_output_name(i
),
186 prev
= stat_surplus_label
[i
];
189 /* Create scrollbars in the minimal surplus column. */
190 prev
= surplus_header
;
191 output_type_iterate(o
) {
193 XtVaCreateManagedWidget("cmapresetscroll",
194 scrollbarWidgetClass
, form
,
195 XtNfromHoriz
, stat_surplus_label
[o
],
198 prev
= stat_surplus_label
[o
];
199 } output_type_iterate_end
;
202 I_L(XtVaCreateManagedWidget("cmapresettoggle",
203 toggleWidgetClass
,form
,
204 XtNfromHoriz
, stat_surplus_label
[0],
205 XtNfromVert
, stat_surplus_label
[O_LAST
- 1],
208 /* Create header label in the factor column. */
210 I_L(XtVaCreateManagedWidget("cmafactorlabel",
211 labelWidgetClass
, form
,
212 XtNfromHoriz
, surplus_slider
[0],
213 XtNfromVert
, result_label
,
216 /* Create stat labels in the factor column. */
217 prev
= factor_header
;
218 for (i
= 0; i
< (O_LAST
+ 1); i
++) {
219 I_L(stat_factor_label
[i
] =
220 XtVaCreateManagedWidget("cmastatlabel",
221 labelWidgetClass
, form
,
222 XtNfromHoriz
, surplus_slider
[0],
225 XtNlabel
, (i
== O_LAST
) ?
226 _("Celebrate") : get_output_name(i
),
228 prev
= stat_factor_label
[i
];
231 /* Create scrollbars in the factor column. */
232 prev
= factor_header
;
233 for (i
= 0; i
< (O_LAST
+ 1); i
++) {
235 XtVaCreateManagedWidget("cmapresetscroll",
236 scrollbarWidgetClass
, form
,
237 XtNfromHoriz
, stat_factor_label
[i
],
240 prev
= stat_factor_label
[i
];
244 I_L(XtVaCreateManagedWidget("cmaclosebutton",
245 commandWidgetClass
, form
,
246 XtNfromVert
, preset_viewport
,
250 I_L(XtVaCreateManagedWidget("cmacontrolbutton",
251 commandWidgetClass
, form
,
252 XtNfromVert
, preset_viewport
,
253 XtNfromHoriz
, close_button
,
257 I_L(XtVaCreateManagedWidget("cmareleasebutton",
258 commandWidgetClass
, form
,
259 XtNfromVert
, preset_viewport
,
260 XtNfromHoriz
, control_button
,
264 I_L(XtVaCreateManagedWidget("cmachangebutton",
265 commandWidgetClass
, form
,
266 XtNfromVert
, preset_viewport
,
267 XtNfromHoriz
, release_button
,
271 I_L(XtVaCreateManagedWidget("cmaaddbutton",
272 commandWidgetClass
, form
,
273 XtNfromVert
, preset_viewport
,
274 XtNfromHoriz
, change_button
,
278 I_L(XtVaCreateManagedWidget("cmaremovebutton",
279 commandWidgetClass
, form
,
280 XtNfromVert
, preset_viewport
,
281 XtNfromHoriz
, add_button
,
285 I_L(XtVaCreateManagedWidget("cmahelpbutton",
286 commandWidgetClass
, form
,
287 XtNfromVert
, preset_viewport
,
288 XtNfromHoriz
, remove_button
,
291 XtAddCallback(control_button
, XtNcallback
, control_city
,
292 (XtPointer
)preset_list
);
293 XtAddCallback(release_button
, XtNcallback
, release_city
,
294 (XtPointer
)preset_list
);
295 XtAddCallback(change_button
, XtNcallback
, change_callback
,
296 (XtPointer
)preset_list
);
297 XtAddCallback(add_button
, XtNcallback
, add_preset
,
298 (XtPointer
)preset_list
);
299 XtAddCallback(remove_button
, XtNcallback
, remove_preset
,
300 (XtPointer
)preset_list
);
301 XtAddCallback(preset_list
, XtNcallback
, select_preset
,
302 (XtPointer
)preset_list
);
303 XtAddCallback(help_button
, XtNcallback
, cma_help
,
304 (XtPointer
)preset_list
);
305 XtAddCallback(celebrate_toggle
, XtNcallback
,
306 celebrate_callback
, NULL
);
307 XtAddCallback(close_button
, XtNcallback
,
308 close_callback
, NULL
);
310 output_type_iterate(o
) {
311 XtAddCallback(surplus_slider
[o
], XtNscrollProc
,
312 sliders_scroll_callback
, NULL
);
313 XtAddCallback(surplus_slider
[o
], XtNjumpProc
,
314 sliders_jump_callback
, NULL
);
315 } output_type_iterate_end
;
317 for (i
= 0; i
< (O_LAST
+ 1); i
++) {
318 XtAddCallback(factor_slider
[i
], XtNscrollProc
,
319 sliders_scroll_callback
, NULL
);
320 XtAddCallback(factor_slider
[i
], XtNjumpProc
,
321 sliders_jump_callback
, NULL
);
324 /* Update dialog with CMA parameters from city. */
325 cmafec_get_fe_parameter(current_city
, ¶meter
);
327 output_type_iterate(o
) {
328 minimal_surplus
[o
] = parameter
.minimal_surplus
[o
];
329 } output_type_iterate_end
;
331 XtVaSetValues(celebrate_toggle
,
332 XtNlabel
, parameter
.require_happy
? _("Yes") : _("No"),
333 XtNstate
, parameter
.require_happy
, NULL
);
335 if (parameter
.happy_factor
> 0) {
336 factors
[O_LAST
] = parameter
.happy_factor
;
341 output_type_iterate(o
) {
342 factors
[o
] = parameter
.factor
[o
];
343 } output_type_iterate_end
;
346 update_cma_preset_list();
348 XtVaSetValues(preset_list
, XtNwidth
, 200, NULL
);
349 XtVaSetValues(preset_list
, XtNheight
, 300, NULL
);
350 XtVaSetValues(celebrate_toggle
, XtNwidth
, 30, NULL
);
351 XtVaSetValues(result_label
, XtNwidth
, 360, NULL
);
352 XtVaSetValues(result_label
, XtNheight
, 110, NULL
);
354 output_type_iterate(o
) {
355 XtVaSetValues(stat_surplus_label
[o
], XtNwidth
, 90, NULL
);
356 XtVaSetValues(stat_factor_label
[o
], XtNwidth
, 90, NULL
);
357 } output_type_iterate_end
;
358 /* FIXME! Now we assume that output_type_iterate ends with O_LAST. */
359 XtVaSetValues(stat_factor_label
[O_LAST
], XtNwidth
, 90, NULL
);
361 XtRealizeWidget(cma_dialog
);
363 update_stat_labels(True
);
364 cm_result_from_main_map(result
, pcity
);
365 xaw_set_label(result_label
,
366 (char *) cmafec_get_result_descr(current_city
, result
, ¶meter
));
368 XSetWMProtocols(display
, XtWindow(cma_dialog
),
369 &wm_delete_window
, 1);
370 XtVaSetValues(preset_viewport
, XtNforceBars
, True
, NULL
);
371 xaw_set_relative_position(citydlg
, cma_dialog
, 5, 5);
372 XtPopup(cma_dialog
, XtGrabNone
);
374 cm_result_destroy(result
);
377 /**************************************************************************
378 Fills in the preset list.
379 **************************************************************************/
380 static void update_cma_preset_list(void)
382 static char *preset_lines
[256];
383 static char preset_text
[256][256];
386 if (cmafec_preset_num()) {
387 /* Add all CMA presets to the list. */
388 for (i
= 0; i
< cmafec_preset_num(); i
++) {
389 fc_strlcpy(preset_text
[i
], cmafec_preset_get_descr(i
),
390 sizeof(preset_text
[i
]));
391 preset_lines
[i
] = preset_text
[i
];
393 XawListChange(preset_list
, preset_lines
, cmafec_preset_num(), 0, True
);
395 /* Show intro message in the preset list. */
396 XawListChange(preset_list
, initial_preset_list
, 8, 0, True
);
400 /****************************************************************
401 Enable CMA control over the city.
402 *****************************************************************/
403 static void control_city(Widget w
, XtPointer list
,
406 struct cm_parameter param
;
408 cmafec_get_fe_parameter(current_city
, ¶m
);
409 cma_put_city_under_agent(current_city
, ¶m
);
410 refresh_city_dialog(current_city
);
412 XtSetSensitive(control_button
, FALSE
);
413 XtSetSensitive(release_button
, TRUE
);
414 XtSetSensitive(change_button
, FALSE
);
417 /****************************************************************
418 Disables CMA control over the city.
419 *****************************************************************/
420 static void release_city(Widget w
, XtPointer list
,
423 cma_release_city(current_city
);
424 refresh_city_dialog(current_city
);
426 XtSetSensitive(control_button
, TRUE
);
427 XtSetSensitive(release_button
, FALSE
);
428 XtSetSensitive(change_button
, TRUE
);
431 /****************************************************************
432 Create a new preset, first asking for the presets name.
433 *****************************************************************/
434 static void add_preset(Widget w
, XtPointer client_data
,
437 input_dialog_create(cma_dialog
, "cmapresetname",
438 _("What should we name the new preset?"),
440 new_preset_callback
, INT_TO_XTPOINTER(TRUE
),
441 new_preset_callback
, INT_TO_XTPOINTER(FALSE
));
444 /****************************************************************
445 Confirm that the user wants to remove the selected preset.
446 *****************************************************************/
447 static void remove_preset(Widget w
, XtPointer list
,
450 XawListReturnStruct
*ret
= XawListShowCurrent(preset_list
);
453 if (ret
->list_index
!= XAW_LIST_NONE
&& cmafec_preset_num()) {
454 fc_snprintf(buf
, sizeof(buf
),
455 _("Do you really want to remove %s?"),
456 cmafec_preset_get_descr(ret
->list_index
));
458 popup_message_dialog(cma_dialog
, "cmaremovepreset",
459 buf
, remove_preset_yes
,
460 INT_TO_XTPOINTER(ret
->list_index
), 0,
461 remove_preset_no
, 0, 0,
466 /****************************************************************
467 Remove the preset selected in the preset list.
468 *****************************************************************/
469 static void remove_preset_yes(Widget w
, XtPointer row
,
472 cmafec_preset_remove(XTPOINTER_TO_INT(row
));
473 update_cma_preset_list();
474 destroy_message_dialog(w
);
477 /****************************************************************
478 Close the remove preset dialog, without removing a preset.
479 *****************************************************************/
480 static void remove_preset_no(Widget w
, XtPointer client_data
,
483 destroy_message_dialog(w
);
486 /****************************************************************
487 Callback for CMA the preset list.
488 *****************************************************************/
489 static void select_preset(Widget w
, XtPointer list
,
492 XawListReturnStruct
*ret
;
493 const struct cm_parameter
*param
;
494 struct cm_parameter parameter
;
495 struct cm_result
*result
;
497 /* check gloabl variable current_city */
498 fc_assert_ret(current_city
!= NULL
);
500 result
= cm_result_new(current_city
);
501 ret
= XawListShowCurrent(list
);
503 if (ret
->list_index
!= XAW_LIST_NONE
&& cmafec_preset_num()) {
504 param
= cmafec_preset_get_parameter(ret
->list_index
);
505 cmafec_set_fe_parameter(current_city
, param
);
507 if (cma_is_city_under_agent(current_city
, NULL
)) {
508 cma_release_city(current_city
);
509 cma_put_city_under_agent(current_city
, param
);
512 cmafec_get_fe_parameter(current_city
, ¶meter
);
513 cm_result_from_main_map(result
, current_city
);
514 xaw_set_label(result_label
,
515 (char *) cmafec_get_result_descr(current_city
, result
, ¶meter
));
517 output_type_iterate(i
) {
518 minimal_surplus
[i
] = param
->minimal_surplus
[i
];
519 } output_type_iterate_end
;
521 XtVaSetValues(celebrate_toggle
, XtNlabel
,
522 param
->require_happy
? _("Yes") : _("No"),
523 XtNstate
, parameter
.require_happy
, NULL
);
525 factors
[O_LAST
] = param
->happy_factor
;
527 output_type_iterate(i
) {
528 factors
[i
] = param
->factor
[i
];
529 } output_type_iterate_end
;
532 update_stat_labels(result
->found_a_valid
);
533 cm_result_destroy(result
);
536 /****************************************************************
537 Show the CMA help page.
538 *****************************************************************/
539 static void cma_help(Widget w
, XtPointer list
,
542 popup_help_dialog_string(HELP_CMA_ITEM
);
545 /****************************************************************
546 Sets the position for all sliders.
547 *****************************************************************/
548 static void set_slider_values(void)
552 output_type_iterate(o
) {
553 XawScrollbarSetThumb(surplus_slider
[o
],
554 (((20 + minimal_surplus
[o
])))*1/41.0f
, 1/41.0f
);
555 } output_type_iterate_end
;
557 for (i
= 0; i
< (O_LAST
+ 1); i
++) {
558 XawScrollbarSetThumb(factor_slider
[i
],
559 (((factors
[i
])))*1/25.0f
, 1/25.0f
);
563 /**************************************************************************
564 Callback to update parameters if slider was scrolled. (Xaw)
565 **************************************************************************/
566 static void sliders_scroll_callback(Widget w
, XtPointer client_data
,
567 XtPointer position_val
)
569 int pos
= XTPOINTER_TO_INT(position_val
);
570 struct cm_parameter parameter
;
571 struct cm_result
*result
;
574 /* check gloabl variable current_city */
575 fc_assert_ret(current_city
!= NULL
);
577 result
= cm_result_new(current_city
);
579 output_type_iterate(o
) {
580 if (w
== surplus_slider
[o
]) {
582 minimal_surplus
[o
]++;
583 if (minimal_surplus
[o
] == 21) {
584 minimal_surplus
[o
]--;
587 minimal_surplus
[o
]--;
588 if (minimal_surplus
[o
] == -21) {
589 minimal_surplus
[o
]++;
593 } output_type_iterate_end
;
595 for (i
= 0; i
< (O_LAST
+ 1); i
++) {
596 if (w
== factor_slider
[i
]) {
599 if (factors
[i
] == 26) {
604 if (factors
[i
] == 0) {
611 cmafec_get_fe_parameter(current_city
, ¶meter
);
613 output_type_iterate(o
) {
614 parameter
.minimal_surplus
[o
] = minimal_surplus
[o
];
615 parameter
.factor
[o
] = factors
[o
];
616 } output_type_iterate_end
;
618 XtVaGetValues(celebrate_toggle
, XtNstate
, ¶meter
.require_happy
, NULL
);
619 parameter
.happy_factor
= factors
[O_LAST
];
621 cmafec_set_fe_parameter(current_city
, ¶meter
);
623 if (cma_is_city_under_agent(current_city
, NULL
)) {
624 cma_release_city(current_city
);
625 cma_put_city_under_agent(current_city
, ¶meter
);
628 cmafec_get_fe_parameter(current_city
, ¶meter
);
629 cm_result_from_main_map(result
, current_city
);
630 xaw_set_label(result_label
,
631 (char *) cmafec_get_result_descr(current_city
, result
, ¶meter
));
633 update_stat_labels(result
->found_a_valid
);
634 update_cma_preset_list();
636 /* highlight preset if parameter matches */
637 preset_index
= cmafec_preset_get_index_of_parameter(¶meter
);
638 if (preset_index
!= -1) {
639 XawListHighlight(preset_list
, preset_index
);
642 cm_result_destroy(result
);
645 /**************************************************************************
646 Callback to update parameters if slider was jumped. (Xaw3D)
647 **************************************************************************/
648 void sliders_jump_callback(Widget w
, XtPointer client_data
,
649 XtPointer percent_ptr
)
651 float percent
=*(float*)percent_ptr
;
652 struct cm_parameter parameter
;
653 struct cm_result
*result
;
656 /* check gloabl variable current_city */
657 fc_assert_ret(current_city
!= NULL
);
659 result
= cm_result_new(current_city
);
661 output_type_iterate(o
) {
662 if (w
== surplus_slider
[o
]) {
663 /* convert from percent to [-20..20] */
664 minimal_surplus
[o
] = (int)(percent
* 41) - 20;
666 } output_type_iterate_end
;
668 for (i
= 0; i
< (O_LAST
+ 1); i
++) {
669 if (w
== factor_slider
[i
]) {
670 /* convert from percent to [1..25] */
671 factors
[i
] = (int)(percent
* 25) + 1;
675 cmafec_get_fe_parameter(current_city
, ¶meter
);
677 output_type_iterate(o
) {
678 parameter
.minimal_surplus
[o
] = minimal_surplus
[o
];
679 parameter
.factor
[o
] = factors
[o
];
680 } output_type_iterate_end
;
682 XtVaGetValues(celebrate_toggle
, XtNstate
, ¶meter
.require_happy
, NULL
);
683 parameter
.happy_factor
= factors
[O_LAST
];
685 cmafec_set_fe_parameter(current_city
, ¶meter
);
687 if (cma_is_city_under_agent(current_city
, NULL
)) {
688 cma_release_city(current_city
);
689 cma_put_city_under_agent(current_city
, ¶meter
);
692 cmafec_get_fe_parameter(current_city
, ¶meter
);
693 cm_result_from_main_map(result
, current_city
);
694 xaw_set_label(result_label
,
695 (char *) cmafec_get_result_descr(current_city
, result
, ¶meter
));
697 update_cma_preset_list();
698 update_stat_labels(result
->found_a_valid
);
700 /* highlight preset if parameter matches */
701 preset_index
= cmafec_preset_get_index_of_parameter(¶meter
);
702 if (preset_index
!= -1) {
703 XawListHighlight(preset_list
, preset_index
);
706 cm_result_destroy(result
);
709 /**************************************************************************
710 Update CMA stat labels, set sensitivity on buttons, refresh city dialog.
711 **************************************************************************/
712 static void update_stat_labels(bool is_valid
)
716 output_type_iterate(i
) {
717 fc_snprintf(buf
, sizeof(buf
), "%-9s%3d",
720 xaw_set_label(stat_surplus_label
[i
], buf
);
721 } output_type_iterate_end
;
723 output_type_iterate(i
) {
724 fc_snprintf(buf
, sizeof(buf
), "%-9s%3d",
727 xaw_set_label(stat_factor_label
[i
], buf
);
728 } output_type_iterate_end
;
729 fc_snprintf(buf
, sizeof(buf
), "%-9s%3d",
732 xaw_set_label(stat_factor_label
[O_LAST
], buf
);
734 XtSetSensitive(release_button
,
735 (cma_is_city_under_agent(current_city
, NULL
)
736 && can_client_issue_orders()));
738 XtSetSensitive(control_button
,
739 (!cma_is_city_under_agent(current_city
, NULL
)
741 && can_client_issue_orders()));
743 XtSetSensitive(change_button
,
744 (!cma_is_city_under_agent(current_city
, NULL
)
746 && can_client_issue_orders()));
748 refresh_city_dialog(current_city
);
751 /**************************************************************************
752 Callback to save the new CMA preset after a name has been typed.
753 **************************************************************************/
754 static void new_preset_callback(Widget w
, XtPointer save_preset
,
757 Boolean celebrate_setting
;
758 struct cm_parameter parameter
;
761 /* The user entered a preset name and clicked OK */
762 XtVaGetValues(celebrate_toggle
, XtNstate
, &celebrate_setting
, NULL
);
763 cmafec_get_fe_parameter(current_city
, ¶meter
);
765 output_type_iterate(i
) {
766 parameter
.minimal_surplus
[i
] = minimal_surplus
[i
];
767 parameter
.factor
[i
] = factors
[i
];
768 } output_type_iterate_end
;
770 parameter
.happy_factor
= factors
[O_LAST
];
771 parameter
.require_happy
= celebrate_setting
;
773 cmafec_preset_add(input_dialog_get_input(w
), ¶meter
);
775 update_cma_preset_list();
777 input_dialog_destroy(w
);
780 /**************************************************************************
781 Callback to handle changes to the celebrate toggle.
782 **************************************************************************/
783 void celebrate_callback(Widget w
, XtPointer client_data
, XtPointer call_data
)
786 struct cm_parameter parameter
;
787 struct cm_result
*result
;
789 /* check gloabl variable current_city */
790 fc_assert_ret(current_city
!= NULL
);
792 /* Change label on celebrate toggle. */
793 XtVaGetValues(w
, XtNstate
, &celebrate
, NULL
);
794 XtVaSetValues(w
, XtNlabel
, celebrate
? _("Yes") : _("No"), NULL
);
796 /* Update parameters with new celebrate setting. */
797 cmafec_get_fe_parameter(current_city
, ¶meter
);
798 output_type_iterate(i
) {
799 parameter
.minimal_surplus
[i
] = minimal_surplus
[i
];
800 parameter
.factor
[i
] = factors
[i
];
801 } output_type_iterate_end
;
803 XtVaGetValues(celebrate_toggle
, XtNstate
, ¶meter
.require_happy
, NULL
);
804 parameter
.happy_factor
= factors
[O_LAST
];
806 cmafec_set_fe_parameter(current_city
, ¶meter
);
808 if (cma_is_city_under_agent(current_city
, NULL
)) {
809 cma_release_city(current_city
);
810 cma_put_city_under_agent(current_city
, ¶meter
);
813 result
= cm_result_new(current_city
);
814 cmafec_get_fe_parameter(current_city
, ¶meter
);
815 cm_result_from_main_map(result
, current_city
);
816 xaw_set_label(result_label
,
817 (char *) cmafec_get_result_descr(current_city
, result
, ¶meter
));
819 update_stat_labels(result
->found_a_valid
);
820 update_cma_preset_list();
822 cm_result_destroy(result
);
825 /**************************************************************************
826 Close the CMA dialog. Also called when the citydialog closes.
827 **************************************************************************/
828 void popdown_cma_dialog(void)
831 city_report_dialog_update_city(current_city
);
832 XtDestroyWidget(cma_dialog
);
837 /**************************************************************************
838 Callback to close the CMA dialog when the user clicks on Close.
839 **************************************************************************/
840 static void close_callback(Widget w
, XtPointer client_data
,
843 popdown_cma_dialog();
846 /**************************************************************************
847 Callback to apply CMA preset to city once.
848 **************************************************************************/
849 static void change_callback(Widget w
, XtPointer client_data
,
852 struct cm_result
*result
;
853 struct cm_parameter param
;
855 /* check gloabl variable current_city */
856 fc_assert_ret(current_city
!= NULL
);
858 result
= cm_result_new(current_city
);
859 cmafec_get_fe_parameter(current_city
, ¶m
);
860 cm_query_result(current_city
, ¶m
, result
);
861 cma_apply_result(current_city
, result
);
862 refresh_city_dialog(current_city
);
864 cm_result_destroy(result
);