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.107 by root, Mon Jul 24 08:23:27 2006 UTC vs.
Revision 1.111 by root, Sun Jul 30 18:23:50 2006 UTC

1=head1 NAME 1=head1 NAME
2 2
3CFClient - undocumented utility garbage for our crossfire client 3CFPlus - undocumented utility garbage for our crossfire client
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use CFClient; 7 use CFPlus;
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11=over 4 11=over 4
12 12
13=cut 13=cut
14 14
15package CFClient; 15package CFPlus;
16 16
17BEGIN { 17BEGIN {
18 $VERSION = '0.1'; 18 $VERSION = '0.2';
19 19
20 use XSLoader; 20 use XSLoader;
21 XSLoader::load "CFClient", $VERSION; 21 XSLoader::load "CFPlus", $VERSION;
22} 22}
23 23
24use utf8; 24use utf8;
25 25
26use Carp (); 26use Carp ();
27use AnyEvent (); 27use AnyEvent ();
28use BerkeleyDB; 28use BerkeleyDB;
29use Pod::POM (); 29use Pod::POM ();
30use Scalar::Util (); 30use Scalar::Util ();
31use YAML ();
32use Storable (); # finally 31use Storable (); # finally
33 32
34our %STAT_TOOLTIP = ( 33our %STAT_TOOLTIP = (
35 Str => "<b>Physical Strength</b>, determines damage dealt with weapons, how much you can carry, and how often you can attack", 34 Str => "<b>Physical Strength</b>, determines damage dealt with weapons, how much you can carry, and how often you can attack",
36 Dex => "<b>Dexterity</b>, your physical agility. Determines chance of being hit and affects armor class and speed", 35 Dex => "<b>Dexterity</b>, your physical agility. Determines chance of being hit and affects armor class and speed",
53Returns an object that executes the given block as soon as it is destroyed. 52Returns an object that executes the given block as soon as it is destroyed.
54 53
55=cut 54=cut
56 55
57sub guard(&) { 56sub guard(&) {
58 bless \(my $cb = $_[0]), "CFClient::Guard" 57 bless \(my $cb = $_[0]), "CFPlus::Guard"
59} 58}
60 59
61sub CFClient::Guard::DESTROY { 60sub CFPlus::Guard::DESTROY {
62 ${$_[0]}->() 61 ${$_[0]}->()
63} 62}
64 63
65sub asxml($) { 64sub asxml($) {
66 local $_ = $_[0]; 65 local $_ = $_[0];
70 s/</&lt;/g; 69 s/</&lt;/g;
71 70
72 $_ 71 $_
73} 72}
74 73
75package CFClient::Database; 74package CFPlus::Database;
76 75
77our @ISA = BerkeleyDB::Btree::; 76our @ISA = BerkeleyDB::Btree::;
78 77
79sub get($$) { 78sub get($$) {
80 my $data; 79 my $data;
92 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync }); 91 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
93 92
94 $db->db_put ($key => $data) 93 $db->db_put ($key => $data)
95} 94}
96 95
97package CFClient; 96package CFPlus;
98 97
99sub find_rcfile($) { 98sub find_rcfile($) {
100 my $path; 99 my $path;
101 100
102 for (grep !ref, @INC) { 101 for (grep !ref, @INC) {
103 $path = "$_/CFClient/resources/$_[0]"; 102 $path = "$_/CFPlus/resources/$_[0]";
104 return $path if -r $path; 103 return $path if -r $path;
105 } 104 }
106 105
107 die "FATAL: can't find required file $_[0]\n"; 106 die "FATAL: can't find required file $_[0]\n";
108} 107}
109 108
110sub parse_yaml { 109BEGIN {
111 my $text = shift; 110 use Crossfire::Protocol::Base ();
112 111 *to_json = \&Crossfire::Protocol::Base::to_json;
113 utf8::decode $text; 112 *from_json = \&Crossfire::Protocol::Base::from_json;
114
115 YAML::Load $text
116} 113}
117 114
118sub read_cfg { 115sub read_cfg {
119 my ($file) = @_; 116 my ($file) = @_;
120 117
122 or return; 119 or return;
123 120
124 local $/; 121 local $/;
125 my $CFG = <$fh>; 122 my $CFG = <$fh>;
126 123
124 if ($CFG =~ /^---/) { ## TODO compatibility cruft, remove
125 require YAML;
126 utf8::decode $CFG;
127 $::CFG = YAML::Load ($CFG);
127 if ($CFG =~ /^---/) { 128 } elsif ($CFG =~ /^\{/) {
128 $::CFG = parse_yaml $CFG; 129 $::CFG = from_json $CFG;
129 } else { 130 } else {
130 $::CFG = eval $CFG; 131 $::CFG = eval $CFG; ## todo comaptibility cruft
131 } 132 }
132} 133}
133 134
134sub write_cfg { 135sub write_cfg {
135 my ($file) = @_; 136 my ($file) = @_;
136 137
137 $::CFG->{VERSION} = $::VERSION; 138 $::CFG->{VERSION} = $::VERSION;
138 139
139 open my $fh, ">:utf8", $file 140 open my $fh, ">:utf8", $file
140 or return; 141 or return;
141 print $fh YAML::Dump $::CFG; 142 print $fh to_json $::CFG;
142} 143}
143 144
144our $DB_ENV; 145our $DB_ENV;
145 146
146{ 147{
165sub db_table($) { 166sub db_table($) {
166 my ($table) = @_; 167 my ($table) = @_;
167 168
168 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 169 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
169 170
170 new CFClient::Database 171 new CFPlus::Database
171 -Env => $DB_ENV, 172 -Env => $DB_ENV,
172 -Filename => $table, 173 -Filename => $table,
173# -Filename => "database", 174# -Filename => "database",
174# -Subname => $table, 175# -Subname => $table,
175 -Property => DB_CHKSUM, 176 -Property => DB_CHKSUM,
176 -Flags => DB_CREATE | DB_UPGRADE, 177 -Flags => DB_CREATE | DB_UPGRADE,
177 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 178 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
178} 179}
179 180
180package CFClient::Layout; 181package CFPlus::Layout;
181 182
182$CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Layout"} = sub { 183$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub {
183 reset_glyph_cache; 184 reset_glyph_cache;
184}; 185};
185 186
186package CFClient::Item; 187package CFPlus::Item;
187 188
188use strict; 189use strict;
189use Crossfire::Protocol::Constants; 190use Crossfire::Protocol::Constants;
190 191
191my $last_enter_count = 1; 192my $last_enter_count = 1;
225} 226}
226 227
227sub do_n_dialog { 228sub do_n_dialog {
228 my ($cb) = @_; 229 my ($cb) = @_;
229 230
230 my $w = new CFClient::UI::FancyFrame 231 my $w = new CFPlus::UI::FancyFrame
231 on_delete => sub { $_[0]->destroy; 1 }, 232 on_delete => sub { $_[0]->destroy; 1 },
232 has_close_button => 1, 233 has_close_button => 1,
233 ; 234 ;
234 235
235 $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center"); 236 $w->add (my $vb = new CFPlus::UI::VBox x => "center", y => "center");
236 $vb->add (new CFClient::UI::Label text => "Enter item count:"); 237 $vb->add (new CFPlus::UI::Label text => "Enter item count:");
237 $vb->add (my $entry = new CFClient::UI::Entry 238 $vb->add (my $entry = new CFPlus::UI::Entry
238 text => $last_enter_count, 239 text => $last_enter_count,
239 on_activate => sub { 240 on_activate => sub {
240 my ($entry) = @_; 241 my ($entry) = @_;
241 $last_enter_count = $entry->get_text; 242 $last_enter_count = $entry->get_text;
242 $cb->($last_enter_count); 243 $cb->($last_enter_count);
264 265
265 if ($self->{container} == $::CONN->{player}{tag}) { 266 if ($self->{container} == $::CONN->{player}{tag}) {
266 $targ = $::CONN->{open_container}; 267 $targ = $::CONN->{open_container};
267 } 268 }
268 269
269 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { 270 if (($ev->{mod} & CFPlus::KMOD_SHIFT) && $ev->{button} == 1) {
270 $::CONN->send ("move $targ $self->{tag} 0") 271 $::CONN->send ("move $targ $self->{tag} 0")
271 if $targ || !($self->{flags} & F_LOCKED); 272 if $targ || !($self->{flags} & F_LOCKED);
272 } elsif (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 2) { 273 } elsif (($ev->{mod} & CFPlus::KMOD_SHIFT) && $ev->{button} == 2) {
273 $self->{flags} & F_LOCKED 274 $self->{flags} & F_LOCKED
274 ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) 275 ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag})
275 : $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) 276 : $::CONN->send ("lock " . pack "CN", 1, $self->{tag})
276 } elsif ($ev->{button} == 1) { 277 } elsif ($ev->{button} == 1) {
277 $::CONN->send ("examine $self->{tag}"); 278 $::CONN->send ("examine $self->{tag}");
288 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 289 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
289 ["ignite/thaw", # first try of an easier use of flint&steel 290 ["ignite/thaw", # first try of an easier use of flint&steel
290 sub { 291 sub {
291 $::CONN->send ("mark ". pack "N", $self->{tag}); 292 $::CONN->send ("mark ". pack "N", $self->{tag});
292 $::CONN->send ("command apply flint and steel"); 293 $::CONN->send ("command apply flint and steel");
294 }
295 ],
296 ["inscribe", # first try of an easier use of flint&steel
297 sub {
298 &::open_string_query ("Text to inscribe", sub {
299 my ($entry, $txt) = @_;
300 $::CONN->send ("mark ". pack "N", $self->{tag});
301 $::CONN->send ("command use_skill inscription $txt");
302 });
293 } 303 }
294 ], 304 ],
295 ["apply", sub { $::CONN->send ("apply $self->{tag}") }], 305 ["apply", sub { $::CONN->send ("apply $self->{tag}") }],
296 ( 306 (
297 $self->{flags} & F_LOCKED 307 $self->{flags} & F_LOCKED
308 ] 318 ]
309 ) 319 )
310 ), 320 ),
311 ); 321 );
312 322
313 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 323 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
314 } 324 }
315 325
316 1 326 1
317 }; 327 };
318 328
326 336
327 my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5] 337 my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5]
328 : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5] 338 : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5]
329 : undef; 339 : undef;
330 340
331 $self->{face_widget} ||= new CFClient::UI::Face 341 $self->{face_widget} ||= new CFPlus::UI::Face
332 can_events => 1, 342 can_events => 1,
333 can_hover => 1, 343 can_hover => 1,
334 anim => $self->{anim}, 344 anim => $self->{anim},
335 animspeed => $self->{animspeed}, # TODO# must be set at creation time 345 animspeed => $self->{animspeed}, # TODO# must be set at creation time
336 on_button_down => $button_cb, 346 on_button_down => $button_cb,
344 . "Item uses face #$self->{face}. " 354 . "Item uses face #$self->{face}. "
345 . ($self->{animspeed} ? "Item uses animation #$self->{anim} at " . (1 / $self->{animspeed}) . "fps. " : "Item is not animated. ") 355 . ($self->{animspeed} ? "Item uses animation #$self->{anim} at " . (1 / $self->{animspeed}) . "fps. " : "Item is not animated. ")
346 . "\n\n$tooltip_std" 356 . "\n\n$tooltip_std"
347 ); 357 );
348 358
349 $self->{desc_widget} ||= new CFClient::UI::Label 359 $self->{desc_widget} ||= new CFPlus::UI::Label
350 can_events => 1, 360 can_events => 1,
351 can_hover => 1, 361 can_hover => 1,
352 ellipsise => 2, 362 ellipsise => 2,
353 align => -1, 363 align => -1,
354 on_button_down => $button_cb, 364 on_button_down => $button_cb,
355 ; 365 ;
356 my $desc = CFClient::Item::desc_string $self; 366 my $desc = CFPlus::Item::desc_string $self;
357 $self->{desc_widget}{bg} = $bg; 367 $self->{desc_widget}{bg} = $bg;
358 $self->{desc_widget}->set_text ($desc); 368 $self->{desc_widget}->set_text ($desc);
359 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); 369 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std");
360 370
361 $self->{weight_widget} ||= new CFClient::UI::Label 371 $self->{weight_widget} ||= new CFPlus::UI::Label
362 can_events => 1, 372 can_events => 1,
363 can_hover => 1, 373 can_hover => 1,
364 ellipsise => 0, 374 ellipsise => 0,
365 align => 0, 375 align => 0,
366 on_button_down => $button_cb, 376 on_button_down => $button_cb,
367 ; 377 ;
368 $self->{weight_widget}{bg} = $bg; 378 $self->{weight_widget}{bg} = $bg;
369 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); 379 $self->{weight_widget}->set_text (CFPlus::Item::weight_string $self);
370 $self->{weight_widget}->set_tooltip ( 380 $self->{weight_widget}->set_tooltip (
371 "<b>Weight</b>.\n" 381 "<b>Weight</b>.\n"
372 . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ") 382 . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ")
373 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") 383 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ")
374 . "\n\n$tooltip_std" 384 . "\n\n$tooltip_std"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines