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.116 by root, Tue Jun 1 13:34:40 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 ###############################################################
625sub update_board { 637sub update_board {
626 my ($self) = @_; 638 my ($self) = @_;
627 639
628 return unless $self->{path}; 640 return unless $self->{path};
629 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
630 if ($self->{rules}{ruleset} == RULESET_JAPANESE) { 647 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
631 if ($self->{curnode}{move} == 0) { 648 if ($self->{curnode}{move} == 0) {
632 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; 649 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
633 } else { 650 } else {
634 $self->{whosemove} = 1 - $self->{cur_board}{last}; 651 $self->{whosemove} = 1 - $self->{cur_board}{last};
642 } else { 659 } else {
643 $self->{whosemove} = 1 - $self->{cur_board}{last}; 660 $self->{whosemove} = 1 - $self->{cur_board}{last};
644 } 661 }
645 } 662 }
646 663
647 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
648
649 $self->{cur_board} = new KGS::Game::Board $self->{size};
650 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
651
652 $self->update_cursor;
653
654 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 664 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
655 for COLOUR_WHITE, COLOUR_BLACK; 665 for COLOUR_WHITE, COLOUR_BLACK;
656 666
657 my $start_time = $self->{rules}{time}; 667 my $start_time = $self->{rules}{time};
658 668
680 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]" 690 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
681 . "</score>"); 691 . "</score>");
682 } elsif ($self->{score_inlay}) { 692 } elsif ($self->{score_inlay}) {
683 (delete $self->{score_inlay})->clear; 693 (delete $self->{score_inlay})->clear;
684 } 694 }
695
696 $self->update_cursor;
697
685} 698}
686 699
687sub event_update_tree { 700sub event_update_tree {
688 my ($self) = @_; 701 my ($self) = @_;
689 702
781} 794}
782 795
783sub event_owner_left { 796sub event_owner_left {
784 my ($self) = @_; 797 my ($self) = @_;
785 798
786 sound::play 2, "info";
787 $self->{chat}->append_text ("\n<infoblock><header>Owner left</header>" 799 $self->{chat}->append_text ("\n<infoblock><header>Owner left</header>"
788 . "\nThe owner of this game left.</infoblock>"); 800 . "\nThe owner of this game left.</infoblock>");
789} 801}
790 802
791sub event_teacher_left { 803sub event_teacher_left {
792 my ($self) = @_; 804 my ($self) = @_;
793 805
794 sound::play 2, "info";
795 $self->{chat}->append_text ("\n<infoblock><header>Teacher left</header>" 806 $self->{chat}->append_text ("\n<infoblock><header>Teacher left</header>"
796 . "\nThe teacher left the game.</infoblock>"); 807 . "\nThe teacher left the game.</infoblock>");
797} 808}
798 809
799sub event_done { 810sub event_done {
875 886
876 my ($size, $time, $interval, $count, $type); 887 my ($size, $time, $interval, $count, $type);
877 888
878 if (!$self->{channel}) { 889 if (!$self->{channel}) {
879 $inlay->append_text ("\nNotes: "); 890 $inlay->append_text ("\nNotes: ");
880 $inlay->append_entry (\$info->{notes}, 20, ""); 891 $inlay->append_widget (gtk::textentry \$info->{notes}, 20, "");
881 $inlay->append_text ("\nGlobal Offer: "); 892 $inlay->append_text ("\nGlobal Offer: ");
882 $inlay->append_optionmenu (\$info->{flags}, 893 $inlay->append_optionmenu (\$info->{flags},
883 0 => "No", 894 0 => "No",
884 2 => "Yes", 895 2 => "Yes",
885 ); 896 );
938 if ($self->{channel}) { 949 if ($self->{channel}) {
939 $inlay->append_text ("\nHandicap: "); 950 $inlay->append_text ("\nHandicap: ");
940 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); 951 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9);
941 952
942 $inlay->append_text ("\nKomi: "); 953 $inlay->append_text ("\nKomi: ");
943 $inlay->append_entry (\$info->{rules}{komi}, 5); 954 $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5);
944 } 955 }
945 956
946 $inlay->append_text ("\nTimesys: "); 957 $inlay->append_text ("\nTimesys: ");
947 $inlay->append_optionmenu ( 958 $inlay->append_optionmenu (
948 \$info->{rules}{timesys}, 959 \$info->{rules}{timesys},
977 } 988 }
978 } 989 }
979 ); 990 );
980 991
981 $inlay->append_text ("\nMain Time: "); 992 $inlay->append_text ("\nMain Time: ");
982 $time = $inlay->append_entry (\$info->{rules}{time}, 5); 993 $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5);
983 $inlay->append_text ("\nInterval: "); 994 $inlay->append_text ("\nInterval: ");
984 $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); 995 $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5);
985 $inlay->append_text ("\nPeriods/Stones: "); 996 $inlay->append_text ("\nPeriods/Stones: ");
986 $count = $inlay->append_entry (\$info->{rules}{count}, 2); 997 $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5);
987 998
988 $inlay->append_text ("\n"); 999 $inlay->append_text ("\n");
989 1000
990 if (!$self->{channel}) { 1001 if (!$self->{channel}) {
991 $inlay->append_button ("Create Challenge", sub { 1002 $inlay->append_button ("Create Challenge", sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines