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-4.0 */
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/**********************************************************************/
216
217/**********************************************************************/
220static int mult_to_scale(const struct multiplier *pmul, int val)
221{
222 return (val - pmul->start) / pmul->step;
223}
224
225/**********************************************************************/
228static int scale_to_mult(const struct multiplier *pmul, int scale)
229{
230 return scale * pmul->step + pmul->start;
231}
232
233/**********************************************************************/
253
254/**********************************************************************/
258{
259 multipliers_iterate(pmul) {
261 int val = player_multiplier_value(client_player(), pmul);
262 int target = player_multiplier_target_value(client_player(), pmul);
263
265 fc_assert(scale_to_mult(pmul, mult_to_scale(pmul, val)) == val);
266 fc_assert(scale_to_mult(pmul, mult_to_scale(pmul, target)) == target);
267
270 mult_to_scale(pmul, val), GTK_POS_BOTTOM,
271 /* TRANS: current value of policy in force */
272 Q_("?multiplier:Now"));
273
274 if (set_positions) {
276 mult_to_scale(pmul, target));
277 }
279}
280
281/**********************************************************************/
285{
287 return;
288 }
289
290 /* If dialog belongs to a player rather than an observer, we don't
291 * want to lose any local changes made by the player.
292 * This dialog should be the only way the values can change, anyway. */
294}
295
296/**********************************************************************/
300{
301 GtkWidget *shell, *content;
302 GtkWidget *label, *scale;
303
305 shell = gtk_dialog_new_with_buttons(_("Change policies"),
306 NULL,
307 0,
308 _("_Cancel"),
310 _("_OK"),
312 NULL);
313 } else {
314 shell = gtk_dialog_new_with_buttons(_("Policies"),
315 NULL,
316 0,
317 _("_Close"),
319 NULL);
320 }
322
324
326 label = gtk_label_new(_("Changes will not take effect until next turn."));
327 gtk_box_insert_child_after(GTK_BOX(content), label, NULL);
328 }
329
330 multipliers_iterate(pmul) {
332 int mscale;
333
336 /* Map each multiplier step to a single step on the UI, to enforce
337 * the step size. */
339 mult_to_scale(pmul, pmul->start),
340 mult_to_scale(pmul, pmul->stop), 1);
342 mscale = mult_to_scale(pmul, pmul->stop) / 10;
344 1, MAX(2, mscale));
348 gtk_box_insert_child_after(GTK_BOX(content), label, NULL);
354
356
357 g_signal_connect(shell, "destroy",
359
360 g_signal_connect(shell, "response",
362
364
365 return shell;
366}
367
368/**********************************************************************/
383
384/**********************************************************************/
388{
389 GtkWidget *shell, *content;
390 GtkWidget *frame, *hbox;
391 int i;
392
394 return NULL;
395 }
396
397 shell = gtk_dialog_new_with_buttons(_("Select tax, luxury and science rates"),
398 NULL,
399 0,
400 _("_Cancel"),
402 _("_OK"),
404 NULL);
408
411
412 frame = gtk_frame_new( _("Tax") );
413 gtk_box_insert_child_after(GTK_BOX(content), frame, NULL);
414
417
421 for (i = 0; i <= 10; i++) {
423 }
428
432
435
436 frame = gtk_frame_new( _("Luxury") );
437 gtk_box_insert_child_after(GTK_BOX(content), frame, NULL);
438
441
445 for (i = 0; i <= 10; i++) {
447 }
452
456
459
460 frame = gtk_frame_new( _("Science") );
461 gtk_box_insert_child_after(GTK_BOX(content), frame, NULL);
462
465
469 for (i = 0; i <= 10; i++) {
471 }
476
480
483
484 g_signal_connect(shell, "response",
486 g_signal_connect(shell, "destroy",
488
490
491 rates_tax_value = -1;
492 rates_lux_value = -1;
493 rates_sci_value = -1;
494
498
502
506
510
511 return shell;
512}
513
514/**********************************************************************/
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 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
void widget_destroyed(GtkWidget *wdg, void *data)
Definition gui_stuff.c:1155
#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