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.118 by root, Tue Jun 1 22:47:47 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 }
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
293 $self->{button_resign}->signal_connect (clicked => sub { 309 $self->{button_resign}->signal_connect (clicked => sub {
294 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); 310 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour});
295 }); 311 });
296 eval { $self->{button_resign}->set (no_show_all => 1) }; # workaround for gtk+-2.2 312 eval { $self->{button_resign}->set (no_show_all => 1) }; # workaround for gtk+-2.2
297 313
298 $vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); 314 $vbox->pack_start (($self->{chat} = new chat), 1, 1, 0);
299 315
300 $self->set_channel ($self->{channel}); 316 $self->set_channel ($self->{channel});
301 317
302 $self->show_all; 318 $self->show_all;
303 319
334 return if $self->{joined}; 350 return if $self->{joined};
335 351
336 $self->SUPER::join; 352 $self->SUPER::join;
337} 353}
338 354
355sub part {
356 my ($self) = @_;
357
358 $self->hide;
359 $self->SUPER::part;
360}
361
339sub event_join { 362sub event_join {
340 my ($self) = @_; 363 my ($self) = @_;
341 364
342 $self->SUPER::event_join (@_); 365 $self->SUPER::event_join (@_);
343 $self->init_tree; 366 $self->init_tree;
382 $important{$self->{black}{name}}++; 405 $important{$self->{black}{name}}++;
383 $important{$self->{white}{name}}++; 406 $important{$self->{white}{name}}++;
384 $important{$self->{owner}{name}}++; 407 $important{$self->{owner}{name}}++;
385 408
386 if (my @users = grep $important{$_->{name}}, @$add) { 409 if (my @users = grep $important{$_->{name}}, @$add) {
387 $self->{chat}->append_text ("\n<header>Joins:</header>"); 410 $self->{chat}->append_text ("\n<leader>Joins:</leader>");
388 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 411 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
389 } 412 }
390 if (my @users = grep $important{$_->{name}}, @$remove) { 413 if (my @users = grep $important{$_->{name}}, @$remove) {
391 $self->{chat}->append_text ("\n<header>Parts:</header>"); 414 $self->{chat}->append_text ("\n<leader>Parts:</leader>");
392 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 415 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
393 } 416 }
394} 417}
395 418
396### GAME INFO ############################################################### 419### GAME INFO ###############################################################
553sub update_cursor { 576sub update_cursor {
554 my ($self) = @_; 577 my ($self) = @_;
555 578
556 return unless $self->{cur_board}; 579 return unless $self->{cur_board};
557 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
558 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; 598 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active;
559 599
560 delete $self->{board_click}; 600 delete $self->{board_click};
561 601
562 if ($self->{teacher} eq $self->{app}{conn}) { 602 if ($self->{teacher} eq $self->{app}{conn}) {
563 #TODO# # teaching mode not implemented 603 #TODO# # teaching mode not implemented
564 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 604 $self->{button_pass}->set (label => "Pass", sensitive => 1);
605 $self->{button_pass}->show;
565 $self->{button_undo}->hide; 606 $self->{button_undo}->hide;
566 $self->{button_resign}->hide; 607 $self->{button_resign}->hide;
567 $self->{board}->set (cursor => undef); 608 $self->{board}->set (cursor => undef);
568 609
569 } elsif ($running && $self->{colour} != COLOUR_NONE) { 610 } elsif ($running && $self->{colour} != COLOUR_NONE) {
571 $self->{button_undo}->show; 612 $self->{button_undo}->show;
572 $self->{button_resign}->show; 613 $self->{button_resign}->show;
573 614
574 if ($self->{cur_board}{score}) { 615 if ($self->{cur_board}{score}) {
575 # during scoring 616 # during scoring
576 $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); 617 $self->{button_pass}->set (label => "Done", sensitive => 1);
618 $self->{button_pass}->show;
577 $self->{board}->set (cursor => sub { 619 $self->{board}->set (cursor => sub {
578 $_[0] & (MARK_B | MARK_W) 620 $_[0] & (MARK_B | MARK_W)
579 ? $_[0] ^ MARK_GRAYED 621 ? $_[0] ^ MARK_GRAYED
580 : $_[0]; 622 : $_[0];
581 }); 623 });
593 } 635 }
594 }; 636 };
595 637
596 } elsif ($self->{colour} == $self->{whosemove}) { 638 } elsif ($self->{colour} == $self->{whosemove}) {
597 # normal move 639 # normal move
598 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 640 $self->{button_pass}->set (label => "Pass", sensitive => 1);
641 $self->{button_pass}->show;
599 $self->{board}->set (cursor => sub { 642 $self->{board}->set (cursor => sub {
600 $self->{cur_board} 643 $self->{cur_board}
601 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 644 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2],
602 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND) 645 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND)
603 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B) 646 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B)
604 : $_[0]; 647 : $_[0];
605 }); 648 });
606 $self->{board_click} = sub { 649 $self->{board_click} = sub {
607 return unless 650 return unless
608 $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 651 $self->{cur_board}->is_valid_move ($self->{colour}, $_[0], $_[1],
609 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND); 652 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND);
610 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); 653 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]);
611 $self->{board}->set (cursor => undef); 654 $self->{board}->set (cursor => undef);
612 delete $self->{board_click}; 655 delete $self->{board_click};
613 $self->{button_pass}->sensitive (0); 656 $self->{button_pass}->sensitive (0);
614 }; 657 };
615 } else { 658 } else {
616 $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); 659 $self->{button_pass}->set (label => "Pass", sensitive => 0);
660 $self->{button_pass}->show;
617 $self->{board}->set (cursor => undef); 661 $self->{board}->set (cursor => undef);
618 } 662 }
619 } else { 663 } else {
620 $self->{button_undo}->hide; 664 $self->{button_undo}->hide;
621 $self->{button_resign}->hide; 665 $self->{button_resign}->hide;
628sub update_board { 672sub update_board {
629 my ($self) = @_; 673 my ($self) = @_;
630 674
631 return unless $self->{path}; 675 return unless $self->{path};
632 676
633 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
634 if ($self->{curnode}{move} == 0) {
635 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
636 } else {
637 $self->{whosemove} = 1 - $self->{cur_board}{last};
638 }
639 } else {
640 # Chinese, Aga, NZ all have manual placement
641 if ($self->{curnode}{move} < $self->{handicap}) {
642 $self->{whosemove} = COLOUR_BLACK;
643 } elsif ($self->{curnode}{move} == $self->{handicap}) {
644 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
645 } else {
646 $self->{whosemove} = 1 - $self->{cur_board}{last};
647 }
648 }
649
650 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); 677 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
651 678
652 $self->{cur_board} = new KGS::Game::Board $self->{size}; 679 $self->{cur_board} = new KGS::Game::Board $self->{size};
653 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); 680 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
654 681
655 $self->update_cursor;
656
657 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 682 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
658 for COLOUR_WHITE, COLOUR_BLACK; 683 for COLOUR_WHITE, COLOUR_BLACK;
659 684
660 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;
661 700
662 if ($self->{showmove} == @{$self->{path}}) { 701 if ($self->{showmove} == @{$self->{path}}) {
663 $self->{timers} = [ 702 $self->{timers} = [
664 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], 703 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}],
665 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], 704 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}],
670 [0, @{$self->{cur_board}{timer}[0]}], 709 [0, @{$self->{cur_board}{timer}[0]}],
671 [0, @{$self->{cur_board}{timer}[1]}], 710 [0, @{$self->{cur_board}{timer}[1]}],
672 ]); 711 ]);
673 } 712 }
674 713
675 $self->{board}->set_board ($self->{cur_board});
676
677 if ($self->{cur_board}{score}) {
678 $self->{score_inlay} ||= $self->{chat}->new_inlay;
679 $self->{score_inlay}->clear;
680 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
681 . "\n<score>"
682 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
683 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
684 . "</score>");
685 } elsif ($self->{score_inlay}) {
686 (delete $self->{score_inlay})->clear;
687 }
688} 714}
689 715
690sub event_update_tree { 716sub event_update_tree {
691 my ($self) = @_; 717 my ($self) = @_;
692 718
710 } 736 }
711} 737}
712 738
713sub event_update_comments { 739sub event_update_comments {
714 my ($self, $node, $comment, $newnode) = @_; 740 my ($self, $node, $comment, $newnode) = @_;
715 $self->SUPER::event_update_comments($node, $comment, $newnode); 741 $self->SUPER::event_update_comments ($node, $comment, $newnode);
716 742
717 my $text; 743 my $text;
718 744
719 $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>"
720 if $newnode; 746 if $newnode;
759 my ($self, $player) = @_; 785 my ($self, $player) = @_;
760 786
761 sound::play 3, "resign"; 787 sound::play 3, "resign";
762 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>" 788 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>"
763 . "\n<user>" 789 . "\n<user>"
764 . (util::toxml $self->{user}[$msg->{player}]->as_string) 790 . (util::toxml $self->{user}[$player]->as_string)
765 . "</user> resigned." 791 . "</user> resigned."
766 . "\n<user>" 792 . "\n<user>"
767 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) 793 . (util::toxml $self->{user}[1 - $player]->as_string)
768 . "</user> wins the game." 794 . "</user> wins the game."
769 . "</infoblock>"); 795 . "</infoblock>");
770} 796}
771 797
772sub event_time_win { 798sub event_time_win {
876 902
877 my ($size, $time, $interval, $count, $type); 903 my ($size, $time, $interval, $count, $type);
878 904
879 if (!$self->{channel}) { 905 if (!$self->{channel}) {
880 $inlay->append_text ("\nNotes: "); 906 $inlay->append_text ("\nNotes: ");
881 $inlay->append_entry (\$info->{notes}, 20, ""); 907 $inlay->append_widget (gtk::textentry \$info->{notes}, 20, "");
882 $inlay->append_text ("\nGlobal Offer: "); 908 $inlay->append_text ("\nGlobal Offer: ");
883 $inlay->append_optionmenu (\$info->{flags}, 909 $inlay->append_optionmenu (\$info->{flags},
884 0 => "No", 910 0 => "No",
885 2 => "Yes", 911 2 => "Yes",
886 ); 912 );
939 if ($self->{channel}) { 965 if ($self->{channel}) {
940 $inlay->append_text ("\nHandicap: "); 966 $inlay->append_text ("\nHandicap: ");
941 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); 967 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9);
942 968
943 $inlay->append_text ("\nKomi: "); 969 $inlay->append_text ("\nKomi: ");
944 $inlay->append_entry (\$info->{rules}{komi}, 5); 970 $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5);
945 } 971 }
946 972
947 $inlay->append_text ("\nTimesys: "); 973 $inlay->append_text ("\nTimesys: ");
948 $inlay->append_optionmenu ( 974 $inlay->append_optionmenu (
949 \$info->{rules}{timesys}, 975 \$info->{rules}{timesys},
978 } 1004 }
979 } 1005 }
980 ); 1006 );
981 1007
982 $inlay->append_text ("\nMain Time: "); 1008 $inlay->append_text ("\nMain Time: ");
983 $time = $inlay->append_entry (\$info->{rules}{time}, 5); 1009 $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5);
984 $inlay->append_text ("\nInterval: "); 1010 $inlay->append_text ("\nInterval: ");
985 $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); 1011 $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5);
986 $inlay->append_text ("\nPeriods/Stones: "); 1012 $inlay->append_text ("\nPeriods/Stones: ");
987 $count = $inlay->append_entry (\$info->{rules}{count}, 2); 1013 $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5);
988 1014
989 $inlay->append_text ("\n"); 1015 $inlay->append_text ("\n");
990 1016
991 if (!$self->{channel}) { 1017 if (!$self->{channel}) {
992 $inlay->append_button ("Create Challenge", sub { 1018 $inlay->append_button ("Create Challenge", sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines