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.81 by elmex, Tue May 30 14:35:08 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
190 $db->db_put ($key => $data) 201 $db->db_put ($key => $data)
191} 202}
192 203
193package CFClient::Item; 204package CFClient::Item;
194 205
206use strict;
207use Crossfire::Protocol::Constants;
208
195sub desc_string { 209sub desc_string {
196 my ($self) = @_; 210 my ($self) = @_;
197 211
198 my $desc = 212 my $desc =
199 $self->{nrof} < 2 213 $self->{nrof} < 2
200 ? $self->{name} 214 ? $self->{name}
201 : "$self->{nrof} × $self->{name_pl}"; 215 : "$self->{nrof} × $self->{name_pl}";
202 216
203 $self->{flags} & Crossfire::Protocol::F_OPEN 217 $self->{flags} & F_OPEN
204 and $desc .= " (open)"; 218 and $desc .= " (open)";
205 $self->{flags} & Crossfire::Protocol::F_APPLIED 219 $self->{flags} & F_APPLIED
206 and $desc .= " (applied)"; 220 and $desc .= " (applied)";
207 $self->{flags} & Crossfire::Protocol::F_UNPAID 221 $self->{flags} & F_UNPAID
208 and $desc .= " (unpaid)"; 222 and $desc .= " (unpaid)";
209 $self->{flags} & Crossfire::Protocol::F_MAGIC 223 $self->{flags} & F_MAGIC
210 and $desc .= " (magic)"; 224 and $desc .= " (magic)";
211 $self->{flags} & Crossfire::Protocol::F_CURSED 225 $self->{flags} & F_CURSED
212 and $desc .= " (cursed)"; 226 and $desc .= " (cursed)";
213 $self->{flags} & Crossfire::Protocol::F_DAMNED 227 $self->{flags} & F_DAMNED
214 and $desc .= " (damned)"; 228 and $desc .= " (damned)";
215 $self->{flags} & Crossfire::Protocol::F_LOCKED 229 $self->{flags} & F_LOCKED
216 and $desc .= " *"; 230 and $desc .= " *";
217 231
218 $desc 232 $desc
219} 233}
220 234
237 251
238 if ($self->{container} == $::CONN->{player}{tag}) { 252 if ($self->{container} == $::CONN->{player}{tag}) {
239 $targ = $::CONN->{open_container}; 253 $targ = $::CONN->{open_container};
240 } 254 }
241 255
242 $::CONN->send ("move $targ $self->{tag} 0"); 256 $::CONN->send ("move $targ $self->{tag} 0")
257 if $targ || !($self->{flags} & F_LOCKED);
243 } elsif ($ev->{button} == 1) { 258 } elsif ($ev->{button} == 1) {
244 $::CONN->send ("examine $self->{tag}"); 259 $::CONN->send ("examine $self->{tag}");
245 } elsif ($ev->{button} == 2) { 260 } elsif ($ev->{button} == 2) {
246 $::CONN->send ("apply $self->{tag}"); 261 $::CONN->send ("apply $self->{tag}");
247 } elsif ($ev->{button} == 3) { 262 } elsif ($ev->{button} == 3) {
248 my @menu_items = ( 263 my @menu_items = (
249 ["examine", sub { $::CONN->send ("examine $self->{tag}") }], 264 ["examine", sub { $::CONN->send ("examine $self->{tag}") }],
250 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 265 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
251 ["apply", sub { $::CONN->send ("apply $self->{tag}") }], 266 ["apply", sub { $::CONN->send ("apply $self->{tag}") }],
252 ( 267 (
253 $self->{flags} & Crossfire::Protocol::F_LOCKED 268 $self->{flags} & F_LOCKED
254 ? ( 269 ? (
255 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], 270 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }],
256 ) 271 )
257 : ( 272 : (
258 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], 273 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }],
277 $self->{face_widget} ||= new CFClient::UI::Face 292 $self->{face_widget} ||= new CFClient::UI::Face
278 can_events => 1, 293 can_events => 1,
279 can_hover => 1, 294 can_hover => 1,
280 anim => $self->{anim}, 295 anim => $self->{anim},
281 animspeed => $self->{animspeed}, # TODO# must be set at creation time 296 animspeed => $self->{animspeed}, # TODO# must be set at creation time
282 connect_button_down => $button_cb, 297 on_button_down => $button_cb,
283 ; 298 ;
284 $self->{face_widget}{face} = $self->{face}; 299 $self->{face_widget}{face} = $self->{face};
285 $self->{face_widget}{anim} = $self->{anim}; 300 $self->{face_widget}{anim} = $self->{anim};
286 $self->{face_widget}{animspeed} = $self->{animspeed}; 301 $self->{face_widget}{animspeed} = $self->{animspeed};
287 $self->{face_widget}->set_tooltip ( 302 $self->{face_widget}->set_tooltip (
294 $self->{desc_widget} ||= new CFClient::UI::Label 309 $self->{desc_widget} ||= new CFClient::UI::Label
295 can_events => 1, 310 can_events => 1,
296 can_hover => 1, 311 can_hover => 1,
297 ellipsise => 2, 312 ellipsise => 2,
298 align => -1, 313 align => -1,
299 connect_button_down => $button_cb, 314 on_button_down => $button_cb,
300 ; 315 ;
301 my $desc = CFClient::Item::desc_string $self; 316 my $desc = CFClient::Item::desc_string $self;
302 $self->{desc_widget}->set_text ($desc); 317 $self->{desc_widget}->set_text ($desc);
303 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); 318 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std");
304 319
305 $self->{weight_widget} ||= new CFClient::UI::Label 320 $self->{weight_widget} ||= new CFClient::UI::Label
306 can_events => 1, 321 can_events => 1,
307 can_hover => 1, 322 can_hover => 1,
308 ellipsise => 0, 323 ellipsise => 0,
309 align => 0, 324 align => 0,
310 connect_button_down => $button_cb, 325 on_button_down => $button_cb,
311 ; 326 ;
312 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); 327 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self);
313 328
314 $self->{weight_widget}->set_tooltip ( 329 $self->{weight_widget}->set_tooltip (
315 "<b>Weight</b>.\n" 330 "<b>Weight</b>.\n"
317 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") 332 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ")
318 . "\n\n$tooltip_std" 333 . "\n\n$tooltip_std"
319 ); 334 );
320} 335}
321 336
337package CFClient::Binder;
338
339my @ALLOWED_MODIFIER_KEYS = (
340 (CFClient::SDLK_LSHIFT),
341 (CFClient::SDLK_LCTRL ),
342 (CFClient::SDLK_LALT ),
343 (CFClient::SDLK_LMETA ),
344
345 (CFClient::SDLK_RSHIFT),
346 (CFClient::SDLK_RCTRL ),
347 (CFClient::SDLK_RALT ),
348 (CFClient::SDLK_RMETA ),
349);
350
351my %ALLOWED_MODIFIERS = (
352 (CFClient::KMOD_LSHIFT) => "LSHIFT",
353 (CFClient::KMOD_LCTRL ) => "LCTRL",
354 (CFClient::KMOD_LALT ) => "LALT",
355 (CFClient::KMOD_LMETA ) => "LMETA",
356
357 (CFClient::KMOD_RSHIFT) => "RSHIFT",
358 (CFClient::KMOD_RCTRL ) => "RCTRL",
359 (CFClient::KMOD_RALT ) => "RALT",
360 (CFClient::KMOD_RMETA ) => "RMETA",
361);
362
363my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/;
364my @DIRECT_BIND_KEYS = (
365 CFClient::SDLK_F1,
366 CFClient::SDLK_F2,
367 CFClient::SDLK_F3,
368 CFClient::SDLK_F4,
369 CFClient::SDLK_F5,
370 CFClient::SDLK_F6,
371 CFClient::SDLK_F7,
372 CFClient::SDLK_F8,
373 CFClient::SDLK_F9,
374 CFClient::SDLK_F10,
375 CFClient::SDLK_F11,
376 CFClient::SDLK_F12,
377 CFClient::SDLK_F13,
378 CFClient::SDLK_F14,
379 CFClient::SDLK_F15,
380);
381
382# this binding dialog asks for a key-combo to be pressed
383# and if successful it calls the $cb with $mod and $sym as args.
384sub open_binding_dialog {
385 my ($cb) = @_;
386
387 my $w = new CFClient::UI::FancyFrame
388 title => "Bind Action",
389 x => "center",
390 y => "center";
391
392 $w->add (my $vb = new CFClient::UI::VBox);
393 $vb->add (new CFClient::UI::Label
394 text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key."
395 ."You can only bind 0-9 and F1-F15 without modifiers."
396 );
397 $vb->add (my $entry = new CFClient::UI::Entry
398 text => "",
399 on_key_down => sub {
400 my ($entry, $ev) = @_;
401
402 my $mod = $ev->{mod};
403 my $sym = $ev->{sym};
404
405 # XXX: This seems a little bit hackisch to me, but i have to ignore them
406 if (grep { $_ == $sym } @ALLOWED_MODIFIER_KEYS) {
407 return;
408 }
409
410 if ($mod == CFClient::KMOD_NONE
411 and not $DIRECT_BIND_CHARS{chr ($ev->{unicode})}
412 and not grep { $sym == $_ } @DIRECT_BIND_KEYS)
413 {
414 $::STATUSBOX->add (
415 "Can't bind key ".CFClient::SDL_GetKeyName ($sym)
416 ." directly without modifier! It would damage the completer handling."
417 );
418 return;
419 }
420
421 $entry->focus_out;
422
423 $cb->($mod, $sym);
424
425 $w->destroy
426 });
427
428 $entry->focus_in;
429 $w->show;
430}
431
432sub keycombo_to_name {
433 my ($mod, $sym) = @_;
434
435 my $mods = join '+',
436 map { $ALLOWED_MODIFIERS{$_} }
437 grep { ($_ + 0) & ($mod + 0) }
438 keys %ALLOWED_MODIFIERS;
439 $mods .= "+" if $mods ne '';
440
441 return $mods . CFClient::SDL_GetKeyName ($sym);
442}
443
3221; 4441;
323 445
324=back 446=back
325 447
326=head1 AUTHOR 448=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines