1 |
pcg |
1.36 |
use utf8; |
2 |
|
|
|
3 |
pcg |
1.82 |
use Scalar::Util (); |
4 |
|
|
|
5 |
pcg |
1.23 |
package game::goclock; |
6 |
|
|
|
7 |
pcg |
1.37 |
# Lo and Behold! I admit it! The rounding stuff etc.. in goclock |
8 |
|
|
# is completely borked. |
9 |
|
|
|
10 |
pcg |
1.23 |
use Time::HiRes (); |
11 |
|
|
|
12 |
|
|
use KGS::Constants; |
13 |
|
|
|
14 |
pcg |
1.82 |
use Glib::Object::Subclass |
15 |
|
|
Gtk2::Label; |
16 |
pcg |
1.23 |
|
17 |
pcg |
1.82 |
sub INIT_INSTANCE { |
18 |
|
|
my $self = shift; |
19 |
pcg |
1.23 |
|
20 |
pcg |
1.84 |
$self->signal_connect (destroy => sub { $_[0]->stop }); |
21 |
pcg |
1.83 |
|
22 |
pcg |
1.23 |
$self->{set} = sub { }; |
23 |
pcg |
1.86 |
$self->{format} = sub { "???" }; |
24 |
pcg |
1.82 |
} |
25 |
pcg |
1.23 |
|
26 |
pcg |
1.38 |
sub configure { |
27 |
pcg |
1.23 |
my ($self, $timesys, $main, $interval, $count) = @_; |
28 |
|
|
|
29 |
|
|
if ($timesys == TIMESYS_ABSOLUTE) { |
30 |
|
|
$self->{set} = sub { $self->{time} = $_[0] }; |
31 |
pcg |
1.37 |
$self->{format} = sub { util::format_time $_[0] }; |
32 |
pcg |
1.23 |
|
33 |
|
|
} elsif ($timesys == TIMESYS_BYO_YOMI) { |
34 |
|
|
my $low = $interval * $count; |
35 |
|
|
|
36 |
|
|
$self->{set} = sub { $self->{time} = $_[0] }; |
37 |
|
|
|
38 |
|
|
$self->{format} = sub { |
39 |
|
|
if ($_[0] > $low) { |
40 |
pcg |
1.37 |
util::format_time $_[0] - $low; |
41 |
pcg |
1.23 |
} else { |
42 |
pcg |
1.34 |
sprintf "%s (%d)", |
43 |
pcg |
1.37 |
util::format_time int (($_[0] - 1) % $interval + 1), |
44 |
pcg |
1.43 |
($_[0] - 1) / $interval; |
45 |
pcg |
1.23 |
} |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
} elsif ($timesys == TIMESYS_CANADIAN) { |
49 |
|
|
$self->{set} = sub { $self->{time} = $_[0]; $self->{moves} = $_[1] }; |
50 |
|
|
|
51 |
|
|
$self->{format} = sub { |
52 |
pcg |
1.34 |
if (!$self->{moves}) { |
53 |
pcg |
1.37 |
util::format_time $_[0] - $low; |
54 |
pcg |
1.23 |
} else { |
55 |
pcg |
1.38 |
my $time = int (($_[0] - 1) % $interval + 1); |
56 |
|
|
|
57 |
pcg |
1.62 |
sprintf "%s/%d =%d", |
58 |
pcg |
1.37 |
util::format_time $time, |
59 |
pcg |
1.34 |
$self->{moves}, |
60 |
pcg |
1.75 |
$self->{moves} > 1 |
61 |
|
|
? $time / $self->{moves} |
62 |
|
|
: $interval; |
63 |
pcg |
1.23 |
} |
64 |
|
|
}; |
65 |
|
|
|
66 |
|
|
} else { |
67 |
|
|
# none, or unknown |
68 |
|
|
$self->{set} = sub { }; |
69 |
|
|
$self->{format} = sub { "---" } |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
sub refresh { |
74 |
|
|
my ($self, $timestamp) = @_; |
75 |
pcg |
1.38 |
my $timer = $self->{time} + $self->{start} - $timestamp; |
76 |
pcg |
1.102 |
|
77 |
pcg |
1.36 |
# we round the timer value slightly... the protocol isn't exact anyways, |
78 |
|
|
# and this gives smoother timers ;) |
79 |
pcg |
1.102 |
my $timer2 = int $timer + 0.4; |
80 |
|
|
|
81 |
|
|
if ($timer2 <= 0) { |
82 |
|
|
$timer2 = 0 if $timer2 < 0; |
83 |
pcg |
1.104 |
$self->set_text ("TIME OUT"); |
84 |
pcg |
1.102 |
} else { |
85 |
|
|
$self->set_text ($self->{format}->($timer2)); |
86 |
|
|
} |
87 |
pcg |
1.23 |
|
88 |
|
|
$timer - int $timer; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
sub set_time { |
92 |
pcg |
1.102 |
my ($self, $time, $moves) = @_; |
93 |
pcg |
1.23 |
|
94 |
pcg |
1.27 |
# we ignore requests to re-set the time of a running clock. |
95 |
|
|
# this is the easiest way to ensure that commentary etc. |
96 |
|
|
# doesn't re-set the clock. yes, this is frickle design, |
97 |
pcg |
1.36 |
# but I think the protocol is to blame here, which gives |
98 |
pcg |
1.27 |
# very little time information. (cgoban2 also has had quite |
99 |
|
|
# a lot of small time update problems...) |
100 |
|
|
unless ($self->{timeout}) { |
101 |
pcg |
1.102 |
$self->{set}->($time, $moves); |
102 |
pcg |
1.27 |
$self->refresh ($self->{start}); |
103 |
|
|
} |
104 |
pcg |
1.23 |
} |
105 |
|
|
|
106 |
|
|
sub start { |
107 |
pcg |
1.36 |
my ($self, $when) = @_; |
108 |
pcg |
1.23 |
|
109 |
pcg |
1.36 |
$self->stop; |
110 |
pcg |
1.23 |
|
111 |
pcg |
1.36 |
$self->{start} = $when; |
112 |
pcg |
1.27 |
|
113 |
pcg |
1.23 |
my $timeout; $timeout = sub { |
114 |
pcg |
1.36 |
my $next = $self->refresh (Time::HiRes::time) * 1000; |
115 |
pcg |
1.27 |
$next += 1000 if $next < 0; |
116 |
pcg |
1.23 |
$self->{timeout} = add Glib::Timeout $next, $timeout; |
117 |
|
|
0; |
118 |
|
|
}; |
119 |
|
|
|
120 |
|
|
$timeout->(); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
sub stop { |
124 |
|
|
my ($self) = @_; |
125 |
|
|
|
126 |
|
|
remove Glib::Source delete $self->{timeout} if $self->{timeout}; |
127 |
pcg |
1.24 |
} |
128 |
|
|
|
129 |
pcg |
1.23 |
package game::userpanel; |
130 |
|
|
|
131 |
pcg |
1.82 |
use Glib::Object::Subclass |
132 |
|
|
Gtk2::HBox, |
133 |
|
|
properties => [ |
134 |
|
|
Glib::ParamSpec->IV ("colour", "colour", "User Colour", 0, 1, 0, [qw(construct-only writable)]), |
135 |
|
|
]; |
136 |
pcg |
1.23 |
|
137 |
pcg |
1.82 |
sub INIT_INSTANCE { |
138 |
|
|
my ($self) = @_; |
139 |
pcg |
1.23 |
|
140 |
pcg |
1.82 |
$self->add (my $vbox = new Gtk2::VBox); |
141 |
pcg |
1.26 |
|
142 |
|
|
$vbox->add ($self->{name} = new Gtk2::Label $self->{name}); |
143 |
|
|
$vbox->add ($self->{info} = new Gtk2::Label ""); |
144 |
pcg |
1.82 |
$vbox->add ($self->{clock} = new game::goclock); Scalar::Util::weaken $self->{clock}; |
145 |
pcg |
1.23 |
|
146 |
pcg |
1.32 |
$vbox->add ($self->{imagebox} = new Gtk2::VBox); |
147 |
|
|
|
148 |
pcg |
1.23 |
$self; |
149 |
|
|
} |
150 |
|
|
|
151 |
pcg |
1.37 |
sub configure { |
152 |
pcg |
1.69 |
my ($self, $app, $user, $rules) = @_; |
153 |
pcg |
1.23 |
|
154 |
pcg |
1.38 |
if ($self->{name}->get_text ne $user->as_string) { |
155 |
|
|
$self->{name}->set_text ($user->as_string); |
156 |
pcg |
1.26 |
|
157 |
pcg |
1.32 |
$self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; |
158 |
|
|
$self->{imagebox}->add (gtk::image_from_data undef); |
159 |
pcg |
1.33 |
$self->{imagebox}->show_all; |
160 |
pcg |
1.32 |
|
161 |
pcg |
1.52 |
if ($user->has_pic) { |
162 |
|
|
# the big picture... |
163 |
pcg |
1.69 |
$app->userpic ($user->{name}, sub { |
164 |
pcg |
1.52 |
return unless $self->{imagebox}; |
165 |
pcg |
1.69 |
|
166 |
pcg |
1.52 |
if ($_[0]) { |
167 |
|
|
$self->{imagebox}->remove ($_) for $self->{imagebox}->get_children; |
168 |
|
|
$self->{imagebox}->add (gtk::image_from_data $_[0]); |
169 |
|
|
$self->{imagebox}->show_all; |
170 |
|
|
} |
171 |
|
|
}); |
172 |
|
|
} |
173 |
pcg |
1.26 |
} |
174 |
|
|
|
175 |
pcg |
1.38 |
$self->{clock}->configure (@{$rules}{qw(timesys time interval count)}); |
176 |
pcg |
1.23 |
} |
177 |
|
|
|
178 |
pcg |
1.102 |
sub set_captures { |
179 |
|
|
my ($self, $captures) = @_; |
180 |
|
|
|
181 |
|
|
$self->{info}->set_text ("$captures pris."); |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
sub set_timer { |
185 |
|
|
my ($self, $when, $time, $moves) = @_; |
186 |
pcg |
1.23 |
|
187 |
pcg |
1.36 |
$self->{clock}->stop unless $when; |
188 |
pcg |
1.102 |
$self->{clock}->set_time ($time, $moves); |
189 |
pcg |
1.36 |
$self->{clock}->start ($when) if $when; |
190 |
pcg |
1.23 |
} |
191 |
|
|
|
192 |
pcg |
1.1 |
package game; |
193 |
|
|
|
194 |
pcg |
1.83 |
use Scalar::Util qw(weaken); |
195 |
|
|
|
196 |
pcg |
1.1 |
use KGS::Constants; |
197 |
|
|
use KGS::Game::Board; |
198 |
|
|
|
199 |
pcg |
1.74 |
use Gtk2::GoBoard; |
200 |
pcg |
1.97 |
use Gtk2::GoBoard::Constants; |
201 |
pcg |
1.74 |
|
202 |
pcg |
1.102 |
use base KGS::Game; |
203 |
|
|
use base KGS::Listener::Game; |
204 |
|
|
|
205 |
pcg |
1.83 |
use Glib::Object::Subclass |
206 |
|
|
Gtk2::Window; |
207 |
|
|
|
208 |
pcg |
1.15 |
use POSIX qw(ceil); |
209 |
|
|
|
210 |
pcg |
1.1 |
sub new { |
211 |
pcg |
1.83 |
my ($self, %arg) = @_; |
212 |
|
|
$self = $self->Glib::Object::new; |
213 |
|
|
$self->{$_} = delete $arg{$_} for keys %arg; |
214 |
pcg |
1.1 |
|
215 |
pcg |
1.83 |
gtk::state $self, "game::window", undef, window_size => [600, 500]; |
216 |
pcg |
1.1 |
|
217 |
pcg |
1.87 |
$self->signal_connect (destroy => sub { |
218 |
|
|
$self->unlisten; |
219 |
|
|
delete $self->{app}{game}{$self->{channel}}; |
220 |
|
|
%{$_[0]} = (); |
221 |
|
|
});#d# |
222 |
pcg |
1.1 |
|
223 |
pcg |
1.83 |
$self->add (my $hpane = new Gtk2::HPaned); |
224 |
|
|
gtk::state $hpane, "game::hpane", undef, position => 500; |
225 |
pcg |
1.1 |
|
226 |
pcg |
1.36 |
# LEFT PANE |
227 |
|
|
|
228 |
pcg |
1.83 |
$hpane->pack1 (($self->{left} = new Gtk2::VBox), 1, 0); |
229 |
pcg |
1.31 |
|
230 |
|
|
$self->{boardbox} = new Gtk2::VBox; |
231 |
|
|
|
232 |
pcg |
1.83 |
$hpane->pack1((my $vbox = new Gtk2::VBox), 1, 1); |
233 |
pcg |
1.1 |
|
234 |
pcg |
1.31 |
# board box (aspect/canvas) |
235 |
|
|
|
236 |
pcg |
1.91 |
#$self->{boardbox}->pack_start((my $frame = new Gtk2::Frame), 0, 1, 0); |
237 |
|
|
|
238 |
|
|
# RIGHT PANE |
239 |
|
|
|
240 |
|
|
$hpane->pack2 ((my $vbox = new Gtk2::VBox), 1, 1); |
241 |
|
|
$hpane->set (position_set => 1); |
242 |
|
|
|
243 |
|
|
$vbox->pack_start ((my $frame = new Gtk2::Frame), 0, 1, 0); |
244 |
pcg |
1.1 |
|
245 |
|
|
{ |
246 |
pcg |
1.66 |
$frame->add (my $vbox = new Gtk2::VBox); |
247 |
|
|
$vbox->add ($self->{title} = new Gtk2::Label $title); |
248 |
|
|
|
249 |
|
|
$vbox->add (my $hbox = new Gtk2::HBox); |
250 |
|
|
|
251 |
|
|
$hbox->pack_start (($self->{board_label} = new Gtk2::Label), 0, 1, 0); |
252 |
pcg |
1.1 |
|
253 |
pcg |
1.63 |
$self->{moveadj} = new Gtk2::Adjustment 1, 1, 1, 1, 5, 0; |
254 |
pcg |
1.2 |
|
255 |
pcg |
1.66 |
$hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0); |
256 |
pcg |
1.2 |
$scale->set_draw_value (0); |
257 |
pcg |
1.30 |
$scale->set_digits (0); |
258 |
pcg |
1.1 |
|
259 |
pcg |
1.104 |
$self->{moveadj}->signal_connect (value_changed => sub { |
260 |
|
|
$self->{showmove} = int $self->{moveadj}->get_value; |
261 |
|
|
$self->update_board; |
262 |
|
|
}); |
263 |
pcg |
1.1 |
} |
264 |
pcg |
1.31 |
|
265 |
pcg |
1.83 |
$vbox->pack_start ((my $hbox = new Gtk2::HBox 1), 0, 1, 0); |
266 |
pcg |
1.82 |
|
267 |
pcg |
1.83 |
$hbox->add ($self->{userpanel}[$_] = new game::userpanel colour => $_) |
268 |
|
|
for COLOUR_WHITE, COLOUR_BLACK; |
269 |
pcg |
1.100 |
|
270 |
|
|
$vbox->pack_start ((my $buttonbox = new Gtk2::HButtonBox), 0, 1, 0); |
271 |
|
|
|
272 |
pcg |
1.101 |
$buttonbox->add ($self->{button_pass} = |
273 |
pcg |
1.102 |
Gtk2::Button->Glib::Object::new (label => "Pass", no_show_all => 1, visible => 0)); |
274 |
pcg |
1.101 |
$self->{button_pass}->signal_connect (clicked => sub { |
275 |
|
|
$self->{board_click}->(255, 255) if $self->{board_click}; |
276 |
|
|
}); |
277 |
pcg |
1.102 |
$buttonbox->add ($self->{button_undo} = |
278 |
|
|
Gtk2::Button->Glib::Object::new (label => "Undo", no_show_all => 1, visible => 0)); |
279 |
|
|
$self->{button_undo}->signal_connect (clicked => sub { |
280 |
|
|
$self->send (req_undo => channel => $self->{channel}); |
281 |
|
|
}); |
282 |
|
|
$buttonbox->add ($self->{button_resign} = |
283 |
|
|
Gtk2::Button->Glib::Object::new (label => "Resign", no_show_all => 1, visible => 0)); |
284 |
|
|
$self->{button_resign}->signal_connect (clicked => sub { |
285 |
|
|
$self->send (resign_game => channel => $self->{channel}, player => $self->{colour}); |
286 |
|
|
}); |
287 |
pcg |
1.1 |
|
288 |
pcg |
1.86 |
$vbox->pack_start (($self->{chat} = new superchat), 1, 1, 0); |
289 |
pcg |
1.73 |
|
290 |
pcg |
1.96 |
$self->set_channel ($self->{channel}); |
291 |
pcg |
1.86 |
|
292 |
pcg |
1.96 |
$self->show_all; |
293 |
pcg |
1.1 |
|
294 |
|
|
$self; |
295 |
|
|
} |
296 |
|
|
|
297 |
pcg |
1.96 |
sub set_channel { |
298 |
|
|
my ($self, $channel) = @_; |
299 |
|
|
|
300 |
|
|
$self->{channel} = $channel; |
301 |
|
|
|
302 |
|
|
if ($self->{channel} > 0) { |
303 |
|
|
$self->listen ($self->{conn}); |
304 |
|
|
|
305 |
|
|
$self->{rules_inlay} = $self->{chat}->new_switchable_inlay ("Game Setup:", sub { $self->draw_setup (@_) }, 1); |
306 |
|
|
$self->{users_inlay} = $self->{chat}->new_switchable_inlay ("Users:", sub { $self->draw_users (@_) }, 1); |
307 |
|
|
|
308 |
|
|
$self->signal_connect (delete_event => sub { $self->part; 1 }); |
309 |
|
|
$self->{chat}->signal_connect (command => sub { |
310 |
|
|
my ($chat, $cmd, $arg) = @_; |
311 |
|
|
if ($cmd eq "rsave") { |
312 |
|
|
Storable::nstore { tree => $self->{tree}, curnode => $self->{curnode}, move => $self->{move} }, $arg;#d# |
313 |
|
|
} else { |
314 |
|
|
$self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, game => $self); |
315 |
|
|
} |
316 |
|
|
}); |
317 |
|
|
} |
318 |
|
|
} |
319 |
|
|
|
320 |
pcg |
1.1 |
sub event_update_users { |
321 |
pcg |
1.18 |
my ($self, $add, $update, $remove) = @_; |
322 |
pcg |
1.1 |
|
323 |
pcg |
1.88 |
# $self->{userlist}->update ($add, $update, $remove); |
324 |
pcg |
1.70 |
|
325 |
pcg |
1.97 |
$self->{challenge}{$_->{name}} && (delete $self->{challenge}{$_->{name}})->{inlay}->destroy |
326 |
|
|
for @$remove; |
327 |
|
|
|
328 |
pcg |
1.88 |
$self->{users_inlay}->refresh; |
329 |
pcg |
1.57 |
|
330 |
|
|
my %important; |
331 |
pcg |
1.98 |
$important{$self->{black}{name}}++; |
332 |
|
|
$important{$self->{white}{name}}++; |
333 |
|
|
$important{$self->{owner}{name}}++; |
334 |
pcg |
1.57 |
|
335 |
|
|
if (my @users = grep $important{$_->{name}}, @$add) { |
336 |
pcg |
1.73 |
$self->{chat}->append_text ("\n<header>Joins:</header>"); |
337 |
|
|
$self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; |
338 |
pcg |
1.57 |
} |
339 |
|
|
if (my @users = grep $important{$_->{name}}, @$remove) { |
340 |
pcg |
1.73 |
$self->{chat}->append_text ("\n<header>Parts:</header>"); |
341 |
|
|
$self->{chat}->append_text (" <user>" . $_->as_string . "</user>") for @users; |
342 |
pcg |
1.57 |
} |
343 |
pcg |
1.1 |
} |
344 |
|
|
|
345 |
|
|
sub join { |
346 |
|
|
my ($self) = @_; |
347 |
pcg |
1.21 |
return if $self->{joined}; |
348 |
|
|
|
349 |
pcg |
1.1 |
$self->SUPER::join; |
350 |
|
|
} |
351 |
|
|
|
352 |
pcg |
1.97 |
sub update_cursor { |
353 |
|
|
my ($self) = @_; |
354 |
|
|
|
355 |
pcg |
1.104 |
my $running = $self->{showmove} == @{$self->{path}} && $self->is_active; |
356 |
pcg |
1.99 |
|
357 |
|
|
delete $self->{board_click}; |
358 |
|
|
|
359 |
|
|
if ($self->{teacher} eq $self->{app}{conn}) { |
360 |
|
|
#TODO# # teaching mode not implemented |
361 |
pcg |
1.101 |
$self->{button_pass}->set (label => "Pass", sensitive => 1, visible => 1); |
362 |
pcg |
1.102 |
$self->{button_undo}->hide; |
363 |
|
|
$self->{button_resign}->hide; |
364 |
pcg |
1.101 |
$self->{board}->set (cursor => undef); |
365 |
|
|
|
366 |
|
|
} elsif ($running && $self->{colour} != COLOUR_NONE) { |
367 |
|
|
# during game |
368 |
pcg |
1.102 |
$self->{button_undo}->show; |
369 |
|
|
$self->{button_resign}->show; |
370 |
pcg |
1.101 |
|
371 |
|
|
if ($self->{cur_board}{score}) { |
372 |
|
|
# during scoring |
373 |
|
|
$self->{button_pass}->set (label => "Done", sensitive => 1, visible => 1); |
374 |
|
|
$self->{board}->set (cursor => sub { |
375 |
|
|
$_[0] & (MARK_B | MARK_W) |
376 |
|
|
? $_[0] ^ MARK_GRAYED |
377 |
|
|
: $_[0]; |
378 |
|
|
}); |
379 |
|
|
$self->{board_click} = sub { |
380 |
|
|
if ($_[0] == 255) { |
381 |
|
|
$self->{button_pass}->sensitive (0); |
382 |
|
|
$self->done; |
383 |
|
|
} else { |
384 |
|
|
$self->send (mark_dead => |
385 |
|
|
channel => $self->{channel}, |
386 |
|
|
x => $_[0], |
387 |
|
|
y => $_[1], |
388 |
|
|
dead => !($self->{cur_board}{board}[$_[0]][$_[1]] & MARK_GRAYED), |
389 |
|
|
); |
390 |
|
|
} |
391 |
|
|
}; |
392 |
|
|
|
393 |
|
|
} elsif (1 - $self->{colour} == $self->{cur_board}{last}) { |
394 |
|
|
# normal move |
395 |
|
|
$self->{button_pass}->set (label => "Pass", sensitive => 1, visible => 1); |
396 |
|
|
$self->{board}->set (cursor => sub { |
397 |
|
|
# if is_valid_move oder so#TODO# |
398 |
|
|
$_[0] & (MARK_B | MARK_W) |
399 |
|
|
? $_[0] |
400 |
|
|
: $_[0] | MARK_GRAYED | ($self->{colour} == COLOUR_WHITE ? MARK_W : MARK_B); |
401 |
|
|
}); |
402 |
|
|
$self->{board_click} = sub { |
403 |
|
|
$self->send (game_move => channel => $self->{channel}, x => $_[0], y => $_[1]); |
404 |
|
|
$self->{board}->set (cursor => undef); |
405 |
|
|
delete $self->{board_click}; |
406 |
|
|
$self->{button_pass}->sensitive (0); |
407 |
|
|
}; |
408 |
|
|
} else { |
409 |
|
|
$self->{button_pass}->set (label => "Pass", sensitive => 0, visible => 1); |
410 |
|
|
} |
411 |
|
|
} else { |
412 |
pcg |
1.102 |
$self->{button_undo}->hide; |
413 |
|
|
$self->{button_resign}->hide; |
414 |
pcg |
1.101 |
$self->{button_pass}->hide; |
415 |
|
|
$self->{board}->set (cursor => undef); |
416 |
pcg |
1.99 |
#TODO# # implement coordinate-grabbing |
417 |
pcg |
1.97 |
} |
418 |
|
|
} |
419 |
|
|
|
420 |
pcg |
1.104 |
sub update_timers { |
421 |
|
|
my ($self, $timers) = @_; |
422 |
|
|
|
423 |
|
|
my $running = $self->{showmove} == @{$self->{path}} && !$self->{teacher}; |
424 |
|
|
|
425 |
|
|
for my $colour (COLOUR_BLACK, COLOUR_WHITE) { |
426 |
|
|
my $t = $timers->[$colour]; |
427 |
|
|
$self->{userpanel}[$colour]->set_timer ( |
428 |
|
|
$running && $self->{lastmove_colour} == 1 - $colour && $t->[0], |
429 |
|
|
$t->[1], $t->[2]); |
430 |
|
|
} |
431 |
|
|
} |
432 |
|
|
|
433 |
pcg |
1.23 |
sub update_board { |
434 |
|
|
my ($self) = @_; |
435 |
|
|
return unless $self->{path}; |
436 |
|
|
|
437 |
pcg |
1.104 |
$self->{board_label}->set_text ("Move " . ($self->{showmove} - 1)); |
438 |
pcg |
1.23 |
|
439 |
pcg |
1.64 |
$self->{cur_board} = new KGS::Game::Board $self->{size}; |
440 |
pcg |
1.104 |
$self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]); |
441 |
pcg |
1.47 |
|
442 |
pcg |
1.102 |
$self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) |
443 |
|
|
for COLOUR_WHITE, COLOUR_BLACK; |
444 |
pcg |
1.23 |
|
445 |
pcg |
1.104 |
if ($self->{showmove} == @{$self->{path}}) { |
446 |
|
|
$self->{timers} = [ |
447 |
|
|
[$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}], |
448 |
|
|
[$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}], |
449 |
|
|
]; |
450 |
|
|
$self->update_timers ($self->{timers}); |
451 |
pcg |
1.103 |
} else { |
452 |
pcg |
1.104 |
$self->update_timers ([ |
453 |
|
|
[0, @{$self->{cur_board}{timer}[0]}], |
454 |
|
|
[0, @{$self->{cur_board}{timer}[1]}], |
455 |
|
|
]); |
456 |
pcg |
1.103 |
} |
457 |
|
|
|
458 |
pcg |
1.64 |
$self->{board}->set_board ($self->{cur_board}); |
459 |
pcg |
1.97 |
|
460 |
|
|
$self->update_cursor; |
461 |
pcg |
1.23 |
} |
462 |
|
|
|
463 |
pcg |
1.1 |
sub event_update_tree { |
464 |
|
|
my ($self) = @_; |
465 |
|
|
|
466 |
|
|
$self->{path} = $self->get_path; |
467 |
pcg |
1.30 |
|
468 |
|
|
if ($self->{moveadj}) { |
469 |
|
|
my $upper = $self->{moveadj}->upper; |
470 |
|
|
my $pos = $self->{moveadj}->get_value; |
471 |
pcg |
1.48 |
my $move = scalar @{$self->{path}}; |
472 |
pcg |
1.30 |
|
473 |
pcg |
1.48 |
$self->{moveadj}->upper ($move); |
474 |
pcg |
1.30 |
|
475 |
|
|
$self->{moveadj}->changed; |
476 |
|
|
if ($pos == $upper) { |
477 |
pcg |
1.48 |
$self->{moveadj}->value ($move); |
478 |
|
|
$self->{moveadj}->value_changed; |
479 |
pcg |
1.30 |
} |
480 |
|
|
} |
481 |
pcg |
1.29 |
} |
482 |
|
|
|
483 |
|
|
sub event_update_comments { |
484 |
|
|
my ($self, $node, $comment, $newnode) = @_; |
485 |
|
|
$self->SUPER::event_update_comments($node, $comment, $newnode); |
486 |
|
|
|
487 |
pcg |
1.30 |
my $text; |
488 |
|
|
|
489 |
pcg |
1.34 |
$text .= "\n<header>Move <move>$node->{move}</move>, Node <node>$node->{id}</node></header>" |
490 |
pcg |
1.29 |
if $newnode; |
491 |
|
|
|
492 |
pcg |
1.30 |
for (split /\n/, $comment) { |
493 |
|
|
$text .= "\n"; |
494 |
pcg |
1.40 |
if (s/^([0-9a-zA-Z]+ \[[0-9dkp\?\-]+\])://) { |
495 |
pcg |
1.30 |
$text .= "<user>" . (util::toxml $1) . "</user>:"; |
496 |
|
|
} |
497 |
pcg |
1.40 |
|
498 |
|
|
# coords only for 19x19 so far |
499 |
|
|
$_ = util::toxml $_; |
500 |
pcg |
1.39 |
s{ |
501 |
|
|
( |
502 |
|
|
\b |
503 |
|
|
(?:[bw])? |
504 |
|
|
[, ]{0,2} |
505 |
pcg |
1.41 |
[a-hj-t] # valid for upto 19x19 |
506 |
pcg |
1.40 |
\s? |
507 |
pcg |
1.42 |
[1-9]?[0-9] |
508 |
pcg |
1.40 |
\b |
509 |
pcg |
1.39 |
) |
510 |
|
|
}{ |
511 |
|
|
"<coord>$1</coord>"; |
512 |
|
|
}sgexi; |
513 |
|
|
|
514 |
pcg |
1.30 |
$text .= $_; |
515 |
|
|
} |
516 |
|
|
|
517 |
pcg |
1.73 |
$self->{chat}->append_text ($text); |
518 |
pcg |
1.1 |
} |
519 |
|
|
|
520 |
pcg |
1.31 |
sub event_join { |
521 |
|
|
my ($self) = @_; |
522 |
pcg |
1.83 |
|
523 |
|
|
$self->SUPER::event_join (@_); |
524 |
pcg |
1.97 |
$self->init_tree; |
525 |
pcg |
1.83 |
$self->event_update_game; |
526 |
pcg |
1.31 |
} |
527 |
|
|
|
528 |
pcg |
1.1 |
sub event_part { |
529 |
|
|
my ($self) = @_; |
530 |
pcg |
1.83 |
|
531 |
pcg |
1.1 |
$self->SUPER::event_part; |
532 |
pcg |
1.50 |
$self->destroy; |
533 |
pcg |
1.1 |
} |
534 |
|
|
|
535 |
|
|
sub event_move { |
536 |
|
|
my ($self, $pass) = @_; |
537 |
|
|
sound::play 1, $pass ? "pass" : "move"; |
538 |
pcg |
1.98 |
|
539 |
|
|
if ($self->{undo_inlay}) { |
540 |
|
|
(delete $self->{undo_inlay})->clear; |
541 |
|
|
} |
542 |
pcg |
1.25 |
} |
543 |
|
|
|
544 |
|
|
sub event_update_game { |
545 |
|
|
my ($self) = @_; |
546 |
pcg |
1.95 |
|
547 |
pcg |
1.25 |
$self->SUPER::event_update_game; |
548 |
pcg |
1.36 |
|
549 |
pcg |
1.83 |
return unless $self->{joined}; |
550 |
pcg |
1.71 |
|
551 |
pcg |
1.101 |
$self->{colour} = $self->player_colour ($self->{conn}{name}); |
552 |
pcg |
1.97 |
|
553 |
pcg |
1.67 |
my $title = defined $self->{channel} |
554 |
|
|
? $self->owner->as_string . " " . $self->opponent_string |
555 |
|
|
: "Game Window"; |
556 |
pcg |
1.102 |
$self->set_title ("KGS Game $title"); |
557 |
pcg |
1.55 |
$self->{title}->set_text ($title); |
558 |
pcg |
1.53 |
|
559 |
pcg |
1.98 |
$self->{user}[COLOUR_BLACK] = $self->{black}; |
560 |
|
|
$self->{user}[COLOUR_WHITE] = $self->{white}; |
561 |
pcg |
1.37 |
|
562 |
pcg |
1.38 |
# show board |
563 |
pcg |
1.80 |
if ($self->is_inprogress) { |
564 |
pcg |
1.92 |
if (!$self->{boardbox}->parent) { |
565 |
|
|
$self->{boardbox}->add ($self->{board} = new Gtk2::GoBoard size => $self->{size}); |
566 |
|
|
$self->{left}->add ($self->{boardbox}); |
567 |
pcg |
1.97 |
$self->{board}->signal_connect (button_release => sub { |
568 |
|
|
if ($_[1] == 1) { |
569 |
|
|
$self->{board_click}->($_[2], $_[3]) if $self->{board_click}; |
570 |
|
|
} |
571 |
|
|
}); |
572 |
pcg |
1.92 |
} |
573 |
pcg |
1.86 |
if (my $ch = delete $self->{challenge}) { |
574 |
pcg |
1.98 |
$_->{inlay}->destroy for values %$ch; |
575 |
pcg |
1.86 |
} |
576 |
pcg |
1.97 |
$self->update_cursor; |
577 |
pcg |
1.38 |
} |
578 |
pcg |
1.86 |
|
579 |
pcg |
1.38 |
$self->{left}->show_all; |
580 |
|
|
|
581 |
pcg |
1.95 |
$self->{rules_inlay}->refresh; |
582 |
pcg |
1.53 |
|
583 |
pcg |
1.25 |
} |
584 |
|
|
|
585 |
pcg |
1.95 |
sub draw_setup { |
586 |
pcg |
1.86 |
my ($self, $inlay) = @_; |
587 |
pcg |
1.37 |
|
588 |
pcg |
1.96 |
return unless $self->{joined}; |
589 |
|
|
|
590 |
pcg |
1.86 |
my $rules = $self->{rules}; |
591 |
pcg |
1.54 |
|
592 |
pcg |
1.86 |
my $text = ""; |
593 |
pcg |
1.37 |
|
594 |
pcg |
1.96 |
$text .= "\nTeacher: <user>" . (util::toxml $self->{teacher}) . "</user>" |
595 |
|
|
if $self->{teacher}; |
596 |
|
|
|
597 |
pcg |
1.98 |
$text .= "\nOwner: <user>" . (util::toxml $self->{owner}->as_string) . "</user>" |
598 |
|
|
if $self->{owner}->is_valid; |
599 |
pcg |
1.96 |
|
600 |
|
|
if ($self->is_inprogress) { |
601 |
pcg |
1.98 |
$text .= "\nPlayers: <user>" . (util::toxml $self->{white}->as_string) . "</user>" |
602 |
|
|
. " vs. <user>" . (util::toxml $self->{black}->as_string) . "</user>"; |
603 |
pcg |
1.96 |
} |
604 |
|
|
$text .= "\nType: " . util::toxml $gametype{$self->type}; |
605 |
pcg |
1.95 |
|
606 |
pcg |
1.37 |
$text .= "\nRuleset: " . $ruleset{$rules->{ruleset}}; |
607 |
|
|
|
608 |
pcg |
1.38 |
$text .= "\nTime: "; |
609 |
pcg |
1.37 |
|
610 |
pcg |
1.38 |
if ($rules->{timesys} == TIMESYS_NONE) { |
611 |
pcg |
1.46 |
$text .= "UNLIMITED"; |
612 |
pcg |
1.38 |
} elsif ($rules->{timesys} == TIMESYS_ABSOLUTE) { |
613 |
|
|
$text .= util::format_time $rules->{time}; |
614 |
pcg |
1.46 |
$text .= " ABS"; |
615 |
pcg |
1.38 |
} elsif ($rules->{timesys} == TIMESYS_BYO_YOMI) { |
616 |
pcg |
1.79 |
$text .= util::format_time $rules->{time}; |
617 |
pcg |
1.46 |
$text .= sprintf " + %s (%d) BY", util::format_time $rules->{interval}, $rules->{count}; |
618 |
pcg |
1.38 |
} elsif ($rules->{timesys} == TIMESYS_CANADIAN) { |
619 |
|
|
$text .= util::format_time $rules->{time}; |
620 |
pcg |
1.46 |
$text .= sprintf " + %s/%d CAN", util::format_time $rules->{interval}, $rules->{count}; |
621 |
pcg |
1.37 |
} |
622 |
|
|
|
623 |
pcg |
1.95 |
$text .= "\nFlags:"; |
624 |
pcg |
1.96 |
$text .= " private" if $self->is_private; |
625 |
pcg |
1.95 |
$text .= " started" if $self->is_inprogress; |
626 |
|
|
$text .= " adjourned" if $self->is_adjourned; |
627 |
|
|
$text .= " scored" if $self->is_scored; |
628 |
|
|
$text .= " saved" if $self->is_saved; |
629 |
|
|
|
630 |
|
|
if ($self->is_inprogress) { |
631 |
|
|
$text .= "\nHandicap: " . $self->{handicap}; |
632 |
|
|
$text .= "\nKomi: " . $self->{komi}; |
633 |
|
|
$text .= "\nSize: " . $self->size_string; |
634 |
|
|
} |
635 |
|
|
|
636 |
|
|
if ($self->is_scored) { |
637 |
|
|
$text .= "\nResult: " . $self->score_string; |
638 |
|
|
} |
639 |
|
|
|
640 |
pcg |
1.86 |
$inlay->append_text ("<infoblock>$text</infoblock>"); |
641 |
pcg |
1.95 |
|
642 |
pcg |
1.86 |
} |
643 |
|
|
|
644 |
|
|
sub event_update_rules { |
645 |
|
|
my ($self, $rules) = @_; |
646 |
|
|
|
647 |
|
|
$self->{rules} = $rules; |
648 |
|
|
|
649 |
|
|
if ($self->{user}) { |
650 |
|
|
$self->{userpanel}[$_]->configure ($self->{app}, $self->{user}[$_], $rules) |
651 |
|
|
for COLOUR_BLACK, COLOUR_WHITE; |
652 |
|
|
} |
653 |
|
|
|
654 |
|
|
sound::play 3, "gamestart"; |
655 |
|
|
|
656 |
pcg |
1.89 |
$self->{rules_inlay}->refresh; |
657 |
pcg |
1.38 |
} |
658 |
|
|
|
659 |
pcg |
1.100 |
sub event_resign_game { |
660 |
|
|
my ($self, $player) = @_; |
661 |
pcg |
1.54 |
|
662 |
|
|
sound::play 3, "resign"; |
663 |
pcg |
1.73 |
$self->{chat}->append_text ("\n<infoblock><header>Resign</header>" |
664 |
pcg |
1.39 |
. "\n<user>" |
665 |
pcg |
1.38 |
. (util::toxml $self->{user}[$msg->{player}]->as_string) |
666 |
|
|
. "</user> resigned.</infoblock>"); |
667 |
|
|
} |
668 |
|
|
|
669 |
pcg |
1.100 |
sub event_out_of_time { |
670 |
|
|
my ($self, $player) = @_; |
671 |
|
|
|
672 |
|
|
sound::play 3, "timewin"; |
673 |
pcg |
1.104 |
$self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>" |
674 |
pcg |
1.100 |
. "\n<user>" |
675 |
|
|
. (util::toxml $self->{user}[$msg->{player}]->as_string) |
676 |
pcg |
1.104 |
. "</user> ran out of time and lost.</infoblock>"); |
677 |
pcg |
1.100 |
} |
678 |
|
|
|
679 |
pcg |
1.102 |
sub event_done { |
680 |
|
|
my ($self) = @_; |
681 |
|
|
|
682 |
|
|
if ($self->{done}[1 - $self->{colour}] && !$self->{done}[$self->{colour}]) { |
683 |
|
|
$self->{chat}->append_text ("\n<infoblock><header>Done</header>" |
684 |
|
|
. "\nYour opponent pressed done."); |
685 |
|
|
} |
686 |
|
|
} |
687 |
|
|
|
688 |
pcg |
1.38 |
sub inject_final_result { |
689 |
|
|
my ($self, $msg) = @_; |
690 |
|
|
|
691 |
pcg |
1.73 |
$self->{chat}->append_text ("<infoblock>\n<header>Game Over</header>" |
692 |
pcg |
1.38 |
. "\nWhite Score " . (util::toxml $msg->{whitescore}->as_string) |
693 |
|
|
. "\nBlack Score " . (util::toxml $msg->{blackscore}->as_string) |
694 |
pcg |
1.42 |
. "</infoblock>" |
695 |
pcg |
1.38 |
); |
696 |
pcg |
1.37 |
} |
697 |
|
|
|
698 |
pcg |
1.102 |
sub inject_set_gametime { |
699 |
|
|
my ($self, $msg) = @_; |
700 |
|
|
|
701 |
pcg |
1.104 |
$self->{timers} = [ |
702 |
|
|
[$msg->{NOW}, $msg->{black_time}, $msg->{black_moves}], |
703 |
|
|
[$msg->{NOW}, $msg->{white_time}, $msg->{white_moves}], |
704 |
|
|
]; |
705 |
pcg |
1.102 |
|
706 |
pcg |
1.104 |
print "SGT\n";#d# |
707 |
|
|
$self->update_timers ($self->{timers}) |
708 |
|
|
if $self->{showmove} == @{$self->{path}}; |
709 |
pcg |
1.102 |
} |
710 |
|
|
|
711 |
pcg |
1.98 |
sub inject_req_undo { |
712 |
|
|
my ($self, $msg) = @_; |
713 |
|
|
|
714 |
|
|
my $inlay = $self->{undo_inlay} ||= $self->{chat}->new_inlay; |
715 |
|
|
return if $inlay->{ignore}; |
716 |
|
|
|
717 |
pcg |
1.101 |
sound::play 3, "warning" unless $inlay->{count}; |
718 |
pcg |
1.98 |
$inlay->{count}++; |
719 |
pcg |
1.101 |
|
720 |
pcg |
1.98 |
$inlay->clear; |
721 |
|
|
$inlay->append_text ("\n<undo>Undo requested ($inlay->{count} times)</undo>\n"); |
722 |
|
|
$inlay->append_button ("Grant", sub { |
723 |
|
|
$inlay->clear; |
724 |
|
|
$self->send (grant_undo => channel => $self->{channel}); |
725 |
|
|
}); |
726 |
|
|
$inlay->append_button ("Ignore", sub { |
727 |
|
|
$inlay->clear; |
728 |
|
|
$inlay->{ignore} = 1; |
729 |
|
|
# but leave inlay, so further undo requests get counted |
730 |
|
|
}); |
731 |
|
|
|
732 |
pcg |
1.101 |
$self->{chat}->set_end; |
733 |
pcg |
1.98 |
} |
734 |
|
|
|
735 |
pcg |
1.97 |
sub inject_new_game { |
736 |
|
|
my ($self, $msg) = @_; |
737 |
|
|
|
738 |
|
|
$self->{chat}->append_text ("\n<header>ACK from server ($msg->{cid} == $self->{cid})</header>"); |
739 |
|
|
delete $self->{cid}; |
740 |
|
|
} |
741 |
|
|
|
742 |
pcg |
1.86 |
sub draw_challenge { |
743 |
pcg |
1.97 |
my ($self, $id) = @_; |
744 |
pcg |
1.86 |
|
745 |
pcg |
1.98 |
my $info = $self->{challenge}{$id}; |
746 |
|
|
my $inlay = $info->{inlay}; |
747 |
|
|
my $rules = $info->{rules}; |
748 |
pcg |
1.97 |
|
749 |
pcg |
1.98 |
my $as_black = $info->{black}{name} eq $self->{conn}{name} ? 1 : 0;; |
750 |
|
|
my $opponent = $as_black ? $info->{white} : $info->{black}; |
751 |
pcg |
1.86 |
|
752 |
pcg |
1.97 |
my ($size, $time, $interval, $count); |
753 |
|
|
|
754 |
|
|
if (!$self->{channel}) { |
755 |
|
|
$inlay->append_text ("\nNotes: "); |
756 |
pcg |
1.98 |
$inlay->append_entry (\$info->{notes}, 20, ""); |
757 |
pcg |
1.97 |
$inlay->append_text ("\nGlobal Offer: "); |
758 |
pcg |
1.98 |
$inlay->append_optionmenu (\$info->{flags}, |
759 |
pcg |
1.97 |
0 => "No", |
760 |
|
|
2 => "Yes", |
761 |
|
|
); |
762 |
|
|
} else { |
763 |
pcg |
1.98 |
$inlay->append_text ("\nNotes: " . util::toxml $info->{notes}); |
764 |
pcg |
1.97 |
} |
765 |
|
|
|
766 |
|
|
$inlay->append_text ("\nType: "); |
767 |
|
|
$inlay->append_optionmenu ( |
768 |
pcg |
1.98 |
\$info->{gametype}, |
769 |
pcg |
1.97 |
GAMETYPE_DEMONSTRATION , "Demonstration", |
770 |
|
|
GAMETYPE_DEMONSTRATION | GAMETYPE_PRIVATE, "Demonstration (P)", |
771 |
|
|
GAMETYPE_TEACHING , "Teaching", |
772 |
|
|
GAMETYPE_TEACHING | GAMETYPE_PRIVATE, "Teaching (P)", |
773 |
|
|
GAMETYPE_SIMUL , "Simul (not yet!)", |
774 |
|
|
GAMETYPE_FREE , "Free", |
775 |
|
|
GAMETYPE_RATED , "Rated", |
776 |
|
|
sub { |
777 |
|
|
$size->set_history (2) if $_[0] eq GAMETYPE_RATED; |
778 |
|
|
}, |
779 |
|
|
); |
780 |
|
|
|
781 |
|
|
if ($self->{channel}) { |
782 |
|
|
$inlay->append_text ("\nMy Colour: "); |
783 |
|
|
$inlay->append_optionmenu ( |
784 |
|
|
\$as_black, |
785 |
|
|
0 => "White", |
786 |
|
|
1 => "Black", |
787 |
|
|
sub { |
788 |
pcg |
1.98 |
if ($info->{$_[0] ? "black" : "white"}{name} ne $self->{conn}{name}) { |
789 |
|
|
($info->{black}, $info->{white}) = ($info->{white}, $info->{black}); |
790 |
pcg |
1.97 |
} |
791 |
|
|
} |
792 |
|
|
); |
793 |
|
|
} |
794 |
pcg |
1.86 |
|
795 |
pcg |
1.97 |
$inlay->append_text ("\nRuleset: "); |
796 |
|
|
$inlay->append_optionmenu ( |
797 |
pcg |
1.98 |
\$info->{rules}{ruleset}, |
798 |
pcg |
1.97 |
RULESET_JAPANESE , "Japanese", |
799 |
|
|
RULESET_CHINESE , "Chinese", |
800 |
|
|
RULESET_AGA , "AGA", |
801 |
|
|
RULESET_NEW_ZEALAND, "New Zealand", |
802 |
|
|
); |
803 |
|
|
|
804 |
|
|
$inlay->append_text ("\nSize: "); |
805 |
|
|
$size = $inlay->append_optionmenu ( |
806 |
pcg |
1.98 |
\$info->{rules}{size}, 9 => 9, 13 => 13, 19 => 19, map +($_, $_), 2..38 |
807 |
pcg |
1.97 |
); |
808 |
|
|
|
809 |
|
|
if ($self->{channel}) { |
810 |
|
|
$inlay->append_text ("\nHandicap: "); |
811 |
pcg |
1.98 |
$inlay->append_optionmenu (\$info->{rules}{handicap}, map +($_, $_), 0..9); |
812 |
pcg |
1.97 |
|
813 |
|
|
$inlay->append_text ("\nKomi: "); |
814 |
pcg |
1.98 |
$inlay->append_entry (\$info->{rules}{komi}, 5); |
815 |
pcg |
1.97 |
} |
816 |
|
|
|
817 |
|
|
$inlay->append_text ("\nTimesys: "); |
818 |
|
|
$inlay->append_optionmenu ( |
819 |
pcg |
1.98 |
\$info->{rules}{timesys}, |
820 |
pcg |
1.97 |
&TIMESYS_NONE => "None", |
821 |
|
|
&TIMESYS_ABSOLUTE => "Absolute", |
822 |
|
|
&TIMESYS_BYO_YOMI => "Byo Yomi", |
823 |
|
|
&TIMESYS_CANADIAN => "Canadian", |
824 |
|
|
sub { |
825 |
|
|
my ($new) = @_; |
826 |
|
|
|
827 |
|
|
if ($new eq TIMESYS_NONE) { |
828 |
|
|
$time->hide; |
829 |
|
|
$interval->hide; |
830 |
|
|
$count->hide; |
831 |
|
|
} else { |
832 |
|
|
$time->show; |
833 |
|
|
$time->set_text ($self->{app}{defaults}{time}); |
834 |
|
|
if ($new eq TIMESYS_ABSOLUTE) { |
835 |
|
|
$interval->hide; |
836 |
|
|
$count->hide; |
837 |
|
|
} else { |
838 |
|
|
$interval->show; |
839 |
|
|
$count->show; |
840 |
|
|
if ($new eq TIMESYS_BYO_YOMI) { |
841 |
|
|
$interval->set_text ($self->{app}{defaults}{byo_time}); |
842 |
|
|
$count->set_text ($self->{app}{defaults}{byo_period}); |
843 |
|
|
} elsif ($new eq TIMESYS_CANADIAN) { |
844 |
|
|
$interval->set_text ($self->{app}{defaults}{can_time}); |
845 |
|
|
$count->set_text ($self->{app}{defaults}{can_period}); |
846 |
|
|
} |
847 |
|
|
} |
848 |
|
|
} |
849 |
|
|
} |
850 |
|
|
); |
851 |
|
|
|
852 |
|
|
$inlay->append_text ("\nMain Time: "); |
853 |
pcg |
1.98 |
$time = $inlay->append_entry (\$info->{rules}{time}, 5); |
854 |
pcg |
1.97 |
$inlay->append_text ("\nInterval: "); |
855 |
pcg |
1.98 |
$interval = $inlay->append_entry (\$info->{rules}{interval}, 3); |
856 |
pcg |
1.97 |
$inlay->append_text ("\nPeriods/Stones: "); |
857 |
pcg |
1.98 |
$count = $inlay->append_entry (\$info->{rules}{count}, 2); |
858 |
pcg |
1.97 |
|
859 |
|
|
$inlay->append_text ("\n"); |
860 |
|
|
|
861 |
|
|
if (!$self->{channel}) { |
862 |
|
|
$inlay->append_button ("Create Challenge", sub { |
863 |
|
|
$inlay->clear; |
864 |
|
|
$self->{cid} = $self->{conn}->alloc_clientid; |
865 |
|
|
$self->send (new_game => |
866 |
pcg |
1.98 |
channel => delete $self->{roomid}, |
867 |
|
|
gametype => $info->{gametype}, |
868 |
|
|
cid => $self->{cid}, |
869 |
|
|
flags => $info->{flags}, |
870 |
|
|
rules => $info->{rules}, |
871 |
|
|
notes => $info->{notes}, |
872 |
pcg |
1.97 |
); |
873 |
|
|
}); |
874 |
|
|
} else { |
875 |
|
|
$inlay->append_button ("OK", sub { |
876 |
|
|
$inlay->clear; |
877 |
|
|
$self->send (challenge => |
878 |
pcg |
1.98 |
channel => $self->{channel}, |
879 |
|
|
black => $info->{black}, |
880 |
|
|
white => $info->{white}, |
881 |
|
|
gametype => $info->{gametype}, |
882 |
|
|
cid => $info->{cid}, |
883 |
|
|
rules => $info->{rules}, |
884 |
pcg |
1.97 |
); |
885 |
|
|
}); |
886 |
|
|
if (exists $self->{challenge}{""}) { |
887 |
|
|
$inlay->append_button ("Reject", sub { |
888 |
|
|
$inlay->clear; |
889 |
|
|
$self->send (reject_challenge => |
890 |
pcg |
1.98 |
channel => $self->{channel}, |
891 |
|
|
name => $opponent->{name}, |
892 |
|
|
gametype => $info->{gametype}, |
893 |
|
|
cid => $info->{cid}, |
894 |
|
|
rules => $info->{rules}, |
895 |
pcg |
1.97 |
); |
896 |
|
|
}); |
897 |
|
|
} |
898 |
|
|
} |
899 |
pcg |
1.86 |
} |
900 |
|
|
|
901 |
pcg |
1.88 |
sub draw_users { |
902 |
|
|
my ($self, $inlay) = @_; |
903 |
|
|
|
904 |
|
|
for (sort keys %{$self->{users}}) { |
905 |
pcg |
1.90 |
$inlay->append_text (" <user>" . $self->{users}{$_}->as_string . "</user>"); |
906 |
pcg |
1.88 |
} |
907 |
|
|
} |
908 |
|
|
|
909 |
pcg |
1.68 |
sub event_challenge { |
910 |
pcg |
1.98 |
my ($self, $info) = @_; |
911 |
pcg |
1.68 |
|
912 |
pcg |
1.98 |
my $as_black = $info->{black}->{name} eq $self->{conn}{name}; |
913 |
|
|
my $opponent = $as_black ? $info->{white} : $info->{black}; |
914 |
pcg |
1.86 |
|
915 |
pcg |
1.97 |
my $id = $opponent->{name}; |
916 |
pcg |
1.86 |
|
917 |
pcg |
1.98 |
$self->{challenge}{$id} = $info; |
918 |
|
|
$self->{challenge}{$id}{inlay} = $self->{chat}->new_switchable_inlay ( |
919 |
|
|
exists $self->{challenge}{""} |
920 |
|
|
? "Challenge from $opponent->{name}" |
921 |
|
|
: "Challenge to $opponent->{name}", |
922 |
pcg |
1.97 |
sub { |
923 |
|
|
$self->{challenge}{$id}{inlay} = $_[0]; |
924 |
|
|
$self->draw_challenge ($id); |
925 |
|
|
}, |
926 |
pcg |
1.101 |
!exists $self->{challenge}{""} # only open when not offerer |
927 |
pcg |
1.97 |
); |
928 |
pcg |
1.68 |
} |
929 |
|
|
|
930 |
pcg |
1.1 |
1; |
931 |
|
|
|