… | |
… | |
26 | use Carp (); |
26 | use Carp (); |
27 | use AnyEvent (); |
27 | use AnyEvent (); |
28 | use BerkeleyDB; |
28 | use BerkeleyDB; |
29 | use Pod::POM (); |
29 | use Pod::POM (); |
30 | use Scalar::Util (); |
30 | use Scalar::Util (); |
|
|
31 | use YAML (); |
31 | use Storable (); # finally |
32 | use Storable (); # finally |
32 | |
33 | |
33 | our %STAT_TOOLTIP = ( |
34 | our %STAT_TOOLTIP = ( |
34 | Str => "<b>Physical Strength</b>, determines damage dealt with weapons, how much you can carry, and how often you can attack", |
35 | Str => "<b>Physical Strength</b>, determines damage dealt with weapons, how much you can carry, and how often you can attack", |
35 | Dex => "<b>Dexterity</b>, your physical agility. Determines chance of being hit and affects armor class and speed", |
36 | Dex => "<b>Dexterity</b>, your physical agility. Determines chance of being hit and affects armor class and speed", |
… | |
… | |
104 | } |
105 | } |
105 | |
106 | |
106 | die "FATAL: can't find required file $_[0]\n"; |
107 | die "FATAL: can't find required file $_[0]\n"; |
107 | } |
108 | } |
108 | |
109 | |
|
|
110 | sub parse_yaml { |
|
|
111 | my $text = shift; |
|
|
112 | |
|
|
113 | utf8::decode $text; |
|
|
114 | |
|
|
115 | YAML::Load $text |
|
|
116 | } |
|
|
117 | |
109 | sub read_cfg { |
118 | sub read_cfg { |
110 | my ($file) = @_; |
119 | my ($file) = @_; |
111 | |
120 | |
112 | open CFG, $file |
121 | open my $fh, $file |
113 | or return; |
122 | or return; |
114 | |
123 | |
115 | my $CFG; |
|
|
116 | |
|
|
117 | local $/; |
124 | local $/; |
118 | $CFG = eval <CFG>; |
125 | my $CFG = <$fh>; |
119 | |
126 | |
|
|
127 | if ($CFG =~ /^---/) { |
|
|
128 | $::CFG = parse_yaml $CFG; |
|
|
129 | } else { |
120 | $::CFG = $CFG; |
130 | $::CFG = eval $CFG; |
121 | |
131 | } |
122 | close CFG; |
|
|
123 | } |
132 | } |
124 | |
133 | |
125 | sub write_cfg { |
134 | sub write_cfg { |
126 | my ($file) = @_; |
135 | my ($file) = @_; |
127 | |
136 | |
128 | open CFG, ">$file" |
137 | $::CFG->{VERSION} = $::VERSION; |
|
|
138 | |
|
|
139 | open my $fh, ">:utf8", $file |
129 | or return; |
140 | or return; |
130 | |
141 | print $fh YAML::Dump $::CFG; |
131 | { |
|
|
132 | require Data::Dumper; |
|
|
133 | local $Data::Dumper::Purity = 1; |
|
|
134 | $::CFG->{VERSION} = $::VERSION; |
|
|
135 | print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]); |
|
|
136 | } |
|
|
137 | |
|
|
138 | close CFG; |
|
|
139 | } |
142 | } |
140 | |
143 | |
141 | our $DB_ENV; |
144 | our $DB_ENV; |
142 | |
145 | |
143 | { |
146 | { |
… | |
… | |
319 | . "Middle click - apply\n" |
322 | . "Middle click - apply\n" |
320 | . "Shift-Middle click - lock/unlock\n" |
323 | . "Shift-Middle click - lock/unlock\n" |
321 | . "Right click - further options" |
324 | . "Right click - further options" |
322 | . "</small>\n"; |
325 | . "</small>\n"; |
323 | |
326 | |
|
|
327 | my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5] |
|
|
328 | : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5] |
|
|
329 | : undef; |
|
|
330 | |
324 | $self->{face_widget} ||= new CFClient::UI::Face |
331 | $self->{face_widget} ||= new CFClient::UI::Face |
325 | can_events => 1, |
332 | can_events => 1, |
326 | can_hover => 1, |
333 | can_hover => 1, |
327 | anim => $self->{anim}, |
334 | anim => $self->{anim}, |
328 | animspeed => $self->{animspeed}, # TODO# must be set at creation time |
335 | animspeed => $self->{animspeed}, # TODO# must be set at creation time |
329 | on_button_down => $button_cb, |
336 | on_button_down => $button_cb, |
330 | ; |
337 | ; |
|
|
338 | $self->{face_widget}{bg} = $bg; |
331 | $self->{face_widget}{face} = $self->{face}; |
339 | $self->{face_widget}{face} = $self->{face}; |
332 | $self->{face_widget}{anim} = $self->{anim}; |
340 | $self->{face_widget}{anim} = $self->{anim}; |
333 | $self->{face_widget}{animspeed} = $self->{animspeed}; |
341 | $self->{face_widget}{animspeed} = $self->{animspeed}; |
334 | $self->{face_widget}->set_tooltip ( |
342 | $self->{face_widget}->set_tooltip ( |
335 | "<b>Face/Animation.</b>\n" |
343 | "<b>Face/Animation.</b>\n" |
… | |
… | |
344 | ellipsise => 2, |
352 | ellipsise => 2, |
345 | align => -1, |
353 | align => -1, |
346 | on_button_down => $button_cb, |
354 | on_button_down => $button_cb, |
347 | ; |
355 | ; |
348 | my $desc = CFClient::Item::desc_string $self; |
356 | my $desc = CFClient::Item::desc_string $self; |
|
|
357 | $self->{desc_widget}{bg} = $bg; |
349 | $self->{desc_widget}->set_text ($desc); |
358 | $self->{desc_widget}->set_text ($desc); |
350 | $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); |
359 | $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); |
351 | |
360 | |
352 | $self->{weight_widget} ||= new CFClient::UI::Label |
361 | $self->{weight_widget} ||= new CFClient::UI::Label |
353 | can_events => 1, |
362 | can_events => 1, |
354 | can_hover => 1, |
363 | can_hover => 1, |
355 | ellipsise => 0, |
364 | ellipsise => 0, |
356 | align => 0, |
365 | align => 0, |
357 | on_button_down => $button_cb, |
366 | on_button_down => $button_cb, |
358 | ; |
367 | ; |
|
|
368 | $self->{weight_widget}{bg} = $bg; |
359 | $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); |
369 | $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); |
360 | |
|
|
361 | $self->{weight_widget}->set_tooltip ( |
370 | $self->{weight_widget}->set_tooltip ( |
362 | "<b>Weight</b>.\n" |
371 | "<b>Weight</b>.\n" |
363 | . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ") |
372 | . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ") |
364 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
373 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
365 | . "\n\n$tooltip_std" |
374 | . "\n\n$tooltip_std" |