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.66 by pcg, Sat Jun 28 16:44:56 2003 UTC vs.
Revision 1.75 by pcg, Sat Aug 2 04:27:24 2003 UTC

55 my $time = int (($_[0] - 1) % $interval + 1); 55 my $time = int (($_[0] - 1) % $interval + 1);
56 56
57 sprintf "%s/%d =%d", 57 sprintf "%s/%d =%d",
58 util::format_time $time, 58 util::format_time $time,
59 $self->{moves}, 59 $self->{moves},
60 $self->{moves} > 1
60 $time / ($self->{moves} || 1); 61 ? $time / $self->{moves}
61 62 : $interval;
62 } 63 }
63 }; 64 };
64 65
65 } else { 66 } else {
66 # none, or unknown 67 # none, or unknown
145 146
146 $self; 147 $self;
147} 148}
148 149
149sub configure { 150sub configure {
150 my ($self, $user, $rules) = @_; 151 my ($self, $app, $user, $rules) = @_;
151 152
152 if ($self->{name}->get_text ne $user->as_string) { 153 if ($self->{name}->get_text ne $user->as_string) {
153 $self->{name}->set_text ($user->as_string); 154 $self->{name}->set_text ($user->as_string);
154 155
155 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 156 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
156 $self->{imagebox}->add (gtk::image_from_data undef); 157 $self->{imagebox}->add (gtk::image_from_data undef);
157 $self->{imagebox}->show_all; 158 $self->{imagebox}->show_all;
158 159
159 if ($user->has_pic) { 160 if ($user->has_pic) {
160 # the big picture... 161 # the big picture...
161 appwin::userpic ($user->{name}, sub { 162 $app->userpic ($user->{name}, sub {
162 return unless $self->{imagebox}; 163 return unless $self->{imagebox};
164
163 if ($_[0]) { 165 if ($_[0]) {
164 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 166 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
165 $self->{imagebox}->add (gtk::image_from_data $_[0]); 167 $self->{imagebox}->add (gtk::image_from_data $_[0]);
166 $self->{imagebox}->show_all; 168 $self->{imagebox}->show_all;
167 } 169 }
185package game; 187package game;
186 188
187use KGS::Constants; 189use KGS::Constants;
188use KGS::Game::Board; 190use KGS::Game::Board;
189 191
192use Gtk2::GoBoard;
193
190use base KGS::Listener::Game; 194use base KGS::Listener::Game;
191use base KGS::Game; 195use base KGS::Game;
192 196
193use base gtk::widget; 197use base gtk::widget;
194 198
262 266
263 $vbox->pack_start((my $hbox = new Gtk2::HBox 1), 0, 1, 0); 267 $vbox->pack_start((my $hbox = new Gtk2::HBox 1), 0, 1, 0);
264 $hbox->add (($self->{userpanel}[WHITE] = new game::userpanel colour => WHITE)->widget); 268 $hbox->add (($self->{userpanel}[WHITE] = new game::userpanel colour => WHITE)->widget);
265 $hbox->add (($self->{userpanel}[BLACK] = new game::userpanel colour => BLACK)->widget); 269 $hbox->add (($self->{userpanel}[BLACK] = new game::userpanel colour => BLACK)->widget);
266 270
267 $vbox->pack_start(($self->{text} = new gtk::text)->widget, 1, 1, 0); 271 $vbox->pack_start(($self->{chat} = new chat), 1, 1, 0);
268 272
269 $vbox->pack_start(($self->{entry} = new Gtk2::Entry), 0, 1, 0);
270 $self->{entry}->signal_connect(activate => sub { 273 $self->{chat}->signal_connect(command => sub {
271 my $text = $self->{entry}->get_text; 274 my ($chat, $cmd, $arg) = @_;
272 $self->say($text) if $text =~ /\S/; 275 if ($cmd eq "rsave") {
273 $self->{entry}->set_text(""); 276 Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d#
277 } else {
278 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self);
279 }
274 }); 280 });
275 281
276 $self->event_update_game; 282 $self->event_update_game;
277 $self; 283 $self;
278} 284}
279 285
280sub event_update_users { 286sub event_update_users {
281 my ($self, $add, $update, $remove) = @_; 287 my ($self, $add, $update, $remove) = @_;
288
289 return unless $self->{userlist};
282 290
283 $self->{userlist}->update ($add, $update, $remove); 291 $self->{userlist}->update ($add, $update, $remove);
284 292
285 my %important; 293 my %important;
286 $important{$self->{user1}{name}}++; 294 $important{$self->{user1}{name}}++;
287 $important{$self->{user2}{name}}++; 295 $important{$self->{user2}{name}}++;
288 $important{$self->{user3}{name}}++; 296 $important{$self->{user3}{name}}++;
289 297
290 if (my @users = grep $important{$_->{name}}, @$add) { 298 if (my @users = grep $important{$_->{name}}, @$add) {
291 $self->{text}->append_text ("\n<header>Joins:</header>"); 299 $self->{chat}->append_text ("\n<header>Joins:</header>");
292 $self->{text}->append_text (" <user>" . $_->as_string . "</user>") for @users; 300 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
293 } 301 }
294 if (my @users = grep $important{$_->{name}}, @$remove) { 302 if (my @users = grep $important{$_->{name}}, @$remove) {
295 $self->{text}->append_text ("\n<header>Parts:</header>"); 303 $self->{chat}->append_text ("\n<header>Parts:</header>");
296 $self->{text}->append_text (" <user>" . $_->as_string . "</user>") for @users; 304 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
297 } 305 }
298 306
299} 307}
300 308
301sub join { 309sub join {
391 }sgexi; 399 }sgexi;
392 400
393 $text .= $_; 401 $text .= $_;
394 } 402 }
395 403
396 $self->{text}->append_text ($text); 404 $self->{chat}->append_text ($text);
397} 405}
398 406
399sub event_join { 407sub event_join {
400 my ($self) = @_; 408 my ($self) = @_;
401 $self->SUPER::event_join; 409 $self->SUPER::event_join;
414 422
415sub event_update_game { 423sub event_update_game {
416 my ($self) = @_; 424 my ($self) = @_;
417 $self->SUPER::event_update_game; 425 $self->SUPER::event_update_game;
418 426
419 my $title = $self->{channel} ? $self->owner->as_string . " " . $self->opponent_string : "Game Window"; 427 return unless $self->{window};
428
429 my $title = defined $self->{channel}
430 ? $self->owner->as_string . " " . $self->opponent_string
431 : "Game Window";
420 $self->{window}->set_title("KGS Game $title"); 432 $self->{window}->set_title("KGS Game $title");
421 $self->{title}->set_text ($title); 433 $self->{title}->set_text ($title);
422 434
423 $self->{user}[BLACK] = $self->{user1}; 435 $self->{user}[BLACK] = $self->{user1};
424 $self->{user}[WHITE] = $self->{user2}; 436 $self->{user}[WHITE] = $self->{user2};
471 $text .= "</infoblock>"; 483 $text .= "</infoblock>";
472 484
473 $self->{gatext} = \@ga; 485 $self->{gatext} = \@ga;
474 }; 486 };
475 487
476 $self->{text}->append_text ($text); 488 $self->{chat}->append_text ($text);
477} 489}
478 490
479sub event_update_rules { 491sub event_update_rules {
480 my ($self, $rules) = @_; 492 my ($self, $rules) = @_;
481 493
482 $self->{userpanel}[$_]->configure ($self->{user}[$_], $rules) 494 $self->{userpanel}[$_]->configure ($self->{app}, $self->{user}[$_], $rules)
483 for BLACK, WHITE; 495 for BLACK, WHITE;
484 496
485 sound::play 3, "gamestart"; 497 sound::play 3, "gamestart";
486 498
487 my $text = "\n<header>Game Rules</header>"; 499 my $text = "\n<header>Game Rules</header>";
501 } elsif ($rules->{timesys} == TIMESYS_CANADIAN) { 513 } elsif ($rules->{timesys} == TIMESYS_CANADIAN) {
502 $text .= util::format_time $rules->{time}; 514 $text .= util::format_time $rules->{time};
503 $text .= sprintf " + %s/%d CAN", util::format_time $rules->{interval}, $rules->{count}; 515 $text .= sprintf " + %s/%d CAN", util::format_time $rules->{interval}, $rules->{count};
504 } 516 }
505 517
506 $self->{text}->append_text ("<infoblock>$text</infoblock>"); 518 $self->{chat}->append_text ("<infoblock>$text</infoblock>");
507} 519}
508 520
509sub inject_resign_game { 521sub inject_resign_game {
510 my ($self, $msg) = @_; 522 my ($self, $msg) = @_;
511 523
512 sound::play 3, "resign"; 524 sound::play 3, "resign";
513 525
514 $self->{text}->append_text ("\n<infoblock><header>Resign</header>" 526 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>"
515 . "\n<user>" 527 . "\n<user>"
516 . (util::toxml $self->{user}[$msg->{player}]->as_string) 528 . (util::toxml $self->{user}[$msg->{player}]->as_string)
517 . "</user> resigned.</infoblock>"); 529 . "</user> resigned.</infoblock>");
518} 530}
519 531
520sub inject_final_result { 532sub inject_final_result {
521 my ($self, $msg) = @_; 533 my ($self, $msg) = @_;
522 534
523 $self->{text}->append_text ("<infoblock>\n<header>Game Over</header>" 535 $self->{chat}->append_text ("<infoblock>\n<header>Game Over</header>"
524 . "\nWhite Score " . (util::toxml $msg->{whitescore}->as_string) 536 . "\nWhite Score " . (util::toxml $msg->{whitescore}->as_string)
525 . "\nBlack Score " . (util::toxml $msg->{blackscore}->as_string) 537 . "\nBlack Score " . (util::toxml $msg->{blackscore}->as_string)
526 . "</infoblock>" 538 . "</infoblock>"
527 ); 539 );
528} 540}
529 541
542sub event_challenge {
543 my ($self, $challenge) = @_;
544
545 use KGS::Listener::Debug;
546 $self->{chat}->append_text ("\n".KGS::Listener::Debug::dumpval($challenge));
547}
548
530sub destroy { 549sub destroy {
531 my ($self) = @_; 550 my ($self) = @_;
551
552 delete $self->{app}{gamelist}{game}{$self->{channel}};
532 $self->{userpanel}[$_] && (delete $self->{userpanel}[$_])->destroy 553 $self->{userpanel}[$_] && (delete $self->{userpanel}[$_])->destroy
533 for BLACK, WHITE; 554 for BLACK, WHITE;
534 $self->SUPER::destroy; 555 $self->SUPER::destroy;
535 delete $appwin::gamelist->{game}{$self->{channel}};
536} 556}
537 557
5381; 5581;
539 559

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines