Freeciv-3.1
Loading...
Searching...
No Matches
rallypointdlg.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 <gtk/gtk.h>
19
20/* utility */
21#include "fcintl.h"
22
23/* common */
24#include "city.h"
25#include "game.h"
26#include "tile.h"
27
28/* client */
29#include "client_main.h"
30#include "goto.h"
31
32/* client/gui-gtk-4.0 */
33#include "gui_main.h"
34#include "gui_stuff.h"
35
36#include "rallypointdlg.h"
37
39static GtkWidget *instruction_label = NULL;
40static GtkWidget *persistent;
41
42static int rally_city_id = -1;
43
44/************************************************************************/
47static bool rally_dialog_open(void)
48{
49 return rally_dialog;
50}
51
52/************************************************************************/
55static void rally_response_callback(GtkWidget *dlg, gint arg)
56{
58 instruction_label = NULL;
59
60 gtk_window_destroy(GTK_WINDOW(dlg));
61}
62
63/************************************************************************/
67{
68 GtkWidget *dlg;
69 GtkWidget *main_box;
70 GtkWidget *sep;
71
72 if (rally_dialog_open()) {
73 /* One rally point dialog already open. */
74 return;
75 }
76
77 dlg = gtk_dialog_new_with_buttons(_("Place Rally Point"), NULL, 0,
78 _("Close"), GTK_RESPONSE_NO,
79 NULL);
80
82 gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_NO);
83 gtk_window_set_destroy_with_parent(GTK_WINDOW(dlg), TRUE);
84
85 main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
86
87 instruction_label = gtk_label_new(_("First click a city."));
88 gtk_box_append(GTK_BOX(main_box), instruction_label);
89
90 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
91 gtk_box_append(GTK_BOX(main_box), sep);
92
93 persistent = gtk_check_button_new_with_label(_("Persistent rallypoint"));
94 gtk_box_append(GTK_BOX(main_box), persistent);
95
96 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
97 gtk_box_append(GTK_BOX(main_box), sep);
98
99 gtk_box_append(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))),
100 main_box);
101
102 g_signal_connect(dlg, "destroy", G_CALLBACK(rally_response_callback), NULL);
103 g_signal_connect(dlg, "response", G_CALLBACK(rally_response_callback), NULL);
104
105 gtk_widget_show(gtk_dialog_get_content_area(GTK_DIALOG(dlg)));
106 gtk_widget_show(dlg);
107
109}
110
111/************************************************************************/
115{
116 if (!rally_dialog) {
117 return RALLY_NONE;
118 }
119
120 if (rally_city_id > 0) {
121 return RALLY_TILE;
122 }
123
124 return RALLY_CITY;
125}
126
127/************************************************************************/
131bool rally_set_tile(struct tile *ptile)
132{
133 struct city *pcity = NULL;
134 enum rally_phase phase = rally_placement_phase();
135
136 if (phase == RALLY_NONE) {
137 return FALSE;
138 }
139
140 if (ptile == NULL) {
141 return TRUE;
142 }
143
144 if (rally_city_id > 0) {
146
147 if (pcity == NULL || city_owner(pcity) != client_player()) {
148 /* City destroyed or captured while we've
149 * been setting the rally point? */
150 rally_city_id = -1;
151 phase = RALLY_CITY;
152
153 gtk_label_set_text(GTK_LABEL(instruction_label),
154 _("Select another city."));
155 }
156 }
157
158 if (phase == RALLY_CITY) {
159 char buffer[100];
160
161 pcity = tile_city(ptile);
162
163 if (pcity == NULL || city_owner(pcity) != client_player()) {
164 return TRUE;
165 }
166
167 rally_city_id = pcity->id;
168
169 fc_snprintf(buffer, sizeof(buffer), _("Now select rally point for %s"),
170 city_name_get(pcity));
171 gtk_label_set_text(GTK_LABEL(instruction_label), buffer);
172 } else {
173 char buffer[100];
174 bool psist = gtk_check_button_get_active(GTK_CHECK_BUTTON(persistent));
175
176 fc_assert(pcity != NULL);
177
178 rally_city_id = -1;
179
180 if (send_rally_tile(pcity, ptile, psist)) {
181 fc_snprintf(buffer, sizeof(buffer),
182 _("%s rally point set. Select another city."),
183 city_name_get(pcity));
184 } else {
185 fc_snprintf(buffer, sizeof(buffer),
186 _("%s rally point setting failed. Select next city."),
187 city_name_get(pcity));
188 }
189
190 gtk_label_set_text(GTK_LABEL(instruction_label), buffer);
191 }
192
193 return TRUE;
194}
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
#define city_owner(_pcity_)
Definition city.h:543
#define client_player()
#define _(String)
Definition fcintl.h:67
struct city * game_city_by_number(int id)
Definition game.c:102
bool send_rally_tile(struct city *pcity, struct tile *ptile, bool persistent)
Definition goto.c:1575
GtkWidget * toplevel
Definition gui_main.c:124
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
static GtkWidget * instruction_label
bool rally_set_tile(struct tile *ptile)
static GtkWidget * persistent
void rally_dialog_popup(void)
static void rally_response_callback(GtkWidget *dlg, gint arg)
static bool rally_dialog_open(void)
enum rally_phase rally_placement_phase(void)
static int rally_city_id
bool rally_dialog
rally_phase
@ RALLY_TILE
@ RALLY_CITY
@ RALLY_NONE
#define fc_assert(condition)
Definition log.h:176
Definition city.h:309
int id
Definition city.h:315
Definition tile.h:49
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83