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.50 by root, Sat Jun 3 23:47:47 2006 UTC vs.
Revision 1.60 by root, Thu Jun 15 08:29:18 2006 UTC

14 14
15 my $self = $class->SUPER::new ( 15 my $self = $class->SUPER::new (
16 z => -1, 16 z => -1,
17 can_focus => 1, 17 can_focus => 1,
18 list => glGenList, 18 list => glGenList,
19
20 smooth_matrix => [
21 0.05, 0.13, 0.05,
22 0.13, 0.30, 0.13,
23 0.05, 0.13, 0.05,
24 ],
25
19 @_ 26 @_
20 ); 27 );
21 28
22 $self->{completer} = new CFClient::MapWidget::Command:: 29 $self->{completer} = new CFClient::MapWidget::Command::
23 command => $self->{command}, 30 command => $self->{command},
54} 61}
55 62
56sub button_down { 63sub button_down {
57 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
58 65
66 return unless $::CONN;
67
59 $self->focus_in; 68 $self->focus_in;
60 69
61 if ($ev->{button} == 1) { 70 if ($ev->{button} == 1) {
62 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 71 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
63 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 72 my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
64 73
65 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};
66 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};
67 76
68 $::CONN->send (sprintf "lookat %d %d", $fx, $fy); 77 $::CONN->lookat ($x, $y)
78 if $::CONN;
69 79
70 } elsif ($ev->{button} == 2) { 80 } elsif ($ev->{button} == 2) {
71 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 81 my ($ox, $oy) = ($ev->{x}, $ev->{y});
72 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 82 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
73 83
167 $self->{completer}->set_prefix (""); 177 $self->{completer}->set_prefix ("");
168 $self->{completer}->show; 178 $self->{completer}->show;
169 } elsif (exists $DIR{$sym}) { 179 } elsif (exists $DIR{$sym}) {
170 if ($mod & CFClient::KMOD_SHIFT) { 180 if ($mod & CFClient::KMOD_SHIFT) {
171 $self->{shft}++; 181 $self->{shft}++;
182 if ($DIR{$sym}[0] != $self->{fire_dir}) {
172 $::CONN->user_send ("fire $DIR{$sym}[0]"); 183 $::CONN->user_send ("fire $DIR{$sym}[0]");
184 }
185 $self->{fire_dir} = $DIR{$sym}[0];
173 } elsif ($mod & CFClient::KMOD_CTRL) { 186 } elsif ($mod & CFClient::KMOD_CTRL) {
174 $self->{ctrl}++; 187 $self->{ctrl}++;
175 $::CONN->user_send ("run $DIR{$sym}[0]"); 188 $::CONN->user_send ("run $DIR{$sym}[0]");
176 } else { 189 } else {
177 $::CONN->user_send ("$DIR{$sym}[1]"); 190 $::CONN->user_send ("$DIR{$sym}[1]");
205 218
206 my $res = 0; 219 my $res = 0;
207 my $mod = $ev->{mod}; 220 my $mod = $ev->{mod};
208 my $sym = $ev->{sym}; 221 my $sym = $ev->{sym};
209 222
223 if ($::CFG->{shift_fire_stop}) {
210 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 224 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
211 $::CONN->user_send ("fire_stop"); 225 $::CONN->user_send ("fire_stop");
226 delete $self->{fire_dir};
212 $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 }
213 } 239 }
214 240
215 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 241 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
216 $::CONN->user_send ("run_stop"); 242 $::CONN->user_send ("run_stop");
217 $res = 1; 243 $res = 1;
221} 247}
222 248
223sub draw { 249sub draw {
224 my ($self) = @_; 250 my ($self) = @_;
225 251
252 return unless $::MAP;
253
226 my $focused = $CFClient::UI::FOCUS == $self 254 my $focused = $CFClient::UI::FOCUS == $self
227 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 255 || $CFClient::UI::FOCUS == $self->{completer}{entry};
228 256
229 return 257 return
230 unless $focused || !$::FAST; 258 unless $focused || !$::FAST;
231 259
232 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
233 glNewList $self->{list}; 299 glNewList $self->{list};
234 300
235 if ($::MAP) {
236 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
237 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
238
239 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
240 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
241
242 glPushMatrix; 301 glPushMatrix;
302 glTranslate $sx0, $sy0;
243 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 303 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
244 304
245 glTranslate $sx0 - 32, $sy0 - 32, 0; 305 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
246 306
247 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 307 if (my $tex = $self->{fow_texture}) {
248
249 if ($::CFG->{fow_enable}) {
250 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
251 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
252 glConvolutionFilter2D (
253 GL_CONVOLUTION_2D,
254 GL_ALPHA,
255 3, 3,
256 GL_ALPHA, GL_FLOAT,
257 pack "f*",
258 0.05, 0.13, 0.05,
259 0.13, 0.30, 0.13,
260 0.05, 0.13, 0.05,
261 );
262 glEnable GL_CONVOLUTION_2D;
263 }
264
265 $self->{fow_texture_name} ||= glGenTexture;
266 # try to re-use the texture name: TODO improve texture class instead
267
268 $self->{fow_texture} = new CFClient::Texture
269 w => $w,
270 h => $h,
271 data => $data,
272 name => $self->{fow_texture_name},
273 internalformat => GL_ALPHA,
274 format => GL_ALPHA;
275
276 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
277
278 glEnable GL_TEXTURE_2D; 308 glEnable GL_TEXTURE_2D;
279 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 309 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
280 310
311 glScale 32, 32;
281 glColor +($::CFG->{fow_intensity}) x 3, 0.8; 312 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
282 $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); 313 $self->{fow_texture}->draw_quad_alpha (0, 0);
283 314
284 glDisable GL_TEXTURE_2D; 315 glDisable GL_TEXTURE_2D;
285 } 316 }
286 317
287 glPopMatrix; 318 glPopMatrix;
288 }
289 319
290 glEndList; 320 glEndList;
291 } 321 }
292 322
293 glPushMatrix; 323 glPushMatrix;
294 glCallList $self->{list}; 324 glCallList $self->{list};
295 glPopMatrix; 325 glPopMatrix;
296 326
297 # TNT2 emulates logops in software (or worse :) 327 # TNT2 emulates logops in software (or worse :)
298 if ($focused) { 328 unless ($focused) {
299 (delete $self->{out_of_focus})->destroy
300 if $self->{out_of_focus};
301 } else {
302 glColor 0.4, 0.2, 0.2, 0.6; 329 glColor 0.4, 0.2, 0.2, 0.6;
303 glEnable GL_BLEND; 330 glEnable GL_BLEND;
304 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 331 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
305 glBegin GL_QUADS; 332 glBegin GL_QUADS;
306 glVertex 0, 0; 333 glVertex 0, 0;
307 glVertex 0, $::HEIGHT; 334 glVertex 0, $::HEIGHT;
308 glVertex $::WIDTH, $::HEIGHT; 335 glVertex $::WIDTH, $::HEIGHT;
309 glVertex $::WIDTH, 0; 336 glVertex $::WIDTH, 0;
310 glEnd; 337 glEnd;
311 glDisable GL_BLEND; 338 glDisable GL_BLEND;
312
313# $self->{out_of_focus} ||= do {
314# my $label = new CFClient::UI::Label
315# x => 0,
316# y => 0,
317# z => 1,
318# ellipsise => 0,
319# text => "map out of focus (click map to play)";
320#
321# $label->show;
322# $label->update;
323#
324# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
325# $label->move_abs (
326# ($::WIDTH - $label->{w}) * 0.5,
327# ($::HEIGHT - $label->{h}) * 0.5,
328# );
329# });
330#
331# $label
332# };
333 } 339 }
334} 340}
335 341
336sub DESTROY { 342sub DESTROY {
337 my $self = shift; 343 my $self = shift;
450 456
451 $self->{entry} = new CFClient::UI::Entry 457 $self->{entry} = new CFClient::UI::Entry
452 on_changed => sub { 458 on_changed => sub {
453 $self->update_labels; 459 $self->update_labels;
454 }, 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
473 },
455 on_key_down => sub { 474 on_key_down => sub {
456 my ($entry, $ev) = @_; 475 my ($entry, $ev) = @_;
457 476
458 my $self = $entry->{parent}{parent}; 477 my $self = $entry->{parent}{parent};
459 478
460 if ($ev->{sym} == 13) { 479 if ($ev->{sym} == 13) {
461 if (exists $self->{select}) { 480 if (exists $self->{select}) {
462 $self->{last_command} = $self->{select}; 481 $self->{last_command} = $self->{select};
463 $::CONN->user_send ($self->{select}); 482 $::CONN->user_send ($self->{select});
483
484 unshift @{$self->{history}}, $self->{select};
485 $self->{hist_ptr} = 0;
486
464 $self->hide; 487 $self->hide;
465 } 488 }
466 } elsif ($ev->{sym} == 27) { 489 } elsif ($ev->{sym} == 27) {
490 $self->{hist_ptr} = 0;
467 $self->hide; 491 $self->hide;
468 return; 492 return;
469 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 493 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
494 if ($self->{hist_ptr} > 1) {
495 $self->{hist_ptr}--;
496 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
497 } elsif ($self->{hist_ptr} > 0) {
498 $self->{hist_ptr}--;
499 $self->{entry}->set_text ($self->{hist_saveback});
500 } else {
470 ++$self->{select_offset} 501 ++$self->{select_offset}
471 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 502 if $self->{select_offset} < $#{ $self->{last_match} || [] };
503 }
472 $self->update_labels; 504 $self->update_labels;
473 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 505 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
506 if ($self->{select_offset}) {
474 --$self->{select_offset} 507 --$self->{select_offset}
508 } else {
509 unless ($self->{hist_ptr}) {
510 $self->{hist_saveback} = $self->{entry}->get_text;
511 }
512 if ($self->{hist_ptr} <= $#{$self->{history}}) {
475 if $self->{select_offset}; 513 $self->{hist_ptr}++;
514 }
515 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
516 if exists $self->{history}->[$self->{hist_ptr} - 1];
517 }
476 $self->update_labels; 518 $self->update_labels;
477 } else { 519 } else {
478 return 0; 520 return 0;
479 } 521 }
480 522

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines