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.126 by root, Wed Jun 2 12:23:35 2004 UTC

218 218
219use POSIX qw(ceil); 219use POSIX qw(ceil);
220 220
221sub new { 221sub new {
222 my ($self, %arg) = @_; 222 my ($self, %arg) = @_;
223
223 $self = $self->Glib::Object::new; 224 $self = $self->Glib::Object::new;
224 $self->{$_} = delete $arg{$_} for keys %arg; 225 $self->{$_} = delete $arg{$_} for keys %arg;
225 226
226 gtk::state $self, "game::window", undef, window_size => [600, 500]; 227 gtk::state $self, "game::window", undef, window_size => [620, 460];
228 $self->set (allow_shrink => 1);
227 229
228 $self->signal_connect (destroy => sub { 230 $self->signal_connect (destroy => sub {
229 $self->unlisten; 231 $self->unlisten;
230 delete $self->{app}{game}{$self->{channel}}; 232 delete $self->{app}{game}{$self->{channel}};
231 %{$_[0]} = (); 233 %{$_[0]} = ();
232 });#d# 234 });#d#
233 235
234 $self->add (my $hpane = new Gtk2::HPaned); 236 $self->add (my $hpane = new Gtk2::HPaned);
235 gtk::state $hpane, "game::hpane", undef, position => 500; 237 gtk::state $hpane, "game::hpane", undef, position => 420;
236 238
237 # LEFT PANE 239 # LEFT PANE
238 240
239 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0); 241 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0);
240 242
275 for COLOUR_WHITE, COLOUR_BLACK; 277 for COLOUR_WHITE, COLOUR_BLACK;
276 278
277 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); 279 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0);
278 280
279 $buttonbox->add ($self->{button_pass} = 281 $buttonbox->add ($self->{button_pass} =
280 Gtk2::Button->Glib::Object::new (label => "Pass", no_show_all => 1, visible => 0)); 282 Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0));
281 $self->{button_pass}->signal_connect (clicked => sub { 283 $self->{button_pass}->signal_connect (clicked => sub {
282 $self->{board_click}->(255, 255) if $self->{board_click}; 284 $self->{board_click}->(255, 255) if $self->{board_click};
283 }); 285 });
286 eval { $self->{button_pass}->set (no_show_all => 1) }; # workaround for gtk+-2.2
284 $buttonbox->add ($self->{button_undo} = 287 $buttonbox->add ($self->{button_undo} =
285 Gtk2::Button->Glib::Object::new (label => "Undo", no_show_all => 1, visible => 0)); 288 Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0));
286 $self->{button_undo}->signal_connect (clicked => sub { 289 $self->{button_undo}->signal_connect (clicked => sub {
287 $self->send (req_undo => channel => $self->{channel}); 290 $self->send (req_undo => channel => $self->{channel});
288 }); 291 });
292 eval { $self->{button_undo}->set (no_show_all => 1) }; # workaround for gtk+-2.2
289 $buttonbox->add ($self->{button_resign} = 293 $buttonbox->add ($self->{button_resign} =
290 Gtk2::Button->Glib::Object::new (label => "Resign", no_show_all => 1, visible => 0)); 294 Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0));
291 $self->{button_resign}->signal_connect (clicked => sub { 295 $self->{button_resign}->signal_connect (clicked => sub {
292 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); 296 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour});
293 }); 297 });
298 eval { $self->{button_resign}->set (no_show_all => 1) }; # workaround for gtk+-2.2
294 299
295 $vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); 300 $vbox->pack_start (($self->{chat} = new chat), 1, 1, 0);
296 301
297 $self->set_channel ($self->{channel}); 302 $self->set_channel ($self->{channel});
298 303
299 $self->show_all; 304 $self->show_all;
300 305
331 return if $self->{joined}; 336 return if $self->{joined};
332 337
333 $self->SUPER::join; 338 $self->SUPER::join;
334} 339}
335 340
341sub part {
342 my ($self) = @_;
343
344 $self->hide;
345 $self->SUPER::part;
346}
347
336sub event_join { 348sub event_join {
337 my ($self) = @_; 349 my ($self) = @_;
338 350
339 $self->SUPER::event_join (@_); 351 $self->SUPER::event_join (@_);
340 $self->init_tree; 352 $self->init_tree;
379 $important{$self->{black}{name}}++; 391 $important{$self->{black}{name}}++;
380 $important{$self->{white}{name}}++; 392 $important{$self->{white}{name}}++;
381 $important{$self->{owner}{name}}++; 393 $important{$self->{owner}{name}}++;
382 394
383 if (my @users = grep $important{$_->{name}}, @$add) { 395 if (my @users = grep $important{$_->{name}}, @$add) {
384 $self->{chat}->append_text ("\n<header>Joins:</header>"); 396 $self->{chat}->append_text ("\n<leader>Joins:</leader>");
385 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 397 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
386 } 398 }
387 if (my @users = grep $important{$_->{name}}, @$remove) { 399 if (my @users = grep $important{$_->{name}}, @$remove) {
388 $self->{chat}->append_text ("\n<header>Parts:</header>"); 400 $self->{chat}->append_text ("\n<leader>Parts:</leader>");
389 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 401 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
390 } 402 }
391} 403}
392 404
393### GAME INFO ############################################################### 405### GAME INFO ###############################################################
554 566
555 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; 567 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active;
556 568
557 delete $self->{board_click}; 569 delete $self->{board_click};
558 570
559 $self->{colour} = COLOUR_BLACK;#d#
560 $self->{whosemove} = COLOUR_BLACK;#d#
561 if ($self->{teacher} eq $self->{app}{conn}) { 571 if ($self->{teacher} eq $self->{app}{conn}) {
562 #TODO# # teaching mode not implemented 572 #TODO# # teaching mode not implemented
563 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 573 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1);
564 $self->{button_undo}->hide; 574 $self->{button_undo}->hide;
565 $self->{button_resign}->hide; 575 $self->{button_resign}->hide;
627sub update_board { 637sub update_board {
628 my ($self) = @_; 638 my ($self) = @_;
629 639
630 return unless $self->{path}; 640 return unless $self->{path};
631 641
642 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
643
644 $self->{cur_board} = new KGS::Game::Board $self->{size};
645 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
646
632 if ($self->{rules}{ruleset} == RULESET_JAPANESE) { 647 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
633 if ($self->{curnode}{move} == 0) { 648 if ($self->{curnode}{move} == 0) {
634 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; 649 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
635 } else { 650 } else {
636 $self->{whosemove} = 1 - $self->{cur_board}{last}; 651 $self->{whosemove} = 1 - $self->{cur_board}{last};
644 } else { 659 } else {
645 $self->{whosemove} = 1 - $self->{cur_board}{last}; 660 $self->{whosemove} = 1 - $self->{cur_board}{last};
646 } 661 }
647 } 662 }
648 663
649 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
650
651 $self->{cur_board} = new KGS::Game::Board $self->{size};
652 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
653
654 $self->update_cursor;
655
656 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 664 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
657 for COLOUR_WHITE, COLOUR_BLACK; 665 for COLOUR_WHITE, COLOUR_BLACK;
658 666
659 my $start_time = $self->{rules}{time}; 667 my $start_time = $self->{rules}{time};
660 668
682 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]" 690 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
683 . "</score>"); 691 . "</score>");
684 } elsif ($self->{score_inlay}) { 692 } elsif ($self->{score_inlay}) {
685 (delete $self->{score_inlay})->clear; 693 (delete $self->{score_inlay})->clear;
686 } 694 }
695
696 $self->update_cursor;
697
687} 698}
688 699
689sub event_update_tree { 700sub event_update_tree {
690 my ($self) = @_; 701 my ($self) = @_;
691 702
783} 794}
784 795
785sub event_owner_left { 796sub event_owner_left {
786 my ($self) = @_; 797 my ($self) = @_;
787 798
788 sound::play 2, "info";
789 $self->{chat}->append_text ("\n<infoblock><header>Owner left</header>" 799 $self->{chat}->append_text ("\n<infoblock><header>Owner left</header>"
790 . "\nThe owner of this game left.</infoblock>"); 800 . "\nThe owner of this game left.</infoblock>");
791} 801}
792 802
793sub event_teacher_left { 803sub event_teacher_left {
794 my ($self) = @_; 804 my ($self) = @_;
795 805
796 sound::play 2, "info";
797 $self->{chat}->append_text ("\n<infoblock><header>Teacher left</header>" 806 $self->{chat}->append_text ("\n<infoblock><header>Teacher left</header>"
798 . "\nThe teacher left the game.</infoblock>"); 807 . "\nThe teacher left the game.</infoblock>");
799} 808}
800 809
801sub event_done { 810sub event_done {
877 886
878 my ($size, $time, $interval, $count, $type); 887 my ($size, $time, $interval, $count, $type);
879 888
880 if (!$self->{channel}) { 889 if (!$self->{channel}) {
881 $inlay->append_text ("\nNotes: "); 890 $inlay->append_text ("\nNotes: ");
882 $inlay->append_entry (\$info->{notes}, 20, ""); 891 $inlay->append_widget (gtk::textentry \$info->{notes}, 20, "");
883 $inlay->append_text ("\nGlobal Offer: "); 892 $inlay->append_text ("\nGlobal Offer: ");
884 $inlay->append_optionmenu (\$info->{flags}, 893 $inlay->append_optionmenu (\$info->{flags},
885 0 => "No", 894 0 => "No",
886 2 => "Yes", 895 2 => "Yes",
887 ); 896 );
940 if ($self->{channel}) { 949 if ($self->{channel}) {
941 $inlay->append_text ("\nHandicap: "); 950 $inlay->append_text ("\nHandicap: ");
942 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); 951 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9);
943 952
944 $inlay->append_text ("\nKomi: "); 953 $inlay->append_text ("\nKomi: ");
945 $inlay->append_entry (\$info->{rules}{komi}, 5); 954 $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5);
946 } 955 }
947 956
948 $inlay->append_text ("\nTimesys: "); 957 $inlay->append_text ("\nTimesys: ");
949 $inlay->append_optionmenu ( 958 $inlay->append_optionmenu (
950 \$info->{rules}{timesys}, 959 \$info->{rules}{timesys},
979 } 988 }
980 } 989 }
981 ); 990 );
982 991
983 $inlay->append_text ("\nMain Time: "); 992 $inlay->append_text ("\nMain Time: ");
984 $time = $inlay->append_entry (\$info->{rules}{time}, 5); 993 $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5);
985 $inlay->append_text ("\nInterval: "); 994 $inlay->append_text ("\nInterval: ");
986 $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); 995 $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5);
987 $inlay->append_text ("\nPeriods/Stones: "); 996 $inlay->append_text ("\nPeriods/Stones: ");
988 $count = $inlay->append_entry (\$info->{rules}{count}, 2); 997 $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5);
989 998
990 $inlay->append_text ("\n"); 999 $inlay->append_text ("\n");
991 1000
992 if (!$self->{channel}) { 1001 if (!$self->{channel}) {
993 $inlay->append_button ("Create Challenge", sub { 1002 $inlay->append_button ("Create Challenge", sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines