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.121 by root, Wed Jun 2 04:39:07 2004 UTC vs.
Revision 1.133 by root, Sun Jun 6 07:55:06 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 }
223 237
224 $self = $self->Glib::Object::new; 238 $self = $self->Glib::Object::new;
225 $self->{$_} = delete $arg{$_} for keys %arg; 239 $self->{$_} = delete $arg{$_} for keys %arg;
226 240
227 gtk::state $self, "game::window", undef, window_size => [620, 460]; 241 gtk::state $self, "game::window", undef, window_size => [620, 460];
242 $self->set (allow_shrink => 1);
228 243
229 $self->signal_connect (destroy => sub { 244 $self->signal_connect (destroy => sub {
230 $self->unlisten; 245 $self->unlisten;
231 delete $self->{app}{game}{$self->{channel}}; 246 delete $self->{app}{game}{$self->{channel}};
232 %{$_[0]} = (); 247 %{$_[0]} = ();
335 return if $self->{joined}; 350 return if $self->{joined};
336 351
337 $self->SUPER::join; 352 $self->SUPER::join;
338} 353}
339 354
355sub part {
356 my ($self) = @_;
357
358 $self->hide;
359 $self->SUPER::part;
360}
361
340sub event_join { 362sub event_join {
341 my ($self) = @_; 363 my ($self) = @_;
342 364
343 $self->SUPER::event_join (@_); 365 $self->SUPER::event_join (@_);
344 $self->init_tree; 366 $self->init_tree;
383 $important{$self->{black}{name}}++; 405 $important{$self->{black}{name}}++;
384 $important{$self->{white}{name}}++; 406 $important{$self->{white}{name}}++;
385 $important{$self->{owner}{name}}++; 407 $important{$self->{owner}{name}}++;
386 408
387 if (my @users = grep $important{$_->{name}}, @$add) { 409 if (my @users = grep $important{$_->{name}}, @$add) {
388 $self->{chat}->append_text ("\n<header>Joins:</header>"); 410 $self->{chat}->append_text ("\n<leader>Joins:</leader>");
389 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 411 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
390 } 412 }
391 if (my @users = grep $important{$_->{name}}, @$remove) { 413 if (my @users = grep $important{$_->{name}}, @$remove) {
392 $self->{chat}->append_text ("\n<header>Parts:</header>"); 414 $self->{chat}->append_text ("\n<leader>Parts:</leader>");
393 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 415 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
394 } 416 }
395} 417}
396 418
397### GAME INFO ############################################################### 419### GAME INFO ###############################################################
554sub update_cursor { 576sub update_cursor {
555 my ($self) = @_; 577 my ($self) = @_;
556 578
557 return unless $self->{cur_board}; 579 return unless $self->{cur_board};
558 580
581 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
582 if ($self->{curnode}{move} == 0) {
583 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
584 } else {
585 $self->{whosemove} = 1 - $self->{cur_board}{last};
586 }
587 } else {
588 # Chinese, Aga, NZ all have manual placement
589 if ($self->{curnode}{move} < $self->{handicap}) {
590 $self->{whosemove} = COLOUR_BLACK;
591 } elsif ($self->{curnode}{move} == $self->{handicap}) {
592 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
593 } else {
594 $self->{whosemove} = 1 - $self->{cur_board}{last};
595 }
596 }
597
559 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; 598 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active;
560 599
561 delete $self->{board_click}; 600 delete $self->{board_click};
562 601
563 if ($self->{teacher} eq $self->{app}{conn}) { 602 if ($self->{teacher} eq $self->{app}{conn}) {
564 #TODO# # teaching mode not implemented 603 #TODO# # teaching mode not implemented
565 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 604 $self->{button_pass}->set (label => "Pass", sensitive => 1);
605 $self->{button_pass}->show;
566 $self->{button_undo}->hide; 606 $self->{button_undo}->hide;
567 $self->{button_resign}->hide; 607 $self->{button_resign}->hide;
568 $self->{board}->set (cursor => undef); 608 $self->{board}->set (cursor => undef);
569 609
570 } elsif ($running && $self->{colour} != COLOUR_NONE) { 610 } elsif ($running && $self->{colour} != COLOUR_NONE) {
572 $self->{button_undo}->show; 612 $self->{button_undo}->show;
573 $self->{button_resign}->show; 613 $self->{button_resign}->show;
574 614
575 if ($self->{cur_board}{score}) { 615 if ($self->{cur_board}{score}) {
576 # during scoring 616 # during scoring
577 $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); 617 $self->{button_pass}->set (label => "Done", sensitive => 1);
618 $self->{button_pass}->show;
578 $self->{board}->set (cursor => sub { 619 $self->{board}->set (cursor => sub {
579 $_[0] & (MARK_B | MARK_W) 620 $_[0] & (MARK_B | MARK_W)
580 ? $_[0] ^ MARK_GRAYED 621 ? $_[0] ^ MARK_GRAYED
581 : $_[0]; 622 : $_[0];
582 }); 623 });
594 } 635 }
595 }; 636 };
596 637
597 } elsif ($self->{colour} == $self->{whosemove}) { 638 } elsif ($self->{colour} == $self->{whosemove}) {
598 # normal move 639 # normal move
599 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 640 $self->{button_pass}->set (label => "Pass", sensitive => 1);
641 $self->{button_pass}->show;
600 $self->{board}->set (cursor => sub { 642 $self->{board}->set (cursor => sub {
601 $self->{cur_board} 643 $self->{cur_board}
602 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 644 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2],
603 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND) 645 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND)
604 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B) 646 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B)
605 : $_[0]; 647 : $_[0];
606 }); 648 });
607 $self->{board_click} = sub { 649 $self->{board_click} = sub {
608 return unless 650 return unless
609 $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 651 $self->{cur_board}->is_valid_move ($self->{colour}, $_[0], $_[1],
610 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND); 652 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND);
611 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); 653 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]);
612 $self->{board}->set (cursor => undef); 654 $self->{board}->set (cursor => undef);
613 delete $self->{board_click}; 655 delete $self->{board_click};
614 $self->{button_pass}->sensitive (0); 656 $self->{button_pass}->sensitive (0);
615 }; 657 };
616 } else { 658 } else {
617 $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); 659 $self->{button_pass}->set (label => "Pass", sensitive => 0);
660 $self->{button_pass}->show;
618 $self->{board}->set (cursor => undef); 661 $self->{board}->set (cursor => undef);
619 } 662 }
620 } else { 663 } else {
621 $self->{button_undo}->hide; 664 $self->{button_undo}->hide;
622 $self->{button_resign}->hide; 665 $self->{button_resign}->hide;
634 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); 677 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
635 678
636 $self->{cur_board} = new KGS::Game::Board $self->{size}; 679 $self->{cur_board} = new KGS::Game::Board $self->{size};
637 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); 680 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
638 681
639 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
640 if ($self->{curnode}{move} == 0) {
641 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
642 } else {
643 $self->{whosemove} = 1 - $self->{cur_board}{last};
644 }
645 } else {
646 # Chinese, Aga, NZ all have manual placement
647 if ($self->{curnode}{move} < $self->{handicap}) {
648 $self->{whosemove} = COLOUR_BLACK;
649 } elsif ($self->{curnode}{move} == $self->{handicap}) {
650 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
651 } else {
652 $self->{whosemove} = 1 - $self->{cur_board}{last};
653 }
654 }
655
656 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 682 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
657 for COLOUR_WHITE, COLOUR_BLACK; 683 for COLOUR_WHITE, COLOUR_BLACK;
658 684
659 my $start_time = $self->{rules}{time}; 685 $self->{board}->set_board ($self->{cur_board});
686
687 if ($self->{cur_board}{score}) {
688 $self->{score_inlay} ||= $self->{chat}->new_inlay;
689 $self->{score_inlay}->clear;
690 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
691 . "\n<score>"
692 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
693 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
694 . "</score>");
695 } elsif ($self->{score_inlay}) {
696 (delete $self->{score_inlay})->clear;
697 }
698
699 $self->update_cursor;
660 700
661 if ($self->{showmove} == @{$self->{path}}) { 701 if ($self->{showmove} == @{$self->{path}}) {
662 $self->{timers} = [ 702 $self->{timers} = [
663 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], 703 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}],
664 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], 704 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}],
669 [0, @{$self->{cur_board}{timer}[0]}], 709 [0, @{$self->{cur_board}{timer}[0]}],
670 [0, @{$self->{cur_board}{timer}[1]}], 710 [0, @{$self->{cur_board}{timer}[1]}],
671 ]); 711 ]);
672 } 712 }
673 713
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
688 $self->update_cursor;
689
690} 714}
691 715
692sub event_update_tree { 716sub event_update_tree {
693 my ($self) = @_; 717 my ($self) = @_;
694 718
712 } 736 }
713} 737}
714 738
715sub event_update_comments { 739sub event_update_comments {
716 my ($self, $node, $comment, $newnode) = @_; 740 my ($self, $node, $comment, $newnode) = @_;
717 $self->SUPER::event_update_comments($node, $comment, $newnode); 741 $self->SUPER::event_update_comments ($node, $comment, $newnode);
718 742
719 my $text; 743 my $text;
720 744
721 $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>" 745 $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>"
722 if $newnode; 746 if $newnode;
761 my ($self, $player) = @_; 785 my ($self, $player) = @_;
762 786
763 sound::play 3, "resign"; 787 sound::play 3, "resign";
764 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>" 788 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>"
765 . "\n<user>" 789 . "\n<user>"
766 . (util::toxml $self->{user}[$msg->{player}]->as_string) 790 . (util::toxml $self->{user}[$player]->as_string)
767 . "</user> resigned." 791 . "</user> resigned."
768 . "\n<user>" 792 . "\n<user>"
769 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) 793 . (util::toxml $self->{user}[1 - $player]->as_string)
770 . "</user> wins the game." 794 . "</user> wins the game."
771 . "</infoblock>"); 795 . "</infoblock>");
772} 796}
773 797
774sub event_time_win { 798sub event_time_win {
878 902
879 my ($size, $time, $interval, $count, $type); 903 my ($size, $time, $interval, $count, $type);
880 904
881 if (!$self->{channel}) { 905 if (!$self->{channel}) {
882 $inlay->append_text ("\nNotes: "); 906 $inlay->append_text ("\nNotes: ");
883 $inlay->append_entry (\$info->{notes}, 20, ""); 907 $inlay->append_widget (gtk::textentry \$info->{notes}, 20, "");
884 $inlay->append_text ("\nGlobal Offer: "); 908 $inlay->append_text ("\nGlobal Offer: ");
885 $inlay->append_optionmenu (\$info->{flags}, 909 $inlay->append_optionmenu (\$info->{flags},
886 0 => "No", 910 0 => "No",
887 2 => "Yes", 911 2 => "Yes",
888 ); 912 );
941 if ($self->{channel}) { 965 if ($self->{channel}) {
942 $inlay->append_text ("\nHandicap: "); 966 $inlay->append_text ("\nHandicap: ");
943 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); 967 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9);
944 968
945 $inlay->append_text ("\nKomi: "); 969 $inlay->append_text ("\nKomi: ");
946 $inlay->append_entry (\$info->{rules}{komi}, 5); 970 $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5);
947 } 971 }
948 972
949 $inlay->append_text ("\nTimesys: "); 973 $inlay->append_text ("\nTimesys: ");
950 $inlay->append_optionmenu ( 974 $inlay->append_optionmenu (
951 \$info->{rules}{timesys}, 975 \$info->{rules}{timesys},
980 } 1004 }
981 } 1005 }
982 ); 1006 );
983 1007
984 $inlay->append_text ("\nMain Time: "); 1008 $inlay->append_text ("\nMain Time: ");
985 $time = $inlay->append_entry (\$info->{rules}{time}, 5); 1009 $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5);
986 $inlay->append_text ("\nInterval: "); 1010 $inlay->append_text ("\nInterval: ");
987 $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); 1011 $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5);
988 $inlay->append_text ("\nPeriods/Stones: "); 1012 $inlay->append_text ("\nPeriods/Stones: ");
989 $count = $inlay->append_entry (\$info->{rules}{count}, 2); 1013 $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5);
990 1014
991 $inlay->append_text ("\n"); 1015 $inlay->append_text ("\n");
992 1016
993 if (!$self->{channel}) { 1017 if (!$self->{channel}) {
994 $inlay->append_button ("Create Challenge", sub { 1018 $inlay->append_button ("Create Challenge", sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines