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.57 by elmex, Tue Jun 13 11:01:04 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},
57 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
58 65
59 $self->focus_in; 66 $self->focus_in;
60 67
61 if ($ev->{button} == 1) { 68 if ($ev->{button} == 1) {
62 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
63 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
64
65 my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99; 69 my $x = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale});
66 my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99; 70 my $y = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale});
71
72 $x += int 0.5 * ($::MAP->w - $self->{sw} - 1);
73 $y += int 0.5 * ($::MAP->h - $self->{sh} - 1);
67 74
68 $::CONN->send (sprintf "lookat %d %d", $fx, $fy); 75 $x -= int 0.5 * $::MAP->w;
76 $y -= int 0.5 * $::MAP->h;
77
78 $x += 1;
79 $y += 1;
80
81 $::CONN->lookat ($x, $y)
82 if $::CONN;
69 83
70 } elsif ($ev->{button} == 2) { 84 } elsif ($ev->{button} == 2) {
71 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 85 my ($ox, $oy) = ($ev->{x}, $ev->{y});
72 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 86 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
73 87
231 245
232 if (delete $self->{need_update}) { 246 if (delete $self->{need_update}) {
233 glNewList $self->{list}; 247 glNewList $self->{list};
234 248
235 if ($::MAP) { 249 if ($::MAP) {
236 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 250 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
237 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 251 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
238 252
239 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; 253 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale};
240 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; 254 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale};
255 my $sx0 = $self->{sx0} = ($sx & 31) - 32; $sx = $self->{sx} = ($sx - $sx0) / 32;
256 my $sy0 = $self->{sy0} = ($sy & 31) - 32; $sy = $self->{sy} = ($sy - $sy0) / 32;
241 257
242 glPushMatrix; 258 glPushMatrix;
243 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 259 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
244 260
245 glTranslate $sx0 - 32, $sy0 - 32, 0; 261 glTranslate $sx0, $sy0;
246 262
247 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 263 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
248 264
249 if ($::CFG->{fow_enable}) { 265 if ($::CFG->{fow_enable}) {
250 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 266 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
252 glConvolutionFilter2D ( 268 glConvolutionFilter2D (
253 GL_CONVOLUTION_2D, 269 GL_CONVOLUTION_2D,
254 GL_ALPHA, 270 GL_ALPHA,
255 3, 3, 271 3, 3,
256 GL_ALPHA, GL_FLOAT, 272 GL_ALPHA, GL_FLOAT,
257 pack "f*", 273 (pack "f*", @{ $self->{smooth_matrix} }),
258 0.05, 0.13, 0.05,
259 0.13, 0.30, 0.13,
260 0.05, 0.13, 0.05,
261 ); 274 );
262 glEnable GL_CONVOLUTION_2D; 275 glEnable GL_CONVOLUTION_2D;
263 } 276 }
264 277
265 $self->{fow_texture_name} ||= glGenTexture; 278 $self->{fow_texture_name} ||= glGenTexture;
450 463
451 $self->{entry} = new CFClient::UI::Entry 464 $self->{entry} = new CFClient::UI::Entry
452 on_changed => sub { 465 on_changed => sub {
453 $self->update_labels; 466 $self->update_labels;
454 }, 467 },
468 on_button_down => sub {
469 my ($entry, $ev, $x, $y) = @_;
470
471 if ($ev->{button} == 3) {
472 (new CFClient::UI::Menu
473 items => [
474 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }]
475 ],
476 )->popup ($ev);
477 return 1;
478 }
479 0
480 },
455 on_key_down => sub { 481 on_key_down => sub {
456 my ($entry, $ev) = @_; 482 my ($entry, $ev) = @_;
457 483
458 my $self = $entry->{parent}{parent}; 484 my $self = $entry->{parent}{parent};
459 485
460 if ($ev->{sym} == 13) { 486 if ($ev->{sym} == 13) {
461 if (exists $self->{select}) { 487 if (exists $self->{select}) {
462 $self->{last_command} = $self->{select}; 488 $self->{last_command} = $self->{select};
463 $::CONN->user_send ($self->{select}); 489 $::CONN->user_send ($self->{select});
490
491 unshift @{$self->{history}}, $self->{select};
492 $self->{hist_ptr} = 0;
493
464 $self->hide; 494 $self->hide;
465 } 495 }
466 } elsif ($ev->{sym} == 27) { 496 } elsif ($ev->{sym} == 27) {
497 $self->{hist_ptr} = 0;
467 $self->hide; 498 $self->hide;
468 return; 499 return;
469 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 500 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
501 if ($self->{hist_ptr} > 1) {
502 $self->{hist_ptr}--;
503 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
504 } elsif ($self->{hist_ptr} > 0) {
505 $self->{hist_ptr}--;
506 $self->{entry}->set_text ($self->{hist_saveback});
507 } else {
470 ++$self->{select_offset} 508 ++$self->{select_offset}
471 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 509 if $self->{select_offset} < $#{ $self->{last_match} || [] };
510 }
472 $self->update_labels; 511 $self->update_labels;
473 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 512 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
513 if ($self->{select_offset}) {
474 --$self->{select_offset} 514 --$self->{select_offset}
515 } else {
516 unless ($self->{hist_ptr}) {
517 $self->{hist_saveback} = $self->{entry}->get_text;
518 }
519 if ($self->{hist_ptr} <= $#{$self->{history}}) {
475 if $self->{select_offset}; 520 $self->{hist_ptr}++;
521 }
522 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
523 if exists $self->{history}->[$self->{hist_ptr} - 1];
524 }
476 $self->update_labels; 525 $self->update_labels;
477 } else { 526 } else {
478 return 0; 527 return 0;
479 } 528 }
480 529

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines