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.70 by root, Fri May 26 18:28:23 2006 UTC vs.
Revision 1.88 by root, Mon Jun 5 05:31:13 2006 UTC

24use utf8; 24use utf8;
25 25
26use Carp (); 26use Carp ();
27use AnyEvent (); 27use AnyEvent ();
28use BerkeleyDB; 28use BerkeleyDB;
29use Pod::POM;
29 30
30sub find_rcfile($) { 31sub find_rcfile($) {
31 my $path; 32 my $path;
32 33
33 for (grep !ref, @INC) { 34 for (grep !ref, @INC) {
68 } 69 }
69 70
70 close CFG; 71 close CFG;
71} 72}
72 73
74my %POD_CACHE;
75
76sub load_pod($) {
77 $POD_CACHE{$_[0]} ||= do {
78 my $pod = do {
79 local $/;
80 open my $pod, "<:utf8", $_[0]
81 or die "$_[0]: $!";
82 <$pod>
83 };
84
85 Pod::POM->new->parse_text ($pod)
86 }
87}
88
89our $DB_ENV;
90
91{
92 use strict;
93
73mkdir "$Crossfire::VARDIR/pclient", 0777; 94 mkdir "$Crossfire::VARDIR/cfplus", 0777;
95 my $recover = $BerkeleyDB::db_version >= 4.4
96 ? eval "DB_REGISTER | DB_RECOVER"
97 : 0;
74 98
75our $DB_ENV = new BerkeleyDB::Env 99 $DB_ENV = new BerkeleyDB::Env
76 -Home => "$Crossfire::VARDIR/pclient", 100 -Home => "$Crossfire::VARDIR/cfplus",
77 -Cachesize => 1_000_000, 101 -Cachesize => 1_000_000,
78 -ErrFile => "$Crossfire::VARDIR/pclient/errorlog.txt", 102 -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt",
79# -ErrPrefix => "DATABASE", 103# -ErrPrefix => "DATABASE",
80 -Verbose => 1, 104 -Verbose => 1,
81 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN, 105 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover,
106 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE,
82 or die "unable to create/open database home $Crossfire::VARDIR/pclient: $BerkeleyDB::Error"; 107 or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error";
108}
83 109
84sub db_table($) { 110sub db_table($) {
85 my ($table) = @_; 111 my ($table) = @_;
86 112
87 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 113 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
88 114
89 new CFClient::Database 115 new CFClient::Database
90 -Env => $DB_ENV, 116 -Env => $DB_ENV,
91 -Filename => $table, 117 -Filename => $table,
92# -Filename => "database", 118# -Filename => "database",
93# -Subname => $table, 119# -Subname => $table,
94 -Property => DB_CHKSUM, 120 -Property => DB_CHKSUM,
95 -Flags => DB_CREATE | DB_UPGRADE, 121 -Flags => DB_CREATE | DB_UPGRADE,
96 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; 122 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
97} 123}
98 124
99sub pod_to_pango($) { 125sub pod_to_pango($) {
100 my ($pom) = @_; 126 my ($pom) = @_;
101 127
190 $db->db_put ($key => $data) 216 $db->db_put ($key => $data)
191} 217}
192 218
193package CFClient::Item; 219package CFClient::Item;
194 220
221use strict;
222use Crossfire::Protocol::Constants;
223
224my $last_enter_count = 1;
225
195sub desc_string { 226sub desc_string {
196 my ($self) = @_; 227 my ($self) = @_;
197 228
198 my $desc = 229 my $desc =
199 $self->{nrof} < 2 230 $self->{nrof} < 2
200 ? $self->{name} 231 ? $self->{name}
201 : "$self->{nrof} × $self->{name_pl}"; 232 : "$self->{nrof} × $self->{name_pl}";
202 233
203 $self->{flags} & Crossfire::Protocol::F_OPEN 234 $self->{flags} & F_OPEN
204 and $desc .= " (open)"; 235 and $desc .= " (open)";
205 $self->{flags} & Crossfire::Protocol::F_APPLIED 236 $self->{flags} & F_APPLIED
206 and $desc .= " (applied)"; 237 and $desc .= " (applied)";
207 $self->{flags} & Crossfire::Protocol::F_UNPAID 238 $self->{flags} & F_UNPAID
208 and $desc .= " (unpaid)"; 239 and $desc .= " (unpaid)";
209 $self->{flags} & Crossfire::Protocol::F_MAGIC 240 $self->{flags} & F_MAGIC
210 and $desc .= " (magic)"; 241 and $desc .= " (magic)";
211 $self->{flags} & Crossfire::Protocol::F_CURSED 242 $self->{flags} & F_CURSED
212 and $desc .= " (cursed)"; 243 and $desc .= " (cursed)";
213 $self->{flags} & Crossfire::Protocol::F_DAMNED 244 $self->{flags} & F_DAMNED
214 and $desc .= " (damned)"; 245 and $desc .= " (damned)";
215 $self->{flags} & Crossfire::Protocol::F_LOCKED 246 $self->{flags} & F_LOCKED
216 and $desc .= " *"; 247 and $desc .= " *";
217 248
218 $desc 249 $desc
219} 250}
220 251
224 my $weight = ($self->{nrof} || 1) * $self->{weight}; 255 my $weight = ($self->{nrof} || 1) * $self->{weight};
225 256
226 $weight < 0 ? "?" : $weight * 0.001 257 $weight < 0 ? "?" : $weight * 0.001
227} 258}
228 259
260sub do_n_dialog {
261 my ($cb) = @_;
262
263 my $w = new CFClient::UI::FancyFrame;
264 $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center");
265 $vb->add (new CFClient::UI::Label text => "Enter item count:");
266 $vb->add (my $entry = new CFClient::UI::Entry
267 text => $last_enter_count,
268 on_activate => sub {
269 my ($entry) = @_;
270 $last_enter_count = $entry->get_text;
271 $cb->($last_enter_count);
272 $w->hide;
273 $w = undef;
274 }
275 );
276 $entry->focus_in;
277 $w->show;
278
279}
280
229sub update_widgets { 281sub update_widgets {
230 my ($self) = @_; 282 my ($self) = @_;
231 283
232 my $button_cb = sub { 284 my $button_cb = sub {
233 my (undef, $ev, $x, $y) = @_; 285 my (undef, $ev, $x, $y) = @_;
234 286
287 my $targ = $::CONN->{player}{tag};
288
289 if ($self->{container} == $::CONN->{player}{tag}) {
290 $targ = $::CONN->{open_container};
291 }
292
235 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { 293 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"); 294 $::CONN->send ("move $targ $self->{tag} 0")
295 if $targ || !($self->{flags} & F_LOCKED);
296 } elsif (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 2) {
297 $self->{flags} & F_LOCKED
298 ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag})
299 : $::CONN->send ("lock " . pack "CN", 1, $self->{tag})
243 } elsif ($ev->{button} == 1) { 300 } elsif ($ev->{button} == 1) {
244 $::CONN->send ("examine $self->{tag}"); 301 $::CONN->send ("examine $self->{tag}");
245 } elsif ($ev->{button} == 2) { 302 } elsif ($ev->{button} == 2) {
246 $::CONN->send ("apply $self->{tag}"); 303 $::CONN->send ("apply $self->{tag}");
247 } elsif ($ev->{button} == 3) { 304 } elsif ($ev->{button} == 3) {
248 my @menu_items = ( 305 my @menu_items = (
249 ["examine", sub { $::CONN->send ("examine $self->{tag}") }], 306 ["examine", sub { $::CONN->send ("examine $self->{tag}") }],
250 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 307 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
251 ["apply", sub { $::CONN->send ("apply $self->{tag}") }], 308 ["apply", sub { $::CONN->send ("apply $self->{tag}") }],
252 ( 309 (
253 $self->{flags} & Crossfire::Protocol::F_LOCKED 310 $self->{flags} & F_LOCKED
254 ? ( 311 ? (
255 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], 312 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }],
256 ) 313 )
257 : ( 314 : (
258 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], 315 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }],
259 ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], 316 ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }],
317 ["move n",
318 sub {
319 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") })
320 }
321 ]
260 ) 322 )
261 ), 323 ),
262 ); 324 );
263 325
264 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 326 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
269 331
270 my $tooltip_std = "<small>" 332 my $tooltip_std = "<small>"
271 . "Left click - examine item\n" 333 . "Left click - examine item\n"
272 . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" 334 . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n"
273 . "Middle click - apply\n" 335 . "Middle click - apply\n"
336 . "Shift-Middle click - lock/unlock\n"
274 . "Right click - further options" 337 . "Right click - further options"
275 . "</small>\n"; 338 . "</small>\n";
276 339
277 $self->{face_widget} ||= new CFClient::UI::Face 340 $self->{face_widget} ||= new CFClient::UI::Face
278 can_events => 1, 341 can_events => 1,
279 can_hover => 1, 342 can_hover => 1,
280 anim => $self->{anim}, 343 anim => $self->{anim},
281 animspeed => $self->{animspeed}, # TODO# must be set at creation time 344 animspeed => $self->{animspeed}, # TODO# must be set at creation time
282 connect_button_down => $button_cb, 345 on_button_down => $button_cb,
283 ; 346 ;
284 $self->{face_widget}{face} = $self->{face}; 347 $self->{face_widget}{face} = $self->{face};
285 $self->{face_widget}{anim} = $self->{anim}; 348 $self->{face_widget}{anim} = $self->{anim};
286 $self->{face_widget}{animspeed} = $self->{animspeed}; 349 $self->{face_widget}{animspeed} = $self->{animspeed};
287 $self->{face_widget}->set_tooltip ( 350 $self->{face_widget}->set_tooltip (
294 $self->{desc_widget} ||= new CFClient::UI::Label 357 $self->{desc_widget} ||= new CFClient::UI::Label
295 can_events => 1, 358 can_events => 1,
296 can_hover => 1, 359 can_hover => 1,
297 ellipsise => 2, 360 ellipsise => 2,
298 align => -1, 361 align => -1,
299 connect_button_down => $button_cb, 362 on_button_down => $button_cb,
300 ; 363 ;
301 my $desc = CFClient::Item::desc_string $self; 364 my $desc = CFClient::Item::desc_string $self;
302 $self->{desc_widget}->set_text ($desc); 365 $self->{desc_widget}->set_text ($desc);
303 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); 366 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std");
304 367
305 $self->{weight_widget} ||= new CFClient::UI::Label 368 $self->{weight_widget} ||= new CFClient::UI::Label
306 can_events => 1, 369 can_events => 1,
307 can_hover => 1, 370 can_hover => 1,
308 ellipsise => 0, 371 ellipsise => 0,
309 align => 0, 372 align => 0,
310 connect_button_down => $button_cb, 373 on_button_down => $button_cb,
311 ; 374 ;
312 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); 375 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self);
313 376
314 $self->{weight_widget}->set_tooltip ( 377 $self->{weight_widget}->set_tooltip (
315 "<b>Weight</b>.\n" 378 "<b>Weight</b>.\n"
317 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") 380 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ")
318 . "\n\n$tooltip_std" 381 . "\n\n$tooltip_std"
319 ); 382 );
320} 383}
321 384
385package CFClient::Binder;
386
387my @ALLOWED_MODIFIER_KEYS = (
388 CFClient::SDLK_LSHIFT,
389 CFClient::SDLK_LCTRL ,
390 CFClient::SDLK_LALT ,
391 CFClient::SDLK_LMETA ,
392
393 CFClient::SDLK_RSHIFT,
394 CFClient::SDLK_RCTRL ,
395 CFClient::SDLK_RALT ,
396 CFClient::SDLK_RMETA ,
397);
398
399my %ALLOWED_MODIFIERS = (
400 CFClient::KMOD_LSHIFT => "LSHIFT",
401 CFClient::KMOD_LCTRL => "LCTRL",
402 CFClient::KMOD_LALT => "LALT",
403 CFClient::KMOD_LMETA => "LMETA",
404
405 CFClient::KMOD_RSHIFT => "RSHIFT",
406 CFClient::KMOD_RCTRL => "RCTRL",
407 CFClient::KMOD_RALT => "RALT",
408 CFClient::KMOD_RMETA => "RMETA",
409);
410
411my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/;
412my @DIRECT_BIND_KEYS = (
413 CFClient::SDLK_F1,
414 CFClient::SDLK_F2,
415 CFClient::SDLK_F3,
416 CFClient::SDLK_F4,
417 CFClient::SDLK_F5,
418 CFClient::SDLK_F6,
419 CFClient::SDLK_F7,
420 CFClient::SDLK_F8,
421 CFClient::SDLK_F9,
422 CFClient::SDLK_F10,
423 CFClient::SDLK_F11,
424 CFClient::SDLK_F12,
425 CFClient::SDLK_F13,
426 CFClient::SDLK_F14,
427 CFClient::SDLK_F15,
428);
429
430# this binding dialog asks for a key-combo to be pressed
431# and if successful it calls the $cb with $mod and $sym as args.
432sub open_binding_dialog {
433 my ($cb) = @_;
434
435 my $w = new CFClient::UI::FancyFrame
436 title => "Bind Action",
437 x => "center",
438 y => "center";
439
440 $w->add (my $vb = new CFClient::UI::VBox);
441 $vb->add (new CFClient::UI::Label
442 text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key."
443 ."You can only bind 0-9 and F1-F15 without modifiers."
444 );
445 $vb->add (my $entry = new CFClient::UI::Entry
446 text => "",
447 on_key_down => sub {
448 my ($entry, $ev) = @_;
449
450 my $mod = $ev->{mod};
451 my $sym = $ev->{sym};
452
453 # XXX: This seems a little bit hackisch to me, but i have to ignore them
454 if (grep { $_ == $sym } @ALLOWED_MODIFIER_KEYS) {
455 return;
456 }
457
458 if ($mod == CFClient::KMOD_NONE
459 and not $DIRECT_BIND_CHARS{chr ($ev->{unicode})}
460 and not grep { $sym == $_ } @DIRECT_BIND_KEYS)
461 {
462 $::STATUSBOX->add (
463 "Can't bind key ".CFClient::SDL_GetKeyName ($sym)
464 ." directly without modifier! It would damage the completer handling."
465 );
466 return;
467 }
468
469 $entry->focus_out;
470
471 $cb->($mod, $sym);
472
473 $w->destroy
474 });
475
476 $entry->focus_in;
477 $w->show;
478}
479
480sub keycombo_to_name {
481 my ($mod, $sym) = @_;
482
483 my $mods = join '+',
484 map { $ALLOWED_MODIFIERS{$_} }
485 grep { ($_ + 0) & ($mod + 0) }
486 keys %ALLOWED_MODIFIERS;
487 $mods .= "+" if $mods ne '';
488
489 return $mods . CFClient::SDL_GetKeyName ($sym);
490}
491
492package CFClient::Pickup;
493# some pickup constants
494sub PU_NOTHING { 0x00000000 }
495
496sub PU_DEBUG { 0x10000000 }
497sub PU_INHIBIT { 0x20000000 }
498sub PU_STOP { 0x40000000 }
499sub PU_NEWMODE { 0x80000000 }
500
501sub PU_RATIO { 0x0000000F }
502
503sub PU_FOOD { 0x00000010 }
504sub PU_DRINK { 0x00000020 }
505sub PU_VALUABLES { 0x00000040 }
506sub PU_BOW { 0x00000080 }
507
508sub PU_ARROW { 0x00000100 }
509sub PU_HELMET { 0x00000200 }
510sub PU_SHIELD { 0x00000400 }
511sub PU_ARMOUR { 0x00000800 }
512
513sub PU_BOOTS { 0x00001000 }
514sub PU_GLOVES { 0x00002000 }
515sub PU_CLOAK { 0x00004000 }
516sub PU_KEY { 0x00008000 }
517
518sub PU_MISSILEWEAPON { 0x00010000 }
519sub PU_ALLWEAPON { 0x00020000 }
520sub PU_MAGICAL { 0x00040000 }
521sub PU_POTION { 0x00080000 }
522
523sub PU_SPELLBOOK { 0x00100000 }
524sub PU_SKILLSCROLL { 0x00200000 }
525sub PU_READABLES { 0x00400000 }
526sub PU_MAGIC_DEVICE { 0x00800000 }
527
528sub PU_NOT_CURSED { 0x01000000 }
529
530sub PU_JEWELS { 0x02000000 }
531
532
3221; 5331;
323 534
324=back 535=back
325 536
326=head1 AUTHOR 537=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines