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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines