… | |
… | |
23 | my $self = shift; |
23 | my $self = shift; |
24 | |
24 | |
25 | glDeleteList $self->{list}; |
25 | glDeleteList $self->{list}; |
26 | |
26 | |
27 | $self->SUPER::DESTROY; |
27 | $self->SUPER::DESTROY; |
28 | } |
|
|
29 | |
|
|
30 | sub key_down { |
|
|
31 | print "MAPKEYDOWN\n"; |
|
|
32 | } |
|
|
33 | |
|
|
34 | sub key_up { |
|
|
35 | } |
28 | } |
36 | |
29 | |
37 | sub button_down { |
30 | sub button_down { |
38 | my ($self, $ev, $x, $y) = @_; |
31 | my ($self, $ev, $x, $y) = @_; |
39 | |
32 | |
… | |
… | |
106 | GL_CONVOLUTION_2D, |
99 | GL_CONVOLUTION_2D, |
107 | GL_ALPHA, |
100 | GL_ALPHA, |
108 | 3, 3, |
101 | 3, 3, |
109 | GL_ALPHA, GL_FLOAT, |
102 | GL_ALPHA, GL_FLOAT, |
110 | pack "f*", |
103 | pack "f*", |
111 | 0.1, 0.1, 0.1, |
104 | 0.05, 0.13, 0.05, |
112 | 0.1, 0.2, 0.1, |
105 | 0.13, 0.30, 0.13, |
113 | 0.1, 0.1, 0.1, |
106 | 0.05, 0.13, 0.05, |
114 | ); |
107 | ); |
115 | glEnable GL_CONVOLUTION_2D; |
108 | glEnable GL_CONVOLUTION_2D; |
116 | } |
109 | } |
117 | |
110 | |
118 | $self->{fow_texture} = new CFClient::Texture |
111 | $self->{fow_texture} = new CFClient::Texture |
… | |
… | |
127 | glEnable GL_BLEND; |
120 | glEnable GL_BLEND; |
128 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
121 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
129 | glEnable GL_TEXTURE_2D; |
122 | glEnable GL_TEXTURE_2D; |
130 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
123 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
131 | |
124 | |
132 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
125 | glColor +($::CFG->{fow_intensity}) x 3, 0.8; |
133 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
126 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
134 | |
127 | |
135 | glDisable GL_TEXTURE_2D; |
128 | glDisable GL_TEXTURE_2D; |
136 | glDisable GL_BLEND; |
129 | glDisable GL_BLEND; |
137 | } |
130 | } |
138 | |
131 | |
139 | # HACK BEGIN |
132 | # HACK BEGIN |
140 | { |
133 | { |
141 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
134 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
135 | |
|
|
136 | glTranslate 0, 30; |
142 | my ($w, $h) = (250, 250); |
137 | my ($w, $h) = (250, 250); |
|
|
138 | |
|
|
139 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
143 | |
140 | |
144 | glEnable GL_BLEND; |
141 | glEnable GL_BLEND; |
145 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
142 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
146 | glEnable GL_TEXTURE_2D; |
143 | glEnable GL_TEXTURE_2D; |
147 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
144 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
148 | |
145 | |
149 | $self->{mapmap_texture} = |
146 | $self->{mapmap_texture} = |
150 | new CFClient::Texture |
147 | new CFClient::Texture |
151 | w => $w, |
148 | w => $w, |
152 | h => $h, |
149 | h => $h, |
153 | data => $::MAP->mapmap ($w, $h), |
150 | data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h), |
154 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
151 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
155 | |
152 | |
156 | $self->{mapmap_texture}->draw_quad (100, 100); |
153 | $self->{mapmap_texture}->draw_quad (0, 0); |
157 | |
154 | |
158 | glDisable GL_TEXTURE_2D; |
155 | glDisable GL_TEXTURE_2D; |
|
|
156 | |
|
|
157 | glTranslate 0.375, 0.375; |
|
|
158 | |
|
|
159 | glColor 1, 1, 0, 1; |
|
|
160 | glBegin GL_LINE_LOOP; |
|
|
161 | glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ; |
|
|
162 | glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh; |
|
|
163 | glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh; |
|
|
164 | glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ; |
|
|
165 | glEnd; |
|
|
166 | |
159 | glDisable GL_BLEND; |
167 | glDisable GL_BLEND; |
160 | } |
168 | } |
161 | # HACK END |
169 | # HACK END |
162 | } |
170 | } |
163 | |
171 | |
… | |
… | |
209 | } elsif ($sym == ord "a") { |
217 | } elsif ($sym == ord "a") { |
210 | $::CONN->user_send ("apply"); |
218 | $::CONN->user_send ("apply"); |
211 | } elsif ($sym == ord "'") { |
219 | } elsif ($sym == ord "'") { |
212 | $self->emit ('activate_console'); |
220 | $self->emit ('activate_console'); |
213 | } elsif ($sym == ord "/") { |
221 | } elsif ($sym == ord "/") { |
214 | $self->emit ('activate_console' => '/'); |
222 | $self->emit (activate_console => '/'); |
215 | } elsif (exists $DIR{$sym}) { |
223 | } elsif (exists $DIR{$sym}) { |
216 | if ($mod & CFClient::KMOD_SHIFT) { |
224 | if ($mod & CFClient::KMOD_SHIFT) { |
217 | $self->{shft}++; |
225 | $self->{shft}++; |
218 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
226 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
219 | } elsif ($mod & CFClient::KMOD_CTRL) { |
227 | } elsif ($mod & CFClient::KMOD_CTRL) { |
220 | $self->{ctrl}++; |
228 | $self->{ctrl}++; |
221 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
229 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
222 | } else { |
230 | } else { |
223 | $::CONN->user_send ("$DIR{$sym}[1]"); |
231 | $::CONN->user_send ("$DIR{$sym}[1]"); |
224 | } |
232 | } |
|
|
233 | } elsif ($ev->{unicode}) { |
|
|
234 | $self->{command_widget} ||= |
|
|
235 | new CFClient::MapWidget::Command:: |
|
|
236 | command => $self->{command}, |
|
|
237 | can_focus => 1, |
|
|
238 | connect_execute => sub { |
|
|
239 | $::CONN->user_send ($_[1]); |
|
|
240 | }, |
|
|
241 | connect_close => sub { |
|
|
242 | (delete $self->{command_widget})->hide; |
|
|
243 | $self->focus_in; |
|
|
244 | }, |
|
|
245 | ; |
|
|
246 | $self->{command_widget}->key_down ($ev); |
|
|
247 | $self->{command_widget}->show; |
|
|
248 | $self->{command_widget}->focus_in; |
225 | } |
249 | } |
226 | } |
250 | } |
227 | |
251 | |
228 | sub key_up { |
252 | sub key_up { |
229 | my ($self, $ev) = @_; |
253 | my ($self, $ev) = @_; |
… | |
… | |
241 | |
265 | |
242 | sub add_command { |
266 | sub add_command { |
243 | my ($self, $command, $widget, $cb) = @_; |
267 | my ($self, $command, $widget, $cb) = @_; |
244 | |
268 | |
245 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
269 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
|
|
270 | |
|
|
271 | push @{$self->{command}}, [$abbrev, $command]; |
246 | warn "$command|$abbrev|$widget\n";#d# |
272 | #warn "$command|$abbrev|$widget\n";#d# |
|
|
273 | } |
|
|
274 | |
|
|
275 | package CFClient::MapWidget::Command; |
|
|
276 | |
|
|
277 | use strict; |
|
|
278 | |
|
|
279 | use CFClient::OpenGL; |
|
|
280 | |
|
|
281 | our @ISA = CFClient::UI::VBox::; |
|
|
282 | |
|
|
283 | sub new { |
|
|
284 | my $class = shift; |
|
|
285 | |
|
|
286 | my $self = $class->SUPER::new ( |
|
|
287 | @_, |
|
|
288 | children => [map |
|
|
289 | CFClient::UI::Label->new ( |
|
|
290 | can_hover => 1, |
|
|
291 | fontsize => $_, |
|
|
292 | ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8 |
|
|
293 | ], |
|
|
294 | ); |
|
|
295 | |
|
|
296 | $self |
|
|
297 | } |
|
|
298 | |
|
|
299 | sub size_allocate { |
|
|
300 | my ($self, $w, $h) = @_; |
|
|
301 | |
|
|
302 | $self->SUPER::size_allocate ($w, $h); |
|
|
303 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
|
|
304 | } |
|
|
305 | |
|
|
306 | sub update_labels { |
|
|
307 | my ($self) = @_; |
|
|
308 | |
|
|
309 | my $command = $self->{command}; |
|
|
310 | my $search_abbrev = qr/^\Q$self->{search}/; |
|
|
311 | my $search_full = qr/\Q$self->{search}/; |
|
|
312 | |
|
|
313 | my @found; |
|
|
314 | |
|
|
315 | for (@$command) { |
|
|
316 | if ($_->[0] =~ $search_abbrev) { |
|
|
317 | push @found, [$_->[0], $_]; |
|
|
318 | } elsif ($_[1] =~ $search_full) { |
|
|
319 | push @found, [$_->[1], $_]; |
|
|
320 | } |
|
|
321 | } |
|
|
322 | |
|
|
323 | @found = sort { $a->[0] cmp $b->[0] } @found; |
|
|
324 | |
|
|
325 | $self->{children}[0]->set_text ("$self->{search}_"); |
|
|
326 | |
|
|
327 | for (0..5) { |
|
|
328 | $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : ""); |
|
|
329 | } |
|
|
330 | |
|
|
331 | $self->{select} = $found[0][1][1] |
|
|
332 | if @found; |
|
|
333 | |
|
|
334 | if (@found > 6) { |
|
|
335 | $self->{children}[6]->set_text ("..."); |
|
|
336 | } |
|
|
337 | |
|
|
338 | $self->check_size; |
|
|
339 | } |
|
|
340 | |
|
|
341 | sub key_down { |
|
|
342 | my ($self, $ev) = @_; |
|
|
343 | |
|
|
344 | if ($ev->{sym} == 8) { |
|
|
345 | substr $self->{search}, -1, 1, ""; |
|
|
346 | $self->update_labels; |
|
|
347 | } elsif ($ev->{sym} == 13) { |
|
|
348 | if (exists $self->{select}) { |
|
|
349 | $self->emit (execute => $self->{select}); |
|
|
350 | $self->emit ("close"); |
|
|
351 | } |
|
|
352 | } elsif ($ev->{sym} == 27) { |
|
|
353 | $self->emit ("close"); |
|
|
354 | } elsif ($ev->{unicode}) { |
|
|
355 | $self->{search} .= chr $ev->{unicode}; |
|
|
356 | $self->update_labels; |
|
|
357 | } |
247 | } |
358 | } |
248 | |
359 | |
249 | 1 |
360 | 1 |