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.47 by root, Fri Jun 2 22:13:47 2006 UTC

20 ); 20 );
21 21
22 $self->{completer} = new CFClient::MapWidget::Command:: 22 $self->{completer} = new CFClient::MapWidget::Command::
23 command => $self->{command}, 23 command => $self->{command},
24 can_focus => 1, 24 can_focus => 1,
25 tooltip => "<b>The Command Completer</b>\n\n"
26 . "This is your central interface to send text commands to the server. "
27 . "To enter a verbatim command to send to the server, just type the command, "
28 . "followed by a space, and press return. "
29 . "Typing the initial letters of words (or just any letters) displays guesses "
30 . "for commands you might want to use.\n"
31 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n"
32 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.",
25 ; 33 ;
26 34
27 $self 35 $self
28} 36}
29 37
31 my ($self, $command, $tooltip, $widget, $cb) = @_; 39 my ($self, $command, $tooltip, $widget, $cb) = @_;
32 40
33 (my $data = $command) =~ s/\\//g; 41 (my $data = $command) =~ s/\\//g;
34 42
35 $tooltip =~ s/^\s+//; 43 $tooltip =~ s/^\s+//;
36
37 $tooltip = "<big>$data</big>\n\n$tooltip"; 44 $tooltip = "<big>$data</big>\n\n$tooltip";
38
39 $tooltip =~ s/\s+$//; 45 $tooltip =~ s/\s+$//;
40 46
41 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; 47 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
42} 48}
43 49
65 $::CFG->{map_shift_y} = $bh + $y - $oy; 71 $::CFG->{map_shift_y} = $bh + $y - $oy;
66 72
67 $self->update; 73 $self->update;
68 }; 74 };
69 } 75 }
76
77 1
70} 78}
71 79
72sub button_up { 80sub button_up {
73 my ($self, $ev, $x, $y) = @_; 81 my ($self, $ev, $x, $y) = @_;
74 82
75 delete $self->{motion}; 83 delete $self->{motion};
84
85 1
76} 86}
77 87
78sub mouse_motion { 88sub mouse_motion {
79 my ($self, $ev, $x, $y) = @_; 89 my ($self, $ev, $x, $y) = @_;
80 90
91 if ($self->{motion}) {
81 $self->{motion}->($ev, $x, $y) if $self->{motion}; 92 $self->{motion}->($ev, $x, $y);
93 } else {
94 return 0;
95 }
96
97 1
82} 98}
83 99
84sub size_request { 100sub size_request {
85 ( 101 (
86 1 + 32 * int $::WIDTH / 32, 102 1 + 32 * int $::WIDTH / 32,
112); 128);
113 129
114sub key_down { 130sub key_down {
115 my ($self, $ev) = @_; 131 my ($self, $ev) = @_;
116 132
117 return unless $::CONN; 133 return 0 unless $::CONN;
118 134
119 my $mod = $ev->{mod}; 135 my $mod = $ev->{mod};
120 my $sym = $ev->{sym}; 136 my $sym = $ev->{sym};
121 my $uni = $ev->{unicode}; 137 my $uni = $ev->{unicode};
122 138
124 $::CONN->user_send ("stay fire"); 140 $::CONN->user_send ("stay fire");
125 } elsif ($uni == ord ",") { 141 } elsif ($uni == ord ",") {
126 $::CONN->user_send ("take"); 142 $::CONN->user_send ("take");
127 } elsif ($uni == ord " ") { 143 } elsif ($uni == ord " ") {
128 $::CONN->user_send ("apply"); 144 $::CONN->user_send ("apply");
145 } elsif ($uni == ord ".") {
146 $::CONN->user_send ($self->{completer}{last_command})
147 if exists $self->{completer}{last_command};
129 } elsif ($uni == ord "\t") { 148 } elsif ($uni == ord "\t") {
130 # TODO: toggle inventory 149 $::INV_WINDOW->toggle_visibility;
131 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 150 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
132 $::CONN->user_send ("rotateshoottype +"); 151 $::CONN->user_send ("rotateshoottype +");
133 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 152 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
134 $::CONN->user_send ("rotateshoottype -"); 153 $::CONN->user_send ("rotateshoottype -");
135 } elsif ($uni == ord '"') { 154 } elsif ($uni == ord '"') {
146 $self->{ctrl}++; 165 $self->{ctrl}++;
147 $::CONN->user_send ("run $DIR{$sym}[0]"); 166 $::CONN->user_send ("run $DIR{$sym}[0]");
148 } else { 167 } else {
149 $::CONN->user_send ("$DIR{$sym}[1]"); 168 $::CONN->user_send ("$DIR{$sym}[1]");
150 } 169 }
151 } elsif ($ev->{unicode}) { 170 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
171 $::BIND_EDITOR->set_binding (undef, undef, [],
172 sub {
173 my ($mod, $sym, $cmds) = @_;
174 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
175 });
176 $::BIND_EDITOR->start;
177 $::BIND_EDITOR->show;
178 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
179 $::BIND_EDITOR->stop;
180 $::BIND_EDITOR->ask_for_bind_and_commit;
181 $::BIND_EDITOR->hide;
182 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
183 $::CONN->user_send ($_) for @$bind_cmd;
184 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
152 $self->{completer}->key_down ($ev); 185 $self->{completer}->key_down ($ev);
153 $self->{completer}->show; 186 $self->{completer}->show;
187 } else {
188 return 0;
189 }
190
154 } 191 1
155} 192}
156 193
157sub key_up { 194sub key_up {
158 my ($self, $ev) = @_; 195 my ($self, $ev) = @_;
159 196
197 my $res = 0;
160 my $mod = $ev->{mod}; 198 my $mod = $ev->{mod};
161 my $sym = $ev->{sym}; 199 my $sym = $ev->{sym};
162 200
163 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 201 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
164 $::CONN->user_send ("fire_stop"); 202 $::CONN->user_send ("fire_stop");
203 $res = 1;
165 } 204 }
205
166 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 206 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
167 $::CONN->user_send ("run_stop"); 207 $::CONN->user_send ("run_stop");
208 $res = 1;
168 } 209 }
210
211 $res
169} 212}
170 213
171sub draw { 214sub draw {
172 my ($self) = @_; 215 my ($self) = @_;
173 216
193 glTranslate $sx0 - 32, $sy0 - 32, 0; 236 glTranslate $sx0 - 32, $sy0 - 32, 0;
194 237
195 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 238 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
196 239
197 if ($::CFG->{fow_enable}) { 240 if ($::CFG->{fow_enable}) {
198 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war 241 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); 242 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
200 glConvolutionFilter2D ( 243 glConvolutionFilter2D (
201 GL_CONVOLUTION_2D, 244 GL_CONVOLUTION_2D,
202 GL_ALPHA, 245 GL_ALPHA,
203 3, 3, 246 3, 3,
256 glVertex $::WIDTH, $::HEIGHT; 299 glVertex $::WIDTH, $::HEIGHT;
257 glVertex $::WIDTH, 0; 300 glVertex $::WIDTH, 0;
258 glEnd; 301 glEnd;
259 glDisable GL_BLEND; 302 glDisable GL_BLEND;
260 303
261 $self->{out_of_focus} ||= do { 304# $self->{out_of_focus} ||= do {
262 my $label = new CFClient::UI::Label 305# my $label = new CFClient::UI::Label
263 x => 0, 306# x => 0,
264 y => 0, 307# y => 0,
265 z => 1, 308# z => 1,
266 ellipsise => 0, 309# ellipsise => 0,
267 text => "map out of focus (click map to play)"; 310# text => "map out of focus (click map to play)";
268 311#
269 $label->show; 312# $label->show;
270 $label->update; 313# $label->update;
271 314#
272 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 315# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
273 $label->move ( 316# $label->move_abs (
274 ($::WIDTH - $label->{w}) * 0.5, 317# ($::WIDTH - $label->{w}) * 0.5,
275 ($::HEIGHT - $label->{h}) * 0.5, 318# ($::HEIGHT - $label->{h}) * 0.5,
276 ); 319# );
277 }); 320# });
278 321#
279 $label 322# $label
280 }; 323# };
281 } 324 }
282} 325}
283 326
284sub DESTROY { 327sub DESTROY {
285 my $self = shift; 328 my $self = shift;
395 fontsize => $_, 438 fontsize => $_,
396 ), (0.8) x 16 439 ), (0.8) x 16
397 ]; 440 ];
398 441
399 $self->{entry} = new CFClient::UI::Entry 442 $self->{entry} = new CFClient::UI::Entry
400 connect_changed => sub { 443 on_changed => sub {
401 $self->update_labels; 444 $self->update_labels;
402 }, 445 },
403 connect_key_down => sub { 446 on_key_down => sub {
404 my ($entry, $ev) = @_; 447 my ($entry, $ev) = @_;
405 448
406 my $self = $entry->{parent}{parent}; 449 my $self = $entry->{parent}{parent};
407 450
408 if ($ev->{sym} == 13) { 451 if ($ev->{sym} == 13) {
409 if (exists $self->{select}) { 452 if (exists $self->{select}) {
453 $self->{last_command} = $self->{select};
410 $::CONN->user_send ($self->{select}); 454 $::CONN->user_send ($self->{select});
411 $self->hide; 455 $self->hide;
412 } 456 }
413 } elsif ($ev->{sym} == 27) { 457 } elsif ($ev->{sym} == 27) {
414 $self->hide; 458 $self->hide;
446 490
447sub size_allocate { 491sub size_allocate {
448 my ($self, $w, $h) = @_; 492 my ($self, $w, $h) = @_;
449 493
450 $self->SUPER::size_allocate ($w, $h); 494 $self->SUPER::size_allocate ($w, $h);
451 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 495 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
452} 496}
453 497
454sub show { 498sub show {
455 my ($self) = @_; 499 my ($self) = @_;
456 500
466} 510}
467 511
468sub key_down { 512sub key_down {
469 my ($self, $ev) = @_; 513 my ($self, $ev) = @_;
470 514
471 $self->{entry}->key_down ($ev); 515 $self->{entry}->key_down ($ev)
472} 516}
473 517
474sub update_labels { 518sub update_labels {
475 my ($self) = @_; 519 my ($self) = @_;
476 520
509 553
510 @match = map $self->{command}{$_->[0]}, 554 @match = map $self->{command}{$_->[0]},
511 sort { 555 sort {
512 $a->[1] <=> $b->[1] 556 $a->[1] <=> $b->[1]
513 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 557 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
514 or (length $a->[0]) <=> (length $b->[0]) 558 or (length $b->[0]) <=> (length $a->[0])
515 } @match; 559 } @match;
516 } 560 }
517 561
518 $self->{last_search} = $cmd; 562 $self->{last_search} = $text;
519 $self->{last_match} = \@match; 563 $self->{last_match} = \@match;
520 564
521 $self->{select_offset} = 0; 565 $self->{select_offset} = 0;
522 } 566 }
523 567

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines