… | |
… | |
39 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
39 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
40 | |
40 | |
41 | (my $data = $command) =~ s/\\//g; |
41 | (my $data = $command) =~ s/\\//g; |
42 | |
42 | |
43 | $tooltip =~ s/^\s+//; |
43 | $tooltip =~ s/^\s+//; |
44 | |
|
|
45 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
44 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
46 | |
|
|
47 | $tooltip =~ s/\s+$//; |
45 | $tooltip =~ s/\s+$//; |
48 | |
46 | |
49 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
47 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
50 | } |
48 | } |
51 | |
49 | |
… | |
… | |
72 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
70 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
73 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
71 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
74 | |
72 | |
75 | $self->update; |
73 | $self->update; |
76 | }; |
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 | |
77 | } |
89 | 1 |
78 | } |
90 | } |
79 | |
91 | |
80 | sub button_up { |
92 | sub button_up { |
81 | my ($self, $ev, $x, $y) = @_; |
93 | my ($self, $ev, $x, $y) = @_; |
82 | |
94 | |
83 | delete $self->{motion}; |
95 | delete $self->{motion}; |
|
|
96 | |
|
|
97 | 1 |
84 | } |
98 | } |
85 | |
99 | |
86 | sub mouse_motion { |
100 | sub mouse_motion { |
87 | my ($self, $ev, $x, $y) = @_; |
101 | my ($self, $ev, $x, $y) = @_; |
88 | |
102 | |
|
|
103 | if ($self->{motion}) { |
89 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
104 | $self->{motion}->($ev, $x, $y); |
|
|
105 | } else { |
|
|
106 | return 0; |
|
|
107 | } |
|
|
108 | |
|
|
109 | 1 |
90 | } |
110 | } |
91 | |
111 | |
92 | sub size_request { |
112 | sub size_request { |
93 | ( |
113 | ( |
94 | 1 + 32 * int $::WIDTH / 32, |
114 | 1 + 32 * int $::WIDTH / 32, |
… | |
… | |
120 | ); |
140 | ); |
121 | |
141 | |
122 | sub key_down { |
142 | sub key_down { |
123 | my ($self, $ev) = @_; |
143 | my ($self, $ev) = @_; |
124 | |
144 | |
125 | return unless $::CONN; |
145 | return 0 unless $::CONN; |
126 | |
146 | |
127 | my $mod = $ev->{mod}; |
147 | my $mod = $ev->{mod}; |
128 | my $sym = $ev->{sym}; |
148 | my $sym = $ev->{sym}; |
129 | my $uni = $ev->{unicode}; |
149 | my $uni = $ev->{unicode}; |
130 | |
150 | |
… | |
… | |
136 | $::CONN->user_send ("apply"); |
156 | $::CONN->user_send ("apply"); |
137 | } elsif ($uni == ord ".") { |
157 | } elsif ($uni == ord ".") { |
138 | $::CONN->user_send ($self->{completer}{last_command}) |
158 | $::CONN->user_send ($self->{completer}{last_command}) |
139 | if exists $self->{completer}{last_command}; |
159 | if exists $self->{completer}{last_command}; |
140 | } elsif ($uni == ord "\t") { |
160 | } elsif ($uni == ord "\t") { |
141 | # TODO: toggle inventory |
161 | $::INV_WINDOW->toggle_visibility; |
142 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
162 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
143 | $::CONN->user_send ("rotateshoottype +"); |
163 | $::CONN->user_send ("rotateshoottype +"); |
144 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
164 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
145 | $::CONN->user_send ("rotateshoottype -"); |
165 | $::CONN->user_send ("rotateshoottype -"); |
146 | } elsif ($uni == ord '"') { |
166 | } elsif ($uni == ord '"') { |
… | |
… | |
157 | $self->{ctrl}++; |
177 | $self->{ctrl}++; |
158 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
178 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
159 | } else { |
179 | } else { |
160 | $::CONN->user_send ("$DIR{$sym}[1]"); |
180 | $::CONN->user_send ("$DIR{$sym}[1]"); |
161 | } |
181 | } |
162 | } 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')) { |
163 | $self->{completer}->key_down ($ev); |
197 | $self->{completer}->key_down ($ev); |
164 | $self->{completer}->show; |
198 | $self->{completer}->show; |
|
|
199 | } else { |
|
|
200 | return 0; |
|
|
201 | } |
|
|
202 | |
165 | } |
203 | 1 |
166 | } |
204 | } |
167 | |
205 | |
168 | sub key_up { |
206 | sub key_up { |
169 | my ($self, $ev) = @_; |
207 | my ($self, $ev) = @_; |
170 | |
208 | |
|
|
209 | my $res = 0; |
171 | my $mod = $ev->{mod}; |
210 | my $mod = $ev->{mod}; |
172 | my $sym = $ev->{sym}; |
211 | my $sym = $ev->{sym}; |
173 | |
212 | |
174 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
213 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
175 | $::CONN->user_send ("fire_stop"); |
214 | $::CONN->user_send ("fire_stop"); |
|
|
215 | $res = 1; |
176 | } |
216 | } |
|
|
217 | |
177 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
218 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
178 | $::CONN->user_send ("run_stop"); |
219 | $::CONN->user_send ("run_stop"); |
|
|
220 | $res = 1; |
179 | } |
221 | } |
|
|
222 | |
|
|
223 | $res |
180 | } |
224 | } |
181 | |
225 | |
182 | sub draw { |
226 | sub draw { |
183 | my ($self) = @_; |
227 | my ($self) = @_; |
184 | |
228 | |
… | |
… | |
204 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
248 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
205 | |
249 | |
206 | 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); |
207 | |
251 | |
208 | if ($::CFG->{fow_enable}) { |
252 | if ($::CFG->{fow_enable}) { |
209 | 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 |
210 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
254 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
211 | glConvolutionFilter2D ( |
255 | glConvolutionFilter2D ( |
212 | GL_CONVOLUTION_2D, |
256 | GL_CONVOLUTION_2D, |
213 | GL_ALPHA, |
257 | GL_ALPHA, |
214 | 3, 3, |
258 | 3, 3, |
… | |
… | |
279 | # |
323 | # |
280 | # $label->show; |
324 | # $label->show; |
281 | # $label->update; |
325 | # $label->update; |
282 | # |
326 | # |
283 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
327 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
284 | # $label->move ( |
328 | # $label->move_abs ( |
285 | # ($::WIDTH - $label->{w}) * 0.5, |
329 | # ($::WIDTH - $label->{w}) * 0.5, |
286 | # ($::HEIGHT - $label->{h}) * 0.5, |
330 | # ($::HEIGHT - $label->{h}) * 0.5, |
287 | # ); |
331 | # ); |
288 | # }); |
332 | # }); |
289 | # |
333 | # |
… | |
… | |
406 | fontsize => $_, |
450 | fontsize => $_, |
407 | ), (0.8) x 16 |
451 | ), (0.8) x 16 |
408 | ]; |
452 | ]; |
409 | |
453 | |
410 | $self->{entry} = new CFClient::UI::Entry |
454 | $self->{entry} = new CFClient::UI::Entry |
411 | connect_changed => sub { |
455 | on_changed => sub { |
412 | $self->update_labels; |
456 | $self->update_labels; |
413 | }, |
457 | }, |
414 | connect_key_down => sub { |
458 | on_key_down => sub { |
415 | my ($entry, $ev) = @_; |
459 | my ($entry, $ev) = @_; |
416 | |
460 | |
417 | my $self = $entry->{parent}{parent}; |
461 | my $self = $entry->{parent}{parent}; |
418 | |
462 | |
419 | if ($ev->{sym} == 13) { |
463 | if ($ev->{sym} == 13) { |
… | |
… | |
458 | |
502 | |
459 | sub size_allocate { |
503 | sub size_allocate { |
460 | my ($self, $w, $h) = @_; |
504 | my ($self, $w, $h) = @_; |
461 | |
505 | |
462 | $self->SUPER::size_allocate ($w, $h); |
506 | $self->SUPER::size_allocate ($w, $h); |
463 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
507 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
464 | } |
508 | } |
465 | |
509 | |
466 | sub show { |
510 | sub show { |
467 | my ($self) = @_; |
511 | my ($self) = @_; |
468 | |
512 | |
… | |
… | |
478 | } |
522 | } |
479 | |
523 | |
480 | sub key_down { |
524 | sub key_down { |
481 | my ($self, $ev) = @_; |
525 | my ($self, $ev) = @_; |
482 | |
526 | |
483 | $self->{entry}->key_down ($ev); |
527 | $self->{entry}->key_down ($ev) |
484 | } |
528 | } |
485 | |
529 | |
486 | sub update_labels { |
530 | sub update_labels { |
487 | my ($self) = @_; |
531 | my ($self) = @_; |
488 | |
532 | |
… | |
… | |
521 | |
565 | |
522 | @match = map $self->{command}{$_->[0]}, |
566 | @match = map $self->{command}{$_->[0]}, |
523 | sort { |
567 | sort { |
524 | $a->[1] <=> $b->[1] |
568 | $a->[1] <=> $b->[1] |
525 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
569 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
526 | or (length $a->[0]) <=> (length $b->[0]) |
570 | or (length $b->[0]) <=> (length $a->[0]) |
527 | } @match; |
571 | } @match; |
528 | } |
572 | } |
529 | |
573 | |
530 | $self->{last_search} = $cmd; |
574 | $self->{last_search} = $text; |
531 | $self->{last_match} = \@match; |
575 | $self->{last_match} = \@match; |
532 | |
576 | |
533 | $self->{select_offset} = 0; |
577 | $self->{select_offset} = 0; |
534 | } |
578 | } |
535 | |
579 | |