ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.72 by root, Sat May 27 20:46:54 2006 UTC vs.
Revision 1.84 by elmex, Wed May 31 12:44:17 2006 UTC

68 } 68 }
69 69
70 close CFG; 70 close CFG;
71} 71}
72 72
73mkdir "$Crossfire::VARDIR/pclient", 0777; 73mkdir "$Crossfire::VARDIR/cfplus", 0777;
74 74
75our $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
75our $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
84sub db_table($) { 95sub 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
99sub pod_to_pango($) { 110sub pod_to_pango($) {
100 my ($pom) = @_; 111 my ($pom) = @_;
101 112
192 203
193package CFClient::Item; 204package CFClient::Item;
194 205
195use strict; 206use strict;
196use Crossfire::Protocol::Constants; 207use Crossfire::Protocol::Constants;
208
209my $last_enter_count = 1;
197 210
198sub desc_string { 211sub desc_string {
199 my ($self) = @_; 212 my ($self) = @_;
200 213
201 my $desc = 214 my $desc =
227 my $weight = ($self->{nrof} || 1) * $self->{weight}; 240 my $weight = ($self->{nrof} || 1) * $self->{weight};
228 241
229 $weight < 0 ? "?" : $weight * 0.001 242 $weight < 0 ? "?" : $weight * 0.001
230} 243}
231 244
245sub 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
232sub update_widgets { 266sub update_widgets {
233 my ($self) = @_; 267 my ($self) = @_;
234 268
235 my $button_cb = sub { 269 my $button_cb = sub {
236 my (undef, $ev, $x, $y) = @_; 270 my (undef, $ev, $x, $y) = @_;
237 271
272 my $targ = $::CONN->{player}{tag};
273
274 if ($self->{container} == $::CONN->{player}{tag}) {
275 $targ = $::CONN->{open_container};
276 }
277
238 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { 278 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
239 my $targ = $::CONN->{player}{tag};
240
241 if ($self->{container} == $::CONN->{player}{tag}) {
242 $targ = $::CONN->{open_container};
243 }
244
245 $::CONN->send ("move $targ $self->{tag} 0"); 279 $::CONN->send ("move $targ $self->{tag} 0")
280 if $targ || !($self->{flags} & F_LOCKED);
246 } elsif ($ev->{button} == 1) { 281 } elsif ($ev->{button} == 1) {
247 $::CONN->send ("examine $self->{tag}"); 282 $::CONN->send ("examine $self->{tag}");
248 } elsif ($ev->{button} == 2) { 283 } elsif ($ev->{button} == 2) {
249 $::CONN->send ("apply $self->{tag}"); 284 $::CONN->send ("apply $self->{tag}");
250 } elsif ($ev->{button} == 3) { 285 } elsif ($ev->{button} == 3) {
258 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], 293 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }],
259 ) 294 )
260 : ( 295 : (
261 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], 296 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }],
262 ["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 ]
263 ) 303 )
264 ), 304 ),
265 ); 305 );
266 306
267 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 307 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
320 . ($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. ")
321 . "\n\n$tooltip_std" 361 . "\n\n$tooltip_std"
322 ); 362 );
323} 363}
324 364
365package CFClient::Binder;
366
367my @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
379my %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
391my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/;
392my @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.
412sub 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
460sub 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
3251; 4721;
326 473
327=back 474=back
328 475
329=head1 AUTHOR 476=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines