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.59 by root, Wed Jun 14 16:20:22 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
48} 61}
49 62
50sub button_down { 63sub button_down {
51 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
52 65
66 return unless $::CONN;
67
53 $self->focus_in; 68 $self->focus_in;
54 69
55 if ($ev->{button} == 2) { 70 if ($ev->{button} == 1) {
71 my $x = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale});
72 my $y = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale});
73
74 $x += int 0.5 * ($::MAP->w - $self->{sw} - 1);
75 $y += int 0.5 * ($::MAP->h - $self->{sh} - 1);
76
77 $x -= int 0.5 * $::MAP->w;
78 $y -= int 0.5 * $::MAP->h;
79
80 $x += 1;
81 $y += 1;
82
83 $::CONN->lookat ($x, $y)
84 if $::CONN;
85
86 } elsif ($ev->{button} == 2) {
56 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 87 my ($ox, $oy) = ($ev->{x}, $ev->{y});
57 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 88 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
58 89
59 $self->{motion} = sub { 90 $self->{motion} = sub {
60 my ($ev, $x, $y) = @_; 91 my ($ev, $x, $y) = @_;
65 $::CFG->{map_shift_y} = $bh + $y - $oy; 96 $::CFG->{map_shift_y} = $bh + $y - $oy;
66 97
67 $self->update; 98 $self->update;
68 }; 99 };
69 } 100 }
101
102 1
70} 103}
71 104
72sub button_up { 105sub button_up {
73 my ($self, $ev, $x, $y) = @_; 106 my ($self, $ev, $x, $y) = @_;
74 107
75 delete $self->{motion}; 108 delete $self->{motion};
109
110 1
76} 111}
77 112
78sub mouse_motion { 113sub mouse_motion {
79 my ($self, $ev, $x, $y) = @_; 114 my ($self, $ev, $x, $y) = @_;
80 115
116 if ($self->{motion}) {
81 $self->{motion}->($ev, $x, $y) if $self->{motion}; 117 $self->{motion}->($ev, $x, $y);
118 } else {
119 return 0;
120 }
121
122 1
82} 123}
83 124
84sub size_request { 125sub size_request {
85 ( 126 (
86 1 + 32 * int $::WIDTH / 32, 127 1 + 32 * int $::WIDTH / 32,
112); 153);
113 154
114sub key_down { 155sub key_down {
115 my ($self, $ev) = @_; 156 my ($self, $ev) = @_;
116 157
117 return unless $::CONN; 158 return 0 unless $::CONN;
118 159
119 my $mod = $ev->{mod}; 160 my $mod = $ev->{mod};
120 my $sym = $ev->{sym}; 161 my $sym = $ev->{sym};
121 my $uni = $ev->{unicode}; 162 my $uni = $ev->{unicode};
122 163
124 $::CONN->user_send ("stay fire"); 165 $::CONN->user_send ("stay fire");
125 } elsif ($uni == ord ",") { 166 } elsif ($uni == ord ",") {
126 $::CONN->user_send ("take"); 167 $::CONN->user_send ("take");
127 } elsif ($uni == ord " ") { 168 } elsif ($uni == ord " ") {
128 $::CONN->user_send ("apply"); 169 $::CONN->user_send ("apply");
170 } elsif ($uni == ord ".") {
171 $::CONN->user_send ($self->{completer}{last_command})
172 if exists $self->{completer}{last_command};
129 } elsif ($uni == ord "\t") { 173 } elsif ($uni == ord "\t") {
130 # TODO: toggle inventory 174 $::INV_WINDOW->toggle_visibility;
131 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 175 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
132 $::CONN->user_send ("rotateshoottype +"); 176 $::CONN->user_send ("rotateshoottype +");
133 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 177 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
134 $::CONN->user_send ("rotateshoottype -"); 178 $::CONN->user_send ("rotateshoottype -");
135 } elsif ($uni == ord '"') { 179 } elsif ($uni == ord '"') {
139 $self->{completer}->set_prefix (""); 183 $self->{completer}->set_prefix ("");
140 $self->{completer}->show; 184 $self->{completer}->show;
141 } elsif (exists $DIR{$sym}) { 185 } elsif (exists $DIR{$sym}) {
142 if ($mod & CFClient::KMOD_SHIFT) { 186 if ($mod & CFClient::KMOD_SHIFT) {
143 $self->{shft}++; 187 $self->{shft}++;
188 if ($DIR{$sym}[0] != $self->{fire_dir}) {
144 $::CONN->user_send ("fire $DIR{$sym}[0]"); 189 $::CONN->user_send ("fire $DIR{$sym}[0]");
190 }
191 $self->{fire_dir} = $DIR{$sym}[0];
145 } elsif ($mod & CFClient::KMOD_CTRL) { 192 } elsif ($mod & CFClient::KMOD_CTRL) {
146 $self->{ctrl}++; 193 $self->{ctrl}++;
147 $::CONN->user_send ("run $DIR{$sym}[0]"); 194 $::CONN->user_send ("run $DIR{$sym}[0]");
148 } else { 195 } else {
149 $::CONN->user_send ("$DIR{$sym}[1]"); 196 $::CONN->user_send ("$DIR{$sym}[1]");
150 } 197 }
151 } elsif ($ev->{unicode}) { 198 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
199 $::BIND_EDITOR->set_binding (undef, undef, [],
200 sub {
201 my ($mod, $sym, $cmds) = @_;
202 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
203 });
204 $::BIND_EDITOR->start;
205 $::BIND_EDITOR->show;
206 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
207 $::BIND_EDITOR->stop;
208 $::BIND_EDITOR->ask_for_bind_and_commit;
209 $::BIND_EDITOR->hide;
210 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
211 $::CONN->user_send ($_) for @$bind_cmd;
212 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
152 $self->{completer}->key_down ($ev); 213 $self->{completer}->key_down ($ev);
153 $self->{completer}->show; 214 $self->{completer}->show;
215 } else {
216 return 0;
217 }
218
154 } 219 1
155} 220}
156 221
157sub key_up { 222sub key_up {
158 my ($self, $ev) = @_; 223 my ($self, $ev) = @_;
159 224
225 my $res = 0;
160 my $mod = $ev->{mod}; 226 my $mod = $ev->{mod};
161 my $sym = $ev->{sym}; 227 my $sym = $ev->{sym};
162 228
229 if ($::CFG->{shift_fire_stop}) {
163 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 230 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
164 $::CONN->user_send ("fire_stop"); 231 $::CONN->user_send ("fire_stop");
232 delete $self->{fire_dir};
233 $res = 1;
234 }
235 } else {
236 if (exists $DIR{$sym} && delete $self->{shft}) {
237 $::CONN->user_send ("fire_stop");
238 delete $self->{fire_dir};
239 $res = 1;
240 } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
241 $::CONN->user_send ("fire_stop");
242 delete $self->{fire_dir};
243 $res = 1;
244 }
165 } 245 }
246
166 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 247 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
167 $::CONN->user_send ("run_stop"); 248 $::CONN->user_send ("run_stop");
249 $res = 1;
168 } 250 }
251
252 $res
169} 253}
170 254
171sub draw { 255sub draw {
172 my ($self) = @_; 256 my ($self) = @_;
173 257
174 my $focused = $CFClient::UI::FOCUS == $self 258 my $focused = $CFClient::UI::FOCUS == $self
175 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 259 || $CFClient::UI::FOCUS == $self->{completer}{entry};
176 260
177 return 261 return
178 unless $focused || !$::FAST; 262 unless $::CONN && ($focused || !$::FAST);
179 263
180 if (delete $self->{need_update}) { 264 if (delete $self->{need_update}) {
265 $self->{fow_texture} ||= glGenTexture;
266
181 glNewList $self->{list}; 267 glNewList $self->{list};
182 268
183 if ($::MAP) { 269 if ($::MAP) {
184 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 270 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
185 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 271 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
186 272
187 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; 273 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; 274 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale};
275 my $sx0 = $self->{sx0} = ($sx & 31) - 32; $sx = $self->{sx} = ($sx - $sx0) / 32;
276 my $sy0 = $self->{sy0} = ($sy & 31) - 32; $sy = $self->{sy} = ($sy - $sy0) / 32;
189 277
190 glPushMatrix; 278 glPushMatrix;
191 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 279 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
192 280
193 glTranslate $sx0 - 32, $sy0 - 32, 0; 281 glTranslate $sx0, $sy0;
194 282
195 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 283 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
196 284
197 if ($::CFG->{fow_enable}) { 285 if ($::CFG->{fow_enable}) {
198 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war 286 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); 287 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
200 glConvolutionFilter2D ( 288 glConvolutionFilter2D (
201 GL_CONVOLUTION_2D, 289 GL_CONVOLUTION_2D,
202 GL_ALPHA, 290 GL_ALPHA,
203 3, 3, 291 3, 3,
204 GL_ALPHA, GL_FLOAT, 292 GL_ALPHA, GL_FLOAT,
205 pack "f*", 293 (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 ); 294 );
210 glEnable GL_CONVOLUTION_2D; 295 glEnable GL_CONVOLUTION_2D;
211 } 296 }
212 297
213 $self->{fow_texture_name} ||= glGenTexture; 298 $self->{fow_texture_name} ||= glGenTexture;
256 glVertex $::WIDTH, $::HEIGHT; 341 glVertex $::WIDTH, $::HEIGHT;
257 glVertex $::WIDTH, 0; 342 glVertex $::WIDTH, 0;
258 glEnd; 343 glEnd;
259 glDisable GL_BLEND; 344 glDisable GL_BLEND;
260 345
261 $self->{out_of_focus} ||= do { 346# $self->{out_of_focus} ||= do {
262 my $label = new CFClient::UI::Label 347# my $label = new CFClient::UI::Label
263 x => 0, 348# x => 0,
264 y => 0, 349# y => 0,
265 z => 1, 350# z => 1,
266 ellipsise => 0, 351# ellipsise => 0,
267 text => "map out of focus (click map to play)"; 352# text => "map out of focus (click map to play)";
268 353#
269 $label->show; 354# $label->show;
270 $label->update; 355# $label->update;
271 356#
272 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 357# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
273 $label->move ( 358# $label->move_abs (
274 ($::WIDTH - $label->{w}) * 0.5, 359# ($::WIDTH - $label->{w}) * 0.5,
275 ($::HEIGHT - $label->{h}) * 0.5, 360# ($::HEIGHT - $label->{h}) * 0.5,
276 ); 361# );
277 }); 362# });
278 363#
279 $label 364# $label
280 }; 365# };
281 } 366 }
282} 367}
283 368
284sub DESTROY { 369sub DESTROY {
285 my $self = shift; 370 my $self = shift;
395 fontsize => $_, 480 fontsize => $_,
396 ), (0.8) x 16 481 ), (0.8) x 16
397 ]; 482 ];
398 483
399 $self->{entry} = new CFClient::UI::Entry 484 $self->{entry} = new CFClient::UI::Entry
400 connect_changed => sub { 485 on_changed => sub {
401 $self->update_labels; 486 $self->update_labels;
402 }, 487 },
488 on_button_down => sub {
489 my ($entry, $ev, $x, $y) = @_;
490
491 if ($ev->{button} == 3) {
492 (new CFClient::UI::Menu
493 items => [
494 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }]
495 ],
496 )->popup ($ev);
497 return 1;
498 }
499 0
500 },
403 connect_key_down => sub { 501 on_key_down => sub {
404 my ($entry, $ev) = @_; 502 my ($entry, $ev) = @_;
405 503
406 my $self = $entry->{parent}{parent}; 504 my $self = $entry->{parent}{parent};
407 505
408 if ($ev->{sym} == 13) { 506 if ($ev->{sym} == 13) {
409 if (exists $self->{select}) { 507 if (exists $self->{select}) {
508 $self->{last_command} = $self->{select};
410 $::CONN->user_send ($self->{select}); 509 $::CONN->user_send ($self->{select});
510
511 unshift @{$self->{history}}, $self->{select};
512 $self->{hist_ptr} = 0;
513
411 $self->hide; 514 $self->hide;
412 } 515 }
413 } elsif ($ev->{sym} == 27) { 516 } elsif ($ev->{sym} == 27) {
517 $self->{hist_ptr} = 0;
414 $self->hide; 518 $self->hide;
415 return; 519 return;
416 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 520 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
521 if ($self->{hist_ptr} > 1) {
522 $self->{hist_ptr}--;
523 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
524 } elsif ($self->{hist_ptr} > 0) {
525 $self->{hist_ptr}--;
526 $self->{entry}->set_text ($self->{hist_saveback});
527 } else {
417 ++$self->{select_offset} 528 ++$self->{select_offset}
418 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 529 if $self->{select_offset} < $#{ $self->{last_match} || [] };
530 }
419 $self->update_labels; 531 $self->update_labels;
420 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 532 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
533 if ($self->{select_offset}) {
421 --$self->{select_offset} 534 --$self->{select_offset}
535 } else {
536 unless ($self->{hist_ptr}) {
537 $self->{hist_saveback} = $self->{entry}->get_text;
538 }
539 if ($self->{hist_ptr} <= $#{$self->{history}}) {
422 if $self->{select_offset}; 540 $self->{hist_ptr}++;
541 }
542 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
543 if exists $self->{history}->[$self->{hist_ptr} - 1];
544 }
423 $self->update_labels; 545 $self->update_labels;
424 } else { 546 } else {
425 return 0; 547 return 0;
426 } 548 }
427 549
446 568
447sub size_allocate { 569sub size_allocate {
448 my ($self, $w, $h) = @_; 570 my ($self, $w, $h) = @_;
449 571
450 $self->SUPER::size_allocate ($w, $h); 572 $self->SUPER::size_allocate ($w, $h);
451 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 573 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
452} 574}
453 575
454sub show { 576sub show {
455 my ($self) = @_; 577 my ($self) = @_;
456 578
466} 588}
467 589
468sub key_down { 590sub key_down {
469 my ($self, $ev) = @_; 591 my ($self, $ev) = @_;
470 592
471 $self->{entry}->key_down ($ev); 593 $self->{entry}->key_down ($ev)
472} 594}
473 595
474sub update_labels { 596sub update_labels {
475 my ($self) = @_; 597 my ($self) = @_;
476 598
509 631
510 @match = map $self->{command}{$_->[0]}, 632 @match = map $self->{command}{$_->[0]},
511 sort { 633 sort {
512 $a->[1] <=> $b->[1] 634 $a->[1] <=> $b->[1]
513 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 635 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
514 or (length $a->[0]) <=> (length $b->[0]) 636 or (length $b->[0]) <=> (length $a->[0])
515 } @match; 637 } @match;
516 } 638 }
517 639
518 $self->{last_search} = $cmd; 640 $self->{last_search} = $text;
519 $self->{last_match} = \@match; 641 $self->{last_match} = \@match;
520 642
521 $self->{select_offset} = 0; 643 $self->{select_offset} = 0;
522 } 644 }
523 645

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines