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.120 by root, Wed Jun 2 03:39:24 2004 UTC vs.
Revision 1.140 by root, Wed Oct 13 00:33:15 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;
160} 162}
161 163
164sub SET_PROPERTY {
165 my ($self, $pspec, $value) = @_;
166
167 $self->{$pspec->get_name} = $value;
168
169 $self->set_name ("userpanel-$self->{colour}");
170}
171
162sub configure { 172sub configure {
163 my ($self, $app, $user, $rules) = @_; 173 my ($self, $app, $user, $rules) = @_;
164 174
165 if ($self->{name}->get_text ne $user->as_string) { 175 if ($self->{name}->get_text ne $user->as_string) {
166 $self->{name}->set_text ($user->as_string); 176 $self->{name}->set_text ($user->as_string);
167 177
168 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 178 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
179 unless ($::config{suppress_userpic}) {
169 $self->{imagebox}->add (gtk::image_from_data undef); 180 $self->{imagebox}->add (gtk::image_from_data undef);
181 }
170 $self->{imagebox}->show_all; 182 $self->{imagebox}->show_all;
171 183
172 if ($user->has_pic) { 184 if ($user->has_pic) {
173 # the big picture... 185 # the big picture...
174 $app->userpic ($user->{name}, sub { 186 $app->userpic ($user->{name}, sub {
175 return unless $self->{imagebox}; 187 return unless $self->{imagebox};
176 188
177 if ($_[0]) { 189 if ($_[0]) {
178 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 190 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
191 unless ($::config{suppress_userpic}) {
179 $self->{imagebox}->add (gtk::image_from_data $_[0]); 192 $self->{imagebox}->add (gtk::image_from_data $_[0]);
193 }
180 $self->{imagebox}->show_all; 194 $self->{imagebox}->show_all;
181 } 195 }
182 }); 196 });
183 } 197 }
184 } 198 }
218 232
219use POSIX qw(ceil); 233use POSIX qw(ceil);
220 234
221sub new { 235sub new {
222 my ($self, %arg) = @_; 236 my ($self, %arg) = @_;
237
223 $self = $self->Glib::Object::new; 238 $self = $self->Glib::Object::new;
224 $self->{$_} = delete $arg{$_} for keys %arg; 239 $self->{$_} = delete $arg{$_} for keys %arg;
225 240
226 gtk::state $self, "game::window", undef, window_size => [600, 500]; 241 gtk::state $self, "game::window", undef, window_size => [620, 460];
242 $self->set (allow_shrink => 1);
227 243
228 $self->signal_connect (destroy => sub { 244 $self->signal_connect (destroy => sub {
229 $self->unlisten; 245 $self->unlisten;
230 delete $self->{app}{game}{$self->{channel}}; 246 delete $self->{app}{game}{$self->{channel}};
231 %{$_[0]} = (); 247 %{$_[0]} = ();
232 });#d# 248 });#d#
233 249
234 $self->add (my $hpane = new Gtk2::HPaned); 250 $self->add (my $hpane = new Gtk2::HPaned);
235 gtk::state $hpane, "game::hpane", undef, position => 500; 251 gtk::state $hpane, "game::hpane", undef, position => 420;
236 252
237 # LEFT PANE 253 # LEFT PANE
238 254
239 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0); 255 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0);
240 256
250 $vbox->pack_start ((my $frame = new Gtk2::Frame), 0, 1, 0); 266 $vbox->pack_start ((my $frame = new Gtk2::Frame), 0, 1, 0);
251 267
252 { 268 {
253 $frame->add (my $vbox = new Gtk2::VBox); 269 $frame->add (my $vbox = new Gtk2::VBox);
254 $vbox->add ($self->{title} = new Gtk2::Label "-"); 270 $vbox->add ($self->{title} = new Gtk2::Label "-");
271 $self->{title}->set (visible => 0, no_show_all => 1); # workaround for refresh-bug
255 272
256 $vbox->add (my $hbox = new Gtk2::HBox); 273 $vbox->add (my $hbox = new Gtk2::HBox);
257 274
258 $hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 0, 0); 275 $hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 0, 0);
259 276
275 for COLOUR_WHITE, COLOUR_BLACK; 292 for COLOUR_WHITE, COLOUR_BLACK;
276 293
277 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); 294 $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0);
278 295
279 $buttonbox->add ($self->{button_pass} = 296 $buttonbox->add ($self->{button_pass} =
280 Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0)); 297 Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0, no_show_all => 1));
281 $self->{button_pass}->signal_connect (clicked => sub { 298 $self->{button_pass}->signal_connect (clicked => sub {
282 $self->{board_click}->(255, 255) if $self->{board_click}; 299 $self->{board_click}->(255, 255) if $self->{board_click};
283 }); 300 });
284 eval { $self->{button_pass}->set (no_show_all => 1) }; # workaround for gtk+-2.2
285 $buttonbox->add ($self->{button_undo} = 301 $buttonbox->add ($self->{button_undo} =
286 Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0)); 302 Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0, no_show_all => 1));
287 $self->{button_undo}->signal_connect (clicked => sub { 303 $self->{button_undo}->signal_connect (clicked => sub {
288 $self->send (req_undo => channel => $self->{channel}); 304 $self->send (req_undo => channel => $self->{channel});
289 }); 305 });
290 eval { $self->{button_undo}->set (no_show_all => 1) }; # workaround for gtk+-2.2
291 $buttonbox->add ($self->{button_resign} = 306 $buttonbox->add ($self->{button_resign} =
292 Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0)); 307 Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0, no_show_all => 1));
293 $self->{button_resign}->signal_connect (clicked => sub { 308 $self->{button_resign}->signal_connect (clicked => sub {
294 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); 309 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour});
295 }); 310 });
296 eval { $self->{button_resign}->set (no_show_all => 1) }; # workaround for gtk+-2.2
297 311
298 $vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); 312 $vbox->pack_start (($self->{chat} = new chat app => $self->{app}), 1, 1, 0);
313
314 $self->{chat}->signal_connect (tag_event => sub {
315 my (undef, $tag, $event, $content) = @_;
316 });
299 317
300 $self->set_channel ($self->{channel}); 318 $self->set_channel ($self->{channel});
301 319
302 $self->show_all; 320 $self->show_all;
303 321
307sub set_channel { 325sub set_channel {
308 my ($self, $channel) = @_; 326 my ($self, $channel) = @_;
309 327
310 $self->{channel} = $channel; 328 $self->{channel} = $channel;
311 329
312 if ($self->{channel} > 0) { 330 if (defined $self->{channel}) {
313 $self->listen ($self->{conn}); 331 $self->listen ($self->{conn});
314 332
315 $self->{rules_inlay} = $self->{chat}->new_switchable_inlay ("Game Setup:", sub { $self->draw_setup (@_) }, 1); 333 $self->{rules_inlay} = $self->{chat}->new_switchable_inlay ("Game Setup:", sub { $self->draw_setup (@_) }, 1);
316 $self->{users_inlay} = $self->{chat}->new_switchable_inlay ("Users:", sub { $self->draw_users (@_) }, 1); 334 $self->{users_inlay} = $self->{chat}->new_switchable_inlay ("Users:", sub { $self->draw_users (@_) }, 1);
317 335
318 $self->signal_connect (delete_event => sub { $self->part; 1 }); 336 $self->signal_connect (delete_event => sub { $self->part; 1 });
319 $self->{chat}->signal_connect (command => sub { 337 $self->{chat}->signal_connect (command => sub {
320 my ($chat, $cmd, $arg) = @_; 338 my ($chat, $cmd, $arg) = @_;
321 if ($cmd eq "rsave") { 339 if ($cmd eq "rsave") {
340 local $Storable::forgive_me = 1;
322 Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d# 341 #Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d#
342 Storable::nstore { %$self }, $arg;#d#
323 } else { 343 } else {
324 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self); 344 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self);
325 } 345 }
326 }); 346 });
327 } 347 }
334 return if $self->{joined}; 354 return if $self->{joined};
335 355
336 $self->SUPER::join; 356 $self->SUPER::join;
337} 357}
338 358
359sub part {
360 my ($self) = @_;
361
362 $self->hide;
363 $self->SUPER::part;
364}
365
339sub event_join { 366sub event_join {
340 my ($self) = @_; 367 my ($self) = @_;
341 368
342 $self->SUPER::event_join (@_); 369 $self->SUPER::event_join (@_);
343 $self->init_tree; 370 $self->init_tree;
362 389
363sub draw_users { 390sub draw_users {
364 my ($self, $inlay) = @_; 391 my ($self, $inlay) = @_;
365 392
366 for (sort keys %{$self->{users}}) { 393 for (sort keys %{$self->{users}}) {
367 $inlay->append_text (" <user>" . $self->{users}{$_}->as_string . "</user>"); 394 $inlay->append_text ("\t<user>" . $self->{users}{$_}->as_string . "</user>");
368 } 395 }
369} 396}
370 397
371sub event_update_users { 398sub event_update_users {
372 my ($self, $add, $update, $remove) = @_; 399 my ($self, $add, $update, $remove) = @_;
382 $important{$self->{black}{name}}++; 409 $important{$self->{black}{name}}++;
383 $important{$self->{white}{name}}++; 410 $important{$self->{white}{name}}++;
384 $important{$self->{owner}{name}}++; 411 $important{$self->{owner}{name}}++;
385 412
386 if (my @users = grep $important{$_->{name}}, @$add) { 413 if (my @users = grep $important{$_->{name}}, @$add) {
387 $self->{chat}->append_text ("\n<header>Joins:</header>"); 414 $self->{chat}->append_text ("\n<leader>Joins:</leader>");
388 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 415 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
389 } 416 }
390 if (my @users = grep $important{$_->{name}}, @$remove) { 417 if (my @users = grep $important{$_->{name}}, @$remove) {
391 $self->{chat}->append_text ("\n<header>Parts:</header>"); 418 $self->{chat}->append_text ("\n<leader>Parts:</leader>");
392 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 419 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
393 } 420 }
394} 421}
395 422
396### GAME INFO ############################################################### 423### GAME INFO ###############################################################
487 my $title = defined $self->{channel} 514 my $title = defined $self->{channel}
488 ? $self->owner->as_string . " " . $self->opponent_string 515 ? $self->owner->as_string . " " . $self->opponent_string
489 : "Game Window"; 516 : "Game Window";
490 $self->set_title ("KGS Game $title"); 517 $self->set_title ("KGS Game $title");
491 $self->{title}->set_text ($title); # title gets redrawn wrongly 518 $self->{title}->set_text ($title); # title gets redrawn wrongly
519 $self->{title}->show; # workaround for refresh-bug
492 520
493 $self->{rules_inlay}->refresh; 521 $self->{rules_inlay}->refresh;
494 522
495 if (exists $self->{teacher}) { 523 if (exists $self->{teacher}) {
496 $self->{teacher_inlay} ||= $self->{chat}->new_inlay; 524 $self->{teacher_inlay} ||= $self->{chat}->new_inlay;
553sub update_cursor { 581sub update_cursor {
554 my ($self) = @_; 582 my ($self) = @_;
555 583
556 return unless $self->{cur_board}; 584 return unless $self->{cur_board};
557 585
586 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
587 if ($self->{curnode}{move} == 0) {
588 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
589 } else {
590 $self->{whosemove} = 1 - $self->{cur_board}{last};
591 }
592 } else {
593 # Chinese, Aga, NZ all have manual placement
594 if ($self->{curnode}{move} < $self->{handicap}) {
595 $self->{whosemove} = COLOUR_BLACK;
596 } elsif ($self->{curnode}{move} == $self->{handicap}) {
597 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
598 } else {
599 $self->{whosemove} = 1 - $self->{cur_board}{last};
600 }
601 }
602
558 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; 603 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active;
559 604
560 delete $self->{board_click}; 605 delete $self->{board_click};
561 606
562 if ($self->{teacher} eq $self->{app}{conn}) { 607 if ($self->{teacher} eq $self->{app}{conn}) {
563 #TODO# # teaching mode not implemented 608 #TODO# # teaching mode not implemented
564 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 609 $self->{button_pass}->set (label => "Pass", sensitive => 1);
610 $self->{button_pass}->show;
565 $self->{button_undo}->hide; 611 $self->{button_undo}->hide;
566 $self->{button_resign}->hide; 612 $self->{button_resign}->hide;
567 $self->{board}->set (cursor => undef); 613 $self->{board}->set (cursor => undef);
568 614
569 } elsif ($running && $self->{colour} != COLOUR_NONE) { 615 } elsif ($running && $self->{colour} != COLOUR_NONE) {
571 $self->{button_undo}->show; 617 $self->{button_undo}->show;
572 $self->{button_resign}->show; 618 $self->{button_resign}->show;
573 619
574 if ($self->{cur_board}{score}) { 620 if ($self->{cur_board}{score}) {
575 # during scoring 621 # during scoring
576 $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); 622 $self->{button_pass}->set (label => "Done", sensitive => 1);
623 $self->{button_pass}->show;
577 $self->{board}->set (cursor => sub { 624 $self->{board}->set (cursor => sub {
578 $_[0] & (MARK_B | MARK_W) 625 $_[0] & (MARK_B | MARK_W)
579 ? $_[0] ^ MARK_GRAYED 626 ? $_[0] ^ MARK_GRAYED
580 : $_[0]; 627 : $_[0];
581 }); 628 });
593 } 640 }
594 }; 641 };
595 642
596 } elsif ($self->{colour} == $self->{whosemove}) { 643 } elsif ($self->{colour} == $self->{whosemove}) {
597 # normal move 644 # normal move
598 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 645 $self->{button_pass}->set (label => "Pass", sensitive => 1);
646 $self->{button_pass}->show;
599 $self->{board}->set (cursor => sub { 647 $self->{board}->set (cursor => sub {
600 $self->{cur_board} 648 $self->{cur_board}
601 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 649 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2],
602 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND) 650 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND)
603 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B) 651 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B)
604 : $_[0]; 652 : $_[0];
605 }); 653 });
606 $self->{board_click} = sub { 654 $self->{board_click} = sub {
607 return unless 655 return unless
608 $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], 656 $self->{cur_board}->is_valid_move ($self->{colour}, $_[0], $_[1],
609 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND); 657 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND);
610 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); 658 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]);
611 $self->{board}->set (cursor => undef); 659 $self->{board}->set (cursor => undef);
612 delete $self->{board_click}; 660 delete $self->{board_click};
613 $self->{button_pass}->sensitive (0); 661 $self->{button_pass}->sensitive (0);
614 }; 662 };
615 } else { 663 } else {
616 $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); 664 $self->{button_pass}->set (label => "Pass", sensitive => 0);
665 $self->{button_pass}->show;
617 $self->{board}->set (cursor => undef); 666 $self->{board}->set (cursor => undef);
618 } 667 }
619 } else { 668 } else {
620 $self->{button_undo}->hide; 669 $self->{button_undo}->hide;
621 $self->{button_resign}->hide; 670 $self->{button_resign}->hide;
633 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); 682 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
634 683
635 $self->{cur_board} = new KGS::Game::Board $self->{size}; 684 $self->{cur_board} = new KGS::Game::Board $self->{size};
636 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); 685 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
637 686
638 if ($self->{rules}{ruleset} == RULESET_JAPANESE) {
639 if ($self->{curnode}{move} == 0) {
640 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
641 } else {
642 $self->{whosemove} = 1 - $self->{cur_board}{last};
643 }
644 } else {
645 # Chinese, Aga, NZ all have manual placement
646 if ($self->{curnode}{move} < $self->{handicap}) {
647 $self->{whosemove} = COLOUR_BLACK;
648 } elsif ($self->{curnode}{move} == $self->{handicap}) {
649 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
650 } else {
651 $self->{whosemove} = 1 - $self->{cur_board}{last};
652 }
653 }
654
655 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 687 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
656 for COLOUR_WHITE, COLOUR_BLACK; 688 for COLOUR_WHITE, COLOUR_BLACK;
657 689
658 my $start_time = $self->{rules}{time}; 690 $self->{board}->set_board ($self->{cur_board});
691
692 if ($self->{cur_board}{score}) {
693 $self->{score_inlay} ||= $self->{chat}->new_inlay;
694 $self->{score_inlay}->clear;
695 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
696 . "\n<score>"
697 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
698 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
699 . "</score>");
700 } elsif ($self->{score_inlay}) {
701 (delete $self->{score_inlay})->clear;
702 }
703
704 $self->update_cursor;
659 705
660 if ($self->{showmove} == @{$self->{path}}) { 706 if ($self->{showmove} == @{$self->{path}}) {
661 $self->{timers} = [ 707 $self->{timers} = [
662 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], 708 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}],
663 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], 709 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}],
668 [0, @{$self->{cur_board}{timer}[0]}], 714 [0, @{$self->{cur_board}{timer}[0]}],
669 [0, @{$self->{cur_board}{timer}[1]}], 715 [0, @{$self->{cur_board}{timer}[1]}],
670 ]); 716 ]);
671 } 717 }
672 718
673 $self->{board}->set_board ($self->{cur_board});
674
675 if ($self->{cur_board}{score}) {
676 $self->{score_inlay} ||= $self->{chat}->new_inlay;
677 $self->{score_inlay}->clear;
678 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
679 . "\n<score>"
680 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
681 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
682 . "</score>");
683 } elsif ($self->{score_inlay}) {
684 (delete $self->{score_inlay})->clear;
685 }
686
687 $self->update_cursor;
688
689} 719}
690 720
691sub event_update_tree { 721sub event_update_tree {
692 my ($self) = @_; 722 my ($self) = @_;
693 723
711 } 741 }
712} 742}
713 743
714sub event_update_comments { 744sub event_update_comments {
715 my ($self, $node, $comment, $newnode) = @_; 745 my ($self, $node, $comment, $newnode) = @_;
716 $self->SUPER::event_update_comments($node, $comment, $newnode); 746 $self->SUPER::event_update_comments ($node, $comment, $newnode);
717 747
718 my $text; 748 my $text;
719 749
720 $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>" 750 $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>"
721 if $newnode; 751 if $newnode;
760 my ($self, $player) = @_; 790 my ($self, $player) = @_;
761 791
762 sound::play 3, "resign"; 792 sound::play 3, "resign";
763 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>" 793 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>"
764 . "\n<user>" 794 . "\n<user>"
765 . (util::toxml $self->{user}[$msg->{player}]->as_string) 795 . (util::toxml $self->{user}[$player]->as_string)
766 . "</user> resigned." 796 . "</user> resigned."
767 . "\n<user>" 797 . "\n<user>"
768 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) 798 . (util::toxml $self->{user}[1 - $player]->as_string)
769 . "</user> wins the game." 799 . "</user> wins the game."
770 . "</infoblock>"); 800 . "</infoblock>");
771} 801}
772 802
773sub event_time_win { 803sub event_out_of_time {
774 my ($self, $player) = @_; 804 my ($self, $player) = @_;
775 805
776 sound::play 3, "timewin"; 806 sound::play 3, "timewin";
777 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>" 807 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>"
778 . "\n<user>" 808 . "\n<user>"
779 . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) 809 . (util::toxml $self->{user}[$msg->{1 - player}]->as_string)
780 . "</user> ran out of time and lost." 810 . "</user> ran out of time and lost."
781 . "\n<user>" 811 . "\n<user>"
782 . (util::toxml $self->{user}[$msg->{player}]->as_string) 812 . (util::toxml $self->{user}[$msg->{player}]->as_string)
783 . "</user> wins the game." 813 . "</user> wins the game."
784 . "</infoblock>"); 814 . "</infoblock>");
875 my $as_black = $info->{black}{name} eq $self->{conn}{name} ? 1 : 0;; 905 my $as_black = $info->{black}{name} eq $self->{conn}{name} ? 1 : 0;;
876 my $opponent = $as_black ? $info->{white} : $info->{black}; 906 my $opponent = $as_black ? $info->{white} : $info->{black};
877 907
878 my ($size, $time, $interval, $count, $type); 908 my ($size, $time, $interval, $count, $type);
879 909
880 if (!$self->{channel}) { 910 if (!defined $self->{channel}) {
881 $inlay->append_text ("\nNotes: "); 911 $inlay->append_text ("\nNotes: ");
882 $inlay->append_entry (\$info->{notes}, 20, ""); 912 $inlay->append_widget (gtk::textentry \$info->{notes}, 20, "");
883 $inlay->append_text ("\nGlobal Offer: "); 913 $inlay->append_text ("\nGlobal Offer: ");
884 $inlay->append_optionmenu (\$info->{flags}, 914 $inlay->append_optionmenu (\$info->{flags},
885 0 => "No", 915 0 => "No",
886 2 => "Yes", 916 2 => "Yes",
887 ); 917 );
902 sub { 932 sub {
903 $size->set_history (2) if $_[0] eq GAMETYPE_RATED; 933 $size->set_history (2) if $_[0] eq GAMETYPE_RATED;
904 }, 934 },
905 ); 935 );
906 936
907 if ($self->{channel}) { 937 if (defined $self->{channel}) {
908 $inlay->append_text ("\nMy Colour: "); 938 $inlay->append_text ("\nMy Colour: ");
909 $inlay->append_optionmenu ( 939 $inlay->append_optionmenu (
910 \$as_black, 940 \$as_black,
911 0 => "White", 941 0 => "White",
912 1 => "Black", 942 1 => "Black",
935 $type->set_history (5) # reset to free 965 $type->set_history (5) # reset to free
936 if $_[0] != 19 && $info->{gametype} == GAMETYPE_RATED; 966 if $_[0] != 19 && $info->{gametype} == GAMETYPE_RATED;
937 }, 967 },
938 ); 968 );
939 969
940 if ($self->{channel}) { 970 if (defined $self->{channel}) {
941 $inlay->append_text ("\nHandicap: "); 971 $inlay->append_text ("\nHandicap: ");
942 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); 972 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9);
943 973
944 $inlay->append_text ("\nKomi: "); 974 $inlay->append_text ("\nKomi: ");
945 $inlay->append_entry (\$info->{rules}{komi}, 5); 975 $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5);
946 } 976 }
947 977
948 $inlay->append_text ("\nTimesys: "); 978 $inlay->append_text ("\nTimesys: ");
949 $inlay->append_optionmenu ( 979 $inlay->append_optionmenu (
950 \$info->{rules}{timesys}, 980 \$info->{rules}{timesys},
979 } 1009 }
980 } 1010 }
981 ); 1011 );
982 1012
983 $inlay->append_text ("\nMain Time: "); 1013 $inlay->append_text ("\nMain Time: ");
984 $time = $inlay->append_entry (\$info->{rules}{time}, 5); 1014 $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5);
985 $inlay->append_text ("\nInterval: "); 1015 $inlay->append_text ("\nInterval: ");
986 $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); 1016 $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5);
987 $inlay->append_text ("\nPeriods/Stones: "); 1017 $inlay->append_text ("\nPeriods/Stones: ");
988 $count = $inlay->append_entry (\$info->{rules}{count}, 2); 1018 $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5);
989 1019
990 $inlay->append_text ("\n"); 1020 $inlay->append_text ("\n");
991 1021
992 if (!$self->{channel}) { 1022 if (!defined $self->{channel}) {
993 $inlay->append_button ("Create Challenge", sub { 1023 $inlay->append_button ("Create Challenge", sub {
994 $inlay->clear; 1024 $inlay->clear;
995 $self->{cid} = $self->{conn}->alloc_clientid; 1025 $self->{cid} = $self->{conn}->alloc_clientid;
996 $self->send (new_game => 1026 $self->send (new_game =>
997 channel => delete $self->{roomid}, 1027 channel => delete $self->{roomid},

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines