--- kgsueme/kgsueme/game.pl 2004/06/02 12:23:35 1.126 +++ kgsueme/kgsueme/game.pl 2004/10/13 00:33:15 1.140 @@ -148,7 +148,9 @@ sub INIT_INSTANCE { my ($self) = @_; - $self->add (my $vbox = new Gtk2::VBox); + $self->add ($self->{window} = my $window = new Gtk2::EventBox); # for bg + + $window->add (my $vbox = new Gtk2::VBox); $vbox->pack_start (($self->{name} = new Gtk2::Label "-"), 1, 1, 0); $vbox->pack_start (($self->{info} = new Gtk2::Label "-"), 1, 1, 0); @@ -159,6 +161,14 @@ $self; } +sub SET_PROPERTY { + my ($self, $pspec, $value) = @_; + + $self->{$pspec->get_name} = $value; + + $self->set_name ("userpanel-$self->{colour}"); +} + sub configure { my ($self, $app, $user, $rules) = @_; @@ -166,7 +176,9 @@ $self->{name}->set_text ($user->as_string); $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; - $self->{imagebox}->add (gtk::image_from_data undef); + unless ($::config{suppress_userpic}) { + $self->{imagebox}->add (gtk::image_from_data undef); + } $self->{imagebox}->show_all; if ($user->has_pic) { @@ -176,7 +188,9 @@ if ($_[0]) { $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; - $self->{imagebox}->add (gtk::image_from_data $_[0]); + unless ($::config{suppress_userpic}) { + $self->{imagebox}->add (gtk::image_from_data $_[0]); + } $self->{imagebox}->show_all; } }); @@ -254,6 +268,7 @@ { $frame->add (my $vbox = new Gtk2::VBox); $vbox->add ($self->{title} = new Gtk2::Label "-"); + $self->{title}->set (visible => 0, no_show_all => 1); # workaround for refresh-bug $vbox->add (my $hbox = new Gtk2::HBox); @@ -279,25 +294,26 @@ $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); $buttonbox->add ($self->{button_pass} = - Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0)); + Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0, no_show_all => 1)); $self->{button_pass}->signal_connect (clicked => sub { $self->{board_click}->(255, 255) if $self->{board_click}; }); - eval { $self->{button_pass}->set (no_show_all => 1) }; # workaround for gtk+-2.2 $buttonbox->add ($self->{button_undo} = - Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0)); + Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0, no_show_all => 1)); $self->{button_undo}->signal_connect (clicked => sub { $self->send (req_undo => channel => $self->{channel}); }); - eval { $self->{button_undo}->set (no_show_all => 1) }; # workaround for gtk+-2.2 $buttonbox->add ($self->{button_resign} = - Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0)); + Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0, no_show_all => 1)); $self->{button_resign}->signal_connect (clicked => sub { $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); }); - eval { $self->{button_resign}->set (no_show_all => 1) }; # workaround for gtk+-2.2 - $vbox->pack_start (($self->{chat} = new chat), 1, 1, 0); + $vbox->pack_start (($self->{chat} = new chat app => $self->{app}), 1, 1, 0); + + $self->{chat}->signal_connect (tag_event => sub { + my (undef, $tag, $event, $content) = @_; + }); $self->set_channel ($self->{channel}); @@ -311,7 +327,7 @@ $self->{channel} = $channel; - if ($self->{channel} > 0) { + if (defined $self->{channel}) { $self->listen ($self->{conn}); $self->{rules_inlay} = $self->{chat}->new_switchable_inlay ("Game Setup:", sub { $self->draw_setup (@_) }, 1); @@ -321,7 +337,9 @@ $self->{chat}->signal_connect (command => sub { my ($chat, $cmd, $arg) = @_; if ($cmd eq "rsave") { - Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d# + local $Storable::forgive_me = 1; + #Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d# + Storable::nstore { %$self }, $arg;#d# } else { $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self); } @@ -373,7 +391,7 @@ my ($self, $inlay) = @_; for (sort keys %{$self->{users}}) { - $inlay->append_text (" " . $self->{users}{$_}->as_string . ""); + $inlay->append_text ("\t" . $self->{users}{$_}->as_string . ""); } } @@ -498,6 +516,7 @@ : "Game Window"; $self->set_title ("KGS Game $title"); $self->{title}->set_text ($title); # title gets redrawn wrongly + $self->{title}->show; # workaround for refresh-bug $self->{rules_inlay}->refresh; @@ -564,13 +583,31 @@ return unless $self->{cur_board}; + if ($self->{rules}{ruleset} == RULESET_JAPANESE) { + if ($self->{curnode}{move} == 0) { + $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; + } else { + $self->{whosemove} = 1 - $self->{cur_board}{last}; + } + } else { + # Chinese, Aga, NZ all have manual placement + if ($self->{curnode}{move} < $self->{handicap}) { + $self->{whosemove} = COLOUR_BLACK; + } elsif ($self->{curnode}{move} == $self->{handicap}) { + $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; + } else { + $self->{whosemove} = 1 - $self->{cur_board}{last}; + } + } + my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; delete $self->{board_click}; if ($self->{teacher} eq $self->{app}{conn}) { #TODO# # teaching mode not implemented - $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); + $self->{button_pass}->set (label => "Pass", sensitive => 1); + $self->{button_pass}->show; $self->{button_undo}->hide; $self->{button_resign}->hide; $self->{board}->set (cursor => undef); @@ -582,7 +619,8 @@ if ($self->{cur_board}{score}) { # during scoring - $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); + $self->{button_pass}->set (label => "Done", sensitive => 1); + $self->{button_pass}->show; $self->{board}->set (cursor => sub { $_[0] & (MARK_B | MARK_W) ? $_[0] ^ MARK_GRAYED @@ -604,7 +642,8 @@ } elsif ($self->{colour} == $self->{whosemove}) { # normal move - $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); + $self->{button_pass}->set (label => "Pass", sensitive => 1); + $self->{button_pass}->show; $self->{board}->set (cursor => sub { $self->{cur_board} && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], @@ -614,7 +653,7 @@ }); $self->{board_click} = sub { return unless - $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], + $self->{cur_board}->is_valid_move ($self->{colour}, $_[0], $_[1], $self->{rules}{ruleset} == RULESET_NEW_ZEALAND); $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); $self->{board}->set (cursor => undef); @@ -622,7 +661,8 @@ $self->{button_pass}->sensitive (0); }; } else { - $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); + $self->{button_pass}->set (label => "Pass", sensitive => 0); + $self->{button_pass}->show; $self->{board}->set (cursor => undef); } } else { @@ -644,41 +684,9 @@ $self->{cur_board} = new KGS::Game::Board $self->{size}; $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); - if ($self->{rules}{ruleset} == RULESET_JAPANESE) { - if ($self->{curnode}{move} == 0) { - $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; - } else { - $self->{whosemove} = 1 - $self->{cur_board}{last}; - } - } else { - # Chinese, Aga, NZ all have manual placement - if ($self->{curnode}{move} < $self->{handicap}) { - $self->{whosemove} = COLOUR_BLACK; - } elsif ($self->{curnode}{move} == $self->{handicap}) { - $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; - } else { - $self->{whosemove} = 1 - $self->{cur_board}{last}; - } - } - $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) for COLOUR_WHITE, COLOUR_BLACK; - my $start_time = $self->{rules}{time}; - - if ($self->{showmove} == @{$self->{path}}) { - $self->{timers} = [ - [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], - [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], - ]; - $self->update_timers ($self->{timers}); - } else { - $self->update_timers ([ - [0, @{$self->{cur_board}{timer}[0]}], - [0, @{$self->{cur_board}{timer}[1]}], - ]); - } - $self->{board}->set_board ($self->{cur_board}); if ($self->{cur_board}{score}) { @@ -695,6 +703,19 @@ $self->update_cursor; + if ($self->{showmove} == @{$self->{path}}) { + $self->{timers} = [ + [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], + [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], + ]; + $self->update_timers ($self->{timers}); + } else { + $self->update_timers ([ + [0, @{$self->{cur_board}{timer}[0]}], + [0, @{$self->{cur_board}{timer}[1]}], + ]); + } + } sub event_update_tree { @@ -722,7 +743,7 @@ sub event_update_comments { my ($self, $node, $comment, $newnode) = @_; - $self->SUPER::event_update_comments($node, $comment, $newnode); + $self->SUPER::event_update_comments ($node, $comment, $newnode); my $text; @@ -771,21 +792,21 @@ sound::play 3, "resign"; $self->{chat}->append_text ("\n
Resign
" . "\n" - . (util::toxml $self->{user}[$msg->{player}]->as_string) + . (util::toxml $self->{user}[$player]->as_string) . " resigned." . "\n" - . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) + . (util::toxml $self->{user}[1 - $player]->as_string) . " wins the game." . "
"); } -sub event_time_win { +sub event_out_of_time { my ($self, $player) = @_; sound::play 3, "timewin"; $self->{chat}->append_text ("\n
Out of Time
" . "\n" - . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) + . (util::toxml $self->{user}[$msg->{1 - player}]->as_string) . " ran out of time and lost." . "\n" . (util::toxml $self->{user}[$msg->{player}]->as_string) @@ -886,7 +907,7 @@ my ($size, $time, $interval, $count, $type); - if (!$self->{channel}) { + if (!defined $self->{channel}) { $inlay->append_text ("\nNotes: "); $inlay->append_widget (gtk::textentry \$info->{notes}, 20, ""); $inlay->append_text ("\nGlobal Offer: "); @@ -913,7 +934,7 @@ }, ); - if ($self->{channel}) { + if (defined $self->{channel}) { $inlay->append_text ("\nMy Colour: "); $inlay->append_optionmenu ( \$as_black, @@ -946,7 +967,7 @@ }, ); - if ($self->{channel}) { + if (defined $self->{channel}) { $inlay->append_text ("\nHandicap: "); $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); @@ -998,7 +1019,7 @@ $inlay->append_text ("\n"); - if (!$self->{channel}) { + if (!defined $self->{channel}) { $inlay->append_button ("Create Challenge", sub { $inlay->clear; $self->{cid} = $self->{conn}->alloc_clientid;