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.117 by root, Tue Jun 1 21:24:11 2004 UTC vs.
Revision 1.128 by root, Thu Jun 3 04:21:10 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;
162}
163
164sub SET_PROPERTY {
165 my ($self, $pspec, $value) = @_;
166
167 $self->{$pspec->get_name} = $value;
168
169 $self->set_name ("userpanel-$self->{colour}");
160} 170}
161 171
162sub configure { 172sub configure {
163 my ($self, $app, $user, $rules) = @_; 173 my ($self, $app, $user, $rules) = @_;
164 174
218 228
219use POSIX qw(ceil); 229use POSIX qw(ceil);
220 230
221sub new { 231sub new {
222 my ($self, %arg) = @_; 232 my ($self, %arg) = @_;
233
223 $self = $self->Glib::Object::new; 234 $self = $self->Glib::Object::new;
224 $self->{$_} = delete $arg{$_} for keys %arg; 235 $self->{$_} = delete $arg{$_} for keys %arg;
225 236
226 gtk::state $self, "game::window", undef, window_size => [600, 500]; 237 gtk::state $self, "game::window", undef, window_size => [620, 460];
238 $self->set (allow_shrink => 1);
227 239
228 $self->signal_connect (destroy => sub { 240 $self->signal_connect (destroy => sub {
229 $self->unlisten; 241 $self->unlisten;
230 delete $self->{app}{game}{$self->{channel}}; 242 delete $self->{app}{game}{$self->{channel}};
231 %{$_[0]} = (); 243 %{$_[0]} = ();
232 });#d# 244 });#d#
233 245
234 $self->add (my $hpane = new Gtk2::HPaned); 246 $self->add (my $hpane = new Gtk2::HPaned);
235 gtk::state $hpane, "game::hpane", undef, position => 500; 247 gtk::state $hpane, "game::hpane", undef, position => 420;
236 248
237 # LEFT PANE 249 # LEFT PANE
238 250
239 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0); 251 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0);
240 252
275 for COLOUR_WHITE, COLOUR_BLACK; 287 for COLOUR_WHITE, COLOUR_BLACK;
276 288
277 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); 289 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0);
278 290
279 $buttonbox->add ($self->{button_pass} = 291 $buttonbox->add ($self->{button_pass} =
280 Gtk2::Button->Glib::Object::new (label => "Pass", no_show_all => 1, visible => 0)); 292 Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0));
281 $self->{button_pass}->signal_connect (clicked => sub { 293 $self->{button_pass}->signal_connect (clicked => sub {
282 $self->{board_click}->(255, 255) if $self->{board_click}; 294 $self->{board_click}->(255, 255) if $self->{board_click};
283 }); 295 });
296 eval { $self->{button_pass}->set (no_show_all => 1) }; # workaround for gtk+-2.2
284 $buttonbox->add ($self->{button_undo} = 297 $buttonbox->add ($self->{button_undo} =
285 Gtk2::Button->Glib::Object::new (label => "Undo", no_show_all => 1, visible => 0)); 298 Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0));
286 $self->{button_undo}->signal_connect (clicked => sub { 299 $self->{button_undo}->signal_connect (clicked => sub {
287 $self->send (req_undo => channel => $self->{channel}); 300 $self->send (req_undo => channel => $self->{channel});
288 }); 301 });
302 eval { $self->{button_undo}->set (no_show_all => 1) }; # workaround for gtk+-2.2
289 $buttonbox->add ($self->{button_resign} = 303 $buttonbox->add ($self->{button_resign} =
290 Gtk2::Button->Glib::Object::new (label => "Resign", no_show_all => 1, visible => 0)); 304 Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0));
291 $self->{button_resign}->signal_connect (clicked => sub { 305 $self->{button_resign}->signal_connect (clicked => sub {
292 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); 306 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour});
293 }); 307 });
308 eval { $self->{button_resign}->set (no_show_all => 1) }; # workaround for gtk+-2.2
294 309
295 $vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); 310 $vbox->pack_start (($self->{chat} = new chat), 1, 1, 0);
296 311
297 $self->set_channel ($self->{channel}); 312 $self->set_channel ($self->{channel});
298 313
299 $self->show_all; 314 $self->show_all;
300 315
331 return if $self->{joined}; 346 return if $self->{joined};
332 347
333 $self->SUPER::join; 348 $self->SUPER::join;
334} 349}
335 350
351sub part {
352 my ($self) = @_;
353
354 $self->hide;
355 $self->SUPER::part;
356}
357
336sub event_join { 358sub event_join {
337 my ($self) = @_; 359 my ($self) = @_;
338 360
339 $self->SUPER::event_join (@_); 361 $self->SUPER::event_join (@_);
340 $self->init_tree; 362 $self->init_tree;
379 $important{$self->{black}{name}}++; 401 $important{$self->{black}{name}}++;
380 $important{$self->{white}{name}}++; 402 $important{$self->{white}{name}}++;
381 $important{$self->{owner}{name}}++; 403 $important{$self->{owner}{name}}++;
382 404
383 if (my @users = grep $important{$_->{name}}, @$add) { 405 if (my @users = grep $important{$_->{name}}, @$add) {
384 $self->{chat}->append_text ("\n<header>Joins:</header>"); 406 $self->{chat}->append_text ("\n<leader>Joins:</leader>");
385 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 407 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
386 } 408 }
387 if (my @users = grep $important{$_->{name}}, @$remove) { 409 if (my @users = grep $important{$_->{name}}, @$remove) {
388 $self->{chat}->append_text ("\n<header>Parts:</header>"); 410 $self->{chat}->append_text ("\n<leader>Parts:</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} 413}
392 414
393### GAME INFO ############################################################### 415### GAME INFO ###############################################################
556 578
557 delete $self->{board_click}; 579 delete $self->{board_click};
558 580
559 if ($self->{teacher} eq $self->{app}{conn}) { 581 if ($self->{teacher} eq $self->{app}{conn}) {
560 #TODO# # teaching mode not implemented 582 #TODO# # teaching mode not implemented
561 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 583 $self->{button_pass}->set (label => "Pass", sensitive => 1);
584 $self->{button_pass}->show;
562 $self->{button_undo}->hide; 585 $self->{button_undo}->hide;
563 $self->{button_resign}->hide; 586 $self->{button_resign}->hide;
564 $self->{board}->set (cursor => undef); 587 $self->{board}->set (cursor => undef);
565 588
566 } elsif ($running && $self->{colour} != COLOUR_NONE) { 589 } elsif ($running && $self->{colour} != COLOUR_NONE) {
568 $self->{button_undo}->show; 591 $self->{button_undo}->show;
569 $self->{button_resign}->show; 592 $self->{button_resign}->show;
570 593
571 if ($self->{cur_board}{score}) { 594 if ($self->{cur_board}{score}) {
572 # during scoring 595 # during scoring
573 $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); 596 $self->{button_pass}->set (label => "Done", sensitive => 1);
597 $self->{button_pass}->show;
574 $self->{board}->set (cursor => sub { 598 $self->{board}->set (cursor => sub {
575 $_[0] & (MARK_B | MARK_W) 599 $_[0] & (MARK_B | MARK_W)
576 ? $_[0] ^ MARK_GRAYED 600 ? $_[0] ^ MARK_GRAYED
577 : $_[0]; 601 : $_[0];
578 }); 602 });
590 } 614 }
591 }; 615 };
592 616
593 } elsif ($self->{colour} == $self->{whosemove}) { 617 } elsif ($self->{colour} == $self->{whosemove}) {
594 # normal move 618 # normal move
595 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 619 $self->{button_pass}->set (label => "Pass", sensitive => 1);
620 $self->{button_pass}->show;
596 $self->{board}->set (cursor => sub { 621 $self->{board}->set (cursor => sub {
597 $self->{cur_board} 622 $self->{cur_board}
598 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 623 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2],
599 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND) 624 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND)
600 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B) 625 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B)
608 $self->{board}->set (cursor => undef); 633 $self->{board}->set (cursor => undef);
609 delete $self->{board_click}; 634 delete $self->{board_click};
610 $self->{button_pass}->sensitive (0); 635 $self->{button_pass}->sensitive (0);
611 }; 636 };
612 } else { 637 } else {
613 $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); 638 $self->{button_pass}->set (label => "Pass", sensitive => 0);
639 $self->{button_pass}->show;
614 $self->{board}->set (cursor => undef); 640 $self->{board}->set (cursor => undef);
615 } 641 }
616 } else { 642 } else {
617 $self->{button_undo}->hide; 643 $self->{button_undo}->hide;
618 $self->{button_resign}->hide; 644 $self->{button_resign}->hide;
624 650
625sub update_board { 651sub update_board {
626 my ($self) = @_; 652 my ($self) = @_;
627 653
628 return unless $self->{path}; 654 return unless $self->{path};
655
656 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
657
658 $self->{cur_board} = new KGS::Game::Board $self->{size};
659 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
629 660
630 if ($self->{rules}{ruleset} == RULESET_JAPANESE) { 661 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
631 if ($self->{curnode}{move} == 0) { 662 if ($self->{curnode}{move} == 0) {
632 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; 663 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
633 } else { 664 } else {
642 } else { 673 } else {
643 $self->{whosemove} = 1 - $self->{cur_board}{last}; 674 $self->{whosemove} = 1 - $self->{cur_board}{last};
644 } 675 }
645 } 676 }
646 677
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}[$_]) 678 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
655 for COLOUR_WHITE, COLOUR_BLACK; 679 for COLOUR_WHITE, COLOUR_BLACK;
656 680
657 my $start_time = $self->{rules}{time}; 681 my $start_time = $self->{rules}{time};
658 682
680 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]" 704 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
681 . "</score>"); 705 . "</score>");
682 } elsif ($self->{score_inlay}) { 706 } elsif ($self->{score_inlay}) {
683 (delete $self->{score_inlay})->clear; 707 (delete $self->{score_inlay})->clear;
684 } 708 }
709
710 $self->update_cursor;
711
685} 712}
686 713
687sub event_update_tree { 714sub event_update_tree {
688 my ($self) = @_; 715 my ($self) = @_;
689 716
873 900
874 my ($size, $time, $interval, $count, $type); 901 my ($size, $time, $interval, $count, $type);
875 902
876 if (!$self->{channel}) { 903 if (!$self->{channel}) {
877 $inlay->append_text ("\nNotes: "); 904 $inlay->append_text ("\nNotes: ");
878 $inlay->append_entry (\$info->{notes}, 20, ""); 905 $inlay->append_widget (gtk::textentry \$info->{notes}, 20, "");
879 $inlay->append_text ("\nGlobal Offer: "); 906 $inlay->append_text ("\nGlobal Offer: ");
880 $inlay->append_optionmenu (\$info->{flags}, 907 $inlay->append_optionmenu (\$info->{flags},
881 0 => "No", 908 0 => "No",
882 2 => "Yes", 909 2 => "Yes",
883 ); 910 );
936 if ($self->{channel}) { 963 if ($self->{channel}) {
937 $inlay->append_text ("\nHandicap: "); 964 $inlay->append_text ("\nHandicap: ");
938 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); 965 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9);
939 966
940 $inlay->append_text ("\nKomi: "); 967 $inlay->append_text ("\nKomi: ");
941 $inlay->append_entry (\$info->{rules}{komi}, 5); 968 $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5);
942 } 969 }
943 970
944 $inlay->append_text ("\nTimesys: "); 971 $inlay->append_text ("\nTimesys: ");
945 $inlay->append_optionmenu ( 972 $inlay->append_optionmenu (
946 \$info->{rules}{timesys}, 973 \$info->{rules}{timesys},
975 } 1002 }
976 } 1003 }
977 ); 1004 );
978 1005
979 $inlay->append_text ("\nMain Time: "); 1006 $inlay->append_text ("\nMain Time: ");
980 $time = $inlay->append_entry (\$info->{rules}{time}, 5); 1007 $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5);
981 $inlay->append_text ("\nInterval: "); 1008 $inlay->append_text ("\nInterval: ");
982 $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); 1009 $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5);
983 $inlay->append_text ("\nPeriods/Stones: "); 1010 $inlay->append_text ("\nPeriods/Stones: ");
984 $count = $inlay->append_entry (\$info->{rules}{count}, 2); 1011 $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5);
985 1012
986 $inlay->append_text ("\n"); 1013 $inlay->append_text ("\n");
987 1014
988 if (!$self->{channel}) { 1015 if (!$self->{channel}) {
989 $inlay->append_button ("Create Challenge", sub { 1016 $inlay->append_button ("Create Challenge", sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines