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