… | |
… | |
18 | $VERSION = '0.1'; |
18 | $VERSION = '0.1'; |
19 | |
19 | |
20 | use XSLoader; |
20 | use XSLoader; |
21 | XSLoader::load "CFClient", $VERSION; |
21 | XSLoader::load "CFClient", $VERSION; |
22 | } |
22 | } |
|
|
23 | |
|
|
24 | use utf8; |
23 | |
25 | |
24 | use Carp (); |
26 | use Carp (); |
25 | use AnyEvent (); |
27 | use AnyEvent (); |
26 | use BerkeleyDB; |
28 | use BerkeleyDB; |
27 | |
29 | |
… | |
… | |
36 | sub gl_init { |
38 | sub gl_init { |
37 | $GL_VERSION = gl_version * 1; |
39 | $GL_VERSION = gl_version * 1; |
38 | %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; |
40 | %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; |
39 | |
41 | |
40 | $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; |
42 | $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; |
|
|
43 | $GL_NPOT = 0 if gl_vendor =~ /ATI Technologies/; # ATI doesn't get it right... |
41 | |
44 | |
42 | glDisable GL_COLOR_MATERIAL; |
45 | glDisable GL_COLOR_MATERIAL; |
43 | glShadeModel GL_FLAT; |
46 | glShadeModel GL_FLAT; |
44 | glDisable GL_DITHER; |
47 | glDisable GL_DITHER; |
45 | glDisable GL_DEPTH_TEST; |
48 | glDisable GL_DEPTH_TEST; |
… | |
… | |
51 | |
54 | |
52 | sub gl_check { |
55 | sub gl_check { |
53 | return unless $GL_DEBUG; |
56 | return unless $GL_DEBUG; |
54 | |
57 | |
55 | if (my $error = glGetError) { |
58 | if (my $error = glGetError) { |
|
|
59 | my ($format, @args) = @_; |
56 | Carp::cluck sprintf "opengl error %x while %s", $error, &sprintf(@_); |
60 | Carp::cluck sprintf "opengl error %x while $format", $error, @args; |
57 | } |
61 | } |
58 | } |
62 | } |
59 | |
63 | |
60 | sub find_rcfile($) { |
64 | sub find_rcfile($) { |
61 | my $path; |
65 | my $path; |
… | |
… | |
106 | -Home => "$Crossfire::VARDIR/pclient", |
110 | -Home => "$Crossfire::VARDIR/pclient", |
107 | -Cachesize => 1_000_000, |
111 | -Cachesize => 1_000_000, |
108 | -ErrFile => "$Crossfire::VARDIR/pclient/errorlog.txt", |
112 | -ErrFile => "$Crossfire::VARDIR/pclient/errorlog.txt", |
109 | # -ErrPrefix => "DATABASE", |
113 | # -ErrPrefix => "DATABASE", |
110 | -Verbose => 1, |
114 | -Verbose => 1, |
111 | -Flags => DB_CREATE | DB_RECOVER_FATAL | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN, |
115 | -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN, |
112 | or die "unable to create/open database home $Crossfire::VARDIR/pclient: $BerkeleyDB::Error"; |
116 | or die "unable to create/open database home $Crossfire::VARDIR/pclient: $BerkeleyDB::Error"; |
113 | |
117 | |
114 | sub db_table($) { |
118 | sub db_table($) { |
115 | my ($table) = @_; |
119 | my ($table) = @_; |
116 | |
120 | |
… | |
… | |
130 | my ($pom) = @_; |
134 | my ($pom) = @_; |
131 | |
135 | |
132 | $pom->present ("CFClient::PodToPango") |
136 | $pom->present ("CFClient::PodToPango") |
133 | } |
137 | } |
134 | |
138 | |
|
|
139 | sub pod_to_pango_list($) { |
|
|
140 | my ($pom) = @_; |
|
|
141 | |
|
|
142 | [ |
|
|
143 | map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "], |
|
|
144 | split /\n/, $pom->present ("CFClient::PodToPango") |
|
|
145 | ] |
|
|
146 | } |
|
|
147 | |
135 | package CFClient::PodToPango; |
148 | package CFClient::PodToPango; |
136 | |
149 | |
137 | use base Pod::POM::View::Text; |
150 | use base Pod::POM::View::Text; |
138 | |
151 | |
139 | our $indent = 0; |
152 | our $indent = 0; |
… | |
… | |
158 | . $_[1]->content->present ($_[0]) |
171 | . $_[1]->content->present ($_[0]) |
159 | } |
172 | } |
160 | |
173 | |
161 | sub view_verbatim { |
174 | sub view_verbatim { |
162 | (join "", |
175 | (join "", |
163 | map +("\t" x ($indent / 2)) . "$_\n", |
176 | map +("\t" x ($indent / 2)) . "<tt>$_</tt>\n", |
164 | split /\n/, CFClient::UI::Label::escape ($_[1])) |
177 | split /\n/, CFClient::UI::Label::escape ($_[1])) |
165 | . "\n" |
178 | . "\n" |
166 | } |
179 | } |
167 | |
180 | |
168 | sub view_textblock { |
181 | sub view_textblock { |
169 | ("\t" x ($indent / 2)) . "$_[1]\n\n" |
182 | ("\t" x ($indent / 2)) . "$_[1]\n\n" |
170 | } |
183 | } |
171 | |
184 | |
|
|
185 | sub view_head1 { |
|
|
186 | "\n\n<span foreground='#ffff00' size='x-large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" |
|
|
187 | . $_[1]->content->present ($_[0]) |
|
|
188 | }; |
|
|
189 | |
172 | sub view_head2 { |
190 | sub view_head2 { |
|
|
191 | "\n<span foreground='#ccccff' size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" |
|
|
192 | . $_[1]->content->present ($_[0]) |
|
|
193 | }; |
|
|
194 | |
|
|
195 | sub view_head3 { |
173 | "<big>" . $_[1]->title->present ($_[0]) . "</big>\n\n" |
196 | "\n<span size='large'>" . $_[1]->title->present ($_[0]) . "</span>\n\n" |
174 | . $_[1]->content->present ($_[0]) |
197 | . $_[1]->content->present ($_[0]) |
175 | }; |
198 | }; |
176 | |
199 | |
177 | sub view_over { |
200 | sub view_over { |
178 | local $indent = $indent + $_[1]->indent; |
201 | local $indent = $indent + $_[1]->indent; |
… | |
… | |
197 | my ($db, $key, $data) = @_; |
220 | my ($db, $key, $data) = @_; |
198 | |
221 | |
199 | $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync }); |
222 | $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync }); |
200 | |
223 | |
201 | $db->db_put ($key => $data) |
224 | $db->db_put ($key => $data) |
|
|
225 | } |
|
|
226 | |
|
|
227 | package CFClient::Item; |
|
|
228 | |
|
|
229 | sub desc_string { |
|
|
230 | my ($self) = @_; |
|
|
231 | |
|
|
232 | my $desc = |
|
|
233 | $self->{nrof} < 2 |
|
|
234 | ? $self->{name} |
|
|
235 | : "$self->{nrof} × $self->{name_pl}"; |
|
|
236 | |
|
|
237 | $self->{flags} & Crossfire::Protocol::F_OPEN |
|
|
238 | and $desc .= " (open)"; |
|
|
239 | $self->{flags} & Crossfire::Protocol::F_APPLIED |
|
|
240 | and $desc .= " (applied)"; |
|
|
241 | $self->{flags} & Crossfire::Protocol::F_UNPAID |
|
|
242 | and $desc .= " (unpaid)"; |
|
|
243 | $self->{flags} & Crossfire::Protocol::F_MAGIC |
|
|
244 | and $desc .= " (magic)"; |
|
|
245 | $self->{flags} & Crossfire::Protocol::F_CURSED |
|
|
246 | and $desc .= " (cursed)"; |
|
|
247 | $self->{flags} & Crossfire::Protocol::F_DAMNED |
|
|
248 | and $desc .= " (damned)"; |
|
|
249 | $self->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
250 | and $desc .= " *"; |
|
|
251 | |
|
|
252 | $desc |
|
|
253 | } |
|
|
254 | |
|
|
255 | sub weight_string { |
|
|
256 | my ($self) = @_; |
|
|
257 | |
|
|
258 | my $weight = ($self->{nrof} || 1) * $self->{weight}; |
|
|
259 | |
|
|
260 | $weight < 0 ? "?" : $weight * 0.001 |
|
|
261 | } |
|
|
262 | |
|
|
263 | sub update_widgets { |
|
|
264 | my ($self) = @_; |
|
|
265 | |
|
|
266 | my $button_cb = sub { |
|
|
267 | my (undef, $ev, $x, $y) = @_; |
|
|
268 | |
|
|
269 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
|
|
270 | my $targ = $::CONN->{player}{tag}; |
|
|
271 | |
|
|
272 | if ($self->{container} == $::CONN->{player}{tag}) { |
|
|
273 | $targ = $::CONN->{open_container}; |
|
|
274 | } |
|
|
275 | |
|
|
276 | $::CONN->send ("move $targ $self->{tag} 0"); |
|
|
277 | } elsif ($ev->{button} == 1) { |
|
|
278 | $::CONN->send ("examine $self->{tag}"); |
|
|
279 | } elsif ($ev->{button} == 2) { |
|
|
280 | $::CONN->send ("apply $self->{tag}"); |
|
|
281 | } elsif ($ev->{button} == 3) { |
|
|
282 | my @menu_items = ( |
|
|
283 | ["examine", sub { $::CONN->send ("examine $self->{tag}") }], |
|
|
284 | ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], |
|
|
285 | ["apply", sub { $::CONN->send ("apply $self->{tag}") }], |
|
|
286 | ( |
|
|
287 | $self->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
288 | ? ( |
|
|
289 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], |
|
|
290 | ) |
|
|
291 | : ( |
|
|
292 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], |
|
|
293 | ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], |
|
|
294 | ) |
|
|
295 | ), |
|
|
296 | ); |
|
|
297 | |
|
|
298 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
|
|
299 | } |
|
|
300 | |
|
|
301 | 1 |
|
|
302 | }; |
|
|
303 | |
|
|
304 | my $tooltip_std = "<small>" |
|
|
305 | . "Left click - examine item\n" |
|
|
306 | . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" |
|
|
307 | . "Middle click - apply\n" |
|
|
308 | . "Right click - further options" |
|
|
309 | . "</small>\n"; |
|
|
310 | |
|
|
311 | $self->{face_widget} ||= new CFClient::UI::Face |
|
|
312 | can_events => 1, |
|
|
313 | can_hover => 1, |
|
|
314 | anim => $self->{anim}, |
|
|
315 | animspeed => $self->{animspeed}, # TODO# must be set at creation time |
|
|
316 | connect_button_down => $button_cb, |
|
|
317 | ; |
|
|
318 | $self->{face_widget}{face} = $self->{face}; |
|
|
319 | $self->{face_widget}{anim} = $self->{anim}; |
|
|
320 | $self->{face_widget}{animspeed} = $self->{animspeed}; |
|
|
321 | $self->{face_widget}->set_tooltip ( |
|
|
322 | "<b>Face/Animation.</b>\n" |
|
|
323 | . "Item uses face #$self->{face}. " |
|
|
324 | . ($self->{animspeed} ? "Item uses animation #$self->{anim} at " . (1 / $self->{animspeed}) . "fps. " : "Item is not animated. ") |
|
|
325 | . "\n\n$tooltip_std" |
|
|
326 | ); |
|
|
327 | |
|
|
328 | $self->{desc_widget} ||= new CFClient::UI::Label |
|
|
329 | can_events => 1, |
|
|
330 | can_hover => 1, |
|
|
331 | ellipsise => 2, |
|
|
332 | align => -1, |
|
|
333 | connect_button_down => $button_cb, |
|
|
334 | ; |
|
|
335 | my $desc = CFClient::Item::desc_string $self; |
|
|
336 | $self->{desc_widget}->set_text ($desc); |
|
|
337 | $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); |
|
|
338 | |
|
|
339 | $self->{weight_widget} ||= new CFClient::UI::Label |
|
|
340 | can_events => 1, |
|
|
341 | can_hover => 1, |
|
|
342 | ellipsise => 0, |
|
|
343 | align => 0, |
|
|
344 | connect_button_down => $button_cb, |
|
|
345 | ; |
|
|
346 | $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); |
|
|
347 | |
|
|
348 | $self->{weight_widget}->set_tooltip ( |
|
|
349 | "<b>Weight</b>.\n" |
|
|
350 | . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ") |
|
|
351 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
|
|
352 | . "\n\n$tooltip_std" |
|
|
353 | ); |
202 | } |
354 | } |
203 | |
355 | |
204 | package CFClient::Texture; |
356 | package CFClient::Texture; |
205 | |
357 | |
206 | use strict; |
358 | use strict; |