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.52 by elmex, Thu Jun 8 18:18:16 2006 UTC vs.
Revision 1.60 by root, Thu Jun 15 08:29:18 2006 UTC

61} 61}
62 62
63sub button_down { 63sub button_down {
64 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
65 65
66 return unless $::CONN;
67
66 $self->focus_in; 68 $self->focus_in;
67 69
68 if ($ev->{button} == 1) { 70 if ($ev->{button} == 1) {
69 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 71 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
70 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 72 my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
71 73
72 my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99; 74 $x -= int 0.5 * $self->{sw};
73 my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99; 75 $y -= int 0.5 * $self->{sh};
74 76
75 $::CONN->send (sprintf "lookat %d %d", $fx, $fy); 77 $::CONN->lookat ($x, $y)
78 if $::CONN;
76 79
77 } elsif ($ev->{button} == 2) { 80 } elsif ($ev->{button} == 2) {
78 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 81 my ($ox, $oy) = ($ev->{x}, $ev->{y});
79 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 82 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
80 83
174 $self->{completer}->set_prefix (""); 177 $self->{completer}->set_prefix ("");
175 $self->{completer}->show; 178 $self->{completer}->show;
176 } elsif (exists $DIR{$sym}) { 179 } elsif (exists $DIR{$sym}) {
177 if ($mod & CFClient::KMOD_SHIFT) { 180 if ($mod & CFClient::KMOD_SHIFT) {
178 $self->{shft}++; 181 $self->{shft}++;
182 if ($DIR{$sym}[0] != $self->{fire_dir}) {
179 $::CONN->user_send ("fire $DIR{$sym}[0]"); 183 $::CONN->user_send ("fire $DIR{$sym}[0]");
184 }
185 $self->{fire_dir} = $DIR{$sym}[0];
180 } elsif ($mod & CFClient::KMOD_CTRL) { 186 } elsif ($mod & CFClient::KMOD_CTRL) {
181 $self->{ctrl}++; 187 $self->{ctrl}++;
182 $::CONN->user_send ("run $DIR{$sym}[0]"); 188 $::CONN->user_send ("run $DIR{$sym}[0]");
183 } else { 189 } else {
184 $::CONN->user_send ("$DIR{$sym}[1]"); 190 $::CONN->user_send ("$DIR{$sym}[1]");
212 218
213 my $res = 0; 219 my $res = 0;
214 my $mod = $ev->{mod}; 220 my $mod = $ev->{mod};
215 my $sym = $ev->{sym}; 221 my $sym = $ev->{sym};
216 222
223 if ($::CFG->{shift_fire_stop}) {
217 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 224 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
218 $::CONN->user_send ("fire_stop"); 225 $::CONN->user_send ("fire_stop");
226 delete $self->{fire_dir};
219 $res = 1; 227 $res = 1;
228 }
229 } else {
230 if (exists $DIR{$sym} && delete $self->{shft}) {
231 $::CONN->user_send ("fire_stop");
232 delete $self->{fire_dir};
233 $res = 1;
234 } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
235 $::CONN->user_send ("fire_stop");
236 delete $self->{fire_dir};
237 $res = 1;
238 }
220 } 239 }
221 240
222 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 241 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
223 $::CONN->user_send ("run_stop"); 242 $::CONN->user_send ("run_stop");
224 $res = 1; 243 $res = 1;
228} 247}
229 248
230sub draw { 249sub draw {
231 my ($self) = @_; 250 my ($self) = @_;
232 251
252 return unless $::MAP;
253
233 my $focused = $CFClient::UI::FOCUS == $self 254 my $focused = $CFClient::UI::FOCUS == $self
234 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 255 || $CFClient::UI::FOCUS == $self->{completer}{entry};
235 256
236 return 257 return
237 unless $focused || !$::FAST; 258 unless $focused || !$::FAST;
238 259
239 if (delete $self->{need_update}) { 260 if (delete $self->{need_update}) {
261 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
262
263 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize;
264 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize;
265
266 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
267 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
268
269 my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize;
270 my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize;
271
272 if ($::CFG->{fow_enable}) {
273 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
274
275 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
276 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
277 glConvolutionFilter2D (
278 GL_CONVOLUTION_2D,
279 GL_ALPHA,
280 3, 3,
281 GL_ALPHA, GL_FLOAT,
282 (pack "f*", @{ $self->{smooth_matrix} }),
283 );
284 glEnable GL_CONVOLUTION_2D;
285 }
286
287 $self->{fow_texture} = new CFClient::Texture
288 w => $w,
289 h => $h,
290 data => $data,
291 internalformat => GL_ALPHA,
292 format => GL_ALPHA;
293
294 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
295 } else {
296 delete $self->{fow_texture};
297 }
298
240 glNewList $self->{list}; 299 glNewList $self->{list};
241 300
242 if ($::MAP) {
243 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
244 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
245
246 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
247 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
248
249 glPushMatrix; 301 glPushMatrix;
302 glTranslate $sx0, $sy0;
250 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 303 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
251 304
252 glTranslate $sx0 - 32, $sy0 - 32, 0; 305 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
253 306
254 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 307 if (my $tex = $self->{fow_texture}) {
255
256 if ($::CFG->{fow_enable}) {
257 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
258 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
259 glConvolutionFilter2D (
260 GL_CONVOLUTION_2D,
261 GL_ALPHA,
262 3, 3,
263 GL_ALPHA, GL_FLOAT,
264 (pack "f*", @{ $self->{smooth_matrix} }),
265 );
266 glEnable GL_CONVOLUTION_2D;
267 }
268
269 $self->{fow_texture_name} ||= glGenTexture;
270 # try to re-use the texture name: TODO improve texture class instead
271
272 $self->{fow_texture} = new CFClient::Texture
273 w => $w,
274 h => $h,
275 data => $data,
276 name => $self->{fow_texture_name},
277 internalformat => GL_ALPHA,
278 format => GL_ALPHA;
279
280 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
281
282 glEnable GL_TEXTURE_2D; 308 glEnable GL_TEXTURE_2D;
283 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 309 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
284 310
311 glScale 32, 32;
285 glColor +($::CFG->{fow_intensity}) x 3, 0.8; 312 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
286 $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); 313 $self->{fow_texture}->draw_quad_alpha (0, 0);
287 314
288 glDisable GL_TEXTURE_2D; 315 glDisable GL_TEXTURE_2D;
289 } 316 }
290 317
291 glPopMatrix; 318 glPopMatrix;
292 }
293 319
294 glEndList; 320 glEndList;
295 } 321 }
296 322
297 glPushMatrix; 323 glPushMatrix;
298 glCallList $self->{list}; 324 glCallList $self->{list};
299 glPopMatrix; 325 glPopMatrix;
300 326
301 # TNT2 emulates logops in software (or worse :) 327 # TNT2 emulates logops in software (or worse :)
302 if ($focused) { 328 unless ($focused) {
303 (delete $self->{out_of_focus})->destroy
304 if $self->{out_of_focus};
305 } else {
306 glColor 0.4, 0.2, 0.2, 0.6; 329 glColor 0.4, 0.2, 0.2, 0.6;
307 glEnable GL_BLEND; 330 glEnable GL_BLEND;
308 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 331 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
309 glBegin GL_QUADS; 332 glBegin GL_QUADS;
310 glVertex 0, 0; 333 glVertex 0, 0;
311 glVertex 0, $::HEIGHT; 334 glVertex 0, $::HEIGHT;
312 glVertex $::WIDTH, $::HEIGHT; 335 glVertex $::WIDTH, $::HEIGHT;
313 glVertex $::WIDTH, 0; 336 glVertex $::WIDTH, 0;
314 glEnd; 337 glEnd;
315 glDisable GL_BLEND; 338 glDisable GL_BLEND;
316
317# $self->{out_of_focus} ||= do {
318# my $label = new CFClient::UI::Label
319# x => 0,
320# y => 0,
321# z => 1,
322# ellipsise => 0,
323# text => "map out of focus (click map to play)";
324#
325# $label->show;
326# $label->update;
327#
328# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
329# $label->move_abs (
330# ($::WIDTH - $label->{w}) * 0.5,
331# ($::HEIGHT - $label->{h}) * 0.5,
332# );
333# });
334#
335# $label
336# };
337 } 339 }
338} 340}
339 341
340sub DESTROY { 342sub DESTROY {
341 my $self = shift; 343 my $self = shift;
453 ]; 455 ];
454 456
455 $self->{entry} = new CFClient::UI::Entry 457 $self->{entry} = new CFClient::UI::Entry
456 on_changed => sub { 458 on_changed => sub {
457 $self->update_labels; 459 $self->update_labels;
460 },
461 on_button_down => sub {
462 my ($entry, $ev, $x, $y) = @_;
463
464 if ($ev->{button} == 3) {
465 (new CFClient::UI::Menu
466 items => [
467 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }]
468 ],
469 )->popup ($ev);
470 return 1;
471 }
472 0
458 }, 473 },
459 on_key_down => sub { 474 on_key_down => sub {
460 my ($entry, $ev) = @_; 475 my ($entry, $ev) = @_;
461 476
462 my $self = $entry->{parent}{parent}; 477 my $self = $entry->{parent}{parent};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines