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.48 by elmex, Sat Jun 3 21:59:55 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
64 $::CFG->{map_shift_x} = $bw + $x - $ox; 70 $::CFG->{map_shift_x} = $bw + $x - $ox;
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 };
75 } elsif ($ev->{button} == 1) {
76 my ($ox, $oy) = ($ev->{x}, $ev->{y});
77
78 my $fx = int ((($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale})) + 0.99);
79 my $fy = int ((($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale})) + 0.99);
80 $fx += $::MAP->x;
81 $fy += $::MAP->y;
82
83 $::CONN->send (sprintf "lookat %d %d", $fx, $fy);
84
85 warn "FOOX: $fx (".$::MAP->ox.")\n";
86 warn "FOOY: $fy (".$::MAP->oy.")\n";
87 }
88
69 } 89 1
70} 90}
71 91
72sub button_up { 92sub button_up {
73 my ($self, $ev, $x, $y) = @_; 93 my ($self, $ev, $x, $y) = @_;
74 94
75 delete $self->{motion}; 95 delete $self->{motion};
96
97 1
76} 98}
77 99
78sub mouse_motion { 100sub mouse_motion {
79 my ($self, $ev, $x, $y) = @_; 101 my ($self, $ev, $x, $y) = @_;
80 102
103 if ($self->{motion}) {
81 $self->{motion}->($ev, $x, $y) if $self->{motion}; 104 $self->{motion}->($ev, $x, $y);
105 } else {
106 return 0;
107 }
108
109 1
82} 110}
83 111
84sub size_request { 112sub size_request {
85 ( 113 (
86 1 + 32 * int $::WIDTH / 32, 114 1 + 32 * int $::WIDTH / 32,
112); 140);
113 141
114sub key_down { 142sub key_down {
115 my ($self, $ev) = @_; 143 my ($self, $ev) = @_;
116 144
117 return unless $::CONN; 145 return 0 unless $::CONN;
118 146
119 my $mod = $ev->{mod}; 147 my $mod = $ev->{mod};
120 my $sym = $ev->{sym}; 148 my $sym = $ev->{sym};
121 my $uni = $ev->{unicode}; 149 my $uni = $ev->{unicode};
122 150
124 $::CONN->user_send ("stay fire"); 152 $::CONN->user_send ("stay fire");
125 } elsif ($uni == ord ",") { 153 } elsif ($uni == ord ",") {
126 $::CONN->user_send ("take"); 154 $::CONN->user_send ("take");
127 } elsif ($uni == ord " ") { 155 } elsif ($uni == ord " ") {
128 $::CONN->user_send ("apply"); 156 $::CONN->user_send ("apply");
157 } elsif ($uni == ord ".") {
158 $::CONN->user_send ($self->{completer}{last_command})
159 if exists $self->{completer}{last_command};
129 } elsif ($uni == ord "\t") { 160 } elsif ($uni == ord "\t") {
130 # TODO: toggle inventory 161 $::INV_WINDOW->toggle_visibility;
131 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 162 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
132 $::CONN->user_send ("rotateshoottype +"); 163 $::CONN->user_send ("rotateshoottype +");
133 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 164 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
134 $::CONN->user_send ("rotateshoottype -"); 165 $::CONN->user_send ("rotateshoottype -");
135 } elsif ($uni == ord '"') { 166 } elsif ($uni == ord '"') {
146 $self->{ctrl}++; 177 $self->{ctrl}++;
147 $::CONN->user_send ("run $DIR{$sym}[0]"); 178 $::CONN->user_send ("run $DIR{$sym}[0]");
148 } else { 179 } else {
149 $::CONN->user_send ("$DIR{$sym}[1]"); 180 $::CONN->user_send ("$DIR{$sym}[1]");
150 } 181 }
151 } elsif ($ev->{unicode}) { 182 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
183 $::BIND_EDITOR->set_binding (undef, undef, [],
184 sub {
185 my ($mod, $sym, $cmds) = @_;
186 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
187 });
188 $::BIND_EDITOR->start;
189 $::BIND_EDITOR->show;
190 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
191 $::BIND_EDITOR->stop;
192 $::BIND_EDITOR->ask_for_bind_and_commit;
193 $::BIND_EDITOR->hide;
194 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
195 $::CONN->user_send ($_) for @$bind_cmd;
196 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
152 $self->{completer}->key_down ($ev); 197 $self->{completer}->key_down ($ev);
153 $self->{completer}->show; 198 $self->{completer}->show;
199 } else {
200 return 0;
201 }
202
154 } 203 1
155} 204}
156 205
157sub key_up { 206sub key_up {
158 my ($self, $ev) = @_; 207 my ($self, $ev) = @_;
159 208
209 my $res = 0;
160 my $mod = $ev->{mod}; 210 my $mod = $ev->{mod};
161 my $sym = $ev->{sym}; 211 my $sym = $ev->{sym};
162 212
163 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 213 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
164 $::CONN->user_send ("fire_stop"); 214 $::CONN->user_send ("fire_stop");
215 $res = 1;
165 } 216 }
217
166 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 218 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
167 $::CONN->user_send ("run_stop"); 219 $::CONN->user_send ("run_stop");
220 $res = 1;
168 } 221 }
222
223 $res
169} 224}
170 225
171sub draw { 226sub draw {
172 my ($self) = @_; 227 my ($self) = @_;
173 228
193 glTranslate $sx0 - 32, $sy0 - 32, 0; 248 glTranslate $sx0 - 32, $sy0 - 32, 0;
194 249
195 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 250 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
196 251
197 if ($::CFG->{fow_enable}) { 252 if ($::CFG->{fow_enable}) {
198 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war 253 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); 254 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
200 glConvolutionFilter2D ( 255 glConvolutionFilter2D (
201 GL_CONVOLUTION_2D, 256 GL_CONVOLUTION_2D,
202 GL_ALPHA, 257 GL_ALPHA,
203 3, 3, 258 3, 3,
256 glVertex $::WIDTH, $::HEIGHT; 311 glVertex $::WIDTH, $::HEIGHT;
257 glVertex $::WIDTH, 0; 312 glVertex $::WIDTH, 0;
258 glEnd; 313 glEnd;
259 glDisable GL_BLEND; 314 glDisable GL_BLEND;
260 315
261 $self->{out_of_focus} ||= do { 316# $self->{out_of_focus} ||= do {
262 my $label = new CFClient::UI::Label 317# my $label = new CFClient::UI::Label
263 x => 0, 318# x => 0,
264 y => 0, 319# y => 0,
265 z => 1, 320# z => 1,
266 ellipsise => 0, 321# ellipsise => 0,
267 text => "map out of focus (click map to play)"; 322# text => "map out of focus (click map to play)";
268 323#
269 $label->show; 324# $label->show;
270 $label->update; 325# $label->update;
271 326#
272 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 327# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
273 $label->move ( 328# $label->move_abs (
274 ($::WIDTH - $label->{w}) * 0.5, 329# ($::WIDTH - $label->{w}) * 0.5,
275 ($::HEIGHT - $label->{h}) * 0.5, 330# ($::HEIGHT - $label->{h}) * 0.5,
276 ); 331# );
277 }); 332# });
278 333#
279 $label 334# $label
280 }; 335# };
281 } 336 }
282} 337}
283 338
284sub DESTROY { 339sub DESTROY {
285 my $self = shift; 340 my $self = shift;
395 fontsize => $_, 450 fontsize => $_,
396 ), (0.8) x 16 451 ), (0.8) x 16
397 ]; 452 ];
398 453
399 $self->{entry} = new CFClient::UI::Entry 454 $self->{entry} = new CFClient::UI::Entry
400 connect_changed => sub { 455 on_changed => sub {
401 $self->update_labels; 456 $self->update_labels;
402 }, 457 },
403 connect_key_down => sub { 458 on_key_down => sub {
404 my ($entry, $ev) = @_; 459 my ($entry, $ev) = @_;
405 460
406 my $self = $entry->{parent}{parent}; 461 my $self = $entry->{parent}{parent};
407 462
408 if ($ev->{sym} == 13) { 463 if ($ev->{sym} == 13) {
409 if (exists $self->{select}) { 464 if (exists $self->{select}) {
465 $self->{last_command} = $self->{select};
410 $::CONN->user_send ($self->{select}); 466 $::CONN->user_send ($self->{select});
411 $self->hide; 467 $self->hide;
412 } 468 }
413 } elsif ($ev->{sym} == 27) { 469 } elsif ($ev->{sym} == 27) {
414 $self->hide; 470 $self->hide;
446 502
447sub size_allocate { 503sub size_allocate {
448 my ($self, $w, $h) = @_; 504 my ($self, $w, $h) = @_;
449 505
450 $self->SUPER::size_allocate ($w, $h); 506 $self->SUPER::size_allocate ($w, $h);
451 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 507 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
452} 508}
453 509
454sub show { 510sub show {
455 my ($self) = @_; 511 my ($self) = @_;
456 512
466} 522}
467 523
468sub key_down { 524sub key_down {
469 my ($self, $ev) = @_; 525 my ($self, $ev) = @_;
470 526
471 $self->{entry}->key_down ($ev); 527 $self->{entry}->key_down ($ev)
472} 528}
473 529
474sub update_labels { 530sub update_labels {
475 my ($self) = @_; 531 my ($self) = @_;
476 532
509 565
510 @match = map $self->{command}{$_->[0]}, 566 @match = map $self->{command}{$_->[0]},
511 sort { 567 sort {
512 $a->[1] <=> $b->[1] 568 $a->[1] <=> $b->[1]
513 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 569 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
514 or (length $a->[0]) <=> (length $b->[0]) 570 or (length $b->[0]) <=> (length $a->[0])
515 } @match; 571 } @match;
516 } 572 }
517 573
518 $self->{last_search} = $cmd; 574 $self->{last_search} = $text;
519 $self->{last_match} = \@match; 575 $self->{last_match} = \@match;
520 576
521 $self->{select_offset} = 0; 577 $self->{select_offset} = 0;
522 } 578 }
523 579

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines