… | |
… | |
21 | $self->{format} = sub { "ERROR" }; |
21 | $self->{format} = sub { "ERROR" }; |
22 | |
22 | |
23 | $self; |
23 | $self; |
24 | } |
24 | } |
25 | |
25 | |
26 | sub set_rules { |
26 | sub configure { |
27 | my ($self, $timesys, $main, $interval, $count) = @_; |
27 | my ($self, $timesys, $main, $interval, $count) = @_; |
28 | |
28 | |
29 | if ($timesys == TIMESYS_ABSOLUTE) { |
29 | if ($timesys == TIMESYS_ABSOLUTE) { |
30 | $self->{set} = sub { $self->{time} = $_[0] }; |
30 | $self->{set} = sub { $self->{time} = $_[0] }; |
31 | $self->{format} = sub { util::format_time $_[0] }; |
31 | $self->{format} = sub { util::format_time $_[0] }; |
… | |
… | |
50 | |
50 | |
51 | $self->{format} = sub { |
51 | $self->{format} = sub { |
52 | if (!$self->{moves}) { |
52 | if (!$self->{moves}) { |
53 | util::format_time $_[0] - $low; |
53 | util::format_time $_[0] - $low; |
54 | } else { |
54 | } else { |
55 | my $time = util::format_time int (($_[0] - 1) % $interval + 1), |
55 | my $time = int (($_[0] - 1) % $interval + 1); |
|
|
56 | |
56 | sprintf "%s/%d {%d}", |
57 | sprintf "%s/%d {%d}", |
57 | util::format_time $time, |
58 | util::format_time $time, |
58 | $self->{moves}, |
59 | $self->{moves}, |
59 | $time / ($self->{moves} || 1); |
60 | $time / ($self->{moves} || 1); |
60 | |
61 | |
… | |
… | |
68 | } |
69 | } |
69 | } |
70 | } |
70 | |
71 | |
71 | sub refresh { |
72 | sub refresh { |
72 | my ($self, $timestamp) = @_; |
73 | my ($self, $timestamp) = @_; |
73 | my $timer = $self->{time} + $self->{start} - $timestamp + 0.5; |
74 | my $timer = $self->{time} + $self->{start} - $timestamp; |
74 | |
75 | |
75 | # we round the timer value slightly... the protocol isn't exact anyways, |
76 | # we round the timer value slightly... the protocol isn't exact anyways, |
76 | # and this gives smoother timers ;) |
77 | # and this gives smoother timers ;) |
|
|
78 | my @format = $self->{format}->(int ($timer + 0.4)); |
77 | $self->{widget}->set_text ($self->{format}->(int ($timer + 0.4))); |
79 | $self->{widget}->set_text ($self->{format}->(int ($timer + 0.4))); |
78 | |
80 | |
79 | $timer - int $timer; |
81 | $timer - int $timer; |
80 | } |
82 | } |
81 | |
83 | |
… | |
… | |
143 | |
145 | |
144 | $self; |
146 | $self; |
145 | } |
147 | } |
146 | |
148 | |
147 | sub configure { |
149 | sub configure { |
148 | my ($self, $name, $rules) = @_; |
150 | my ($self, $user, $rules) = @_; |
149 | |
151 | |
150 | if ($self->{name}->get_text ne $name) { |
152 | if ($self->{name}->get_text ne $user->as_string) { |
151 | $self->{name}->set_text ($name); |
153 | $self->{name}->set_text ($user->as_string); |
152 | |
154 | |
153 | $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; |
155 | $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; |
154 | $self->{imagebox}->add (gtk::image_from_data undef); |
156 | $self->{imagebox}->add (gtk::image_from_data undef); |
155 | $self->{imagebox}->show_all; |
157 | $self->{imagebox}->show_all; |
156 | |
158 | |
157 | # the big picture... |
159 | # the big picture... |
158 | appwin::userpic ($name, sub { |
160 | appwin::userpic ($user->{name}, sub { |
159 | return unless $self->{imagebox}; |
161 | return unless $self->{imagebox}; |
160 | if ($_[0]) { |
162 | if ($_[0]) { |
161 | $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; |
163 | $self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; |
162 | $self->{imagebox}->add (gtk::image_from_data $_[0]); |
164 | $self->{imagebox}->add (gtk::image_from_data $_[0]); |
163 | $self->{imagebox}->show_all; |
165 | $self->{imagebox}->show_all; |
164 | } |
166 | } |
165 | }); |
167 | }); |
166 | } |
168 | } |
167 | |
169 | |
168 | $self->{clock}->set_rules (@{$rules}{qw(timesys time interval count)}); |
170 | $self->{clock}->configure (@{$rules}{qw(timesys time interval count)}); |
169 | } |
171 | } |
170 | |
172 | |
171 | sub set_state { |
173 | sub set_state { |
172 | my ($self, $captures, $timer, $when) = @_; |
174 | my ($self, $captures, $timer, $when) = @_; |
173 | |
175 | |
… | |
… | |
371 | $size / $::shadow_img->get_width, $size / $::shadow_img->get_height, |
373 | $size / $::shadow_img->get_width, $size / $::shadow_img->get_height, |
372 | $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192 |
374 | $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192 |
373 | ); |
375 | ); |
374 | } |
376 | } |
375 | |
377 | |
376 | # first the big stones (handicap stones different for effect) |
378 | # first the big stones (handicap stones could be different) |
377 | for ([MARK_B, $mark & MARK_MOVE ? 255 : 192], |
379 | for ([MARK_B, $mark & MARK_MOVE ? 255 : 255], |
378 | [MARK_W, $mark & MARK_MOVE ? 255 : 192], |
380 | [MARK_W, $mark & MARK_MOVE ? 255 : 255], |
379 | [MARK_GRAY_B, 128], |
381 | [MARK_GRAY_B, 128], |
380 | [MARK_GRAY_W, 128]) { |
382 | [MARK_GRAY_W, 128]) { |
381 | my ($mask, $alpha) = @$_; |
383 | my ($mask, $alpha) = @$_; |
382 | if ($mark & $mask) { |
384 | if ($mark & $mask) { |
383 | $stone->composite ( |
385 | $stone->composite ( |
… | |
… | |
570 | } |
572 | } |
571 | } |
573 | } |
572 | |
574 | |
573 | $self->{pixbuf} = $pixbuf; |
575 | $self->{pixbuf} = $pixbuf; |
574 | |
576 | |
575 | # hoshi-points(!)#d# |
|
|
576 | # caching of empty board gfx(!)#d# |
|
|
577 | |
|
|
578 | for my $x (1 .. $size) { |
577 | for my $x (1 .. $size) { |
579 | for my $y (1 .. $size) { |
578 | for my $y (1 .. $size) { |
580 | my $rand = ($x ^ $y ^ 0x5555); |
579 | my $rand = ($x ^ $y ^ 0x5555); |
581 | |
580 | |
582 | my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs); |
581 | my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs); |
… | |
… | |
730 | $self->SUPER::event_update_game; |
729 | $self->SUPER::event_update_game; |
731 | |
730 | |
732 | $self->{user}[BLACK] = $self->{user1}; |
731 | $self->{user}[BLACK] = $self->{user1}; |
733 | $self->{user}[WHITE] = $self->{user2}; |
732 | $self->{user}[WHITE] = $self->{user2}; |
734 | |
733 | |
|
|
734 | # show board |
|
|
735 | |
|
|
736 | $self->{left}->remove ($_) for $self->{left}->get_children; |
|
|
737 | if ($self->is_valid) { |
|
|
738 | $self->{left}->add ($self->{boardbox}); |
|
|
739 | (delete $self->{challenge})->destroy if $self->{challenge}; |
|
|
740 | } else { |
|
|
741 | $self->{left}->add ($self->{challenge}->widget); |
|
|
742 | } |
|
|
743 | $self->{left}->show_all; |
|
|
744 | |
|
|
745 | # view text |
|
|
746 | |
735 | $text = "\n<header>Game Update</header>"; |
747 | $text = "\n<header>Game Update</header>"; |
736 | |
748 | |
737 | $text .= "\nType: " . (util::toxml $gametype{$self->type}) |
749 | $text .= "\nType: " . (util::toxml $gametype{$self->type}) |
738 | . " (" . (util::toxml $gameopt{$self->option}) . ")"; |
750 | . " (" . (util::toxml $gameopt{$self->option}) . ")"; |
739 | $text .= "\nFlags:"; |
751 | $text .= "\nFlags:"; |
… | |
… | |
750 | $text .= "\nHandicap: " . $self->{handicap}; |
762 | $text .= "\nHandicap: " . $self->{handicap}; |
751 | $text .= "\nKomi: " . $self->{komi}; |
763 | $text .= "\nKomi: " . $self->{komi}; |
752 | $text .= "\nSize: " . $self->size_string; |
764 | $text .= "\nSize: " . $self->size_string; |
753 | } |
765 | } |
754 | |
766 | |
755 | $self->{text}->append_text ($text); |
767 | $self->{text}->append_text ("<infoblock>$text</infoblock>"); |
756 | |
|
|
757 | $self->{left}->remove ($_) for $self->{left}->get_children; |
|
|
758 | if ($self->is_valid) { |
|
|
759 | $self->{left}->add ($self->{boardbox}); |
|
|
760 | (delete $self->{challenge})->destroy if $self->{challenge}; |
|
|
761 | } else { |
|
|
762 | $self->{left}->add ($self->{challenge}->widget); |
|
|
763 | } |
|
|
764 | $self->{left}->show_all; |
|
|
765 | } |
768 | } |
766 | |
769 | |
767 | sub event_update_rules { |
770 | sub event_update_rules { |
768 | my ($self, $rules) = @_; |
771 | my ($self, $rules) = @_; |
769 | |
772 | |
770 | $self->{userpanel}[$_]->configure ( |
773 | $self->{userpanel}[$_]->configure ($self->{user}[$_], $rules) |
771 | $self->{user}[$_]->as_string, # OMG.. better use self->user or something!!! |
|
|
772 | ) for BLACK, WHITE; |
774 | for BLACK, WHITE; |
773 | |
775 | |
774 | my $text = "\n<header>Game Rules</header>"; |
776 | my $text = "\n<header>Game Rules</header>"; |
775 | |
777 | |
776 | $text .= "\nRuleset: " . $ruleset{$rules->{ruleset}}; |
778 | $text .= "\nRuleset: " . $ruleset{$rules->{ruleset}}; |
777 | |
779 | |
|
|
780 | $text .= "\nTime: "; |
|
|
781 | |
778 | if ($rules->{timesys} != TIMESYS_NONE) { |
782 | if ($rules->{timesys} == TIMESYS_NONE) { |
779 | # probably subtract interval * count.. |
|
|
780 | $text .= "\nTime: " |
783 | $text .= "infinite"; |
|
|
784 | } elsif ($rules->{timesys} == TIMESYS_ABSOLUTE) { |
|
|
785 | $text .= util::format_time $rules->{time}; |
|
|
786 | } elsif ($rules->{timesys} == TIMESYS_BYO_YOMI) { |
781 | . (util::format_time $rules->{time} - $rules->{interval} * $rules->{count}) |
787 | $text .= util::format_time $rules->{time} - $rules->{interval} * $rules->{count}; |
782 | . " + "; |
|
|
783 | |
|
|
784 | $text .= sprintf "%d (%d)", $rules->{interval}, $rules->{count} |
788 | $text .= sprintf " + %s (%d)", util::format_time $rules->{interval}, $rules->{count}; |
785 | if $rules->{timesys} == TIMESYS_BYO_YOMI; |
789 | } elsif ($rules->{timesys} == TIMESYS_CANADIAN) { |
|
|
790 | $text .= util::format_time $rules->{time}; |
786 | $text .= sprintf "%d/%d", $rules->{interval}, $rules->{count} |
791 | $text .= sprintf " + %s/%d", util::format_time $rules->{interval}, $rules->{count}; |
787 | if $rules->{timesys} == TIMESYS_CANADIAN; |
|
|
788 | |
|
|
789 | $text .= " " . $timesys{$rules->{timesys}}; |
|
|
790 | } |
|
|
791 | |
792 | } |
|
|
793 | |
792 | $self->{text}->append_text ($text); |
794 | $self->{text}->append_text ("<infoblock>$text</infoblock>"); |
|
|
795 | } |
|
|
796 | |
|
|
797 | sub inject_resign_game { |
|
|
798 | my ($self, $msg) = @_; |
|
|
799 | |
|
|
800 | $self->{text}->append_text ("\n<infoblock><header>Resign</header><user>" |
|
|
801 | . (util::toxml $self->{user}[$msg->{player}]->as_string) |
|
|
802 | . "</user> resigned.</infoblock>"); |
|
|
803 | } |
|
|
804 | |
|
|
805 | sub inject_final_result { |
|
|
806 | my ($self, $msg) = @_; |
|
|
807 | |
|
|
808 | $self->{text}->append_text ("\n<header>Game Over</header>" |
|
|
809 | . "\nWhite Score " . (util::toxml $msg->{whitescore}->as_string) |
|
|
810 | . "\nBlack Score " . (util::toxml $msg->{blackscore}->as_string) |
|
|
811 | ); |
793 | } |
812 | } |
794 | |
813 | |
795 | sub destroy { |
814 | sub destroy { |
796 | my ($self) = @_; |
815 | my ($self) = @_; |
797 | $self->{userpanel}[$_] && (delete $self->{userpanel}[$_])->destroy |
816 | $self->{userpanel}[$_] && (delete $self->{userpanel}[$_])->destroy |