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.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},
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->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 '"') {
139 $self->{completer}->set_prefix (""); 181 $self->{completer}->set_prefix ("");
140 $self->{completer}->show; 182 $self->{completer}->show;
141 } elsif (exists $DIR{$sym}) { 183 } elsif (exists $DIR{$sym}) {
142 if ($mod & CFClient::KMOD_SHIFT) { 184 if ($mod & CFClient::KMOD_SHIFT) {
143 $self->{shft}++; 185 $self->{shft}++;
186 if ($DIR{$sym}[0] != $self->{fire_dir}) {
144 $::CONN->user_send ("fire $DIR{$sym}[0]"); 187 $::CONN->user_send ("fire $DIR{$sym}[0]");
188 }
189 $self->{fire_dir} = $DIR{$sym}[0];
145 } elsif ($mod & CFClient::KMOD_CTRL) { 190 } elsif ($mod & CFClient::KMOD_CTRL) {
146 $self->{ctrl}++; 191 $self->{ctrl}++;
147 $::CONN->user_send ("run $DIR{$sym}[0]"); 192 $::CONN->user_send ("run $DIR{$sym}[0]");
148 } else { 193 } else {
149 $::CONN->user_send ("$DIR{$sym}[1]"); 194 $::CONN->user_send ("$DIR{$sym}[1]");
150 } 195 }
151 } 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')) {
152 $self->{completer}->key_down ($ev); 211 $self->{completer}->key_down ($ev);
153 $self->{completer}->show; 212 $self->{completer}->show;
213 } else {
214 return 0;
215 }
216
154 } 217 1
155} 218}
156 219
157sub key_up { 220sub key_up {
158 my ($self, $ev) = @_; 221 my ($self, $ev) = @_;
159 222
223 my $res = 0;
160 my $mod = $ev->{mod}; 224 my $mod = $ev->{mod};
161 my $sym = $ev->{sym}; 225 my $sym = $ev->{sym};
162 226
227 if ($::CFG->{shift_fire_stop}) {
163 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 228 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
164 $::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 }
165 } 243 }
244
166 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 245 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
167 $::CONN->user_send ("run_stop"); 246 $::CONN->user_send ("run_stop");
247 $res = 1;
168 } 248 }
249
250 $res
169} 251}
170 252
171sub draw { 253sub draw {
172 my ($self) = @_; 254 my ($self) = @_;
173 255
179 261
180 if (delete $self->{need_update}) { 262 if (delete $self->{need_update}) {
181 glNewList $self->{list}; 263 glNewList $self->{list};
182 264
183 if ($::MAP) { 265 if ($::MAP) {
184 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 266 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
185 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 267 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
186 268
187 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};
188 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;
189 273
190 glPushMatrix; 274 glPushMatrix;
191 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 275 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
192 276
193 glTranslate $sx0 - 32, $sy0 - 32, 0; 277 glTranslate $sx0, $sy0;
194 278
195 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);
196 280
197 if ($::CFG->{fow_enable}) { 281 if ($::CFG->{fow_enable}) {
198 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
199 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 283 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
200 glConvolutionFilter2D ( 284 glConvolutionFilter2D (
201 GL_CONVOLUTION_2D, 285 GL_CONVOLUTION_2D,
202 GL_ALPHA, 286 GL_ALPHA,
203 3, 3, 287 3, 3,
204 GL_ALPHA, GL_FLOAT, 288 GL_ALPHA, GL_FLOAT,
205 pack "f*", 289 (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 ); 290 );
210 glEnable GL_CONVOLUTION_2D; 291 glEnable GL_CONVOLUTION_2D;
211 } 292 }
212 293
213 $self->{fow_texture_name} ||= glGenTexture; 294 $self->{fow_texture_name} ||= glGenTexture;
256 glVertex $::WIDTH, $::HEIGHT; 337 glVertex $::WIDTH, $::HEIGHT;
257 glVertex $::WIDTH, 0; 338 glVertex $::WIDTH, 0;
258 glEnd; 339 glEnd;
259 glDisable GL_BLEND; 340 glDisable GL_BLEND;
260 341
261 $self->{out_of_focus} ||= do { 342# $self->{out_of_focus} ||= do {
262 my $label = new CFClient::UI::Label 343# my $label = new CFClient::UI::Label
263 x => 0, 344# x => 0,
264 y => 0, 345# y => 0,
265 z => 1, 346# z => 1,
266 ellipsise => 0, 347# ellipsise => 0,
267 text => "map out of focus (click map to play)"; 348# text => "map out of focus (click map to play)";
268 349#
269 $label->show; 350# $label->show;
270 $label->update; 351# $label->update;
271 352#
272 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 353# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
273 $label->move ( 354# $label->move_abs (
274 ($::WIDTH - $label->{w}) * 0.5, 355# ($::WIDTH - $label->{w}) * 0.5,
275 ($::HEIGHT - $label->{h}) * 0.5, 356# ($::HEIGHT - $label->{h}) * 0.5,
276 ); 357# );
277 }); 358# });
278 359#
279 $label 360# $label
280 }; 361# };
281 } 362 }
282} 363}
283 364
284sub DESTROY { 365sub DESTROY {
285 my $self = shift; 366 my $self = shift;
395 fontsize => $_, 476 fontsize => $_,
396 ), (0.8) x 16 477 ), (0.8) x 16
397 ]; 478 ];
398 479
399 $self->{entry} = new CFClient::UI::Entry 480 $self->{entry} = new CFClient::UI::Entry
400 connect_changed => sub { 481 on_changed => sub {
401 $self->update_labels; 482 $self->update_labels;
402 }, 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 },
403 connect_key_down => sub { 497 on_key_down => sub {
404 my ($entry, $ev) = @_; 498 my ($entry, $ev) = @_;
405 499
406 my $self = $entry->{parent}{parent}; 500 my $self = $entry->{parent}{parent};
407 501
408 if ($ev->{sym} == 13) { 502 if ($ev->{sym} == 13) {
409 if (exists $self->{select}) { 503 if (exists $self->{select}) {
504 $self->{last_command} = $self->{select};
410 $::CONN->user_send ($self->{select}); 505 $::CONN->user_send ($self->{select});
506
507 unshift @{$self->{history}}, $self->{select};
508 $self->{hist_ptr} = 0;
509
411 $self->hide; 510 $self->hide;
412 } 511 }
413 } elsif ($ev->{sym} == 27) { 512 } elsif ($ev->{sym} == 27) {
513 $self->{hist_ptr} = 0;
414 $self->hide; 514 $self->hide;
415 return; 515 return;
416 } 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 {
417 ++$self->{select_offset} 524 ++$self->{select_offset}
418 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 525 if $self->{select_offset} < $#{ $self->{last_match} || [] };
526 }
419 $self->update_labels; 527 $self->update_labels;
420 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 528 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
529 if ($self->{select_offset}) {
421 --$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}}) {
422 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 }
423 $self->update_labels; 541 $self->update_labels;
424 } else { 542 } else {
425 return 0; 543 return 0;
426 } 544 }
427 545
446 564
447sub size_allocate { 565sub size_allocate {
448 my ($self, $w, $h) = @_; 566 my ($self, $w, $h) = @_;
449 567
450 $self->SUPER::size_allocate ($w, $h); 568 $self->SUPER::size_allocate ($w, $h);
451 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 569 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
452} 570}
453 571
454sub show { 572sub show {
455 my ($self) = @_; 573 my ($self) = @_;
456 574
466} 584}
467 585
468sub key_down { 586sub key_down {
469 my ($self, $ev) = @_; 587 my ($self, $ev) = @_;
470 588
471 $self->{entry}->key_down ($ev); 589 $self->{entry}->key_down ($ev)
472} 590}
473 591
474sub update_labels { 592sub update_labels {
475 my ($self) = @_; 593 my ($self) = @_;
476 594
509 627
510 @match = map $self->{command}{$_->[0]}, 628 @match = map $self->{command}{$_->[0]},
511 sort { 629 sort {
512 $a->[1] <=> $b->[1] 630 $a->[1] <=> $b->[1]
513 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 631 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
514 or (length $a->[0]) <=> (length $b->[0]) 632 or (length $b->[0]) <=> (length $a->[0])
515 } @match; 633 } @match;
516 } 634 }
517 635
518 $self->{last_search} = $cmd; 636 $self->{last_search} = $text;
519 $self->{last_match} = \@match; 637 $self->{last_match} = \@match;
520 638
521 $self->{select_offset} = 0; 639 $self->{select_offset} = 0;
522 } 640 }
523 641

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines