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.36 by root, Thu May 25 00:26:19 2006 UTC vs.
Revision 1.53 by root, Sun Jun 11 17:30:53 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},
24 can_focus => 1, 31 can_focus => 1,
32 tooltip => "<b>The Command Completer</b>\n\n"
33 . "This is your central interface to send text commands to the server. "
34 . "To enter a verbatim command to send to the server, just type the command, "
35 . "followed by a space, and press return. "
36 . "Typing the initial letters of words (or just any letters) displays guesses "
37 . "for commands you might want to use.\n"
38 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n"
39 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.",
25 ; 40 ;
26 41
27 $self 42 $self
28} 43}
29 44
31 my ($self, $command, $tooltip, $widget, $cb) = @_; 46 my ($self, $command, $tooltip, $widget, $cb) = @_;
32 47
33 (my $data = $command) =~ s/\\//g; 48 (my $data = $command) =~ s/\\//g;
34 49
35 $tooltip =~ s/^\s+//; 50 $tooltip =~ s/^\s+//;
36
37 $tooltip = "<big>$data</big>\n\n$tooltip"; 51 $tooltip = "<big>$data</big>\n\n$tooltip";
38
39 $tooltip =~ s/\s+$//; 52 $tooltip =~ s/\s+$//;
40 53
41 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; 54 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
42} 55}
43 56
50sub button_down { 63sub button_down {
51 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
52 65
53 $self->focus_in; 66 $self->focus_in;
54 67
55 if ($ev->{button} == 2) { 68 if ($ev->{button} == 1) {
69 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
70 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
71
72 my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99;
73 my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99;
74
75 $::CONN->send (sprintf "lookat %d %d", $fx, $fy)
76 if $::CONN;
77
78 } elsif ($ev->{button} == 2) {
56 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 79 my ($ox, $oy) = ($ev->{x}, $ev->{y});
57 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 80 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
58 81
59 $self->{motion} = sub { 82 $self->{motion} = sub {
60 my ($ev, $x, $y) = @_; 83 my ($ev, $x, $y) = @_;
65 $::CFG->{map_shift_y} = $bh + $y - $oy; 88 $::CFG->{map_shift_y} = $bh + $y - $oy;
66 89
67 $self->update; 90 $self->update;
68 }; 91 };
69 } 92 }
93
94 1
70} 95}
71 96
72sub button_up { 97sub button_up {
73 my ($self, $ev, $x, $y) = @_; 98 my ($self, $ev, $x, $y) = @_;
74 99
75 delete $self->{motion}; 100 delete $self->{motion};
101
102 1
76} 103}
77 104
78sub mouse_motion { 105sub mouse_motion {
79 my ($self, $ev, $x, $y) = @_; 106 my ($self, $ev, $x, $y) = @_;
80 107
108 if ($self->{motion}) {
81 $self->{motion}->($ev, $x, $y) if $self->{motion}; 109 $self->{motion}->($ev, $x, $y);
110 } else {
111 return 0;
112 }
113
114 1
82} 115}
83 116
84sub size_request { 117sub size_request {
85 ( 118 (
86 1 + 32 * int $::WIDTH / 32, 119 1 + 32 * int $::WIDTH / 32,
112); 145);
113 146
114sub key_down { 147sub key_down {
115 my ($self, $ev) = @_; 148 my ($self, $ev) = @_;
116 149
117 return unless $::CONN; 150 return 0 unless $::CONN;
118 151
119 my $mod = $ev->{mod}; 152 my $mod = $ev->{mod};
120 my $sym = $ev->{sym}; 153 my $sym = $ev->{sym};
121 my $uni = $ev->{unicode}; 154 my $uni = $ev->{unicode};
122 155
124 $::CONN->user_send ("stay fire"); 157 $::CONN->user_send ("stay fire");
125 } elsif ($uni == ord ",") { 158 } elsif ($uni == ord ",") {
126 $::CONN->user_send ("take"); 159 $::CONN->user_send ("take");
127 } elsif ($uni == ord " ") { 160 } elsif ($uni == ord " ") {
128 $::CONN->user_send ("apply"); 161 $::CONN->user_send ("apply");
162 } elsif ($uni == ord ".") {
163 $::CONN->user_send ($self->{completer}{last_command})
164 if exists $self->{completer}{last_command};
129 } elsif ($uni == ord "\t") { 165 } elsif ($uni == ord "\t") {
130 # TODO: toggle inventory 166 $::INV_WINDOW->toggle_visibility;
131 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 167 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
132 $::CONN->user_send ("rotateshoottype +"); 168 $::CONN->user_send ("rotateshoottype +");
133 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 169 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
134 $::CONN->user_send ("rotateshoottype -"); 170 $::CONN->user_send ("rotateshoottype -");
135 } elsif ($uni == ord '"') { 171 } elsif ($uni == ord '"') {
146 $self->{ctrl}++; 182 $self->{ctrl}++;
147 $::CONN->user_send ("run $DIR{$sym}[0]"); 183 $::CONN->user_send ("run $DIR{$sym}[0]");
148 } else { 184 } else {
149 $::CONN->user_send ("$DIR{$sym}[1]"); 185 $::CONN->user_send ("$DIR{$sym}[1]");
150 } 186 }
151 } elsif ($ev->{unicode}) { 187 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
188 $::BIND_EDITOR->set_binding (undef, undef, [],
189 sub {
190 my ($mod, $sym, $cmds) = @_;
191 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
192 });
193 $::BIND_EDITOR->start;
194 $::BIND_EDITOR->show;
195 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
196 $::BIND_EDITOR->stop;
197 $::BIND_EDITOR->ask_for_bind_and_commit;
198 $::BIND_EDITOR->hide;
199 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
200 $::CONN->user_send ($_) for @$bind_cmd;
201 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
152 $self->{completer}->key_down ($ev); 202 $self->{completer}->key_down ($ev);
153 $self->{completer}->show; 203 $self->{completer}->show;
204 } else {
205 return 0;
206 }
207
154 } 208 1
155} 209}
156 210
157sub key_up { 211sub key_up {
158 my ($self, $ev) = @_; 212 my ($self, $ev) = @_;
159 213
214 my $res = 0;
160 my $mod = $ev->{mod}; 215 my $mod = $ev->{mod};
161 my $sym = $ev->{sym}; 216 my $sym = $ev->{sym};
162 217
163 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 218 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
164 $::CONN->user_send ("fire_stop"); 219 $::CONN->user_send ("fire_stop");
220 $res = 1;
165 } 221 }
222
166 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 223 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
167 $::CONN->user_send ("run_stop"); 224 $::CONN->user_send ("run_stop");
225 $res = 1;
168 } 226 }
227
228 $res
169} 229}
170 230
171sub draw { 231sub draw {
172 my ($self) = @_; 232 my ($self) = @_;
173 233
193 glTranslate $sx0 - 32, $sy0 - 32, 0; 253 glTranslate $sx0 - 32, $sy0 - 32, 0;
194 254
195 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 255 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
196 256
197 if ($::CFG->{fow_enable}) { 257 if ($::CFG->{fow_enable}) {
198 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war 258 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
199 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 259 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
200 glConvolutionFilter2D ( 260 glConvolutionFilter2D (
201 GL_CONVOLUTION_2D, 261 GL_CONVOLUTION_2D,
202 GL_ALPHA, 262 GL_ALPHA,
203 3, 3, 263 3, 3,
204 GL_ALPHA, GL_FLOAT, 264 GL_ALPHA, GL_FLOAT,
205 pack "f*", 265 (pack "f*", @{ $self->{smooth_matrix} }),
206 0.05, 0.13, 0.05,
207 0.13, 0.30, 0.13,
208 0.05, 0.13, 0.05,
209 ); 266 );
210 glEnable GL_CONVOLUTION_2D; 267 glEnable GL_CONVOLUTION_2D;
211 } 268 }
212 269
213 $self->{fow_texture_name} ||= glGenTexture; 270 $self->{fow_texture_name} ||= glGenTexture;
256 glVertex $::WIDTH, $::HEIGHT; 313 glVertex $::WIDTH, $::HEIGHT;
257 glVertex $::WIDTH, 0; 314 glVertex $::WIDTH, 0;
258 glEnd; 315 glEnd;
259 glDisable GL_BLEND; 316 glDisable GL_BLEND;
260 317
261 $self->{out_of_focus} ||= do { 318# $self->{out_of_focus} ||= do {
262 my $label = new CFClient::UI::Label 319# my $label = new CFClient::UI::Label
263 x => 0, 320# x => 0,
264 y => 0, 321# y => 0,
265 z => 1, 322# z => 1,
266 ellipsise => 0, 323# ellipsise => 0,
267 text => "map out of focus (click map to play)"; 324# text => "map out of focus (click map to play)";
268 325#
269 $label->show; 326# $label->show;
270 $label->update; 327# $label->update;
271 328#
272 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 329# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
273 $label->move ( 330# $label->move_abs (
274 ($::WIDTH - $label->{w}) * 0.5, 331# ($::WIDTH - $label->{w}) * 0.5,
275 ($::HEIGHT - $label->{h}) * 0.5, 332# ($::HEIGHT - $label->{h}) * 0.5,
276 ); 333# );
277 }); 334# });
278 335#
279 $label 336# $label
280 }; 337# };
281 } 338 }
282} 339}
283 340
284sub DESTROY { 341sub DESTROY {
285 my $self = shift; 342 my $self = shift;
395 fontsize => $_, 452 fontsize => $_,
396 ), (0.8) x 16 453 ), (0.8) x 16
397 ]; 454 ];
398 455
399 $self->{entry} = new CFClient::UI::Entry 456 $self->{entry} = new CFClient::UI::Entry
400 connect_changed => sub { 457 on_changed => sub {
401 $self->update_labels; 458 $self->update_labels;
402 }, 459 },
403 connect_key_down => sub { 460 on_key_down => sub {
404 my ($entry, $ev) = @_; 461 my ($entry, $ev) = @_;
405 462
406 my $self = $entry->{parent}{parent}; 463 my $self = $entry->{parent}{parent};
407 464
408 if ($ev->{sym} == 13) { 465 if ($ev->{sym} == 13) {
409 if (exists $self->{select}) { 466 if (exists $self->{select}) {
467 $self->{last_command} = $self->{select};
410 $::CONN->user_send ($self->{select}); 468 $::CONN->user_send ($self->{select});
469
470 unshift @{$self->{history}}, $self->{select};
471 $self->{hist_ptr} = 0;
472
411 $self->hide; 473 $self->hide;
412 } 474 }
413 } elsif ($ev->{sym} == 27) { 475 } elsif ($ev->{sym} == 27) {
476 $self->{hist_ptr} = 0;
414 $self->hide; 477 $self->hide;
415 return; 478 return;
416 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 479 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
480 if ($self->{hist_ptr} > 1) {
481 $self->{hist_ptr}--;
482 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
483 } elsif ($self->{hist_ptr} > 0) {
484 $self->{hist_ptr}--;
485 $self->{entry}->set_text ($self->{hist_saveback});
486 } else {
417 ++$self->{select_offset} 487 ++$self->{select_offset}
418 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 488 if $self->{select_offset} < $#{ $self->{last_match} || [] };
489 }
419 $self->update_labels; 490 $self->update_labels;
420 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 491 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
492 if ($self->{select_offset}) {
421 --$self->{select_offset} 493 --$self->{select_offset}
494 } else {
495 unless ($self->{hist_ptr}) {
496 $self->{hist_saveback} = $self->{entry}->get_text;
497 }
498 if ($self->{hist_ptr} <= $#{$self->{history}}) {
422 if $self->{select_offset}; 499 $self->{hist_ptr}++;
500 }
501 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
502 if exists $self->{history}->[$self->{hist_ptr} - 1];
503 }
423 $self->update_labels; 504 $self->update_labels;
424 } else { 505 } else {
425 return 0; 506 return 0;
426 } 507 }
427 508
446 527
447sub size_allocate { 528sub size_allocate {
448 my ($self, $w, $h) = @_; 529 my ($self, $w, $h) = @_;
449 530
450 $self->SUPER::size_allocate ($w, $h); 531 $self->SUPER::size_allocate ($w, $h);
451 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 532 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
452} 533}
453 534
454sub show { 535sub show {
455 my ($self) = @_; 536 my ($self) = @_;
456 537
466} 547}
467 548
468sub key_down { 549sub key_down {
469 my ($self, $ev) = @_; 550 my ($self, $ev) = @_;
470 551
471 $self->{entry}->key_down ($ev); 552 $self->{entry}->key_down ($ev)
472} 553}
473 554
474sub update_labels { 555sub update_labels {
475 my ($self) = @_; 556 my ($self) = @_;
476 557
509 590
510 @match = map $self->{command}{$_->[0]}, 591 @match = map $self->{command}{$_->[0]},
511 sort { 592 sort {
512 $a->[1] <=> $b->[1] 593 $a->[1] <=> $b->[1]
513 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 594 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
514 or (length $a->[0]) <=> (length $b->[0]) 595 or (length $b->[0]) <=> (length $a->[0])
515 } @match; 596 } @match;
516 } 597 }
517 598
518 $self->{last_search} = $cmd; 599 $self->{last_search} = $text;
519 $self->{last_match} = \@match; 600 $self->{last_match} = \@match;
520 601
521 $self->{select_offset} = 0; 602 $self->{select_offset} = 0;
522 } 603 }
523 604

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines