Freeciv-3.2
Loading...
Searching...
No Matches
voteinfo_bar.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#include "mem.h"
23#include "support.h"
24
25/* client */
26#include "options.h"
27#include "voteinfo.h"
28
29/* client/gui-gtk-3.22 */
30#include "chatline.h"
31#include "pages.h"
32
33#include "voteinfo_bar.h"
34
35/* A set of widgets. */
48
49GtkWidget *pregame_votebar = NULL; /* PAGE_START voteinfo bar. */
50GtkWidget *ingame_votebar = NULL; /* PAGE_GAME voteinfo bar. */
51
52/**********************************************************************/
56{
58 struct voteinfo *vi;
59
62
63 if (vi == NULL) {
64 return;
65 }
66
67 voteinfo_do_vote(vi->vote_no, vote);
68}
69
70/**********************************************************************/
78
79/**********************************************************************/
83{
84 free((struct voteinfo_bar *) userdata);
85}
86
87/**********************************************************************/
93{
94 GtkWidget *label, *button, *vbox, *hbox, *arrow;
95 struct voteinfo_bar *vib;
96 const int BUTTON_HEIGHT = 12;
97
98 vib = fc_calloc(1, sizeof(struct voteinfo_bar));
99
100 if (!split_bar) {
101 hbox = gtk_grid_new();
103 g_object_set_data(G_OBJECT(hbox), "voteinfo_bar", vib);
105 vib->box = hbox;
106 vbox = NULL; /* The compiler may require it. */
107 } else {
108 vbox = gtk_grid_new();
113 g_object_set_data(G_OBJECT(vbox), "voteinfo_bar", vib);
115 vib->box = vbox;
116 hbox = gtk_grid_new();
119 }
120
121 label = gtk_label_new("");
131 gtk_widget_set_name(label, "vote label");
132 vib->label = label;
133
134 arrow = gtk_image_new_from_icon_name("media-seek-backward",
138
139 if (split_bar) {
140 hbox = gtk_grid_new();
143 }
144
145 button = gtk_button_new();
146 gtk_widget_set_margin_end(button, 16);
147 g_signal_connect(button, "clicked",
149 gtk_button_set_image(GTK_BUTTON(button), arrow);
154 vib->next_button = button;
155
156 button = gtk_button_new_with_mnemonic(_("_YES"));
157 g_signal_connect(button, "clicked",
162 gtk_widget_set_name(button, "vote yes button");
163 vib->yes_button = button;
164
165 label = gtk_label_new("0");
169 vib->yes_count_label = label;
170
171 button = gtk_button_new_with_mnemonic(_("_NO"));
172 g_signal_connect(button, "clicked",
177 gtk_widget_set_name(button, "vote no button");
178 vib->no_button = button;
179
180 label = gtk_label_new("0");
184 vib->no_count_label = label;
185
186 button = gtk_button_new_with_mnemonic(_("_ABSTAIN"));
187 g_signal_connect(button, "clicked",
192 gtk_widget_set_name(button, "vote abstain button");
193 vib->abstain_button = button;
194
195 label = gtk_label_new("0");
199 vib->abstain_count_label = label;
200
201 label = gtk_label_new("/0");
205 vib->voter_count_label = label;
206
207 return vib->box;
208}
209
210/**********************************************************************/
215{
216 int vote_count, index;
217 struct voteinfo_bar *vib = NULL;
218 struct voteinfo *vi = NULL;
219 char buf[1024], status[1024], ordstr[128], color[32];
220 bool running, need_scroll;
222
224 vib = g_object_get_data(G_OBJECT(pregame_votebar), "voteinfo_bar");
225 } else if (get_client_page() == PAGE_GAME && NULL != ingame_votebar) {
226 vib = g_object_get_data(G_OBJECT(ingame_votebar), "voteinfo_bar");
227 }
228
229 if (vib == NULL) {
230 return;
231 }
232
234 gtk_widget_hide(vib->box);
235 return;
236 }
237
240
241 if (vi != NULL && vi->resolved && vi->passed) {
242 /* TRANS: Describing a vote that passed. */
243 fc_snprintf(status, sizeof(status), _("[passed]"));
244 sz_strlcpy(color, "green");
245 } else if (vi != NULL && vi->resolved && !vi->passed) {
246 /* TRANS: Describing a vote that failed. */
247 fc_snprintf(status, sizeof(status), _("[failed]"));
248 sz_strlcpy(color, "red");
249 } else if (vi != NULL && vi->remove_time > 0) {
250 /* TRANS: Describing a vote that was removed. */
251 fc_snprintf(status, sizeof(status), _("[removed]"));
252 sz_strlcpy(color, "grey");
253 } else {
254 status[0] = '\0';
255 }
256
257 if (vote_count > 1) {
258 fc_snprintf(ordstr, sizeof(ordstr),
259 "<span weight=\"bold\">(%d/%d)</span> ",
260 index + 1, vote_count);
261 } else {
262 ordstr[0] = '\0';
263 }
264
265 if (status[0] != '\0') {
266 fc_snprintf(buf, sizeof(buf),
267 "<span weight=\"bold\" background=\"%s\">%s</span> ",
268 color, status);
269 sz_strlcpy(status, buf);
270 }
271
272 if (vi != NULL) {
275 /* TRANS: "Vote" as a process */
276 fc_snprintf(buf, sizeof(buf), _("%sVote %d by %s: %s%s"),
277 ordstr, vi->vote_no, escaped_user, status,
281 } else {
282 buf[0] = '\0';
283 }
285
286 if (vi != NULL) {
287 fc_snprintf(buf, sizeof(buf), "%d", vi->yes);
288 gtk_label_set_text(GTK_LABEL(vib->yes_count_label), buf);
289 fc_snprintf(buf, sizeof(buf), "%d", vi->no);
290 gtk_label_set_text(GTK_LABEL(vib->no_count_label), buf);
291 fc_snprintf(buf, sizeof(buf), "%d", vi->abstain);
292 gtk_label_set_text(GTK_LABEL(vib->abstain_count_label), buf);
293 fc_snprintf(buf, sizeof(buf), "/%d", vi->num_voters);
294 gtk_label_set_text(GTK_LABEL(vib->voter_count_label), buf);
295 } else {
296 gtk_label_set_text(GTK_LABEL(vib->yes_count_label), "-");
297 gtk_label_set_text(GTK_LABEL(vib->no_count_label), "-");
298 gtk_label_set_text(GTK_LABEL(vib->abstain_count_label), "-");
299 gtk_label_set_text(GTK_LABEL(vib->voter_count_label), "/-");
300 }
301
302 running = vi != NULL && !vi->resolved && vi->remove_time == 0;
303
306 gtk_widget_set_sensitive(vib->abstain_button, running);
307
310
312
313 if (vote_count <= 1) {
314 gtk_widget_hide(vib->next_button);
315 }
316
317 if (need_scroll) {
318 /* Showing the votebar when it was hidden
319 * previously makes the chatline scroll up. */
321 }
322}
char * incite_cost
Definition comments.c:75
#define _(String)
Definition fcintl.h:67
bool chatline_is_scrolled_to_bottom(void)
Definition chatline.c:959
void chatline_scroll_to_bottom(bool delayed)
Definition chatline.c:1006
void voteinfo_gui_update(void)
static void voteinfo_bar_do_vote_callback(GtkWidget *w, gpointer userdata)
GtkWidget * ingame_votebar
GtkWidget * voteinfo_bar_new(bool split_bar)
static void voteinfo_bar_next_callback(GtkWidget *w, gpointer userdata)
GtkWidget * pregame_votebar
static void voteinfo_bar_destroy(GtkWidget *w, gpointer userdata)
#define fc_calloc(n, esz)
Definition mem.h:38
enum client_pages get_client_page(void)
Definition colors.h:21
Definition voting.h:46
GtkWidget * abstain_button
GtkWidget * next_button
GtkWidget * voter_count_label
GtkWidget * abstain_count_label
GtkWidget * box
GtkWidget * label
GtkWidget * yes_button
GtkWidget * no_button
GtkWidget * yes_count_label
GtkWidget * no_count_label
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void voteinfo_do_vote(int vote_no, enum client_vote_type vote)
Definition voteinfo.c:234
bool voteinfo_bar_can_be_shown(void)
Definition voteinfo.c:299
struct voteinfo * voteinfo_queue_get_current(int *pindex)
Definition voteinfo.c:201
void voteinfo_queue_next(void)
Definition voteinfo.c:272
int voteinfo_queue_size(void)
Definition voteinfo.c:291
client_vote_type
Definition voteinfo.h:22
@ CVT_YES
Definition voteinfo.h:24
@ CVT_NO
Definition voteinfo.h:25
@ CVT_ABSTAIN
Definition voteinfo.h:26