1 /*
2
3 Euchre - a free as in freedom and as in beer version of the
4 euchre card game
5
6 Copyright 2002 C Nathan Buckles (nbuckles@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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 */
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <gtk/gtk.h>
29
30 #include <Debug.hpp>
31
32 #include "callbacks.hpp"
33 extern "C" {
34 #include "interface.h"
35 }
36 #include "support.hpp"
37 #include "globals.hpp"
38 #include "HumanGuiPlayer.hpp"
39 #include "GuiOptions.hpp"
40
41 void
on_new1_activate(GtkMenuItem * menuitem,gpointer user_data)42 on_new1_activate (GtkMenuItem *menuitem,
43 gpointer user_data)
44 {
45 theGame->addEvent(Game::START);
46 theGame->run();
47 }
48
49
50 void
on_exit1_activate(GtkMenuItem * menuitem,gpointer user_data)51 on_exit1_activate (GtkMenuItem *menuitem,
52 gpointer user_data)
53 {
54 gtk_main_quit();
55 }
56
57
58 void
on_properties1_activate(GtkMenuItem * menuitem,gpointer user_data)59 on_properties1_activate (GtkMenuItem *menuitem,
60 gpointer user_data)
61 {
62 gtk_widget_show(GTK_WIDGET(prefdiag));
63 }
64
65
66 void
on_passbutton_clicked(GtkButton * button,gpointer user_data)67 on_passbutton_clicked (GtkButton *button,
68 gpointer user_data)
69 {
70 Player* p = theGame->getPlayer(Common::SOUTH);
71 if (p != NULL) {
72 p->assignBid(Common::PASS);
73
74 theGame->addEvent(Game::AUCTION_CONT);
75 theGame->run();
76 }
77 }
78
79
80 void
on_pickitupbutton_clicked(GtkButton * button,gpointer user_data)81 on_pickitupbutton_clicked (GtkButton *button,
82 gpointer user_data)
83 {
84 Player* p = theGame->getPlayer(Common::SOUTH);
85 p->assignBid(Common::PICKITUP);
86
87 theGame->addEvent(Game::AUCTION_CONT);
88 theGame->run();
89 }
90
91
92 void
on_lonerbutton_clicked(GtkButton * button,gpointer user_data)93 on_lonerbutton_clicked (GtkButton *button,
94 gpointer user_data)
95 {
96 Player* p = theGame->getPlayer(Common::SOUTH);
97 p->assignBid(Common::LONER);
98
99 theGame->addEvent(Game::AUCTION_CONT);
100 theGame->run();
101 }
102
103 void
on_pcard_clicked(GtkButton * button,gpointer user_data)104 on_pcard_clicked (GtkButton *button,
105 gpointer user_data)
106 {
107 LOG("enter on_pcard_clicked with " << (long) user_data << std::endl);
108 HumanGuiPlayer* p = (HumanGuiPlayer*) theGame->getPlayer(Common::SOUTH);
109 if (p == NULL) {
110 return;
111 }
112
113 p->setSelectedCard((long) user_data);
114 theGame->addEvent(Game::PAUSE_END);
115 theGame->run();
116 }
117
118 void
on_bad_pcard_clicked(GtkButton * button,gpointer user_data)119 on_bad_pcard_clicked (GtkButton *button,
120 gpointer user_data)
121 {
122 LOG("### enter on_bad_pcard_clicked ###" << std::endl);
123 theGame->updateStatus("You must follow suit");
124 }
125
126 gboolean
on_root_button_press_event(GtkWidget * widget,GdkEventButton * event,gpointer user_data)127 on_root_button_press_event (GtkWidget *widget,
128 GdkEventButton *event,
129 gpointer user_data)
130 {
131 if (event->type == GDK_BUTTON_PRESS && theGame->isPaused()) {
132 theGame->addEvent(Game::PAUSE_END);
133 theGame->run();
134 return TRUE;
135 }
136
137 return FALSE;
138 }
139
140 void
on_auction2_clicked(GtkButton * button,gpointer user_data)141 on_auction2_clicked (GtkButton *button,
142 gpointer user_data)
143 {
144 Player* p = theGame->getPlayer(Common::SOUTH);
145 p->assignBid((Common::Bid) ((long) user_data));
146
147 theGame->addEvent(Game::AUCTION_CONT);
148 theGame->run();
149 }
150
151 void
on_pref_ok_clicked(GtkButton * button,gpointer user_data)152 on_pref_ok_clicked (GtkButton *button,
153 gpointer user_data)
154 {
155 gtk_widget_hide(GTK_WIDGET(prefdiag));
156
157 GuiOptions::get()->configure();
158 theGame->setOptions();
159 }
160
161
162 void
on_pref_apply_clicked(GtkButton * button,gpointer user_data)163 on_pref_apply_clicked (GtkButton *button,
164 gpointer user_data)
165 {
166 GuiOptions::get()->configure();
167 theGame->setOptions();
168 }
169
170
171 void
on_pref_cancel_clicked(GtkButton * button,gpointer user_data)172 on_pref_cancel_clicked (GtkButton *button,
173 gpointer user_data)
174 {
175 gtk_widget_hide(GTK_WIDGET(prefdiag));
176 }
177
178
179 gboolean
on_cardback_select_up_button_press_event(GtkWidget * widget,GdkEventButton * event,gpointer user_data)180 on_cardback_select_up_button_press_event (GtkWidget *widget,
181 GdkEventButton *event,
182 gpointer user_data)
183 {
184 return TRUE;
185 }
186
187
188 gboolean
on_cardback_select_down_button_press_event(GtkWidget * widget,GdkEventButton * event,gpointer user_data)189 on_cardback_select_down_button_press_event (GtkWidget *widget,
190 GdkEventButton *event,
191 gpointer user_data)
192 {
193
194 return TRUE;
195 }
196
197 void
on_bid_clicked(GtkButton * button,gpointer user_data)198 on_bid_clicked (GtkButton *button,
199 gpointer user_data)
200 {
201 GtkWidget* t = lookup_widget(mainwin, "bid_loner");
202 Player* p = theGame->getPlayer(Common::SOUTH);
203
204 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t))) {
205 p->assignBid(Common::LONER, (Card::Suit) (long) user_data);
206 } else {
207 p->assignBid(Common::PICKITUP, (Card::Suit) (long) user_data);
208 }
209
210 theGame->addEvent(Game::AUCTION_CONT);
211 theGame->run();
212 }
213
214 void
on_bid_pass_clicked(GtkButton * button,gpointer user_data)215 on_bid_pass_clicked (GtkButton *button,
216 gpointer user_data)
217 {
218 Player* p = theGame->getPlayer(Common::SOUTH);
219 if (p != NULL) {
220 p->assignBid(Common::PASS);
221
222 theGame->addEvent(Game::AUCTION_CONT);
223 theGame->run();
224 }
225 }
226
227 void
on_previous_tricks_activate(GtkMenuItem * menuitem,gpointer user_data)228 on_previous_tricks_activate (GtkMenuItem *menuitem,
229 gpointer user_data)
230 {
231 theGame->showPrevTrickDiag();
232 }
233
234
235 void
on_next_prev_trick_clicked(GtkButton * button,gpointer user_data)236 on_next_prev_trick_clicked (GtkButton *button,
237 gpointer user_data)
238 {
239 theGame->incrPrevTrickDiag(1);
240 }
241
242
243 void
on_prev_prev_trick_clicked(GtkButton * button,gpointer user_data)244 on_prev_prev_trick_clicked (GtkButton *button,
245 gpointer user_data)
246 {
247 theGame->incrPrevTrickDiag(-1);
248 }
249 void
on_prev_trick_ok_clicked(GtkButton * button,gpointer user_data)250 on_prev_trick_ok_clicked (GtkButton *button,
251 gpointer user_data)
252 {
253 theGame->hidePrevTrickDiag();
254 }
255