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.87 by root, Sun Oct 8 21:57:54 2006 UTC vs.
Revision 1.102 by root, Sun Apr 1 15:08:14 2007 UTC

6use List::Util qw(min max); 6use List::Util qw(min max);
7 7
8use CFPlus; 8use CFPlus;
9use CFPlus::OpenGL; 9use CFPlus::OpenGL;
10use CFPlus::UI; 10use CFPlus::UI;
11use CFPlus::Macro;
11 12
12our @ISA = CFPlus::UI::Base::; 13our @ISA = CFPlus::UI::Base::;
14
15sub ::T() { 64 }
13 16
14my $magicmap_tex = 17my $magicmap_tex =
15 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", 18 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png",
16 mipmap => 1, wrap => 0, internalformat => GL_ALPHA; 19 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
17 20
67 ::stop_game (); 70 ::stop_game ();
68 local $::PROFILE->{host} = $server; 71 local $::PROFILE->{host} = $server;
69 ::start_game (); 72 ::start_game ();
70} 73}
71 74
72sub check_lwp($) {
73 my ($res) = @_;
74
75 $res->is_error
76 and die $res->status_line;
77
78 $res
79}
80
81sub editor_invoke { 75sub editor_invoke {
82 my $editsup = $::CONN && $::CONN->{editor_support} 76 my $editsup = $::CONN && $::CONN->{editor_support}
83 or return; 77 or return;
84 78
85 my ($pid, $fh); 79 CFPlus::background {
86 unless ($pid = open $fh, "-|:utf8", "-") {
87 $SIG{__DIE__} = sub {
88 my $msg = $_[0];
89 $msg =~ s/\n+/\n/;
90 warn "FATAL: $msg";
91 CFPlus::_exit 99;
92 };
93
94 open STDERR, ">&STDOUT";
95 binmode STDOUT, ":utf8";
96 binmode STDERR, ":utf8";
97 close $fh;
98
99 $| = 1;
100 print "preparing editor startup...\n"; 80 print "preparing editor startup...\n";
101 CFPlus::set_proxy;
102 81
103 my $server = $editsup->{gameserver} || "default"; 82 my $server = $editsup->{gameserver} || "default";
104 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 83 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
105 84
106 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir; 85 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir;
107 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir; 86 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir;
108 87
109 print "map directory is $mapdir\n"; 88 print "map directory is $mapdir\n";
110 print "lib directory is $libdir\n"; 89 print "lib directory is $libdir\n";
111 90
112 require LWP::UserAgent; 91 my $ua = CFPlus::lwp_useragent;
113
114 my $ua = LWP::UserAgent->new (
115 agent => "cfplus $CFPlus::VERSION",
116 keep_alive => 1,
117 env_proxy => 1,
118 timeout => 30,
119 );
120 92
121 for my $file (qw(archetypes crossfire.0)) { 93 for my $file (qw(archetypes crossfire.0)) {
122 my $url = "$editsup->{lib_root}$file"; 94 my $url = "$editsup->{lib_root}$file";
123 print "mirroring $url...\n"; 95 print "mirroring $url...\n";
124 check_lwp $ua->mirror ($url, "$libdir/$file"); 96 CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file");
125 printf "%s size %d octets\n", $file, -s "$libdir/$file"; 97 printf "%s size %d octets\n", $file, -s "$libdir/$file";
126 } 98 }
127 99
128 if (1) { # upload a map 100 if (1) { # upload a map
129 my $mapname = $::CONN->{map_info}[0]; 101 my $mapname = $::CONN->{map_info}[0];
134 106
135 print "getting map revision for $mapname...\n"; 107 print "getting map revision for $mapname...\n";
136 108
137 # try to get the most recent head revision, what a hack, 109 # try to get the most recent head revision, what a hack,
138 # this should have been returned while downloading *sigh* 110 # this should have been returned while downloading *sigh*
139 my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; 111 my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
140 112
141 if ($log =~ /\?rev=(\d+\.\d+)"/) { 113 if ($log =~ /\?rev=(\d+\.\d+)"/) {
142 my $rev = $1; 114 my $rev = $1;
143 115
144 print "downloading revision $rev...\n"; 116 print "downloading revision $rev...\n";
145 117
146 my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; 118 my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
147 119
148 my $meta = { 120 my $meta = {
149 %$editsup, 121 %$editsup,
150 path => $mapname, 122 path => $mapname,
151 revision => $rev, 123 revision => $rev,
197# } 169# }
198 } else { 170 } else {
199 die "viewvc parse error, unable to detect revision\n"; 171 die "viewvc parse error, unable to detect revision\n";
200 } 172 }
201 } 173 }
202
203 CFPlus::_exit;
204 }
205
206 my $buffer;
207
208 Event->io (fd => $fh, poll => 'r', cb => sub {
209 unless (sysread $fh, $buffer, 4096, length $buffer) {
210 $_[0]->w->cancel;
211 $buffer .= "done\n";
212 }
213
214 while ($buffer =~ s/^(.*)\n//) {
215 ::message ({
216 markup => "editor($pid): " . CFPlus::asxml $1,
217 });
218 }
219 }); 174 }
220} 175}
221 176
222sub invoke_button_down { 177sub invoke_button_down {
223 my ($self, $ev, $x, $y) = @_; 178 my ($self, $ev, $x, $y) = @_;
224 179
225 if ($ev->{button} == 1) { 180 if ($ev->{button} == 1) {
226 $self->grab_focus; 181 $self->grab_focus;
227 return unless $::CONN; 182 return unless $::CONN;
228 183
229 my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 184 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize};
230 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 185 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize};
231 186
232 $x -= int 0.5 * $self->{sw}; 187 $x -= CFPlus::floor $::MAP->w * 0.5;
233 $y -= int 0.5 * $self->{sh}; 188 $y -= CFPlus::floor $::MAP->h * 0.5;
234 189
190 if ($::CONN) {
191 if ($::IN_BUILD_MODE) {
192 $::CONN->buildat ($::IN_BUILD_MODE, $x, $y);
193 } else {
235 $::CONN->lookat ($x, $y) 194 $::CONN->lookat ($x, $y)
236 if $::CONN; 195 }
196 }
237 197
238 } elsif ($ev->{button} == 2) { 198 } elsif ($ev->{button} == 2) {
239 $self->grab_focus; 199 $self->grab_focus;
240 return unless $::CONN; 200 return unless $::CONN;
241 201
328 1 288 1
329} 289}
330 290
331sub size_request { 291sub size_request {
332 ( 292 (
333 32 * CFPlus::ceil $::WIDTH / 32, 293 ::T * CFPlus::ceil $::WIDTH / ::T,
334 32 * CFPlus::ceil $::HEIGHT / 32, 294 ::T * CFPlus::ceil $::HEIGHT / ::T,
335 ) 295 )
336} 296}
337 297
338sub update { 298sub update {
339 my ($self) = @_; 299 my ($self) = @_;
365 my $sym = $ev->{sym}; 325 my $sym = $ev->{sym};
366 my $uni = $ev->{unicode}; 326 my $uni = $ev->{unicode};
367 327
368 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; 328 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
369 329
370 if ($uni == ord "\t") { 330 if ($sym == 9) {
371 $::PL_WINDOW->toggle_visibility; 331 ($mod & CFPlus::KMOD_SHIFT ? $::CONSOLE->{window} : $::PL_WINDOW)->toggle_visibility;
372 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { 332 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
373 $::HELP_WINDOW->toggle_visibility; 333 $::HELP_WINDOW->toggle_visibility;
374 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { 334 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
375 ::toggle_player_page ($::STATS_PAGE); 335 ::toggle_player_page ($::STATS_PAGE);
376 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { 336 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
379 ::toggle_player_page ($::SPELL_PAGE); 339 ::toggle_player_page ($::SPELL_PAGE);
380 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { 340 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
381 ::toggle_player_page ($::INVENTORY_PAGE); 341 ::toggle_player_page ($::INVENTORY_PAGE);
382 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { 342 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
383 $::SETUP_DIALOG->toggle_visibility; 343 $::SETUP_DIALOG->toggle_visibility;
384 } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) {
385 $::BIND_EDITOR->set_binding (undef, undef, [],
386 sub {
387 my ($mod, $sym, $cmds) = @_;
388 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
389 });
390 $::BIND_EDITOR->start;
391 $::BIND_EDITOR->show;
392#TODO: elmex, what was this supposed to do? it currently crashes the client.
393# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
394# $::BIND_EDITOR->stop;
395# $::BIND_EDITOR->ask_for_bind_and_commit;
396# $::BIND_EDITOR->hide;
397 } elsif (!$::CONN) { 344 } elsif (!$::CONN) {
398 return 0; # bindings further down need a valid connection 345 return 0; # bindings further down need a valid connection
399 346
400 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { 347 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
401 $::CONN->user_send ("stay fire"); 348 $::CONN->user_send ("stay fire");
406 } elsif ($uni == 13) { 353 } elsif ($uni == 13) {
407 $::CONN->user_send ("examine"); 354 $::CONN->user_send ("examine");
408 } elsif ($uni == ord ".") { 355 } elsif ($uni == ord ".") {
409 $::CONN->user_send ($self->{completer}{last_command}) 356 $::CONN->user_send ($self->{completer}{last_command})
410 if exists $self->{completer}{last_command}; 357 if exists $self->{completer}{last_command};
411 } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) { 358 } elsif (my @macros = CFPlus::Macro::match_event $ev) {
412 $::CONN->user_send ($_) for @$bind_cmd; 359 $::CONN->macro_send ($_) for @macros;
413 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { 360 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
414 $::CONN->user_send ("rotateshoottype +"); 361 $::CONN->user_send ("rotateshoottype +");
415 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { 362 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
416 $::CONN->user_send ("rotateshoottype -"); 363 $::CONN->user_send ("rotateshoottype -");
364 } elsif ($uni == ord '!') {
365 $self->{completer}->set_prefix ("shout ");
366 $self->{completer}->show;
417 } elsif ($uni == ord '"') { 367 } elsif ($uni == ord '"') {
418 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 368 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
419 $self->{completer}->show; 369 $self->{completer}->show;
420 } elsif ($uni == ord "'") { 370 } elsif ($uni == ord "'") {
421 $self->{completer}->set_prefix (""); 371 $self->{completer}->set_prefix ("");
477} 427}
478 428
479sub set_magicmap { 429sub set_magicmap {
480 my ($self, $w, $h, $x, $y, $data) = @_; 430 my ($self, $w, $h, $x, $y, $data) = @_;
481 431
482 $x -= $::MAP->ox + int 0.5 * $::MAP->w; 432 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
483 $y -= $::MAP->oy + int 0.5 * $::MAP->h; 433 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
484 434
485 $self->{magicmap} = [$x, $y, $w, $h, $data]; 435 $self->{magicmap} = [$x, $y, $w, $h, $data];
486 436
487 $self->update; 437 $self->update;
488} 438}
497 447
498 return 448 return
499 unless $focused || !$::FAST; 449 unless $focused || !$::FAST;
500 450
501 if (delete $self->{need_update}) { 451 if (delete $self->{need_update}) {
502 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 452 my $tilesize = $self->{tilesize} = int ::T * $::CFG->{map_scale};
503 453
454 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
455 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
456
504 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 457 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
505 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 458 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
506 459
507 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 460 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
508 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 461 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
509 462
510 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 463 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
511 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 464 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
512 465
513 if ($::CFG->{fow_enable}) { 466 if ($::CFG->{fow_enable}) {
514 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 467 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
515 468
516 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 469 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
517 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 470 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
518 glConvolutionFilter2D ( 471 glConvolutionFilter2D (
519 GL_CONVOLUTION_2D, 472 GL_CONVOLUTION_2D,
541 494
542 glPushMatrix; 495 glPushMatrix;
543 glTranslate $sx0, $sy0; 496 glTranslate $sx0, $sy0;
544 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 497 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
545 498
546 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 499 $::MAP->draw ($dx, $dy, $sw, $sh, ::T);
547 500
548 glScale 32, 32; 501 glScale ::T, ::T;
549 502
550 if (my $tex = $self->{fow_texture}) { 503 if (my $tex = $self->{fow_texture}) {
551 glEnable GL_TEXTURE_2D; 504 glEnable GL_TEXTURE_2D;
552 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 505 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
553 506
558 } 511 }
559 512
560 if ($self->{magicmap}) { 513 if ($self->{magicmap}) {
561 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 514 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
562 515
563 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); 516 $x += $::MAP->ox + $self->{dx};
564 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); 517 $y += $::MAP->oy + $self->{dy};
565 518
566 glTranslate - $x - 1, - $y - 1; 519 glTranslate - $x - 1, - $y - 1;
567 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 520 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
568 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 521 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
569 } 522 }
628 581
629 $::MAP or return; 582 $::MAP or return;
630 583
631 my ($w, $h) = @$self{qw(w h)}; 584 my ($w, $h) = @$self{qw(w h)};
632 585
633 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 586 my $sw = int $::WIDTH / (::T * $::CFG->{map_scale}) + 0.99;
634 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 587 my $sh = int $::HEIGHT / (::T * $::CFG->{map_scale}) + 0.99;
635 588
636 my $sx = int $::CFG->{map_shift_x} / 32; 589 my $sx = int $::CFG->{map_shift_x} / ::T;
637 my $sy = int $::CFG->{map_shift_y} / 32; 590 my $sy = int $::CFG->{map_shift_y} / ::T;
638 591
639 my $ox = 0.5 * ($w - $sw); 592 my $ox = 0.5 * ($w - $sw);
640 my $oy = 0.5 * ($h - $sh); 593 my $oy = 0.5 * ($h - $sh);
641 594
642 glEnable GL_BLEND; 595 glEnable GL_BLEND;
715 668
716 if ($ev->{button} == 3) { 669 if ($ev->{button} == 3) {
717 (new CFPlus::UI::Menu 670 (new CFPlus::UI::Menu
718 items => [ 671 items => [
719 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" 672 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key"
720 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] 673 => sub { CFPlus::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }]
721 ], 674 ],
722 )->popup ($ev); 675 )->popup ($ev);
723 return 1; 676 return 1;
724 } 677 }
725 0 678 0

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines