ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/game.pl
Revision: 1.29
Committed: Sun Jun 1 16:51:38 2003 UTC (20 years, 11 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.28: +10 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package game::goclock;
2
3 use Time::HiRes ();
4
5 use KGS::Constants;
6
7 use base gtk::widget;
8
9 sub new {
10 my $class = shift;
11 my $self = $class->SUPER::new(@_);
12
13 $self->{widget} = new Gtk2::Label;
14
15 $self->{set} = sub { };
16 $self->{format} = sub { "ERROR" };
17
18 $self;
19 }
20
21 sub append_text {
22 my ($self, $text) = @_;
23
24 $self->{buffer}->insert ($self->{buffer}->get_end_iter, $text);
25 }
26
27 sub format_time {
28 my ($time) = @_;
29
30 $time > 60*60
31 ? sprintf "%d:%02d:%02d", $time / (60 * 60), $time / 60 % 60, $time % 60
32 : sprintf "%d:%02d", $time / 60 % 60, $time % 60;
33 }
34
35 sub set_rules {
36 my ($self, $timesys, $main, $interval, $count) = @_;
37
38 if ($timesys == TIMESYS_ABSOLUTE) {
39 $self->{set} = sub { $self->{time} = $_[0] };
40 $self->{format} = sub { format_time $_[0] };
41
42 } elsif ($timesys == TIMESYS_BYO_YOMI) {
43 my $low = $interval * $count;
44
45 $self->{set} = sub { $self->{time} = $_[0] };
46
47 $self->{format} = sub {
48 if ($_[0] > $low) {
49 format_time $_[0] - $low;
50 } else {
51 sprintf "%s (%d)", (format_time int ($_[0] % $interval) || $interval), $_[0] / $interval;
52 }
53 };
54
55 } elsif ($timesys == TIMESYS_CANADIAN) {
56 my $low = $interval;
57
58 $self->{set} = sub { $self->{time} = $_[0]; $self->{moves} = $_[1] };
59
60 $self->{format} = sub {
61 if ($_[0] > $low) {
62 format_time $_[0] - $low;
63 } else {
64 sprintf "%s / %d", (format_time int($_[0] % $interval) || $interval), $self->{moves};
65 }
66 };
67
68 } else {
69 # none, or unknown
70 $self->{set} = sub { };
71 $self->{format} = sub { "---" }
72 }
73 }
74
75 sub refresh {
76 my ($self, $timestamp) = @_;
77 my $timer = $self->{time} + $self->{start} - $timestamp;
78 $self->{widget}->set_text ($self->{format}->($timer));
79
80 $timer - int $timer;
81 }
82
83 sub set_time {
84 my ($self, $time) = @_;
85
86 # we ignore requests to re-set the time of a running clock.
87 # this is the easiest way to ensure that commentary etc.
88 # doesn't re-set the clock. yes, this is frickle design,
89 # but I think the protoocl is to blame here, which gives
90 # very little time information. (cgoban2 also has had quite
91 # a lot of small time update problems...)
92 unless ($self->{timeout}) {
93 $self->{set}->($time->[0], $time->[1]);
94 $self->refresh ($self->{start});
95 }
96 }
97
98 sub start {
99 my ($self) = @_;
100
101 return if $self->{timeout};
102
103 # this is correct, since we assume the last message triggered a start
104 $self->{start} = $KGS::Protocol::NOW;
105
106 my $timeout; $timeout = sub {
107 # -100 means we run the timer a bit earlier to avoid 10.99 => 10s roundings.
108 # we "could" cheat by precalculating the time, but I feel uneasy about both
109 # ways to cheat.
110 my $next = int ($self->refresh (Time::HiRes::time) * 1000) - 100;
111 $next += 1000 if $next < 0;
112 $self->{timeout} = add Glib::Timeout $next, $timeout;
113 0;
114 };
115
116 $timeout->();
117 }
118
119 sub stop {
120 my ($self) = @_;
121
122 remove Glib::Source delete $self->{timeout} if $self->{timeout};
123 }
124
125 sub destroy {
126 my ($self) = @_;
127 $self->stop;
128 $self->SUPER::destroy;
129 }
130
131 package game::userpanel;
132
133 use base gtk::widget;
134
135 sub new {
136 my $class = shift;
137 my $self = $class->SUPER::new(@_);
138
139 $self->{widget} = new Gtk2::HBox;
140
141 $self->{widget}->add (my $vbox = new Gtk2::VBox);
142
143 $vbox->add ($self->{name} = new Gtk2::Label $self->{name});
144 $vbox->add ($self->{info} = new Gtk2::Label "");
145 $vbox->add (($self->{clock} = new game::goclock)->widget);
146
147 $self;
148 }
149
150 sub set_rules {
151 my ($self, $rules) = @_;
152
153 if ($self->{name}->get_text ne $rules->{player}[$self->{colour}]) {
154 $self->{name}->set_text ($rules->{player}[$self->{colour}]);
155
156 # the big picture...
157 appwin::userpic ($rules->{player}[$self->{colour}], sub {
158 $self->{widget}->add (gtk::image_from_data $_[0]) if $_[0];
159 $self->{widget}->show_all;
160 # undef => show sth. funny
161 });
162 }
163
164 $self->{clock}->set_rules (@{$rules->{rules}}{qw(timesys time interval count)});
165 }
166
167 sub set_state {
168 my ($self, $captures, $timer, $running) = @_;
169
170 $self->{clock}->stop unless $running;
171 $self->{clock}->set_time ($timer);
172 $self->{clock}->start if $running;
173
174 $self->{info}->set_text ("$captures pris.");
175 }
176
177 package game;
178
179 use KGS::Constants;
180 use KGS::Game::Board;
181
182 use base KGS::Listener::Game;
183 use base KGS::Game;
184
185 use base gtk::widget;
186
187 use POSIX qw(ceil);
188
189 sub new {
190 my $self = shift;
191 $self = $self->SUPER::new(@_);
192
193 $self->listen($self->{conn});
194
195 $self->{window} = new Gtk2::Window 'toplevel';
196 my $title = $self->{channel} ? $self->owner->as_string." ".$self->opponent_string : "Game Window";
197 $self->{window}->set_title("KGS Game $title");
198 gtk::state $self->{window}, "game::window", undef, window_size => [600, 500];
199
200 $self->{window}->signal_connect(delete_event => sub {
201 $self->part;
202 $self->destroy;
203 1;
204 });
205
206 $self->{window}->add($self->{hpane} = new Gtk2::HPaned);
207 gtk::state $self->{hpane}, "game::hpane", undef, position => 500;
208
209 $self->{hpane}->pack1((my $vbox = new Gtk2::VBox), 1, 1);
210
211 $vbox->pack_start((my $frame = new Gtk2::Frame), 0, 1, 0);
212
213 {
214 # grrr...
215 $frame->add(my $vbox = new Gtk2::VBox);
216 $vbox->add($self->{title} = new Gtk2::Label $title);
217
218 $self->{moveadj} = new Gtk2::Adjustment 1, 0, 1, 0.001, 0.05, 0;
219
220 $vbox->add(my $scale = new Gtk2::HScale $self->{moveadj});
221 $scale->set_draw_value (0);
222
223 $self->{moveadj}->signal_connect (value_changed => sub { $self->update_board });
224 }
225
226 $vbox->pack_start((my $aspect_frame = new Gtk2::AspectFrame "", 0.5, 0.5, 1, 0), 1, 1, 0);
227 $aspect_frame->set (border_width => 0, shadow_type => 'none', label_xalign => 0.5);
228 $self->{board_label} = $aspect_frame->get_label_widget;
229
230 $aspect_frame->add($self->{canvas} = new Gtk2::DrawingArea);
231 $self->{canvas}->double_buffered (0) if $::config->{conserve_memory};
232
233 $self->{canvas}->signal_connect(configure_event => \&configure_event, $self);
234 $self->{canvas}->signal_connect(expose_event => \&expose_event, $self);
235
236 # RIGHT PANE
237
238 $self->{hpane}->pack2(($self->{vpane} = new Gtk2::VPaned), 0, 0);
239 $self->{hpane}->set(position_set => 1);
240 gtk::state $self->{vpane}, "game::vpane", $self->{name}, position => 80;
241
242 $self->{vpane}->add(my $sw = new Gtk2::ScrolledWindow);
243 $sw->set_policy("automatic", "always");
244
245 $sw->add(($self->{userlist} = new userlist)->widget);
246
247 $self->{vpane}->add(my $vbox = new Gtk2::VBox);
248
249 $vbox->pack_start((my $hbox = new Gtk2::HBox 1), 0, 1, 0);
250 $hbox->add (($self->{userpanel}[WHITE] = new game::userpanel colour => WHITE)->widget);
251 $hbox->add (($self->{userpanel}[BLACK] = new game::userpanel colour => BLACK)->widget);
252
253 $vbox->pack_start((my $sw = new Gtk2::ScrolledWindow), 1, 1, 0);
254 $sw->set_policy("never", "always");
255
256 $sw->add(($self->{text} = new gtk::text)->widget);
257
258 $vbox->pack_start(($self->{entry} = new Gtk2::Entry), 0, 1, 0);
259 $self->{entry}->signal_connect(activate => sub {
260 my $text = $self->{entry}->get_text;
261 $self->say($text) if $text =~ /\S/;
262 $self->{entry}->set_text("");
263 });
264
265 $self;
266 }
267
268 sub event_update_users {
269 my ($self, $add, $update, $remove) = @_;
270
271 $self->{userlist}->update ($add, $update, $remove);
272 }
273
274 sub join {
275 my ($self) = @_;
276 return if $self->{joined};
277
278 $self->SUPER::join;
279
280 $self->{window}->show_all;
281 }
282
283 sub part {
284 my ($self) = @_;
285
286 $self->SUPER::part;
287 $self->destroy;
288 }
289
290 sub configure_event {
291 my ($widget, $event, $self) = @_;
292 delete $self->{stack};
293 delete $self->{pixbuf};
294 delete $self->{board_shown};
295 delete $self->{background};
296 $self->repaint_board;
297 0;
298 }
299
300 sub expose_event {
301 my ($widget, $event, $self) = @_;
302
303 $self->{pixbuf} or return;
304
305 my $area = $event->area;
306
307 $self->redraw ($area);
308
309 0;
310 }
311
312 # something Gtk2 fixed
313 sub INTERP_NEAREST (){ 'nearest' }
314 sub INTERP_TILES (){ 'tiles' }
315 sub INTERP_BILINEAR (){ 'bilinear' }
316 sub INTERP_HYPER (){ 'hyper' }
317
318 sub new_pixbuf {
319 my ($w, $h, $alpha, $fill) = @_;
320
321 my $pixbuf = new Gtk2::Gdk::Pixbuf 'rgb', $alpha, 8, $w, $h;
322 $pixbuf->fill ($fill) if defined $fill;
323
324 $pixbuf;
325 }
326
327 sub scale_pixbuf {
328 my ($src, $w, $h, $mode) = @_;
329
330 my $dst = new_pixbuf $w, $h, 1;
331
332 $src->scale(
333 $dst, 0, 0, $w, $h, 0, 0,
334 $w / $src->get_width, $h / $src->get_height,
335 $mode,
336 );
337
338 $dst;
339 }
340
341 # create a stack of stones
342 sub create_stack {
343 my ($self, $mark, $size, $rand) = @_;
344
345 my $shadow = $size * 0.05;
346
347 my $c = \$self->{stack}{$mark};
348 unless ($$c) {
349 for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) {
350 my $base = new_pixbuf $size + $shadow, $size + $shadow, 1, 0x00000000;
351
352 # zeroeth the shadow
353 if ($mark & (MARK_B | MARK_W)) {
354 # the -0.5's are a mystery to me
355 $::shadow_img->composite (
356 $base, $shadow, $shadow, $size, $size, $shadow - 0.5, $shadow - 0.5,
357 $size / $::shadow_img->get_width, $size / $::shadow_img->get_height,
358 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192
359 );
360 }
361
362 # first the big stones (handicap stones different for effect)
363 for ([MARK_B, $mark & MARK_MOVE ? 255 : 192],
364 [MARK_W, $mark & MARK_MOVE ? 255 : 192],
365 [MARK_GRAY_B, 128],
366 [MARK_GRAY_W, 128]) {
367 my ($mask, $alpha) = @$_;
368 if ($mark & $mask) {
369 $stone->composite (
370 $base, 0, 0, $size, $size, 0, 0,
371 $size / $stone->get_width, $size / $stone->get_height,
372 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, $alpha
373 );
374 }
375 }
376
377 # then the small stones
378 for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]],
379 [MARK_SMALL_W, $::white_img[$rand % @::white_img]]) {
380 my ($mask, $img) = @$_;
381 if ($mark & $mask) {
382 $img->composite (
383 $base, (int ($size / 4)) x2, (ceil ($size / 2 + 1)) x2, ($size / 4) x2,
384 $size / $img->get_width / 2, $size / $img->get_height / 2,
385 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 224
386 );
387 }
388 }
389
390 # and lastly any markers
391 my $dark_bg = ! ! ($mark & (MARK_B | MARK_GRAY_B));
392
393 for ([MARK_CIRCLE, $::circle_img[$dark_bg]],
394 [MARK_TRIANGLE, $::triangle_img[$dark_bg]],
395 [MARK_SQUARE, $::square_img[$dark_bg]]) {
396 my ($mask, $img) = @$_;
397 if ($mark & $mask) {
398 $img->composite (
399 $base, 0, 0, $size, $size, 0, 0,
400 $size / $img->get_width, $size / $img->get_height,
401 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192
402 );
403 }
404 }
405
406 push @$$c, $base;
407 }
408 }
409
410 $$c->[$rand % @$$c];
411 }
412
413 sub pixbuf_text {
414 my ($pixbuf, $colour, $x, $y, $height, $text) = @_;
415
416 my @c = grep $_,
417 map $::font[$colour][$::fontmap{$_}],
418 split //, $text;
419
420 if (@c) {
421 my $spacing = $height * 0.1;
422 my $s = $height / List::Util::max map $_->get_height, @c;
423 my $W = List::Util::sum map $_->get_width, @c;
424
425 $x -= ($W * $s + $spacing * (@c - 1)) * 0.5;
426 $y -= $height * 0.5;
427
428 for (@c) {
429 my $w = $_->get_width * $s;
430 # +2 == don't fight the rounding
431 $_->composite ($pixbuf,
432 $x, $y, $w+2, $height+2, $x, $y, $s, $s,
433 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255);
434
435 $x += $w + $spacing;
436 }
437 }
438 }
439
440 sub pixbuf_rect {
441 my ($pb, $colour, $x1, $y1, $x2, $y2, $alpha) = @_;
442 # we fake lines by... a horrible method :/
443 my $colour_pb = new_pixbuf 1, 1, 0, $colour;
444 $colour_pb->composite ($pb, $x1, $y1, $x2 - $x1 + 1, $y2 - $y1 + 1, $x1, $y1, $x2 + 1, $y2 + 1,
445 INTERP_NEAREST, $alpha);
446 }
447
448 sub repaint_board {
449 my ($self) = @_;
450 my $canvas = $self->{canvas};
451 my $expose_area = undef;
452
453 return $expose_area unless $self->{board};
454
455 my ($w, $h) = ($canvas->allocation->values)[2,3];
456
457 die "FATAL: board aspect ratio != 1" unless $w == $h;
458
459 my $s = $w;
460
461 return unless $s >= 200;
462
463 my $size = $self->{size};
464
465 # we leave enough space for the shadows.. I like smaller stones, and we
466 # do no need to do the nifty recursive screen updates that goban2 does
467 my $border = int ($s / ($size + 3) * 0.5);
468 my $s2 = $s - $border * 2;
469 my $edge = int ($s2 / ($size + 1) * 0.96) - ($::config->{randomize} ? 3 : 0);
470 my $ofs = int ($edge / 2);
471
472 my @k = map int ($s2 * $_ / ($size+1) + $border + 0.5), 0 .. $size;
473
474 my $pixbuf;
475
476 my $oldboard;
477
478 if ($self->{background}) {
479 if ($oldboard = $self->{board_shown}) {
480 $pixbuf = $self->{pixbuf};
481 } else {
482 $pixbuf = $self->{background}->copy;
483 $expose_area = new Gtk2::Gdk::Rectangle 0, 0, $s, $s;
484 }
485 } else {
486 $expose_area = new Gtk2::Gdk::Rectangle 0, 0, $s, $s;
487
488 my ($bw, $bh) = ($::board_img->get_width, $::board_img->get_height);
489
490 if ($s < $bw && $s < $bh) {
491 $pixbuf = new_pixbuf $s, $s, 0;
492 $::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0);
493 } else {
494 $pixbuf = scale_pixbuf $::board_img, $s, $s, $::config->{speed} ? INTERP_NEAREST : INTERP_TILES;
495 }
496
497 my $linew = int ($s / 40 / $size);
498
499 # ornamental border... we have time to waste :/
500 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $s-1, $linew, 255;
501 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $s-1, 255;
502 pixbuf_rect $pixbuf, 0xffcc7700, $s-$linew-1, 0, $s-1, $s-1, 255;
503 pixbuf_rect $pixbuf, 0xffcc7700, 0, $s-$linew-1, $s-1, $s-1, 255;
504
505 for my $i (1 .. $size) {
506 pixbuf_rect $pixbuf, 0x44111100, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew, 192;
507 pixbuf_rect $pixbuf, 0x44111100, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew, 192;
508
509 # 38 max, but we allow a bit more
510 my $label = (qw(- A B C D E F G H J K L M N O P Q R S T U V W X Y Z
511 AA BB CC DD EE FF GG HH JJ KK LL MM NN OO PP QQ RR SS TT UU VV WW XX YY ZZ))[$i];
512
513 pixbuf_text $pixbuf, 0, $k[$i], $border, $ofs, $label;
514 pixbuf_text $pixbuf, 0, $k[$i], $s2 + $border, $ofs, $label;
515 pixbuf_text $pixbuf, 0, $border, $k[$i], $ofs, $size - $i + 1;
516 pixbuf_text $pixbuf, 0, $s2 + $border, $k[$i], $ofs, $size - $i + 1;
517
518 $a++;
519 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK...
520 }
521
522 # hoshi points
523 my $hoshi = sub {
524 my ($x, $y) = @_;
525 my $hs = int ($edge / 4) | 1;
526 $x = $k[$x] - $hs / 2; $y = $k[$y] - $hs / 2;
527
528 # we use the shadow mask... not perfect, but I want to finish this
529 $::shadow_img->composite ($pixbuf,
530 $x, $y, $hs + 1, $hs + 1, $x, $y,
531 $hs / $::shadow_img->get_width, $hs / $::shadow_img->get_height,
532 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255);
533 };
534
535 my $h1 = $size < 10 ? 3 : 4; # corner / edge offset
536 $hoshi->($h1, $h1);
537 $hoshi->($size - $h1 + 1, $h1);
538 $hoshi->($h1, $size - $h1 + 1);
539 $hoshi->($size - $h1 + 1, $size - $h1 + 1);
540
541 if ($size % 2) { # on odd boards, also the remaining 5
542 my $h2 = ($size + 1) / 2;
543 if ($size > 10) {
544 $hoshi->($h1, $h2);
545 $hoshi->($size - $h1 + 1, $h2);
546 $hoshi->($h2, $size - $h1 + 1);
547 $hoshi->($h2, $h1);
548 }
549 # the tengen
550 $hoshi->($h2, $h2);
551 }
552
553 unless ($::config->{conserve_memory} > 1) {
554 $self->{background} = $pixbuf;
555 $pixbuf = $pixbuf->copy;
556 }
557 }
558
559 $self->{pixbuf} = $pixbuf;
560
561 # hoshi-points(!)#d#
562 # caching of empty board gfx(!)#d#
563
564 for my $x (1 .. $size) {
565 for my $y (1 .. $size) {
566 my $rand = ($x ^ $y ^ 0x5555);
567
568 my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs);
569
570 if ($::config->{randomize}) {
571 $dx += ($rand % 7) - 3;
572 $dy += ($rand / 3 % 7) - 3;
573 }
574
575 my $shadow = $edge * 0.05;
576 my $area = [$dx, $dy, $edge + $shadow, $edge + $shadow];
577
578 my $mark = $self->{board}{board}[$x-1][$y-1];
579 my $old = $oldboard ? $oldboard->{board}[$x-1][$y-1] : 0;
580
581 if ($oldboard) {
582 next if $old == $mark; # no change
583
584 $self->{background}->copy_area (@$area, $pixbuf, $dx, $dy);
585 $expose_area = $expose_area
586 ? $expose_area->union (new Gtk2::Gdk::Rectangle @$area)
587 : new Gtk2::Gdk::Rectangle @$area;
588 }
589
590 if ($mark) {
591 my $pb = $self->create_stack($mark, $edge, $rand);
592
593 $pb->composite ($pixbuf, @$area,
594 $dx, $dy, 1, 1, $::config->{speed} ? INTERP_NEAREST : INTERP_NEAREST, 255);
595
596 # labels are handled here because they are quite rare
597 if ($mark & MARK_LABEL) {
598 my $white = $mark & (MARK_W | MARK_GRAY_W) ? 0 : 1;
599
600 if ($white) {
601 pixbuf_text $pixbuf, 0,
602 $k[$x] + $ofs * 0.1, $k[$y] + $ofs * 0.1, $ofs * 0.7,
603 $self->{board}{label}[$x-1][$y-1];
604 }
605 pixbuf_text $pixbuf, $white,
606 $k[$x], $k[$y], $ofs * 0.7,
607 $self->{board}{label}[$x-1][$y-1];
608 }
609 }
610 }
611 }
612
613 $self->{board_shown} = Storable::dclone $self->{board};
614 #d# save
615 #Storable::nstore { board => $self->{board}, size => $self->{size}, path => $self->{path}}, "testboard.storable";
616
617 $expose_area;
618 }
619
620 sub redraw {
621 my ($self, $area) = @_;
622
623 if ($area && $self->{pixbuf}) {
624 my ($x, $y, $w, $h) = $area->values;
625
626 $self->{canvas}->window->draw_pixbuf ($self->{canvas}->style->white_gc, $self->{pixbuf},
627 $x, $y, $x, $y, $w, $h,
628 "normal", 0, 0);
629 $self->{canvas}->window->draw_rectangle ($self->{canvas}->style->black_gc, 0,
630 $x - 1, $y - 1, $w + 2, $h + 2) if $::DEBUG_EXPOSE;
631 }
632 }
633
634 sub update_board {
635 my ($self) = @_;
636 return unless $self->{path};
637
638 my $move = int (@{$self->{path}} * $self->{moveadj}->get_value);
639
640 my $running = $move == @{$self->{path}};
641
642 $self->{board_label}->set_text ("Move $move");
643
644 $self->{board} = new KGS::Game::Board $self->{size};
645 $self->{board}->interpret_path ([@{$self->{path}}[0 .. $move - 1]]);
646
647 $self->{userpanel}[WHITE]->set_state ($self->{board}{captures}[WHITE],
648 $self->{board}{timer}[WHITE],
649 $running && $self->{board}{last} == BLACK);
650 $self->{userpanel}[BLACK]->set_state ($self->{board}{captures}[BLACK],
651 $self->{board}{timer}[BLACK],
652 $running && $self->{board}{last} == WHITE);
653
654 $self->redraw ($self->repaint_board);
655 }
656
657 sub event_update_tree {
658 my ($self) = @_;
659
660 $self->{path} = $self->get_path;
661 $self->{userpanel}[WHITE]->set_rules ($self->{path}[0]); # should be onload only
662 $self->{userpanel}[BLACK]->set_rules ($self->{path}[0]); # should be onload only
663
664 $self->{moveadj}->value_changed if $self->{moveadj};
665 }
666
667 sub event_update_comments {
668 my ($self, $node, $comment, $newnode) = @_;
669 $self->SUPER::event_update_comments($node, $comment, $newnode);
670
671 $self->{text}->append_text ("\nMove <move>$node->{move}</move>, <header>Node <node>$node->{id}</node></header>")
672 if $newnode;
673
674 $self->{text}->append_text ("\n" . util::toxml $comment);
675 }
676
677 sub event_part {
678 my ($self) = @_;
679 $self->SUPER::event_part;
680 }
681
682 sub event_move {
683 my ($self, $pass) = @_;
684 sound::play 1, $pass ? "pass" : "move";
685 }
686
687 sub event_update_game {
688 my ($self) = @_;
689 $self->SUPER::event_update_game;
690 warn "UPDATE GAME";#d#
691 }
692
693 sub destroy {
694 my ($self) = @_;
695 (delete $self->{userpanel}[WHITE])->destroy if $self->{userpanel}[WHITE];
696 (delete $self->{userpanel}[BLACK])->destroy if $self->{userpanel}[BLACK];
697 $self->SUPER::destroy;
698 delete $appwin::gamelist->{game}{$self->{channel}};
699 }
700
701 1;
702