1 /* Pioneers - Implementation of the excellent Settlers of Catan board game.
2 * Go buy a copy.
3 *
4 * Copyright (C) 1999 Dave Cole
5 * Copyright (C) 2003 Bas Wijnen <shevek@fmf.nl>
6 * Copyright (C) 2004 Roland Clobus <rclobus@bigfoot.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "config.h"
24 #include "frontend.h"
25
26 static GtkWidget *monop_dlg;
27 static Resource monop_type;
28
monop_toggled(GtkToggleButton * btn,gpointer type)29 static void monop_toggled(GtkToggleButton * btn, gpointer type)
30 {
31 if (gtk_toggle_button_get_active(btn))
32 monop_type = GPOINTER_TO_INT(type);
33 }
34
add_resource_btn(GtkWidget * vbox,GSList * grp,Resource resource)35 static GSList *add_resource_btn(GtkWidget * vbox,
36 GSList * grp, Resource resource)
37 {
38 GtkWidget *btn;
39 gboolean active;
40
41 active = grp == NULL;
42 btn = gtk_radio_button_new_with_label(grp,
43 resource_name(resource,
44 TRUE));
45 grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(btn));
46 gtk_widget_show(btn);
47 gtk_box_pack_start(GTK_BOX(vbox), btn, TRUE, TRUE, 0);
48 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(btn), active);
49
50 g_signal_connect(G_OBJECT(btn), "toggled",
51 G_CALLBACK(monop_toggled),
52 GINT_TO_POINTER(resource));
53 if (active)
54 monop_type = resource;
55
56 return grp;
57 }
58
monopoly_destroyed(G_GNUC_UNUSED GtkWidget * widget,G_GNUC_UNUSED gpointer data)59 static void monopoly_destroyed(G_GNUC_UNUSED GtkWidget * widget,
60 G_GNUC_UNUSED gpointer data)
61 {
62 if (callback_mode == MODE_MONOPOLY)
63 monopoly_create_dlg();
64 }
65
monopoly_type(void)66 Resource monopoly_type(void)
67 {
68 return monop_type;
69 }
70
monopoly_create_dlg(void)71 void monopoly_create_dlg(void)
72 {
73 GtkWidget *dlg_vbox;
74 GtkWidget *vbox;
75 GtkWidget *lbl;
76 GSList *monop_grp = NULL;
77
78 if (monop_dlg != NULL) {
79 gtk_window_present(GTK_WINDOW(monop_dlg));
80 return;
81 };
82
83 /* Dialog caption */
84 monop_dlg = gtk_dialog_new_with_buttons(_("Monopoly"),
85 GTK_WINDOW(app_window),
86 GTK_DIALOG_DESTROY_WITH_PARENT,
87 /* Button text */
88 _("_OK"),
89 GTK_RESPONSE_OK, NULL);
90 g_signal_connect(G_OBJECT(monop_dlg), "destroy",
91 G_CALLBACK(gtk_widget_destroyed), &monop_dlg);
92 gtk_widget_realize(monop_dlg);
93 /* Disable close */
94 gdk_window_set_functions(gtk_widget_get_window(monop_dlg),
95 GDK_FUNC_ALL | GDK_FUNC_CLOSE);
96
97 dlg_vbox = gtk_dialog_get_content_area(GTK_DIALOG(monop_dlg));
98 gtk_widget_show(dlg_vbox);
99
100 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
101 gtk_widget_show(vbox);
102 gtk_box_pack_start(GTK_BOX(dlg_vbox), vbox, FALSE, TRUE, 0);
103 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
104
105 /* Label */
106 lbl = gtk_label_new(_("Select the resource you wish to "
107 "monopolize."));
108 gtk_widget_show(lbl);
109 gtk_box_pack_start(GTK_BOX(vbox), lbl, TRUE, TRUE, 0);
110 gtk_label_set_xalign(GTK_LABEL(lbl), 0.0);
111
112 monop_grp = add_resource_btn(vbox, monop_grp, BRICK_RESOURCE);
113 monop_grp = add_resource_btn(vbox, monop_grp, GRAIN_RESOURCE);
114 monop_grp = add_resource_btn(vbox, monop_grp, ORE_RESOURCE);
115 monop_grp = add_resource_btn(vbox, monop_grp, WOOL_RESOURCE);
116 add_resource_btn(vbox, monop_grp, LUMBER_RESOURCE);
117
118 frontend_gui_register(gui_get_dialog_button
119 (GTK_DIALOG(monop_dlg), 0), GUI_MONOPOLY,
120 "clicked");
121 gtk_dialog_set_default_response(GTK_DIALOG(monop_dlg),
122 GTK_RESPONSE_OK);
123 /* This _must_ be after frontend_gui_register, otherwise the
124 * regeneration of the button happens before the destruction, which
125 * results in an incorrectly sensitive OK button. */
126 g_signal_connect(gui_get_dialog_button(GTK_DIALOG(monop_dlg), 0),
127 "destroy", G_CALLBACK(monopoly_destroyed), NULL);
128 gtk_widget_show(monop_dlg);
129 frontend_gui_update();
130 }
131
monopoly_destroy_dlg(void)132 void monopoly_destroy_dlg(void)
133 {
134 if (monop_dlg == NULL)
135 return;
136
137 gtk_widget_destroy(monop_dlg);
138 monop_dlg = NULL;
139 }
140