ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/game.pl
(Generate patch)

Comparing kgsueme/kgsueme/game.pl (file contents):
Revision 1.61 by pcg, Wed Jun 18 01:07:27 2003 UTC vs.
Revision 1.78 by pcg, Mon Aug 4 02:14:44 2003 UTC

52 if (!$self->{moves}) { 52 if (!$self->{moves}) {
53 util::format_time $_[0] - $low; 53 util::format_time $_[0] - $low;
54 } else { 54 } else {
55 my $time = int (($_[0] - 1) % $interval + 1); 55 my $time = int (($_[0] - 1) % $interval + 1);
56 56
57 sprintf "%s/%d [%d]", 57 sprintf "%s/%d =%d",
58 util::format_time $time, 58 util::format_time $time,
59 $self->{moves}, 59 $self->{moves},
60 $self->{moves} > 1
60 $time / ($self->{moves} || 1); 61 ? $time / $self->{moves}
61 62 : $interval;
62 } 63 }
63 }; 64 };
64 65
65 } else { 66 } else {
66 # none, or unknown 67 # none, or unknown
145 146
146 $self; 147 $self;
147} 148}
148 149
149sub configure { 150sub configure {
150 my ($self, $user, $rules) = @_; 151 my ($self, $app, $user, $rules) = @_;
151 152
152 if ($self->{name}->get_text ne $user->as_string) { 153 if ($self->{name}->get_text ne $user->as_string) {
153 $self->{name}->set_text ($user->as_string); 154 $self->{name}->set_text ($user->as_string);
154 155
155 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 156 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
156 $self->{imagebox}->add (gtk::image_from_data undef); 157 $self->{imagebox}->add (gtk::image_from_data undef);
157 $self->{imagebox}->show_all; 158 $self->{imagebox}->show_all;
158 159
159 if ($user->has_pic) { 160 if ($user->has_pic) {
160 # the big picture... 161 # the big picture...
161 appwin::userpic ($user->{name}, sub { 162 $app->userpic ($user->{name}, sub {
162 return unless $self->{imagebox}; 163 return unless $self->{imagebox};
164
163 if ($_[0]) { 165 if ($_[0]) {
164 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 166 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
165 $self->{imagebox}->add (gtk::image_from_data $_[0]); 167 $self->{imagebox}->add (gtk::image_from_data $_[0]);
166 $self->{imagebox}->show_all; 168 $self->{imagebox}->show_all;
167 } 169 }
185package game; 187package game;
186 188
187use KGS::Constants; 189use KGS::Constants;
188use KGS::Game::Board; 190use KGS::Game::Board;
189 191
192use Gtk2::GoBoard;
193
190use base KGS::Listener::Game; 194use base KGS::Listener::Game;
191use base KGS::Game; 195use base KGS::Game;
192 196
193use base gtk::widget; 197use base gtk::widget;
194 198
227 # board box (aspect/canvas) 231 # board box (aspect/canvas)
228 232
229 $self->{boardbox}->pack_start((my $frame = new Gtk2::Frame), 0, 1, 0); 233 $self->{boardbox}->pack_start((my $frame = new Gtk2::Frame), 0, 1, 0);
230 234
231 { 235 {
232 $frame->add(my $vbox = new Gtk2::VBox); 236 $frame->add (my $vbox = new Gtk2::VBox);
233 $vbox->add($self->{title} = new Gtk2::Label $title); 237 $vbox->add ($self->{title} = new Gtk2::Label $title);
234 238
239 $vbox->add (my $hbox = new Gtk2::HBox);
240
241 $hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 1, 0);
242
235 $self->{moveadj} = new Gtk2::Adjustment 1, 1, 1, 1, 1, 0; 243 $self->{moveadj} = new Gtk2::Adjustment 1, 1, 1, 1, 5, 0;
236 244
237 $vbox->add(my $scale = new Gtk2::HScale $self->{moveadj}); 245 $hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0);
238 $scale->set_draw_value (0); 246 $scale->set_draw_value (0);
239 $scale->set_digits (0); 247 $scale->set_digits (0);
240 248
241 $self->{moveadj}->signal_connect (value_changed => sub { $self->update_board }); 249 $self->{moveadj}->signal_connect (value_changed => sub { $self->update_board });
242 } 250 }
243 251
244 $self->{boardbox}->pack_start((my $aspect_frame = new Gtk2::AspectFrame "", 0.5, 0.5, 1, 0), 1, 1, 0); 252 $self->{boardbox}->add ($self->{board} = new Gtk2::GoBoard size => $self->{size});
245 $aspect_frame->set (border_width => 0, shadow_type => 'none', label_xalign => 0.5);
246 $self->{board_label} = $aspect_frame->get_label_widget;
247
248 $aspect_frame->add($self->{canvas} = new Gtk2::DrawingArea);
249 $self->{canvas}->double_buffered (0);
250
251 $self->{canvas}->signal_connect(configure_event => \&configure_event, $self);
252 $self->{canvas}->signal_connect(expose_event => \&expose_event, $self);
253 253
254 # RIGHT PANE 254 # RIGHT PANE
255 255
256 $self->{hpane}->pack2(($self->{vpane} = new Gtk2::VPaned), 1, 1); 256 $self->{hpane}->pack2(($self->{vpane} = new Gtk2::VPaned), 1, 1);
257 $self->{hpane}->set(position_set => 1); 257 $self->{hpane}->set(position_set => 1);
263 $sw->add(($self->{userlist} = new userlist)->widget); 263 $sw->add(($self->{userlist} = new userlist)->widget);
264 264
265 $self->{vpane}->add(my $vbox = new Gtk2::VBox); 265 $self->{vpane}->add(my $vbox = new Gtk2::VBox);
266 266
267 $vbox->pack_start((my $hbox = new Gtk2::HBox 1), 0, 1, 0); 267 $vbox->pack_start((my $hbox = new Gtk2::HBox 1), 0, 1, 0);
268 $hbox->add (($self->{userpanel}[WHITE] = new game::userpanel colour => WHITE)->widget); 268 $hbox->add (($self->{userpanel}[COLOUR_WHITE] = new game::userpanel colour => COLOUR_WHITE)->widget);
269 $hbox->add (($self->{userpanel}[BLACK] = new game::userpanel colour => BLACK)->widget); 269 $hbox->add (($self->{userpanel}[COLOUR_BLACK] = new game::userpanel colour => COLOUR_BLACK)->widget);
270 270
271 $vbox->pack_start(($self->{text} = new gtk::text)->widget, 1, 1, 0); 271 $vbox->pack_start(($self->{chat} = new chat), 1, 1, 0);
272 272
273 $vbox->pack_start(($self->{entry} = new Gtk2::Entry), 0, 1, 0);
274 $self->{entry}->signal_connect(activate => sub { 273 $self->{chat}->signal_connect(command => sub {
275 my $text = $self->{entry}->get_text; 274 my ($chat, $cmd, $arg) = @_;
276 $self->say($text) if $text =~ /\S/; 275 if ($cmd eq "rsave") {
277 $self->{entry}->set_text(""); 276 Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d#
277 } else {
278 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self);
279 }
278 }); 280 });
279 281
280 $self->event_update_game; 282 $self->event_update_game;
281 $self; 283 $self;
282} 284}
283 285
284sub event_update_users { 286sub event_update_users {
285 my ($self, $add, $update, $remove) = @_; 287 my ($self, $add, $update, $remove) = @_;
288
289 return unless $self->{userlist};
286 290
287 $self->{userlist}->update ($add, $update, $remove); 291 $self->{userlist}->update ($add, $update, $remove);
288 292
289 my %important; 293 my %important;
290 $important{$self->{user1}{name}}++; 294 $important{$self->{user1}{name}}++;
291 $important{$self->{user2}{name}}++; 295 $important{$self->{user2}{name}}++;
292 $important{$self->{user3}{name}}++; 296 $important{$self->{user3}{name}}++;
293 297
294 if (my @users = grep $important{$_->{name}}, @$add) { 298 if (my @users = grep $important{$_->{name}}, @$add) {
295 $self->{text}->append_text ("\n<header>Joins:</header>"); 299 $self->{chat}->append_text ("\n<header>Joins:</header>");
296 $self->{text}->append_text (" <user>" . $_->as_string . "</user>") for @users; 300 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
297 } 301 }
298 if (my @users = grep $important{$_->{name}}, @$remove) { 302 if (my @users = grep $important{$_->{name}}, @$remove) {
299 $self->{text}->append_text ("\n<header>Parts:</header>"); 303 $self->{chat}->append_text ("\n<header>Parts:</header>");
300 $self->{text}->append_text (" <user>" . $_->as_string . "</user>") for @users; 304 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
301 } 305 }
302 306
303} 307}
304 308
305sub join { 309sub join {
316 320
317 $self->SUPER::part; 321 $self->SUPER::part;
318 $self->destroy; 322 $self->destroy;
319} 323}
320 324
321sub configure_event {
322 my ($widget, $event, $self) = @_;
323 delete $self->{stack};
324 delete $self->{pixbuf};
325 delete $self->{board_shown};
326 delete $self->{background};
327 $self->repaint_board;
328 0;
329}
330
331sub expose_event {
332 my ($widget, $event, $self) = @_;
333
334 $self->{pixbuf} or return;
335
336 $self->redraw ($event->area->values);
337
338 0;
339}
340
341# something Gtk2 fixed
342sub INTERP_NEAREST (){ 'nearest' }
343sub INTERP_TILES (){ 'tiles' }
344sub INTERP_BILINEAR (){ 'bilinear' }
345sub INTERP_HYPER (){ 'hyper' }
346
347sub new_pixbuf {
348 my ($w, $h, $alpha, $fill) = @_;
349
350 my $pixbuf = new Gtk2::Gdk::Pixbuf 'rgb', $alpha, 8, $w, $h;
351 $pixbuf->fill ($fill) if defined $fill;
352
353 $pixbuf;
354}
355
356sub scale_pixbuf {
357 my ($src, $w, $h, $mode) = @_;
358
359 my $dst = new_pixbuf $w, $h, 1;
360
361 $src->scale(
362 $dst, 0, 0, $w, $h, 0, 0,
363 $w / $src->get_width, $h / $src->get_height,
364 $mode,
365 );
366
367 $dst;
368}
369
370# create a stack of stones
371sub create_stack {
372 my ($self, $mark, $size, $rand) = @_;
373
374 my $shadow = $size * 0.05;
375
376 my $c = \$self->{stack}{$mark};
377 unless ($$c) {
378 for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) {
379 my $base = new_pixbuf $size + $shadow, $size + $shadow, 1, 0x00000000;
380
381 # zeroeth the shadow
382 if ($mark & (MARK_B | MARK_W)) {
383 # the -0.5's are a mystery to me
384 $::shadow_img->composite (
385 $base, $shadow, $shadow, $size, $size, $shadow - 0.5, $shadow - 0.5,
386 $size / $::shadow_img->get_width, $size / $::shadow_img->get_height,
387 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192
388 );
389 }
390
391 # first the big stones (handicap stones could be different)
392 for ([MARK_B, $mark & MARK_MOVE ? 255 : 255],
393 [MARK_W, $mark & MARK_MOVE ? 255 : 255],
394 [MARK_GRAY_B, 128],
395 [MARK_GRAY_W, 128]) {
396 my ($mask, $alpha) = @$_;
397 if ($mark & $mask) {
398 $stone->composite (
399 $base, 0, 0, $size, $size, 0, 0,
400 $size / $stone->get_width, $size / $stone->get_height,
401 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, $alpha
402 );
403 }
404 }
405
406 # then the small stones
407 for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]],
408 [MARK_SMALL_W, $::white_img[$rand % @::white_img]]) {
409 my ($mask, $img) = @$_;
410 if ($mark & $mask) {
411 $img->composite (
412 $base, (int ($size / 4)) x2, (ceil ($size / 2 + 1)) x2, ($size / 4) x2,
413 $size / $img->get_width / 2, $size / $img->get_height / 2,
414 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 224
415 );
416 }
417 }
418
419 # and lastly any markers
420 my $dark_bg = ! ! ($mark & (MARK_B | MARK_GRAY_B));
421
422 for ([MARK_CIRCLE, $::circle_img[$dark_bg]],
423 [MARK_TRIANGLE, $::triangle_img[$dark_bg]],
424 [MARK_SQUARE, $::square_img[$dark_bg]]) {
425 my ($mask, $img) = @$_;
426 if ($mark & $mask) {
427 $img->composite (
428 $base, 0, 0, $size, $size, 0, 0,
429 $size / $img->get_width, $size / $img->get_height,
430 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192
431 );
432 }
433 }
434
435 push @$$c, $base;
436 }
437 }
438
439 $$c->[$rand % @$$c];
440}
441
442sub pixbuf_text {
443 my ($pixbuf, $colour, $x, $y, $height, $text) = @_;
444
445 my @c = grep $_,
446 map $::font[$colour][$::fontmap{$_}],
447 split //, $text;
448
449 if (@c) {
450 my $spacing = $height * 0.1;
451 my $s = $height / List::Util::max map $_->get_height, @c;
452 my $W = List::Util::sum map $_->get_width, @c;
453
454 $x -= ($W * $s + $spacing * (@c - 1)) * 0.5;
455 $y -= $height * 0.5;
456
457 for (@c) {
458 my $w = $_->get_width * $s;
459 # +2 == don't fight the rounding
460 $_->composite ($pixbuf,
461 $x, $y, $w+2, $height+2, $x, $y, $s, $s,
462 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255);
463
464 $x += $w + $spacing;
465 }
466 }
467}
468
469sub pixbuf_rect {
470 my ($pb, $colour, $x1, $y1, $x2, $y2, $alpha) = @_;
471 # we fake lines by... a horrible method :/
472 my $colour_pb = new_pixbuf 1, 1, 0, $colour;
473 $colour_pb->composite ($pb, $x1, $y1, $x2 - $x1 + 1, $y2 - $y1 + 1, $x1, $y1, $x2 + 1, $y2 + 1,
474 INTERP_NEAREST, $alpha);
475}
476
477sub repaint_board {
478 my ($self) = @_;
479 my $canvas = $self->{canvas};
480
481 return unless $self->{board};
482
483 my ($w, $h) = ($canvas->allocation->values)[2,3];
484
485 die "FATAL: board aspect ratio != 1" unless $w == $h;
486
487 my $s = $w;
488
489 return unless $s >= 200;
490
491 my $size = $self->{size};
492
493 # we leave enough space for the shadows.. I like smaller stones, and we
494 # do no need to do the nifty recursive screen updates that goban2 does
495 my $border = int ($s / ($size + 3) * 0.5);
496 my $s2 = $s - $border * 2;
497 my $edge = int ($s2 / ($size + 1) * 0.96) - ($::config->{randomize} ? 3 : 0);
498 my $ofs = int ($edge / 2);
499
500 my @k = map int ($s2 * $_ / ($size+1) + $border + 0.5), 0 .. $size;
501
502 my $pixbuf;
503
504 my $oldboard;
505
506 if ($self->{background}) {
507 if ($oldboard = $self->{board_shown}) {
508 $pixbuf = $self->{pixbuf};
509 } else {
510 $pixbuf = $self->{background}->copy;
511 $self->{canvas}->queue_draw_area (0, 0, $s, $s);
512 }
513 } else {
514 $self->{canvas}->queue_draw_area (0, 0, $s, $s);
515
516 my ($bw, $bh) = ($::board_img->get_width, $::board_img->get_height);
517
518 if ($s < $bw && $s < $bh) {
519 $pixbuf = new_pixbuf $s, $s, 0;
520 $::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0);
521 } else {
522 $pixbuf = scale_pixbuf $::board_img, $s, $s, $::config->{speed} ? INTERP_NEAREST : INTERP_TILES;
523 }
524
525 my $linew = int ($s / 40 / $size);
526
527 # ornamental border... we have time to waste :/
528 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $s-1, $linew, 255;
529 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $s-1, 255;
530 pixbuf_rect $pixbuf, 0xffcc7700, $s-$linew-1, 0, $s-1, $s-1, 255;
531 pixbuf_rect $pixbuf, 0xffcc7700, 0, $s-$linew-1, $s-1, $s-1, 255;
532
533 for my $i (1 .. $size) {
534 pixbuf_rect $pixbuf, 0x44111100, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew, 192;
535 pixbuf_rect $pixbuf, 0x44111100, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew, 192;
536
537 # 38 max, but we allow a bit more
538 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
539 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];
540
541 pixbuf_text $pixbuf, 0, $k[$i], $border, $ofs, $label;
542 pixbuf_text $pixbuf, 0, $k[$i], $s2 + $border, $ofs, $label;
543 pixbuf_text $pixbuf, 0, $border, $k[$i], $ofs, $size - $i + 1;
544 pixbuf_text $pixbuf, 0, $s2 + $border, $k[$i], $ofs, $size - $i + 1;
545
546 $a++;
547 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK...
548 }
549
550 # hoshi points
551 my $hoshi = sub {
552 my ($x, $y) = @_;
553 my $hs = int ($edge / 4) | 1;
554 $x = $k[$x] - $hs / 2; $y = $k[$y] - $hs / 2;
555
556 # we use the shadow mask... not perfect, but I want to finish this
557 $::shadow_img->composite ($pixbuf,
558 $x, $y, $hs + 1, $hs + 1, $x, $y,
559 $hs / $::shadow_img->get_width, $hs / $::shadow_img->get_height,
560 $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255);
561 };
562
563 my $h1 = $size < 10 ? 3 : 4; # corner / edge offset
564 $hoshi->($h1, $h1);
565 $hoshi->($size - $h1 + 1, $h1);
566 $hoshi->($h1, $size - $h1 + 1);
567 $hoshi->($size - $h1 + 1, $size - $h1 + 1);
568
569 if ($size % 2) { # on odd boards, also the remaining 5
570 my $h2 = ($size + 1) / 2;
571 if ($size > 10) {
572 $hoshi->($h1, $h2);
573 $hoshi->($size - $h1 + 1, $h2);
574 $hoshi->($h2, $size - $h1 + 1);
575 $hoshi->($h2, $h1);
576 }
577 # the tengen
578 $hoshi->($h2, $h2);
579 }
580
581 unless ($::config->{conserve_memory} > 1) {
582 $self->{background} = $pixbuf;
583 $pixbuf = $pixbuf->copy;
584 }
585 }
586
587 $self->{pixbuf} = $pixbuf;
588
589 for my $x (1 .. $size) {
590 for my $y (1 .. $size) {
591 my $rand = ($x ^ $y ^ 0x5555);
592
593 my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs);
594
595 if ($::config->{randomize}) {
596 $dx += ($rand % 7) - 3;
597 $dy += ($rand / 3 % 7) - 3;
598 }
599
600 my $shadow = $edge * 0.05;
601 my $area = [$dx, $dy, $edge + $shadow, $edge + $shadow];
602
603 my $mark = $self->{board}{board}[$x-1][$y-1];
604 my $old = $oldboard ? $oldboard->{board}[$x-1][$y-1] : 0;
605
606 if ($oldboard) {
607 next if $old == $mark; # no change
608
609 $self->{background}->copy_area (@$area, $pixbuf, $dx, $dy);
610 }
611
612 if ($mark) {
613 my $pb = $self->create_stack($mark, $edge, $rand);
614
615 $pb->composite ($pixbuf, @$area,
616 $dx, $dy, 1, 1, $::config->{speed} ? INTERP_NEAREST : INTERP_NEAREST, 255);
617
618 # labels are handled here because they are quite rare
619 if ($mark & MARK_LABEL) {
620 my $white = $mark & (MARK_W | MARK_GRAY_W) ? 0 : 1;
621
622 if ($white) {
623 pixbuf_text $pixbuf, 0,
624 $k[$x] + $ofs * 0.1, $k[$y] + $ofs * 0.1, $ofs * 0.7,
625 $self->{board}{label}[$x-1][$y-1];
626 }
627 pixbuf_text $pixbuf, $white,
628 $k[$x], $k[$y], $ofs * 0.7,
629 $self->{board}{label}[$x-1][$y-1];
630 }
631 }
632
633 if ($oldboard) {
634 $self->redraw (@$area);
635 }
636 }
637 }
638
639 $self->{board_shown} = Storable::dclone $self->{board};
640}
641
642sub redraw {
643 my ($self, $x, $y, $w, $h) = @_;
644
645 if ($self->{pixbuf}) {
646 $self->{canvas}->window->draw_pixbuf ($self->{canvas}->style->white_gc, $self->{pixbuf},
647 $x, $y, $x, $y, $w, $h,
648 "normal", 0, 0);
649 $self->{canvas}->window->draw_rectangle ($self->{canvas}->style->black_gc, 0,
650 $x - 1, $y - 1, $w + 2, $h + 2) if $::DEBUG_EXPOSE;
651 }
652}
653
654sub update_board { 325sub update_board {
655 my ($self) = @_; 326 my ($self) = @_;
656 return unless $self->{path}; 327 return unless $self->{path};
657 328
658 my $move = int $self->{moveadj}->get_value; 329 my $move = int $self->{moveadj}->get_value;
659 330
660 my $running = $move == @{$self->{path}}; 331 my $running = $move == @{$self->{path}};
661 332
662 $self->{board_label}->set_text ("Move " . ($move - 1)); 333 $self->{board_label}->set_text ("Move " . ($move - 1));
663 334
664 $self->{board} = new KGS::Game::Board $self->{size}; 335 $self->{cur_board} = new KGS::Game::Board $self->{size};
665 $self->{board}->interpret_path ([@{$self->{path}}[0 .. $move - 1]]); 336 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $move - 1]]);
666 337
667 for my $colour (WHITE, BLACK) { 338 for my $colour (COLOUR_WHITE, COLOUR_BLACK) {
668 $self->{userpanel}[$colour]->set_state ( 339 $self->{userpanel}[$colour]->set_state (
669 $self->{board}{captures}[$colour], 340 $self->{cur_board}{captures}[$colour],
670 $self->{board}{timer}[$colour], 341 $self->{cur_board}{timer}[$colour],
671 ($running && $self->{lastmove_colour} == !$colour) 342 ($running && $self->{lastmove_colour} == !$colour)
672 ? $self->{lastmove_time} : 0 343 ? $self->{lastmove_time} : 0
673 ); 344 );
674 } 345 }
675 346
676 $self->repaint_board; 347 $self->{board}->set_board ($self->{cur_board});
677} 348}
678 349
679sub event_update_tree { 350sub event_update_tree {
680 my ($self) = @_; 351 my ($self) = @_;
681 352
728 }sgexi; 399 }sgexi;
729 400
730 $text .= $_; 401 $text .= $_;
731 } 402 }
732 403
733 $self->{text}->append_text ($text); 404 $self->{chat}->append_text ($text);
734} 405}
735 406
736sub event_join { 407sub event_join {
737 my ($self) = @_; 408 my ($self) = @_;
738 $self->SUPER::event_join; 409 $self->SUPER::event_join;
751 422
752sub event_update_game { 423sub event_update_game {
753 my ($self) = @_; 424 my ($self) = @_;
754 $self->SUPER::event_update_game; 425 $self->SUPER::event_update_game;
755 426
756 my $title = $self->{channel} ? $self->owner->as_string . " " . $self->opponent_string : "Game Window"; 427 return unless $self->{window};
428
429 my $title = defined $self->{channel}
430 ? $self->owner->as_string . " " . $self->opponent_string
431 : "Game Window";
757 $self->{window}->set_title("KGS Game $title"); 432 $self->{window}->set_title("KGS Game $title");
758 $self->{title}->set_text ($title); 433 $self->{title}->set_text ($title);
759 434
760 $self->{user}[BLACK] = $self->{user1}; 435 $self->{user}[COLOUR_BLACK] = $self->{user1};
761 $self->{user}[WHITE] = $self->{user2}; 436 $self->{user}[COLOUR_WHITE] = $self->{user2};
762 437
763 # show board 438 # show board
764 439
765 $self->{left}->remove ($_) for $self->{left}->get_children;
766 if ($self->is_valid) { 440 if ($self->is_valid) {
441 #D# TODO: check wether already inside, or already removed!!!
767 $self->{left}->add ($self->{boardbox}); 442 $self->{left}->add ($self->{boardbox});
768 (delete $self->{challenge})->destroy if $self->{challenge}; 443 $self->{left}->remove ($self->{challenge}->widget) if $self->{challenge};
769 } else { 444 } else {
445 #D# TODO: check wether already inside, or already removed!!!
770 $self->{left}->add ($self->{challenge}->widget); 446 $self->{left}->add ($self->{challenge}->widget);
447 $self->{left}->remove ($self->{boardbox});
771 } 448 }
772 $self->{left}->show_all; 449 $self->{left}->show_all;
773 450
774 # view text 451 # view text
775 452
453 eval { #d#
776 my @ga; 454 my @ga;
777 $ga[0] = "\nType: " . (util::toxml $gametype{$self->type}) 455 $ga[0] = "\nType: " . (util::toxml $gametype{$self->type})
778 . " (" . (util::toxml $gameopt{$self->option}) . ")"; 456 . " (" . (util::toxml $gameopt{$self->option}) . ")";
779 $ga[1] = "\nFlags:"; 457 $ga[1] = "\nFlags:";
780 $ga[1] .= " valid" if $self->is_valid; 458 $ga[1] .= " valid" if $self->is_valid;
805 } 483 }
806 } 484 }
807 $text .= "</infoblock>"; 485 $text .= "</infoblock>";
808 486
809 $self->{gatext} = \@ga; 487 $self->{gatext} = \@ga;
810 488 };
489
811 $self->{text}->append_text ($text); 490 $self->{chat}->append_text ($text);
812} 491}
813 492
814sub event_update_rules { 493sub event_update_rules {
815 my ($self, $rules) = @_; 494 my ($self, $rules) = @_;
816 495
817 $self->{userpanel}[$_]->configure ($self->{user}[$_], $rules) 496 $self->{userpanel}[$_]->configure ($self->{app}, $self->{user}[$_], $rules)
818 for BLACK, WHITE; 497 for COLOUR_BLACK, COLOUR_WHITE;
819 498
820 sound::play 3, "gamestart"; 499 sound::play 3, "gamestart";
821 500
822 my $text = "\n<header>Game Rules</header>"; 501 my $text = "\n<header>Game Rules</header>";
823 502
836 } elsif ($rules->{timesys} == TIMESYS_CANADIAN) { 515 } elsif ($rules->{timesys} == TIMESYS_CANADIAN) {
837 $text .= util::format_time $rules->{time}; 516 $text .= util::format_time $rules->{time};
838 $text .= sprintf " + %s/%d CAN", util::format_time $rules->{interval}, $rules->{count}; 517 $text .= sprintf " + %s/%d CAN", util::format_time $rules->{interval}, $rules->{count};
839 } 518 }
840 519
841 $self->{text}->append_text ("<infoblock>$text</infoblock>"); 520 $self->{chat}->append_text ("<infoblock>$text</infoblock>");
842} 521}
843 522
844sub inject_resign_game { 523sub inject_resign_game {
845 my ($self, $msg) = @_; 524 my ($self, $msg) = @_;
846 525
847 sound::play 3, "resign"; 526 sound::play 3, "resign";
848 527
849 $self->{text}->append_text ("\n<infoblock><header>Resign</header>" 528 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>"
850 . "\n<user>" 529 . "\n<user>"
851 . (util::toxml $self->{user}[$msg->{player}]->as_string) 530 . (util::toxml $self->{user}[$msg->{player}]->as_string)
852 . "</user> resigned.</infoblock>"); 531 . "</user> resigned.</infoblock>");
853} 532}
854 533
855sub inject_final_result { 534sub inject_final_result {
856 my ($self, $msg) = @_; 535 my ($self, $msg) = @_;
857 536
858 $self->{text}->append_text ("<infoblock>\n<header>Game Over</header>" 537 $self->{chat}->append_text ("<infoblock>\n<header>Game Over</header>"
859 . "\nWhite Score " . (util::toxml $msg->{whitescore}->as_string) 538 . "\nWhite Score " . (util::toxml $msg->{whitescore}->as_string)
860 . "\nBlack Score " . (util::toxml $msg->{blackscore}->as_string) 539 . "\nBlack Score " . (util::toxml $msg->{blackscore}->as_string)
861 . "</infoblock>" 540 . "</infoblock>"
862 ); 541 );
863} 542}
864 543
544sub event_challenge {
545 my ($self, $challenge) = @_;
546
547 use KGS::Listener::Debug;
548 $self->{chat}->append_text ("\n".KGS::Listener::Debug::dumpval($challenge));
549}
550
865sub destroy { 551sub destroy {
866 my ($self) = @_; 552 my ($self) = @_;
553
554 delete $self->{app}{gamelist}{game}{$self->{channel}};
867 $self->{userpanel}[$_] && (delete $self->{userpanel}[$_])->destroy 555 $self->{userpanel}[$_] && (delete $self->{userpanel}[$_])->destroy
868 for BLACK, WHITE; 556 for COLOUR_BLACK, COLOUR_WHITE;
869 $self->SUPER::destroy; 557 $self->SUPER::destroy;
870 delete $appwin::gamelist->{game}{$self->{channel}};
871} 558}
872 559
8731; 5601;
874 561

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines