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.82 by root, Fri Sep 29 00:56:06 2006 UTC vs.
Revision 1.116 by root, Mon Aug 6 05:06:33 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::;
13 14
14my $magicmap_tex = 15my $magicmap_tex =
15 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", 16 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png",
19 my $class = shift; 20 my $class = shift;
20 21
21 my $self = $class->SUPER::new ( 22 my $self = $class->SUPER::new (
22 z => -1, 23 z => -1,
23 can_focus => 1, 24 can_focus => 1,
24 list => glGenList, 25 tilesize => 32,
25
26 smooth_matrix => [
27 0.05, 0.13, 0.05,
28 0.13, 0.30, 0.13,
29 0.05, 0.13, 0.05,
30 ],
31
32 @_ 26 @_
33 ); 27 );
34 28
35 $self->{completer} = new CFPlus::MapWidget::Command:: 29 $self->{completer} = new CFPlus::MapWidget::Command::
36 command => $self->{command}, 30 command => $self->{command},
38 ; 32 ;
39 33
40 $self 34 $self
41} 35}
42 36
37sub set_tilesize {
38 my ($self, $tilesize) = @_;
39
40 $self->{tilesize} = $tilesize;
41}
42
43sub add_command { 43sub add_command {
44 my ($self, $command, $tooltip, $widget, $cb) = @_; 44 my ($self, $command, $tooltip, $widget, $cb) = @_;
45 45
46 (my $data = $command) =~ s/\\//g; 46 (my $data = $command) =~ s/\\//g;
47 47
59 59
60 $self->{completer}->hide 60 $self->{completer}->hide
61 if $self->{completer}; 61 if $self->{completer};
62} 62}
63 63
64sub server_login {
65 my ($server) = @_;
66
67 ::stop_game ();
68 local $::PROFILE->{host} = $server;
69 ::start_game ();
70}
71
72sub editor_invoke {
73 my $editsup = $::CONN && $::CONN->{editor_support}
74 or return;
75
76 CFPlus::background {
77 print "preparing editor startup...\n";
78
79 my $server = $editsup->{gameserver} || "default";
80 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
81
82 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir;
83 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir;
84
85 print "map directory is $mapdir\n";
86 print "lib directory is $libdir\n";
87
88 my $ua = CFPlus::lwp_useragent;
89
90 for my $file (qw(archetypes crossfire.0)) {
91 my $url = "$editsup->{lib_root}$file";
92 print "mirroring $url...\n";
93 CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file");
94 printf "%s size %d octets\n", $file, -s "$libdir/$file";
95 }
96
97 if (1) { # upload a map
98 my $mapname = $::CONN->{map_info}[0];
99
100 my $mappath = "$mapdir/$mapname";
101
102 -e $mappath and die "$mappath already exists\n";
103
104 print "getting map revision for $mapname...\n";
105
106 # try to get the most recent head revision, what a hack,
107 # this should have been returned while downloading *sigh*
108 my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
109
110 if ($log =~ /\?rev=(\d+\.\d+)"/) {
111 my $rev = $1;
112
113 print "downloading revision $rev...\n";
114
115 my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
116
117 my $meta = {
118 %$editsup,
119 path => $mapname,
120 revision => $rev,
121 cf_login => $::PROFILE->{user},
122 };
123
124 require File::Basename;
125 require File::Path;
126
127 File::Path::mkpath (File::Basename::dirname ($mappath));
128 open my $fh, ">:raw:perlio", "$mappath.meta"
129 or die "$mappath.meta: $!\n";
130 print $fh CFPlus::to_json $meta;
131 close $fh;
132 open my $fh, ">:raw:perlio:utf8", $mappath
133 or die "$mappath: $!\n";
134 print $fh $map;
135 close $fh;
136
137 print "saved as $mappath\n";
138
139 print "invoking editor...\n";
140 exec "/root/s2/gce $mappath";#d#
141
142 # now upload it
143# require HTTP::Request::Common;
144#
145# my $res = $ua->post (
146# $ENV{CFPLUS_UPLOAD},
147# Content_Type => 'multipart/form-data',
148# Content => [
149# path => $mapname,
150# mapdir => $ENV{CROSSFIRE_MAPDIR},
151# map => $map,
152# revision => $rev,
153# cf_login => $ENV{CFPLUS_LOGIN},
154# cf_password => $ENV{CFPLUS_PASSWORD},
155# comment => "",
156# ]
157# );
158#
159# if ($res->is_error) {
160# # fatal condition
161# warn $res->status_line;
162# } else {
163# # script replies are marked as {{..}}
164# my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
165# warn map "$_\n", @msgs;
166# }
167 } else {
168 die "viewvc parse error, unable to detect revision\n";
169 }
170 }
171 }
172}
173
64sub invoke_button_down { 174sub invoke_button_down {
65 my ($self, $ev, $x, $y) = @_; 175 my ($self, $ev, $x, $y) = @_;
66 176
67 if ($ev->{button} == 1) { 177 if ($ev->{button} == 1) {
68 $self->grab_focus; 178 $self->grab_focus;
69 return unless $::CONN; 179 return unless $::CONN;
70 180
71 my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 181 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize};
72 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 182 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize};
73 183
74 $x -= int 0.5 * $self->{sw}; 184 $x -= CFPlus::floor $::MAP->w * 0.5;
75 $y -= int 0.5 * $self->{sh}; 185 $y -= CFPlus::floor $::MAP->h * 0.5;
76 186
187 if ($::CONN) {
77 $::CONN->lookat ($x, $y) 188 $::CONN->lookat ($x, $y)
78 if $::CONN; 189 }
79 190
80 } elsif ($ev->{button} == 2) { 191 } elsif ($ev->{button} == 2) {
81 $self->grab_focus; 192 $self->grab_focus;
82 return unless $::CONN; 193 return unless $::CONN;
83 194
93 $::CFG->{map_shift_y} = $bh + $y - $oy; 204 $::CFG->{map_shift_y} = $bh + $y - $oy;
94 205
95 $self->update; 206 $self->update;
96 }; 207 };
97 } elsif ($ev->{button} == 3) { 208 } elsif ($ev->{button} == 3) {
98 (new CFPlus::UI::Menu 209 my @items = (
99 items => [
100 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], 210 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
101 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], 211 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
102 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 212 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
103 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 213 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
104 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 214 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
108 $::PICKUP_ENABLE->{state} 218 $::PICKUP_ENABLE->{state}
109 ? "Disable automatic pickup" 219 ? "Disable automatic pickup"
110 : "Enable automatic pickup", 220 : "Enable automatic pickup",
111 sub { $::PICKUP_ENABLE->toggle } 221 sub { $::PICKUP_ENABLE->toggle }
112 ], 222 ],
223 );
224
225 if ($::CONN && $::CONN->{editor_support}) {
226 push @items, [
227 "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>",
228 \&editor_invoke,
229 ];
230
231 for my $type (qw(test name)) {
232 $::CONN->{editor_support}{type} ne $type
233 or next;
234 my $server = $::CONN->{editor_support}{"${type}server"}
235 or next;
236
237 push @items, [
238 "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>",
239 sub { server_login $server },
240 ];
241 }
242 }
243
244 push @items,
113 ["Quit", 245 ["Quit",
114 sub { 246 sub {
115 if ($::CONN) { 247 if ($::CONN) {
116 &::open_quit_dialog; 248 &::open_quit_dialog;
117 } else { 249 } else {
118 exit; 250 exit;
119 }
120 } 251 }
121 ], 252 }
122 ], 253 ],
254 ;
255
256 (new CFPlus::UI::Menu
257 items => \@items,
123 )->popup ($ev); 258 )->popup ($ev);
124 } 259 }
125 260
126 1 261 1
127} 262}
145 280
146 1 281 1
147} 282}
148 283
149sub size_request { 284sub size_request {
285 my ($self) = @_;
286
150 ( 287 (
151 32 * CFPlus::ceil $::WIDTH / 32, 288 $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize},
152 32 * CFPlus::ceil $::HEIGHT / 32, 289 $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize},
153 ) 290 )
154} 291}
155 292
156sub update { 293sub update {
157 my ($self) = @_; 294 my ($self) = @_;
159 $self->{need_update} = 1; 296 $self->{need_update} = 1;
160 $self->SUPER::update; 297 $self->SUPER::update;
161} 298}
162 299
163my %DIR = ( 300my %DIR = (
301 ( "," . CFPlus::SDLK_KP5 ), [0, "stay fire"],
164 CFPlus::SDLK_KP8, [1, "north"], 302 ( "," . CFPlus::SDLK_KP8 ), [1, "north"],
165 CFPlus::SDLK_KP9, [2, "northeast"], 303 ( "," . CFPlus::SDLK_KP9 ), [2, "northeast"],
166 CFPlus::SDLK_KP6, [3, "east"], 304 ( "," . CFPlus::SDLK_KP6 ), [3, "east"],
167 CFPlus::SDLK_KP3, [4, "southeast"], 305 ( "," . CFPlus::SDLK_KP3 ), [4, "southeast"],
168 CFPlus::SDLK_KP2, [5, "south"], 306 ( "," . CFPlus::SDLK_KP2 ), [5, "south"],
169 CFPlus::SDLK_KP1, [6, "southwest"], 307 ( "," . CFPlus::SDLK_KP1 ), [6, "southwest"],
170 CFPlus::SDLK_KP4, [7, "west"], 308 ( "," . CFPlus::SDLK_KP4 ), [7, "west"],
171 CFPlus::SDLK_KP7, [8, "northwest"], 309 ( "," . CFPlus::SDLK_KP7 ), [8, "northwest"],
172 310
173 CFPlus::SDLK_UP, [1, "north"], 311 ( "," . CFPlus::SDLK_UP ), [1, "north"],
312 ("1," . CFPlus::SDLK_UP ), [2, "northeast"],
174 CFPlus::SDLK_RIGHT, [3, "east"], 313 ( "," . CFPlus::SDLK_RIGHT), [3, "east"],
314 ("1," . CFPlus::SDLK_RIGHT), [4, "southeast"],
175 CFPlus::SDLK_DOWN, [5, "south"], 315 ( "," . CFPlus::SDLK_DOWN ), [5, "south"],
316 ("1," . CFPlus::SDLK_DOWN ), [6, "southwest"],
176 CFPlus::SDLK_LEFT, [7, "west"], 317 ( "," . CFPlus::SDLK_LEFT ), [7, "west"],
318 ("1," . CFPlus::SDLK_LEFT ), [8, "northwest"],
177); 319);
178 320
179sub invoke_key_down { 321sub invoke_key_down {
180 my ($self, $ev) = @_; 322 my ($self, $ev) = @_;
181 323
183 my $sym = $ev->{sym}; 325 my $sym = $ev->{sym};
184 my $uni = $ev->{unicode}; 326 my $uni = $ev->{unicode};
185 327
186 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; 328 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
187 329
188 if ($uni == ord "\t") { 330 if ($sym == 9) {
189 $::PL_WINDOW->toggle_visibility; 331 ($mod & CFPlus::KMOD_SHIFT ? $::MESSAGE_WINDOW : $::PL_WINDOW)->toggle_visibility;
190 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { 332 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
191 $::HELP_WINDOW->toggle_visibility; 333 $::HELP_WINDOW->toggle_visibility;
192 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { 334 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
193 ::toggle_player_page ($::STATS_PAGE); 335 ::toggle_player_page ($::STATS_PAGE);
194 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { 336 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
197 ::toggle_player_page ($::SPELL_PAGE); 339 ::toggle_player_page ($::SPELL_PAGE);
198 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { 340 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
199 ::toggle_player_page ($::INVENTORY_PAGE); 341 ::toggle_player_page ($::INVENTORY_PAGE);
200 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { 342 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
201 $::SETUP_DIALOG->toggle_visibility; 343 $::SETUP_DIALOG->toggle_visibility;
202 } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) {
203 $::BIND_EDITOR->set_binding (undef, undef, [],
204 sub {
205 my ($mod, $sym, $cmds) = @_;
206 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
207 });
208 $::BIND_EDITOR->start;
209 $::BIND_EDITOR->show;
210#TODO: elmex, what was this supposed to do? it currently crashes the client.
211# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
212# $::BIND_EDITOR->stop;
213# $::BIND_EDITOR->ask_for_bind_and_commit;
214# $::BIND_EDITOR->hide;
215 } elsif (!$::CONN) { 344 } elsif (!$::CONN) {
216 return 0; # bindings further down need a valid connection 345 return 0; # bindings further down need a valid connection
217 346
218 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
219 $::CONN->user_send ("stay fire");
220 } elsif ($uni == ord ",") { 347 } elsif ($uni == ord ",") {
221 $::CONN->user_send ("take"); 348 $::CONN->user_send ("take");
222 } elsif ($uni == ord " ") { 349 } elsif ($uni == ord " ") {
223 $::CONN->user_send ("apply"); 350 $::CONN->user_send ("apply");
224 } elsif ($uni == 13) { 351 } elsif ($uni == 13) {
225 $::CONN->user_send ("examine"); 352 $::CONN->user_send ("examine");
226 } elsif ($uni == ord ".") { 353 } elsif ($uni == ord ".") {
227 $::CONN->user_send ($self->{completer}{last_command}) 354 $::CONN->user_send ($self->{completer}{last_command})
228 if exists $self->{completer}{last_command}; 355 if exists $self->{completer}{last_command};
229 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { 356 } elsif (my @macros = CFPlus::Macro::match_event $ev) {
230 $::CONN->user_send ($_) for @$bind_cmd; 357 $::CONN->macro_send ($_) for @macros;
231 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { 358 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
232 $::CONN->user_send ("rotateshoottype +"); 359 $::CONN->user_send ("rotateshoottype +");
233 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { 360 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
234 $::CONN->user_send ("rotateshoottype -"); 361 $::CONN->user_send ("rotateshoottype -");
362 } elsif ($uni == ord '!') {
363 $self->{completer}->set_prefix ("shout ");
364 $self->{completer}->show;
235 } elsif ($uni == ord '"') { 365 } elsif ($uni == ord '"') {
236 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 366 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
237 $self->{completer}->show; 367 $self->{completer}->show;
238 } elsif ($uni == ord "'") { 368 } elsif ($uni == ord "'") {
239 $self->{completer}->set_prefix (""); 369 $self->{completer}->set_prefix ("");
240 $self->{completer}->show; 370 $self->{completer}->show;
241 } elsif (exists $DIR{$sym}) { 371 } elsif (my $dir = $DIR{(!!($mod & CFPlus::KMOD_ALT)) . ",$sym"}) {
242 if ($mod & CFPlus::KMOD_SHIFT) { 372 if ($mod & CFPlus::KMOD_SHIFT) {
243 $self->{shft}++; 373 $self->{shft}++;
244 if ($DIR{$sym}[0] != $self->{fire_dir}) { 374 if ($dir->[0] != $self->{fire_dir}) {
245 $::CONN->user_send ("fire $DIR{$sym}[0]"); 375 $::CONN->user_send ("fire $dir->[0]");
246 } 376 }
247 $self->{fire_dir} = $DIR{$sym}[0]; 377 $self->{fire_dir} = $DIR{$sym}[0];
248 } elsif ($mod & CFPlus::KMOD_CTRL) { 378 } elsif ($mod & CFPlus::KMOD_CTRL) {
249 $self->{ctrl}++; 379 $self->{ctrl}++;
250 $::CONN->user_send ("run $DIR{$sym}[0]"); 380 $::CONN->user_send ("run $dir->[0]");
251 } else { 381 } else {
252 $::CONN->user_send ("$DIR{$sym}[1]"); 382 $::CONN->user_send ("$dir->[1]");
253 } 383 }
254 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 384 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
255 $self->{completer}->inject_key_down ($ev); 385 $self->{completer}->inject_key_down ($ev);
256 $self->{completer}->show; 386 $self->{completer}->show;
257 } else { 387 } else {
292 } 422 }
293 423
294 $res 424 $res
295} 425}
296 426
427sub invoke_visibility_change {
428 my ($self) = @_;
429
430 $self->refresh_hook;
431
432 0
433}
434
297sub set_magicmap { 435sub set_magicmap {
298 my ($self, $w, $h, $x, $y, $data) = @_; 436 my ($self, $w, $h, $x, $y, $data) = @_;
299 437
300 $x -= $::MAP->ox + int 0.5 * $::MAP->w; 438 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
301 $y -= $::MAP->oy + int 0.5 * $::MAP->h; 439 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
302 440
303 $self->{magicmap} = [$x, $y, $w, $h, $data]; 441 $self->{magicmap} = [$x, $y, $w, $h, $data];
304 442
305 $self->update; 443 $self->update;
306} 444}
307 445
446sub refresh_hook {
447 my ($self) = @_;
448
449 if ($::MAP && $::CONN) {
450 if (delete $self->{need_update}) {
451 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
452
453 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
454 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
455
456 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
457 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
458
459 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
460 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
461
462 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
463 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
464
465 if ($::CFG->{fow_enable}) {
466 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
467
468 $self->{fow_texture} = new CFPlus::Texture
469 w => $w,
470 h => $h,
471 data => $data,
472 internalformat => GL_ALPHA,
473 format => GL_ALPHA;
474 } else {
475 delete $self->{fow_texture};
476 }
477
478 glNewList ($self->{list} ||= glGenList);
479
480 glPushMatrix;
481 glTranslate $sx0, $sy0;
482 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
483
484 my $missing = $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
485
486 glScale $self->{tilesize}, $self->{tilesize};
487
488 if (my $tex = $self->{fow_texture}) {
489 glPushMatrix;
490 glScale 1/3, 1/3;
491 glEnable GL_TEXTURE_2D;
492 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
493
494 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
495 $self->{fow_texture}->draw_quad_alpha (0, 0);
496
497 glDisable GL_TEXTURE_2D;
498 glPopMatrix;
499 }
500
501 if ($self->{magicmap}) {
502 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
503
504 $x += $::MAP->ox + $self->{dx};
505 $y += $::MAP->oy + $self->{dy};
506
507 glTranslate - $x - 1, - $y - 1;
508 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
509 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
510 }
511
512 glPopMatrix;
513 glEndList;
514
515 for my $tile (@$missing) {
516 $tile = $::CONN->{texture}[$tile]
517 or next;
518 next if $tile->{loading};
519 $tile->upload;
520 }
521 }
522 } else {
523 glDeleteList delete $self->{list}
524 if $self->{list};
525 }
526}
527
308sub draw { 528sub draw {
309 my ($self) = @_; 529 my ($self) = @_;
310 530
311 return unless $::MAP; 531 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook });
532
533 return unless $self->{list};
312 534
313 my $focused = $CFPlus::UI::FOCUS == $self 535 my $focused = $CFPlus::UI::FOCUS == $self
314 || $CFPlus::UI::FOCUS == $self->{completer}{entry}; 536 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
315 537
316 return 538 return
317 unless $focused || !$::FAST; 539 unless $focused || !$::FAST;
318
319 if (delete $self->{need_update}) {
320 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
321
322 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
323 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
324
325 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
326 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
327
328 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
329 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
330
331 if ($::CFG->{fow_enable}) {
332 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
333
334 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
335 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
336 glConvolutionFilter2D (
337 GL_CONVOLUTION_2D,
338 GL_ALPHA,
339 3, 3,
340 GL_ALPHA, GL_FLOAT,
341 (pack "f*", @{ $self->{smooth_matrix} }),
342 );
343 glEnable GL_CONVOLUTION_2D;
344 }
345
346 $self->{fow_texture} = new CFPlus::Texture
347 w => $w,
348 h => $h,
349 data => $data,
350 internalformat => GL_ALPHA,
351 format => GL_ALPHA;
352
353 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
354 } else {
355 delete $self->{fow_texture};
356 }
357
358 glNewList $self->{list};
359
360 glPushMatrix;
361 glTranslate $sx0, $sy0;
362 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
363
364 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
365
366 glScale 32, 32;
367
368 if (my $tex = $self->{fow_texture}) {
369 glEnable GL_TEXTURE_2D;
370 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
371
372 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
373 $self->{fow_texture}->draw_quad_alpha (0, 0);
374
375 glDisable GL_TEXTURE_2D;
376 }
377
378 if ($self->{magicmap}) {
379 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
380
381 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1);
382 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1);
383
384 glTranslate - $x - 1, - $y - 1;
385 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
386 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
387 }
388
389 glPopMatrix;
390 glEndList;
391 }
392 540
393 glCallList $self->{list}; 541 glCallList $self->{list};
394 542
395 # TNT2 emulates logops in software (or worse :) 543 # TNT2 emulates logops in software (or worse :)
396 unless ($focused) { 544 unless ($focused) {
415 $self->SUPER::DESTROY; 563 $self->SUPER::DESTROY;
416} 564}
417 565
418package CFPlus::MapWidget::MapMap; 566package CFPlus::MapWidget::MapMap;
419 567
568use strict;
569use utf8;
570
420our @ISA = CFPlus::UI::Base::; 571our @ISA = CFPlus::UI::Base::;
421 572
422use Time::HiRes qw(time); 573use Time::HiRes qw(time);
423use CFPlus::OpenGL; 574use CFPlus::OpenGL;
424 575
425sub size_request { 576sub size_request {
426 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 577 ($::HEIGHT * 0.2, $::HEIGHT * 0.2)
427} 578}
428 579
429sub invoke_size_allocate { 580sub refresh_hook {
430 my ($self, $w, $h) = @_; 581 my ($self) = @_;
431 582
432 $self->update; 583 if ($::MAP && $self->{texture_atime} < time) {
433
434 1
435}
436
437sub update {
438 my ($self) = @_;
439
440 delete $self->{texture_atime};
441 $self->SUPER::update;
442}
443
444sub _draw {
445 my ($self) = @_;
446
447 $::MAP or return;
448
449 my ($w, $h) = @$self{qw(w h)}; 584 my ($w, $h) = @$self{qw(w h)};
450 585
451 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 586 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
452 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 587 my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
453 588
454 my $sx = int $::CFG->{map_shift_x} / 32;
455 my $sy = int $::CFG->{map_shift_y} / 32;
456
457 my $ox = 0.5 * ($w - $sw); 589 my $ox = 0.5 * ($w - $sw);
458 my $oy = 0.5 * ($h - $sh); 590 my $oy = 0.5 * ($h - $sh);
459 591
460 glEnable GL_BLEND; 592 my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize};
461 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 593 my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize};
462 glEnable GL_TEXTURE_2D;
463 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
464 594
465 if ($self->{texture_atime} < time) { 595 #TODO: map scale is completely borked
596
597 my $x0 = int $ox - $sx + 0.5;
598 my $y0 = int $oy - $sy + 0.5;
599
600 $self->{sw} = $sw;
601 $self->{sh} = $sh;
602
603 $self->{x0} = $x0;
604 $self->{y0} = $y0;
605
466 $self->{texture_atime} = time + 1/3; 606 $self->{texture_atime} = time + 1/3;
467 607
468 $self->{texture} = 608 $self->{texture} =
469 new CFPlus::Texture 609 new CFPlus::Texture
470 w => $w, 610 w => $w,
471 h => $h, 611 h => $h,
472 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 612 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
473 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; 613 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
474 } 614 }
615}
616
617sub invoke_visibility_change {
618 my ($self) = @_;
619
620 $self->refresh_hook;
621
622 0
623}
624
625sub invoke_size_allocate {
626 my ($self, $w, $h) = @_;
627
628 $self->update;
629
630 1
631}
632
633sub update {
634 my ($self) = @_;
635
636 delete $self->{texture_atime};
637 $self->SUPER::update;
638}
639
640sub _draw {
641 my ($self) = @_;
642
643 $self->{root}->on_post_alloc (texture => sub { $self->refresh_hook });
644
645 $self->{texture} or return;
646
647 glEnable GL_BLEND;
648 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
649 glEnable GL_TEXTURE_2D;
650 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
475 651
476 $self->{texture}->draw_quad (0, 0); 652 $self->{texture}->draw_quad (0, 0);
477 653
478 glDisable GL_TEXTURE_2D; 654 glDisable GL_TEXTURE_2D;
479 655
480 glTranslate 0.375, 0.375; 656 glTranslate 0.375, 0.375;
481
482 #TODO: map scale is completely borked
483
484 my $x0 = int $ox - $sx + 0.5;
485 my $y0 = int $oy - $sy + 0.5;
486 657
487 glColor 1, 1, 0, 1; 658 glColor 1, 1, 0, 1;
488 glBegin GL_LINE_LOOP; 659 glBegin GL_LINE_LOOP;
489 glVertex $x0 , $y0 ; 660 glVertex $self->{x0} , $self->{y0} ;
490 glVertex $x0 , $y0 + $sh; 661 glVertex $self->{x0} , $self->{y0} + $self->{sh};
491 glVertex $x0 + $sw, $y0 + $sh; 662 glVertex $self->{x0} + $self->{sw}, $self->{y0} + $self->{sh};
492 glVertex $x0 + $sw, $y0 ; 663 glVertex $self->{x0} + $self->{sw}, $self->{y0} ;
493 glEnd; 664 glEnd;
494 665
495 glDisable GL_BLEND; 666 glDisable GL_BLEND;
496} 667}
497 668
533 704
534 if ($ev->{button} == 3) { 705 if ($ev->{button} == 3) {
535 (new CFPlus::UI::Menu 706 (new CFPlus::UI::Menu
536 items => [ 707 items => [
537 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" 708 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key"
538 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] 709 => sub { CFPlus::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }]
539 ], 710 ],
540 )->popup ($ev); 711 )->popup ($ev);
541 return 1; 712 return 1;
542 } 713 }
543 0 714 0
744 915
745 $self->SUPER::_draw; 916 $self->SUPER::_draw;
746} 917}
747 918
7481 9191
920

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines