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.112 by root, Mon May 31 18:18:26 2004 UTC vs.
Revision 1.140 by root, Wed Oct 13 00:33:15 2004 UTC

34sub configure { 34sub configure {
35 my ($self, $timesys, $main, $interval, $count) = @_; 35 my ($self, $timesys, $main, $interval, $count) = @_;
36 36
37 if ($timesys == TIMESYS_ABSOLUTE) { 37 if ($timesys == TIMESYS_ABSOLUTE) {
38 $self->{format} = sub { 38 $self->{format} = sub {
39 if ($_[0] <= 0) { 39 if ($_[0] < 0) {
40 "TIMEOUT"; 40 "TIMEOUT";
41 } else { 41 } else {
42 util::format_time $_[0]; 42 util::format_time $_[0];
43 } 43 }
44 }; 44 };
45 45
46 } elsif ($timesys == TIMESYS_BYO_YOMI) { 46 } elsif ($timesys == TIMESYS_BYO_YOMI) {
47 my $low = $interval * $count; 47 my $low = $interval * $count;
48 48
49 $self->{format} = sub { 49 $self->{format} = sub {
50 if ($_[0] <= 0) { 50 if ($_[0] < 0) {
51 "TIMEOUT"; 51 "TIMEOUT";
52 } elsif ($_[0] > $low) { 52 } elsif ($_[0] > $low) {
53 util::format_time $_[0] - $low; 53 util::format_time $_[0] - $low;
54 } else { 54 } else {
55 sprintf "%s (%d)", 55 sprintf "%s (%d)",
58 } 58 }
59 }; 59 };
60 60
61 } elsif ($timesys == TIMESYS_CANADIAN) { 61 } elsif ($timesys == TIMESYS_CANADIAN) {
62 $self->{format} = sub { 62 $self->{format} = sub {
63 if ($_[0] <= 0) { 63 if ($_[0] < 0) {
64 "TIMEOUT"; 64 "TIMEOUT";
65 } elsif (!$self->{moves}) { 65 } elsif (!$self->{moves}) {
66 util::format_time $_[0] - $low; 66 util::format_time $_[0] - $low;
67 } else { 67 } else {
68 my $time = int (($_[0] - 1) % $interval + 1); 68 my $time = int (($_[0] - 1) % $interval + 1);
133 133
134### USER PANEL ############################################################## 134### USER PANEL ##############################################################
135 135
136package game::userpanel; 136package game::userpanel;
137 137
138use KGS::Constants;
139
138use Glib::Object::Subclass 140use Glib::Object::Subclass
139 Gtk2::HBox, 141 Gtk2::Frame,
140 properties => [ 142 properties => [
141 Glib::ParamSpec->IV ("colour", "colour", "User Colour", 0, 1, 0, [qw(construct-only writable)]), 143 Glib::ParamSpec->IV ("colour", "colour", "User Colour",
144 COLOUR_BLACK, COLOUR_WHITE, COLOUR_BLACK,
145 [qw(construct-only readable writable)]),
142 ]; 146 ];
143 147
144sub INIT_INSTANCE { 148sub INIT_INSTANCE {
145 my ($self) = @_; 149 my ($self) = @_;
146 150
151 $self->add ($self->{window} = my $window = new Gtk2::EventBox); # for bg
152
147 $self->add (my $vbox = new Gtk2::VBox); 153 $window->add (my $vbox = new Gtk2::VBox);
148 154
149 $vbox->add ($self->{name} = new Gtk2::Label $self->{name}); 155 $vbox->pack_start (($self->{name} = new Gtk2::Label "-"), 1, 1, 0);
150 $vbox->add ($self->{info} = new Gtk2::Label ""); 156 $vbox->pack_start (($self->{info} = new Gtk2::Label "-"), 1, 1, 0);
151 $vbox->add ($self->{clock} = new game::goclock); Scalar::Util::weaken $self->{clock}; 157 $vbox->pack_start (($self->{clock} = new game::goclock), 1, 1, 0);
152 158
153 $vbox->add ($self->{imagebox} = new Gtk2::VBox); 159 $vbox->add ($self->{imagebox} = new Gtk2::VBox);
154 160
155 $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}");
156} 170}
157 171
158sub configure { 172sub configure {
159 my ($self, $app, $user, $rules) = @_; 173 my ($self, $app, $user, $rules) = @_;
160 174
161 if ($self->{name}->get_text ne $user->as_string) { 175 if ($self->{name}->get_text ne $user->as_string) {
162 $self->{name}->set_text ($user->as_string); 176 $self->{name}->set_text ($user->as_string);
163 177
164 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 178 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
179 unless ($::config{suppress_userpic}) {
165 $self->{imagebox}->add (gtk::image_from_data undef); 180 $self->{imagebox}->add (gtk::image_from_data undef);
181 }
166 $self->{imagebox}->show_all; 182 $self->{imagebox}->show_all;
167 183
168 if ($user->has_pic) { 184 if ($user->has_pic) {
169 # the big picture... 185 # the big picture...
170 $app->userpic ($user->{name}, sub { 186 $app->userpic ($user->{name}, sub {
171 return unless $self->{imagebox}; 187 return unless $self->{imagebox};
172 188
173 if ($_[0]) { 189 if ($_[0]) {
174 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; 190 $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children;
191 unless ($::config{suppress_userpic}) {
175 $self->{imagebox}->add (gtk::image_from_data $_[0]); 192 $self->{imagebox}->add (gtk::image_from_data $_[0]);
193 }
176 $self->{imagebox}->show_all; 194 $self->{imagebox}->show_all;
177 } 195 }
178 }); 196 });
179 } 197 }
180 } 198 }
214 232
215use POSIX qw(ceil); 233use POSIX qw(ceil);
216 234
217sub new { 235sub new {
218 my ($self, %arg) = @_; 236 my ($self, %arg) = @_;
237
219 $self = $self->Glib::Object::new; 238 $self = $self->Glib::Object::new;
220 $self->{$_} = delete $arg{$_} for keys %arg; 239 $self->{$_} = delete $arg{$_} for keys %arg;
221 240
222 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);
223 243
224 $self->signal_connect (destroy => sub { 244 $self->signal_connect (destroy => sub {
225 $self->unlisten; 245 $self->unlisten;
226 delete $self->{app}{game}{$self->{channel}}; 246 delete $self->{app}{game}{$self->{channel}};
227 %{$_[0]} = (); 247 %{$_[0]} = ();
228 });#d# 248 });#d#
229 249
230 $self->add (my $hpane = new Gtk2::HPaned); 250 $self->add (my $hpane = new Gtk2::HPaned);
231 gtk::state $hpane, "game::hpane", undef, position => 500; 251 gtk::state $hpane, "game::hpane", undef, position => 420;
232 252
233 # LEFT PANE 253 # LEFT PANE
234 254
235 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0); 255 $hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0);
236 256
237 $self->{boardbox} = new Gtk2::VBox;
238
239 $hpane->pack1((my $vbox = new Gtk2::VBox), 1, 1); 257 $hpane->pack1((my $vbox = new Gtk2::VBox), 1, 1);
240 258
241 # board box (aspect/canvas) 259 # board box (aspect/canvas)
242 260
243 #$self->{boardbox}->pack_start((my $frame = new Gtk2::Frame), 0, 1, 0);
244
245 # RIGHT PANE 261 # RIGHT PANE
246 262
247 $hpane->pack2 ((my $vbox = new Gtk2::VBox), 1, 1); 263 $hpane->pack2 ((my $vbox = new Gtk2::VBox), 1, 1);
248 $hpane->set (position_set => 1); 264 $hpane->set (position_set => 1);
249 265
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 $title); 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, 1, 0); 275 $hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 0, 0);
259 276
260 $self->{moveadj} = new Gtk2::Adjustment 1, 1, 1, 1, 5, 0; 277 $self->{moveadj} = new Gtk2::Adjustment 1, 1, 1, 1, 5, 0;
261 278
262 $hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0); 279 $hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0);
263 $scale->set_draw_value (0); 280 $scale->set_draw_value (0);
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", no_show_all => 1, 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 $buttonbox->add ($self->{button_undo} = 301 $buttonbox->add ($self->{button_undo} =
285 Gtk2::Button->Glib::Object::new (label => "Undo", no_show_all => 1, visible => 0)); 302 Gtk2::Button->Glib::Object::new (label => "Undo", visible => 0, no_show_all => 1));
286 $self->{button_undo}->signal_connect (clicked => sub { 303 $self->{button_undo}->signal_connect (clicked => sub {
287 $self->send (req_undo => channel => $self->{channel}); 304 $self->send (req_undo => channel => $self->{channel});
288 }); 305 });
289 $buttonbox->add ($self->{button_resign} = 306 $buttonbox->add ($self->{button_resign} =
290 Gtk2::Button->Glib::Object::new (label => "Resign", no_show_all => 1, visible => 0)); 307 Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0, no_show_all => 1));
291 $self->{button_resign}->signal_connect (clicked => sub { 308 $self->{button_resign}->signal_connect (clicked => sub {
292 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); 309 $self->send (resign_game => channel => $self->{channel}, player => $self->{colour});
293 }); 310 });
294 311
295 $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 });
296 317
297 $self->set_channel ($self->{channel}); 318 $self->set_channel ($self->{channel});
298 319
299 $self->show_all; 320 $self->show_all;
300 321
304sub set_channel { 325sub set_channel {
305 my ($self, $channel) = @_; 326 my ($self, $channel) = @_;
306 327
307 $self->{channel} = $channel; 328 $self->{channel} = $channel;
308 329
309 if ($self->{channel} > 0) { 330 if (defined $self->{channel}) {
310 $self->listen ($self->{conn}); 331 $self->listen ($self->{conn});
311 332
312 $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);
313 $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);
314 335
315 $self->signal_connect (delete_event => sub { $self->part; 1 }); 336 $self->signal_connect (delete_event => sub { $self->part; 1 });
316 $self->{chat}->signal_connect (command => sub { 337 $self->{chat}->signal_connect (command => sub {
317 my ($chat, $cmd, $arg) = @_; 338 my ($chat, $cmd, $arg) = @_;
318 if ($cmd eq "rsave") { 339 if ($cmd eq "rsave") {
340 local $Storable::forgive_me = 1;
319 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#
320 } else { 343 } else {
321 $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);
322 } 345 }
323 }); 346 });
324 } 347 }
331 return if $self->{joined}; 354 return if $self->{joined};
332 355
333 $self->SUPER::join; 356 $self->SUPER::join;
334} 357}
335 358
359sub part {
360 my ($self) = @_;
361
362 $self->hide;
363 $self->SUPER::part;
364}
365
336sub event_join { 366sub event_join {
337 my ($self) = @_; 367 my ($self) = @_;
338 368
339 $self->SUPER::event_join (@_); 369 $self->SUPER::event_join (@_);
340 $self->init_tree; 370 $self->init_tree;
359 389
360sub draw_users { 390sub draw_users {
361 my ($self, $inlay) = @_; 391 my ($self, $inlay) = @_;
362 392
363 for (sort keys %{$self->{users}}) { 393 for (sort keys %{$self->{users}}) {
364 $inlay->append_text (" <user>" . $self->{users}{$_}->as_string . "</user>"); 394 $inlay->append_text ("\t<user>" . $self->{users}{$_}->as_string . "</user>");
365 } 395 }
366} 396}
367 397
368sub event_update_users { 398sub event_update_users {
369 my ($self, $add, $update, $remove) = @_; 399 my ($self, $add, $update, $remove) = @_;
379 $important{$self->{black}{name}}++; 409 $important{$self->{black}{name}}++;
380 $important{$self->{white}{name}}++; 410 $important{$self->{white}{name}}++;
381 $important{$self->{owner}{name}}++; 411 $important{$self->{owner}{name}}++;
382 412
383 if (my @users = grep $important{$_->{name}}, @$add) { 413 if (my @users = grep $important{$_->{name}}, @$add) {
384 $self->{chat}->append_text ("\n<header>Joins:</header>"); 414 $self->{chat}->append_text ("\n<leader>Joins:</leader>");
385 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 415 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
386 } 416 }
387 if (my @users = grep $important{$_->{name}}, @$remove) { 417 if (my @users = grep $important{$_->{name}}, @$remove) {
388 $self->{chat}->append_text ("\n<header>Parts:</header>"); 418 $self->{chat}->append_text ("\n<leader>Parts:</leader>");
389 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; 419 $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users;
390 } 420 }
391} 421}
392 422
393### GAME INFO ############################################################### 423### GAME INFO ###############################################################
458 488
459 return unless $self->{joined}; 489 return unless $self->{joined};
460 490
461 $self->{colour} = $self->player_colour ($self->{conn}{name}); 491 $self->{colour} = $self->player_colour ($self->{conn}{name});
462 492
463 my $title = defined $self->{channel}
464 ? $self->owner->as_string . " " . $self->opponent_string
465 : "Game Window";
466 $self->set_title ("KGS Game $title");
467 $self->{title}->set_text ($title);
468
469 $self->{user}[COLOUR_BLACK] = $self->{black}; 493 $self->{user}[COLOUR_BLACK] = $self->{black};
470 $self->{user}[COLOUR_WHITE] = $self->{white}; 494 $self->{user}[COLOUR_WHITE] = $self->{white};
471 495
472 # show board 496 # show board
473 if ($self->is_inprogress) { 497 if ($self->is_inprogress) {
474 if (!$self->{boardbox}->parent) { 498 if (!$self->{board}) {
475 $self->{boardbox}->add ($self->{board} = new Gtk2::GoBoard size => $self->{size}); 499 $self->{left}->add ($self->{board} = new Gtk2::GoBoard size => $self->{size});
476 $self->{left}->add ($self->{boardbox});
477 $self->{board}->signal_connect (button_release => sub { 500 $self->{board}->signal_connect (button_release => sub {
501 return unless $self->{cur_board};
478 if ($_[1] == 1) { 502 if ($_[1] == 1) {
479 $self->{board_click}->($_[2], $_[3]) if $self->{board_click}; 503 $self->{board_click}->($_[2], $_[3]) if $self->{board_click};
480 } 504 }
481 }); 505 });
506 $self->{board}->show_all;
482 } 507 }
483 if (my $ch = delete $self->{challenge}) { 508 if (my $ch = delete $self->{challenge}) {
484 $_->{inlay}->destroy for values %$ch; 509 $_->{inlay}->destroy for values %$ch;
485 } 510 }
486 $self->update_cursor; 511 $self->update_cursor;
487 } 512 }
488 513
489 $self->{left}->show_all; 514 my $title = defined $self->{channel}
515 ? $self->owner->as_string . " " . $self->opponent_string
516 : "Game Window";
517 $self->set_title ("KGS Game $title");
518 $self->{title}->set_text ($title); # title gets redrawn wrongly
519 $self->{title}->show; # workaround for refresh-bug
490 520
491 $self->{rules_inlay}->refresh; 521 $self->{rules_inlay}->refresh;
522
523 if (exists $self->{teacher}) {
524 $self->{teacher_inlay} ||= $self->{chat}->new_inlay;
525 $self->{teacher_inlay}->clear;
526 $self->{teacher_inlay}->append_text ("\n<header>Teacher:</header> <user>"
527 . (util::toxml $self->{teacher}) . "</user>");
528 } elsif ($self->{teacher_inlay}) {
529 (delete $self->{teacher_inlay})->clear;
492 530 }
531
532 $self->update_cursor;
493} 533}
494 534
495sub event_update_rules { 535sub event_update_rules {
496 my ($self, $rules) = @_; 536 my ($self, $rules) = @_;
497 537
498 $self->{rules} = $rules; 538 $self->{rules} = $rules;
499 539
500 if ($self->{user}) { 540 if ($self->{user}) {
541 # todo. gets drawn wrongly
542
501 $self->{userpanel}[$_]->configure ($self->{app}, $self->{user}[$_], $rules) 543 $self->{userpanel}[$_]->configure ($self->{app}, $self->{user}[$_], $rules)
502 for COLOUR_BLACK, COLOUR_WHITE; 544 for COLOUR_BLACK, COLOUR_WHITE;
503 } 545 }
504 546
505 sound::play 3, "gamestart"; 547 sound::play 3, "gamestart";
518 $self->{userpanel}[$colour]->set_timer ( 560 $self->{userpanel}[$colour]->set_timer (
519 $running && $colour == $self->{whosemove} && $t->[0], 561 $running && $colour == $self->{whosemove} && $t->[0],
520 $t->[1] || $self->{rules}{time} 562 $t->[1] || $self->{rules}{time}
521 + ($self->{rules}{timesys} == TIMESYS_BYO_YOMI 563 + ($self->{rules}{timesys} == TIMESYS_BYO_YOMI
522 && $self->{rules}{interval} * $self->{rules}{count}), 564 && $self->{rules}{interval} * $self->{rules}{count}),
523 $t->[2] || $self->{rules}{count}); 565 $t->[2]);
524 } 566 }
525} 567}
526 568
527sub inject_set_gametime { 569sub inject_set_gametime {
528 my ($self, $msg) = @_; 570 my ($self, $msg) = @_;
537} 579}
538 580
539sub update_cursor { 581sub update_cursor {
540 my ($self) = @_; 582 my ($self) = @_;
541 583
584 return unless $self->{cur_board};
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
542 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; 603 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active;
543 604
544 delete $self->{board_click}; 605 delete $self->{board_click};
545 606
546 if ($self->{teacher} eq $self->{app}{conn}) { 607 if ($self->{teacher} eq $self->{app}{conn}) {
547 #TODO# # teaching mode not implemented 608 #TODO# # teaching mode not implemented
548 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 609 $self->{button_pass}->set (label => "Pass", sensitive => 1);
610 $self->{button_pass}->show;
549 $self->{button_undo}->hide; 611 $self->{button_undo}->hide;
550 $self->{button_resign}->hide; 612 $self->{button_resign}->hide;
551 $self->{board}->set (cursor => undef); 613 $self->{board}->set (cursor => undef);
552 614
553 } elsif ($running && $self->{colour} != COLOUR_NONE) { 615 } elsif ($running && $self->{colour} != COLOUR_NONE) {
555 $self->{button_undo}->show; 617 $self->{button_undo}->show;
556 $self->{button_resign}->show; 618 $self->{button_resign}->show;
557 619
558 if ($self->{cur_board}{score}) { 620 if ($self->{cur_board}{score}) {
559 # during scoring 621 # during scoring
560 $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); 622 $self->{button_pass}->set (label => "Done", sensitive => 1);
623 $self->{button_pass}->show;
561 $self->{board}->set (cursor => sub { 624 $self->{board}->set (cursor => sub {
562 $_[0] & (MARK_B | MARK_W) 625 $_[0] & (MARK_B | MARK_W)
563 ? $_[0] ^ MARK_GRAYED 626 ? $_[0] ^ MARK_GRAYED
564 : $_[0]; 627 : $_[0];
565 }); 628 });
577 } 640 }
578 }; 641 };
579 642
580 } elsif ($self->{colour} == $self->{whosemove}) { 643 } elsif ($self->{colour} == $self->{whosemove}) {
581 # normal move 644 # normal move
582 $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); 645 $self->{button_pass}->set (label => "Pass", sensitive => 1);
646 $self->{button_pass}->show;
583 $self->{board}->set (cursor => sub { 647 $self->{board}->set (cursor => sub {
584 # if is_valid_move oder so#TODO# 648 $self->{cur_board}
585 $_[0] & (MARK_B | MARK_W) 649 && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2],
586 ? $_[0] 650 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND)
587 : $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B); 651 ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B)
652 : $_[0];
588 }); 653 });
589 $self->{board_click} = sub { 654 $self->{board_click} = sub {
655 return unless
656 $self->{cur_board}->is_valid_move ($self->{colour}, $_[0], $_[1],
657 $self->{rules}{ruleset} == RULESET_NEW_ZEALAND);
590 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); 658 $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]);
591 $self->{board}->set (cursor => undef); 659 $self->{board}->set (cursor => undef);
592 delete $self->{board_click}; 660 delete $self->{board_click};
593 $self->{button_pass}->sensitive (0); 661 $self->{button_pass}->sensitive (0);
594 }; 662 };
595 } else { 663 } else {
596 $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); 664 $self->{button_pass}->set (label => "Pass", sensitive => 0);
665 $self->{button_pass}->show;
597 $self->{board}->set (cursor => undef); 666 $self->{board}->set (cursor => undef);
598 } 667 }
599 } else { 668 } else {
600 $self->{button_undo}->hide; 669 $self->{button_undo}->hide;
601 $self->{button_resign}->hide; 670 $self->{button_resign}->hide;
605 } 674 }
606} 675}
607 676
608sub update_board { 677sub update_board {
609 my ($self) = @_; 678 my ($self) = @_;
679
610 return unless $self->{path}; 680 return unless $self->{path};
611 681
612 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); 682 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
613 683
614 $self->{cur_board} = new KGS::Game::Board $self->{size}; 684 $self->{cur_board} = new KGS::Game::Board $self->{size};
615 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); 685 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
616 686
617 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 687 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
618 for COLOUR_WHITE, COLOUR_BLACK; 688 for COLOUR_WHITE, COLOUR_BLACK;
619 689
620 if ($self->{rules}{ruleset} == RULESET_JAPANESE) { 690 $self->{board}->set_board ($self->{cur_board});
621 if ($self->{curnode}{move} == 0) {
622 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
623 } else {
624 $self->{whosemove} = 1 - $self->{cur_board}{last};
625 }
626 } else {
627 # Chinese, Aga, NZ all have manual placement
628 if ($self->{curnode}{move} < $self->{handicap}) {
629 $self->{whosemove} = COLOUR_BLACK;
630 } elsif ($self->{curnode}{move} == $self->{handicap}) {
631 $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK;
632 } else {
633 $self->{whosemove} = 1 - $self->{cur_board}{last};
634 }
635 }
636 691
637 my $start_time = $self->{rules}{time}; 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;
638 705
639 if ($self->{showmove} == @{$self->{path}}) { 706 if ($self->{showmove} == @{$self->{path}}) {
640 $self->{timers} = [ 707 $self->{timers} = [
641 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], 708 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}],
642 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], 709 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}],
647 [0, @{$self->{cur_board}{timer}[0]}], 714 [0, @{$self->{cur_board}{timer}[0]}],
648 [0, @{$self->{cur_board}{timer}[1]}], 715 [0, @{$self->{cur_board}{timer}[1]}],
649 ]); 716 ]);
650 } 717 }
651 718
652 $self->{board}->set_board ($self->{cur_board});
653
654 if ($self->{cur_board}{score}) {
655 $self->{score_inlay} ||= $self->{chat}->new_inlay;
656 $self->{score_inlay}->clear;
657 $self->{score_inlay}->append_text ("\n<header>Scoring</header>"
658 . "\n<score>"
659 . "White: $self->{cur_board}{score}[COLOUR_WHITE], "
660 . "Black: $self->{cur_board}{score}[COLOUR_BLACK]"
661 . "</score>");
662 } elsif ($self->{score_inlay}) {
663 (delete $self->{score_inlay})->clear;
664 }
665
666 $self->update_cursor;
667} 719}
668 720
669sub event_update_tree { 721sub event_update_tree {
670 my ($self) = @_; 722 my ($self) = @_;
671 723
689 } 741 }
690} 742}
691 743
692sub event_update_comments { 744sub event_update_comments {
693 my ($self, $node, $comment, $newnode) = @_; 745 my ($self, $node, $comment, $newnode) = @_;
694 $self->SUPER::event_update_comments($node, $comment, $newnode); 746 $self->SUPER::event_update_comments ($node, $comment, $newnode);
695 747
696 my $text; 748 my $text;
697 749
698 $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>"
699 if $newnode; 751 if $newnode;
738 my ($self, $player) = @_; 790 my ($self, $player) = @_;
739 791
740 sound::play 3, "resign"; 792 sound::play 3, "resign";
741 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>" 793 $self->{chat}->append_text ("\n<infoblock><header>Resign</header>"
742 . "\n<user>" 794 . "\n<user>"
743 . (util::toxml $self->{user}[$msg->{player}]->as_string) 795 . (util::toxml $self->{user}[$player]->as_string)
744 . "</user> resigned.</infoblock>"); 796 . "</user> resigned."
797 . "\n<user>"
798 . (util::toxml $self->{user}[1 - $player]->as_string)
799 . "</user> wins the game."
800 . "</infoblock>");
745} 801}
746 802
747sub event_out_of_time { 803sub event_out_of_time {
748 my ($self, $player) = @_; 804 my ($self, $player) = @_;
749 805
750 sound::play 3, "timewin"; 806 sound::play 3, "timewin";
751 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>" 807 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>"
752 . "\n<user>" 808 . "\n<user>"
809 . (util::toxml $self->{user}[$msg->{1 - player}]->as_string)
810 . "</user> ran out of time and lost."
811 . "\n<user>"
753 . (util::toxml $self->{user}[$msg->{player}]->as_string) 812 . (util::toxml $self->{user}[$msg->{player}]->as_string)
813 . "</user> wins the game."
814 . "</infoblock>");
815}
816
817sub event_owner_left {
818 my ($self) = @_;
819
820 $self->{chat}->append_text ("\n<infoblock><header>Owner left</header>"
754 . "</user> ran out of time and lost.</infoblock>"); 821 . "\nThe owner of this game left.</infoblock>");
822}
823
824sub event_teacher_left {
825 my ($self) = @_;
826
827 $self->{chat}->append_text ("\n<infoblock><header>Teacher left</header>"
828 . "\nThe teacher left the game.</infoblock>");
755} 829}
756 830
757sub event_done { 831sub event_done {
758 my ($self) = @_; 832 my ($self) = @_;
759 833
831 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;;
832 my $opponent = $as_black ? $info->{white} : $info->{black}; 906 my $opponent = $as_black ? $info->{white} : $info->{black};
833 907
834 my ($size, $time, $interval, $count, $type); 908 my ($size, $time, $interval, $count, $type);
835 909
836 if (!$self->{channel}) { 910 if (!defined $self->{channel}) {
837 $inlay->append_text ("\nNotes: "); 911 $inlay->append_text ("\nNotes: ");
838 $inlay->append_entry (\$info->{notes}, 20, ""); 912 $inlay->append_widget (gtk::textentry \$info->{notes}, 20, "");
839 $inlay->append_text ("\nGlobal Offer: "); 913 $inlay->append_text ("\nGlobal Offer: ");
840 $inlay->append_optionmenu (\$info->{flags}, 914 $inlay->append_optionmenu (\$info->{flags},
841 0 => "No", 915 0 => "No",
842 2 => "Yes", 916 2 => "Yes",
843 ); 917 );
858 sub { 932 sub {
859 $size->set_history (2) if $_[0] eq GAMETYPE_RATED; 933 $size->set_history (2) if $_[0] eq GAMETYPE_RATED;
860 }, 934 },
861 ); 935 );
862 936
863 if ($self->{channel}) { 937 if (defined $self->{channel}) {
864 $inlay->append_text ("\nMy Colour: "); 938 $inlay->append_text ("\nMy Colour: ");
865 $inlay->append_optionmenu ( 939 $inlay->append_optionmenu (
866 \$as_black, 940 \$as_black,
867 0 => "White", 941 0 => "White",
868 1 => "Black", 942 1 => "Black",
891 $type->set_history (5) # reset to free 965 $type->set_history (5) # reset to free
892 if $_[0] != 19 && $info->{gametype} == GAMETYPE_RATED; 966 if $_[0] != 19 && $info->{gametype} == GAMETYPE_RATED;
893 }, 967 },
894 ); 968 );
895 969
896 if ($self->{channel}) { 970 if (defined $self->{channel}) {
897 $inlay->append_text ("\nHandicap: "); 971 $inlay->append_text ("\nHandicap: ");
898 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); 972 $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9);
899 973
900 $inlay->append_text ("\nKomi: "); 974 $inlay->append_text ("\nKomi: ");
901 $inlay->append_entry (\$info->{rules}{komi}, 5); 975 $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5);
902 } 976 }
903 977
904 $inlay->append_text ("\nTimesys: "); 978 $inlay->append_text ("\nTimesys: ");
905 $inlay->append_optionmenu ( 979 $inlay->append_optionmenu (
906 \$info->{rules}{timesys}, 980 \$info->{rules}{timesys},
935 } 1009 }
936 } 1010 }
937 ); 1011 );
938 1012
939 $inlay->append_text ("\nMain Time: "); 1013 $inlay->append_text ("\nMain Time: ");
940 $time = $inlay->append_entry (\$info->{rules}{time}, 5); 1014 $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5);
941 $inlay->append_text ("\nInterval: "); 1015 $inlay->append_text ("\nInterval: ");
942 $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); 1016 $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5);
943 $inlay->append_text ("\nPeriods/Stones: "); 1017 $inlay->append_text ("\nPeriods/Stones: ");
944 $count = $inlay->append_entry (\$info->{rules}{count}, 2); 1018 $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5);
945 1019
946 $inlay->append_text ("\n"); 1020 $inlay->append_text ("\n");
947 1021
948 if (!$self->{channel}) { 1022 if (!defined $self->{channel}) {
949 $inlay->append_button ("Create Challenge", sub { 1023 $inlay->append_button ("Create Challenge", sub {
950 $inlay->clear; 1024 $inlay->clear;
951 $self->{cid} = $self->{conn}->alloc_clientid; 1025 $self->{cid} = $self->{conn}->alloc_clientid;
952 $self->send (new_game => 1026 $self->send (new_game =>
953 channel => delete $self->{roomid}, 1027 channel => delete $self->{roomid},

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines