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.55 by root, Sun Jun 11 20:09:12 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 $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->send ("lookat $x $y")
82 if $::CONN;
83
84 } elsif ($ev->{button} == 2) {
56 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 85 my ($ox, $oy) = ($ev->{x}, $ev->{y});
57 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 86 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
58 87
59 $self->{motion} = sub { 88 $self->{motion} = sub {
60 my ($ev, $x, $y) = @_; 89 my ($ev, $x, $y) = @_;
65 $::CFG->{map_shift_y} = $bh + $y - $oy; 94 $::CFG->{map_shift_y} = $bh + $y - $oy;
66 95
67 $self->update; 96 $self->update;
68 }; 97 };
69 } 98 }
99
100 1
70} 101}
71 102
72sub button_up { 103sub button_up {
73 my ($self, $ev, $x, $y) = @_; 104 my ($self, $ev, $x, $y) = @_;
74 105
75 delete $self->{motion}; 106 delete $self->{motion};
107
108 1
76} 109}
77 110
78sub mouse_motion { 111sub mouse_motion {
79 my ($self, $ev, $x, $y) = @_; 112 my ($self, $ev, $x, $y) = @_;
80 113
114 if ($self->{motion}) {
81 $self->{motion}->($ev, $x, $y) if $self->{motion}; 115 $self->{motion}->($ev, $x, $y);
116 } else {
117 return 0;
118 }
119
120 1
82} 121}
83 122
84sub size_request { 123sub size_request {
85 ( 124 (
86 1 + 32 * int $::WIDTH / 32, 125 1 + 32 * int $::WIDTH / 32,
112); 151);
113 152
114sub key_down { 153sub key_down {
115 my ($self, $ev) = @_; 154 my ($self, $ev) = @_;
116 155
117 return unless $::CONN; 156 return 0 unless $::CONN;
118 157
119 my $mod = $ev->{mod}; 158 my $mod = $ev->{mod};
120 my $sym = $ev->{sym}; 159 my $sym = $ev->{sym};
121 my $uni = $ev->{unicode}; 160 my $uni = $ev->{unicode};
122 161
124 $::CONN->user_send ("stay fire"); 163 $::CONN->user_send ("stay fire");
125 } elsif ($uni == ord ",") { 164 } elsif ($uni == ord ",") {
126 $::CONN->user_send ("take"); 165 $::CONN->user_send ("take");
127 } elsif ($uni == ord " ") { 166 } elsif ($uni == ord " ") {
128 $::CONN->user_send ("apply"); 167 $::CONN->user_send ("apply");
168 } elsif ($uni == ord ".") {
169 $::CONN->user_send ($self->{completer}{last_command})
170 if exists $self->{completer}{last_command};
129 } elsif ($uni == ord "\t") { 171 } elsif ($uni == ord "\t") {
130 # TODO: toggle inventory 172 $::INV_WINDOW->toggle_visibility;
131 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 173 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
132 $::CONN->user_send ("rotateshoottype +"); 174 $::CONN->user_send ("rotateshoottype +");
133 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 175 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
134 $::CONN->user_send ("rotateshoottype -"); 176 $::CONN->user_send ("rotateshoottype -");
135 } elsif ($uni == ord '"') { 177 } elsif ($uni == ord '"') {
146 $self->{ctrl}++; 188 $self->{ctrl}++;
147 $::CONN->user_send ("run $DIR{$sym}[0]"); 189 $::CONN->user_send ("run $DIR{$sym}[0]");
148 } else { 190 } else {
149 $::CONN->user_send ("$DIR{$sym}[1]"); 191 $::CONN->user_send ("$DIR{$sym}[1]");
150 } 192 }
151 } 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')) {
152 $self->{completer}->key_down ($ev); 208 $self->{completer}->key_down ($ev);
153 $self->{completer}->show; 209 $self->{completer}->show;
210 } else {
211 return 0;
212 }
213
154 } 214 1
155} 215}
156 216
157sub key_up { 217sub key_up {
158 my ($self, $ev) = @_; 218 my ($self, $ev) = @_;
159 219
220 my $res = 0;
160 my $mod = $ev->{mod}; 221 my $mod = $ev->{mod};
161 my $sym = $ev->{sym}; 222 my $sym = $ev->{sym};
162 223
163 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 224 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
164 $::CONN->user_send ("fire_stop"); 225 $::CONN->user_send ("fire_stop");
226 $res = 1;
165 } 227 }
228
166 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 229 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
167 $::CONN->user_send ("run_stop"); 230 $::CONN->user_send ("run_stop");
231 $res = 1;
168 } 232 }
233
234 $res
169} 235}
170 236
171sub draw { 237sub draw {
172 my ($self) = @_; 238 my ($self) = @_;
173 239
179 245
180 if (delete $self->{need_update}) { 246 if (delete $self->{need_update}) {
181 glNewList $self->{list}; 247 glNewList $self->{list};
182 248
183 if ($::MAP) { 249 if ($::MAP) {
184 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 250 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
185 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 251 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
186 252
187 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};
188 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;
189 257
190 glPushMatrix; 258 glPushMatrix;
191 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 259 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
192 260
193 glTranslate $sx0 - 32, $sy0 - 32, 0; 261 glTranslate $sx0, $sy0;
194 262
195 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);
196 264
197 if ($::CFG->{fow_enable}) { 265 if ($::CFG->{fow_enable}) {
198 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
199 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 267 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
200 glConvolutionFilter2D ( 268 glConvolutionFilter2D (
201 GL_CONVOLUTION_2D, 269 GL_CONVOLUTION_2D,
202 GL_ALPHA, 270 GL_ALPHA,
203 3, 3, 271 3, 3,
204 GL_ALPHA, GL_FLOAT, 272 GL_ALPHA, GL_FLOAT,
205 pack "f*", 273 (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 ); 274 );
210 glEnable GL_CONVOLUTION_2D; 275 glEnable GL_CONVOLUTION_2D;
211 } 276 }
212 277
213 $self->{fow_texture_name} ||= glGenTexture; 278 $self->{fow_texture_name} ||= glGenTexture;
256 glVertex $::WIDTH, $::HEIGHT; 321 glVertex $::WIDTH, $::HEIGHT;
257 glVertex $::WIDTH, 0; 322 glVertex $::WIDTH, 0;
258 glEnd; 323 glEnd;
259 glDisable GL_BLEND; 324 glDisable GL_BLEND;
260 325
261 $self->{out_of_focus} ||= do { 326# $self->{out_of_focus} ||= do {
262 my $label = new CFClient::UI::Label 327# my $label = new CFClient::UI::Label
263 x => 0, 328# x => 0,
264 y => 0, 329# y => 0,
265 z => 1, 330# z => 1,
266 ellipsise => 0, 331# ellipsise => 0,
267 text => "map out of focus (click map to play)"; 332# text => "map out of focus (click map to play)";
268 333#
269 $label->show; 334# $label->show;
270 $label->update; 335# $label->update;
271 336#
272 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 337# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
273 $label->move ( 338# $label->move_abs (
274 ($::WIDTH - $label->{w}) * 0.5, 339# ($::WIDTH - $label->{w}) * 0.5,
275 ($::HEIGHT - $label->{h}) * 0.5, 340# ($::HEIGHT - $label->{h}) * 0.5,
276 ); 341# );
277 }); 342# });
278 343#
279 $label 344# $label
280 }; 345# };
281 } 346 }
282} 347}
283 348
284sub DESTROY { 349sub DESTROY {
285 my $self = shift; 350 my $self = shift;
395 fontsize => $_, 460 fontsize => $_,
396 ), (0.8) x 16 461 ), (0.8) x 16
397 ]; 462 ];
398 463
399 $self->{entry} = new CFClient::UI::Entry 464 $self->{entry} = new CFClient::UI::Entry
400 connect_changed => sub { 465 on_changed => sub {
401 $self->update_labels; 466 $self->update_labels;
402 }, 467 },
403 connect_key_down => sub { 468 on_key_down => sub {
404 my ($entry, $ev) = @_; 469 my ($entry, $ev) = @_;
405 470
406 my $self = $entry->{parent}{parent}; 471 my $self = $entry->{parent}{parent};
407 472
408 if ($ev->{sym} == 13) { 473 if ($ev->{sym} == 13) {
409 if (exists $self->{select}) { 474 if (exists $self->{select}) {
475 $self->{last_command} = $self->{select};
410 $::CONN->user_send ($self->{select}); 476 $::CONN->user_send ($self->{select});
477
478 unshift @{$self->{history}}, $self->{select};
479 $self->{hist_ptr} = 0;
480
411 $self->hide; 481 $self->hide;
412 } 482 }
413 } elsif ($ev->{sym} == 27) { 483 } elsif ($ev->{sym} == 27) {
484 $self->{hist_ptr} = 0;
414 $self->hide; 485 $self->hide;
415 return; 486 return;
416 } 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 {
417 ++$self->{select_offset} 495 ++$self->{select_offset}
418 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 496 if $self->{select_offset} < $#{ $self->{last_match} || [] };
497 }
419 $self->update_labels; 498 $self->update_labels;
420 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 499 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
500 if ($self->{select_offset}) {
421 --$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}}) {
422 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 }
423 $self->update_labels; 512 $self->update_labels;
424 } else { 513 } else {
425 return 0; 514 return 0;
426 } 515 }
427 516
446 535
447sub size_allocate { 536sub size_allocate {
448 my ($self, $w, $h) = @_; 537 my ($self, $w, $h) = @_;
449 538
450 $self->SUPER::size_allocate ($w, $h); 539 $self->SUPER::size_allocate ($w, $h);
451 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 540 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
452} 541}
453 542
454sub show { 543sub show {
455 my ($self) = @_; 544 my ($self) = @_;
456 545
466} 555}
467 556
468sub key_down { 557sub key_down {
469 my ($self, $ev) = @_; 558 my ($self, $ev) = @_;
470 559
471 $self->{entry}->key_down ($ev); 560 $self->{entry}->key_down ($ev)
472} 561}
473 562
474sub update_labels { 563sub update_labels {
475 my ($self) = @_; 564 my ($self) = @_;
476 565
509 598
510 @match = map $self->{command}{$_->[0]}, 599 @match = map $self->{command}{$_->[0]},
511 sort { 600 sort {
512 $a->[1] <=> $b->[1] 601 $a->[1] <=> $b->[1]
513 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 602 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
514 or (length $a->[0]) <=> (length $b->[0]) 603 or (length $b->[0]) <=> (length $a->[0])
515 } @match; 604 } @match;
516 } 605 }
517 606
518 $self->{last_search} = $cmd; 607 $self->{last_search} = $text;
519 $self->{last_match} = \@match; 608 $self->{last_match} = \@match;
520 609
521 $self->{select_offset} = 0; 610 $self->{select_offset} = 0;
522 } 611 }
523 612

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines