Freeciv-3.3
Loading...
Searching...
No Matches
gamedlgs.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#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include <gtk/gtk.h>
23#include <gdk/gdkkeysyms.h>
24
25/* utility */
26#include "log.h"
27#include "shared.h"
28#include "string_vector.h"
29#include "support.h"
30
31/* common */
32#include "events.h"
33#include "fcintl.h"
34#include "government.h"
35#include "multipliers.h"
36
37/* client */
38#include "client_main.h"
39#include "options.h"
40
41/* client/gui-gtk-3.22 */
42#include "chatline.h"
43#include "cityrep.h"
44#include "dialogs.h"
45#include "gui_main.h"
46#include "gui_stuff.h"
47#include "ratesdlg.h"
48
49#include "gamedlgs.h"
50
51/******************************************************************/
57
60
62/******************************************************************/
63
65
67
68/**********************************************************************/
71static void rates_set_values(int tax, int no_tax_scroll,
72 int lux, int no_lux_scroll,
73 int sci, int no_sci_scroll)
74{
75 char buf[64];
77 int maxrate;
78
82
83 if (NULL != client.conn.playing) {
85 } else {
86 maxrate = 100;
87 }
88
89 /* This's quite a simple-minded "double check".. */
90 tax = MIN(tax, maxrate);
91 lux = MIN(lux, maxrate);
92 sci = MIN(sci, maxrate);
93
94 if (tax + sci + lux != 100) {
95 if (tax != rates_tax_value) {
96 if (!lux_lock) {
97 lux = MIN(MAX(100 - tax - sci, 0), maxrate);
98 }
99 if (!sci_lock) {
100 sci = MIN(MAX(100 - tax - lux, 0), maxrate);
101 }
102 } else if (lux != rates_lux_value) {
103 if (!tax_lock) {
104 tax = MIN(MAX(100 - lux - sci, 0), maxrate);
105 }
106 if (!sci_lock) {
107 sci = MIN(MAX(100 - lux - tax, 0), maxrate);
108 }
109 } else if (sci != rates_sci_value) {
110 if (!lux_lock) {
111 lux = MIN(MAX(100 - tax - sci, 0), maxrate);
112 }
113 if (!tax_lock) {
114 tax = MIN(MAX(100 - lux - sci, 0), maxrate);
115 }
116 }
117
118 if (tax + sci + lux != 100) {
119 tax = rates_tax_value;
122
123 rates_tax_value = -1;
124 rates_lux_value = -1;
125 rates_sci_value = -1;
126
127 no_tax_scroll = 0;
128 no_lux_scroll = 0;
129 no_sci_scroll = 0;
130 }
131 }
132
133 if (tax != rates_tax_value) {
134 fc_snprintf(buf, sizeof(buf), "%3d%%", tax);
135
138 }
139 if (!no_tax_scroll) {
143 }
144 rates_tax_value = tax;
145 }
146
147 if (lux != rates_lux_value) {
148 fc_snprintf(buf, sizeof(buf), "%3d%%", lux);
149
152 }
153 if (!no_lux_scroll) {
157 }
159 }
160
161 if (sci != rates_sci_value) {
162 fc_snprintf(buf, sizeof(buf), "%3d%%", sci);
163
166 }
167 if (!no_sci_scroll) {
171 }
173 }
174}
175
176/**********************************************************************/
180{
182
183 if (range == rates_tax_scale) {
184 int tax_value;
185
186 tax_value = 10 * percent;
187 tax_value = MIN(tax_value, 100);
189 } else if (range == rates_lux_scale) {
190 int lux_value;
191
192 lux_value = 10 * percent;
193 lux_value = MIN(lux_value, 100);
195 } else {
196 int sci_value;
197
198 sci_value = 10 * percent;
199 sci_value = MIN(sci_value, 100);
201 }
202}
203
204/**********************************************************************/
215
216/**********************************************************************/
219static int mult_to_scale(const struct multiplier *pmul, int val)
220{
221 return (val - pmul->start) / pmul->step;
222}
223
224/**********************************************************************/
227static int scale_to_mult(const struct multiplier *pmul, int scale)
228{
229 return scale * pmul->step + pmul->start;
230}
231
232/**********************************************************************/
236 void *udata)
237{
238 const struct multiplier *pmul = udata;
239
240 return g_strdup_printf("%d", scale_to_mult(pmul, value));
241}
242
243/**********************************************************************/
262
263/**********************************************************************/
267{
268 multipliers_iterate(pmul) {
270 int val = player_multiplier_value(client_player(), pmul);
271 int target = player_multiplier_target_value(client_player(), pmul);
272
274 fc_assert(scale_to_mult(pmul, mult_to_scale(pmul, val)) == val);
275 fc_assert(scale_to_mult(pmul, mult_to_scale(pmul, target)) == target);
276
279 mult_to_scale(pmul, val), GTK_POS_BOTTOM,
280 /* TRANS: current value of policy in force */
281 Q_("?multiplier:Now"));
282
283 if (set_positions) {
285 mult_to_scale(pmul, target));
286 }
288}
289
290/**********************************************************************/
294{
296 return;
297 }
298
299 /* If dialog belongs to a player rather than an observer, we don't
300 * want to lose any local changes made by the player.
301 * This dialog should be the only way the values can change, anyway. */
303}
304
305/**********************************************************************/
309{
310 GtkWidget *shell, *content;
311 GtkWidget *label, *scale;
312
314 shell = gtk_dialog_new_with_buttons(_("Change policies"),
315 NULL,
316 0,
317 _("_Cancel"),
319 _("_OK"),
321 NULL);
322 } else {
323 shell = gtk_dialog_new_with_buttons(_("Policies"),
324 NULL,
325 0,
326 _("_Close"),
328 NULL);
329 }
331
334
336 label = gtk_label_new(_("Changes will not take effect until next turn."));
337 gtk_box_pack_start( GTK_BOX( content ), label, FALSE, FALSE, 0);
338 }
339
340 multipliers_iterate(pmul) {
342 int mscale;
343
346 /* Map each multiplier step to a single step on the UI, to enforce
347 * the step size. */
349 mult_to_scale(pmul, pmul->start),
350 mult_to_scale(pmul, pmul->stop), 1);
352 mscale = mult_to_scale(pmul, pmul->stop) / 10;
354 1, MAX(2, mscale));
360 gtk_box_pack_start( GTK_BOX( content ), label, TRUE, TRUE, 5 );
361 gtk_box_pack_start( GTK_BOX( content ), scale, TRUE, TRUE, 5 );
366
368
369 g_signal_connect(shell, "destroy",
371
372 g_signal_connect(shell, "response",
374
375 gtk_widget_show_all(content);
376
377 return shell;
378}
379
380/**********************************************************************/
395
396/**********************************************************************/
400{
401 GtkWidget *shell, *content;
402 GtkWidget *frame, *hgrid;
403 int i;
404
406 return NULL;
407 }
408
409 shell = gtk_dialog_new_with_buttons(_("Select tax, luxury and science rates"),
410 NULL,
411 0,
412 _("_Cancel"),
414 _("_OK"),
416 NULL);
421
424
425 frame = gtk_frame_new( _("Tax") );
426 gtk_box_pack_start( GTK_BOX( content ), frame, TRUE, TRUE, 5 );
427
431
435 for (i = 0; i <= 10; i++) {
437 }
442
446
449
450 frame = gtk_frame_new( _("Luxury") );
451 gtk_box_pack_start( GTK_BOX( content ), frame, TRUE, TRUE, 5 );
452
456
460 for (i = 0; i <= 10; i++) {
462 }
467
471
474
475 frame = gtk_frame_new( _("Science") );
476 gtk_box_pack_start( GTK_BOX( content ), frame, TRUE, TRUE, 5 );
477
481
485 for (i = 0; i <= 10; i++) {
487 }
492
496
499
500
501 g_signal_connect(shell, "response",
503 g_signal_connect(shell, "destroy",
505
507
508 rates_tax_value = -1;
509 rates_lux_value = -1;
510 rates_sci_value = -1;
511
515
519
523
527 return shell;
528}
529
530/**********************************************************************/
struct civclient client
bool can_client_issue_orders(void)
#define client_player()
char * incite_cost
Definition comments.c:76
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
#define MAX_NUM_MULTIPLIERS
Definition fc_types.h:55
int Multiplier_type_id
Definition fc_types.h:245
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:154
static void multipliers_command_callback(GtkWidget *w, gint response_id)
Definition gamedlgs.c:246
static gulong rates_sci_sig
Definition gamedlgs.c:61
static GtkWidget * rates_tax_scale
Definition gamedlgs.c:56
static gulong rates_tax_sig
Definition gamedlgs.c:61
static GtkWidget * rates_tax_toggle
Definition gamedlgs.c:54
static int rates_lux_value
Definition gamedlgs.c:64
static GtkWidget * multiplier_dialog_shell
Definition gamedlgs.c:58
static GtkWidget * rates_gov_label
Definition gamedlgs.c:53
static int rates_sci_value
Definition gamedlgs.c:64
static GtkWidget * rates_sci_label
Definition gamedlgs.c:55
static void rates_changed_callback(GtkWidget *range)
Definition gamedlgs.c:179
static GtkWidget * create_rates_dialog(void)
Definition gamedlgs.c:399
static GtkWidget * rates_sci_scale
Definition gamedlgs.c:56
static GtkWidget * rates_lux_scale
Definition gamedlgs.c:56
static GtkWidget * create_multiplier_dialog(void)
Definition gamedlgs.c:308
static gulong rates_lux_sig
Definition gamedlgs.c:61
void popup_multiplier_dialog(void)
Definition gamedlgs.c:383
static GtkWidget * rates_lux_label
Definition gamedlgs.c:55
static GtkWidget * rates_lux_toggle
Definition gamedlgs.c:54
void popup_rates_dialog(void)
Definition gamedlgs.c:533
static void rates_command_callback(GtkWidget *w, gint response_id)
Definition gamedlgs.c:207
static void rates_set_values(int tax, int no_tax_scroll, int lux, int no_lux_scroll, int sci, int no_sci_scroll)
Definition gamedlgs.c:71
static GtkWidget * rates_tax_label
Definition gamedlgs.c:55
static int rates_tax_value
Definition gamedlgs.c:64
void real_multipliers_dialog_update(void *unused)
Definition gamedlgs.c:293
static int scale_to_mult(const struct multiplier *pmul, int scale)
Definition gamedlgs.c:227
static int mult_to_scale(const struct multiplier *pmul, int val)
Definition gamedlgs.c:219
static GtkWidget * rates_sci_toggle
Definition gamedlgs.c:54
static gchar * multiplier_value_callback(GtkScale *scale, gdouble value, void *udata)
Definition gamedlgs.c:235
static GtkWidget * multipliers_scale[MAX_NUM_MULTIPLIERS]
Definition gamedlgs.c:59
static void multiplier_dialog_update_values(bool set_positions)
Definition gamedlgs.c:266
static GtkWidget * rates_dialog_shell
Definition gamedlgs.c:52
GtkWidget * toplevel
Definition gui_main.c:126
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
static struct gui_dialog * shell
Definition messagedlg.c:39
#define fc_assert(condition)
Definition log.h:177
Multiplier_type_id multiplier_count(void)
Definition multipliers.c:88
const char * multiplier_name_translation(const struct multiplier *pmul)
Definition multipliers.c:97
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
#define multipliers_iterate_end
Definition multipliers.h:67
int dsend_packet_player_rates(struct connection *pc, int tax, int luxury, int science)
int send_packet_player_multiplier(struct connection *pc, const struct packet_player_multiplier *packet)
int player_multiplier_target_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1987
int player_multiplier_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1964
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
struct sprite int int int int struct sprite int int float scale
Definition sprite_g.h:33
struct connection conn
Definition client_main.h:96
struct player * playing
Definition connection.h:151
struct player_economic economic
Definition player.h:284
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