… | |
… | |
34 | sub configure { |
34 | sub 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 | |
136 | package game::userpanel; |
136 | package game::userpanel; |
137 | |
137 | |
|
|
138 | use KGS::Constants; |
|
|
139 | |
138 | use Glib::Object::Subclass |
140 | use 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 | |
144 | sub INIT_INSTANCE { |
148 | sub 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 | |
|
|
164 | sub 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 | |
158 | sub configure { |
172 | sub 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 | |
215 | use POSIX qw(ceil); |
233 | use POSIX qw(ceil); |
216 | |
234 | |
217 | sub new { |
235 | sub 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 "-"); |
255 | |
271 | |
256 | $vbox->add (my $hbox = new Gtk2::HBox); |
272 | $vbox->add (my $hbox = new Gtk2::HBox); |
257 | |
273 | |
258 | $hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 1, 0); |
274 | $hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 0, 0); |
259 | |
275 | |
260 | $self->{moveadj} = new Gtk2::Adjustment 1, 1, 1, 1, 5, 0; |
276 | $self->{moveadj} = new Gtk2::Adjustment 1, 1, 1, 1, 5, 0; |
261 | |
277 | |
262 | $hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0); |
278 | $hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0); |
263 | $scale->set_draw_value (0); |
279 | $scale->set_draw_value (0); |
… | |
… | |
275 | for COLOUR_WHITE, COLOUR_BLACK; |
291 | for COLOUR_WHITE, COLOUR_BLACK; |
276 | |
292 | |
277 | $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); |
293 | $vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); |
278 | |
294 | |
279 | $buttonbox->add ($self->{button_pass} = |
295 | $buttonbox->add ($self->{button_pass} = |
280 | Gtk2::Button->Glib::Object::new (label => "Pass", no_show_all => 1, visible => 0)); |
296 | Gtk2::Button->Glib::Object::new (label => "Pass", visible => 0)); |
281 | $self->{button_pass}->signal_connect (clicked => sub { |
297 | $self->{button_pass}->signal_connect (clicked => sub { |
282 | $self->{board_click}->(255, 255) if $self->{board_click}; |
298 | $self->{board_click}->(255, 255) if $self->{board_click}; |
283 | }); |
299 | }); |
|
|
300 | eval { $self->{button_pass}->set (no_show_all => 1) }; # workaround for gtk+-2.2 |
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)); |
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 | }); |
|
|
306 | eval { $self->{button_undo}->set (no_show_all => 1) }; # workaround for gtk+-2.2 |
289 | $buttonbox->add ($self->{button_resign} = |
307 | $buttonbox->add ($self->{button_resign} = |
290 | Gtk2::Button->Glib::Object::new (label => "Resign", no_show_all => 1, visible => 0)); |
308 | Gtk2::Button->Glib::Object::new (label => "Resign", visible => 0)); |
291 | $self->{button_resign}->signal_connect (clicked => sub { |
309 | $self->{button_resign}->signal_connect (clicked => sub { |
292 | $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); |
310 | $self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); |
293 | }); |
311 | }); |
|
|
312 | eval { $self->{button_resign}->set (no_show_all => 1) }; # workaround for gtk+-2.2 |
294 | |
313 | |
295 | $vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); |
314 | $vbox->pack_start (($self->{chat} = new chat), 1, 1, 0); |
296 | |
315 | |
297 | $self->set_channel ($self->{channel}); |
316 | $self->set_channel ($self->{channel}); |
298 | |
317 | |
299 | $self->show_all; |
318 | $self->show_all; |
300 | |
319 | |
… | |
… | |
331 | return if $self->{joined}; |
350 | return if $self->{joined}; |
332 | |
351 | |
333 | $self->SUPER::join; |
352 | $self->SUPER::join; |
334 | } |
353 | } |
335 | |
354 | |
|
|
355 | sub part { |
|
|
356 | my ($self) = @_; |
|
|
357 | |
|
|
358 | $self->hide; |
|
|
359 | $self->SUPER::part; |
|
|
360 | } |
|
|
361 | |
336 | sub event_join { |
362 | sub event_join { |
337 | my ($self) = @_; |
363 | my ($self) = @_; |
338 | |
364 | |
339 | $self->SUPER::event_join (@_); |
365 | $self->SUPER::event_join (@_); |
340 | $self->init_tree; |
366 | $self->init_tree; |
… | |
… | |
379 | $important{$self->{black}{name}}++; |
405 | $important{$self->{black}{name}}++; |
380 | $important{$self->{white}{name}}++; |
406 | $important{$self->{white}{name}}++; |
381 | $important{$self->{owner}{name}}++; |
407 | $important{$self->{owner}{name}}++; |
382 | |
408 | |
383 | if (my @users = grep $important{$_->{name}}, @$add) { |
409 | if (my @users = grep $important{$_->{name}}, @$add) { |
384 | $self->{chat}->append_text ("\n<header>Joins:</header>"); |
410 | $self->{chat}->append_text ("\n<leader>Joins:</leader>"); |
385 | $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; |
411 | $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; |
386 | } |
412 | } |
387 | if (my @users = grep $important{$_->{name}}, @$remove) { |
413 | if (my @users = grep $important{$_->{name}}, @$remove) { |
388 | $self->{chat}->append_text ("\n<header>Parts:</header>"); |
414 | $self->{chat}->append_text ("\n<leader>Parts:</leader>"); |
389 | $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; |
415 | $self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; |
390 | } |
416 | } |
391 | } |
417 | } |
392 | |
418 | |
393 | ### GAME INFO ############################################################### |
419 | ### GAME INFO ############################################################### |
… | |
… | |
458 | |
484 | |
459 | return unless $self->{joined}; |
485 | return unless $self->{joined}; |
460 | |
486 | |
461 | $self->{colour} = $self->player_colour ($self->{conn}{name}); |
487 | $self->{colour} = $self->player_colour ($self->{conn}{name}); |
462 | |
488 | |
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}; |
489 | $self->{user}[COLOUR_BLACK] = $self->{black}; |
470 | $self->{user}[COLOUR_WHITE] = $self->{white}; |
490 | $self->{user}[COLOUR_WHITE] = $self->{white}; |
471 | |
491 | |
472 | # show board |
492 | # show board |
473 | if ($self->is_inprogress) { |
493 | if ($self->is_inprogress) { |
474 | if (!$self->{boardbox}->parent) { |
494 | if (!$self->{board}) { |
475 | $self->{boardbox}->add ($self->{board} = new Gtk2::GoBoard size => $self->{size}); |
495 | $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 { |
496 | $self->{board}->signal_connect (button_release => sub { |
|
|
497 | return unless $self->{cur_board}; |
478 | if ($_[1] == 1) { |
498 | if ($_[1] == 1) { |
479 | $self->{board_click}->($_[2], $_[3]) if $self->{board_click}; |
499 | $self->{board_click}->($_[2], $_[3]) if $self->{board_click}; |
480 | } |
500 | } |
481 | }); |
501 | }); |
|
|
502 | $self->{board}->show_all; |
482 | } |
503 | } |
483 | if (my $ch = delete $self->{challenge}) { |
504 | if (my $ch = delete $self->{challenge}) { |
484 | $_->{inlay}->destroy for values %$ch; |
505 | $_->{inlay}->destroy for values %$ch; |
485 | } |
506 | } |
486 | $self->update_cursor; |
507 | $self->update_cursor; |
487 | } |
508 | } |
488 | |
509 | |
489 | $self->{left}->show_all; |
510 | my $title = defined $self->{channel} |
|
|
511 | ? $self->owner->as_string . " " . $self->opponent_string |
|
|
512 | : "Game Window"; |
|
|
513 | $self->set_title ("KGS Game $title"); |
|
|
514 | $self->{title}->set_text ($title); # title gets redrawn wrongly |
490 | |
515 | |
491 | $self->{rules_inlay}->refresh; |
516 | $self->{rules_inlay}->refresh; |
|
|
517 | |
|
|
518 | if (exists $self->{teacher}) { |
|
|
519 | $self->{teacher_inlay} ||= $self->{chat}->new_inlay; |
|
|
520 | $self->{teacher_inlay}->clear; |
|
|
521 | $self->{teacher_inlay}->append_text ("\n<header>Teacher:</header> <user>" |
|
|
522 | . (util::toxml $self->{teacher}) . "</user>"); |
|
|
523 | } elsif ($self->{teacher_inlay}) { |
|
|
524 | (delete $self->{teacher_inlay})->clear; |
492 | |
525 | } |
|
|
526 | |
|
|
527 | $self->update_cursor; |
493 | } |
528 | } |
494 | |
529 | |
495 | sub event_update_rules { |
530 | sub event_update_rules { |
496 | my ($self, $rules) = @_; |
531 | my ($self, $rules) = @_; |
497 | |
532 | |
498 | $self->{rules} = $rules; |
533 | $self->{rules} = $rules; |
499 | |
534 | |
500 | if ($self->{user}) { |
535 | if ($self->{user}) { |
|
|
536 | # todo. gets drawn wrongly |
|
|
537 | |
501 | $self->{userpanel}[$_]->configure ($self->{app}, $self->{user}[$_], $rules) |
538 | $self->{userpanel}[$_]->configure ($self->{app}, $self->{user}[$_], $rules) |
502 | for COLOUR_BLACK, COLOUR_WHITE; |
539 | for COLOUR_BLACK, COLOUR_WHITE; |
503 | } |
540 | } |
504 | |
541 | |
505 | sound::play 3, "gamestart"; |
542 | sound::play 3, "gamestart"; |
… | |
… | |
518 | $self->{userpanel}[$colour]->set_timer ( |
555 | $self->{userpanel}[$colour]->set_timer ( |
519 | $running && $colour == $self->{whosemove} && $t->[0], |
556 | $running && $colour == $self->{whosemove} && $t->[0], |
520 | $t->[1] || $self->{rules}{time} |
557 | $t->[1] || $self->{rules}{time} |
521 | + ($self->{rules}{timesys} == TIMESYS_BYO_YOMI |
558 | + ($self->{rules}{timesys} == TIMESYS_BYO_YOMI |
522 | && $self->{rules}{interval} * $self->{rules}{count}), |
559 | && $self->{rules}{interval} * $self->{rules}{count}), |
523 | $t->[2] || $self->{rules}{count}); |
560 | $t->[2]); |
524 | } |
561 | } |
525 | } |
562 | } |
526 | |
563 | |
527 | sub inject_set_gametime { |
564 | sub inject_set_gametime { |
528 | my ($self, $msg) = @_; |
565 | my ($self, $msg) = @_; |
… | |
… | |
537 | } |
574 | } |
538 | |
575 | |
539 | sub update_cursor { |
576 | sub update_cursor { |
540 | my ($self) = @_; |
577 | my ($self) = @_; |
541 | |
578 | |
|
|
579 | return unless $self->{cur_board}; |
|
|
580 | |
|
|
581 | if ($self->{rules}{ruleset} == RULESET_JAPANESE) { |
|
|
582 | if ($self->{curnode}{move} == 0) { |
|
|
583 | $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; |
|
|
584 | } else { |
|
|
585 | $self->{whosemove} = 1 - $self->{cur_board}{last}; |
|
|
586 | } |
|
|
587 | } else { |
|
|
588 | # Chinese, Aga, NZ all have manual placement |
|
|
589 | if ($self->{curnode}{move} < $self->{handicap}) { |
|
|
590 | $self->{whosemove} = COLOUR_BLACK; |
|
|
591 | } elsif ($self->{curnode}{move} == $self->{handicap}) { |
|
|
592 | $self->{whosemove} = $self->{handicap} ? COLOUR_WHITE : COLOUR_BLACK; |
|
|
593 | } else { |
|
|
594 | $self->{whosemove} = 1 - $self->{cur_board}{last}; |
|
|
595 | } |
|
|
596 | } |
|
|
597 | |
542 | my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; |
598 | my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; |
543 | |
599 | |
544 | delete $self->{board_click}; |
600 | delete $self->{board_click}; |
545 | |
601 | |
546 | if ($self->{teacher} eq $self->{app}{conn}) { |
602 | if ($self->{teacher} eq $self->{app}{conn}) { |
547 | #TODO# # teaching mode not implemented |
603 | #TODO# # teaching mode not implemented |
548 | $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); |
604 | $self->{button_pass}->set (label => "Pass", sensitive => 1); |
|
|
605 | $self->{button_pass}->show; |
549 | $self->{button_undo}->hide; |
606 | $self->{button_undo}->hide; |
550 | $self->{button_resign}->hide; |
607 | $self->{button_resign}->hide; |
551 | $self->{board}->set (cursor => undef); |
608 | $self->{board}->set (cursor => undef); |
552 | |
609 | |
553 | } elsif ($running && $self->{colour} != COLOUR_NONE) { |
610 | } elsif ($running && $self->{colour} != COLOUR_NONE) { |
… | |
… | |
555 | $self->{button_undo}->show; |
612 | $self->{button_undo}->show; |
556 | $self->{button_resign}->show; |
613 | $self->{button_resign}->show; |
557 | |
614 | |
558 | if ($self->{cur_board}{score}) { |
615 | if ($self->{cur_board}{score}) { |
559 | # during scoring |
616 | # during scoring |
560 | $self->{button_pass}->set (label => "Done", visible => 1, sensitive => 1); |
617 | $self->{button_pass}->set (label => "Done", sensitive => 1); |
|
|
618 | $self->{button_pass}->show; |
561 | $self->{board}->set (cursor => sub { |
619 | $self->{board}->set (cursor => sub { |
562 | $_[0] & (MARK_B | MARK_W) |
620 | $_[0] & (MARK_B | MARK_W) |
563 | ? $_[0] ^ MARK_GRAYED |
621 | ? $_[0] ^ MARK_GRAYED |
564 | : $_[0]; |
622 | : $_[0]; |
565 | }); |
623 | }); |
… | |
… | |
577 | } |
635 | } |
578 | }; |
636 | }; |
579 | |
637 | |
580 | } elsif ($self->{colour} == $self->{whosemove}) { |
638 | } elsif ($self->{colour} == $self->{whosemove}) { |
581 | # normal move |
639 | # normal move |
582 | $self->{button_pass}->set (label => "Pass", visible => 1, sensitive => 1); |
640 | $self->{button_pass}->set (label => "Pass", sensitive => 1); |
|
|
641 | $self->{button_pass}->show; |
583 | $self->{board}->set (cursor => sub { |
642 | $self->{board}->set (cursor => sub { |
584 | # if is_valid_move oder so#TODO# |
643 | $self->{cur_board} |
585 | $_[0] & (MARK_B | MARK_W) |
644 | && $self->{cur_board}->is_valid_move ($self->{colour}, $_[1], $_[2], |
586 | ? $_[0] |
645 | $self->{rules}{ruleset} == RULESET_NEW_ZEALAND) |
587 | : $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B); |
646 | ? $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B) |
|
|
647 | : $_[0]; |
588 | }); |
648 | }); |
589 | $self->{board_click} = sub { |
649 | $self->{board_click} = sub { |
|
|
650 | return unless |
|
|
651 | $self->{cur_board}->is_valid_move ($self->{colour}, $_[0], $_[1], |
|
|
652 | $self->{rules}{ruleset} == RULESET_NEW_ZEALAND); |
590 | $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); |
653 | $self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); |
591 | $self->{board}->set (cursor => undef); |
654 | $self->{board}->set (cursor => undef); |
592 | delete $self->{board_click}; |
655 | delete $self->{board_click}; |
593 | $self->{button_pass}->sensitive (0); |
656 | $self->{button_pass}->sensitive (0); |
594 | }; |
657 | }; |
595 | } else { |
658 | } else { |
596 | $self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); |
659 | $self->{button_pass}->set (label => "Pass", sensitive => 0); |
|
|
660 | $self->{button_pass}->show; |
597 | $self->{board}->set (cursor => undef); |
661 | $self->{board}->set (cursor => undef); |
598 | } |
662 | } |
599 | } else { |
663 | } else { |
600 | $self->{button_undo}->hide; |
664 | $self->{button_undo}->hide; |
601 | $self->{button_resign}->hide; |
665 | $self->{button_resign}->hide; |
… | |
… | |
605 | } |
669 | } |
606 | } |
670 | } |
607 | |
671 | |
608 | sub update_board { |
672 | sub update_board { |
609 | my ($self) = @_; |
673 | my ($self) = @_; |
|
|
674 | |
610 | return unless $self->{path}; |
675 | return unless $self->{path}; |
611 | |
676 | |
612 | $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); |
677 | $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); |
613 | |
678 | |
614 | $self->{cur_board} = new KGS::Game::Board $self->{size}; |
679 | $self->{cur_board} = new KGS::Game::Board $self->{size}; |
615 | $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); |
680 | $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); |
616 | |
681 | |
617 | $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) |
682 | $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) |
618 | for COLOUR_WHITE, COLOUR_BLACK; |
683 | for COLOUR_WHITE, COLOUR_BLACK; |
619 | |
684 | |
620 | if ($self->{rules}{ruleset} == RULESET_JAPANESE) { |
685 | $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 | |
686 | |
637 | my $start_time = $self->{rules}{time}; |
687 | if ($self->{cur_board}{score}) { |
|
|
688 | $self->{score_inlay} ||= $self->{chat}->new_inlay; |
|
|
689 | $self->{score_inlay}->clear; |
|
|
690 | $self->{score_inlay}->append_text ("\n<header>Scoring</header>" |
|
|
691 | . "\n<score>" |
|
|
692 | . "White: $self->{cur_board}{score}[COLOUR_WHITE], " |
|
|
693 | . "Black: $self->{cur_board}{score}[COLOUR_BLACK]" |
|
|
694 | . "</score>"); |
|
|
695 | } elsif ($self->{score_inlay}) { |
|
|
696 | (delete $self->{score_inlay})->clear; |
|
|
697 | } |
|
|
698 | |
|
|
699 | $self->update_cursor; |
638 | |
700 | |
639 | if ($self->{showmove} == @{$self->{path}}) { |
701 | if ($self->{showmove} == @{$self->{path}}) { |
640 | $self->{timers} = [ |
702 | $self->{timers} = [ |
641 | [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], |
703 | [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], |
642 | [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], |
704 | [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], |
… | |
… | |
647 | [0, @{$self->{cur_board}{timer}[0]}], |
709 | [0, @{$self->{cur_board}{timer}[0]}], |
648 | [0, @{$self->{cur_board}{timer}[1]}], |
710 | [0, @{$self->{cur_board}{timer}[1]}], |
649 | ]); |
711 | ]); |
650 | } |
712 | } |
651 | |
713 | |
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 | } |
714 | } |
668 | |
715 | |
669 | sub event_update_tree { |
716 | sub event_update_tree { |
670 | my ($self) = @_; |
717 | my ($self) = @_; |
671 | |
718 | |
… | |
… | |
689 | } |
736 | } |
690 | } |
737 | } |
691 | |
738 | |
692 | sub event_update_comments { |
739 | sub event_update_comments { |
693 | my ($self, $node, $comment, $newnode) = @_; |
740 | my ($self, $node, $comment, $newnode) = @_; |
694 | $self->SUPER::event_update_comments($node, $comment, $newnode); |
741 | $self->SUPER::event_update_comments ($node, $comment, $newnode); |
695 | |
742 | |
696 | my $text; |
743 | my $text; |
697 | |
744 | |
698 | $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>" |
745 | $text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>" |
699 | if $newnode; |
746 | if $newnode; |
… | |
… | |
738 | my ($self, $player) = @_; |
785 | my ($self, $player) = @_; |
739 | |
786 | |
740 | sound::play 3, "resign"; |
787 | sound::play 3, "resign"; |
741 | $self->{chat}->append_text ("\n<infoblock><header>Resign</header>" |
788 | $self->{chat}->append_text ("\n<infoblock><header>Resign</header>" |
742 | . "\n<user>" |
789 | . "\n<user>" |
743 | . (util::toxml $self->{user}[$msg->{player}]->as_string) |
790 | . (util::toxml $self->{user}[$player]->as_string) |
744 | . "</user> resigned.</infoblock>"); |
791 | . "</user> resigned." |
|
|
792 | . "\n<user>" |
|
|
793 | . (util::toxml $self->{user}[1 - $player]->as_string) |
|
|
794 | . "</user> wins the game." |
|
|
795 | . "</infoblock>"); |
745 | } |
796 | } |
746 | |
797 | |
747 | sub event_out_of_time { |
798 | sub event_out_of_time { |
748 | my ($self, $player) = @_; |
799 | my ($self, $player) = @_; |
749 | |
800 | |
750 | sound::play 3, "timewin"; |
801 | sound::play 3, "timewin"; |
751 | $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>" |
802 | $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>" |
752 | . "\n<user>" |
803 | . "\n<user>" |
753 | . (util::toxml $self->{user}[$msg->{player}]->as_string) |
804 | . (util::toxml $self->{user}[$msg->{player}]->as_string) |
754 | . "</user> ran out of time and lost.</infoblock>"); |
805 | . "</user> ran out of time and lost." |
|
|
806 | . "\n<user>" |
|
|
807 | . (util::toxml $self->{user}[1 - $msg->{player}]->as_string) |
|
|
808 | . "</user> wins the game." |
|
|
809 | . "</infoblock>"); |
|
|
810 | } |
|
|
811 | |
|
|
812 | sub event_owner_left { |
|
|
813 | my ($self) = @_; |
|
|
814 | |
|
|
815 | $self->{chat}->append_text ("\n<infoblock><header>Owner left</header>" |
|
|
816 | . "\nThe owner of this game left.</infoblock>"); |
|
|
817 | } |
|
|
818 | |
|
|
819 | sub event_teacher_left { |
|
|
820 | my ($self) = @_; |
|
|
821 | |
|
|
822 | $self->{chat}->append_text ("\n<infoblock><header>Teacher left</header>" |
|
|
823 | . "\nThe teacher left the game.</infoblock>"); |
755 | } |
824 | } |
756 | |
825 | |
757 | sub event_done { |
826 | sub event_done { |
758 | my ($self) = @_; |
827 | my ($self) = @_; |
759 | |
828 | |
… | |
… | |
833 | |
902 | |
834 | my ($size, $time, $interval, $count, $type); |
903 | my ($size, $time, $interval, $count, $type); |
835 | |
904 | |
836 | if (!$self->{channel}) { |
905 | if (!$self->{channel}) { |
837 | $inlay->append_text ("\nNotes: "); |
906 | $inlay->append_text ("\nNotes: "); |
838 | $inlay->append_entry (\$info->{notes}, 20, ""); |
907 | $inlay->append_widget (gtk::textentry \$info->{notes}, 20, ""); |
839 | $inlay->append_text ("\nGlobal Offer: "); |
908 | $inlay->append_text ("\nGlobal Offer: "); |
840 | $inlay->append_optionmenu (\$info->{flags}, |
909 | $inlay->append_optionmenu (\$info->{flags}, |
841 | 0 => "No", |
910 | 0 => "No", |
842 | 2 => "Yes", |
911 | 2 => "Yes", |
843 | ); |
912 | ); |
… | |
… | |
896 | if ($self->{channel}) { |
965 | if ($self->{channel}) { |
897 | $inlay->append_text ("\nHandicap: "); |
966 | $inlay->append_text ("\nHandicap: "); |
898 | $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); |
967 | $inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); |
899 | |
968 | |
900 | $inlay->append_text ("\nKomi: "); |
969 | $inlay->append_text ("\nKomi: "); |
901 | $inlay->append_entry (\$info->{rules}{komi}, 5); |
970 | $inlay->append_widget (gtk::numentry \$info->{rules}{komi}, 5); |
902 | } |
971 | } |
903 | |
972 | |
904 | $inlay->append_text ("\nTimesys: "); |
973 | $inlay->append_text ("\nTimesys: "); |
905 | $inlay->append_optionmenu ( |
974 | $inlay->append_optionmenu ( |
906 | \$info->{rules}{timesys}, |
975 | \$info->{rules}{timesys}, |
… | |
… | |
935 | } |
1004 | } |
936 | } |
1005 | } |
937 | ); |
1006 | ); |
938 | |
1007 | |
939 | $inlay->append_text ("\nMain Time: "); |
1008 | $inlay->append_text ("\nMain Time: "); |
940 | $time = $inlay->append_entry (\$info->{rules}{time}, 5); |
1009 | $time = $inlay->append_widget (gtk::timeentry \$info->{rules}{time}, 5); |
941 | $inlay->append_text ("\nInterval: "); |
1010 | $inlay->append_text ("\nInterval: "); |
942 | $interval = $inlay->append_entry (\$info->{rules}{interval}, 3); |
1011 | $interval = $inlay->append_widget (gtk::timeentry \$info->{rules}{interval}, 5); |
943 | $inlay->append_text ("\nPeriods/Stones: "); |
1012 | $inlay->append_text ("\nPeriods/Stones: "); |
944 | $count = $inlay->append_entry (\$info->{rules}{count}, 2); |
1013 | $count = $inlay->append_widget (gtk::numentry \$info->{rules}{count}, 5); |
945 | |
1014 | |
946 | $inlay->append_text ("\n"); |
1015 | $inlay->append_text ("\n"); |
947 | |
1016 | |
948 | if (!$self->{channel}) { |
1017 | if (!$self->{channel}) { |
949 | $inlay->append_button ("Create Challenge", sub { |
1018 | $inlay->append_button ("Create Challenge", sub { |