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.126 by root, Wed Jun 2 12:23:35 2004 UTC vs.
Revision 1.136 by root, Tue Jun 8 17:50:12 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 }
277 for COLOUR_WHITE, COLOUR_BLACK; 291 for COLOUR_WHITE, COLOUR_BLACK;
278 292
279 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); 293 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0);
280 294
281 $buttonbox->add ($self->{button_pass} = 295 $buttonbox->add ($self->{button_pass} =
282 Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0)); 296 Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0, no_show_all => 1));
283 $self->{button_pass}->signal_connect (clicked => sub { 297 $self->{button_pass}->signal_connect (clicked => sub {
284 $self->{board_click}->(255, 255) if $self->{board_click}; 298 $self->{board_click}->(255, 255) if $self->{board_click};
285 }); 299 });
286 eval { $self->{button_pass}->set (no_show_all => 1) }; # workaround for gtk+-2.2
287 $buttonbox->add ($self->{button_undo} = 300 $buttonbox->add ($self->{button_undo} =
288 Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0)); 301 Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0, no_show_all => 1));
289 $self->{button_undo}->signal_connect (clicked => sub { 302 $self->{button_undo}->signal_connect (clicked => sub {
290 $self->send (req_undo => channel => $self->{channel}); 303 $self->send (req_undo => channel => $self->{channel});
291 }); 304 });
292 eval { $self->{button_undo}->set (no_show_all => 1) }; # workaround for gtk+-2.2
293 $buttonbox->add ($self->{button_resign} = 305 $buttonbox->add ($self->{button_resign} =
294 Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0)); 306 Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0, no_show_all => 1));
295 $self->{button_resign}->signal_connect (clicked => sub { 307 $self->{button_resign}->signal_connect (clicked => sub {
296 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); 308 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour});
297 }); 309 });
298 eval { $self->{button_resign}->set (no_show_all => 1) }; # workaround for gtk+-2.2
299 310
300 $vbox->pack_start (($self->{chat} = new chat), 1, 1, 0); 311 $vbox->pack_start (($self->{chat} = new chat app => $self->{app}), 1, 1, 0);
312
313 $self->{chat}->signal_connect (tag_event => sub {
314 my (undef, $tag, $event, $content) = @_;
315 });
301 316
302 $self->set_channel ($self->{channel}); 317 $self->set_channel ($self->{channel});
303 318
304 $self->show_all; 319 $self->show_all;
305 320
371 386
372sub draw_users { 387sub draw_users {
373 my ($self, $inlay) = @_; 388 my ($self, $inlay) = @_;
374 389
375 for (sort keys %{$self->{users}}) { 390 for (sort keys %{$self->{users}}) {
376 $inlay->append_text (" <user>" . $self->{users}{$_}->as_string . "</user>"); 391 $inlay->append_text ("\t<user>" . $self->{users}{$_}->as_string . "</user>");
377 } 392 }
378} 393}
379 394
380sub event_update_users { 395sub event_update_users {
381 my ($self, $add, $update, $remove) = @_; 396 my ($self, $add, $update, $remove) = @_;
562sub update_cursor { 577sub update_cursor {
563 my ($self) = @_; 578 my ($self) = @_;
564 579
565 return unless $self->{cur_board}; 580 return unless $self->{cur_board};
566 581
582 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
583 if ($self->{curnode}{move} == 0) {
584 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
585 } else {
586 $self->{whosemove} = 1 - $self->{cur_board}{last};
587 }
588 } else {
589 # Chinese, Aga, NZ all have manual placement
590 if ($self->{curnode}{move} < $self->{handicap}) {
591 $self->{whosemove} = COLOUR_BLACK;
592 } elsif ($self->{curnode}{move} == $self->{handicap}) {
593 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
594 } else {
595 $self->{whosemove} = 1 - $self->{cur_board}{last};
596 }
597 }
598
567 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; 599 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active;
568 600
569 delete $self->{board_click}; 601 delete $self->{board_click};
570 602
571 if ($self->{teacher} eq $self->{app}{conn}) { 603 if ($self->{teacher} eq $self->{app}{conn}) {
572 #TODO# # teaching mode not implemented 604 #TODO# # teaching mode not implemented
573 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 605 $self->{button_pass}->set (label => "Pass", sensitive => 1);
606 $self->{button_pass}->show;
574 $self->{button_undo}->hide; 607 $self->{button_undo}->hide;
575 $self->{button_resign}->hide; 608 $self->{button_resign}->hide;
576 $self->{board}->set (cursor => undef); 609 $self->{board}->set (cursor => undef);
577 610
578 } elsif ($running && $self->{colour} != COLOUR_NONE) { 611 } elsif ($running && $self->{colour} != COLOUR_NONE) {
580 $self->{button_undo}->show; 613 $self->{button_undo}->show;
581 $self->{button_resign}->show; 614 $self->{button_resign}->show;
582 615
583 if ($self->{cur_board}{score}) { 616 if ($self->{cur_board}{score}) {
584 # during scoring 617 # during scoring
585 $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); 618 $self->{button_pass}->set (label => "Done", sensitive => 1);
619 $self->{button_pass}->show;
586 $self->{board}->set (cursor => sub { 620 $self->{board}->set (cursor => sub {
587 $_[0] & (MARK_B | MARK_W) 621 $_[0] & (MARK_B | MARK_W)
588 ? $_[0] ^ MARK_GRAYED 622 ? $_[0] ^ MARK_GRAYED
589 : $_[0]; 623 : $_[0];
590 }); 624 });
602 } 636 }
603 }; 637 };
604 638
605 } elsif ($self->{colour} == $self->{whosemove}) { 639 } elsif ($self->{colour} == $self->{whosemove}) {
606 # normal move 640 # normal move
607 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 641 $self->{button_pass}->set (label => "Pass", sensitive => 1);
642 $self->{button_pass}->show;
608 $self->{board}->set (cursor => sub { 643 $self->{board}->set (cursor => sub {
609 $self->{cur_board} 644 $self->{cur_board}
610 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 645 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2],
611 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND) 646 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND)
612 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B) 647 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B)
613 : $_[0]; 648 : $_[0];
614 }); 649 });
615 $self->{board_click} = sub { 650 $self->{board_click} = sub {
616 return unless 651 return unless
617 $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 652 $self->{cur_board}->is_valid_move ($self->{colour}, $_[0], $_[1],
618 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND); 653 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND);
619 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); 654 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]);
620 $self->{board}->set (cursor => undef); 655 $self->{board}->set (cursor => undef);
621 delete $self->{board_click}; 656 delete $self->{board_click};
622 $self->{button_pass}->sensitive (0); 657 $self->{button_pass}->sensitive (0);
623 }; 658 };
624 } else { 659 } else {
625 $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); 660 $self->{button_pass}->set (label => "Pass", sensitive => 0);
661 $self->{button_pass}->show;
626 $self->{board}->set (cursor => undef); 662 $self->{board}->set (cursor => undef);
627 } 663 }
628 } else { 664 } else {
629 $self->{button_undo}->hide; 665 $self->{button_undo}->hide;
630 $self->{button_resign}->hide; 666 $self->{button_resign}->hide;
642 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); 678 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
643 679
644 $self->{cur_board} = new KGS::Game::Board $self->{size}; 680 $self->{cur_board} = new KGS::Game::Board $self->{size};
645 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); 681 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
646 682
647 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
648 if ($self->{curnode}{move} == 0) {
649 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
650 } else {
651 $self->{whosemove} = 1 - $self->{cur_board}{last};
652 }
653 } else {
654 # Chinese, Aga, NZ all have manual placement
655 if ($self->{curnode}{move} < $self->{handicap}) {
656 $self->{whosemove} = COLOUR_BLACK;
657 } elsif ($self->{curnode}{move} == $self->{handicap}) {
658 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
659 } else {
660 $self->{whosemove} = 1 - $self->{cur_board}{last};
661 }
662 }
663
664 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 683 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
665 for COLOUR_WHITE, COLOUR_BLACK; 684 for COLOUR_WHITE, COLOUR_BLACK;
666 685
667 my $start_time = $self->{rules}{time}; 686 $self->{board}->set_board ($self->{cur_board});
687
688 if ($self->{cur_board}{score}) {
689 $self->{score_inlay} ||= $self->{chat}->new_inlay;
690 $self->{score_inlay}->clear;
691 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
692 . "\n<score>"
693 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
694 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
695 . "</score>");
696 } elsif ($self->{score_inlay}) {
697 (delete $self->{score_inlay})->clear;
698 }
699
700 $self->update_cursor;
668 701
669 if ($self->{showmove} == @{$self->{path}}) { 702 if ($self->{showmove} == @{$self->{path}}) {
670 $self->{timers} = [ 703 $self->{timers} = [
671 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], 704 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}],
672 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], 705 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}],
677 [0, @{$self->{cur_board}{timer}[0]}], 710 [0, @{$self->{cur_board}{timer}[0]}],
678 [0, @{$self->{cur_board}{timer}[1]}], 711 [0, @{$self->{cur_board}{timer}[1]}],
679 ]); 712 ]);
680 } 713 }
681 714
682 $self->{board}->set_board ($self->{cur_board});
683
684 if ($self->{cur_board}{score}) {
685 $self->{score_inlay} ||= $self->{chat}->new_inlay;
686 $self->{score_inlay}->clear;
687 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
688 . "\n<score>"
689 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
690 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
691 . "</score>");
692 } elsif ($self->{score_inlay}) {
693 (delete $self->{score_inlay})->clear;
694 }
695
696 $self->update_cursor;
697
698} 715}
699 716
700sub event_update_tree { 717sub event_update_tree {
701 my ($self) = @_; 718 my ($self) = @_;
702 719
720 } 737 }
721} 738}
722 739
723sub event_update_comments { 740sub event_update_comments {
724 my ($self, $node, $comment, $newnode) = @_; 741 my ($self, $node, $comment, $newnode) = @_;
725 $self->SUPER::event_update_comments($node, $comment, $newnode); 742 $self->SUPER::event_update_comments ($node, $comment, $newnode);
726 743
727 my $text; 744 my $text;
728 745
729 $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>" 746 $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>"
730 if $newnode; 747 if $newnode;
769 my ($self, $player) = @_; 786 my ($self, $player) = @_;
770 787
771 sound::play 3, "resign"; 788 sound::play 3, "resign";
772 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>" 789 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>"
773 . "\n<user>" 790 . "\n<user>"
774 . (util::toxml $self->{user}[$msg->{player}]->as_string) 791 . (util::toxml $self->{user}[$player]->as_string)
775 . "</user> resigned." 792 . "</user> resigned."
776 . "\n<user>" 793 . "\n<user>"
777 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) 794 . (util::toxml $self->{user}[1 - $player]->as_string)
778 . "</user> wins the game." 795 . "</user> wins the game."
779 . "</infoblock>"); 796 . "</infoblock>");
780} 797}
781 798
782sub event_time_win { 799sub event_out_of_time {
783 my ($self, $player) = @_; 800 my ($self, $player) = @_;
784 801
785 sound::play 3, "timewin"; 802 sound::play 3, "timewin";
786 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>" 803 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>"
787 . "\n<user>" 804 . "\n<user>"
788 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) 805 . (util::toxml $self->{user}[$msg->{player}]->as_string)
789 . "</user> ran out of time and lost." 806 . "</user> ran out of time and lost."
790 . "\n<user>" 807 . "\n<user>"
791 . (util::toxml $self->{user}[$msg->{player}]->as_string) 808 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string)
792 . "</user> wins the game." 809 . "</user> wins the game."
793 . "</infoblock>"); 810 . "</infoblock>");
794} 811}
795 812
796sub event_owner_left { 813sub event_owner_left {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines