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.47 by root, Fri Jun 2 22:13: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},
56sub button_down { 63sub button_down {
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} == 2) { 68 if ($ev->{button} == 1) {
69 my $x = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale});
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);
74
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;
83
84 } elsif ($ev->{button} == 2) {
62 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 85 my ($ox, $oy) = ($ev->{x}, $ev->{y});
63 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 86 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
64 87
65 $self->{motion} = sub { 88 $self->{motion} = sub {
66 my ($ev, $x, $y) = @_; 89 my ($ev, $x, $y) = @_;
222 245
223 if (delete $self->{need_update}) { 246 if (delete $self->{need_update}) {
224 glNewList $self->{list}; 247 glNewList $self->{list};
225 248
226 if ($::MAP) { 249 if ($::MAP) {
227 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 250 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
228 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 251 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
229 252
230 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};
231 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;
232 257
233 glPushMatrix; 258 glPushMatrix;
234 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 259 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
235 260
236 glTranslate $sx0 - 32, $sy0 - 32, 0; 261 glTranslate $sx0, $sy0;
237 262
238 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);
239 264
240 if ($::CFG->{fow_enable}) { 265 if ($::CFG->{fow_enable}) {
241 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
243 glConvolutionFilter2D ( 268 glConvolutionFilter2D (
244 GL_CONVOLUTION_2D, 269 GL_CONVOLUTION_2D,
245 GL_ALPHA, 270 GL_ALPHA,
246 3, 3, 271 3, 3,
247 GL_ALPHA, GL_FLOAT, 272 GL_ALPHA, GL_FLOAT,
248 pack "f*", 273 (pack "f*", @{ $self->{smooth_matrix} }),
249 0.05, 0.13, 0.05,
250 0.13, 0.30, 0.13,
251 0.05, 0.13, 0.05,
252 ); 274 );
253 glEnable GL_CONVOLUTION_2D; 275 glEnable GL_CONVOLUTION_2D;
254 } 276 }
255 277
256 $self->{fow_texture_name} ||= glGenTexture; 278 $self->{fow_texture_name} ||= glGenTexture;
441 463
442 $self->{entry} = new CFClient::UI::Entry 464 $self->{entry} = new CFClient::UI::Entry
443 on_changed => sub { 465 on_changed => sub {
444 $self->update_labels; 466 $self->update_labels;
445 }, 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 },
446 on_key_down => sub { 481 on_key_down => sub {
447 my ($entry, $ev) = @_; 482 my ($entry, $ev) = @_;
448 483
449 my $self = $entry->{parent}{parent}; 484 my $self = $entry->{parent}{parent};
450 485
451 if ($ev->{sym} == 13) { 486 if ($ev->{sym} == 13) {
452 if (exists $self->{select}) { 487 if (exists $self->{select}) {
453 $self->{last_command} = $self->{select}; 488 $self->{last_command} = $self->{select};
454 $::CONN->user_send ($self->{select}); 489 $::CONN->user_send ($self->{select});
490
491 unshift @{$self->{history}}, $self->{select};
492 $self->{hist_ptr} = 0;
493
455 $self->hide; 494 $self->hide;
456 } 495 }
457 } elsif ($ev->{sym} == 27) { 496 } elsif ($ev->{sym} == 27) {
497 $self->{hist_ptr} = 0;
458 $self->hide; 498 $self->hide;
459 return; 499 return;
460 } 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 {
461 ++$self->{select_offset} 508 ++$self->{select_offset}
462 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 509 if $self->{select_offset} < $#{ $self->{last_match} || [] };
510 }
463 $self->update_labels; 511 $self->update_labels;
464 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 512 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
513 if ($self->{select_offset}) {
465 --$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}}) {
466 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 }
467 $self->update_labels; 525 $self->update_labels;
468 } else { 526 } else {
469 return 0; 527 return 0;
470 } 528 }
471 529

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines