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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines