1 |
pcg |
1.36 |
use utf8; |
2 |
|
|
|
3 |
pcg |
1.82 |
use Scalar::Util (); |
4 |
|
|
|
5 |
root |
1.111 |
### GO CLOCK WIDGET ######################################################### |
6 |
|
|
|
7 |
pcg |
1.23 |
package game::goclock; |
8 |
|
|
|
9 |
pcg |
1.37 |
# Lo and Behold! I admit it! The rounding stuff etc.. in goclock |
10 |
|
|
# is completely borked. |
11 |
|
|
|
12 |
pcg |
1.23 |
use Time::HiRes (); |
13 |
|
|
|
14 |
|
|
use KGS::Constants; |
15 |
|
|
|
16 |
pcg |
1.82 |
use Glib::Object::Subclass |
17 |
|
|
Gtk2::Label; |
18 |
pcg |
1.23 |
|
19 |
pcg |
1.82 |
sub INIT_INSTANCE { |
20 |
|
|
my $self = shift; |
21 |
pcg |
1.23 |
|
22 |
pcg |
1.84 |
$self->signal_connect (destroy => sub { $_[0]->stop }); |
23 |
pcg |
1.83 |
|
24 |
pcg |
1.23 |
$self->{set} = sub { }; |
25 |
pcg |
1.86 |
$self->{format} = sub { "???" }; |
26 |
pcg |
1.82 |
} |
27 |
pcg |
1.23 |
|
28 |
root |
1.106 |
sub FINALIZE_INSTANCE { |
29 |
|
|
my $self = shift; |
30 |
|
|
|
31 |
|
|
$self->stop; |
32 |
|
|
} |
33 |
|
|
|
34 |
pcg |
1.38 |
sub configure { |
35 |
pcg |
1.23 |
my ($self, $timesys, $main, $interval, $count) = @_; |
36 |
|
|
|
37 |
|
|
if ($timesys == TIMESYS_ABSOLUTE) { |
38 |
pcg |
1.105 |
$self->{format} = sub { |
39 |
|
|
if ($_[0] <= 0) { |
40 |
|
|
"TIMEOUT"; |
41 |
|
|
} else { |
42 |
|
|
util::format_time $_[0]; |
43 |
|
|
} |
44 |
|
|
}; |
45 |
pcg |
1.23 |
|
46 |
|
|
} elsif ($timesys == TIMESYS_BYO_YOMI) { |
47 |
|
|
my $low = $interval * $count; |
48 |
|
|
|
49 |
|
|
$self->{format} = sub { |
50 |
pcg |
1.105 |
if ($_[0] <= 0) { |
51 |
|
|
"TIMEOUT"; |
52 |
|
|
} elsif ($_[0] > $low) { |
53 |
pcg |
1.37 |
util::format_time $_[0] - $low; |
54 |
pcg |
1.23 |
} else { |
55 |
pcg |
1.34 |
sprintf "%s (%d)", |
56 |
pcg |
1.37 |
util::format_time int (($_[0] - 1) % $interval + 1), |
57 |
pcg |
1.43 |
($_[0] - 1) / $interval; |
58 |
pcg |
1.23 |
} |
59 |
|
|
}; |
60 |
|
|
|
61 |
|
|
} elsif ($timesys == TIMESYS_CANADIAN) { |
62 |
|
|
$self->{format} = sub { |
63 |
pcg |
1.105 |
if ($_[0] <= 0) { |
64 |
|
|
"TIMEOUT"; |
65 |
|
|
} elsif (!$self->{moves}) { |
66 |
pcg |
1.37 |
util::format_time $_[0] - $low; |
67 |
pcg |
1.23 |
} else { |
68 |
pcg |
1.38 |
my $time = int (($_[0] - 1) % $interval + 1); |
69 |
|
|
|
70 |
pcg |
1.62 |
sprintf "%s/%d =%d", |
71 |
pcg |
1.37 |
util::format_time $time, |
72 |
pcg |
1.34 |
$self->{moves}, |
73 |
pcg |
1.75 |
$self->{moves} > 1 |
74 |
|
|
? $time / $self->{moves} |
75 |
|
|
: $interval; |
76 |
pcg |
1.23 |
} |
77 |
|
|
}; |
78 |
|
|
|
79 |
|
|
} else { |
80 |
|
|
# none, or unknown |
81 |
pcg |
1.105 |
$self->{format} = sub { "-" } |
82 |
pcg |
1.23 |
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
sub refresh { |
86 |
|
|
my ($self, $timestamp) = @_; |
87 |
pcg |
1.38 |
my $timer = $self->{time} + $self->{start} - $timestamp; |
88 |
pcg |
1.102 |
|
89 |
pcg |
1.36 |
# we round the timer value slightly... the protocol isn't exact anyways, |
90 |
|
|
# and this gives smoother timers ;) |
91 |
pcg |
1.102 |
my $timer2 = int $timer + 0.4; |
92 |
|
|
|
93 |
pcg |
1.105 |
$self->set_text ($self->{format}->($timer2)); |
94 |
pcg |
1.23 |
|
95 |
|
|
$timer - int $timer; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
sub set_time { |
99 |
root |
1.106 |
my ($self, $start, $time, $moves) = @_; |
100 |
|
|
|
101 |
|
|
$self->{time} = $time; |
102 |
|
|
$self->{moves} = $moves; |
103 |
pcg |
1.23 |
|
104 |
root |
1.106 |
if ($start) { |
105 |
|
|
$self->{start} = $start; |
106 |
|
|
$self->start; |
107 |
|
|
} else { |
108 |
|
|
$self->stop; |
109 |
pcg |
1.27 |
$self->refresh ($self->{start}); |
110 |
|
|
} |
111 |
pcg |
1.23 |
} |
112 |
|
|
|
113 |
|
|
sub start { |
114 |
root |
1.106 |
my ($self) = @_; |
115 |
pcg |
1.23 |
|
116 |
pcg |
1.36 |
$self->stop; |
117 |
pcg |
1.23 |
|
118 |
|
|
my $timeout; $timeout = sub { |
119 |
pcg |
1.36 |
my $next = $self->refresh (Time::HiRes::time) * 1000; |
120 |
pcg |
1.27 |
$next += 1000 if $next < 0; |
121 |
pcg |
1.23 |
$self->{timeout} = add Glib::Timeout $next, $timeout; |
122 |
|
|
0; |
123 |
|
|
}; |
124 |
|
|
|
125 |
|
|
$timeout->(); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
sub stop { |
129 |
|
|
my ($self) = @_; |
130 |
|
|
|
131 |
|
|
remove Glib::Source delete $self->{timeout} if $self->{timeout}; |
132 |
pcg |
1.24 |
} |
133 |
|
|
|
134 |
root |
1.111 |
### USER PANEL ############################################################## |
135 |
|
|
|
136 |
pcg |
1.23 |
package game::userpanel; |
137 |
|
|
|
138 |
pcg |
1.82 |
use Glib::Object::Subclass |
139 |
|
|
Gtk2::HBox, |
140 |
|
|
properties => [ |
141 |
|
|
Glib::ParamSpec->IV ("colour", "colour", "User Colour", 0, 1, 0, [qw(construct-only writable)]), |
142 |
|
|
]; |
143 |
pcg |
1.23 |
|
144 |
pcg |
1.82 |
sub INIT_INSTANCE { |
145 |
|
|
my ($self) = @_; |
146 |
pcg |
1.23 |
|
147 |
pcg |
1.82 |
$self->add (my $vbox = new Gtk2::VBox); |
148 |
pcg |
1.26 |
|
149 |
|
|
$vbox->add ($self->{name} = new Gtk2::Label $self->{name}); |
150 |
|
|
$vbox->add ($self->{info} = new Gtk2::Label ""); |
151 |
pcg |
1.82 |
$vbox->add ($self->{clock} = new game::goclock); Scalar::Util::weaken $self->{clock}; |
152 |
pcg |
1.23 |
|
153 |
pcg |
1.32 |
$vbox->add ($self->{imagebox} = new Gtk2::VBox); |
154 |
|
|
|
155 |
pcg |
1.23 |
$self; |
156 |
|
|
} |
157 |
|
|
|
158 |
pcg |
1.37 |
sub configure { |
159 |
pcg |
1.69 |
my ($self, $app, $user, $rules) = @_; |
160 |
pcg |
1.23 |
|
161 |
pcg |
1.38 |
if ($self->{name}->get_text ne $user->as_string) { |
162 |
|
|
$self->{name}->set_text ($user->as_string); |
163 |
pcg |
1.26 |
|
164 |
pcg |
1.32 |
$self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; |
165 |
|
|
$self->{imagebox}->add (gtk::image_from_data undef); |
166 |
pcg |
1.33 |
$self->{imagebox}->show_all; |
167 |
pcg |
1.32 |
|
168 |
pcg |
1.52 |
if ($user->has_pic) { |
169 |
|
|
# the big picture... |
170 |
pcg |
1.69 |
$app->userpic ($user->{name}, sub { |
171 |
pcg |
1.52 |
return unless $self->{imagebox}; |
172 |
pcg |
1.69 |
|
173 |
pcg |
1.52 |
if ($_[0]) { |
174 |
|
|
$self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; |
175 |
|
|
$self->{imagebox}->add (gtk::image_from_data $_[0]); |
176 |
|
|
$self->{imagebox}->show_all; |
177 |
|
|
} |
178 |
|
|
}); |
179 |
|
|
} |
180 |
pcg |
1.26 |
} |
181 |
|
|
|
182 |
pcg |
1.38 |
$self->{clock}->configure (@{$rules}{qw(timesys time interval count)}); |
183 |
pcg |
1.23 |
} |
184 |
|
|
|
185 |
pcg |
1.102 |
sub set_captures { |
186 |
|
|
my ($self, $captures) = @_; |
187 |
|
|
|
188 |
|
|
$self->{info}->set_text ("$captures pris."); |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
sub set_timer { |
192 |
root |
1.106 |
my ($self, $start, $time, $moves) = @_; |
193 |
pcg |
1.23 |
|
194 |
root |
1.106 |
$self->{clock}->set_time ($start, $time, $moves); |
195 |
pcg |
1.23 |
} |
196 |
|
|
|
197 |
root |
1.111 |
### GAME WINDOW ############################################################# |
198 |
|
|
|
199 |
pcg |
1.1 |
package game; |
200 |
|
|
|
201 |
pcg |
1.83 |
use Scalar::Util qw(weaken); |
202 |
|
|
|
203 |
pcg |
1.1 |
use KGS::Constants; |
204 |
|
|
use KGS::Game::Board; |
205 |
|
|
|
206 |
pcg |
1.74 |
use Gtk2::GoBoard; |
207 |
pcg |
1.97 |
use Gtk2::GoBoard::Constants; |
208 |
pcg |
1.74 |
|
209 |
pcg |
1.102 |
use base KGS::Game; |
210 |
|
|
use base KGS::Listener::Game; |
211 |
|
|
|
212 |
pcg |
1.83 |
use Glib::Object::Subclass |
213 |
|
|
Gtk2::Window; |
214 |
|
|
|
215 |
pcg |
1.15 |
use POSIX qw(ceil); |
216 |
|
|
|
217 |
pcg |
1.1 |
sub new { |
218 |
pcg |
1.83 |
my ($self, %arg) = @_; |
219 |
|
|
$self = $self->Glib::Object::new; |
220 |
|
|
$self->{$_} = delete $arg{$_} for keys %arg; |
221 |
pcg |
1.1 |
|
222 |
pcg |
1.83 |
gtk::state $self, "game::window", undef, window_size => [600, 500]; |
223 |
pcg |
1.1 |
|
224 |
pcg |
1.87 |
$self->signal_connect (destroy => sub { |
225 |
|
|
$self->unlisten; |
226 |
|
|
delete $self->{app}{game}{$self->{channel}}; |
227 |
|
|
%{$_[0]} = (); |
228 |
|
|
});#d# |
229 |
pcg |
1.1 |
|
230 |
pcg |
1.83 |
$self->add (my $hpane = new Gtk2::HPaned); |
231 |
|
|
gtk::state $hpane, "game::hpane", undef, position => 500; |
232 |
pcg |
1.1 |
|
233 |
pcg |
1.36 |
# LEFT PANE |
234 |
|
|
|
235 |
pcg |
1.83 |
$hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0); |
236 |
pcg |
1.31 |
|
237 |
|
|
$self->{boardbox} = new Gtk2::VBox; |
238 |
|
|
|
239 |
pcg |
1.83 |
$hpane->pack1((my $vbox = new Gtk2::VBox), 1, 1); |
240 |
pcg |
1.1 |
|
241 |
pcg |
1.31 |
# board box (aspect/canvas) |
242 |
|
|
|
243 |
pcg |
1.91 |
#$self->{boardbox}->pack_start((my $frame = new Gtk2::Frame), 0, 1, 0); |
244 |
|
|
|
245 |
|
|
# RIGHT PANE |
246 |
|
|
|
247 |
|
|
$hpane->pack2 ((my $vbox = new Gtk2::VBox), 1, 1); |
248 |
|
|
$hpane->set (position_set => 1); |
249 |
|
|
|
250 |
|
|
$vbox->pack_start ((my $frame = new Gtk2::Frame), 0, 1, 0); |
251 |
pcg |
1.1 |
|
252 |
|
|
{ |
253 |
pcg |
1.66 |
$frame->add (my $vbox = new Gtk2::VBox); |
254 |
|
|
$vbox->add ($self->{title} = new Gtk2::Label $title); |
255 |
|
|
|
256 |
|
|
$vbox->add (my $hbox = new Gtk2::HBox); |
257 |
|
|
|
258 |
|
|
$hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 1, 0); |
259 |
pcg |
1.1 |
|
260 |
pcg |
1.63 |
$self->{moveadj} = new Gtk2::Adjustment 1, 1, 1, 1, 5, 0; |
261 |
pcg |
1.2 |
|
262 |
pcg |
1.66 |
$hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0); |
263 |
pcg |
1.2 |
$scale->set_draw_value (0); |
264 |
pcg |
1.30 |
$scale->set_digits (0); |
265 |
pcg |
1.1 |
|
266 |
pcg |
1.104 |
$self->{moveadj}->signal_connect (value_changed => sub { |
267 |
|
|
$self->{showmove} = int $self->{moveadj}->get_value; |
268 |
|
|
$self->update_board; |
269 |
|
|
}); |
270 |
pcg |
1.1 |
} |
271 |
pcg |
1.31 |
|
272 |
pcg |
1.83 |
$vbox->pack_start ((my $hbox = new Gtk2::HBox 1), 0, 1, 0); |
273 |
pcg |
1.82 |
|
274 |
pcg |
1.83 |
$hbox->add ($self->{userpanel}[$_] = new game::userpanel colour => $_) |
275 |
|
|
for COLOUR_WHITE, COLOUR_BLACK; |
276 |
pcg |
1.100 |
|
277 |
|
|
$vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); |
278 |
|
|
|
279 |
pcg |
1.101 |
$buttonbox->add ($self->{button_pass} = |
280 |
pcg |
1.102 |
Gtk2::Button->Glib::Object::new (label => "Pass", no_show_all => 1, visible => 0)); |
281 |
pcg |
1.101 |
$self->{button_pass}->signal_connect (clicked => sub { |
282 |
|
|
$self->{board_click}->(255, 255) if $self->{board_click}; |
283 |
|
|
}); |
284 |
pcg |
1.102 |
$buttonbox->add ($self->{button_undo} = |
285 |
|
|
Gtk2::Button->Glib::Object::new (label => "Undo", no_show_all => 1, visible => 0)); |
286 |
|
|
$self->{button_undo}->signal_connect (clicked => sub { |
287 |
|
|
$self->send (req_undo => channel => $self->{channel}); |
288 |
|
|
}); |
289 |
|
|
$buttonbox->add ($self->{button_resign} = |
290 |
|
|
Gtk2::Button->Glib::Object::new (label => "Resign", no_show_all => 1, visible => 0)); |
291 |
|
|
$self->{button_resign}->signal_connect (clicked => sub { |
292 |
|
|
$self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); |
293 |
|
|
}); |
294 |
pcg |
1.1 |
|
295 |
pcg |
1.86 |
$vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); |
296 |
pcg |
1.73 |
|
297 |
pcg |
1.96 |
$self->set_channel ($self->{channel}); |
298 |
pcg |
1.86 |
|
299 |
pcg |
1.96 |
$self->show_all; |
300 |
pcg |
1.1 |
|
301 |
|
|
$self; |
302 |
|
|
} |
303 |
|
|
|
304 |
pcg |
1.96 |
sub set_channel { |
305 |
|
|
my ($self, $channel) = @_; |
306 |
|
|
|
307 |
|
|
$self->{channel} = $channel; |
308 |
|
|
|
309 |
|
|
if ($self->{channel} > 0) { |
310 |
|
|
$self->listen ($self->{conn}); |
311 |
|
|
|
312 |
|
|
$self->{rules_inlay} = $self->{chat}->new_switchable_inlay ("Game Setup:", sub { $self->draw_setup (@_) }, 1); |
313 |
|
|
$self->{users_inlay} = $self->{chat}->new_switchable_inlay ("Users:", sub { $self->draw_users (@_) }, 1); |
314 |
|
|
|
315 |
|
|
$self->signal_connect (delete_event => sub { $self->part; 1 }); |
316 |
|
|
$self->{chat}->signal_connect (command => sub { |
317 |
|
|
my ($chat, $cmd, $arg) = @_; |
318 |
|
|
if ($cmd eq "rsave") { |
319 |
|
|
Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d# |
320 |
|
|
} else { |
321 |
|
|
$self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self); |
322 |
|
|
} |
323 |
|
|
}); |
324 |
|
|
} |
325 |
|
|
} |
326 |
|
|
|
327 |
root |
1.111 |
### JOIN/LEAVE ############################################################## |
328 |
|
|
|
329 |
|
|
sub join { |
330 |
|
|
my ($self) = @_; |
331 |
|
|
return if $self->{joined}; |
332 |
|
|
|
333 |
|
|
$self->SUPER::join; |
334 |
|
|
} |
335 |
|
|
|
336 |
|
|
sub event_join { |
337 |
|
|
my ($self) = @_; |
338 |
|
|
|
339 |
|
|
$self->SUPER::event_join (@_); |
340 |
|
|
$self->init_tree; |
341 |
|
|
$self->event_update_game; |
342 |
|
|
} |
343 |
|
|
|
344 |
|
|
sub event_part { |
345 |
|
|
my ($self) = @_; |
346 |
|
|
|
347 |
|
|
$self->SUPER::event_part; |
348 |
|
|
$self->destroy; |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
### USERS ################################################################### |
352 |
|
|
|
353 |
|
|
sub draw_users { |
354 |
|
|
my ($self, $inlay) = @_; |
355 |
|
|
|
356 |
|
|
for (sort keys %{$self->{users}}) { |
357 |
|
|
$inlay->append_text (" <user>" . $self->{users}{$_}->as_string . "</user>"); |
358 |
|
|
} |
359 |
|
|
} |
360 |
|
|
|
361 |
pcg |
1.1 |
sub event_update_users { |
362 |
pcg |
1.18 |
my ($self, $add, $update, $remove) = @_; |
363 |
pcg |
1.1 |
|
364 |
pcg |
1.88 |
# $self->{userlist}->update ($add, $update, $remove); |
365 |
pcg |
1.70 |
|
366 |
pcg |
1.97 |
$self->{challenge}{$_->{name}} && (delete $self->{challenge}{$_->{name}})->{inlay}->destroy |
367 |
|
|
for @$remove; |
368 |
|
|
|
369 |
pcg |
1.88 |
$self->{users_inlay}->refresh; |
370 |
pcg |
1.57 |
|
371 |
|
|
my %important; |
372 |
pcg |
1.98 |
$important{$self->{black}{name}}++; |
373 |
|
|
$important{$self->{white}{name}}++; |
374 |
|
|
$important{$self->{owner}{name}}++; |
375 |
pcg |
1.57 |
|
376 |
|
|
if (my @users = grep $important{$_->{name}}, @$add) { |
377 |
pcg |
1.73 |
$self->{chat}->append_text ("\n<header>Joins:</header>"); |
378 |
|
|
$self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; |
379 |
pcg |
1.57 |
} |
380 |
|
|
if (my @users = grep $important{$_->{name}}, @$remove) { |
381 |
pcg |
1.73 |
$self->{chat}->append_text ("\n<header>Parts:</header>"); |
382 |
|
|
$self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; |
383 |
pcg |
1.57 |
} |
384 |
pcg |
1.1 |
} |
385 |
|
|
|
386 |
root |
1.111 |
### GAME INFO ############################################################### |
387 |
|
|
|
388 |
|
|
sub draw_setup { |
389 |
|
|
my ($self, $inlay) = @_; |
390 |
|
|
|
391 |
|
|
return unless $self->{joined}; |
392 |
|
|
|
393 |
|
|
my $rules = $self->{rules}; |
394 |
|
|
|
395 |
|
|
my $text = ""; |
396 |
|
|
|
397 |
|
|
$text .= "\nTeacher: <user>" . (util::toxml $self->{teacher}) . "</user>" |
398 |
|
|
if $self->{teacher}; |
399 |
|
|
|
400 |
|
|
$text .= "\nOwner: <user>" . (util::toxml $self->{owner}->as_string) . "</user>" |
401 |
|
|
if $self->{owner}->is_valid; |
402 |
|
|
|
403 |
|
|
if ($self->is_inprogress) { |
404 |
|
|
$text .= "\nPlayers: <user>" . (util::toxml $self->{white}->as_string) . "</user>" |
405 |
|
|
. " vs. <user>" . (util::toxml $self->{black}->as_string) . "</user>"; |
406 |
|
|
} |
407 |
|
|
$text .= "\nType: " . util::toxml $gametype{$self->type}; |
408 |
|
|
|
409 |
|
|
$text .= "\nRuleset: " . $ruleset{$rules->{ruleset}}; |
410 |
|
|
|
411 |
|
|
$text .= "\nTime: "; |
412 |
|
|
|
413 |
|
|
if ($rules->{timesys} == TIMESYS_NONE) { |
414 |
|
|
$text .= "UNLIMITED"; |
415 |
|
|
} elsif ($rules->{timesys} == TIMESYS_ABSOLUTE) { |
416 |
|
|
$text .= util::format_time $rules->{time}; |
417 |
|
|
$text .= " ABS"; |
418 |
|
|
} elsif ($rules->{timesys} == TIMESYS_BYO_YOMI) { |
419 |
|
|
$text .= util::format_time $rules->{time}; |
420 |
|
|
$text .= sprintf " + %s (%d) BY", util::format_time $rules->{interval}, $rules->{count}; |
421 |
|
|
} elsif ($rules->{timesys} == TIMESYS_CANADIAN) { |
422 |
|
|
$text .= util::format_time $rules->{time}; |
423 |
|
|
$text .= sprintf " + %s/%d CAN", util::format_time $rules->{interval}, $rules->{count}; |
424 |
|
|
} |
425 |
|
|
|
426 |
|
|
$text .= "\nFlags:"; |
427 |
|
|
$text .= " private" if $self->is_private; |
428 |
|
|
$text .= " started" if $self->is_inprogress; |
429 |
|
|
$text .= " adjourned" if $self->is_adjourned; |
430 |
|
|
$text .= " scored" if $self->is_scored; |
431 |
|
|
$text .= " saved" if $self->is_saved; |
432 |
|
|
|
433 |
|
|
if ($self->is_inprogress) { |
434 |
|
|
$text .= "\nHandicap: " . $self->{handicap}; |
435 |
|
|
$text .= "\nKomi: " . $self->{komi}; |
436 |
|
|
$text .= "\nSize: " . $self->size_string; |
437 |
|
|
} |
438 |
|
|
|
439 |
|
|
if ($self->is_scored) { |
440 |
|
|
$text .= "\nResult: " . $self->score_string; |
441 |
|
|
} |
442 |
|
|
|
443 |
|
|
$inlay->append_text ("<infoblock>$text</infoblock>"); |
444 |
|
|
|
445 |
|
|
} |
446 |
|
|
|
447 |
|
|
sub event_update_game { |
448 |
pcg |
1.1 |
my ($self) = @_; |
449 |
pcg |
1.21 |
|
450 |
root |
1.111 |
$self->SUPER::event_update_game; |
451 |
|
|
|
452 |
|
|
return unless $self->{joined}; |
453 |
|
|
|
454 |
|
|
$self->{colour} = $self->player_colour ($self->{conn}{name}); |
455 |
|
|
|
456 |
|
|
my $title = defined $self->{channel} |
457 |
|
|
? $self->owner->as_string . " " . $self->opponent_string |
458 |
|
|
: "Game Window"; |
459 |
|
|
$self->set_title ("KGS Game $title"); |
460 |
|
|
$self->{title}->set_text ($title); |
461 |
|
|
|
462 |
|
|
$self->{user}[COLOUR_BLACK] = $self->{black}; |
463 |
|
|
$self->{user}[COLOUR_WHITE] = $self->{white}; |
464 |
|
|
|
465 |
|
|
# show board |
466 |
|
|
if ($self->is_inprogress) { |
467 |
|
|
if (!$self->{boardbox}->parent) { |
468 |
|
|
$self->{boardbox}->add ($self->{board} = new Gtk2::GoBoard size => $self->{size}); |
469 |
|
|
$self->{left}->add ($self->{boardbox}); |
470 |
|
|
$self->{board}->signal_connect (button_release => sub { |
471 |
|
|
if ($_[1] == 1) { |
472 |
|
|
$self->{board_click}->($_[2], $_[3]) if $self->{board_click}; |
473 |
|
|
} |
474 |
|
|
}); |
475 |
|
|
} |
476 |
|
|
if (my $ch = delete $self->{challenge}) { |
477 |
|
|
$_->{inlay}->destroy for values %$ch; |
478 |
|
|
} |
479 |
|
|
$self->update_cursor; |
480 |
|
|
} |
481 |
|
|
|
482 |
|
|
$self->{left}->show_all; |
483 |
|
|
|
484 |
|
|
$self->{rules_inlay}->refresh; |
485 |
|
|
|
486 |
|
|
} |
487 |
|
|
|
488 |
|
|
sub event_update_rules { |
489 |
|
|
my ($self, $rules) = @_; |
490 |
|
|
|
491 |
|
|
$self->{rules} = $rules; |
492 |
|
|
|
493 |
|
|
if ($self->{user}) { |
494 |
|
|
$self->{userpanel}[$_]->configure ($self->{app}, $self->{user}[$_], $rules) |
495 |
|
|
for COLOUR_BLACK, COLOUR_WHITE; |
496 |
|
|
} |
497 |
|
|
|
498 |
|
|
sound::play 3, "gamestart"; |
499 |
|
|
$self->{rules_inlay}->refresh; |
500 |
|
|
} |
501 |
|
|
|
502 |
|
|
### BOARD DISPLAY ########################################################### |
503 |
|
|
|
504 |
|
|
sub update_timers { |
505 |
|
|
my ($self, $timers) = @_; |
506 |
|
|
|
507 |
|
|
my $running = $self->{showmove} == @{$self->{path}} && !$self->{teacher}; |
508 |
|
|
|
509 |
|
|
for my $colour (COLOUR_BLACK, COLOUR_WHITE) { |
510 |
|
|
my $t = $timers->[$colour]; |
511 |
|
|
$self->{userpanel}[$colour]->set_timer ( |
512 |
|
|
$running && $colour == $self->{whosemove} && $t->[0], |
513 |
|
|
$t->[1] || $self->{rules}{time} |
514 |
|
|
+ ($self->{rules}{timesys} == TIMESYS_BYO_YOMI |
515 |
|
|
&& $self->{rules}{interval} * $self->{rules}{count}), |
516 |
|
|
$t->[2] || $self->{rules}{count}); |
517 |
|
|
} |
518 |
|
|
} |
519 |
|
|
|
520 |
|
|
sub inject_set_gametime { |
521 |
|
|
my ($self, $msg) = @_; |
522 |
|
|
|
523 |
|
|
$self->{timers} = [ |
524 |
|
|
[$msg->{NOW}, $msg->{black_time}, $msg->{black_moves}], |
525 |
|
|
[$msg->{NOW}, $msg->{white_time}, $msg->{white_moves}], |
526 |
|
|
]; |
527 |
|
|
|
528 |
|
|
$self->update_timers ($self->{timers}) |
529 |
|
|
if $self->{showmove} == @{$self->{path}}; |
530 |
pcg |
1.1 |
} |
531 |
|
|
|
532 |
pcg |
1.97 |
sub update_cursor { |
533 |
|
|
my ($self) = @_; |
534 |
|
|
|
535 |
pcg |
1.104 |
my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; |
536 |
pcg |
1.99 |
|
537 |
|
|
delete $self->{board_click}; |
538 |
|
|
|
539 |
|
|
if ($self->{teacher} eq $self->{app}{conn}) { |
540 |
|
|
#TODO# # teaching mode not implemented |
541 |
root |
1.107 |
$self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); |
542 |
pcg |
1.102 |
$self->{button_undo}->hide; |
543 |
|
|
$self->{button_resign}->hide; |
544 |
pcg |
1.101 |
$self->{board}->set (cursor => undef); |
545 |
|
|
|
546 |
|
|
} elsif ($running && $self->{colour} != COLOUR_NONE) { |
547 |
|
|
# during game |
548 |
pcg |
1.102 |
$self->{button_undo}->show; |
549 |
|
|
$self->{button_resign}->show; |
550 |
pcg |
1.101 |
|
551 |
|
|
if ($self->{cur_board}{score}) { |
552 |
|
|
# during scoring |
553 |
root |
1.107 |
$self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); |
554 |
pcg |
1.101 |
$self->{board}->set (cursor => sub { |
555 |
|
|
$_[0] & (MARK_B | MARK_W) |
556 |
|
|
? $_[0] ^ MARK_GRAYED |
557 |
|
|
: $_[0]; |
558 |
|
|
}); |
559 |
|
|
$self->{board_click} = sub { |
560 |
|
|
if ($_[0] == 255) { |
561 |
|
|
$self->{button_pass}->sensitive (0); |
562 |
|
|
$self->done; |
563 |
|
|
} else { |
564 |
|
|
$self->send (mark_dead => |
565 |
|
|
channel => $self->{channel}, |
566 |
|
|
x => $_[0], |
567 |
|
|
y => $_[1], |
568 |
|
|
dead => !($self->{cur_board}{board}[$_[0]][$_[1]] & MARK_GRAYED), |
569 |
|
|
); |
570 |
|
|
} |
571 |
|
|
}; |
572 |
|
|
|
573 |
root |
1.106 |
} elsif ($self->{colour} == $self->{whosemove}) { |
574 |
pcg |
1.101 |
# normal move |
575 |
root |
1.107 |
$self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); |
576 |
pcg |
1.101 |
$self->{board}->set (cursor => sub { |
577 |
|
|
# if is_valid_move oder so#TODO# |
578 |
|
|
$_[0] & (MARK_B | MARK_W) |
579 |
|
|
? $_[0] |
580 |
|
|
: $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B); |
581 |
|
|
}); |
582 |
|
|
$self->{board_click} = sub { |
583 |
|
|
$self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); |
584 |
|
|
$self->{board}->set (cursor => undef); |
585 |
|
|
delete $self->{board_click}; |
586 |
|
|
$self->{button_pass}->sensitive (0); |
587 |
|
|
}; |
588 |
|
|
} else { |
589 |
|
|
$self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); |
590 |
root |
1.106 |
$self->{board}->set (cursor => undef); |
591 |
pcg |
1.101 |
} |
592 |
|
|
} else { |
593 |
pcg |
1.102 |
$self->{button_undo}->hide; |
594 |
|
|
$self->{button_resign}->hide; |
595 |
pcg |
1.101 |
$self->{button_pass}->hide; |
596 |
|
|
$self->{board}->set (cursor => undef); |
597 |
pcg |
1.99 |
#TODO# # implement coordinate-grabbing |
598 |
pcg |
1.97 |
} |
599 |
|
|
} |
600 |
|
|
|
601 |
pcg |
1.23 |
sub update_board { |
602 |
|
|
my ($self) = @_; |
603 |
|
|
return unless $self->{path}; |
604 |
|
|
|
605 |
pcg |
1.104 |
$self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); |
606 |
pcg |
1.23 |
|
607 |
pcg |
1.64 |
$self->{cur_board} = new KGS::Game::Board $self->{size}; |
608 |
pcg |
1.104 |
$self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); |
609 |
pcg |
1.47 |
|
610 |
pcg |
1.102 |
$self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) |
611 |
|
|
for COLOUR_WHITE, COLOUR_BLACK; |
612 |
pcg |
1.23 |
|
613 |
root |
1.106 |
if ($self->{rules}{ruleset} == RULESET_JAPANESE) { |
614 |
|
|
if ($self->{curnode}{move} == 0) { |
615 |
|
|
$self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; |
616 |
|
|
} else { |
617 |
|
|
$self->{whosemove} = 1 - $self->{cur_board}{last}; |
618 |
|
|
} |
619 |
|
|
} else { |
620 |
|
|
# Chinese, Aga, NZ all have manual placement |
621 |
|
|
if ($self->{curnode}{move} < $self->{handicap}) { |
622 |
|
|
$self->{whosemove} = COLOUR_BLACK; |
623 |
|
|
} elsif ($self->{curnode}{move} == $self->{handicap}) { |
624 |
root |
1.109 |
$self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; |
625 |
root |
1.106 |
} else { |
626 |
|
|
$self->{whosemove} = 1 - $self->{cur_board}{last}; |
627 |
|
|
} |
628 |
|
|
} |
629 |
|
|
|
630 |
|
|
my $start_time = $self->{rules}{time}; |
631 |
|
|
|
632 |
pcg |
1.104 |
if ($self->{showmove} == @{$self->{path}}) { |
633 |
|
|
$self->{timers} = [ |
634 |
|
|
[$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], |
635 |
|
|
[$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], |
636 |
|
|
]; |
637 |
|
|
$self->update_timers ($self->{timers}); |
638 |
pcg |
1.103 |
} else { |
639 |
pcg |
1.104 |
$self->update_timers ([ |
640 |
|
|
[0, @{$self->{cur_board}{timer}[0]}], |
641 |
|
|
[0, @{$self->{cur_board}{timer}[1]}], |
642 |
|
|
]); |
643 |
pcg |
1.103 |
} |
644 |
|
|
|
645 |
pcg |
1.64 |
$self->{board}->set_board ($self->{cur_board}); |
646 |
pcg |
1.97 |
|
647 |
pcg |
1.105 |
if ($self->{cur_board}{score}) { |
648 |
|
|
$self->{score_inlay} ||= $self->{chat}->new_inlay; |
649 |
|
|
$self->{score_inlay}->clear; |
650 |
|
|
$self->{score_inlay}->append_text ("\n<header>Scoring</header>" |
651 |
|
|
. "\n<score>" |
652 |
|
|
. "White: $self->{cur_board}{score}[COLOUR_WHITE], " |
653 |
|
|
. "Black: $self->{cur_board}{score}[COLOUR_BLACK]" |
654 |
|
|
. "</score>"); |
655 |
|
|
} elsif ($self->{score_inlay}) { |
656 |
|
|
(delete $self->{score_inlay})->clear; |
657 |
|
|
} |
658 |
|
|
|
659 |
pcg |
1.97 |
$self->update_cursor; |
660 |
pcg |
1.23 |
} |
661 |
|
|
|
662 |
pcg |
1.1 |
sub event_update_tree { |
663 |
|
|
my ($self) = @_; |
664 |
|
|
|
665 |
root |
1.106 |
(delete $self->{undo_inlay})->clear |
666 |
|
|
if $self->{undo_inlay}; |
667 |
|
|
|
668 |
pcg |
1.1 |
$self->{path} = $self->get_path; |
669 |
pcg |
1.30 |
|
670 |
|
|
if ($self->{moveadj}) { |
671 |
|
|
my $upper = $self->{moveadj}->upper; |
672 |
|
|
my $pos = $self->{moveadj}->get_value; |
673 |
pcg |
1.48 |
my $move = scalar @{$self->{path}}; |
674 |
pcg |
1.30 |
|
675 |
pcg |
1.48 |
$self->{moveadj}->upper ($move); |
676 |
pcg |
1.30 |
|
677 |
|
|
$self->{moveadj}->changed; |
678 |
|
|
if ($pos == $upper) { |
679 |
pcg |
1.48 |
$self->{moveadj}->value ($move); |
680 |
|
|
$self->{moveadj}->value_changed; |
681 |
pcg |
1.30 |
} |
682 |
|
|
} |
683 |
pcg |
1.29 |
} |
684 |
|
|
|
685 |
|
|
sub event_update_comments { |
686 |
|
|
my ($self, $node, $comment, $newnode) = @_; |
687 |
|
|
$self->SUPER::event_update_comments($node, $comment, $newnode); |
688 |
|
|
|
689 |
pcg |
1.30 |
my $text; |
690 |
|
|
|
691 |
pcg |
1.34 |
$text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>" |
692 |
pcg |
1.29 |
if $newnode; |
693 |
|
|
|
694 |
pcg |
1.30 |
for (split /\n/, $comment) { |
695 |
|
|
$text .= "\n"; |
696 |
pcg |
1.40 |
if (s/^([0-9a-zA-Z]+ \[[0-9dkp\?\-]+\])://) { |
697 |
pcg |
1.30 |
$text .= "<user>" . (util::toxml $1) . "</user>:"; |
698 |
|
|
} |
699 |
pcg |
1.40 |
|
700 |
|
|
# coords only for 19x19 so far |
701 |
|
|
$_ = util::toxml $_; |
702 |
pcg |
1.39 |
s{ |
703 |
|
|
( |
704 |
|
|
\b |
705 |
|
|
(?:[bw])? |
706 |
|
|
[, ]{0,2} |
707 |
pcg |
1.41 |
[a-hj-t] # valid for upto 19x19 |
708 |
pcg |
1.40 |
\s? |
709 |
pcg |
1.42 |
[1-9]?[0-9] |
710 |
pcg |
1.40 |
\b |
711 |
pcg |
1.39 |
) |
712 |
|
|
}{ |
713 |
|
|
"<coord>$1</coord>"; |
714 |
|
|
}sgexi; |
715 |
|
|
|
716 |
pcg |
1.30 |
$text .= $_; |
717 |
|
|
} |
718 |
|
|
|
719 |
pcg |
1.73 |
$self->{chat}->append_text ($text); |
720 |
pcg |
1.1 |
} |
721 |
|
|
|
722 |
|
|
sub event_move { |
723 |
|
|
my ($self, $pass) = @_; |
724 |
root |
1.107 |
|
725 |
pcg |
1.1 |
sound::play 1, $pass ? "pass" : "move"; |
726 |
pcg |
1.25 |
} |
727 |
|
|
|
728 |
root |
1.111 |
### GAMEPLAY EVENTS ######################################################### |
729 |
pcg |
1.38 |
|
730 |
pcg |
1.100 |
sub event_resign_game { |
731 |
|
|
my ($self, $player) = @_; |
732 |
pcg |
1.54 |
|
733 |
|
|
sound::play 3, "resign"; |
734 |
pcg |
1.73 |
$self->{chat}->append_text ("\n<infoblock><header>Resign</header>" |
735 |
pcg |
1.39 |
. "\n<user>" |
736 |
pcg |
1.38 |
. (util::toxml $self->{user}[$msg->{player}]->as_string) |
737 |
|
|
. "</user> resigned.</infoblock>"); |
738 |
|
|
} |
739 |
|
|
|
740 |
pcg |
1.100 |
sub event_out_of_time { |
741 |
|
|
my ($self, $player) = @_; |
742 |
|
|
|
743 |
|
|
sound::play 3, "timewin"; |
744 |
pcg |
1.104 |
$self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>" |
745 |
pcg |
1.100 |
. "\n<user>" |
746 |
|
|
. (util::toxml $self->{user}[$msg->{player}]->as_string) |
747 |
pcg |
1.104 |
. "</user> ran out of time and lost.</infoblock>"); |
748 |
pcg |
1.100 |
} |
749 |
|
|
|
750 |
pcg |
1.102 |
sub event_done { |
751 |
|
|
my ($self) = @_; |
752 |
|
|
|
753 |
|
|
if ($self->{done}[1 - $self->{colour}] && !$self->{done}[$self->{colour}]) { |
754 |
root |
1.108 |
sound::play 2, "info" unless $inlay->{count}; |
755 |
root |
1.107 |
$self->{chat}->append_text ("\n<infoblock><header>Press Done</header>" |
756 |
|
|
. "\nYour opponent pressed done. Now it's up to you."); |
757 |
pcg |
1.102 |
} |
758 |
root |
1.107 |
if ($self->{doneid} & 0x80000000) { |
759 |
root |
1.108 |
sound::play 2, "info" unless $inlay->{count}; |
760 |
root |
1.107 |
$self->{chat}->append_text ("\n<infoblock><header>Press Done Again</header>" |
761 |
root |
1.108 |
. "\nThe board has changed."); |
762 |
root |
1.107 |
} |
763 |
|
|
|
764 |
|
|
$self->{button_pass}->sensitive (!$self->{done}[$self->{colour}]); |
765 |
|
|
|
766 |
|
|
$self->{chat}->set_end; |
767 |
pcg |
1.102 |
} |
768 |
|
|
|
769 |
pcg |
1.38 |
sub inject_final_result { |
770 |
|
|
my ($self, $msg) = @_; |
771 |
|
|
|
772 |
pcg |
1.73 |
$self->{chat}->append_text ("<infoblock>\n<header>Game Over</header>" |
773 |
pcg |
1.38 |
. "\nWhite Score " . (util::toxml $msg->{whitescore}->as_string) |
774 |
|
|
. "\nBlack Score " . (util::toxml $msg->{blackscore}->as_string) |
775 |
pcg |
1.42 |
. "</infoblock>" |
776 |
pcg |
1.38 |
); |
777 |
pcg |
1.37 |
} |
778 |
|
|
|
779 |
pcg |
1.98 |
sub inject_req_undo { |
780 |
|
|
my ($self, $msg) = @_; |
781 |
|
|
|
782 |
|
|
my $inlay = $self->{undo_inlay} ||= $self->{chat}->new_inlay; |
783 |
|
|
return if $inlay->{ignore}; |
784 |
|
|
|
785 |
root |
1.107 |
sound::play 2, "warning" unless $inlay->{count}; |
786 |
pcg |
1.98 |
$inlay->{count}++; |
787 |
pcg |
1.101 |
|
788 |
pcg |
1.98 |
$inlay->clear; |
789 |
|
|
$inlay->append_text ("\n<undo>Undo requested ($inlay->{count} times)</undo>\n"); |
790 |
|
|
$inlay->append_button ("Grant", sub { |
791 |
root |
1.106 |
(delete $self->{undo_inlay})->clear; |
792 |
pcg |
1.98 |
$self->send (grant_undo => channel => $self->{channel}); |
793 |
|
|
}); |
794 |
|
|
$inlay->append_button ("Ignore", sub { |
795 |
|
|
$inlay->clear; |
796 |
|
|
$inlay->{ignore} = 1; |
797 |
|
|
# but leave inlay, so further undo requests get counted |
798 |
|
|
}); |
799 |
|
|
|
800 |
pcg |
1.101 |
$self->{chat}->set_end; |
801 |
pcg |
1.98 |
} |
802 |
|
|
|
803 |
pcg |
1.97 |
sub inject_new_game { |
804 |
|
|
my ($self, $msg) = @_; |
805 |
|
|
|
806 |
root |
1.107 |
if ($msg->{cid} != $self->{cid}) { |
807 |
|
|
$self->part; |
808 |
|
|
warn "ERROR: challenge id mismatch, PLEASE REPORT, especially the circumstances (many games open? etc..)\n";#d# |
809 |
|
|
} |
810 |
|
|
|
811 |
|
|
$self->{chat}->append_text ("\n<header>Game successfully created on server.</header>"); |
812 |
pcg |
1.97 |
delete $self->{cid}; |
813 |
|
|
} |
814 |
|
|
|
815 |
root |
1.111 |
### CHALLENGE HANDLING ###################################################### |
816 |
|
|
|
817 |
pcg |
1.86 |
sub draw_challenge { |
818 |
pcg |
1.97 |
my ($self, $id) = @_; |
819 |
pcg |
1.86 |
|
820 |
pcg |
1.98 |
my $info = $self->{challenge}{$id}; |
821 |
|
|
my $inlay = $info->{inlay}; |
822 |
|
|
my $rules = $info->{rules}; |
823 |
pcg |
1.97 |
|
824 |
pcg |
1.98 |
my $as_black = $info->{black}{name} eq $self->{conn}{name} ? 1 : 0;; |
825 |
|
|
my $opponent = $as_black ? $info->{white} : $info->{black}; |
826 |
pcg |
1.86 |
|
827 |
root |
1.106 |
my ($size, $time, $interval, $count, $type); |
828 |
pcg |
1.97 |
|
829 |
|
|
if (!$self->{channel}) { |
830 |
|
|
$inlay->append_text ("\nNotes: "); |
831 |
pcg |
1.98 |
$inlay->append_entry (\$info->{notes}, 20, ""); |
832 |
pcg |
1.97 |
$inlay->append_text ("\nGlobal Offer: "); |
833 |
pcg |
1.98 |
$inlay->append_optionmenu (\$info->{flags}, |
834 |
pcg |
1.97 |
0 => "No", |
835 |
|
|
2 => "Yes", |
836 |
|
|
); |
837 |
|
|
} else { |
838 |
pcg |
1.98 |
$inlay->append_text ("\nNotes: " . util::toxml $info->{notes}); |
839 |
pcg |
1.97 |
} |
840 |
|
|
|
841 |
|
|
$inlay->append_text ("\nType: "); |
842 |
root |
1.106 |
$type = $inlay->append_optionmenu ( |
843 |
pcg |
1.98 |
\$info->{gametype}, |
844 |
root |
1.106 |
GAMETYPE_DEMONSTRATION , "Demonstration (not yet)", |
845 |
|
|
GAMETYPE_DEMONSTRATION | GAMETYPE_PRIVATE, "Demonstration (P) (not yet)", |
846 |
|
|
GAMETYPE_TEACHING , "Teaching (not yet)", |
847 |
|
|
GAMETYPE_TEACHING | GAMETYPE_PRIVATE, "Teaching (P) (not yet)", |
848 |
pcg |
1.97 |
GAMETYPE_SIMUL , "Simul (not yet!)", |
849 |
|
|
GAMETYPE_FREE , "Free", |
850 |
|
|
GAMETYPE_RATED , "Rated", |
851 |
|
|
sub { |
852 |
|
|
$size->set_history (2) if $_[0] eq GAMETYPE_RATED; |
853 |
|
|
}, |
854 |
|
|
); |
855 |
|
|
|
856 |
|
|
if ($self->{channel}) { |
857 |
|
|
$inlay->append_text ("\nMy Colour: "); |
858 |
|
|
$inlay->append_optionmenu ( |
859 |
|
|
\$as_black, |
860 |
|
|
0 => "White", |
861 |
|
|
1 => "Black", |
862 |
|
|
sub { |
863 |
pcg |
1.98 |
if ($info->{$_[0] ? "black" : "white"}{name} ne $self->{conn}{name}) { |
864 |
|
|
($info->{black}, $info->{white}) = ($info->{white}, $info->{black}); |
865 |
pcg |
1.97 |
} |
866 |
|
|
} |
867 |
|
|
); |
868 |
|
|
} |
869 |
pcg |
1.86 |
|
870 |
pcg |
1.97 |
$inlay->append_text ("\nRuleset: "); |
871 |
|
|
$inlay->append_optionmenu ( |
872 |
pcg |
1.98 |
\$info->{rules}{ruleset}, |
873 |
pcg |
1.97 |
RULESET_JAPANESE , "Japanese", |
874 |
|
|
RULESET_CHINESE , "Chinese", |
875 |
|
|
RULESET_AGA , "AGA", |
876 |
|
|
RULESET_NEW_ZEALAND, "New Zealand", |
877 |
|
|
); |
878 |
|
|
|
879 |
|
|
$inlay->append_text ("\nSize: "); |
880 |
|
|
$size = $inlay->append_optionmenu ( |
881 |
root |
1.106 |
\$info->{rules}{size}, |
882 |
|
|
(9 => 9, 13 => 13, 19 => 19, map +($_, $_), 2..38), |
883 |
|
|
sub { |
884 |
|
|
$type->set_history (5) # reset to free |
885 |
|
|
if $_[0] != 19 && $info->{gametype} == GAMETYPE_RATED; |
886 |
|
|
}, |
887 |
pcg |
1.97 |
); |
888 |
|
|
|
889 |
|
|
if ($self->{channel}) { |
890 |
|
|
$inlay->append_text ("\nHandicap: "); |
891 |
pcg |
1.98 |
$inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); |
892 |
pcg |
1.97 |
|
893 |
|
|
$inlay->append_text ("\nKomi: "); |
894 |
pcg |
1.98 |
$inlay->append_entry (\$info->{rules}{komi}, 5); |
895 |
pcg |
1.97 |
} |
896 |
|
|
|
897 |
|
|
$inlay->append_text ("\nTimesys: "); |
898 |
|
|
$inlay->append_optionmenu ( |
899 |
pcg |
1.98 |
\$info->{rules}{timesys}, |
900 |
pcg |
1.97 |
&TIMESYS_NONE => "None", |
901 |
|
|
&TIMESYS_ABSOLUTE => "Absolute", |
902 |
|
|
&TIMESYS_BYO_YOMI => "Byo Yomi", |
903 |
|
|
&TIMESYS_CANADIAN => "Canadian", |
904 |
|
|
sub { |
905 |
|
|
my ($new) = @_; |
906 |
|
|
|
907 |
|
|
if ($new eq TIMESYS_NONE) { |
908 |
|
|
$time->hide; |
909 |
|
|
$interval->hide; |
910 |
|
|
$count->hide; |
911 |
|
|
} else { |
912 |
|
|
$time->show; |
913 |
|
|
$time->set_text ($self->{app}{defaults}{time}); |
914 |
|
|
if ($new eq TIMESYS_ABSOLUTE) { |
915 |
|
|
$interval->hide; |
916 |
|
|
$count->hide; |
917 |
|
|
} else { |
918 |
|
|
$interval->show; |
919 |
|
|
$count->show; |
920 |
|
|
if ($new eq TIMESYS_BYO_YOMI) { |
921 |
|
|
$interval->set_text ($self->{app}{defaults}{byo_time}); |
922 |
|
|
$count->set_text ($self->{app}{defaults}{byo_period}); |
923 |
|
|
} elsif ($new eq TIMESYS_CANADIAN) { |
924 |
|
|
$interval->set_text ($self->{app}{defaults}{can_time}); |
925 |
|
|
$count->set_text ($self->{app}{defaults}{can_period}); |
926 |
|
|
} |
927 |
|
|
} |
928 |
|
|
} |
929 |
|
|
} |
930 |
|
|
); |
931 |
|
|
|
932 |
|
|
$inlay->append_text ("\nMain Time: "); |
933 |
pcg |
1.98 |
$time = $inlay->append_entry (\$info->{rules}{time}, 5); |
934 |
pcg |
1.97 |
$inlay->append_text ("\nInterval: "); |
935 |
pcg |
1.98 |
$interval = $inlay->append_entry (\$info->{rules}{interval}, 3); |
936 |
pcg |
1.97 |
$inlay->append_text ("\nPeriods/Stones: "); |
937 |
pcg |
1.98 |
$count = $inlay->append_entry (\$info->{rules}{count}, 2); |
938 |
pcg |
1.97 |
|
939 |
|
|
$inlay->append_text ("\n"); |
940 |
|
|
|
941 |
|
|
if (!$self->{channel}) { |
942 |
|
|
$inlay->append_button ("Create Challenge", sub { |
943 |
|
|
$inlay->clear; |
944 |
|
|
$self->{cid} = $self->{conn}->alloc_clientid; |
945 |
|
|
$self->send (new_game => |
946 |
pcg |
1.98 |
channel => delete $self->{roomid}, |
947 |
|
|
gametype => $info->{gametype}, |
948 |
|
|
cid => $self->{cid}, |
949 |
|
|
flags => $info->{flags}, |
950 |
|
|
rules => $info->{rules}, |
951 |
|
|
notes => $info->{notes}, |
952 |
pcg |
1.97 |
); |
953 |
|
|
}); |
954 |
|
|
} else { |
955 |
|
|
$inlay->append_button ("OK", sub { |
956 |
|
|
$inlay->clear; |
957 |
|
|
$self->send (challenge => |
958 |
pcg |
1.98 |
channel => $self->{channel}, |
959 |
|
|
black => $info->{black}, |
960 |
|
|
white => $info->{white}, |
961 |
|
|
gametype => $info->{gametype}, |
962 |
|
|
cid => $info->{cid}, |
963 |
|
|
rules => $info->{rules}, |
964 |
pcg |
1.97 |
); |
965 |
|
|
}); |
966 |
|
|
if (exists $self->{challenge}{""}) { |
967 |
|
|
$inlay->append_button ("Reject", sub { |
968 |
|
|
$inlay->clear; |
969 |
|
|
$self->send (reject_challenge => |
970 |
pcg |
1.98 |
channel => $self->{channel}, |
971 |
|
|
name => $opponent->{name}, |
972 |
|
|
gametype => $info->{gametype}, |
973 |
|
|
cid => $info->{cid}, |
974 |
|
|
rules => $info->{rules}, |
975 |
pcg |
1.97 |
); |
976 |
|
|
}); |
977 |
|
|
} |
978 |
|
|
} |
979 |
pcg |
1.86 |
} |
980 |
|
|
|
981 |
root |
1.111 |
sub new_game_challenge { |
982 |
|
|
my ($self) = @_; |
983 |
|
|
|
984 |
|
|
my $d = $self->{app}{defaults}; |
985 |
|
|
|
986 |
|
|
$self->{challenge}{""} = { |
987 |
|
|
gametype => $d->{gametype}, |
988 |
|
|
flags => 0, |
989 |
|
|
notes => $d->{stones}, |
990 |
|
|
rules => { |
991 |
|
|
ruleset => $d->{ruleset}, |
992 |
|
|
size => $d->{size}, |
993 |
|
|
timesys => $d->{timesys}, |
994 |
|
|
time => $d->{time}, |
995 |
|
|
interval => $d->{timesys} == TIMESYS_BYO_YOMI ? $d->{byo_time} : $d->{can_time}, |
996 |
|
|
count => $d->{timesys} == TIMESYS_BYO_YOMI ? $d->{byo_periods} : $d->{can_stones}, |
997 |
|
|
}, |
998 |
pcg |
1.88 |
|
999 |
root |
1.111 |
inlay => $self->{chat}->new_inlay, |
1000 |
|
|
}; |
1001 |
|
|
$self->draw_challenge (""); |
1002 |
pcg |
1.88 |
} |
1003 |
|
|
|
1004 |
pcg |
1.68 |
sub event_challenge { |
1005 |
pcg |
1.98 |
my ($self, $info) = @_; |
1006 |
pcg |
1.68 |
|
1007 |
pcg |
1.98 |
my $as_black = $info->{black}->{name} eq $self->{conn}{name}; |
1008 |
|
|
my $opponent = $as_black ? $info->{white} : $info->{black}; |
1009 |
pcg |
1.86 |
|
1010 |
pcg |
1.97 |
my $id = $opponent->{name}; |
1011 |
root |
1.108 |
|
1012 |
|
|
sound::play 2, "info"; |
1013 |
pcg |
1.86 |
|
1014 |
pcg |
1.98 |
$self->{challenge}{$id} = $info; |
1015 |
|
|
$self->{challenge}{$id}{inlay} = $self->{chat}->new_switchable_inlay ( |
1016 |
|
|
exists $self->{challenge}{""} |
1017 |
root |
1.110 |
? "Challenge from " . $opponent->as_string |
1018 |
|
|
: "Challenge to " . $opponent->as_string, |
1019 |
pcg |
1.97 |
sub { |
1020 |
|
|
$self->{challenge}{$id}{inlay} = $_[0]; |
1021 |
|
|
$self->draw_challenge ($id); |
1022 |
|
|
}, |
1023 |
pcg |
1.101 |
!exists $self->{challenge}{""} # only open when not offerer |
1024 |
pcg |
1.97 |
); |
1025 |
pcg |
1.68 |
} |
1026 |
|
|
|
1027 |
pcg |
1.1 |
1; |
1028 |
|
|
|