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.57 by elmex, Tue Jun 13 11:01:04 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
58sub button_down { 63sub button_down {
59 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
60 65
61 $self->focus_in; 66 $self->focus_in;
62 67
63 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) {
64 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 85 my ($ox, $oy) = ($ev->{x}, $ev->{y});
65 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 86 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
66 87
67 $self->{motion} = sub { 88 $self->{motion} = sub {
68 my ($ev, $x, $y) = @_; 89 my ($ev, $x, $y) = @_;
73 $::CFG->{map_shift_y} = $bh + $y - $oy; 94 $::CFG->{map_shift_y} = $bh + $y - $oy;
74 95
75 $self->update; 96 $self->update;
76 }; 97 };
77 } 98 }
99
100 1
78} 101}
79 102
80sub button_up { 103sub button_up {
81 my ($self, $ev, $x, $y) = @_; 104 my ($self, $ev, $x, $y) = @_;
82 105
83 delete $self->{motion}; 106 delete $self->{motion};
107
108 1
84} 109}
85 110
86sub mouse_motion { 111sub mouse_motion {
87 my ($self, $ev, $x, $y) = @_; 112 my ($self, $ev, $x, $y) = @_;
88 113
114 if ($self->{motion}) {
89 $self->{motion}->($ev, $x, $y) if $self->{motion}; 115 $self->{motion}->($ev, $x, $y);
116 } else {
117 return 0;
118 }
119
120 1
90} 121}
91 122
92sub size_request { 123sub size_request {
93 ( 124 (
94 1 + 32 * int $::WIDTH / 32, 125 1 + 32 * int $::WIDTH / 32,
120); 151);
121 152
122sub key_down { 153sub key_down {
123 my ($self, $ev) = @_; 154 my ($self, $ev) = @_;
124 155
125 return unless $::CONN; 156 return 0 unless $::CONN;
126 157
127 my $mod = $ev->{mod}; 158 my $mod = $ev->{mod};
128 my $sym = $ev->{sym}; 159 my $sym = $ev->{sym};
129 my $uni = $ev->{unicode}; 160 my $uni = $ev->{unicode};
130 161
136 $::CONN->user_send ("apply"); 167 $::CONN->user_send ("apply");
137 } elsif ($uni == ord ".") { 168 } elsif ($uni == ord ".") {
138 $::CONN->user_send ($self->{completer}{last_command}) 169 $::CONN->user_send ($self->{completer}{last_command})
139 if exists $self->{completer}{last_command}; 170 if exists $self->{completer}{last_command};
140 } elsif ($uni == ord "\t") { 171 } elsif ($uni == ord "\t") {
141 # TODO: toggle inventory 172 $::INV_WINDOW->toggle_visibility;
142 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 173 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
143 $::CONN->user_send ("rotateshoottype +"); 174 $::CONN->user_send ("rotateshoottype +");
144 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 175 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
145 $::CONN->user_send ("rotateshoottype -"); 176 $::CONN->user_send ("rotateshoottype -");
146 } elsif ($uni == ord '"') { 177 } elsif ($uni == ord '"') {
157 $self->{ctrl}++; 188 $self->{ctrl}++;
158 $::CONN->user_send ("run $DIR{$sym}[0]"); 189 $::CONN->user_send ("run $DIR{$sym}[0]");
159 } else { 190 } else {
160 $::CONN->user_send ("$DIR{$sym}[1]"); 191 $::CONN->user_send ("$DIR{$sym}[1]");
161 } 192 }
162 } 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')) {
163 $self->{completer}->key_down ($ev); 208 $self->{completer}->key_down ($ev);
164 $self->{completer}->show; 209 $self->{completer}->show;
210 } else {
211 return 0;
212 }
213
165 } 214 1
166} 215}
167 216
168sub key_up { 217sub key_up {
169 my ($self, $ev) = @_; 218 my ($self, $ev) = @_;
170 219
220 my $res = 0;
171 my $mod = $ev->{mod}; 221 my $mod = $ev->{mod};
172 my $sym = $ev->{sym}; 222 my $sym = $ev->{sym};
173 223
174 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 224 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
175 $::CONN->user_send ("fire_stop"); 225 $::CONN->user_send ("fire_stop");
226 $res = 1;
176 } 227 }
228
177 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 229 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
178 $::CONN->user_send ("run_stop"); 230 $::CONN->user_send ("run_stop");
231 $res = 1;
179 } 232 }
233
234 $res
180} 235}
181 236
182sub draw { 237sub draw {
183 my ($self) = @_; 238 my ($self) = @_;
184 239
190 245
191 if (delete $self->{need_update}) { 246 if (delete $self->{need_update}) {
192 glNewList $self->{list}; 247 glNewList $self->{list};
193 248
194 if ($::MAP) { 249 if ($::MAP) {
195 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 250 my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
196 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 251 my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
197 252
198 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};
199 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;
200 257
201 glPushMatrix; 258 glPushMatrix;
202 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 259 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
203 260
204 glTranslate $sx0 - 32, $sy0 - 32, 0; 261 glTranslate $sx0, $sy0;
205 262
206 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);
207 264
208 if ($::CFG->{fow_enable}) { 265 if ($::CFG->{fow_enable}) {
209 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
210 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 267 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
211 glConvolutionFilter2D ( 268 glConvolutionFilter2D (
212 GL_CONVOLUTION_2D, 269 GL_CONVOLUTION_2D,
213 GL_ALPHA, 270 GL_ALPHA,
214 3, 3, 271 3, 3,
215 GL_ALPHA, GL_FLOAT, 272 GL_ALPHA, GL_FLOAT,
216 pack "f*", 273 (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 ); 274 );
221 glEnable GL_CONVOLUTION_2D; 275 glEnable GL_CONVOLUTION_2D;
222 } 276 }
223 277
224 $self->{fow_texture_name} ||= glGenTexture; 278 $self->{fow_texture_name} ||= glGenTexture;
279# 333#
280# $label->show; 334# $label->show;
281# $label->update; 335# $label->update;
282# 336#
283# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 337# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
284# $label->move ( 338# $label->move_abs (
285# ($::WIDTH - $label->{w}) * 0.5, 339# ($::WIDTH - $label->{w}) * 0.5,
286# ($::HEIGHT - $label->{h}) * 0.5, 340# ($::HEIGHT - $label->{h}) * 0.5,
287# ); 341# );
288# }); 342# });
289# 343#
406 fontsize => $_, 460 fontsize => $_,
407 ), (0.8) x 16 461 ), (0.8) x 16
408 ]; 462 ];
409 463
410 $self->{entry} = new CFClient::UI::Entry 464 $self->{entry} = new CFClient::UI::Entry
411 connect_changed => sub { 465 on_changed => sub {
412 $self->update_labels; 466 $self->update_labels;
413 }, 467 },
468 on_button_down => sub {
469 my ($entry, $ev, $x, $y) = @_;
470
471 if ($ev->{button} == 3) {
472 (new CFClient::UI::Menu
473 items => [
474 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }]
475 ],
476 )->popup ($ev);
477 return 1;
478 }
479 0
480 },
414 connect_key_down => sub { 481 on_key_down => sub {
415 my ($entry, $ev) = @_; 482 my ($entry, $ev) = @_;
416 483
417 my $self = $entry->{parent}{parent}; 484 my $self = $entry->{parent}{parent};
418 485
419 if ($ev->{sym} == 13) { 486 if ($ev->{sym} == 13) {
420 if (exists $self->{select}) { 487 if (exists $self->{select}) {
421 $self->{last_command} = $self->{select}; 488 $self->{last_command} = $self->{select};
422 $::CONN->user_send ($self->{select}); 489 $::CONN->user_send ($self->{select});
490
491 unshift @{$self->{history}}, $self->{select};
492 $self->{hist_ptr} = 0;
493
423 $self->hide; 494 $self->hide;
424 } 495 }
425 } elsif ($ev->{sym} == 27) { 496 } elsif ($ev->{sym} == 27) {
497 $self->{hist_ptr} = 0;
426 $self->hide; 498 $self->hide;
427 return; 499 return;
428 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 500 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
501 if ($self->{hist_ptr} > 1) {
502 $self->{hist_ptr}--;
503 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
504 } elsif ($self->{hist_ptr} > 0) {
505 $self->{hist_ptr}--;
506 $self->{entry}->set_text ($self->{hist_saveback});
507 } else {
429 ++$self->{select_offset} 508 ++$self->{select_offset}
430 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 509 if $self->{select_offset} < $#{ $self->{last_match} || [] };
510 }
431 $self->update_labels; 511 $self->update_labels;
432 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 512 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
513 if ($self->{select_offset}) {
433 --$self->{select_offset} 514 --$self->{select_offset}
515 } else {
516 unless ($self->{hist_ptr}) {
517 $self->{hist_saveback} = $self->{entry}->get_text;
518 }
519 if ($self->{hist_ptr} <= $#{$self->{history}}) {
434 if $self->{select_offset}; 520 $self->{hist_ptr}++;
521 }
522 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
523 if exists $self->{history}->[$self->{hist_ptr} - 1];
524 }
435 $self->update_labels; 525 $self->update_labels;
436 } else { 526 } else {
437 return 0; 527 return 0;
438 } 528 }
439 529
458 548
459sub size_allocate { 549sub size_allocate {
460 my ($self, $w, $h) = @_; 550 my ($self, $w, $h) = @_;
461 551
462 $self->SUPER::size_allocate ($w, $h); 552 $self->SUPER::size_allocate ($w, $h);
463 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 553 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
464} 554}
465 555
466sub show { 556sub show {
467 my ($self) = @_; 557 my ($self) = @_;
468 558
478} 568}
479 569
480sub key_down { 570sub key_down {
481 my ($self, $ev) = @_; 571 my ($self, $ev) = @_;
482 572
483 $self->{entry}->key_down ($ev); 573 $self->{entry}->key_down ($ev)
484} 574}
485 575
486sub update_labels { 576sub update_labels {
487 my ($self) = @_; 577 my ($self) = @_;
488 578
521 611
522 @match = map $self->{command}{$_->[0]}, 612 @match = map $self->{command}{$_->[0]},
523 sort { 613 sort {
524 $a->[1] <=> $b->[1] 614 $a->[1] <=> $b->[1]
525 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 615 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
526 or (length $a->[0]) <=> (length $b->[0]) 616 or (length $b->[0]) <=> (length $a->[0])
527 } @match; 617 } @match;
528 } 618 }
529 619
530 $self->{last_search} = $cmd; 620 $self->{last_search} = $text;
531 $self->{last_match} = \@match; 621 $self->{last_match} = \@match;
532 622
533 $self->{select_offset} = 0; 623 $self->{select_offset} = 0;
534 } 624 }
535 625

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines