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.58 by elmex, Tue Jun 13 14:35:17 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 '"') {
150 $self->{completer}->set_prefix (""); 181 $self->{completer}->set_prefix ("");
151 $self->{completer}->show; 182 $self->{completer}->show;
152 } elsif (exists $DIR{$sym}) { 183 } elsif (exists $DIR{$sym}) {
153 if ($mod & CFClient::KMOD_SHIFT) { 184 if ($mod & CFClient::KMOD_SHIFT) {
154 $self->{shft}++; 185 $self->{shft}++;
186 if ($DIR{$sym}[0] != $self->{fire_dir}) {
155 $::CONN->user_send ("fire $DIR{$sym}[0]"); 187 $::CONN->user_send ("fire $DIR{$sym}[0]");
188 }
189 $self->{fire_dir} = $DIR{$sym}[0];
156 } elsif ($mod & CFClient::KMOD_CTRL) { 190 } elsif ($mod & CFClient::KMOD_CTRL) {
157 $self->{ctrl}++; 191 $self->{ctrl}++;
158 $::CONN->user_send ("run $DIR{$sym}[0]"); 192 $::CONN->user_send ("run $DIR{$sym}[0]");
159 } else { 193 } else {
160 $::CONN->user_send ("$DIR{$sym}[1]"); 194 $::CONN->user_send ("$DIR{$sym}[1]");
161 } 195 }
162 } elsif ($ev->{unicode}) { 196 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
197 $::BIND_EDITOR->set_binding (undef, undef, [],
198 sub {
199 my ($mod, $sym, $cmds) = @_;
200 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
201 });
202 $::BIND_EDITOR->start;
203 $::BIND_EDITOR->show;
204 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
205 $::BIND_EDITOR->stop;
206 $::BIND_EDITOR->ask_for_bind_and_commit;
207 $::BIND_EDITOR->hide;
208 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
209 $::CONN->user_send ($_) for @$bind_cmd;
210 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
163 $self->{completer}->key_down ($ev); 211 $self->{completer}->key_down ($ev);
164 $self->{completer}->show; 212 $self->{completer}->show;
213 } else {
214 return 0;
215 }
216
165 } 217 1
166} 218}
167 219
168sub key_up { 220sub key_up {
169 my ($self, $ev) = @_; 221 my ($self, $ev) = @_;
170 222
223 my $res = 0;
171 my $mod = $ev->{mod}; 224 my $mod = $ev->{mod};
172 my $sym = $ev->{sym}; 225 my $sym = $ev->{sym};
173 226
227 if ($::CFG->{shift_fire_stop}) {
174 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 228 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
175 $::CONN->user_send ("fire_stop"); 229 $::CONN->user_send ("fire_stop");
230 delete $self->{fire_dir};
231 $res = 1;
232 }
233 } else {
234 if (exists $DIR{$sym} && delete $self->{shft}) {
235 $::CONN->user_send ("fire_stop");
236 delete $self->{fire_dir};
237 $res = 1;
238 } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
239 $::CONN->user_send ("fire_stop");
240 delete $self->{fire_dir};
241 $res = 1;
242 }
176 } 243 }
244
177 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 245 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
178 $::CONN->user_send ("run_stop"); 246 $::CONN->user_send ("run_stop");
247 $res = 1;
179 } 248 }
249
250 $res
180} 251}
181 252
182sub draw { 253sub draw {
183 my ($self) = @_; 254 my ($self) = @_;
184 255
190 261
191 if (delete $self->{need_update}) { 262 if (delete $self->{need_update}) {
192 glNewList $self->{list}; 263 glNewList $self->{list};
193 264
194 if ($::MAP) { 265 if ($::MAP) {
195 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 266 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
196 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 267 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
197 268
198 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; 269 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; 270 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale};
271 my $sx0 = $self->{sx0} = ($sx & 31) - 32; $sx = $self->{sx} = ($sx - $sx0) / 32;
272 my $sy0 = $self->{sy0} = ($sy & 31) - 32; $sy = $self->{sy} = ($sy - $sy0) / 32;
200 273
201 glPushMatrix; 274 glPushMatrix;
202 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 275 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
203 276
204 glTranslate $sx0 - 32, $sy0 - 32, 0; 277 glTranslate $sx0, $sy0;
205 278
206 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 279 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
207 280
208 if ($::CFG->{fow_enable}) { 281 if ($::CFG->{fow_enable}) {
209 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war 282 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); 283 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
211 glConvolutionFilter2D ( 284 glConvolutionFilter2D (
212 GL_CONVOLUTION_2D, 285 GL_CONVOLUTION_2D,
213 GL_ALPHA, 286 GL_ALPHA,
214 3, 3, 287 3, 3,
215 GL_ALPHA, GL_FLOAT, 288 GL_ALPHA, GL_FLOAT,
216 pack "f*", 289 (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 ); 290 );
221 glEnable GL_CONVOLUTION_2D; 291 glEnable GL_CONVOLUTION_2D;
222 } 292 }
223 293
224 $self->{fow_texture_name} ||= glGenTexture; 294 $self->{fow_texture_name} ||= glGenTexture;
267 glVertex $::WIDTH, $::HEIGHT; 337 glVertex $::WIDTH, $::HEIGHT;
268 glVertex $::WIDTH, 0; 338 glVertex $::WIDTH, 0;
269 glEnd; 339 glEnd;
270 glDisable GL_BLEND; 340 glDisable GL_BLEND;
271 341
272 $self->{out_of_focus} ||= do { 342# $self->{out_of_focus} ||= do {
273 my $label = new CFClient::UI::Label 343# my $label = new CFClient::UI::Label
274 x => 0, 344# x => 0,
275 y => 0, 345# y => 0,
276 z => 1, 346# z => 1,
277 ellipsise => 0, 347# ellipsise => 0,
278 text => "map out of focus (click map to play)"; 348# text => "map out of focus (click map to play)";
279 349#
280 $label->show; 350# $label->show;
281 $label->update; 351# $label->update;
282 352#
283 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 353# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
284 $label->move ( 354# $label->move_abs (
285 ($::WIDTH - $label->{w}) * 0.5, 355# ($::WIDTH - $label->{w}) * 0.5,
286 ($::HEIGHT - $label->{h}) * 0.5, 356# ($::HEIGHT - $label->{h}) * 0.5,
287 ); 357# );
288 }); 358# });
289 359#
290 $label 360# $label
291 }; 361# };
292 } 362 }
293} 363}
294 364
295sub DESTROY { 365sub DESTROY {
296 my $self = shift; 366 my $self = shift;
406 fontsize => $_, 476 fontsize => $_,
407 ), (0.8) x 16 477 ), (0.8) x 16
408 ]; 478 ];
409 479
410 $self->{entry} = new CFClient::UI::Entry 480 $self->{entry} = new CFClient::UI::Entry
411 connect_changed => sub { 481 on_changed => sub {
412 $self->update_labels; 482 $self->update_labels;
413 }, 483 },
484 on_button_down => sub {
485 my ($entry, $ev, $x, $y) = @_;
486
487 if ($ev->{button} == 3) {
488 (new CFClient::UI::Menu
489 items => [
490 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }]
491 ],
492 )->popup ($ev);
493 return 1;
494 }
495 0
496 },
414 connect_key_down => sub { 497 on_key_down => sub {
415 my ($entry, $ev) = @_; 498 my ($entry, $ev) = @_;
416 499
417 my $self = $entry->{parent}{parent}; 500 my $self = $entry->{parent}{parent};
418 501
419 if ($ev->{sym} == 13) { 502 if ($ev->{sym} == 13) {
420 if (exists $self->{select}) { 503 if (exists $self->{select}) {
421 $self->{last_command} = $self->{select}; 504 $self->{last_command} = $self->{select};
422 $::CONN->user_send ($self->{select}); 505 $::CONN->user_send ($self->{select});
506
507 unshift @{$self->{history}}, $self->{select};
508 $self->{hist_ptr} = 0;
509
423 $self->hide; 510 $self->hide;
424 } 511 }
425 } elsif ($ev->{sym} == 27) { 512 } elsif ($ev->{sym} == 27) {
513 $self->{hist_ptr} = 0;
426 $self->hide; 514 $self->hide;
427 return; 515 return;
428 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 516 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
517 if ($self->{hist_ptr} > 1) {
518 $self->{hist_ptr}--;
519 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
520 } elsif ($self->{hist_ptr} > 0) {
521 $self->{hist_ptr}--;
522 $self->{entry}->set_text ($self->{hist_saveback});
523 } else {
429 ++$self->{select_offset} 524 ++$self->{select_offset}
430 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 525 if $self->{select_offset} < $#{ $self->{last_match} || [] };
526 }
431 $self->update_labels; 527 $self->update_labels;
432 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 528 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
529 if ($self->{select_offset}) {
433 --$self->{select_offset} 530 --$self->{select_offset}
531 } else {
532 unless ($self->{hist_ptr}) {
533 $self->{hist_saveback} = $self->{entry}->get_text;
534 }
535 if ($self->{hist_ptr} <= $#{$self->{history}}) {
434 if $self->{select_offset}; 536 $self->{hist_ptr}++;
537 }
538 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
539 if exists $self->{history}->[$self->{hist_ptr} - 1];
540 }
435 $self->update_labels; 541 $self->update_labels;
436 } else { 542 } else {
437 return 0; 543 return 0;
438 } 544 }
439 545
458 564
459sub size_allocate { 565sub size_allocate {
460 my ($self, $w, $h) = @_; 566 my ($self, $w, $h) = @_;
461 567
462 $self->SUPER::size_allocate ($w, $h); 568 $self->SUPER::size_allocate ($w, $h);
463 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 569 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
464} 570}
465 571
466sub show { 572sub show {
467 my ($self) = @_; 573 my ($self) = @_;
468 574
478} 584}
479 585
480sub key_down { 586sub key_down {
481 my ($self, $ev) = @_; 587 my ($self, $ev) = @_;
482 588
483 $self->{entry}->key_down ($ev); 589 $self->{entry}->key_down ($ev)
484} 590}
485 591
486sub update_labels { 592sub update_labels {
487 my ($self) = @_; 593 my ($self) = @_;
488 594
521 627
522 @match = map $self->{command}{$_->[0]}, 628 @match = map $self->{command}{$_->[0]},
523 sort { 629 sort {
524 $a->[1] <=> $b->[1] 630 $a->[1] <=> $b->[1]
525 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 631 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
526 or (length $a->[0]) <=> (length $b->[0]) 632 or (length $b->[0]) <=> (length $a->[0])
527 } @match; 633 } @match;
528 } 634 }
529 635
530 $self->{last_search} = $cmd; 636 $self->{last_search} = $text;
531 $self->{last_match} = \@match; 637 $self->{last_match} = \@match;
532 638
533 $self->{select_offset} = 0; 639 $self->{select_offset} = 0;
534 } 640 }
535 641

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines