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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines