… | |
… | |
68 | } |
68 | } |
69 | |
69 | |
70 | close CFG; |
70 | close CFG; |
71 | } |
71 | } |
72 | |
72 | |
73 | mkdir "$Crossfire::VARDIR/pclient", 0777; |
73 | mkdir "$Crossfire::VARDIR/cfplus", 0777; |
74 | |
74 | |
|
|
75 | our $DB_ENV; |
|
|
76 | |
|
|
77 | { |
|
|
78 | use strict; |
|
|
79 | |
|
|
80 | my $recover = $BerkeleyDB::db_version >= 4.4 |
|
|
81 | ? eval "DB_REGISTER | DB_RECOVER" |
|
|
82 | : 0; |
|
|
83 | |
75 | our $DB_ENV = new BerkeleyDB::Env |
84 | $DB_ENV = new BerkeleyDB::Env |
76 | -Home => "$Crossfire::VARDIR/pclient", |
85 | -Home => "$Crossfire::VARDIR/cfplus", |
77 | -Cachesize => 1_000_000, |
86 | -Cachesize => 1_000_000, |
78 | -ErrFile => "$Crossfire::VARDIR/pclient/errorlog.txt", |
87 | -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt", |
79 | # -ErrPrefix => "DATABASE", |
88 | # -ErrPrefix => "DATABASE", |
80 | -Verbose => 1, |
89 | -Verbose => 1, |
81 | -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN, |
90 | -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, |
|
|
91 | -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, |
82 | or die "unable to create/open database home $Crossfire::VARDIR/pclient: $BerkeleyDB::Error"; |
92 | or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error"; |
|
|
93 | } |
83 | |
94 | |
84 | sub db_table($) { |
95 | sub db_table($) { |
85 | my ($table) = @_; |
96 | my ($table) = @_; |
86 | |
97 | |
87 | $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
98 | $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
88 | |
99 | |
89 | new CFClient::Database |
100 | new CFClient::Database |
90 | -Env => $DB_ENV, |
101 | -Env => $DB_ENV, |
91 | -Filename => $table, |
102 | -Filename => $table, |
92 | # -Filename => "database", |
103 | # -Filename => "database", |
93 | # -Subname => $table, |
104 | # -Subname => $table, |
94 | -Property => DB_CHKSUM, |
105 | -Property => DB_CHKSUM, |
95 | -Flags => DB_CREATE | DB_UPGRADE, |
106 | -Flags => DB_CREATE | DB_UPGRADE, |
96 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; |
107 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" |
97 | } |
108 | } |
98 | |
109 | |
99 | sub pod_to_pango($) { |
110 | sub pod_to_pango($) { |
100 | my ($pom) = @_; |
111 | my ($pom) = @_; |
101 | |
112 | |
… | |
… | |
190 | $db->db_put ($key => $data) |
201 | $db->db_put ($key => $data) |
191 | } |
202 | } |
192 | |
203 | |
193 | package CFClient::Item; |
204 | package CFClient::Item; |
194 | |
205 | |
|
|
206 | use strict; |
|
|
207 | use Crossfire::Protocol::Constants; |
|
|
208 | |
|
|
209 | my $last_enter_count = 1; |
|
|
210 | |
195 | sub desc_string { |
211 | sub desc_string { |
196 | my ($self) = @_; |
212 | my ($self) = @_; |
197 | |
213 | |
198 | my $desc = |
214 | my $desc = |
199 | $self->{nrof} < 2 |
215 | $self->{nrof} < 2 |
200 | ? $self->{name} |
216 | ? $self->{name} |
201 | : "$self->{nrof} × $self->{name_pl}"; |
217 | : "$self->{nrof} × $self->{name_pl}"; |
202 | |
218 | |
203 | $self->{flags} & Crossfire::Protocol::F_OPEN |
219 | $self->{flags} & F_OPEN |
204 | and $desc .= " (open)"; |
220 | and $desc .= " (open)"; |
205 | $self->{flags} & Crossfire::Protocol::F_APPLIED |
221 | $self->{flags} & F_APPLIED |
206 | and $desc .= " (applied)"; |
222 | and $desc .= " (applied)"; |
207 | $self->{flags} & Crossfire::Protocol::F_UNPAID |
223 | $self->{flags} & F_UNPAID |
208 | and $desc .= " (unpaid)"; |
224 | and $desc .= " (unpaid)"; |
209 | $self->{flags} & Crossfire::Protocol::F_MAGIC |
225 | $self->{flags} & F_MAGIC |
210 | and $desc .= " (magic)"; |
226 | and $desc .= " (magic)"; |
211 | $self->{flags} & Crossfire::Protocol::F_CURSED |
227 | $self->{flags} & F_CURSED |
212 | and $desc .= " (cursed)"; |
228 | and $desc .= " (cursed)"; |
213 | $self->{flags} & Crossfire::Protocol::F_DAMNED |
229 | $self->{flags} & F_DAMNED |
214 | and $desc .= " (damned)"; |
230 | and $desc .= " (damned)"; |
215 | $self->{flags} & Crossfire::Protocol::F_LOCKED |
231 | $self->{flags} & F_LOCKED |
216 | and $desc .= " *"; |
232 | and $desc .= " *"; |
217 | |
233 | |
218 | $desc |
234 | $desc |
219 | } |
235 | } |
220 | |
236 | |
… | |
… | |
224 | my $weight = ($self->{nrof} || 1) * $self->{weight}; |
240 | my $weight = ($self->{nrof} || 1) * $self->{weight}; |
225 | |
241 | |
226 | $weight < 0 ? "?" : $weight * 0.001 |
242 | $weight < 0 ? "?" : $weight * 0.001 |
227 | } |
243 | } |
228 | |
244 | |
|
|
245 | sub do_n_dialog { |
|
|
246 | my ($cb) = @_; |
|
|
247 | |
|
|
248 | my $w = new CFClient::UI::FancyFrame; |
|
|
249 | $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center"); |
|
|
250 | $vb->add (new CFClient::UI::Label text => "Enter item count:"); |
|
|
251 | $vb->add (my $entry = new CFClient::UI::Entry |
|
|
252 | text => $last_enter_count, |
|
|
253 | on_activate => sub { |
|
|
254 | my ($entry) = @_; |
|
|
255 | $last_enter_count = $entry->get_text; |
|
|
256 | $cb->($last_enter_count); |
|
|
257 | $w->hide; |
|
|
258 | $w = undef; |
|
|
259 | } |
|
|
260 | ); |
|
|
261 | $entry->focus_in; |
|
|
262 | $w->show; |
|
|
263 | |
|
|
264 | } |
|
|
265 | |
229 | sub update_widgets { |
266 | sub update_widgets { |
230 | my ($self) = @_; |
267 | my ($self) = @_; |
231 | |
268 | |
232 | my $button_cb = sub { |
269 | my $button_cb = sub { |
233 | my (undef, $ev, $x, $y) = @_; |
270 | my (undef, $ev, $x, $y) = @_; |
234 | |
271 | |
|
|
272 | my $targ = $::CONN->{player}{tag}; |
|
|
273 | |
|
|
274 | if ($self->{container} == $::CONN->{player}{tag}) { |
|
|
275 | $targ = $::CONN->{open_container}; |
|
|
276 | } |
|
|
277 | |
235 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
278 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
236 | my $targ = $::CONN->{player}{tag}; |
|
|
237 | |
|
|
238 | if ($self->{container} == $::CONN->{player}{tag}) { |
|
|
239 | $targ = $::CONN->{open_container}; |
|
|
240 | } |
|
|
241 | |
|
|
242 | $::CONN->send ("move $targ $self->{tag} 0"); |
279 | $::CONN->send ("move $targ $self->{tag} 0") |
|
|
280 | if $targ || !($self->{flags} & F_LOCKED); |
243 | } elsif ($ev->{button} == 1) { |
281 | } elsif ($ev->{button} == 1) { |
244 | $::CONN->send ("examine $self->{tag}"); |
282 | $::CONN->send ("examine $self->{tag}"); |
245 | } elsif ($ev->{button} == 2) { |
283 | } elsif ($ev->{button} == 2) { |
246 | $::CONN->send ("apply $self->{tag}"); |
284 | $::CONN->send ("apply $self->{tag}"); |
247 | } elsif ($ev->{button} == 3) { |
285 | } elsif ($ev->{button} == 3) { |
248 | my @menu_items = ( |
286 | my @menu_items = ( |
249 | ["examine", sub { $::CONN->send ("examine $self->{tag}") }], |
287 | ["examine", sub { $::CONN->send ("examine $self->{tag}") }], |
250 | ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], |
288 | ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], |
251 | ["apply", sub { $::CONN->send ("apply $self->{tag}") }], |
289 | ["apply", sub { $::CONN->send ("apply $self->{tag}") }], |
252 | ( |
290 | ( |
253 | $self->{flags} & Crossfire::Protocol::F_LOCKED |
291 | $self->{flags} & F_LOCKED |
254 | ? ( |
292 | ? ( |
255 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], |
293 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], |
256 | ) |
294 | ) |
257 | : ( |
295 | : ( |
258 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], |
296 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], |
259 | ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], |
297 | ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], |
|
|
298 | ["move n", |
|
|
299 | sub { |
|
|
300 | do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") }) |
|
|
301 | } |
|
|
302 | ] |
260 | ) |
303 | ) |
261 | ), |
304 | ), |
262 | ); |
305 | ); |
263 | |
306 | |
264 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
307 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
… | |
… | |
277 | $self->{face_widget} ||= new CFClient::UI::Face |
320 | $self->{face_widget} ||= new CFClient::UI::Face |
278 | can_events => 1, |
321 | can_events => 1, |
279 | can_hover => 1, |
322 | can_hover => 1, |
280 | anim => $self->{anim}, |
323 | anim => $self->{anim}, |
281 | animspeed => $self->{animspeed}, # TODO# must be set at creation time |
324 | animspeed => $self->{animspeed}, # TODO# must be set at creation time |
282 | connect_button_down => $button_cb, |
325 | on_button_down => $button_cb, |
283 | ; |
326 | ; |
284 | $self->{face_widget}{face} = $self->{face}; |
327 | $self->{face_widget}{face} = $self->{face}; |
285 | $self->{face_widget}{anim} = $self->{anim}; |
328 | $self->{face_widget}{anim} = $self->{anim}; |
286 | $self->{face_widget}{animspeed} = $self->{animspeed}; |
329 | $self->{face_widget}{animspeed} = $self->{animspeed}; |
287 | $self->{face_widget}->set_tooltip ( |
330 | $self->{face_widget}->set_tooltip ( |
… | |
… | |
294 | $self->{desc_widget} ||= new CFClient::UI::Label |
337 | $self->{desc_widget} ||= new CFClient::UI::Label |
295 | can_events => 1, |
338 | can_events => 1, |
296 | can_hover => 1, |
339 | can_hover => 1, |
297 | ellipsise => 2, |
340 | ellipsise => 2, |
298 | align => -1, |
341 | align => -1, |
299 | connect_button_down => $button_cb, |
342 | on_button_down => $button_cb, |
300 | ; |
343 | ; |
301 | my $desc = CFClient::Item::desc_string $self; |
344 | my $desc = CFClient::Item::desc_string $self; |
302 | $self->{desc_widget}->set_text ($desc); |
345 | $self->{desc_widget}->set_text ($desc); |
303 | $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); |
346 | $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); |
304 | |
347 | |
305 | $self->{weight_widget} ||= new CFClient::UI::Label |
348 | $self->{weight_widget} ||= new CFClient::UI::Label |
306 | can_events => 1, |
349 | can_events => 1, |
307 | can_hover => 1, |
350 | can_hover => 1, |
308 | ellipsise => 0, |
351 | ellipsise => 0, |
309 | align => 0, |
352 | align => 0, |
310 | connect_button_down => $button_cb, |
353 | on_button_down => $button_cb, |
311 | ; |
354 | ; |
312 | $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); |
355 | $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); |
313 | |
356 | |
314 | $self->{weight_widget}->set_tooltip ( |
357 | $self->{weight_widget}->set_tooltip ( |
315 | "<b>Weight</b>.\n" |
358 | "<b>Weight</b>.\n" |
… | |
… | |
317 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
360 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
318 | . "\n\n$tooltip_std" |
361 | . "\n\n$tooltip_std" |
319 | ); |
362 | ); |
320 | } |
363 | } |
321 | |
364 | |
|
|
365 | package CFClient::Binder; |
|
|
366 | |
|
|
367 | my @ALLOWED_MODIFIER_KEYS = ( |
|
|
368 | CFClient::SDLK_LSHIFT, |
|
|
369 | CFClient::SDLK_LCTRL , |
|
|
370 | CFClient::SDLK_LALT , |
|
|
371 | CFClient::SDLK_LMETA , |
|
|
372 | |
|
|
373 | CFClient::SDLK_RSHIFT, |
|
|
374 | CFClient::SDLK_RCTRL , |
|
|
375 | CFClient::SDLK_RALT , |
|
|
376 | CFClient::SDLK_RMETA , |
|
|
377 | ); |
|
|
378 | |
|
|
379 | my %ALLOWED_MODIFIERS = ( |
|
|
380 | CFClient::KMOD_LSHIFT => "LSHIFT", |
|
|
381 | CFClient::KMOD_LCTRL => "LCTRL", |
|
|
382 | CFClient::KMOD_LALT => "LALT", |
|
|
383 | CFClient::KMOD_LMETA => "LMETA", |
|
|
384 | |
|
|
385 | CFClient::KMOD_RSHIFT => "RSHIFT", |
|
|
386 | CFClient::KMOD_RCTRL => "RCTRL", |
|
|
387 | CFClient::KMOD_RALT => "RALT", |
|
|
388 | CFClient::KMOD_RMETA => "RMETA", |
|
|
389 | ); |
|
|
390 | |
|
|
391 | my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/; |
|
|
392 | my @DIRECT_BIND_KEYS = ( |
|
|
393 | CFClient::SDLK_F1, |
|
|
394 | CFClient::SDLK_F2, |
|
|
395 | CFClient::SDLK_F3, |
|
|
396 | CFClient::SDLK_F4, |
|
|
397 | CFClient::SDLK_F5, |
|
|
398 | CFClient::SDLK_F6, |
|
|
399 | CFClient::SDLK_F7, |
|
|
400 | CFClient::SDLK_F8, |
|
|
401 | CFClient::SDLK_F9, |
|
|
402 | CFClient::SDLK_F10, |
|
|
403 | CFClient::SDLK_F11, |
|
|
404 | CFClient::SDLK_F12, |
|
|
405 | CFClient::SDLK_F13, |
|
|
406 | CFClient::SDLK_F14, |
|
|
407 | CFClient::SDLK_F15, |
|
|
408 | ); |
|
|
409 | |
|
|
410 | # this binding dialog asks for a key-combo to be pressed |
|
|
411 | # and if successful it calls the $cb with $mod and $sym as args. |
|
|
412 | sub open_binding_dialog { |
|
|
413 | my ($cb) = @_; |
|
|
414 | |
|
|
415 | my $w = new CFClient::UI::FancyFrame |
|
|
416 | title => "Bind Action", |
|
|
417 | x => "center", |
|
|
418 | y => "center"; |
|
|
419 | |
|
|
420 | $w->add (my $vb = new CFClient::UI::VBox); |
|
|
421 | $vb->add (new CFClient::UI::Label |
|
|
422 | text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key." |
|
|
423 | ."You can only bind 0-9 and F1-F15 without modifiers." |
|
|
424 | ); |
|
|
425 | $vb->add (my $entry = new CFClient::UI::Entry |
|
|
426 | text => "", |
|
|
427 | on_key_down => sub { |
|
|
428 | my ($entry, $ev) = @_; |
|
|
429 | |
|
|
430 | my $mod = $ev->{mod}; |
|
|
431 | my $sym = $ev->{sym}; |
|
|
432 | |
|
|
433 | # XXX: This seems a little bit hackisch to me, but i have to ignore them |
|
|
434 | if (grep { $_ == $sym } @ALLOWED_MODIFIER_KEYS) { |
|
|
435 | return; |
|
|
436 | } |
|
|
437 | |
|
|
438 | if ($mod == CFClient::KMOD_NONE |
|
|
439 | and not $DIRECT_BIND_CHARS{chr ($ev->{unicode})} |
|
|
440 | and not grep { $sym == $_ } @DIRECT_BIND_KEYS) |
|
|
441 | { |
|
|
442 | $::STATUSBOX->add ( |
|
|
443 | "Can't bind key ".CFClient::SDL_GetKeyName ($sym) |
|
|
444 | ." directly without modifier! It would damage the completer handling." |
|
|
445 | ); |
|
|
446 | return; |
|
|
447 | } |
|
|
448 | |
|
|
449 | $entry->focus_out; |
|
|
450 | |
|
|
451 | $cb->($mod, $sym); |
|
|
452 | |
|
|
453 | $w->destroy |
|
|
454 | }); |
|
|
455 | |
|
|
456 | $entry->focus_in; |
|
|
457 | $w->show; |
|
|
458 | } |
|
|
459 | |
|
|
460 | sub keycombo_to_name { |
|
|
461 | my ($mod, $sym) = @_; |
|
|
462 | |
|
|
463 | my $mods = join '+', |
|
|
464 | map { $ALLOWED_MODIFIERS{$_} } |
|
|
465 | grep { ($_ + 0) & ($mod + 0) } |
|
|
466 | keys %ALLOWED_MODIFIERS; |
|
|
467 | $mods .= "+" if $mods ne ''; |
|
|
468 | |
|
|
469 | return $mods . CFClient::SDL_GetKeyName ($sym); |
|
|
470 | } |
|
|
471 | |
322 | 1; |
472 | 1; |
323 | |
473 | |
324 | =back |
474 | =back |
325 | |
475 | |
326 | =head1 AUTHOR |
476 | =head1 AUTHOR |