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