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.82 by root, Wed May 31 07:13:50 2006 UTC vs.
Revision 1.94 by elmex, Wed Jun 28 09:45:10 2006 UTC

24use utf8; 24use utf8;
25 25
26use Carp (); 26use Carp ();
27use AnyEvent (); 27use AnyEvent ();
28use BerkeleyDB; 28use BerkeleyDB;
29use Pod::POM ();
30use Scalar::Util ();
31use Storable (); # finally
32
33package CFClient::PodToPango;
34
35use base Pod::POM::View::Text;
36
37our $VERSION = 1; # bump if resultant formatting changes
38
39our $indent = 0;
40
41*view_seq_code =
42*view_seq_bold = sub { "<b>$_[1]</b>" };
43*view_seq_italic = sub { "<i>$_[1]</i>" };
44*view_seq_space =
45*view_seq_link =
46*view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) };
47
48sub view_seq_text {
49 my $text = $_[1];
50 $text =~ s/\s+/ /g;
51 CFClient::UI::Label::escape ($text)
52}
53
54sub view_item {
55 ("\t" x ($indent / 4))
56 . $_[1]->title->present ($_[0])
57 . "\n\n"
58 . $_[1]->content->present ($_[0])
59}
60
61sub view_verbatim {
62 (join "",
63 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n",
64 split /\n/, CFClient::UI::Label::escape ($_[1]))
65 . "\n"
66}
67
68sub view_textblock {
69 ("\t" x ($indent / 2)) . "$_[1]\n\n"
70}
71
72sub view_head1 {
73 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
74 . $_[1]->content->present ($_[0])
75};
76
77sub view_head2 {
78 "\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
79 . $_[1]->content->present ($_[0])
80};
81
82sub view_head3 {
83 "\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
84 . $_[1]->content->present ($_[0])
85};
86
87sub view_over {
88 local $indent = $indent + $_[1]->indent;
89 $_[1]->content->present ($_[0])
90}
91
92package CFClient::Database;
93
94our @ISA = BerkeleyDB::Btree::;
95
96sub get($$) {
97 my $data;
98
99 $_[0]->db_get ($_[1], $data) == 0
100 ? $data
101 : ()
102}
103
104my %DB_SYNC;
105
106sub put($$$) {
107 my ($db, $key, $data) = @_;
108
109 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
110
111 $db->db_put ($key => $data)
112}
113
114package CFClient;
29 115
30sub find_rcfile($) { 116sub find_rcfile($) {
31 my $path; 117 my $path;
32 118
33 for (grep !ref, @INC) { 119 for (grep !ref, @INC) {
68 } 154 }
69 155
70 close CFG; 156 close CFG;
71} 157}
72 158
73mkdir "$Crossfire::VARDIR/cfplus", 0777;
74
75our $DB_ENV; 159our $DB_ENV;
76 160
77{ 161{
78 use strict; 162 use strict;
79 163
164 mkdir "$Crossfire::VARDIR/cfplus", 0777;
80 my $recover = $BerkeleyDB::db_version >= 4.4 165 my $recover = $BerkeleyDB::db_version >= 4.4
81 ? eval "DB_REGISTER | DB_RECOVER" 166 ? eval "DB_REGISTER | DB_RECOVER"
82 : 0; 167 : 0;
83 warn $recover;
84 168
85 $DB_ENV = new BerkeleyDB::Env 169 $DB_ENV = new BerkeleyDB::Env
86 -Home => "$Crossfire::VARDIR/cfplus", 170 -Home => "$Crossfire::VARDIR/cfplus",
87 -Cachesize => 1_000_000, 171 -Cachesize => 1_000_000,
88 -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt", 172 -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt",
106 -Property => DB_CHKSUM, 190 -Property => DB_CHKSUM,
107 -Flags => DB_CREATE | DB_UPGRADE, 191 -Flags => DB_CREATE | DB_UPGRADE,
108 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 192 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
109} 193}
110 194
195my $pod_cache = db_table "pod_cache";
196
197sub load_pod($$$$) {
198 my ($path, $filtertype, $filterversion, $filtercb) = @_;
199
200 stat $path
201 or die "$path: $!";
202
203 my $phash = join ",", $filterversion, $CFClient::PodToPango::VERSION, (stat _)[7,9];
204
205 my ($chash, $pom) = eval { @{ Storable::thaw $pod_cache->get ("$path/$filtertype") } };
206
207 return $pom if $chash eq $phash;
208
209 my $pod = do {
210 local $/;
211 open my $pod, "<:utf8", $_[0]
212 or die "$_[0]: $!";
213 <$pod>
214 };
215
216 #utf8::downgrade $pod;
217
218 $pom = $filtercb-> (Pod::POM->new->parse_text ($pod));
219
220 $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]);
221
222 $pom
223}
224
111sub pod_to_pango($) { 225sub pod_to_pango($) {
112 my ($pom) = @_; 226 my ($pom) = @_;
113 227
114 $pom->present ("CFClient::PodToPango") 228 $pom->present ("CFClient::PodToPango")
115} 229}
121 map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "], 235 map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "],
122 split /\n/, $pom->present ("CFClient::PodToPango") 236 split /\n/, $pom->present ("CFClient::PodToPango")
123 ] 237 ]
124} 238}
125 239
126package CFClient::PodToPango;
127
128use base Pod::POM::View::Text;
129
130our $indent = 0;
131
132*view_seq_code =
133*view_seq_bold = sub { "<b>$_[1]</b>" };
134*view_seq_italic = sub { "<i>$_[1]</i>" };
135*view_seq_space =
136*view_seq_link =
137*view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) };
138
139sub view_seq_text {
140 my $text = $_[1];
141 $text =~ s/\s+/ /g;
142 CFClient::UI::Label::escape ($text)
143}
144
145sub view_item {
146 ("\t" x ($indent / 4))
147 . $_[1]->title->present ($_[0])
148 . "\n"
149 . $_[1]->content->present ($_[0])
150}
151
152sub view_verbatim {
153 (join "",
154 map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n",
155 split /\n/, CFClient::UI::Label::escape ($_[1]))
156 . "\n"
157}
158
159sub view_textblock {
160 ("\t" x ($indent / 2)) . "$_[1]\n\n"
161}
162
163sub view_head1 {
164 "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
165 . $_[1]->content->present ($_[0])
166};
167
168sub view_head2 {
169 "\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
170 . $_[1]->content->present ($_[0])
171};
172
173sub view_head3 {
174 "\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n"
175 . $_[1]->content->present ($_[0])
176};
177
178sub view_over {
179 local $indent = $indent + $_[1]->indent;
180 $_[1]->content->present ($_[0])
181}
182
183package CFClient::Database;
184
185our @ISA = BerkeleyDB::Btree::;
186
187sub get($$) {
188 my $data;
189
190 $_[0]->db_get ($_[1], $data) == 0
191 ? $data
192 : ()
193}
194
195my %DB_SYNC;
196
197sub put($$$) {
198 my ($db, $key, $data) = @_;
199
200 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
201
202 $db->db_put ($key => $data)
203}
204
205package CFClient::Item; 240package CFClient::Item;
206 241
207use strict; 242use strict;
208use Crossfire::Protocol::Constants; 243use Crossfire::Protocol::Constants;
244
245my $last_enter_count = 1;
209 246
210sub desc_string { 247sub desc_string {
211 my ($self) = @_; 248 my ($self) = @_;
212 249
213 my $desc = 250 my $desc =
239 my $weight = ($self->{nrof} || 1) * $self->{weight}; 276 my $weight = ($self->{nrof} || 1) * $self->{weight};
240 277
241 $weight < 0 ? "?" : $weight * 0.001 278 $weight < 0 ? "?" : $weight * 0.001
242} 279}
243 280
281sub do_n_dialog {
282 my ($cb) = @_;
283
284 my $w = new CFClient::UI::FancyFrame;
285 $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center");
286 $vb->add (new CFClient::UI::Label text => "Enter item count:");
287 $vb->add (my $entry = new CFClient::UI::Entry
288 text => $last_enter_count,
289 on_activate => sub {
290 my ($entry) = @_;
291 $last_enter_count = $entry->get_text;
292 $cb->($last_enter_count);
293 $w->hide;
294 $w = undef;
295 }
296 );
297 $entry->grab_focus;
298 $w->show;
299
300}
301
244sub update_widgets { 302sub update_widgets {
245 my ($self) = @_; 303 my ($self) = @_;
246 304
305 # necessary to avoid cyclic references
306 Scalar::Util::weaken $self;
307
247 my $button_cb = sub { 308 my $button_cb = sub {
248 my (undef, $ev, $x, $y) = @_; 309 my (undef, $ev, $x, $y) = @_;
249 310
311 my $targ = $::CONN->{player}{tag};
312
313 if ($self->{container} == $::CONN->{player}{tag}) {
314 $targ = $::CONN->{open_container};
315 }
316
250 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { 317 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
251 my $targ = $::CONN->{player}{tag};
252
253 if ($self->{container} == $::CONN->{player}{tag}) {
254 $targ = $::CONN->{open_container};
255 }
256
257 $::CONN->send ("move $targ $self->{tag} 0") 318 $::CONN->send ("move $targ $self->{tag} 0")
258 if $targ || !($self->{flags} & F_LOCKED); 319 if $targ || !($self->{flags} & F_LOCKED);
320 } elsif (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 2) {
321 $self->{flags} & F_LOCKED
322 ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag})
323 : $::CONN->send ("lock " . pack "CN", 1, $self->{tag})
259 } elsif ($ev->{button} == 1) { 324 } elsif ($ev->{button} == 1) {
260 $::CONN->send ("examine $self->{tag}"); 325 $::CONN->send ("examine $self->{tag}");
261 } elsif ($ev->{button} == 2) { 326 } elsif ($ev->{button} == 2) {
262 $::CONN->send ("apply $self->{tag}"); 327 $::CONN->send ("apply $self->{tag}");
263 } elsif ($ev->{button} == 3) { 328 } elsif ($ev->{button} == 3) {
271 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], 336 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }],
272 ) 337 )
273 : ( 338 : (
274 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], 339 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }],
275 ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], 340 ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }],
341 ["move n",
342 sub {
343 do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") })
344 }
345 ]
276 ) 346 )
277 ), 347 ),
278 ); 348 );
279 349
280 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 350 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
285 355
286 my $tooltip_std = "<small>" 356 my $tooltip_std = "<small>"
287 . "Left click - examine item\n" 357 . "Left click - examine item\n"
288 . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" 358 . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n"
289 . "Middle click - apply\n" 359 . "Middle click - apply\n"
360 . "Shift-Middle click - lock/unlock\n"
290 . "Right click - further options" 361 . "Right click - further options"
291 . "</small>\n"; 362 . "</small>\n";
292 363
293 $self->{face_widget} ||= new CFClient::UI::Face 364 $self->{face_widget} ||= new CFClient::UI::Face
294 can_events => 1, 365 can_events => 1,
336} 407}
337 408
338package CFClient::Binder; 409package CFClient::Binder;
339 410
340my @ALLOWED_MODIFIER_KEYS = ( 411my @ALLOWED_MODIFIER_KEYS = (
341 (CFClient::SDLK_LSHIFT), 412 CFClient::SDLK_LSHIFT,
342 (CFClient::SDLK_LCTRL ), 413 CFClient::SDLK_LCTRL ,
343 (CFClient::SDLK_LALT ), 414 CFClient::SDLK_LALT ,
344 (CFClient::SDLK_LMETA ), 415 CFClient::SDLK_LMETA ,
345 416
346 (CFClient::SDLK_RSHIFT), 417 CFClient::SDLK_RSHIFT,
347 (CFClient::SDLK_RCTRL ), 418 CFClient::SDLK_RCTRL ,
348 (CFClient::SDLK_RALT ), 419 CFClient::SDLK_RALT ,
349 (CFClient::SDLK_RMETA ), 420 CFClient::SDLK_RMETA ,
350); 421);
351 422
352my %ALLOWED_MODIFIERS = ( 423my %ALLOWED_MODIFIERS = (
353 (CFClient::KMOD_LSHIFT) => "LSHIFT", 424 CFClient::KMOD_LSHIFT => "LSHIFT",
354 (CFClient::KMOD_LCTRL ) => "LCTRL", 425 CFClient::KMOD_LCTRL => "LCTRL",
355 (CFClient::KMOD_LALT ) => "LALT", 426 CFClient::KMOD_LALT => "LALT",
356 (CFClient::KMOD_LMETA ) => "LMETA", 427 CFClient::KMOD_LMETA => "LMETA",
357 428
358 (CFClient::KMOD_RSHIFT) => "RSHIFT", 429 CFClient::KMOD_RSHIFT => "RSHIFT",
359 (CFClient::KMOD_RCTRL ) => "RCTRL", 430 CFClient::KMOD_RCTRL => "RCTRL",
360 (CFClient::KMOD_RALT ) => "RALT", 431 CFClient::KMOD_RALT => "RALT",
361 (CFClient::KMOD_RMETA ) => "RMETA", 432 CFClient::KMOD_RMETA => "RMETA",
362); 433);
363 434
364my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/; 435my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/;
365my @DIRECT_BIND_KEYS = ( 436my @DIRECT_BIND_KEYS = (
366 CFClient::SDLK_F1, 437 CFClient::SDLK_F1,
386 my ($cb) = @_; 457 my ($cb) = @_;
387 458
388 my $w = new CFClient::UI::FancyFrame 459 my $w = new CFClient::UI::FancyFrame
389 title => "Bind Action", 460 title => "Bind Action",
390 x => "center", 461 x => "center",
391 y => "center"; 462 y => "center",
463 z => 1000;
392 464
393 $w->add (my $vb = new CFClient::UI::VBox); 465 $w->add (my $vb = new CFClient::UI::VBox);
394 $vb->add (new CFClient::UI::Label 466 $vb->add (new CFClient::UI::Label
395 text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key." 467 text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key."
396 ."You can only bind 0-9 and F1-F15 without modifiers." 468 ."You can only bind 0-9 and F1-F15 without modifiers."
417 ." directly without modifier! It would damage the completer handling." 489 ." directly without modifier! It would damage the completer handling."
418 ); 490 );
419 return; 491 return;
420 } 492 }
421 493
422 $entry->focus_out; 494 $entry->grab_focus;
423 495
424 $cb->($mod, $sym); 496 $cb->($mod, $sym);
425 497
426 $w->destroy 498 $w->destroy
427 }); 499 });
428 500
429 $entry->focus_in; 501 $entry->grab_focus;
430 $w->show; 502 $w->show;
431} 503}
432 504
433sub keycombo_to_name { 505sub keycombo_to_name {
434 my ($mod, $sym) = @_; 506 my ($mod, $sym) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines