1 | package CFPlus::MapWidget; |
1 | package DC::MapWidget; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use List::Util qw(min max); |
6 | use List::Util qw(min max); |
7 | |
7 | |
8 | use CFPlus; |
8 | use DC; |
9 | use CFPlus::OpenGL; |
9 | use DC::OpenGL; |
10 | use CFPlus::UI; |
10 | use DC::UI; |
11 | use CFPlus::Macro; |
11 | use DC::Macro; |
12 | |
12 | |
13 | our @ISA = CFPlus::UI::Base::; |
13 | our @ISA = DC::UI::Base::; |
14 | |
14 | |
15 | my $magicmap_tex = |
15 | my $magicmap_tex = |
16 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
16 | new_from_file DC::Texture DC::find_rcfile "magicmap.png", |
17 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
17 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
18 | |
18 | |
19 | sub new { |
19 | sub new { |
20 | my $class = shift; |
20 | my $class = shift; |
21 | |
21 | |
… | |
… | |
27 | ); |
27 | ); |
28 | |
28 | |
29 | $self |
29 | $self |
30 | } |
30 | } |
31 | |
31 | |
32 | sub set_tilesize { |
|
|
33 | my ($self, $tilesize) = @_; |
|
|
34 | |
|
|
35 | $self->{tilesize} = $tilesize; |
|
|
36 | } |
|
|
37 | |
|
|
38 | sub add_command { |
32 | sub add_command { |
39 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
33 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
40 | |
34 | |
41 | (my $data = $command) =~ s/\\//g; |
35 | (my $data = $command) =~ s/\\//g; |
42 | |
36 | |
… | |
… | |
66 | |
60 | |
67 | sub editor_invoke { |
61 | sub editor_invoke { |
68 | my $editsup = $::CONN && $::CONN->{editor_support} |
62 | my $editsup = $::CONN && $::CONN->{editor_support} |
69 | or return; |
63 | or return; |
70 | |
64 | |
71 | CFPlus::background { |
65 | DC::background { |
72 | print "preparing editor startup...\n"; |
66 | print "preparing editor startup...\n"; |
73 | |
67 | |
74 | my $server = $editsup->{gameserver} || "default"; |
68 | my $server = $editsup->{gameserver} || "default"; |
75 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
69 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
76 | |
70 | |
77 | local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir; |
71 | local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Deliantra::VARDIR/map.$server"; mkdir $mapdir; |
78 | local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir; |
72 | local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Deliantra::VARDIR/lib.$server"; mkdir $libdir; |
79 | |
73 | |
80 | print "map directory is $mapdir\n"; |
74 | print "map directory is $mapdir\n"; |
81 | print "lib directory is $libdir\n"; |
75 | print "lib directory is $libdir\n"; |
82 | |
76 | |
83 | my $ua = CFPlus::lwp_useragent; |
77 | my $ua = DC::lwp_useragent; |
84 | |
78 | |
85 | for my $file (qw(archetypes crossfire.0)) { |
79 | for my $file (qw(archetypes crossfire.0)) { |
86 | my $url = "$editsup->{lib_root}$file"; |
80 | my $url = "$editsup->{lib_root}$file"; |
87 | print "mirroring $url...\n"; |
81 | print "mirroring $url...\n"; |
88 | CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file"); |
82 | DC::lwp_check $ua->mirror ($url, "$libdir/$file"); |
89 | printf "%s size %d octets\n", $file, -s "$libdir/$file"; |
83 | printf "%s size %d octets\n", $file, -s "$libdir/$file"; |
90 | } |
84 | } |
91 | |
85 | |
92 | if (1) { # upload a map |
86 | if (1) { # upload a map |
93 | my $mapname = $::CONN->{map_info}[0]; |
87 | my $mapname = $::CONN->{map_info}[0]; |
… | |
… | |
98 | |
92 | |
99 | print "getting map revision for $mapname...\n"; |
93 | print "getting map revision for $mapname...\n"; |
100 | |
94 | |
101 | # try to get the most recent head revision, what a hack, |
95 | # try to get the most recent head revision, what a hack, |
102 | # this should have been returned while downloading *sigh* |
96 | # this should have been returned while downloading *sigh* |
103 | my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; |
97 | my $log = (DC::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; |
104 | |
98 | |
105 | if ($log =~ /\?rev=(\d+\.\d+)"/) { |
99 | if ($log =~ /\?rev=(\d+\.\d+)"/) { |
106 | my $rev = $1; |
100 | my $rev = $1; |
107 | |
101 | |
108 | print "downloading revision $rev...\n"; |
102 | print "downloading revision $rev...\n"; |
109 | |
103 | |
110 | my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; |
104 | my $map = (DC::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; |
111 | |
105 | |
112 | my $meta = { |
106 | my $meta = { |
113 | %$editsup, |
107 | %$editsup, |
114 | path => $mapname, |
108 | path => $mapname, |
115 | revision => $rev, |
109 | revision => $rev, |
… | |
… | |
120 | require File::Path; |
114 | require File::Path; |
121 | |
115 | |
122 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
116 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
123 | open my $fh, ">:raw:perlio", "$mappath.meta" |
117 | open my $fh, ">:raw:perlio", "$mappath.meta" |
124 | or die "$mappath.meta: $!\n"; |
118 | or die "$mappath.meta: $!\n"; |
125 | print $fh CFPlus::to_json $meta; |
119 | print $fh DC::encode_json $meta; |
126 | close $fh; |
120 | close $fh; |
127 | open my $fh, ">:raw:perlio:utf8", $mappath |
121 | open my $fh, ">:raw:perlio:utf8", $mappath |
128 | or die "$mappath: $!\n"; |
122 | or die "$mappath: $!\n"; |
129 | print $fh $map; |
123 | print $fh $map; |
130 | close $fh; |
124 | close $fh; |
… | |
… | |
171 | |
165 | |
172 | if ($ev->{button} == 1) { |
166 | if ($ev->{button} == 1) { |
173 | $self->grab_focus; |
167 | $self->grab_focus; |
174 | return unless $::CONN; |
168 | return unless $::CONN; |
175 | |
169 | |
176 | my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
170 | my $x = $self->{dx} + DC::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
177 | my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
171 | my $y = $self->{dy} + DC::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
178 | |
172 | |
179 | $x -= CFPlus::floor $::MAP->w * 0.5; |
173 | $x -= DC::floor $::MAP->w * 0.5; |
180 | $y -= CFPlus::floor $::MAP->h * 0.5; |
174 | $y -= DC::floor $::MAP->h * 0.5; |
181 | |
175 | |
182 | if ($::CONN) { |
176 | if ($::CONN) { |
183 | $::CONN->lookat ($x, $y) |
177 | $::CONN->lookat ($x, $y) |
184 | } |
178 | } |
185 | |
179 | |
… | |
… | |
206 | ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], |
200 | ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], |
207 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
201 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
208 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
202 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
209 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
203 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
210 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
204 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
211 | ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
205 | # ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
212 | [ |
206 | [ |
213 | $::PICKUP_ENABLE->{state} |
207 | $::PICKUP_ENABLE->{state} |
214 | ? "Disable automatic pickup" |
208 | ? "Disable automatic pickup" |
215 | : "Enable automatic pickup", |
209 | : "Enable automatic pickup", |
216 | sub { $::PICKUP_ENABLE->toggle } |
210 | sub { $::PICKUP_ENABLE->toggle } |
217 | ], |
211 | ], |
218 | ); |
212 | ); |
219 | |
213 | |
220 | if ($::CONN && $::CONN->{editor_support}) { |
214 | if ($::CONN && $::CONN->{editor_support}) { |
221 | push @items, [ |
215 | # push @items, [ |
222 | "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", |
216 | # "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", |
223 | \&editor_invoke, |
217 | # \&editor_invoke, |
224 | ]; |
218 | # ]; |
225 | |
219 | |
226 | for my $type (qw(test name)) { |
220 | for my $type (qw(test name)) { |
227 | $::CONN->{editor_support}{type} ne $type |
221 | $::CONN->{editor_support}{type} ne $type |
228 | or next; |
222 | or next; |
229 | my $server = $::CONN->{editor_support}{"${type}server"} |
223 | my $server = $::CONN->{editor_support}{"${type}server"} |
230 | or next; |
224 | or next; |
231 | |
225 | |
232 | push @items, [ |
226 | push @items, [ |
233 | "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>", |
227 | "Login on $type server <span size='xx-small'>(" . (DC::asxml $server) . ")</span>", |
234 | sub { server_login $server }, |
228 | sub { server_login $server }, |
235 | ]; |
229 | ]; |
236 | } |
230 | } |
237 | } |
231 | } |
238 | |
232 | |
… | |
… | |
246 | } |
240 | } |
247 | } |
241 | } |
248 | ], |
242 | ], |
249 | ; |
243 | ; |
250 | |
244 | |
251 | (new CFPlus::UI::Menu |
245 | (new DC::UI::Menu |
252 | items => \@items, |
246 | items => \@items, |
253 | )->popup ($ev); |
247 | )->popup ($ev); |
254 | } |
248 | } |
255 | |
249 | |
256 | 1 |
250 | 1 |
… | |
… | |
278 | |
272 | |
279 | sub size_request { |
273 | sub size_request { |
280 | my ($self) = @_; |
274 | my ($self) = @_; |
281 | |
275 | |
282 | ( |
276 | ( |
283 | $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize}, |
277 | $self->{tilesize} * DC::ceil $::WIDTH / $self->{tilesize}, |
284 | $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize}, |
278 | $self->{tilesize} * DC::ceil $::HEIGHT / $self->{tilesize}, |
285 | ) |
279 | ) |
286 | } |
280 | } |
287 | |
281 | |
288 | sub update { |
282 | sub update { |
289 | my ($self) = @_; |
283 | my ($self) = @_; |
… | |
… | |
291 | $self->{need_update} = 1; |
285 | $self->{need_update} = 1; |
292 | $self->SUPER::update; |
286 | $self->SUPER::update; |
293 | } |
287 | } |
294 | |
288 | |
295 | my %DIR = ( |
289 | my %DIR = ( |
296 | ( "," . CFPlus::SDLK_KP5 ), [0, "stay fire"], |
290 | ( "," . DC::SDLK_KP5 ), [0, "stay fire"], |
297 | ( "," . CFPlus::SDLK_KP8 ), [1, "north"], |
291 | ( "," . DC::SDLK_KP8 ), [1, "north"], |
298 | ( "," . CFPlus::SDLK_KP9 ), [2, "northeast"], |
292 | ( "," . DC::SDLK_KP9 ), [2, "northeast"], |
299 | ( "," . CFPlus::SDLK_KP6 ), [3, "east"], |
293 | ( "," . DC::SDLK_KP6 ), [3, "east"], |
300 | ( "," . CFPlus::SDLK_KP3 ), [4, "southeast"], |
294 | ( "," . DC::SDLK_KP3 ), [4, "southeast"], |
301 | ( "," . CFPlus::SDLK_KP2 ), [5, "south"], |
295 | ( "," . DC::SDLK_KP2 ), [5, "south"], |
302 | ( "," . CFPlus::SDLK_KP1 ), [6, "southwest"], |
296 | ( "," . DC::SDLK_KP1 ), [6, "southwest"], |
303 | ( "," . CFPlus::SDLK_KP4 ), [7, "west"], |
297 | ( "," . DC::SDLK_KP4 ), [7, "west"], |
304 | ( "," . CFPlus::SDLK_KP7 ), [8, "northwest"], |
298 | ( "," . DC::SDLK_KP7 ), [8, "northwest"], |
305 | |
299 | |
306 | ( "," . CFPlus::SDLK_UP ), [1, "north"], |
300 | ( "," . DC::SDLK_UP ), [1, "north"], |
307 | ("1," . CFPlus::SDLK_UP ), [2, "northeast"], |
301 | ("1," . DC::SDLK_UP ), [2, "northeast"], |
308 | ( "," . CFPlus::SDLK_RIGHT), [3, "east"], |
302 | ( "," . DC::SDLK_RIGHT), [3, "east"], |
309 | ("1," . CFPlus::SDLK_RIGHT), [4, "southeast"], |
303 | ("1," . DC::SDLK_RIGHT), [4, "southeast"], |
310 | ( "," . CFPlus::SDLK_DOWN ), [5, "south"], |
304 | ( "," . DC::SDLK_DOWN ), [5, "south"], |
311 | ("1," . CFPlus::SDLK_DOWN ), [6, "southwest"], |
305 | ("1," . DC::SDLK_DOWN ), [6, "southwest"], |
312 | ( "," . CFPlus::SDLK_LEFT ), [7, "west"], |
306 | ( "," . DC::SDLK_LEFT ), [7, "west"], |
313 | ("1," . CFPlus::SDLK_LEFT ), [8, "northwest"], |
307 | ("1," . DC::SDLK_LEFT ), [8, "northwest"], |
314 | ); |
308 | ); |
315 | |
309 | |
316 | sub invoke_key_down { |
310 | sub invoke_key_down { |
317 | my ($self, $ev) = @_; |
311 | my ($self, $ev) = @_; |
318 | |
312 | |
319 | my $mod = $ev->{mod}; |
313 | my $mod = $ev->{mod}; |
320 | my $sym = $ev->{sym}; |
314 | my $sym = $ev->{sym}; |
321 | my $uni = $ev->{unicode}; |
315 | my $uni = $ev->{unicode}; |
322 | |
316 | |
323 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
317 | $mod &= DC::KMOD_CTRL | DC::KMOD_ALT | DC::KMOD_SHIFT; |
324 | |
318 | |
|
|
319 | # ignore repeated keypresses |
|
|
320 | return if $self->{last_mod} == $mod && $self->{last_sym} == $sym; |
|
|
321 | $self->{last_mod} = $mod; |
|
|
322 | $self->{last_sym} = $sym; |
|
|
323 | |
325 | if ($::CONN && (my $dir = $DIR{(!!($mod & CFPlus::KMOD_ALT)) . ",$sym"})) { |
324 | if ($::CONN && (my $dir = $DIR{(!!($mod & DC::KMOD_ALT)) . ",$sym"})) { |
326 | if ($mod & CFPlus::KMOD_SHIFT) { |
325 | if ($mod & DC::KMOD_SHIFT) { |
327 | $self->{shft}++; |
326 | $self->{shft}++; |
328 | if ($dir->[0] != $self->{fire_dir}) { |
327 | if ($dir->[0] != $self->{fire_dir}) { |
329 | $::CONN->user_send ("fire $dir->[0]"); |
328 | $::CONN->user_send ("fire $dir->[0]"); |
330 | } |
329 | } |
331 | $self->{fire_dir} = $DIR{$sym}[0]; |
330 | $self->{fire_dir} = $dir->[0]; |
332 | } elsif ($mod & CFPlus::KMOD_CTRL) { |
331 | } elsif ($mod & DC::KMOD_CTRL) { |
333 | $self->{ctrl}++; |
332 | $self->{ctrl}++; |
334 | $::CONN->user_send ("run $dir->[0]"); |
333 | $::CONN->user_send ("run $dir->[0]"); |
335 | } else { |
334 | } else { |
336 | $::CONN->user_send ("$dir->[1]"); |
335 | $::CONN->user_send ("$dir->[1]"); |
337 | } |
336 | } |
… | |
… | |
347 | |
346 | |
348 | my $res = 0; |
347 | my $res = 0; |
349 | my $mod = $ev->{mod}; |
348 | my $mod = $ev->{mod}; |
350 | my $sym = $ev->{sym}; |
349 | my $sym = $ev->{sym}; |
351 | |
350 | |
|
|
351 | delete $self->{last_mod}; |
|
|
352 | delete $self->{last_sym}; |
|
|
353 | |
352 | if ($::CFG->{shift_fire_stop}) { |
354 | if ($::CFG->{shift_fire_stop}) { |
353 | if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) { |
355 | if (!($mod & DC::KMOD_SHIFT) && delete $self->{shft}) { |
354 | $::CONN->user_send ("fire_stop"); |
356 | $::CONN->user_send ("fire_stop"); |
355 | delete $self->{fire_dir}; |
357 | delete $self->{fire_dir}; |
356 | $res = 1; |
358 | $res = 1; |
357 | } |
359 | } |
358 | } else { |
360 | } else { |
359 | if (exists $DIR{$sym} && delete $self->{shft}) { |
361 | if (exists $DIR{(!!($mod & DC::KMOD_ALT)) . ",$sym"} && delete $self->{shft}) { |
360 | $::CONN->user_send ("fire_stop"); |
362 | $::CONN->user_send ("fire_stop"); |
361 | delete $self->{fire_dir}; |
363 | delete $self->{fire_dir}; |
362 | $res = 1; |
364 | $res = 1; |
363 | } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? |
365 | } elsif (($sym == DC::SDLK_LSHIFT || $sym == DC::SDLK_RSHIFT) |
|
|
366 | && delete $self->{shft}) { # XXX: is RSHIFT ok? |
364 | $::CONN->user_send ("fire_stop"); |
367 | $::CONN->user_send ("fire_stop"); |
365 | delete $self->{fire_dir}; |
368 | delete $self->{fire_dir}; |
366 | $res = 1; |
369 | $res = 1; |
367 | } |
370 | } |
368 | } |
371 | } |
369 | |
372 | |
370 | if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) { |
373 | if (!($mod & DC::KMOD_CTRL ) && delete $self->{ctrl}) { |
371 | $::CONN->user_send ("run_stop"); |
374 | $::CONN->user_send ("run_stop"); |
372 | $res = 1; |
375 | $res = 1; |
373 | } |
376 | } |
374 | |
377 | |
375 | $res |
378 | $res |
… | |
… | |
381 | $self->refresh_hook; |
384 | $self->refresh_hook; |
382 | |
385 | |
383 | 0 |
386 | 0 |
384 | } |
387 | } |
385 | |
388 | |
|
|
389 | sub set_tilesize { |
|
|
390 | my ($self, $tilesize) = @_; |
|
|
391 | |
|
|
392 | $self->{tilesize} = $tilesize; |
|
|
393 | } |
|
|
394 | |
|
|
395 | sub scroll { |
|
|
396 | my ($self, $dx, $dy) = @_; |
|
|
397 | |
|
|
398 | $::MAP->scroll ($dx, $dy); |
|
|
399 | |
|
|
400 | $self->movement_update; |
|
|
401 | |
|
|
402 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
|
|
403 | $self->{sdy} += $dy * $self->{tilesize}; |
|
|
404 | } |
|
|
405 | |
386 | sub set_magicmap { |
406 | sub set_magicmap { |
387 | my ($self, $w, $h, $x, $y, $data) = @_; |
407 | my ($self, $w, $h, $x, $y, $data) = @_; |
388 | |
408 | |
389 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
409 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
390 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
410 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
… | |
… | |
392 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
412 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
393 | |
413 | |
394 | $self->update; |
414 | $self->update; |
395 | } |
415 | } |
396 | |
416 | |
|
|
417 | sub movement_update { |
|
|
418 | my ($self) = @_; |
|
|
419 | |
|
|
420 | if ($::CFG->{smooth_movement}) { |
|
|
421 | if ($self->{sdx} || $self->{sdy}) { |
|
|
422 | my $diff = EV::time - ($self->{last_update} || $::LAST_REFRESH); |
|
|
423 | my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; |
|
|
424 | |
|
|
425 | # the minimum time for a single tile movement |
|
|
426 | my $mintime = DC::Protocol::TICK * DC::ceil 1 / ($spd * DC::Protocol::TICK); |
|
|
427 | |
|
|
428 | # jump if "impossibly high" speed |
|
|
429 | if ( |
|
|
430 | (max abs $self->{sdx}, abs $self->{sdy}) |
|
|
431 | > $spd * $self->{tilesize} * $mintime * 1.1 |
|
|
432 | ) { |
|
|
433 | #warn "jump ", (max abs $self->{sdx}, abs $self->{sdy}), " ", $spd * $mintime * 1.0;#d# |
|
|
434 | $self->{sdx} = $self->{sdy} = 0; |
|
|
435 | } else { |
|
|
436 | my $upd = 0; |
|
|
437 | |
|
|
438 | $spd *= $self->{tilesize} * $diff * 1.0001; |
|
|
439 | |
|
|
440 | my $dx = $self->{sdx} < 0 ? -$spd : $spd; |
|
|
441 | my $dy = $self->{sdy} < 0 ? -$spd : $spd; |
|
|
442 | |
|
|
443 | if ($self->{sdx} * ($self->{sdx} - $dx) <= 0) { $self->{sdx} = 0 } else { $self->{sdx} -= $dx; $upd = 1 } |
|
|
444 | if ($self->{sdy} * ($self->{sdy} - $dy) <= 0) { $self->{sdy} = 0 } else { $self->{sdy} -= $dy; $upd = 1 } |
|
|
445 | |
|
|
446 | $self->update if $upd; |
|
|
447 | } |
|
|
448 | } |
|
|
449 | } else { |
|
|
450 | $self->{sdx} = $self->{sdy} = 0; |
|
|
451 | } |
|
|
452 | |
|
|
453 | $self->{last_update} = EV::time; |
|
|
454 | } |
|
|
455 | |
397 | sub refresh_hook { |
456 | sub refresh_hook { |
398 | my ($self) = @_; |
457 | my ($self) = @_; |
399 | |
458 | |
400 | if ($::MAP && $::CONN) { |
459 | if ($::MAP && $::CONN) { |
401 | if (delete $self->{need_update}) { |
460 | if (delete $self->{need_update}) { |
|
|
461 | $self->movement_update; |
|
|
462 | |
402 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
463 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
403 | |
464 | |
|
|
465 | # width/height of map, in tiles |
404 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
466 | my $sw = $self->{sw} = 1 + DC::ceil $self->{w} / $tilesize; |
405 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
467 | my $sh = $self->{sh} = 1 + DC::ceil $self->{h} / $tilesize; |
406 | |
468 | |
407 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
469 | # the map displacement, in tiles |
408 | my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
470 | my $sx = DC::ceil $::CFG->{map_shift_x} / $tilesize + $self->{sdx} / $self->{tilesize}; |
|
|
471 | my $sy = DC::ceil $::CFG->{map_shift_y} / $tilesize + $self->{sdy} / $self->{tilesize}; |
409 | |
472 | |
|
|
473 | # the upper left "visible" corner, in pixels |
410 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
474 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
411 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
475 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
412 | |
476 | |
413 | my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
477 | my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
414 | my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
478 | my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
415 | |
479 | |
416 | if ($::CFG->{fow_enable}) { |
480 | if ($::CFG->{fow_enable}) { |
417 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
481 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
418 | |
482 | |
419 | $self->{fow_texture} = new CFPlus::Texture |
483 | $self->{fow_texture} = new DC::Texture |
420 | w => $w, |
484 | w => $w, |
421 | h => $h, |
485 | h => $h, |
422 | data => $data, |
486 | data => $data, |
423 | internalformat => GL_ALPHA, |
487 | internalformat => GL_ALPHA, |
424 | format => GL_ALPHA; |
488 | format => GL_ALPHA; |
… | |
… | |
427 | } |
491 | } |
428 | |
492 | |
429 | glNewList ($self->{list} ||= glGenList); |
493 | glNewList ($self->{list} ||= glGenList); |
430 | |
494 | |
431 | glPushMatrix; |
495 | glPushMatrix; |
432 | glTranslate $sx0, $sy0; |
496 | glTranslate $sx0 + $self->{sdx}, $sy0 + $self->{sdy}; |
433 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
497 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
434 | |
498 | |
435 | $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize}); |
499 | $::MAP->draw ($dx, $dy, $sw, $sh, |
|
|
500 | $self->{tilesize}, |
|
|
501 | $::CONN->{player}{tag}, |
|
|
502 | -$self->{sdx}, -$self->{sdy}); |
436 | |
503 | |
437 | glScale $self->{tilesize}, $self->{tilesize}; |
504 | glScale $self->{tilesize}, $self->{tilesize}; |
438 | |
505 | |
439 | if (my $tex = $self->{fow_texture}) { |
506 | if (my $tex = $self->{fow_texture}) { |
440 | glPushMatrix; |
507 | glPushMatrix; |
… | |
… | |
474 | |
541 | |
475 | $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook }); |
542 | $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook }); |
476 | |
543 | |
477 | return unless $self->{list}; |
544 | return unless $self->{list}; |
478 | |
545 | |
479 | my $focused = $CFPlus::UI::FOCUS == $self |
546 | my $focused = $DC::UI::FOCUS == $self |
480 | || $CFPlus::UI::FOCUS == $::COMPLETER->{entry}; |
547 | || $DC::UI::FOCUS == $::COMPLETER->{entry}; |
481 | |
548 | |
482 | return |
549 | return |
483 | unless $focused || !$::FAST; |
550 | unless $focused || !$::FAST; |
484 | |
551 | |
485 | glCallList $self->{list}; |
552 | glCallList $self->{list}; |
… | |
… | |
505 | glDeleteList $self->{list}; |
572 | glDeleteList $self->{list}; |
506 | |
573 | |
507 | $self->SUPER::DESTROY; |
574 | $self->SUPER::DESTROY; |
508 | } |
575 | } |
509 | |
576 | |
510 | package CFPlus::MapWidget::MapMap; |
577 | package DC::MapWidget::MapMap; |
511 | |
578 | |
512 | use strict; |
579 | use strict; |
513 | use utf8; |
580 | use utf8; |
514 | |
581 | |
515 | our @ISA = CFPlus::UI::Base::; |
582 | our @ISA = DC::UI::Base::; |
516 | |
583 | |
517 | use Time::HiRes qw(time); |
584 | use Time::HiRes qw(time); |
518 | use CFPlus::OpenGL; |
585 | use DC::OpenGL; |
519 | |
586 | |
520 | sub size_request { |
587 | sub size_request { |
521 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
588 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
522 | } |
589 | } |
523 | |
590 | |
… | |
… | |
548 | $self->{y0} = $y0; |
615 | $self->{y0} = $y0; |
549 | |
616 | |
550 | $self->{texture_atime} = time + 1/3; |
617 | $self->{texture_atime} = time + 1/3; |
551 | |
618 | |
552 | $self->{texture} = |
619 | $self->{texture} = |
553 | new CFPlus::Texture |
620 | new DC::Texture |
554 | w => $w, |
621 | w => $w, |
555 | h => $h, |
622 | h => $h, |
556 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
623 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
557 | type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
624 | type => $DC::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
558 | } |
625 | } |
559 | } |
626 | } |
560 | |
627 | |
561 | sub invoke_visibility_change { |
628 | sub invoke_visibility_change { |
562 | my ($self) = @_; |
629 | my ($self) = @_; |
… | |
… | |
608 | glEnd; |
675 | glEnd; |
609 | |
676 | |
610 | glDisable GL_BLEND; |
677 | glDisable GL_BLEND; |
611 | } |
678 | } |
612 | |
679 | |
613 | package CFPlus::MapWidget::Command; |
680 | package DC::MapWidget::Command; |
614 | |
681 | |
615 | use strict; |
682 | use strict; |
616 | |
683 | |
617 | use CFPlus::OpenGL; |
684 | use DC::OpenGL; |
618 | |
685 | |
619 | our @ISA = CFPlus::UI::Frame::; |
686 | our @ISA = DC::UI::Frame::; |
620 | |
687 | |
621 | sub new { |
688 | sub new { |
622 | my $class = shift; |
689 | my $class = shift; |
623 | |
690 | |
624 | my $self = $class->SUPER::new ( |
691 | my $self = $class->SUPER::new ( |
625 | bg => [0, 0, 0, 0.8], |
692 | bg => [0, 0, 0, 0.8], |
626 | @_, |
693 | @_, |
627 | ); |
694 | ); |
628 | |
695 | |
629 | $self->add ($self->{vbox} = new CFPlus::UI::VBox); |
696 | $self->add ($self->{vbox} = new DC::UI::VBox); |
630 | |
697 | |
631 | $self->{label} = [ |
698 | $self->{label} = [ |
632 | map |
699 | map |
633 | CFPlus::UI::Label->new ( |
700 | DC::UI::Label->new ( |
|
|
701 | align => 0, |
634 | can_hover => 1, |
702 | can_hover => 1, |
635 | can_events => 1, |
703 | can_events => 1, |
636 | tooltip_width => 0.33, |
704 | tooltip_width => 0.33, |
637 | fontsize => $_, |
705 | fontsize => $_, |
638 | ), (0.8) x 16 |
706 | ), (0.8) x 16 |
639 | ]; |
707 | ]; |
640 | |
708 | |
641 | $self->{entry} = new CFPlus::UI::Entry |
709 | $self->{entry} = new DC::UI::Entry |
642 | on_changed => sub { |
710 | on_changed => sub { |
643 | $self->update_labels; |
711 | $self->update_labels; |
644 | 0 |
712 | 0 |
645 | }, |
713 | }, |
646 | on_button_down => sub { |
714 | on_button_down => sub { |
647 | my ($entry, $ev, $x, $y) = @_; |
715 | my ($entry, $ev, $x, $y) = @_; |
648 | |
716 | |
649 | if ($ev->{button} == 3) { |
717 | if ($ev->{button} == 3) { |
650 | (new CFPlus::UI::Menu |
718 | (new DC::UI::Menu |
651 | items => [ |
719 | items => [ |
652 | ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" |
720 | ["bind <i>" . (DC::asxml $self->{select}) . "</i> to a key" |
653 | => sub { CFPlus::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }] |
721 | => sub { DC::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }] |
654 | ], |
722 | ], |
655 | )->popup ($ev); |
723 | )->popup ($ev); |
656 | return 1; |
724 | return 1; |
657 | } |
725 | } |
658 | 0 |
726 | 0 |
… | |
… | |
673 | $self->hide; |
741 | $self->hide; |
674 | } |
742 | } |
675 | } elsif ($ev->{sym} == 27) { |
743 | } elsif ($ev->{sym} == 27) { |
676 | $self->{hist_ptr} = 0; |
744 | $self->{hist_ptr} = 0; |
677 | $self->hide; |
745 | $self->hide; |
678 | } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) { |
746 | } elsif ($ev->{sym} == DC::SDLK_DOWN) { |
679 | if ($self->{hist_ptr} > 1) { |
747 | if ($self->{hist_ptr} > 1) { |
680 | $self->{hist_ptr}--; |
748 | $self->{hist_ptr}--; |
681 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
749 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
682 | } elsif ($self->{hist_ptr} > 0) { |
750 | } elsif ($self->{hist_ptr} > 0) { |
683 | $self->{hist_ptr}--; |
751 | $self->{hist_ptr}--; |
… | |
… | |
685 | } else { |
753 | } else { |
686 | ++$self->{select_offset} |
754 | ++$self->{select_offset} |
687 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
755 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
688 | } |
756 | } |
689 | $self->update_labels; |
757 | $self->update_labels; |
690 | } elsif ($ev->{sym} == CFPlus::SDLK_UP) { |
758 | } elsif ($ev->{sym} == DC::SDLK_UP) { |
691 | if ($self->{select_offset}) { |
759 | if ($self->{select_offset}) { |
692 | --$self->{select_offset} |
760 | --$self->{select_offset} |
693 | } else { |
761 | } else { |
694 | unless ($self->{hist_ptr}) { |
762 | unless ($self->{hist_ptr}) { |
695 | $self->{hist_saveback} = $self->{entry}->get_text; |
763 | $self->{hist_saveback} = $self->{entry}->get_text; |
… | |
… | |
853 | |
921 | |
854 | sub _draw { |
922 | sub _draw { |
855 | my ($self) = @_; |
923 | my ($self) = @_; |
856 | |
924 | |
857 | # hack |
925 | # hack |
858 | local $CFPlus::UI::FOCUS = $self->{entry}; |
926 | local $DC::UI::FOCUS = $self->{entry}; |
859 | |
927 | |
860 | $self->SUPER::_draw; |
928 | $self->SUPER::_draw; |
861 | } |
929 | } |
862 | |
930 | |
863 | 1 |
931 | 1 |