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.114 by root, Tue Jun 1 12:46:54 2004 UTC vs.
Revision 1.139 by root, Mon Aug 9 21:59:37 2004 UTC

146 ]; 146 ];
147 147
148sub INIT_INSTANCE { 148sub INIT_INSTANCE {
149 my ($self) = @_; 149 my ($self) = @_;
150 150
151 $self->add ($self->{window} = my $window = new Gtk2::EventBox); # for bg
152
151 $self->add (my $vbox = new Gtk2::VBox); 153 $window->add (my $vbox = new Gtk2::VBox);
152 154
153 $vbox->pack_start (($self->{name} = new Gtk2::Label "-"), 1, 1, 0); 155 $vbox->pack_start (($self->{name} = new Gtk2::Label "-"), 1, 1, 0);
154 $vbox->pack_start (($self->{info} = new Gtk2::Label "-"), 1, 1, 0); 156 $vbox->pack_start (($self->{info} = new Gtk2::Label "-"), 1, 1, 0);
155 $vbox->pack_start (($self->{clock} = new game::goclock), 1, 1, 0); 157 $vbox->pack_start (($self->{clock} = new game::goclock), 1, 1, 0);
156 158
157 $vbox->add ($self->{imagebox} = new Gtk2::VBox); 159 $vbox->add ($self->{imagebox} = new Gtk2::VBox);
158 160
159 $self; 161 $self;
160} 162}
161 163
164sub SET_PROPERTY {
165 my ($self, $pspec, $value) = @_;
166
167 $self->{$pspec->get_name} = $value;
168
169 $self->set_name ("userpanel-$self->{colour}");
170}
171
162sub configure { 172sub configure {
163 my ($self, $app, $user, $rules) = @_; 173 my ($self, $app, $user, $rules) = @_;
164 174
165 if ($self->{name}->get_text ne $user->as_string) { 175 if ($self->{name}->get_text ne $user->as_string) {
166 $self->{name}->set_text ($user->as_string); 176 $self->{name}->set_text ($user->as_string);
167 177
168 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 178 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
179 unless ($::config{suppress_userpic}) {
169 $self->{imagebox}->add (gtk::image_from_data undef); 180 $self->{imagebox}->add (gtk::image_from_data undef);
181 }
170 $self->{imagebox}->show_all; 182 $self->{imagebox}->show_all;
171 183
172 if ($user->has_pic) { 184 if ($user->has_pic) {
173 # the big picture... 185 # the big picture...
174 $app->userpic ($user->{name}, sub { 186 $app->userpic ($user->{name}, sub {
175 return unless $self->{imagebox}; 187 return unless $self->{imagebox};
176 188
177 if ($_[0]) { 189 if ($_[0]) {
178 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 190 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
191 unless ($::config{suppress_userpic}) {
179 $self->{imagebox}->add (gtk::image_from_data $_[0]); 192 $self->{imagebox}->add (gtk::image_from_data $_[0]);
193 }
180 $self->{imagebox}->show_all; 194 $self->{imagebox}->show_all;
181 } 195 }
182 }); 196 });
183 } 197 }
184 } 198 }
218 232
219use POSIX qw(ceil); 233use POSIX qw(ceil);
220 234
221sub new { 235sub new {
222 my ($self, %arg) = @_; 236 my ($self, %arg) = @_;
237
223 $self = $self->Glib::Object::new; 238 $self = $self->Glib::Object::new;
224 $self->{$_} = delete $arg{$_} for keys %arg; 239 $self->{$_} = delete $arg{$_} for keys %arg;
225 240
226 gtk::state $self, "game::window", undef, window_size => [600, 500]; 241 gtk::state $self, "game::window", undef, window_size => [620, 460];
242 $self->set (allow_shrink => 1);
227 243
228 $self->signal_connect (destroy => sub { 244 $self->signal_connect (destroy => sub {
229 $self->unlisten; 245 $self->unlisten;
230 delete $self->{app}{game}{$self->{channel}}; 246 delete $self->{app}{game}{$self->{channel}};
231 %{$_[0]} = (); 247 %{$_[0]} = ();
232 });#d# 248 });#d#
233 249
234 $self->add (my $hpane = new Gtk2::HPaned); 250 $self->add (my $hpane = new Gtk2::HPaned);
235 gtk::state $hpane, "game::hpane", undef, position => 500; 251 gtk::state $hpane, "game::hpane", undef, position => 420;
236 252
237 # LEFT PANE 253 # LEFT PANE
238 254
239 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0); 255 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0);
240 256
250 $vbox->pack_start ((my $frame = new Gtk2::Frame), 0, 1, 0); 266 $vbox->pack_start ((my $frame = new Gtk2::Frame), 0, 1, 0);
251 267
252 { 268 {
253 $frame->add (my $vbox = new Gtk2::VBox); 269 $frame->add (my $vbox = new Gtk2::VBox);
254 $vbox->add ($self->{title} = new Gtk2::Label "-"); 270 $vbox->add ($self->{title} = new Gtk2::Label "-");
271 $self->{title}->set (visible => 0, no_show_all => 1); # workaround for refresh-bug
255 272
256 $vbox->add (my $hbox = new Gtk2::HBox); 273 $vbox->add (my $hbox = new Gtk2::HBox);
257 274
258 $hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 0, 0); 275 $hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 0, 0);
259 276
275 for COLOUR_WHITE, COLOUR_BLACK; 292 for COLOUR_WHITE, COLOUR_BLACK;
276 293
277 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); 294 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0);
278 295
279 $buttonbox->add ($self->{button_pass} = 296 $buttonbox->add ($self->{button_pass} =
280 Gtk2::Button->Glib::Object::new (label => "Pass", no_show_all => 1, visible => 0)); 297 Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0, no_show_all => 1));
281 $self->{button_pass}->signal_connect (clicked => sub { 298 $self->{button_pass}->signal_connect (clicked => sub {
282 $self->{board_click}->(255, 255) if $self->{board_click}; 299 $self->{board_click}->(255, 255) if $self->{board_click};
283 }); 300 });
284 $buttonbox->add ($self->{button_undo} = 301 $buttonbox->add ($self->{button_undo} =
285 Gtk2::Button->Glib::Object::new (label => "Undo", no_show_all => 1, visible => 0)); 302 Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0, no_show_all => 1));
286 $self->{button_undo}->signal_connect (clicked => sub { 303 $self->{button_undo}->signal_connect (clicked => sub {
287 $self->send (req_undo => channel => $self->{channel}); 304 $self->send (req_undo => channel => $self->{channel});
288 }); 305 });
289 $buttonbox->add ($self->{button_resign} = 306 $buttonbox->add ($self->{button_resign} =
290 Gtk2::Button->Glib::Object::new (label => "Resign", no_show_all => 1, visible => 0)); 307 Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0, no_show_all => 1));
291 $self->{button_resign}->signal_connect (clicked => sub { 308 $self->{button_resign}->signal_connect (clicked => sub {
292 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); 309 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour});
293 }); 310 });
294 311
295 $vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); 312 $vbox->pack_start (($self->{chat} = new chat app => $self->{app}), 1, 1, 0);
313
314 $self->{chat}->signal_connect (tag_event => sub {
315 my (undef, $tag, $event, $content) = @_;
316 });
296 317
297 $self->set_channel ($self->{channel}); 318 $self->set_channel ($self->{channel});
298 319
299 $self->show_all; 320 $self->show_all;
300 321
304sub set_channel { 325sub set_channel {
305 my ($self, $channel) = @_; 326 my ($self, $channel) = @_;
306 327
307 $self->{channel} = $channel; 328 $self->{channel} = $channel;
308 329
309 if ($self->{channel} > 0) { 330 if (defined $self->{channel}) {
310 $self->listen ($self->{conn}); 331 $self->listen ($self->{conn});
311 332
312 $self->{rules_inlay} = $self->{chat}->new_switchable_inlay ("Game Setup:", sub { $self->draw_setup (@_) }, 1); 333 $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); 334 $self->{users_inlay} = $self->{chat}->new_switchable_inlay ("Users:", sub { $self->draw_users (@_) }, 1);
314 335
315 $self->signal_connect (delete_event => sub { $self->part; 1 }); 336 $self->signal_connect (delete_event => sub { $self->part; 1 });
316 $self->{chat}->signal_connect (command => sub { 337 $self->{chat}->signal_connect (command => sub {
317 my ($chat, $cmd, $arg) = @_; 338 my ($chat, $cmd, $arg) = @_;
318 if ($cmd eq "rsave") { 339 if ($cmd eq "rsave") {
340 local $Storable::forgive_me = 1;
319 Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d# 341 #Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d#
342 Storable::nstore { %$self }, $arg;#d#
320 } else { 343 } else {
321 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self); 344 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self);
322 } 345 }
323 }); 346 });
324 } 347 }
331 return if $self->{joined}; 354 return if $self->{joined};
332 355
333 $self->SUPER::join; 356 $self->SUPER::join;
334} 357}
335 358
359sub part {
360 my ($self) = @_;
361
362 $self->hide;
363 $self->SUPER::part;
364}
365
336sub event_join { 366sub event_join {
337 my ($self) = @_; 367 my ($self) = @_;
338 368
339 $self->SUPER::event_join (@_); 369 $self->SUPER::event_join (@_);
340 $self->init_tree; 370 $self->init_tree;
359 389
360sub draw_users { 390sub draw_users {
361 my ($self, $inlay) = @_; 391 my ($self, $inlay) = @_;
362 392
363 for (sort keys %{$self->{users}}) { 393 for (sort keys %{$self->{users}}) {
364 $inlay->append_text (" <user>" . $self->{users}{$_}->as_string . "</user>"); 394 $inlay->append_text ("\t<user>" . $self->{users}{$_}->as_string . "</user>");
365 } 395 }
366} 396}
367 397
368sub event_update_users { 398sub event_update_users {
369 my ($self, $add, $update, $remove) = @_; 399 my ($self, $add, $update, $remove) = @_;
379 $important{$self->{black}{name}}++; 409 $important{$self->{black}{name}}++;
380 $important{$self->{white}{name}}++; 410 $important{$self->{white}{name}}++;
381 $important{$self->{owner}{name}}++; 411 $important{$self->{owner}{name}}++;
382 412
383 if (my @users = grep $important{$_->{name}}, @$add) { 413 if (my @users = grep $important{$_->{name}}, @$add) {
384 $self->{chat}->append_text ("\n<header>Joins:</header>"); 414 $self->{chat}->append_text ("\n<leader>Joins:</leader>");
385 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 415 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
386 } 416 }
387 if (my @users = grep $important{$_->{name}}, @$remove) { 417 if (my @users = grep $important{$_->{name}}, @$remove) {
388 $self->{chat}->append_text ("\n<header>Parts:</header>"); 418 $self->{chat}->append_text ("\n<leader>Parts:</leader>");
389 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 419 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
390 } 420 }
391} 421}
392 422
393### GAME INFO ############################################################### 423### GAME INFO ###############################################################
484 my $title = defined $self->{channel} 514 my $title = defined $self->{channel}
485 ? $self->owner->as_string . " " . $self->opponent_string 515 ? $self->owner->as_string . " " . $self->opponent_string
486 : "Game Window"; 516 : "Game Window";
487 $self->set_title ("KGS Game $title"); 517 $self->set_title ("KGS Game $title");
488 $self->{title}->set_text ($title); # title gets redrawn wrongly 518 $self->{title}->set_text ($title); # title gets redrawn wrongly
519 $self->{title}->show; # workaround for refresh-bug
489 520
490 $self->{rules_inlay}->refresh; 521 $self->{rules_inlay}->refresh;
491 522
492 if (exists $self->{teacher}) { 523 if (exists $self->{teacher}) {
493 $self->{teacher_inlay} ||= $self->{chat}->new_inlay; 524 $self->{teacher_inlay} ||= $self->{chat}->new_inlay;
550sub update_cursor { 581sub update_cursor {
551 my ($self) = @_; 582 my ($self) = @_;
552 583
553 return unless $self->{cur_board}; 584 return unless $self->{cur_board};
554 585
586 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
587 if ($self->{curnode}{move} == 0) {
588 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
589 } else {
590 $self->{whosemove} = 1 - $self->{cur_board}{last};
591 }
592 } else {
593 # Chinese, Aga, NZ all have manual placement
594 if ($self->{curnode}{move} < $self->{handicap}) {
595 $self->{whosemove} = COLOUR_BLACK;
596 } elsif ($self->{curnode}{move} == $self->{handicap}) {
597 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
598 } else {
599 $self->{whosemove} = 1 - $self->{cur_board}{last};
600 }
601 }
602
555 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; 603 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active;
556 604
557 delete $self->{board_click}; 605 delete $self->{board_click};
558 606
559 $self->{colour} = COLOUR_BLACK;#d#
560 $self->{whosemove} = COLOUR_BLACK;#d#
561 if ($self->{teacher} eq $self->{app}{conn}) { 607 if ($self->{teacher} eq $self->{app}{conn}) {
562 #TODO# # teaching mode not implemented 608 #TODO# # teaching mode not implemented
563 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 609 $self->{button_pass}->set (label => "Pass", sensitive => 1);
610 $self->{button_pass}->show;
564 $self->{button_undo}->hide; 611 $self->{button_undo}->hide;
565 $self->{button_resign}->hide; 612 $self->{button_resign}->hide;
566 $self->{board}->set (cursor => undef); 613 $self->{board}->set (cursor => undef);
567 614
568 } elsif ($running && $self->{colour} != COLOUR_NONE) { 615 } elsif ($running && $self->{colour} != COLOUR_NONE) {
570 $self->{button_undo}->show; 617 $self->{button_undo}->show;
571 $self->{button_resign}->show; 618 $self->{button_resign}->show;
572 619
573 if ($self->{cur_board}{score}) { 620 if ($self->{cur_board}{score}) {
574 # during scoring 621 # during scoring
575 $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); 622 $self->{button_pass}->set (label => "Done", sensitive => 1);
623 $self->{button_pass}->show;
576 $self->{board}->set (cursor => sub { 624 $self->{board}->set (cursor => sub {
577 $_[0] & (MARK_B | MARK_W) 625 $_[0] & (MARK_B | MARK_W)
578 ? $_[0] ^ MARK_GRAYED 626 ? $_[0] ^ MARK_GRAYED
579 : $_[0]; 627 : $_[0];
580 }); 628 });
592 } 640 }
593 }; 641 };
594 642
595 } elsif ($self->{colour} == $self->{whosemove}) { 643 } elsif ($self->{colour} == $self->{whosemove}) {
596 # normal move 644 # normal move
597 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 645 $self->{button_pass}->set (label => "Pass", sensitive => 1);
646 $self->{button_pass}->show;
598 $self->{board}->set (cursor => sub { 647 $self->{board}->set (cursor => sub {
599 $self->{cur_board} 648 $self->{cur_board}
600 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 649 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2],
601 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND) 650 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND)
602 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B) 651 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B)
603 : $_[0]; 652 : $_[0];
604 }); 653 });
605 $self->{board_click} = sub { 654 $self->{board_click} = sub {
606 return unless 655 return unless
607 $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 656 $self->{cur_board}->is_valid_move ($self->{colour}, $_[0], $_[1],
608 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND); 657 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND);
609 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); 658 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]);
610 $self->{board}->set (cursor => undef); 659 $self->{board}->set (cursor => undef);
611 delete $self->{board_click}; 660 delete $self->{board_click};
612 $self->{button_pass}->sensitive (0); 661 $self->{button_pass}->sensitive (0);
613 }; 662 };
614 } else { 663 } else {
615 $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); 664 $self->{button_pass}->set (label => "Pass", sensitive => 0);
665 $self->{button_pass}->show;
616 $self->{board}->set (cursor => undef); 666 $self->{board}->set (cursor => undef);
617 } 667 }
618 } else { 668 } else {
619 $self->{button_undo}->hide; 669 $self->{button_undo}->hide;
620 $self->{button_resign}->hide; 670 $self->{button_resign}->hide;
627sub update_board { 677sub update_board {
628 my ($self) = @_; 678 my ($self) = @_;
629 679
630 return unless $self->{path}; 680 return unless $self->{path};
631 681
632 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
633 if ($self->{curnode}{move} == 0) {
634 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
635 } else {
636 $self->{whosemove} = 1 - $self->{cur_board}{last};
637 }
638 } else {
639 # Chinese, Aga, NZ all have manual placement
640 if ($self->{curnode}{move} < $self->{handicap}) {
641 $self->{whosemove} = COLOUR_BLACK;
642 } elsif ($self->{curnode}{move} == $self->{handicap}) {
643 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
644 } else {
645 $self->{whosemove} = 1 - $self->{cur_board}{last};
646 }
647 }
648
649 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); 682 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
650 683
651 $self->{cur_board} = new KGS::Game::Board $self->{size}; 684 $self->{cur_board} = new KGS::Game::Board $self->{size};
652 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); 685 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
653 686
654 $self->update_cursor;
655
656 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 687 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
657 for COLOUR_WHITE, COLOUR_BLACK; 688 for COLOUR_WHITE, COLOUR_BLACK;
658 689
659 my $start_time = $self->{rules}{time}; 690 $self->{board}->set_board ($self->{cur_board});
691
692 if ($self->{cur_board}{score}) {
693 $self->{score_inlay} ||= $self->{chat}->new_inlay;
694 $self->{score_inlay}->clear;
695 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
696 . "\n<score>"
697 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
698 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
699 . "</score>");
700 } elsif ($self->{score_inlay}) {
701 (delete $self->{score_inlay})->clear;
702 }
703
704 $self->update_cursor;
660 705
661 if ($self->{showmove} == @{$self->{path}}) { 706 if ($self->{showmove} == @{$self->{path}}) {
662 $self->{timers} = [ 707 $self->{timers} = [
663 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], 708 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}],
664 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], 709 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}],
669 [0, @{$self->{cur_board}{timer}[0]}], 714 [0, @{$self->{cur_board}{timer}[0]}],
670 [0, @{$self->{cur_board}{timer}[1]}], 715 [0, @{$self->{cur_board}{timer}[1]}],
671 ]); 716 ]);
672 } 717 }
673 718
674 $self->{board}->set_board ($self->{cur_board});
675
676 if ($self->{cur_board}{score}) {
677 $self->{score_inlay} ||= $self->{chat}->new_inlay;
678 $self->{score_inlay}->clear;
679 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
680 . "\n<score>"
681 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
682 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
683 . "</score>");
684 } elsif ($self->{score_inlay}) {
685 (delete $self->{score_inlay})->clear;
686 }
687} 719}
688 720
689sub event_update_tree { 721sub event_update_tree {
690 my ($self) = @_; 722 my ($self) = @_;
691 723
709 } 741 }
710} 742}
711 743
712sub event_update_comments { 744sub event_update_comments {
713 my ($self, $node, $comment, $newnode) = @_; 745 my ($self, $node, $comment, $newnode) = @_;
714 $self->SUPER::event_update_comments($node, $comment, $newnode); 746 $self->SUPER::event_update_comments ($node, $comment, $newnode);
715 747
716 my $text; 748 my $text;
717 749
718 $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>" 750 $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>"
719 if $newnode; 751 if $newnode;
758 my ($self, $player) = @_; 790 my ($self, $player) = @_;
759 791
760 sound::play 3, "resign"; 792 sound::play 3, "resign";
761 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>" 793 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>"
762 . "\n<user>" 794 . "\n<user>"
795 . (util::toxml $self->{user}[$player]->as_string)
796 . "</user> resigned."
797 . "\n<user>"
798 . (util::toxml $self->{user}[1 - $player]->as_string)
799 . "</user> wins the game."
800 . "</infoblock>");
801}
802
803sub event_out_of_time {
804 my ($self, $player) = @_;
805
806 sound::play 3, "timewin";
807 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>"
808 . "\n<user>"
763 . (util::toxml $self->{user}[$msg->{player}]->as_string) 809 . (util::toxml $self->{user}[$msg->{player}]->as_string)
764 . "</user> resigned." 810 . "</user> ran out of time and lost."
765 . "\n<user>" 811 . "\n<user>"
766 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) 812 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string)
767 . "</user> wins the game." 813 . "</user> wins the game."
768 . "</infoblock>"); 814 . "</infoblock>");
769} 815}
770 816
771sub event_time_win {
772 my ($self, $player) = @_;
773
774 sound::play 3, "timewin";
775 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>"
776 . "\n<user>"
777 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string)
778 . "</user> ran out of time and lost."
779 . "\n<user>"
780 . (util::toxml $self->{user}[$msg->{player}]->as_string)
781 . "</user> wins the game."
782 . "</infoblock>");
783}
784
785sub event_owner_left { 817sub event_owner_left {
786 my ($self) = @_; 818 my ($self) = @_;
787 819
788 sound::play 2, "info";
789 $self->{chat}->append_text ("\n<infoblock><header>Owner left</header>" 820 $self->{chat}->append_text ("\n<infoblock><header>Owner left</header>"
790 . "\nThe owner of this game left.</infoblock>"); 821 . "\nThe owner of this game left.</infoblock>");
791} 822}
792 823
793sub event_teacher_left { 824sub event_teacher_left {
794 my ($self) = @_; 825 my ($self) = @_;
795 826
796 sound::play 2, "info";
797 $self->{chat}->append_text ("\n<infoblock><header>Teacher left</header>" 827 $self->{chat}->append_text ("\n<infoblock><header>Teacher left</header>"
798 . "\nThe teacher left the game.</infoblock>"); 828 . "\nThe teacher left the game.</infoblock>");
799} 829}
800 830
801sub event_done { 831sub event_done {
875 my $as_black = $info->{black}{name} eq $self->{conn}{name} ? 1 : 0;; 905 my $as_black = $info->{black}{name} eq $self->{conn}{name} ? 1 : 0;;
876 my $opponent = $as_black ? $info->{white} : $info->{black}; 906 my $opponent = $as_black ? $info->{white} : $info->{black};
877 907
878 my ($size, $time, $interval, $count, $type); 908 my ($size, $time, $interval, $count, $type);
879 909
880 if (!$self->{channel}) { 910 if (!defined $self->{channel}) {
881 $inlay->append_text ("\nNotes: "); 911 $inlay->append_text ("\nNotes: ");
882 $inlay->append_entry (\$info->{notes}, 20, ""); 912 $inlay->append_widget (gtk::textentry \$info->{notes}, 20, "");
883 $inlay->append_text ("\nGlobal Offer: "); 913 $inlay->append_text ("\nGlobal Offer: ");
884 $inlay->append_optionmenu (\$info->{flags}, 914 $inlay->append_optionmenu (\$info->{flags},
885 0 => "No", 915 0 => "No",
886 2 => "Yes", 916 2 => "Yes",
887 ); 917 );
902 sub { 932 sub {
903 $size->set_history (2) if $_[0] eq GAMETYPE_RATED; 933 $size->set_history (2) if $_[0] eq GAMETYPE_RATED;
904 }, 934 },
905 ); 935 );
906 936
907 if ($self->{channel}) { 937 if (defined $self->{channel}) {
908 $inlay->append_text ("\nMy Colour: "); 938 $inlay->append_text ("\nMy Colour: ");
909 $inlay->append_optionmenu ( 939 $inlay->append_optionmenu (
910 \$as_black, 940 \$as_black,
911 0 => "White", 941 0 => "White",
912 1 => "Black", 942 1 => "Black",
935 $type->set_history (5) # reset to free 965 $type->set_history (5) # reset to free
936 if $_[0] != 19 && $info->{gametype} == GAMETYPE_RATED; 966 if $_[0] != 19 && $info->{gametype} == GAMETYPE_RATED;
937 }, 967 },
938 ); 968 );
939 969
940 if ($self->{channel}) { 970 if (defined $self->{channel}) {
941 $inlay->append_text ("\nHandicap: "); 971 $inlay->append_text ("\nHandicap: ");
942 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); 972 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9);
943 973
944 $inlay->append_text ("\nKomi: "); 974 $inlay->append_text ("\nKomi: ");
945 $inlay->append_entry (\$info->{rules}{komi}, 5); 975 $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5);
946 } 976 }
947 977
948 $inlay->append_text ("\nTimesys: "); 978 $inlay->append_text ("\nTimesys: ");
949 $inlay->append_optionmenu ( 979 $inlay->append_optionmenu (
950 \$info->{rules}{timesys}, 980 \$info->{rules}{timesys},
979 } 1009 }
980 } 1010 }
981 ); 1011 );
982 1012
983 $inlay->append_text ("\nMain Time: "); 1013 $inlay->append_text ("\nMain Time: ");
984 $time = $inlay->append_entry (\$info->{rules}{time}, 5); 1014 $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5);
985 $inlay->append_text ("\nInterval: "); 1015 $inlay->append_text ("\nInterval: ");
986 $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); 1016 $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5);
987 $inlay->append_text ("\nPeriods/Stones: "); 1017 $inlay->append_text ("\nPeriods/Stones: ");
988 $count = $inlay->append_entry (\$info->{rules}{count}, 2); 1018 $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5);
989 1019
990 $inlay->append_text ("\n"); 1020 $inlay->append_text ("\n");
991 1021
992 if (!$self->{channel}) { 1022 if (!defined $self->{channel}) {
993 $inlay->append_button ("Create Challenge", sub { 1023 $inlay->append_button ("Create Challenge", sub {
994 $inlay->clear; 1024 $inlay->clear;
995 $self->{cid} = $self->{conn}->alloc_clientid; 1025 $self->{cid} = $self->{conn}->alloc_clientid;
996 $self->send (new_game => 1026 $self->send (new_game =>
997 channel => delete $self->{roomid}, 1027 channel => delete $self->{roomid},

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines