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