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.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
190 $db->db_put ($key => $data) 202 $db->db_put ($key => $data)
191} 203}
192 204
193package CFClient::Item; 205package CFClient::Item;
194 206
207use strict;
208use Crossfire::Protocol::Constants;
209
195sub desc_string { 210sub desc_string {
196 my ($self) = @_; 211 my ($self) = @_;
197 212
198 my $desc = 213 my $desc =
199 $self->{nrof} < 2 214 $self->{nrof} < 2
200 ? $self->{name} 215 ? $self->{name}
201 : "$self->{nrof} × $self->{name_pl}"; 216 : "$self->{nrof} × $self->{name_pl}";
202 217
203 $self->{flags} & Crossfire::Protocol::F_OPEN 218 $self->{flags} & F_OPEN
204 and $desc .= " (open)"; 219 and $desc .= " (open)";
205 $self->{flags} & Crossfire::Protocol::F_APPLIED 220 $self->{flags} & F_APPLIED
206 and $desc .= " (applied)"; 221 and $desc .= " (applied)";
207 $self->{flags} & Crossfire::Protocol::F_UNPAID 222 $self->{flags} & F_UNPAID
208 and $desc .= " (unpaid)"; 223 and $desc .= " (unpaid)";
209 $self->{flags} & Crossfire::Protocol::F_MAGIC 224 $self->{flags} & F_MAGIC
210 and $desc .= " (magic)"; 225 and $desc .= " (magic)";
211 $self->{flags} & Crossfire::Protocol::F_CURSED 226 $self->{flags} & F_CURSED
212 and $desc .= " (cursed)"; 227 and $desc .= " (cursed)";
213 $self->{flags} & Crossfire::Protocol::F_DAMNED 228 $self->{flags} & F_DAMNED
214 and $desc .= " (damned)"; 229 and $desc .= " (damned)";
215 $self->{flags} & Crossfire::Protocol::F_LOCKED 230 $self->{flags} & F_LOCKED
216 and $desc .= " *"; 231 and $desc .= " *";
217 232
218 $desc 233 $desc
219} 234}
220 235
237 252
238 if ($self->{container} == $::CONN->{player}{tag}) { 253 if ($self->{container} == $::CONN->{player}{tag}) {
239 $targ = $::CONN->{open_container}; 254 $targ = $::CONN->{open_container};
240 } 255 }
241 256
242 $::CONN->send ("move $targ $self->{tag} 0"); 257 $::CONN->send ("move $targ $self->{tag} 0")
258 if $targ || !($self->{flags} & F_LOCKED);
243 } elsif ($ev->{button} == 1) { 259 } elsif ($ev->{button} == 1) {
244 $::CONN->send ("examine $self->{tag}"); 260 $::CONN->send ("examine $self->{tag}");
245 } elsif ($ev->{button} == 2) { 261 } elsif ($ev->{button} == 2) {
246 $::CONN->send ("apply $self->{tag}"); 262 $::CONN->send ("apply $self->{tag}");
247 } elsif ($ev->{button} == 3) { 263 } elsif ($ev->{button} == 3) {
248 my @menu_items = ( 264 my @menu_items = (
249 ["examine", sub { $::CONN->send ("examine $self->{tag}") }], 265 ["examine", sub { $::CONN->send ("examine $self->{tag}") }],
250 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 266 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
251 ["apply", sub { $::CONN->send ("apply $self->{tag}") }], 267 ["apply", sub { $::CONN->send ("apply $self->{tag}") }],
252 ( 268 (
253 $self->{flags} & Crossfire::Protocol::F_LOCKED 269 $self->{flags} & F_LOCKED
254 ? ( 270 ? (
255 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], 271 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }],
256 ) 272 )
257 : ( 273 : (
258 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], 274 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }],
277 $self->{face_widget} ||= new CFClient::UI::Face 293 $self->{face_widget} ||= new CFClient::UI::Face
278 can_events => 1, 294 can_events => 1,
279 can_hover => 1, 295 can_hover => 1,
280 anim => $self->{anim}, 296 anim => $self->{anim},
281 animspeed => $self->{animspeed}, # TODO# must be set at creation time 297 animspeed => $self->{animspeed}, # TODO# must be set at creation time
282 connect_button_down => $button_cb, 298 on_button_down => $button_cb,
283 ; 299 ;
284 $self->{face_widget}{face} = $self->{face}; 300 $self->{face_widget}{face} = $self->{face};
285 $self->{face_widget}{anim} = $self->{anim}; 301 $self->{face_widget}{anim} = $self->{anim};
286 $self->{face_widget}{animspeed} = $self->{animspeed}; 302 $self->{face_widget}{animspeed} = $self->{animspeed};
287 $self->{face_widget}->set_tooltip ( 303 $self->{face_widget}->set_tooltip (
294 $self->{desc_widget} ||= new CFClient::UI::Label 310 $self->{desc_widget} ||= new CFClient::UI::Label
295 can_events => 1, 311 can_events => 1,
296 can_hover => 1, 312 can_hover => 1,
297 ellipsise => 2, 313 ellipsise => 2,
298 align => -1, 314 align => -1,
299 connect_button_down => $button_cb, 315 on_button_down => $button_cb,
300 ; 316 ;
301 my $desc = CFClient::Item::desc_string $self; 317 my $desc = CFClient::Item::desc_string $self;
302 $self->{desc_widget}->set_text ($desc); 318 $self->{desc_widget}->set_text ($desc);
303 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); 319 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std");
304 320
305 $self->{weight_widget} ||= new CFClient::UI::Label 321 $self->{weight_widget} ||= new CFClient::UI::Label
306 can_events => 1, 322 can_events => 1,
307 can_hover => 1, 323 can_hover => 1,
308 ellipsise => 0, 324 ellipsise => 0,
309 align => 0, 325 align => 0,
310 connect_button_down => $button_cb, 326 on_button_down => $button_cb,
311 ; 327 ;
312 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); 328 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self);
313 329
314 $self->{weight_widget}->set_tooltip ( 330 $self->{weight_widget}->set_tooltip (
315 "<b>Weight</b>.\n" 331 "<b>Weight</b>.\n"
317 . ($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. ")
318 . "\n\n$tooltip_std" 334 . "\n\n$tooltip_std"
319 ); 335 );
320} 336}
321 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
3221; 4451;
323 446
324=back 447=back
325 448
326=head1 AUTHOR 449=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines