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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines