1 |
root |
1.1 |
package CFClient::Protocol; |
2 |
|
|
|
3 |
|
|
use utf8; |
4 |
|
|
use strict; |
5 |
|
|
|
6 |
root |
1.2 |
use Crossfire::Protocol::Constants; |
7 |
|
|
|
8 |
root |
1.1 |
use CFClient::UI; |
9 |
|
|
|
10 |
|
|
use base 'Crossfire::Protocol::Base'; |
11 |
|
|
|
12 |
|
|
sub new { |
13 |
|
|
my $class = shift; |
14 |
|
|
|
15 |
|
|
my $self = $class->SUPER::new (@_); |
16 |
|
|
|
17 |
|
|
$self->{map_widget}->clr_commands; |
18 |
|
|
|
19 |
|
|
my $parser = new Pod::POM; |
20 |
|
|
my $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); |
21 |
|
|
|
22 |
|
|
for my $head2 ($pod->head1->[-2]->head2) { |
23 |
|
|
$head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
24 |
|
|
or next; |
25 |
|
|
|
26 |
|
|
my $cmd = $1; |
27 |
|
|
my @args = split /\|/, $2; |
28 |
|
|
@args = (".*") unless @args; |
29 |
|
|
|
30 |
root |
1.6 |
$_ = $_ eq ".*" ? "" : " $_" |
31 |
|
|
for @args; |
32 |
|
|
|
33 |
root |
1.1 |
my $text = CFClient::pod_to_pango $head2->content; |
34 |
|
|
|
35 |
root |
1.6 |
$self->{map_widget}->add_command ("$cmd$_", $text) |
36 |
|
|
for sort { (length $a) <=> (length $b) } |
37 |
|
|
@args; |
38 |
root |
1.1 |
} |
39 |
|
|
|
40 |
|
|
$self->{noface} = new_from_file CFClient::Texture |
41 |
|
|
CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
42 |
|
|
|
43 |
|
|
$self->{open_container} = 0; |
44 |
|
|
|
45 |
|
|
# "global" |
46 |
|
|
$self->{tilecache} = CFClient::db_table "tilecache"; |
47 |
|
|
$self->{facemap} = CFClient::db_table "facemap"; |
48 |
|
|
|
49 |
|
|
# per server |
50 |
|
|
$self->{mapcache} = CFClient::db_table "mapcache_$self->{host}_$self->{port}"; |
51 |
|
|
|
52 |
|
|
$self |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
sub stats_update { |
56 |
|
|
my ($self, $stats) = @_; |
57 |
|
|
|
58 |
elmex |
1.4 |
if (my $exp = $stats->{+CS_STAT_EXP64}) { |
59 |
root |
1.1 |
my $diff = $exp - $self->{prev_exp}; |
60 |
elmex |
1.5 |
$self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5) |
61 |
root |
1.1 |
if exists $self->{prev_exp} && $diff; |
62 |
|
|
$self->{prev_exp} = $exp; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
::update_stats_window ($stats); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
sub user_send { |
69 |
|
|
my ($self, $command) = @_; |
70 |
|
|
|
71 |
elmex |
1.9 |
if ($self->{record}) { |
72 |
|
|
push @{$self->{record}}, $command; |
73 |
|
|
} |
74 |
|
|
|
75 |
root |
1.1 |
$self->send_command ($command); |
76 |
root |
1.2 |
::status $command; |
77 |
root |
1.1 |
} |
78 |
|
|
|
79 |
elmex |
1.9 |
sub start_record { |
80 |
|
|
my ($self) = @_; |
81 |
|
|
|
82 |
|
|
$self->{record} = []; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
sub stop_record { |
86 |
|
|
my ($self) = @_; |
87 |
|
|
return delete $self->{record}; |
88 |
|
|
} |
89 |
|
|
|
90 |
root |
1.1 |
sub map_scroll { |
91 |
|
|
my ($self, $dx, $dy) = @_; |
92 |
|
|
|
93 |
|
|
$self->{map}->scroll ($dx, $dy); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
sub feed_map1a { |
97 |
|
|
my ($self, $data) = @_; |
98 |
|
|
|
99 |
|
|
$self->{map}->map1a_update ($data); |
100 |
|
|
$self->{map_widget}->update; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
sub flush_map { |
104 |
|
|
my ($self) = @_; |
105 |
|
|
|
106 |
|
|
my $map_info = delete $self->{map_info} |
107 |
|
|
or return; |
108 |
|
|
|
109 |
|
|
my ($hash, $x, $y, $w, $h) = @$map_info; |
110 |
|
|
|
111 |
|
|
my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
112 |
|
|
$self->{mapcache}->put ($hash => Compress::LZF::compress $data); |
113 |
|
|
#warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
sub map_clear { |
117 |
|
|
my ($self) = @_; |
118 |
|
|
|
119 |
|
|
$self->flush_map; |
120 |
|
|
delete $self->{neigh_map}; |
121 |
|
|
|
122 |
|
|
$self->{map}->clear; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
|
126 |
|
|
sub load_map($$$) { |
127 |
|
|
my ($self, $hash, $x, $y) = @_; |
128 |
|
|
|
129 |
|
|
if (defined (my $data = $self->{mapcache}->get ($hash))) { |
130 |
|
|
$data = Compress::LZF::decompress $data; |
131 |
|
|
#warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
132 |
|
|
for my $id ($self->{map}->set_rect ($x, $y, $data)) { |
133 |
|
|
my $data = $self->{tilecache}->get ($id) |
134 |
|
|
or next; |
135 |
|
|
|
136 |
|
|
$self->set_texture ($id => $data); |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
# hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
142 |
|
|
# (server resource,s latency, bandwidth), so this hack is warranted. |
143 |
|
|
# the right fix is to make real tiled maps with an overview file |
144 |
|
|
sub send_mapinfo { |
145 |
|
|
my ($self, $data, $cb) = @_; |
146 |
|
|
|
147 |
|
|
if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
148 |
|
|
my ($wx, $wy) = ($1, $2); |
149 |
|
|
|
150 |
|
|
if ($data =~ /^spatial ([1-4]+)$/) { |
151 |
|
|
my @dx = (0, 0, 1, 0, -1); |
152 |
|
|
my @dy = (0, -1, 0, 1, 0); |
153 |
|
|
my ($dx, $dy); |
154 |
|
|
|
155 |
|
|
for (split //, $1) { |
156 |
|
|
$dx += $dx[$_]; |
157 |
|
|
$dy += $dy[$_]; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
$cb->(spatial => 15, |
161 |
|
|
$self->{map_info}[1] - $self->{map}->ox + $dx * 50, |
162 |
|
|
$self->{map_info}[2] - $self->{map}->oy + $dy * 50, |
163 |
|
|
50, 50, |
164 |
|
|
sprintf "/world/world_%03d_%03d", $wx + $dx, $wy + $dy |
165 |
|
|
); |
166 |
|
|
|
167 |
|
|
return; |
168 |
|
|
} |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
$self->SUPER::send_mapinfo ($data, $cb); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
# this method does a "flood fill" into every tile direction |
175 |
|
|
# it assumes that tiles are arranged in a rectangular grid, |
176 |
|
|
# i.e. a map is the same as the left of the right map etc. |
177 |
|
|
# failure to comply are harmless and result in display errors |
178 |
|
|
# at worst. |
179 |
|
|
sub flood_fill { |
180 |
|
|
my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
181 |
|
|
|
182 |
|
|
# the server does not allow map paths > 6 |
183 |
|
|
return if 7 <= length $path; |
184 |
|
|
|
185 |
|
|
my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
186 |
|
|
|
187 |
|
|
for ( |
188 |
|
|
[1, 3, 0, -1], |
189 |
|
|
[2, 4, 1, 0], |
190 |
|
|
[3, 1, 0, 1], |
191 |
|
|
[4, 2, -1, 0], |
192 |
|
|
) { |
193 |
|
|
my ($tile, $tile2, $dx, $dy) = @$_; |
194 |
|
|
|
195 |
|
|
next if $block & (1 << $tile); |
196 |
|
|
my $block = $block | (1 << $tile2); |
197 |
|
|
|
198 |
|
|
my $gx = $gx + $dx; |
199 |
|
|
my $gy = $gy + $dy; |
200 |
|
|
|
201 |
|
|
next unless $flags & (1 << ($tile - 1)); |
202 |
|
|
next if $self->{neigh_grid}{$gx, $gy}++; |
203 |
|
|
|
204 |
|
|
my $neigh = $self->{neigh_map}{$hash} ||= []; |
205 |
|
|
if (my $info = $neigh->[$tile]) { |
206 |
|
|
my ($flags, $x, $y, $w, $h, $hash) = @$info; |
207 |
|
|
|
208 |
|
|
$self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
209 |
|
|
if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
210 |
|
|
|
211 |
|
|
} else { |
212 |
|
|
$self->send_mapinfo ("spatial $path$tile", sub { |
213 |
|
|
my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
214 |
|
|
|
215 |
|
|
return if $mode ne "spatial"; |
216 |
|
|
|
217 |
|
|
$x += $self->{map}->ox; |
218 |
|
|
$y += $self->{map}->oy; |
219 |
|
|
|
220 |
|
|
$self->load_map ($hash, $x, $y) |
221 |
|
|
unless $self->{neigh_map}{$hash}[5]++;#d# |
222 |
|
|
|
223 |
|
|
$neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
224 |
|
|
|
225 |
|
|
$self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
226 |
|
|
if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
227 |
|
|
}); |
228 |
|
|
} |
229 |
|
|
} |
230 |
|
|
} |
231 |
|
|
|
232 |
|
|
sub map_change { |
233 |
|
|
my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
234 |
|
|
|
235 |
|
|
$self->flush_map; |
236 |
|
|
|
237 |
|
|
my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
238 |
|
|
|
239 |
|
|
my $mapmapw = $self->{mapmap}->{w}; |
240 |
|
|
my $mapmaph = $self->{mapmap}->{h}; |
241 |
|
|
|
242 |
|
|
$self->{neigh_rect} = [ |
243 |
|
|
$ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
244 |
|
|
$ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
245 |
|
|
]; |
246 |
|
|
|
247 |
|
|
delete $self->{neigh_grid}; |
248 |
|
|
|
249 |
|
|
$x += $ox; |
250 |
|
|
$y += $oy; |
251 |
|
|
|
252 |
|
|
$self->{map_info} = [$hash, $x, $y, $w, $h]; |
253 |
|
|
|
254 |
|
|
(my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
255 |
|
|
$::STATWIDS->{map}->set_text ("Map: " . $map); |
256 |
|
|
|
257 |
|
|
$self->load_map ($hash, $x, $y); |
258 |
|
|
$self->flood_fill (0, 0, 0, "", $hash, $flags); |
259 |
|
|
} |
260 |
|
|
|
261 |
|
|
sub face_find { |
262 |
|
|
my ($self, $facenum, $face) = @_; |
263 |
|
|
|
264 |
|
|
my $hash = "$face->{chksum},$face->{name}"; |
265 |
|
|
|
266 |
|
|
my $id = $self->{facemap}->get ($hash); |
267 |
|
|
|
268 |
|
|
unless ($id) { |
269 |
|
|
# create new id for face |
270 |
|
|
# I love transactions |
271 |
|
|
for (1..100) { |
272 |
|
|
my $txn = $CFClient::DB_ENV->txn_begin; |
273 |
|
|
my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); |
274 |
|
|
if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
275 |
|
|
$id = ($id || 16) + 1; |
276 |
|
|
if ($self->{facemap}->put (id => $id) == 0 |
277 |
|
|
&& $self->{facemap}->put ($hash => $id) == 0) { |
278 |
|
|
$txn->txn_commit; |
279 |
|
|
|
280 |
|
|
goto gotid; |
281 |
|
|
} |
282 |
|
|
} |
283 |
|
|
$txn->abort; |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
gotid: |
290 |
|
|
$face->{id} = $id; |
291 |
|
|
$self->{map}->set_face ($facenum => $id); |
292 |
|
|
$self->{faceid}[$facenum] = $id;#d# |
293 |
|
|
|
294 |
|
|
my $face = $self->{tilecache}->get ($id); |
295 |
|
|
|
296 |
|
|
if ($face) { |
297 |
|
|
#$self->face_prefetch; |
298 |
|
|
$face |
299 |
|
|
} else { |
300 |
|
|
my $tex = $self->{noface}; |
301 |
|
|
$self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
302 |
|
|
undef |
303 |
|
|
}; |
304 |
|
|
} |
305 |
|
|
|
306 |
|
|
sub face_update { |
307 |
|
|
my ($self, $facenum, $face) = @_; |
308 |
|
|
|
309 |
|
|
$self->{tilecache}->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
310 |
|
|
|
311 |
|
|
$self->set_texture ($face->{id} => delete $face->{image}); |
312 |
|
|
} |
313 |
|
|
|
314 |
|
|
sub set_texture { |
315 |
|
|
my ($self, $id, $data) = @_; |
316 |
|
|
|
317 |
|
|
$self->{texture}[$id] ||= do { |
318 |
|
|
my $tex = |
319 |
|
|
new_from_image CFClient::Texture |
320 |
|
|
$data, minify => 1, mipmap => 1; |
321 |
|
|
|
322 |
|
|
$self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
323 |
|
|
$self->{map_widget}->update; |
324 |
|
|
|
325 |
|
|
$tex |
326 |
|
|
}; |
327 |
|
|
} |
328 |
|
|
|
329 |
|
|
sub sound_play { |
330 |
|
|
my ($self, $x, $y, $soundnum, $type) = @_; |
331 |
|
|
|
332 |
|
|
$self->{sound_play}->($x, $y, $soundnum, $type); |
333 |
|
|
} |
334 |
|
|
|
335 |
|
|
my $LAST_QUERY; # server is stupid, stupid, stupid |
336 |
|
|
|
337 |
|
|
sub query { |
338 |
|
|
my ($self, $flags, $prompt) = @_; |
339 |
|
|
|
340 |
|
|
$prompt = $LAST_QUERY unless length $prompt; |
341 |
|
|
$LAST_QUERY = $prompt; |
342 |
|
|
|
343 |
|
|
my $dialog = new CFClient::UI::FancyFrame |
344 |
root |
1.11 |
x => "center", |
345 |
|
|
y => "center", |
346 |
root |
1.1 |
title => "Query", |
347 |
root |
1.8 |
child => my $vbox = new CFClient::UI::VBox, |
348 |
|
|
; |
349 |
root |
1.1 |
|
350 |
|
|
$vbox->add (new CFClient::UI::Label |
351 |
|
|
max_w => $::WIDTH * 0.4, |
352 |
|
|
ellipsise => 0, |
353 |
|
|
text => $prompt); |
354 |
|
|
|
355 |
root |
1.2 |
if ($flags & CS_QUERY_YESNO) { |
356 |
root |
1.1 |
$vbox->add (my $hbox = new CFClient::UI::HBox); |
357 |
|
|
$hbox->add (new CFClient::UI::Button |
358 |
|
|
text => "No", |
359 |
root |
1.7 |
on_activate => sub { |
360 |
root |
1.1 |
$self->send ("reply n"); |
361 |
|
|
$dialog->destroy; |
362 |
|
|
$self->{map_widget}->focus_in; |
363 |
|
|
} |
364 |
|
|
); |
365 |
|
|
$hbox->add (new CFClient::UI::Button |
366 |
|
|
text => "Yes", |
367 |
root |
1.7 |
on_activate => sub { |
368 |
root |
1.1 |
$self->send ("reply y"); |
369 |
|
|
$dialog->destroy; |
370 |
|
|
}, |
371 |
|
|
); |
372 |
|
|
|
373 |
|
|
$dialog->focus_in; |
374 |
|
|
|
375 |
root |
1.2 |
} elsif ($flags & CS_QUERY_SINGLECHAR) { |
376 |
root |
1.1 |
$dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
377 |
|
|
$vbox->add (my $entry = new CFClient::UI::Entry |
378 |
root |
1.7 |
on_changed => sub { |
379 |
root |
1.1 |
$self->send ("reply $_[1]"); |
380 |
|
|
$dialog->destroy; |
381 |
|
|
}, |
382 |
|
|
); |
383 |
|
|
|
384 |
|
|
$entry->focus_in; |
385 |
|
|
|
386 |
|
|
} else { |
387 |
|
|
$dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
388 |
|
|
|
389 |
|
|
$vbox->add (my $entry = new CFClient::UI::Entry |
390 |
root |
1.2 |
$flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
391 |
root |
1.7 |
on_activate => sub { |
392 |
root |
1.1 |
$self->send ("reply $_[1]"); |
393 |
|
|
$dialog->destroy; |
394 |
|
|
}, |
395 |
|
|
); |
396 |
|
|
|
397 |
|
|
$entry->focus_in; |
398 |
|
|
} |
399 |
|
|
|
400 |
root |
1.8 |
$dialog->show; |
401 |
root |
1.1 |
} |
402 |
|
|
|
403 |
|
|
sub drawinfo { |
404 |
|
|
my ($self, $color, $text) = @_; |
405 |
|
|
|
406 |
|
|
my @color = ( |
407 |
|
|
[1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
408 |
|
|
[1.00, 1.00, 1.00], |
409 |
|
|
[0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
410 |
|
|
[1.00, 0.00, 0.00], |
411 |
|
|
[1.00, 0.54, 0.00], |
412 |
|
|
[0.11, 0.56, 1.00], |
413 |
|
|
[0.93, 0.46, 0.00], |
414 |
|
|
[0.18, 0.54, 0.34], |
415 |
|
|
[0.56, 0.73, 0.56], |
416 |
|
|
[0.80, 0.80, 0.80], |
417 |
|
|
[0.55, 0.41, 0.13], |
418 |
|
|
[0.99, 0.77, 0.26], |
419 |
|
|
[0.74, 0.65, 0.41], |
420 |
|
|
); |
421 |
|
|
|
422 |
|
|
my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
423 |
|
|
|
424 |
|
|
$text = CFClient::UI::Label::escape $text; |
425 |
|
|
$text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
426 |
|
|
$text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
427 |
|
|
|
428 |
|
|
$self->{logview}->add_paragraph ($color[$color], |
429 |
|
|
join "\n", map "$time $_", split /\n/, $text); |
430 |
|
|
|
431 |
elmex |
1.5 |
$self->{statusbox}->add ($text, |
432 |
root |
1.1 |
group => $text, |
433 |
|
|
fg => $color[$color], |
434 |
|
|
timeout => 10, |
435 |
|
|
tooltip_font => $::FONT_FIXED, |
436 |
|
|
); |
437 |
|
|
} |
438 |
|
|
|
439 |
|
|
sub drawextinfo { |
440 |
|
|
my ($self, $color, $type, $subtype, $message) = @_; |
441 |
|
|
|
442 |
|
|
$self->drawinfo ($color, $message); |
443 |
|
|
} |
444 |
|
|
|
445 |
|
|
sub spell_add { |
446 |
|
|
my ($self, $spell) = @_; |
447 |
|
|
|
448 |
|
|
# TODO |
449 |
|
|
# create a widget dynamically, using spell face (CF::Protocol downloads them) |
450 |
|
|
$self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
451 |
|
|
$self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
452 |
|
|
} |
453 |
|
|
|
454 |
|
|
sub spell_delete { |
455 |
|
|
my ($self, $spell) = @_; |
456 |
|
|
} |
457 |
|
|
|
458 |
|
|
sub addme_success { |
459 |
|
|
my ($self) = @_; |
460 |
|
|
|
461 |
|
|
my $parser = new Pod::POM; |
462 |
|
|
my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
463 |
|
|
|
464 |
|
|
my %skill_tooltip; |
465 |
|
|
|
466 |
|
|
for my $head2 ($pod->head1->[-2]->head2) { |
467 |
|
|
$skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
468 |
|
|
} |
469 |
|
|
|
470 |
|
|
for my $skill (values %{$self->{skill_info}}) { |
471 |
|
|
$self->{map_widget}->add_command ("ready_skill $skill", |
472 |
|
|
(CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
473 |
|
|
. $skill_tooltip{$skill}); |
474 |
|
|
$self->{map_widget}->add_command ("use_skill $skill", |
475 |
|
|
(CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
476 |
|
|
. $skill_tooltip{$skill}); |
477 |
|
|
} |
478 |
|
|
} |
479 |
|
|
|
480 |
|
|
sub eof { |
481 |
|
|
my ($self) = @_; |
482 |
|
|
|
483 |
|
|
$self->{map_widget}->clr_commands; |
484 |
|
|
|
485 |
|
|
::stop_game (); |
486 |
|
|
} |
487 |
|
|
|
488 |
|
|
sub image_info { |
489 |
|
|
my ($self, $numfaces) = @_; |
490 |
|
|
|
491 |
|
|
$self->{num_faces} = $numfaces; |
492 |
|
|
$self->{face_prefetch} = [1 .. $numfaces]; |
493 |
|
|
$self->face_prefetch; |
494 |
|
|
} |
495 |
|
|
|
496 |
|
|
sub face_prefetch { |
497 |
|
|
my ($self) = @_; |
498 |
|
|
|
499 |
|
|
return unless $::CFG->{face_prefetch}; |
500 |
|
|
|
501 |
|
|
if ($self->{num_faces}) { |
502 |
|
|
return if @{ $self->{send_queue} || [] }; |
503 |
|
|
my $todo = @{ $self->{face_prefetch} } |
504 |
|
|
or return; |
505 |
|
|
|
506 |
|
|
my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
507 |
|
|
|
508 |
|
|
$self->send ("requestinfo image_sums $face $face"); |
509 |
|
|
|
510 |
elmex |
1.5 |
$self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
511 |
root |
1.1 |
group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
512 |
|
|
} elsif (!exists $self->{num_faces}) { |
513 |
|
|
$self->send ("requestinfo image_info"); |
514 |
|
|
|
515 |
|
|
$self->{num_faces} = 0; |
516 |
|
|
|
517 |
elmex |
1.5 |
$self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
518 |
root |
1.1 |
group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
519 |
|
|
} |
520 |
|
|
} |
521 |
|
|
|
522 |
|
|
sub update_floorbox { |
523 |
|
|
$CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
524 |
|
|
return unless $::CONN; |
525 |
|
|
|
526 |
|
|
$::FLOORBOX->clear; |
527 |
|
|
|
528 |
|
|
my $row; |
529 |
|
|
for (@{ $::CONN->{container}{0} }) { |
530 |
|
|
if ($row < 7) { |
531 |
|
|
local $_->{face_widget}; # hack to force recreation of widget |
532 |
|
|
local $_->{desc_widget}; # hack to force recreation of widget |
533 |
|
|
CFClient::Item::update_widgets $_; |
534 |
|
|
|
535 |
|
|
$::FLOORBOX->add (0, $row, $_->{face_widget}); |
536 |
|
|
$::FLOORBOX->add (1, $row, $_->{desc_widget}); |
537 |
|
|
|
538 |
|
|
$row++; |
539 |
|
|
} else { |
540 |
|
|
$::FLOORBOX->add (1, $row, new CFClient::UI::Label text => "More..."); |
541 |
|
|
last; |
542 |
|
|
} |
543 |
|
|
} |
544 |
|
|
}); |
545 |
|
|
|
546 |
|
|
$::WANT_REFRESH++; |
547 |
|
|
} |
548 |
|
|
|
549 |
|
|
sub set_opencont { |
550 |
|
|
my ($conn, $tag, $name) = @_; |
551 |
|
|
$conn->{open_container} = $tag; |
552 |
elmex |
1.10 |
|
553 |
|
|
$::INV_RIGHT_HB->clear (); |
554 |
|
|
$::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
555 |
|
|
|
556 |
|
|
if ($tag != 0) { # Floor isn't closable, is it? |
557 |
|
|
$::INV_RIGHT_HB->add (new CFClient::UI::Button |
558 |
|
|
text => "Close container", |
559 |
|
|
tooltip => "Close the currently open container (if one is open)", |
560 |
|
|
on_activate => sub { |
561 |
|
|
$::CONN->send ("apply $tag") # $::CONN->{open_container}") |
562 |
|
|
if $tag != 0; |
563 |
|
|
#if $CONN->{open_container} != 0; |
564 |
|
|
}, |
565 |
|
|
); |
566 |
|
|
} |
567 |
|
|
|
568 |
root |
1.1 |
$::INVR->set_items ($conn->{container}{$tag}); |
569 |
|
|
} |
570 |
|
|
|
571 |
|
|
sub update_container { |
572 |
|
|
my ($tag) = @_; |
573 |
|
|
|
574 |
|
|
$::INVR->set_items ($::CONN->{container}{$::CONN->{open_container}}) |
575 |
|
|
if $tag == $::CONN->{open_container}; |
576 |
|
|
} |
577 |
|
|
|
578 |
|
|
sub container_add { |
579 |
|
|
my ($self, $tag, $items) = @_; |
580 |
|
|
|
581 |
|
|
#d# print "container_add: container $tag ($self->{player}{tag})\n"; |
582 |
|
|
|
583 |
|
|
if ($tag == 0) { |
584 |
|
|
update_floorbox; |
585 |
|
|
update_container (0); |
586 |
|
|
} elsif ($tag == $self->{player}{tag}) { |
587 |
|
|
$::INV->set_items ($self->{container}{$self->{player}{tag}}) |
588 |
|
|
} else { |
589 |
|
|
update_container ($tag); |
590 |
|
|
} |
591 |
|
|
|
592 |
|
|
# $self-<{player}{tag} => player inv |
593 |
|
|
#use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
594 |
|
|
} |
595 |
|
|
|
596 |
|
|
sub container_clear { |
597 |
|
|
my ($self, $tag) = @_; |
598 |
|
|
|
599 |
|
|
#d# print "container_clear: container $tag ($self->{player}{tag})\n"; |
600 |
|
|
|
601 |
|
|
if ($tag == 0) { |
602 |
|
|
update_floorbox; |
603 |
|
|
update_container (0); |
604 |
|
|
} elsif ($tag == $self->{player}{tag}) { |
605 |
|
|
$::INV->set_items ($self->{container}{$tag}) |
606 |
elmex |
1.12 |
} else { |
607 |
|
|
update_container ($tag); |
608 |
root |
1.1 |
} |
609 |
|
|
|
610 |
|
|
# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
611 |
|
|
} |
612 |
|
|
|
613 |
|
|
sub item_delete { |
614 |
|
|
my ($self, @items) = @_; |
615 |
|
|
|
616 |
|
|
for (@items) { |
617 |
|
|
#d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; |
618 |
|
|
|
619 |
|
|
if ($_->{container} == 0) { |
620 |
|
|
update_floorbox; |
621 |
|
|
update_container ($_->{tag}); |
622 |
|
|
} elsif ($_->{container} == $self->{player}{tag}) { |
623 |
|
|
$::INV->set_items ($self->{container}{$self->{player}{tag}}) |
624 |
|
|
} else { |
625 |
elmex |
1.12 |
update_container ($_->{container}); |
626 |
root |
1.1 |
} |
627 |
|
|
} |
628 |
|
|
} |
629 |
|
|
|
630 |
|
|
sub item_update { |
631 |
|
|
my ($self, $item) = @_; |
632 |
|
|
|
633 |
|
|
#d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
634 |
|
|
|
635 |
|
|
if ($item->{tag} == $self->{player}{tag}) { |
636 |
|
|
$::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $item->{weight} / 1000); |
637 |
|
|
return; |
638 |
|
|
} |
639 |
|
|
|
640 |
|
|
CFClient::Item::update_widgets $item; |
641 |
|
|
|
642 |
root |
1.2 |
if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
643 |
root |
1.1 |
set_opencont ($::CONN, 0, "Floor"); |
644 |
|
|
|
645 |
root |
1.2 |
} elsif ($item->{flags} & F_OPEN) { |
646 |
root |
1.1 |
set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
647 |
|
|
} else { |
648 |
|
|
if ($item->{container} == 0) { |
649 |
|
|
update_floorbox; |
650 |
|
|
update_container (0); |
651 |
|
|
} elsif ($item->{container} == $self->{player}{tag}) { |
652 |
|
|
$::INV->set_items ($self->{container}{$item->{container}}) |
653 |
|
|
} |
654 |
|
|
} |
655 |
|
|
} |
656 |
|
|
|
657 |
elmex |
1.3 |
sub player_update { |
658 |
|
|
my ($self, $player) = @_; |
659 |
|
|
$::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
660 |
root |
1.13 |
|
661 |
|
|
# do it here because it is ignored earlier, and there is no "login" event |
662 |
|
|
$self->send_command ("output-sync $::CFG->{output_sync}"); |
663 |
|
|
$self->send_command ("output-count $::CFG->{output_count}"); |
664 |
elmex |
1.3 |
} |
665 |
|
|
|
666 |
root |
1.1 |
1; |