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.95 by pcg, Fri May 28 23:19:59 2004 UTC vs.
Revision 1.96 by pcg, Sat May 29 02:01:43 2004 UTC

199sub new { 199sub new {
200 my ($self, %arg) = @_; 200 my ($self, %arg) = @_;
201 $self = $self->Glib::Object::new; 201 $self = $self->Glib::Object::new;
202 $self->{$_} = delete $arg{$_} for keys %arg; 202 $self->{$_} = delete $arg{$_} for keys %arg;
203 203
204 $self->listen ($self->{conn});
205
206 gtk::state $self, "game::window", undef, window_size => [600, 500]; 204 gtk::state $self, "game::window", undef, window_size => [600, 500];
207 205
208 $self->signal_connect (delete_event => sub { $self->part; 1 });
209 $self->signal_connect (destroy => sub { 206 $self->signal_connect (destroy => sub {
210 $self->unlisten; 207 $self->unlisten;
211 delete $self->{app}{game}{$self->{channel}}; 208 delete $self->{app}{game}{$self->{channel}};
212 %{$_[0]} = (); 209 %{$_[0]} = ();
213 });#d# 210 });#d#
256 $hbox->add ($self->{userpanel}[$_] = new game::userpanel colour => $_) 253 $hbox->add ($self->{userpanel}[$_] = new game::userpanel colour => $_)
257 for COLOUR_WHITE, COLOUR_BLACK; 254 for COLOUR_WHITE, COLOUR_BLACK;
258 255
259 $vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); 256 $vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0);
260 257
261 $self->{rules_inlay} = $self->{chat}->new_switchable_inlay ("Game Setup:", sub { $self->draw_setup (@_) }, 1); 258 $self->set_channel ($self->{channel});
262 $self->{users_inlay} = $self->{chat}->new_switchable_inlay ("Users:", sub { $self->draw_users (@_) }, 1);
263 259
264 $self->{chat}->signal_connect (command => sub { 260 $self->show_all;
265 my ($chat, $cmd, $arg) = @_;
266 if ($cmd eq "rsave") {
267 Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d#
268 } else {
269 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self);
270 }
271 });
272 261
273 $self; 262 $self;
263}
264
265sub set_channel {
266 my ($self, $channel) = @_;
267
268 $self->{channel} = $channel;
269
270 if ($self->{channel} > 0) {
271 $self->listen ($self->{conn});
272
273 $self->{rules_inlay} = $self->{chat}->new_switchable_inlay ("Game Setup:", sub { $self->draw_setup (@_) }, 1);
274 $self->{users_inlay} = $self->{chat}->new_switchable_inlay ("Users:", sub { $self->draw_users (@_) }, 1);
275
276 $self->signal_connect (delete_event => sub { $self->part; 1 });
277 $self->{chat}->signal_connect (command => sub {
278 my ($chat, $cmd, $arg) = @_;
279 if ($cmd eq "rsave") {
280 Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d#
281 } else {
282 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self);
283 }
284 });
285 }
274} 286}
275 287
276sub event_update_users { 288sub event_update_users {
277 my ($self, $add, $update, $remove) = @_; 289 my ($self, $add, $update, $remove) = @_;
278 290
307 my ($self) = @_; 319 my ($self) = @_;
308 return unless $self->{path}; 320 return unless $self->{path};
309 321
310 my $move = int $self->{moveadj}->get_value; 322 my $move = int $self->{moveadj}->get_value;
311 323
312 my $running = $move == @{$self->{path}}; 324 my $running = $move == @{$self->{path}}
325 && !$self->{teacher}
326 && $self->is_active;
313 327
314 $self->{board_label}->set_text ("Move " . ($move - 1)); 328 $self->{board_label}->set_text ("Move " . ($move - 1));
315 329
316 $self->{cur_board} = new KGS::Game::Board $self->{size}; 330 $self->{cur_board} = new KGS::Game::Board $self->{size};
317 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $move - 1]]); 331 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $move - 1]]);
388sub event_join { 402sub event_join {
389 my ($self) = @_; 403 my ($self) = @_;
390 404
391 $self->SUPER::event_join (@_); 405 $self->SUPER::event_join (@_);
392 $self->event_update_game; 406 $self->event_update_game;
393 $self->show_all;
394} 407}
395 408
396sub event_part { 409sub event_part {
397 my ($self) = @_; 410 my ($self) = @_;
398 411
439} 452}
440 453
441sub draw_setup { 454sub draw_setup {
442 my ($self, $inlay) = @_; 455 my ($self, $inlay) = @_;
443 456
457 return unless $self->{joined};
458
444 my $rules = $self->{rules}; 459 my $rules = $self->{rules};
445 460
446 my $text = ""; 461 my $text = "";
447 462
448 ## Rules 463 $text .= "\nTeacher: <user>" . (util::toxml $self->{teacher}) . "</user>"
464 if $self->{teacher};
465
466 $text .= "\nOwner: <user>" . (util::toxml $self->{user3}->as_string) . "</user>"
467 if $self->{user3}->is_valid;
468
469 if ($self->is_inprogress) {
470 $text .= "\nPlayers: <user>" . (util::toxml $self->{user2}->as_string) . "</user>"
471 . " vs. <user>" . (util::toxml $self->{user1}->as_string) . "</user>";
472 }
473 $text .= "\nType: " . util::toxml $gametype{$self->type};
449 474
450 $text .= "\nRuleset: " . $ruleset{$rules->{ruleset}}; 475 $text .= "\nRuleset: " . $ruleset{$rules->{ruleset}};
451 476
452 $text .= "\nTime: "; 477 $text .= "\nTime: ";
453 478
462 } elsif ($rules->{timesys} == TIMESYS_CANADIAN) { 487 } elsif ($rules->{timesys} == TIMESYS_CANADIAN) {
463 $text .= util::format_time $rules->{time}; 488 $text .= util::format_time $rules->{time};
464 $text .= sprintf " + %s/%d CAN", util::format_time $rules->{interval}, $rules->{count}; 489 $text .= sprintf " + %s/%d CAN", util::format_time $rules->{interval}, $rules->{count};
465 } 490 }
466 491
467 ## Other state info
468
469 $text .= "\nType: " . util::toxml $self->type_char;
470 $text .= "\nFlags:"; 492 $text .= "\nFlags:";
493 $text .= " private" if $self->is_private;
471 $text .= " started" if $self->is_inprogress; 494 $text .= " started" if $self->is_inprogress;
472 $text .= " adjourned" if $self->is_adjourned; 495 $text .= " adjourned" if $self->is_adjourned;
473 $text .= " scored" if $self->is_scored; 496 $text .= " scored" if $self->is_scored;
474 $text .= " saved" if $self->is_saved; 497 $text .= " saved" if $self->is_saved;
475 498
476 $text .= "\nOwner: <user>" . (util::toxml $self->{user3}->as_string) . "</user>"
477 if $self->{user3}->is_valid;
478
479 if ($self->is_inprogress) { 499 if ($self->is_inprogress) {
480 $text .= "\nPlayers: <user>" . (util::toxml $self->{user2}->as_string) . "</user>"
481 . " vs. <user>" . (util::toxml $self->{user1}->as_string) . "</user>";
482 $text .= "\nHandicap: " . $self->{handicap}; 500 $text .= "\nHandicap: " . $self->{handicap};
483 $text .= "\nKomi: " . $self->{komi}; 501 $text .= "\nKomi: " . $self->{komi};
484 $text .= "\nSize: " . $self->size_string; 502 $text .= "\nSize: " . $self->size_string;
485 } 503 }
486 504

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines