Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-gtk-3.22/rallypointdlg.c Source File

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-3.22 */
33#include "gui_main.h"
34#include "gui_stuff.h"
35
36#include "rallypointdlg.h"
37
38 bool rally_dialog = FALSE;
39 static GtkWidget *instruction_label = NULL;
40 static GtkWidget *persistent;
41
42 static int rally_city_id = -1;
43
44/************************************************************************/
47 static bool rally_dialog_open(void)
48{
49 return rally_dialog;
50}
51
52/************************************************************************/
55 static void rally_response_callback(GtkWidget *dlg, gint arg)
56{
57 rally_dialog = FALSE;
58 instruction_label = NULL;
59
60 gtk_widget_destroy(dlg);
61}
62
63/************************************************************************/
66 void rally_dialog_popup(void)
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
81 setup_dialog(dlg, toplevel);
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_grid_new();
86 gtk_orientable_set_orientation(GTK_ORIENTABLE(main_box),
87 GTK_ORIENTATION_VERTICAL);
88
89 instruction_label = gtk_label_new(_("First click a city."));
90 gtk_container_add(GTK_CONTAINER(main_box), instruction_label);
91
92 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
93 gtk_container_add(GTK_CONTAINER(main_box), sep);
94
95 persistent = gtk_check_button_new_with_label(_("Persistent rallypoint"));
96 gtk_container_add(GTK_CONTAINER(main_box), persistent);
97
98 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
99 gtk_container_add(GTK_CONTAINER(main_box), sep);
100
101 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dlg))),
102 main_box);
103
104 g_signal_connect(dlg, "destroy", G_CALLBACK(rally_response_callback), NULL);
105 g_signal_connect(dlg, "response", G_CALLBACK(rally_response_callback), NULL);
106
107 gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(dlg)));
108 gtk_widget_show(dlg);
109
110 rally_dialog = TRUE;
111}
112
113/************************************************************************/
116 enum rally_phase rally_placement_phase(void)
117{
118 if (!rally_dialog) {
119 return RALLY_NONE;
120 }
121
122 if (rally_city_id > 0) {
123 return RALLY_TILE;
124 }
125
126 return RALLY_CITY;
127}
128
129/************************************************************************/
133 bool rally_set_tile(struct tile *ptile)
134{
135 struct city *pcity = NULL;
136 enum rally_phase phase = rally_placement_phase();
137
138 if (phase == RALLY_NONE) {
139 return FALSE;
140 }
141
142 if (ptile == NULL) {
143 return TRUE;
144 }
145
146 if (rally_city_id > 0) {
147 pcity = game_city_by_number(rally_city_id);
148
149 if (pcity == NULL || city_owner(pcity) != client_player()) {
150 /* City destroyed or captured while we've
151 * been setting the rally point? */
152 rally_city_id = -1;
153 phase = RALLY_CITY;
154
155 gtk_label_set_text(GTK_LABEL(instruction_label),
156 _("Select another city."));
157 }
158 }
159
160 if (phase == RALLY_CITY) {
161 char buffer[100];
162
163 pcity = tile_city(ptile);
164
165 if (pcity == NULL || city_owner(pcity) != client_player()) {
166 return TRUE;
167 }
168
169 rally_city_id = pcity->id;
170
171 fc_snprintf(buffer, sizeof(buffer), _("Now select rally point for %s"),
172 city_name_get(pcity));
173 gtk_label_set_text(GTK_LABEL(instruction_label), buffer);
174 } else {
175 char buffer[100];
176 bool psist = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(persistent));
177
178 fc_assert(pcity != NULL);
179
180 rally_city_id = -1;
181
182 if (send_rally_tile(pcity, ptile, psist)) {
183 fc_snprintf(buffer, sizeof(buffer),
184 _("%s rally point set. Select another city."),
185 city_name_get(pcity));
186 } else {
187 fc_snprintf(buffer, sizeof(buffer),
188 _("%s rally point setting failed. Select next city."),
189 city_name_get(pcity));
190 }
191
192 gtk_label_set_text(GTK_LABEL(instruction_label), buffer);
193 }
194
195 return TRUE;
196}
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1111
city.h
city_owner
#define city_owner(_pcity_)
Definition city.h:543
client_main.h
client_player
#define client_player()
Definition client_main.h:106
fcintl.h
_
#define _(String)
Definition fcintl.h:67
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
game.h
send_rally_tile
bool send_rally_tile(struct city *pcity, struct tile *ptile, bool persistent)
Definition goto.c:1575
goto.h
toplevel
GtkWidget * toplevel
Definition gui_main.c:124
setup_dialog
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
instruction_label
static GtkWidget * instruction_label
Definition rallypointdlg.c:39
rally_set_tile
bool rally_set_tile(struct tile *ptile)
Definition rallypointdlg.c:133
persistent
static GtkWidget * persistent
Definition rallypointdlg.c:40
rally_dialog_popup
void rally_dialog_popup(void)
Definition rallypointdlg.c:66
rally_response_callback
static void rally_response_callback(GtkWidget *dlg, gint arg)
Definition rallypointdlg.c:55
rally_dialog_open
static bool rally_dialog_open(void)
Definition rallypointdlg.c:47
rally_placement_phase
enum rally_phase rally_placement_phase(void)
Definition rallypointdlg.c:116
rally_city_id
static int rally_city_id
Definition rallypointdlg.c:42
rally_dialog
bool rally_dialog
Definition rallypointdlg.c:38
rally_phase
rally_phase
Definition rallypointdlg.h:16
RALLY_TILE
@ RALLY_TILE
Definition rallypointdlg.h:16
RALLY_CITY
@ RALLY_CITY
Definition rallypointdlg.h:16
RALLY_NONE
@ RALLY_NONE
Definition rallypointdlg.h:16
gui_stuff.h
rallypointdlg.h
gui_main.h
fc_assert
#define fc_assert(condition)
Definition log.h:176
city
Definition city.h:309
city::id
int id
Definition city.h:315
tile
Definition tile.h:49
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile.h