ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.110 by root, Thu Jul 19 13:45:18 2007 UTC vs.
Revision 1.127 by root, Sat Dec 29 16:29:00 2007 UTC

1package CFPlus::MapWidget; 1package DC::MapWidget;
2 2
3use strict; 3use strict;
4use utf8; 4use utf8;
5 5
6use List::Util qw(min max); 6use List::Util qw(min max);
7 7
8use CFPlus; 8use DC;
9use CFPlus::OpenGL; 9use DC::OpenGL;
10use CFPlus::UI; 10use DC::UI;
11use CFPlus::Macro; 11use DC::Macro;
12 12
13our @ISA = CFPlus::UI::Base::; 13our @ISA = DC::UI::Base::;
14 14
15my $magicmap_tex = 15my $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
19sub new { 19sub new {
20 my $class = shift; 20 my $class = shift;
21 21
22 my $self = $class->SUPER::new ( 22 my $self = $class->SUPER::new (
23 z => -1, 23 z => -1,
24 can_focus => 1, 24 can_focus => 1,
25 list => glGenList,
26 tilesize => 32, 25 tilesize => 32,
27
28 smooth_matrix => [
29 0.30, 0.50, 0.30,
30 0.50, 0.50, 0.50,
31 0.30, 0.50, 0.30,
32 ],
33
34 @_ 26 @_
35 ); 27 );
36
37 $self->{completer} = new CFPlus::MapWidget::Command::
38 command => $self->{command},
39 tooltip => "#completer_help",
40 ;
41 28
42 $self 29 $self
43} 30}
44 31
45sub set_tilesize { 32sub set_tilesize {
55 42
56 $tooltip =~ s/^\s+//; 43 $tooltip =~ s/^\s+//;
57 $tooltip = "<big>$data</big>\n\n$tooltip"; 44 $tooltip = "<big>$data</big>\n\n$tooltip";
58 $tooltip =~ s/\s+$//; 45 $tooltip =~ s/\s+$//;
59 46
60 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; 47 $::COMPLETER->{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
61} 48}
62 49
63sub clr_commands { 50sub clr_commands {
64 my ($self) = @_; 51 my ($self) = @_;
65 52
66 %{$self->{completer}{command}} = (); 53 %{$::COMPLETER->{command}} = ();
67 54
68 $self->{completer}->hide 55 $::COMPLETER->hide
69 if $self->{completer}; 56 if $::COMPLETER;
70} 57}
71 58
72sub server_login { 59sub server_login {
73 my ($server) = @_; 60 my ($server) = @_;
74 61
79 66
80sub editor_invoke { 67sub editor_invoke {
81 my $editsup = $::CONN && $::CONN->{editor_support} 68 my $editsup = $::CONN && $::CONN->{editor_support}
82 or return; 69 or return;
83 70
84 CFPlus::background { 71 DC::background {
85 print "preparing editor startup...\n"; 72 print "preparing editor startup...\n";
86 73
87 my $server = $editsup->{gameserver} || "default"; 74 my $server = $editsup->{gameserver} || "default";
88 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 75 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
89 76
90 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir; 77 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Deliantra::VARDIR/map.$server"; mkdir $mapdir;
91 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir; 78 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Deliantra::VARDIR/lib.$server"; mkdir $libdir;
92 79
93 print "map directory is $mapdir\n"; 80 print "map directory is $mapdir\n";
94 print "lib directory is $libdir\n"; 81 print "lib directory is $libdir\n";
95 82
96 my $ua = CFPlus::lwp_useragent; 83 my $ua = DC::lwp_useragent;
97 84
98 for my $file (qw(archetypes crossfire.0)) { 85 for my $file (qw(archetypes crossfire.0)) {
99 my $url = "$editsup->{lib_root}$file"; 86 my $url = "$editsup->{lib_root}$file";
100 print "mirroring $url...\n"; 87 print "mirroring $url...\n";
101 CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file"); 88 DC::lwp_check $ua->mirror ($url, "$libdir/$file");
102 printf "%s size %d octets\n", $file, -s "$libdir/$file"; 89 printf "%s size %d octets\n", $file, -s "$libdir/$file";
103 } 90 }
104 91
105 if (1) { # upload a map 92 if (1) { # upload a map
106 my $mapname = $::CONN->{map_info}[0]; 93 my $mapname = $::CONN->{map_info}[0];
111 98
112 print "getting map revision for $mapname...\n"; 99 print "getting map revision for $mapname...\n";
113 100
114 # try to get the most recent head revision, what a hack, 101 # try to get the most recent head revision, what a hack,
115 # this should have been returned while downloading *sigh* 102 # this should have been returned while downloading *sigh*
116 my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; 103 my $log = (DC::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
117 104
118 if ($log =~ /\?rev=(\d+\.\d+)"/) { 105 if ($log =~ /\?rev=(\d+\.\d+)"/) {
119 my $rev = $1; 106 my $rev = $1;
120 107
121 print "downloading revision $rev...\n"; 108 print "downloading revision $rev...\n";
122 109
123 my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; 110 my $map = (DC::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
124 111
125 my $meta = { 112 my $meta = {
126 %$editsup, 113 %$editsup,
127 path => $mapname, 114 path => $mapname,
128 revision => $rev, 115 revision => $rev,
133 require File::Path; 120 require File::Path;
134 121
135 File::Path::mkpath (File::Basename::dirname ($mappath)); 122 File::Path::mkpath (File::Basename::dirname ($mappath));
136 open my $fh, ">:raw:perlio", "$mappath.meta" 123 open my $fh, ">:raw:perlio", "$mappath.meta"
137 or die "$mappath.meta: $!\n"; 124 or die "$mappath.meta: $!\n";
138 print $fh CFPlus::to_json $meta; 125 print $fh DC::encode_json $meta;
139 close $fh; 126 close $fh;
140 open my $fh, ">:raw:perlio:utf8", $mappath 127 open my $fh, ">:raw:perlio:utf8", $mappath
141 or die "$mappath: $!\n"; 128 or die "$mappath: $!\n";
142 print $fh $map; 129 print $fh $map;
143 close $fh; 130 close $fh;
184 171
185 if ($ev->{button} == 1) { 172 if ($ev->{button} == 1) {
186 $self->grab_focus; 173 $self->grab_focus;
187 return unless $::CONN; 174 return unless $::CONN;
188 175
189 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; 176 my $x = $self->{dx} + DC::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize};
190 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; 177 my $y = $self->{dy} + DC::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize};
191 178
192 $x -= CFPlus::floor $::MAP->w * 0.5; 179 $x -= DC::floor $::MAP->w * 0.5;
193 $y -= CFPlus::floor $::MAP->h * 0.5; 180 $y -= DC::floor $::MAP->h * 0.5;
194 181
195 if ($::CONN) { 182 if ($::CONN) {
196 if ($::IN_BUILD_MODE) {
197 $::CONN->buildat ($::IN_BUILD_MODE, $x, $y);
198 } else {
199 $::CONN->lookat ($x, $y) 183 $::CONN->lookat ($x, $y)
200 }
201 } 184 }
202 185
203 } elsif ($ev->{button} == 2) { 186 } elsif ($ev->{button} == 2) {
204 $self->grab_focus; 187 $self->grab_focus;
205 return unless $::CONN; 188 return unless $::CONN;
234 ], 217 ],
235 ); 218 );
236 219
237 if ($::CONN && $::CONN->{editor_support}) { 220 if ($::CONN && $::CONN->{editor_support}) {
238 push @items, [ 221 push @items, [
239 "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", 222 "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>",
240 \&editor_invoke, 223 \&editor_invoke,
241 ]; 224 ];
242 225
243 for my $type (qw(test name)) { 226 for my $type (qw(test name)) {
244 $::CONN->{editor_support}{type} ne $type 227 $::CONN->{editor_support}{type} ne $type
245 or next; 228 or next;
246 my $server = $::CONN->{editor_support}{"${type}server"} 229 my $server = $::CONN->{editor_support}{"${type}server"}
247 or next; 230 or next;
248 231
249 push @items, [ 232 push @items, [
250 "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>", 233 "Login on $type server <span size='xx-small'>(" . (DC::asxml $server) . ")</span>",
251 sub { server_login $server }, 234 sub { server_login $server },
252 ]; 235 ];
253 } 236 }
254 } 237 }
255 238
263 } 246 }
264 } 247 }
265 ], 248 ],
266 ; 249 ;
267 250
268 (new CFPlus::UI::Menu 251 (new DC::UI::Menu
269 items => \@items, 252 items => \@items,
270 )->popup ($ev); 253 )->popup ($ev);
271 } 254 }
272 255
273 1 256 1
295 278
296sub size_request { 279sub size_request {
297 my ($self) = @_; 280 my ($self) = @_;
298 281
299 ( 282 (
300 $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize}, 283 $self->{tilesize} * DC::ceil $::WIDTH / $self->{tilesize},
301 $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize}, 284 $self->{tilesize} * DC::ceil $::HEIGHT / $self->{tilesize},
302 ) 285 )
303} 286}
304 287
305sub update { 288sub update {
306 my ($self) = @_; 289 my ($self) = @_;
308 $self->{need_update} = 1; 291 $self->{need_update} = 1;
309 $self->SUPER::update; 292 $self->SUPER::update;
310} 293}
311 294
312my %DIR = ( 295my %DIR = (
313 CFPlus::SDLK_KP5, [0, "stay fire"], 296 ( "," . DC::SDLK_KP5 ), [0, "stay fire"],
314 CFPlus::SDLK_KP8, [1, "north"], 297 ( "," . DC::SDLK_KP8 ), [1, "north"],
315 CFPlus::SDLK_KP9, [2, "northeast"], 298 ( "," . DC::SDLK_KP9 ), [2, "northeast"],
316 CFPlus::SDLK_KP6, [3, "east"], 299 ( "," . DC::SDLK_KP6 ), [3, "east"],
317 CFPlus::SDLK_KP3, [4, "southeast"], 300 ( "," . DC::SDLK_KP3 ), [4, "southeast"],
318 CFPlus::SDLK_KP2, [5, "south"], 301 ( "," . DC::SDLK_KP2 ), [5, "south"],
319 CFPlus::SDLK_KP1, [6, "southwest"], 302 ( "," . DC::SDLK_KP1 ), [6, "southwest"],
320 CFPlus::SDLK_KP4, [7, "west"], 303 ( "," . DC::SDLK_KP4 ), [7, "west"],
321 CFPlus::SDLK_KP7, [8, "northwest"], 304 ( "," . DC::SDLK_KP7 ), [8, "northwest"],
322 305
323 CFPlus::SDLK_UP, [1, "north"], 306 ( "," . DC::SDLK_UP ), [1, "north"],
307 ("1," . DC::SDLK_UP ), [2, "northeast"],
324 CFPlus::SDLK_RIGHT, [3, "east"], 308 ( "," . DC::SDLK_RIGHT), [3, "east"],
309 ("1," . DC::SDLK_RIGHT), [4, "southeast"],
325 CFPlus::SDLK_DOWN, [5, "south"], 310 ( "," . DC::SDLK_DOWN ), [5, "south"],
311 ("1," . DC::SDLK_DOWN ), [6, "southwest"],
326 CFPlus::SDLK_LEFT, [7, "west"], 312 ( "," . DC::SDLK_LEFT ), [7, "west"],
313 ("1," . DC::SDLK_LEFT ), [8, "northwest"],
327); 314);
328 315
329sub invoke_key_down { 316sub invoke_key_down {
330 my ($self, $ev) = @_; 317 my ($self, $ev) = @_;
331 318
332 my $mod = $ev->{mod}; 319 my $mod = $ev->{mod};
333 my $sym = $ev->{sym}; 320 my $sym = $ev->{sym};
334 my $uni = $ev->{unicode}; 321 my $uni = $ev->{unicode};
335 322
336 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; 323 $mod &= DC::KMOD_CTRL | DC::KMOD_ALT | DC::KMOD_SHIFT;
337 324
338 if ($sym == 9) { 325 if ($::CONN && (my $dir = $DIR{(!!($mod & DC::KMOD_ALT)) . ",$sym"})) {
339 ($mod & CFPlus::KMOD_SHIFT ? $::CONSOLE->{window} : $::PL_WINDOW)->toggle_visibility;
340 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
341 $::HELP_WINDOW->toggle_visibility;
342 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
343 ::toggle_player_page ($::STATS_PAGE);
344 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
345 ::toggle_player_page ($::SKILL_PAGE);
346 } elsif ($sym == CFPlus::SDLK_F4 && !$mod) {
347 ::toggle_player_page ($::SPELL_PAGE);
348 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
349 ::toggle_player_page ($::INVENTORY_PAGE);
350 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
351 $::SETUP_DIALOG->toggle_visibility;
352 } elsif (!$::CONN) {
353 return 0; # bindings further down need a valid connection
354
355 } elsif ($uni == ord ",") {
356 $::CONN->user_send ("take");
357 } elsif ($uni == ord " ") {
358 $::CONN->user_send ("apply");
359 } elsif ($uni == 13) {
360 $::CONN->user_send ("examine");
361 } elsif ($uni == ord ".") {
362 $::CONN->user_send ($self->{completer}{last_command})
363 if exists $self->{completer}{last_command};
364 } elsif (my @macros = CFPlus::Macro::match_event $ev) {
365 $::CONN->macro_send ($_) for @macros;
366 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
367 $::CONN->user_send ("rotateshoottype +");
368 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
369 $::CONN->user_send ("rotateshoottype -");
370 } elsif ($uni == ord '!') {
371 $self->{completer}->set_prefix ("shout ");
372 $self->{completer}->show;
373 } elsif ($uni == ord '"') {
374 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
375 $self->{completer}->show;
376 } elsif ($uni == ord "'") {
377 $self->{completer}->set_prefix ("");
378 $self->{completer}->show;
379 } elsif (exists $DIR{$sym}) {
380 if ($mod & CFPlus::KMOD_SHIFT) { 326 if ($mod & DC::KMOD_SHIFT) {
381 $self->{shft}++; 327 $self->{shft}++;
382 if ($DIR{$sym}[0] != $self->{fire_dir}) { 328 if ($dir->[0] != $self->{fire_dir}) {
383 $::CONN->user_send ("fire $DIR{$sym}[0]"); 329 $::CONN->user_send ("fire $dir->[0]");
384 } 330 }
385 $self->{fire_dir} = $DIR{$sym}[0]; 331 $self->{fire_dir} = $dir->[0];
386 } elsif ($mod & CFPlus::KMOD_CTRL) { 332 } elsif ($mod & DC::KMOD_CTRL) {
387 $self->{ctrl}++; 333 $self->{ctrl}++;
388 $::CONN->user_send ("run $DIR{$sym}[0]"); 334 $::CONN->user_send ("run $dir->[0]");
389 } else { 335 } else {
390 $::CONN->user_send ("$DIR{$sym}[1]"); 336 $::CONN->user_send ("$dir->[1]");
391 } 337 }
392 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 338
393 $self->{completer}->inject_key_down ($ev);
394 $self->{completer}->show;
395 } else {
396 return 0; 339 return 1;
397 }
398
399 1 340 }
341
342 0
400} 343}
401 344
402sub invoke_key_up { 345sub invoke_key_up {
403 my ($self, $ev) = @_; 346 my ($self, $ev) = @_;
404 347
405 my $res = 0; 348 my $res = 0;
406 my $mod = $ev->{mod}; 349 my $mod = $ev->{mod};
407 my $sym = $ev->{sym}; 350 my $sym = $ev->{sym};
408 351
409 if ($::CFG->{shift_fire_stop}) { 352 if ($::CFG->{shift_fire_stop}) {
410 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) { 353 if (!($mod & DC::KMOD_SHIFT) && delete $self->{shft}) {
411 $::CONN->user_send ("fire_stop"); 354 $::CONN->user_send ("fire_stop");
412 delete $self->{fire_dir}; 355 delete $self->{fire_dir};
413 $res = 1; 356 $res = 1;
414 } 357 }
415 } else { 358 } else {
416 if (exists $DIR{$sym} && delete $self->{shft}) { 359 if (exists $DIR{(!!($mod & DC::KMOD_ALT)) . ",$sym"} && delete $self->{shft}) {
417 $::CONN->user_send ("fire_stop"); 360 $::CONN->user_send ("fire_stop");
418 delete $self->{fire_dir}; 361 delete $self->{fire_dir};
419 $res = 1; 362 $res = 1;
420 } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? 363 } elsif (($sym == DC::SDLK_LSHIFT || $sym == DC::SDLK_RSHIFT)
364 && delete $self->{shft}) { # XXX: is RSHIFT ok?
421 $::CONN->user_send ("fire_stop"); 365 $::CONN->user_send ("fire_stop");
422 delete $self->{fire_dir}; 366 delete $self->{fire_dir};
423 $res = 1; 367 $res = 1;
424 } 368 }
425 } 369 }
426 370
427 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) { 371 if (!($mod & DC::KMOD_CTRL ) && delete $self->{ctrl}) {
428 $::CONN->user_send ("run_stop"); 372 $::CONN->user_send ("run_stop");
429 $res = 1; 373 $res = 1;
430 } 374 }
431 375
432 $res 376 $res
452} 396}
453 397
454sub refresh_hook { 398sub refresh_hook {
455 my ($self) = @_; 399 my ($self) = @_;
456 400
457 return unless $::MAP; 401 if ($::MAP && $::CONN) {
458
459 if (delete $self->{need_update}) { 402 if (delete $self->{need_update}) {
460 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; 403 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
461 404
462 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 405 my $sw = $self->{sw} = 1 + DC::ceil $self->{w} / $tilesize;
463 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 406 my $sh = $self->{sh} = 1 + DC::ceil $self->{h} / $tilesize;
464 407
465 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 408 my $sx = DC::ceil $::CFG->{map_shift_x} / $tilesize;
466 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 409 my $sy = DC::ceil $::CFG->{map_shift_y} / $tilesize;
467 410
468 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 411 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
469 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 412 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
470 413
471 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; 414 my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx;
472 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; 415 my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy;
473 416
474 if ($::CFG->{fow_enable}) { 417 if ($::CFG->{fow_enable}) {
475 my ($w, $h, $data) = $::MAP->fow_texture ( 418 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
476 $dx, $dy, $sw, $sh,
477 $::CFG->{fow_smooth},
478 pack "f*", @{ $self->{smooth_matrix} },
479 );
480 419
481 $self->{fow_texture} = new CFPlus::Texture 420 $self->{fow_texture} = new DC::Texture
482 w => $w, 421 w => $w,
483 h => $h, 422 h => $h,
484 data => $data, 423 data => $data,
485 internalformat => GL_ALPHA, 424 internalformat => GL_ALPHA,
486 format => GL_ALPHA; 425 format => GL_ALPHA;
487 } else { 426 } else {
488 delete $self->{fow_texture}; 427 delete $self->{fow_texture};
489 } 428 }
490 429
491 glNewList $self->{list}; 430 glNewList ($self->{list} ||= glGenList);
492 431
493 glPushMatrix;
494 glTranslate $sx0, $sy0;
495 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
496
497 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
498
499 glScale $self->{tilesize}, $self->{tilesize};
500
501 if (my $tex = $self->{fow_texture}) {
502 glPushMatrix; 432 glPushMatrix;
503 #glScale 1/3, 1/3 if $::CFG->{fow_smooth}; 433 glTranslate $sx0, $sy0;
434 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
435
436 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
437
438 glScale $self->{tilesize}, $self->{tilesize};
439
440 if (my $tex = $self->{fow_texture}) {
441 glPushMatrix;
442 glScale 1/3, 1/3;
504 glEnable GL_TEXTURE_2D; 443 glEnable GL_TEXTURE_2D;
505 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 444 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
506 445
507 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 446 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
508 $self->{fow_texture}->draw_quad_alpha (0, 0); 447 $self->{fow_texture}->draw_quad_alpha (0, 0);
509 448
510 glDisable GL_TEXTURE_2D; 449 glDisable GL_TEXTURE_2D;
450 glPopMatrix;
451 }
452
453 if ($self->{magicmap}) {
454 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
455
456 $x += $::MAP->ox + $self->{dx};
457 $y += $::MAP->oy + $self->{dy};
458
459 glTranslate - $x - 1, - $y - 1;
460 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
461 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
462 }
463
511 glPopMatrix; 464 glPopMatrix;
512 }
513
514 if ($self->{magicmap}) {
515 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
516
517 $x += $::MAP->ox + $self->{dx};
518 $y += $::MAP->oy + $self->{dy};
519
520 glTranslate - $x - 1, - $y - 1;
521 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
522 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
523 }
524
525 glPopMatrix;
526 glEndList; 465 glEndList;
466 }
467 } else {
468 glDeleteList delete $self->{list}
469 if $self->{list};
527 } 470 }
528
529} 471}
530 472
531sub draw { 473sub draw {
532 my ($self) = @_; 474 my ($self) = @_;
533 475
534 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook }); 476 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook });
535 477
536 return unless $self->{list}; 478 return unless $self->{list};
537 479
538 my $focused = $CFPlus::UI::FOCUS == $self 480 my $focused = $DC::UI::FOCUS == $self
539 || $CFPlus::UI::FOCUS == $self->{completer}{entry}; 481 || $DC::UI::FOCUS == $::COMPLETER->{entry};
540 482
541 return 483 return
542 unless $focused || !$::FAST; 484 unless $focused || !$::FAST;
543 485
544 glCallList $self->{list}; 486 glCallList $self->{list};
545 487
546 # TNT2 emulates logops in software (or worse :) 488 # TNT2 emulates logops in software (or worse :)
547 unless ($focused) { 489 unless ($focused) {
548 glColor 0.4, 0.2, 0.2, 0.6; 490 glColor_premultiply 0, 0, 1, 0.25;
549 glEnable GL_BLEND; 491 glEnable GL_BLEND;
550 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 492 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
551 glBegin GL_QUADS; 493 glBegin GL_QUADS;
552 glVertex 0, 0; 494 glVertex 0, 0;
553 glVertex 0, $::HEIGHT; 495 glVertex 0, $::HEIGHT;
554 glVertex $::WIDTH, $::HEIGHT; 496 glVertex $::WIDTH, $::HEIGHT;
555 glVertex $::WIDTH, 0; 497 glVertex $::WIDTH, 0;
564 glDeleteList $self->{list}; 506 glDeleteList $self->{list};
565 507
566 $self->SUPER::DESTROY; 508 $self->SUPER::DESTROY;
567} 509}
568 510
569package CFPlus::MapWidget::MapMap; 511package DC::MapWidget::MapMap;
570 512
571use strict; 513use strict;
572use utf8; 514use utf8;
573 515
574our @ISA = CFPlus::UI::Base::; 516our @ISA = DC::UI::Base::;
575 517
576use Time::HiRes qw(time); 518use Time::HiRes qw(time);
577use CFPlus::OpenGL; 519use DC::OpenGL;
578 520
579sub size_request { 521sub size_request {
580 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 522 ($::HEIGHT * 0.2, $::HEIGHT * 0.2)
581} 523}
582 524
583sub refresh_hook { 525sub refresh_hook {
584 my ($self) = @_; 526 my ($self) = @_;
585 527
607 $self->{y0} = $y0; 549 $self->{y0} = $y0;
608 550
609 $self->{texture_atime} = time + 1/3; 551 $self->{texture_atime} = time + 1/3;
610 552
611 $self->{texture} = 553 $self->{texture} =
612 new CFPlus::Texture 554 new DC::Texture
613 w => $w, 555 w => $w,
614 h => $h, 556 h => $h,
615 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 557 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
616 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; 558 type => $DC::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
617 } 559 }
618} 560}
619 561
620sub invoke_visibility_change { 562sub invoke_visibility_change {
621 my ($self) = @_; 563 my ($self) = @_;
667 glEnd; 609 glEnd;
668 610
669 glDisable GL_BLEND; 611 glDisable GL_BLEND;
670} 612}
671 613
672package CFPlus::MapWidget::Command; 614package DC::MapWidget::Command;
673 615
674use strict; 616use strict;
675 617
676use CFPlus::OpenGL; 618use DC::OpenGL;
677 619
678our @ISA = CFPlus::UI::Frame::; 620our @ISA = DC::UI::Frame::;
679 621
680sub new { 622sub new {
681 my $class = shift; 623 my $class = shift;
682 624
683 my $self = $class->SUPER::new ( 625 my $self = $class->SUPER::new (
684 bg => [0, 0, 0, 0.8], 626 bg => [0, 0, 0, 0.8],
685 @_, 627 @_,
686 ); 628 );
687 629
688 $self->add ($self->{vbox} = new CFPlus::UI::VBox); 630 $self->add ($self->{vbox} = new DC::UI::VBox);
689 631
690 $self->{label} = [ 632 $self->{label} = [
691 map 633 map
692 CFPlus::UI::Label->new ( 634 DC::UI::Label->new (
635 align => 0,
693 can_hover => 1, 636 can_hover => 1,
694 can_events => 1, 637 can_events => 1,
695 tooltip_width => 0.33, 638 tooltip_width => 0.33,
696 fontsize => $_, 639 fontsize => $_,
697 ), (0.8) x 16 640 ), (0.8) x 16
698 ]; 641 ];
699 642
700 $self->{entry} = new CFPlus::UI::Entry 643 $self->{entry} = new DC::UI::Entry
701 on_changed => sub { 644 on_changed => sub {
702 $self->update_labels; 645 $self->update_labels;
703 0 646 0
704 }, 647 },
705 on_button_down => sub { 648 on_button_down => sub {
706 my ($entry, $ev, $x, $y) = @_; 649 my ($entry, $ev, $x, $y) = @_;
707 650
708 if ($ev->{button} == 3) { 651 if ($ev->{button} == 3) {
709 (new CFPlus::UI::Menu 652 (new DC::UI::Menu
710 items => [ 653 items => [
711 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" 654 ["bind <i>" . (DC::asxml $self->{select}) . "</i> to a key"
712 => sub { CFPlus::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }] 655 => sub { DC::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }]
713 ], 656 ],
714 )->popup ($ev); 657 )->popup ($ev);
715 return 1; 658 return 1;
716 } 659 }
717 0 660 0
732 $self->hide; 675 $self->hide;
733 } 676 }
734 } elsif ($ev->{sym} == 27) { 677 } elsif ($ev->{sym} == 27) {
735 $self->{hist_ptr} = 0; 678 $self->{hist_ptr} = 0;
736 $self->hide; 679 $self->hide;
737 } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) { 680 } elsif ($ev->{sym} == DC::SDLK_DOWN) {
738 if ($self->{hist_ptr} > 1) { 681 if ($self->{hist_ptr} > 1) {
739 $self->{hist_ptr}--; 682 $self->{hist_ptr}--;
740 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 683 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
741 } elsif ($self->{hist_ptr} > 0) { 684 } elsif ($self->{hist_ptr} > 0) {
742 $self->{hist_ptr}--; 685 $self->{hist_ptr}--;
744 } else { 687 } else {
745 ++$self->{select_offset} 688 ++$self->{select_offset}
746 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 689 if $self->{select_offset} < $#{ $self->{last_match} || [] };
747 } 690 }
748 $self->update_labels; 691 $self->update_labels;
749 } elsif ($ev->{sym} == CFPlus::SDLK_UP) { 692 } elsif ($ev->{sym} == DC::SDLK_UP) {
750 if ($self->{select_offset}) { 693 if ($self->{select_offset}) {
751 --$self->{select_offset} 694 --$self->{select_offset}
752 } else { 695 } else {
753 unless ($self->{hist_ptr}) { 696 unless ($self->{hist_ptr}) {
754 $self->{hist_saveback} = $self->{entry}->get_text; 697 $self->{hist_saveback} = $self->{entry}->get_text;
912 855
913sub _draw { 856sub _draw {
914 my ($self) = @_; 857 my ($self) = @_;
915 858
916 # hack 859 # hack
917 local $CFPlus::UI::FOCUS = $self->{entry}; 860 local $DC::UI::FOCUS = $self->{entry};
918 861
919 $self->SUPER::_draw; 862 $self->SUPER::_draw;
920} 863}
921 864
9221 8651

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines