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.37 by root, Thu May 25 01:26:53 2006 UTC vs.
Revision 1.56 by root, Mon Jun 12 13:26:14 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},
39 my ($self, $command, $tooltip, $widget, $cb) = @_; 46 my ($self, $command, $tooltip, $widget, $cb) = @_;
40 47
41 (my $data = $command) =~ s/\\//g; 48 (my $data = $command) =~ s/\\//g;
42 49
43 $tooltip =~ s/^\s+//; 50 $tooltip =~ s/^\s+//;
44
45 $tooltip = "<big>$data</big>\n\n$tooltip"; 51 $tooltip = "<big>$data</big>\n\n$tooltip";
46
47 $tooltip =~ s/\s+$//; 52 $tooltip =~ s/\s+$//;
48 53
49 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; 54 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
50} 55}
51 56
58sub button_down { 63sub button_down {
59 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
60 65
61 $self->focus_in; 66 $self->focus_in;
62 67
63 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) {
64 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 85 my ($ox, $oy) = ($ev->{x}, $ev->{y});
65 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 86 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
66 87
67 $self->{motion} = sub { 88 $self->{motion} = sub {
68 my ($ev, $x, $y) = @_; 89 my ($ev, $x, $y) = @_;
73 $::CFG->{map_shift_y} = $bh + $y - $oy; 94 $::CFG->{map_shift_y} = $bh + $y - $oy;
74 95
75 $self->update; 96 $self->update;
76 }; 97 };
77 } 98 }
99
100 1
78} 101}
79 102
80sub button_up { 103sub button_up {
81 my ($self, $ev, $x, $y) = @_; 104 my ($self, $ev, $x, $y) = @_;
82 105
83 delete $self->{motion}; 106 delete $self->{motion};
107
108 1
84} 109}
85 110
86sub mouse_motion { 111sub mouse_motion {
87 my ($self, $ev, $x, $y) = @_; 112 my ($self, $ev, $x, $y) = @_;
88 113
114 if ($self->{motion}) {
89 $self->{motion}->($ev, $x, $y) if $self->{motion}; 115 $self->{motion}->($ev, $x, $y);
116 } else {
117 return 0;
118 }
119
120 1
90} 121}
91 122
92sub size_request { 123sub size_request {
93 ( 124 (
94 1 + 32 * int $::WIDTH / 32, 125 1 + 32 * int $::WIDTH / 32,
120); 151);
121 152
122sub key_down { 153sub key_down {
123 my ($self, $ev) = @_; 154 my ($self, $ev) = @_;
124 155
125 return unless $::CONN; 156 return 0 unless $::CONN;
126 157
127 my $mod = $ev->{mod}; 158 my $mod = $ev->{mod};
128 my $sym = $ev->{sym}; 159 my $sym = $ev->{sym};
129 my $uni = $ev->{unicode}; 160 my $uni = $ev->{unicode};
130 161
136 $::CONN->user_send ("apply"); 167 $::CONN->user_send ("apply");
137 } elsif ($uni == ord ".") { 168 } elsif ($uni == ord ".") {
138 $::CONN->user_send ($self->{completer}{last_command}) 169 $::CONN->user_send ($self->{completer}{last_command})
139 if exists $self->{completer}{last_command}; 170 if exists $self->{completer}{last_command};
140 } elsif ($uni == ord "\t") { 171 } elsif ($uni == ord "\t") {
141 # TODO: toggle inventory 172 $::INV_WINDOW->toggle_visibility;
142 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 173 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
143 $::CONN->user_send ("rotateshoottype +"); 174 $::CONN->user_send ("rotateshoottype +");
144 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 175 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
145 $::CONN->user_send ("rotateshoottype -"); 176 $::CONN->user_send ("rotateshoottype -");
146 } elsif ($uni == ord '"') { 177 } elsif ($uni == ord '"') {
157 $self->{ctrl}++; 188 $self->{ctrl}++;
158 $::CONN->user_send ("run $DIR{$sym}[0]"); 189 $::CONN->user_send ("run $DIR{$sym}[0]");
159 } else { 190 } else {
160 $::CONN->user_send ("$DIR{$sym}[1]"); 191 $::CONN->user_send ("$DIR{$sym}[1]");
161 } 192 }
162 } elsif ($ev->{unicode}) { 193 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
194 $::BIND_EDITOR->set_binding (undef, undef, [],
195 sub {
196 my ($mod, $sym, $cmds) = @_;
197 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
198 });
199 $::BIND_EDITOR->start;
200 $::BIND_EDITOR->show;
201 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
202 $::BIND_EDITOR->stop;
203 $::BIND_EDITOR->ask_for_bind_and_commit;
204 $::BIND_EDITOR->hide;
205 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
206 $::CONN->user_send ($_) for @$bind_cmd;
207 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
163 $self->{completer}->key_down ($ev); 208 $self->{completer}->key_down ($ev);
164 $self->{completer}->show; 209 $self->{completer}->show;
210 } else {
211 return 0;
212 }
213
165 } 214 1
166} 215}
167 216
168sub key_up { 217sub key_up {
169 my ($self, $ev) = @_; 218 my ($self, $ev) = @_;
170 219
220 my $res = 0;
171 my $mod = $ev->{mod}; 221 my $mod = $ev->{mod};
172 my $sym = $ev->{sym}; 222 my $sym = $ev->{sym};
173 223
174 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 224 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
175 $::CONN->user_send ("fire_stop"); 225 $::CONN->user_send ("fire_stop");
226 $res = 1;
176 } 227 }
228
177 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 229 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
178 $::CONN->user_send ("run_stop"); 230 $::CONN->user_send ("run_stop");
231 $res = 1;
179 } 232 }
233
234 $res
180} 235}
181 236
182sub draw { 237sub draw {
183 my ($self) = @_; 238 my ($self) = @_;
184 239
190 245
191 if (delete $self->{need_update}) { 246 if (delete $self->{need_update}) {
192 glNewList $self->{list}; 247 glNewList $self->{list};
193 248
194 if ($::MAP) { 249 if ($::MAP) {
195 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 250 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
196 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 251 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
197 252
198 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};
199 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;
200 257
201 glPushMatrix; 258 glPushMatrix;
202 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 259 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
203 260
204 glTranslate $sx0 - 32, $sy0 - 32, 0; 261 glTranslate $sx0, $sy0;
205 262
206 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);
207 264
208 if ($::CFG->{fow_enable}) { 265 if ($::CFG->{fow_enable}) {
209 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war 266 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
210 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 267 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
211 glConvolutionFilter2D ( 268 glConvolutionFilter2D (
212 GL_CONVOLUTION_2D, 269 GL_CONVOLUTION_2D,
213 GL_ALPHA, 270 GL_ALPHA,
214 3, 3, 271 3, 3,
215 GL_ALPHA, GL_FLOAT, 272 GL_ALPHA, GL_FLOAT,
216 pack "f*", 273 (pack "f*", @{ $self->{smooth_matrix} }),
217 0.05, 0.13, 0.05,
218 0.13, 0.30, 0.13,
219 0.05, 0.13, 0.05,
220 ); 274 );
221 glEnable GL_CONVOLUTION_2D; 275 glEnable GL_CONVOLUTION_2D;
222 } 276 }
223 277
224 $self->{fow_texture_name} ||= glGenTexture; 278 $self->{fow_texture_name} ||= glGenTexture;
267 glVertex $::WIDTH, $::HEIGHT; 321 glVertex $::WIDTH, $::HEIGHT;
268 glVertex $::WIDTH, 0; 322 glVertex $::WIDTH, 0;
269 glEnd; 323 glEnd;
270 glDisable GL_BLEND; 324 glDisable GL_BLEND;
271 325
272 $self->{out_of_focus} ||= do { 326# $self->{out_of_focus} ||= do {
273 my $label = new CFClient::UI::Label 327# my $label = new CFClient::UI::Label
274 x => 0, 328# x => 0,
275 y => 0, 329# y => 0,
276 z => 1, 330# z => 1,
277 ellipsise => 0, 331# ellipsise => 0,
278 text => "map out of focus (click map to play)"; 332# text => "map out of focus (click map to play)";
279 333#
280 $label->show; 334# $label->show;
281 $label->update; 335# $label->update;
282 336#
283 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 337# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
284 $label->move ( 338# $label->move_abs (
285 ($::WIDTH - $label->{w}) * 0.5, 339# ($::WIDTH - $label->{w}) * 0.5,
286 ($::HEIGHT - $label->{h}) * 0.5, 340# ($::HEIGHT - $label->{h}) * 0.5,
287 ); 341# );
288 }); 342# });
289 343#
290 $label 344# $label
291 }; 345# };
292 } 346 }
293} 347}
294 348
295sub DESTROY { 349sub DESTROY {
296 my $self = shift; 350 my $self = shift;
406 fontsize => $_, 460 fontsize => $_,
407 ), (0.8) x 16 461 ), (0.8) x 16
408 ]; 462 ];
409 463
410 $self->{entry} = new CFClient::UI::Entry 464 $self->{entry} = new CFClient::UI::Entry
411 connect_changed => sub { 465 on_changed => sub {
412 $self->update_labels; 466 $self->update_labels;
413 }, 467 },
414 connect_key_down => sub { 468 on_key_down => sub {
415 my ($entry, $ev) = @_; 469 my ($entry, $ev) = @_;
416 470
417 my $self = $entry->{parent}{parent}; 471 my $self = $entry->{parent}{parent};
418 472
419 if ($ev->{sym} == 13) { 473 if ($ev->{sym} == 13) {
420 if (exists $self->{select}) { 474 if (exists $self->{select}) {
421 $self->{last_command} = $self->{select}; 475 $self->{last_command} = $self->{select};
422 $::CONN->user_send ($self->{select}); 476 $::CONN->user_send ($self->{select});
477
478 unshift @{$self->{history}}, $self->{select};
479 $self->{hist_ptr} = 0;
480
423 $self->hide; 481 $self->hide;
424 } 482 }
425 } elsif ($ev->{sym} == 27) { 483 } elsif ($ev->{sym} == 27) {
484 $self->{hist_ptr} = 0;
426 $self->hide; 485 $self->hide;
427 return; 486 return;
428 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 487 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
488 if ($self->{hist_ptr} > 1) {
489 $self->{hist_ptr}--;
490 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
491 } elsif ($self->{hist_ptr} > 0) {
492 $self->{hist_ptr}--;
493 $self->{entry}->set_text ($self->{hist_saveback});
494 } else {
429 ++$self->{select_offset} 495 ++$self->{select_offset}
430 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 496 if $self->{select_offset} < $#{ $self->{last_match} || [] };
497 }
431 $self->update_labels; 498 $self->update_labels;
432 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 499 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
500 if ($self->{select_offset}) {
433 --$self->{select_offset} 501 --$self->{select_offset}
502 } else {
503 unless ($self->{hist_ptr}) {
504 $self->{hist_saveback} = $self->{entry}->get_text;
505 }
506 if ($self->{hist_ptr} <= $#{$self->{history}}) {
434 if $self->{select_offset}; 507 $self->{hist_ptr}++;
508 }
509 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
510 if exists $self->{history}->[$self->{hist_ptr} - 1];
511 }
435 $self->update_labels; 512 $self->update_labels;
436 } else { 513 } else {
437 return 0; 514 return 0;
438 } 515 }
439 516
458 535
459sub size_allocate { 536sub size_allocate {
460 my ($self, $w, $h) = @_; 537 my ($self, $w, $h) = @_;
461 538
462 $self->SUPER::size_allocate ($w, $h); 539 $self->SUPER::size_allocate ($w, $h);
463 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 540 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
464} 541}
465 542
466sub show { 543sub show {
467 my ($self) = @_; 544 my ($self) = @_;
468 545
478} 555}
479 556
480sub key_down { 557sub key_down {
481 my ($self, $ev) = @_; 558 my ($self, $ev) = @_;
482 559
483 $self->{entry}->key_down ($ev); 560 $self->{entry}->key_down ($ev)
484} 561}
485 562
486sub update_labels { 563sub update_labels {
487 my ($self) = @_; 564 my ($self) = @_;
488 565
521 598
522 @match = map $self->{command}{$_->[0]}, 599 @match = map $self->{command}{$_->[0]},
523 sort { 600 sort {
524 $a->[1] <=> $b->[1] 601 $a->[1] <=> $b->[1]
525 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 602 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
526 or (length $a->[0]) <=> (length $b->[0]) 603 or (length $b->[0]) <=> (length $a->[0])
527 } @match; 604 } @match;
528 } 605 }
529 606
530 $self->{last_search} = $cmd; 607 $self->{last_search} = $text;
531 $self->{last_match} = \@match; 608 $self->{last_match} = \@match;
532 609
533 $self->{select_offset} = 0; 610 $self->{select_offset} = 0;
534 } 611 }
535 612

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines