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.71 by root, Fri May 26 20:36:32 2006 UTC vs.
Revision 1.82 by root, Wed May 31 07:13:50 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 warn $recover;
84
75our $DB_ENV = new BerkeleyDB::Env 85 $DB_ENV = new BerkeleyDB::Env
76 -Home => "$Crossfire::VARDIR/pclient", 86 -Home => "$Crossfire::VARDIR/cfplus",
77 -Cachesize => 1_000_000, 87 -Cachesize => 1_000_000,
78 -ErrFile => "$Crossfire::VARDIR/pclient/errorlog.txt", 88 -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt",
79# -ErrPrefix => "DATABASE", 89# -ErrPrefix => "DATABASE",
80 -Verbose => 1, 90 -Verbose => 1,
81 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN, 91 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover,
92 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE,
82 or die "unable to create/open database home $Crossfire::VARDIR/pclient: $BerkeleyDB::Error"; 93 or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error";
94}
83 95
84sub db_table($) { 96sub db_table($) {
85 my ($table) = @_; 97 my ($table) = @_;
86 98
87 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 99 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
88 100
89 new CFClient::Database 101 new CFClient::Database
90 -Env => $DB_ENV, 102 -Env => $DB_ENV,
91 -Filename => $table, 103 -Filename => $table,
92# -Filename => "database", 104# -Filename => "database",
93# -Subname => $table, 105# -Subname => $table,
94 -Property => DB_CHKSUM, 106 -Property => DB_CHKSUM,
95 -Flags => DB_CREATE | DB_UPGRADE, 107 -Flags => DB_CREATE | DB_UPGRADE,
96 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; 108 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
97} 109}
98 110
99sub pod_to_pango($) { 111sub pod_to_pango($) {
100 my ($pom) = @_; 112 my ($pom) = @_;
101 113
240 252
241 if ($self->{container} == $::CONN->{player}{tag}) { 253 if ($self->{container} == $::CONN->{player}{tag}) {
242 $targ = $::CONN->{open_container}; 254 $targ = $::CONN->{open_container};
243 } 255 }
244 256
245 $::CONN->send ("move $targ $self->{tag} 0"); 257 $::CONN->send ("move $targ $self->{tag} 0")
258 if $targ || !($self->{flags} & F_LOCKED);
246 } elsif ($ev->{button} == 1) { 259 } elsif ($ev->{button} == 1) {
247 $::CONN->send ("examine $self->{tag}"); 260 $::CONN->send ("examine $self->{tag}");
248 } elsif ($ev->{button} == 2) { 261 } elsif ($ev->{button} == 2) {
249 $::CONN->send ("apply $self->{tag}"); 262 $::CONN->send ("apply $self->{tag}");
250 } elsif ($ev->{button} == 3) { 263 } elsif ($ev->{button} == 3) {
280 $self->{face_widget} ||= new CFClient::UI::Face 293 $self->{face_widget} ||= new CFClient::UI::Face
281 can_events => 1, 294 can_events => 1,
282 can_hover => 1, 295 can_hover => 1,
283 anim => $self->{anim}, 296 anim => $self->{anim},
284 animspeed => $self->{animspeed}, # TODO# must be set at creation time 297 animspeed => $self->{animspeed}, # TODO# must be set at creation time
285 connect_button_down => $button_cb, 298 on_button_down => $button_cb,
286 ; 299 ;
287 $self->{face_widget}{face} = $self->{face}; 300 $self->{face_widget}{face} = $self->{face};
288 $self->{face_widget}{anim} = $self->{anim}; 301 $self->{face_widget}{anim} = $self->{anim};
289 $self->{face_widget}{animspeed} = $self->{animspeed}; 302 $self->{face_widget}{animspeed} = $self->{animspeed};
290 $self->{face_widget}->set_tooltip ( 303 $self->{face_widget}->set_tooltip (
297 $self->{desc_widget} ||= new CFClient::UI::Label 310 $self->{desc_widget} ||= new CFClient::UI::Label
298 can_events => 1, 311 can_events => 1,
299 can_hover => 1, 312 can_hover => 1,
300 ellipsise => 2, 313 ellipsise => 2,
301 align => -1, 314 align => -1,
302 connect_button_down => $button_cb, 315 on_button_down => $button_cb,
303 ; 316 ;
304 my $desc = CFClient::Item::desc_string $self; 317 my $desc = CFClient::Item::desc_string $self;
305 $self->{desc_widget}->set_text ($desc); 318 $self->{desc_widget}->set_text ($desc);
306 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); 319 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std");
307 320
308 $self->{weight_widget} ||= new CFClient::UI::Label 321 $self->{weight_widget} ||= new CFClient::UI::Label
309 can_events => 1, 322 can_events => 1,
310 can_hover => 1, 323 can_hover => 1,
311 ellipsise => 0, 324 ellipsise => 0,
312 align => 0, 325 align => 0,
313 connect_button_down => $button_cb, 326 on_button_down => $button_cb,
314 ; 327 ;
315 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); 328 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self);
316 329
317 $self->{weight_widget}->set_tooltip ( 330 $self->{weight_widget}->set_tooltip (
318 "<b>Weight</b>.\n" 331 "<b>Weight</b>.\n"
320 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") 333 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ")
321 . "\n\n$tooltip_std" 334 . "\n\n$tooltip_std"
322 ); 335 );
323} 336}
324 337
338package CFClient::Binder;
339
340my @ALLOWED_MODIFIER_KEYS = (
341 (CFClient::SDLK_LSHIFT),
342 (CFClient::SDLK_LCTRL ),
343 (CFClient::SDLK_LALT ),
344 (CFClient::SDLK_LMETA ),
345
346 (CFClient::SDLK_RSHIFT),
347 (CFClient::SDLK_RCTRL ),
348 (CFClient::SDLK_RALT ),
349 (CFClient::SDLK_RMETA ),
350);
351
352my %ALLOWED_MODIFIERS = (
353 (CFClient::KMOD_LSHIFT) => "LSHIFT",
354 (CFClient::KMOD_LCTRL ) => "LCTRL",
355 (CFClient::KMOD_LALT ) => "LALT",
356 (CFClient::KMOD_LMETA ) => "LMETA",
357
358 (CFClient::KMOD_RSHIFT) => "RSHIFT",
359 (CFClient::KMOD_RCTRL ) => "RCTRL",
360 (CFClient::KMOD_RALT ) => "RALT",
361 (CFClient::KMOD_RMETA ) => "RMETA",
362);
363
364my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/;
365my @DIRECT_BIND_KEYS = (
366 CFClient::SDLK_F1,
367 CFClient::SDLK_F2,
368 CFClient::SDLK_F3,
369 CFClient::SDLK_F4,
370 CFClient::SDLK_F5,
371 CFClient::SDLK_F6,
372 CFClient::SDLK_F7,
373 CFClient::SDLK_F8,
374 CFClient::SDLK_F9,
375 CFClient::SDLK_F10,
376 CFClient::SDLK_F11,
377 CFClient::SDLK_F12,
378 CFClient::SDLK_F13,
379 CFClient::SDLK_F14,
380 CFClient::SDLK_F15,
381);
382
383# this binding dialog asks for a key-combo to be pressed
384# and if successful it calls the $cb with $mod and $sym as args.
385sub open_binding_dialog {
386 my ($cb) = @_;
387
388 my $w = new CFClient::UI::FancyFrame
389 title => "Bind Action",
390 x => "center",
391 y => "center";
392
393 $w->add (my $vb = new CFClient::UI::VBox);
394 $vb->add (new CFClient::UI::Label
395 text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key."
396 ."You can only bind 0-9 and F1-F15 without modifiers."
397 );
398 $vb->add (my $entry = new CFClient::UI::Entry
399 text => "",
400 on_key_down => sub {
401 my ($entry, $ev) = @_;
402
403 my $mod = $ev->{mod};
404 my $sym = $ev->{sym};
405
406 # XXX: This seems a little bit hackisch to me, but i have to ignore them
407 if (grep { $_ == $sym } @ALLOWED_MODIFIER_KEYS) {
408 return;
409 }
410
411 if ($mod == CFClient::KMOD_NONE
412 and not $DIRECT_BIND_CHARS{chr ($ev->{unicode})}
413 and not grep { $sym == $_ } @DIRECT_BIND_KEYS)
414 {
415 $::STATUSBOX->add (
416 "Can't bind key ".CFClient::SDL_GetKeyName ($sym)
417 ." directly without modifier! It would damage the completer handling."
418 );
419 return;
420 }
421
422 $entry->focus_out;
423
424 $cb->($mod, $sym);
425
426 $w->destroy
427 });
428
429 $entry->focus_in;
430 $w->show;
431}
432
433sub keycombo_to_name {
434 my ($mod, $sym) = @_;
435
436 my $mods = join '+',
437 map { $ALLOWED_MODIFIERS{$_} }
438 grep { ($_ + 0) & ($mod + 0) }
439 keys %ALLOWED_MODIFIERS;
440 $mods .= "+" if $mods ne '';
441
442 return $mods . CFClient::SDL_GetKeyName ($sym);
443}
444
3251; 4451;
326 446
327=back 447=back
328 448
329=head1 AUTHOR 449=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines