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.38 by root, Thu May 25 02:23:14 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},
39 my ($self, $command, $tooltip, $widget, $cb) = @_; 46 my ($self, $command, $tooltip, $widget, $cb) = @_;
40 47
41 (my $data = $command) =~ s/\\//g; 48 (my $data = $command) =~ s/\\//g;
42 49
43 $tooltip =~ s/^\s+//; 50 $tooltip =~ s/^\s+//;
44
45 $tooltip = "<big>$data</big>\n\n$tooltip"; 51 $tooltip = "<big>$data</big>\n\n$tooltip";
46
47 $tooltip =~ s/\s+$//; 52 $tooltip =~ s/\s+$//;
48 53
49 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; 54 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
50} 55}
51 56
56} 61}
57 62
58sub button_down { 63sub button_down {
59 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
60 65
66 return unless $::CONN;
67
61 $self->focus_in; 68 $self->focus_in;
62 69
63 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) {
64 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 87 my ($ox, $oy) = ($ev->{x}, $ev->{y});
65 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 88 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
66 89
67 $self->{motion} = sub { 90 $self->{motion} = sub {
68 my ($ev, $x, $y) = @_; 91 my ($ev, $x, $y) = @_;
73 $::CFG->{map_shift_y} = $bh + $y - $oy; 96 $::CFG->{map_shift_y} = $bh + $y - $oy;
74 97
75 $self->update; 98 $self->update;
76 }; 99 };
77 } 100 }
101
102 1
78} 103}
79 104
80sub button_up { 105sub button_up {
81 my ($self, $ev, $x, $y) = @_; 106 my ($self, $ev, $x, $y) = @_;
82 107
83 delete $self->{motion}; 108 delete $self->{motion};
109
110 1
84} 111}
85 112
86sub mouse_motion { 113sub mouse_motion {
87 my ($self, $ev, $x, $y) = @_; 114 my ($self, $ev, $x, $y) = @_;
88 115
116 if ($self->{motion}) {
89 $self->{motion}->($ev, $x, $y) if $self->{motion}; 117 $self->{motion}->($ev, $x, $y);
118 } else {
119 return 0;
120 }
121
122 1
90} 123}
91 124
92sub size_request { 125sub size_request {
93 ( 126 (
94 1 + 32 * int $::WIDTH / 32, 127 1 + 32 * int $::WIDTH / 32,
120); 153);
121 154
122sub key_down { 155sub key_down {
123 my ($self, $ev) = @_; 156 my ($self, $ev) = @_;
124 157
125 return unless $::CONN; 158 return 0 unless $::CONN;
126 159
127 my $mod = $ev->{mod}; 160 my $mod = $ev->{mod};
128 my $sym = $ev->{sym}; 161 my $sym = $ev->{sym};
129 my $uni = $ev->{unicode}; 162 my $uni = $ev->{unicode};
130 163
136 $::CONN->user_send ("apply"); 169 $::CONN->user_send ("apply");
137 } elsif ($uni == ord ".") { 170 } elsif ($uni == ord ".") {
138 $::CONN->user_send ($self->{completer}{last_command}) 171 $::CONN->user_send ($self->{completer}{last_command})
139 if exists $self->{completer}{last_command}; 172 if exists $self->{completer}{last_command};
140 } elsif ($uni == ord "\t") { 173 } elsif ($uni == ord "\t") {
141 # TODO: toggle inventory 174 $::INV_WINDOW->toggle_visibility;
142 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 175 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
143 $::CONN->user_send ("rotateshoottype +"); 176 $::CONN->user_send ("rotateshoottype +");
144 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 177 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
145 $::CONN->user_send ("rotateshoottype -"); 178 $::CONN->user_send ("rotateshoottype -");
146 } elsif ($uni == ord '"') { 179 } elsif ($uni == ord '"') {
150 $self->{completer}->set_prefix (""); 183 $self->{completer}->set_prefix ("");
151 $self->{completer}->show; 184 $self->{completer}->show;
152 } elsif (exists $DIR{$sym}) { 185 } elsif (exists $DIR{$sym}) {
153 if ($mod & CFClient::KMOD_SHIFT) { 186 if ($mod & CFClient::KMOD_SHIFT) {
154 $self->{shft}++; 187 $self->{shft}++;
188 if ($DIR{$sym}[0] != $self->{fire_dir}) {
155 $::CONN->user_send ("fire $DIR{$sym}[0]"); 189 $::CONN->user_send ("fire $DIR{$sym}[0]");
190 }
191 $self->{fire_dir} = $DIR{$sym}[0];
156 } elsif ($mod & CFClient::KMOD_CTRL) { 192 } elsif ($mod & CFClient::KMOD_CTRL) {
157 $self->{ctrl}++; 193 $self->{ctrl}++;
158 $::CONN->user_send ("run $DIR{$sym}[0]"); 194 $::CONN->user_send ("run $DIR{$sym}[0]");
159 } else { 195 } else {
160 $::CONN->user_send ("$DIR{$sym}[1]"); 196 $::CONN->user_send ("$DIR{$sym}[1]");
161 } 197 }
162 } 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')) {
163 $self->{completer}->key_down ($ev); 213 $self->{completer}->key_down ($ev);
164 $self->{completer}->show; 214 $self->{completer}->show;
215 } else {
216 return 0;
217 }
218
165 } 219 1
166} 220}
167 221
168sub key_up { 222sub key_up {
169 my ($self, $ev) = @_; 223 my ($self, $ev) = @_;
170 224
225 my $res = 0;
171 my $mod = $ev->{mod}; 226 my $mod = $ev->{mod};
172 my $sym = $ev->{sym}; 227 my $sym = $ev->{sym};
173 228
229 if ($::CFG->{shift_fire_stop}) {
174 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 230 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
175 $::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 }
176 } 245 }
246
177 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 247 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
178 $::CONN->user_send ("run_stop"); 248 $::CONN->user_send ("run_stop");
249 $res = 1;
179 } 250 }
251
252 $res
180} 253}
181 254
182sub draw { 255sub draw {
183 my ($self) = @_; 256 my ($self) = @_;
184 257
185 my $focused = $CFClient::UI::FOCUS == $self 258 my $focused = $CFClient::UI::FOCUS == $self
186 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 259 || $CFClient::UI::FOCUS == $self->{completer}{entry};
187 260
188 return 261 return
189 unless $focused || !$::FAST; 262 unless $::CONN && ($focused || !$::FAST);
190 263
191 if (delete $self->{need_update}) { 264 if (delete $self->{need_update}) {
265 $self->{fow_texture} ||= glGenTexture;
266
192 glNewList $self->{list}; 267 glNewList $self->{list};
193 268
194 if ($::MAP) { 269 if ($::MAP) {
195 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 270 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
196 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 271 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
197 272
198 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};
199 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;
200 277
201 glPushMatrix; 278 glPushMatrix;
202 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 279 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
203 280
204 glTranslate $sx0 - 32, $sy0 - 32, 0; 281 glTranslate $sx0, $sy0;
205 282
206 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);
207 284
208 if ($::CFG->{fow_enable}) { 285 if ($::CFG->{fow_enable}) {
209 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
210 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 287 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
211 glConvolutionFilter2D ( 288 glConvolutionFilter2D (
212 GL_CONVOLUTION_2D, 289 GL_CONVOLUTION_2D,
213 GL_ALPHA, 290 GL_ALPHA,
214 3, 3, 291 3, 3,
215 GL_ALPHA, GL_FLOAT, 292 GL_ALPHA, GL_FLOAT,
216 pack "f*", 293 (pack "f*", @{ $self->{smooth_matrix} }),
217 0.05, 0.13, 0.05,
218 0.13, 0.30, 0.13,
219 0.05, 0.13, 0.05,
220 ); 294 );
221 glEnable GL_CONVOLUTION_2D; 295 glEnable GL_CONVOLUTION_2D;
222 } 296 }
223 297
224 $self->{fow_texture_name} ||= glGenTexture; 298 $self->{fow_texture_name} ||= glGenTexture;
279# 353#
280# $label->show; 354# $label->show;
281# $label->update; 355# $label->update;
282# 356#
283# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 357# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
284# $label->move ( 358# $label->move_abs (
285# ($::WIDTH - $label->{w}) * 0.5, 359# ($::WIDTH - $label->{w}) * 0.5,
286# ($::HEIGHT - $label->{h}) * 0.5, 360# ($::HEIGHT - $label->{h}) * 0.5,
287# ); 361# );
288# }); 362# });
289# 363#
406 fontsize => $_, 480 fontsize => $_,
407 ), (0.8) x 16 481 ), (0.8) x 16
408 ]; 482 ];
409 483
410 $self->{entry} = new CFClient::UI::Entry 484 $self->{entry} = new CFClient::UI::Entry
411 connect_changed => sub { 485 on_changed => sub {
412 $self->update_labels; 486 $self->update_labels;
413 }, 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 },
414 connect_key_down => sub { 501 on_key_down => sub {
415 my ($entry, $ev) = @_; 502 my ($entry, $ev) = @_;
416 503
417 my $self = $entry->{parent}{parent}; 504 my $self = $entry->{parent}{parent};
418 505
419 if ($ev->{sym} == 13) { 506 if ($ev->{sym} == 13) {
420 if (exists $self->{select}) { 507 if (exists $self->{select}) {
421 $self->{last_command} = $self->{select}; 508 $self->{last_command} = $self->{select};
422 $::CONN->user_send ($self->{select}); 509 $::CONN->user_send ($self->{select});
510
511 unshift @{$self->{history}}, $self->{select};
512 $self->{hist_ptr} = 0;
513
423 $self->hide; 514 $self->hide;
424 } 515 }
425 } elsif ($ev->{sym} == 27) { 516 } elsif ($ev->{sym} == 27) {
517 $self->{hist_ptr} = 0;
426 $self->hide; 518 $self->hide;
427 return; 519 return;
428 } 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 {
429 ++$self->{select_offset} 528 ++$self->{select_offset}
430 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 529 if $self->{select_offset} < $#{ $self->{last_match} || [] };
530 }
431 $self->update_labels; 531 $self->update_labels;
432 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 532 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
533 if ($self->{select_offset}) {
433 --$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}}) {
434 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 }
435 $self->update_labels; 545 $self->update_labels;
436 } else { 546 } else {
437 return 0; 547 return 0;
438 } 548 }
439 549
458 568
459sub size_allocate { 569sub size_allocate {
460 my ($self, $w, $h) = @_; 570 my ($self, $w, $h) = @_;
461 571
462 $self->SUPER::size_allocate ($w, $h); 572 $self->SUPER::size_allocate ($w, $h);
463 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 573 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
464} 574}
465 575
466sub show { 576sub show {
467 my ($self) = @_; 577 my ($self) = @_;
468 578
478} 588}
479 589
480sub key_down { 590sub key_down {
481 my ($self, $ev) = @_; 591 my ($self, $ev) = @_;
482 592
483 $self->{entry}->key_down ($ev); 593 $self->{entry}->key_down ($ev)
484} 594}
485 595
486sub update_labels { 596sub update_labels {
487 my ($self) = @_; 597 my ($self) = @_;
488 598
521 631
522 @match = map $self->{command}{$_->[0]}, 632 @match = map $self->{command}{$_->[0]},
523 sort { 633 sort {
524 $a->[1] <=> $b->[1] 634 $a->[1] <=> $b->[1]
525 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 635 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
526 or (length $a->[0]) <=> (length $b->[0]) 636 or (length $b->[0]) <=> (length $a->[0])
527 } @match; 637 } @match;
528 } 638 }
529 639
530 $self->{last_search} = $cmd; 640 $self->{last_search} = $text;
531 $self->{last_match} = \@match; 641 $self->{last_match} = \@match;
532 642
533 $self->{select_offset} = 0; 643 $self->{select_offset} = 0;
534 } 644 }
535 645

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines