… | |
… | |
6 | use List::Util qw(min max); |
6 | use List::Util qw(min max); |
7 | |
7 | |
8 | use CFClient::OpenGL; |
8 | use CFClient::OpenGL; |
9 | |
9 | |
10 | our @ISA = CFClient::UI::Base::; |
10 | our @ISA = CFClient::UI::Base::; |
|
|
11 | |
|
|
12 | my $magicmap_tex = |
|
|
13 | new_from_file CFClient::Texture CFClient::find_rcfile "magicmap.png", |
|
|
14 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
11 | |
15 | |
12 | sub new { |
16 | sub new { |
13 | my $class = shift; |
17 | my $class = shift; |
14 | |
18 | |
15 | my $self = $class->SUPER::new ( |
19 | my $self = $class->SUPER::new ( |
… | |
… | |
34 | . "To enter a verbatim command to send to the server, just type the command, " |
38 | . "To enter a verbatim command to send to the server, just type the command, " |
35 | . "followed by a space, and press return. " |
39 | . "followed by a space, and press return. " |
36 | . "Typing the initial letters of words (or just any letters) displays guesses " |
40 | . "Typing the initial letters of words (or just any letters) displays guesses " |
37 | . "for commands you might want to use.\n" |
41 | . "for commands you might want to use.\n" |
38 | . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" |
42 | . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" |
39 | . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.", |
43 | . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining key bindings.", |
40 | ; |
44 | ; |
41 | |
45 | |
42 | $self |
46 | $self |
43 | } |
47 | } |
44 | |
48 | |
… | |
… | |
58 | my ($self) = @_; |
62 | my ($self) = @_; |
59 | |
63 | |
60 | %{$self->{completer}{command}} = (); |
64 | %{$self->{completer}{command}} = (); |
61 | } |
65 | } |
62 | |
66 | |
63 | sub button_down { |
67 | sub invoke_button_down { |
64 | my ($self, $ev, $x, $y) = @_; |
68 | my ($self, $ev, $x, $y) = @_; |
65 | |
69 | |
66 | return unless $::CONN; |
70 | return unless $::CONN; |
67 | |
71 | |
68 | $self->focus_in; |
72 | $self->grab_focus; |
69 | |
73 | |
70 | if ($ev->{button} == 1) { |
74 | if ($ev->{button} == 1) { |
71 | my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
75 | my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
72 | my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
76 | my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
73 | |
77 | |
… | |
… | |
94 | } |
98 | } |
95 | |
99 | |
96 | 1 |
100 | 1 |
97 | } |
101 | } |
98 | |
102 | |
99 | sub button_up { |
103 | sub invoke_button_up { |
100 | my ($self, $ev, $x, $y) = @_; |
104 | my ($self, $ev, $x, $y) = @_; |
101 | |
105 | |
102 | delete $self->{motion}; |
106 | delete $self->{motion}; |
103 | |
107 | |
104 | 1 |
108 | 1 |
105 | } |
109 | } |
106 | |
110 | |
107 | sub mouse_motion { |
111 | sub invoke_mouse_motion { |
108 | my ($self, $ev, $x, $y) = @_; |
112 | my ($self, $ev, $x, $y) = @_; |
109 | |
113 | |
110 | if ($self->{motion}) { |
114 | if ($self->{motion}) { |
111 | $self->{motion}->($ev, $x, $y); |
115 | $self->{motion}->($ev, $x, $y); |
112 | } else { |
116 | } else { |
… | |
… | |
144 | CFClient::SDLK_RIGHT, [3, "east"], |
148 | CFClient::SDLK_RIGHT, [3, "east"], |
145 | CFClient::SDLK_DOWN, [5, "south"], |
149 | CFClient::SDLK_DOWN, [5, "south"], |
146 | CFClient::SDLK_LEFT, [7, "west"], |
150 | CFClient::SDLK_LEFT, [7, "west"], |
147 | ); |
151 | ); |
148 | |
152 | |
149 | sub key_down { |
153 | sub invoke_key_down { |
150 | my ($self, $ev) = @_; |
154 | my ($self, $ev) = @_; |
151 | |
155 | |
152 | return 0 unless $::CONN; |
156 | return 0 unless $::CONN; |
153 | |
157 | |
154 | my $mod = $ev->{mod}; |
158 | my $mod = $ev->{mod}; |
… | |
… | |
191 | } |
195 | } |
192 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
196 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
193 | $::BIND_EDITOR->set_binding (undef, undef, [], |
197 | $::BIND_EDITOR->set_binding (undef, undef, [], |
194 | sub { |
198 | sub { |
195 | my ($mod, $sym, $cmds) = @_; |
199 | my ($mod, $sym, $cmds) = @_; |
196 | $::CFG->{bindings}->{$mod}->{$sym} = $cmds; |
200 | $::CFG->{profile}{default}{bindings}{$mod}{$sym} = $cmds; |
197 | }); |
201 | }); |
198 | $::BIND_EDITOR->start; |
202 | $::BIND_EDITOR->start; |
199 | $::BIND_EDITOR->show; |
203 | $::BIND_EDITOR->show; |
200 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
204 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
201 | $::BIND_EDITOR->stop; |
205 | $::BIND_EDITOR->stop; |
202 | $::BIND_EDITOR->ask_for_bind_and_commit; |
206 | $::BIND_EDITOR->ask_for_bind_and_commit; |
203 | $::BIND_EDITOR->hide; |
207 | $::BIND_EDITOR->hide; |
204 | } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { |
208 | } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { |
205 | $::CONN->user_send ($_) for @$bind_cmd; |
209 | $::CONN->user_send ($_) for @$bind_cmd; |
206 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
210 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
207 | $self->{completer}->key_down ($ev); |
211 | $self->{completer}->invoke_key_down ($ev); |
208 | $self->{completer}->show; |
212 | $self->{completer}->show; |
209 | } else { |
213 | } else { |
210 | return 0; |
214 | return 0; |
211 | } |
215 | } |
212 | |
216 | |
213 | 1 |
217 | 1 |
214 | } |
218 | } |
215 | |
219 | |
216 | sub key_up { |
220 | sub invoke_key_up { |
217 | my ($self, $ev) = @_; |
221 | my ($self, $ev) = @_; |
218 | |
222 | |
219 | my $res = 0; |
223 | my $res = 0; |
220 | my $mod = $ev->{mod}; |
224 | my $mod = $ev->{mod}; |
221 | my $sym = $ev->{sym}; |
225 | my $sym = $ev->{sym}; |
… | |
… | |
244 | } |
248 | } |
245 | |
249 | |
246 | $res |
250 | $res |
247 | } |
251 | } |
248 | |
252 | |
|
|
253 | sub set_magicmap { |
|
|
254 | my ($self, $w, $h, $x, $y, $data) = @_; |
|
|
255 | |
|
|
256 | $x -= $::MAP->ox + int 0.5 * $::MAP->w; |
|
|
257 | $y -= $::MAP->oy + int 0.5 * $::MAP->h; |
|
|
258 | |
|
|
259 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
|
|
260 | |
|
|
261 | $self->update; |
|
|
262 | } |
|
|
263 | |
249 | sub draw { |
264 | sub draw { |
250 | my ($self) = @_; |
265 | my ($self) = @_; |
251 | |
266 | |
252 | return unless $::MAP; |
267 | return unless $::MAP; |
253 | |
268 | |
… | |
… | |
264 | my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; |
279 | my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; |
265 | |
280 | |
266 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
281 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
267 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
282 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
268 | |
283 | |
269 | my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize; |
284 | my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize; |
270 | my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize; |
285 | my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize; |
271 | |
286 | |
272 | if ($::CFG->{fow_enable}) { |
287 | if ($::CFG->{fow_enable}) { |
273 | my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); |
288 | my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); |
274 | |
289 | |
275 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
290 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
… | |
… | |
302 | glTranslate $sx0, $sy0; |
317 | glTranslate $sx0, $sy0; |
303 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
318 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
304 | |
319 | |
305 | $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); |
320 | $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); |
306 | |
321 | |
|
|
322 | glScale 32, 32; |
|
|
323 | |
307 | if (my $tex = $self->{fow_texture}) { |
324 | if (my $tex = $self->{fow_texture}) { |
308 | glEnable GL_TEXTURE_2D; |
325 | glEnable GL_TEXTURE_2D; |
309 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
326 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
310 | |
327 | |
311 | glScale 32, 32; |
|
|
312 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
328 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
313 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
329 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
314 | |
330 | |
315 | glDisable GL_TEXTURE_2D; |
331 | glDisable GL_TEXTURE_2D; |
316 | } |
332 | } |
317 | |
333 | |
|
|
334 | if ($self->{magicmap}) { |
|
|
335 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
|
|
336 | |
|
|
337 | $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); |
|
|
338 | $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); |
|
|
339 | |
|
|
340 | glTranslate - $x - 1, - $y - 1; |
|
|
341 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
|
|
342 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
|
|
343 | } |
|
|
344 | |
318 | glPopMatrix; |
345 | glPopMatrix; |
319 | |
|
|
320 | glEndList; |
346 | glEndList; |
321 | } |
347 | } |
322 | |
348 | |
323 | glPushMatrix; |
|
|
324 | glCallList $self->{list}; |
349 | glCallList $self->{list}; |
325 | glPopMatrix; |
|
|
326 | |
350 | |
327 | # TNT2 emulates logops in software (or worse :) |
351 | # TNT2 emulates logops in software (or worse :) |
328 | unless ($focused) { |
352 | unless ($focused) { |
329 | glColor 0.4, 0.2, 0.2, 0.6; |
353 | glColor 0.4, 0.2, 0.2, 0.6; |
330 | glEnable GL_BLEND; |
354 | glEnable GL_BLEND; |
… | |
… | |
356 | |
380 | |
357 | sub size_request { |
381 | sub size_request { |
358 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
382 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
359 | } |
383 | } |
360 | |
384 | |
361 | sub size_allocate { |
385 | sub invoke_size_allocate { |
362 | my ($self, $w, $h) = @_; |
386 | my ($self, $w, $h) = @_; |
363 | |
387 | |
364 | $self->SUPER::size_allocate ($w, $h); |
|
|
365 | $self->update; |
388 | $self->update; |
|
|
389 | |
|
|
390 | 1 |
366 | } |
391 | } |
367 | |
392 | |
368 | sub update { |
393 | sub update { |
369 | my ($self) = @_; |
394 | my ($self) = @_; |
370 | |
395 | |
… | |
… | |
455 | ]; |
480 | ]; |
456 | |
481 | |
457 | $self->{entry} = new CFClient::UI::Entry |
482 | $self->{entry} = new CFClient::UI::Entry |
458 | on_changed => sub { |
483 | on_changed => sub { |
459 | $self->update_labels; |
484 | $self->update_labels; |
|
|
485 | 0 |
460 | }, |
486 | }, |
461 | on_button_down => sub { |
487 | on_button_down => sub { |
462 | my ($entry, $ev, $x, $y) = @_; |
488 | my ($entry, $ev, $x, $y) = @_; |
463 | |
489 | |
464 | if ($ev->{button} == 3) { |
490 | if ($ev->{button} == 3) { |
465 | (new CFClient::UI::Menu |
491 | (new CFClient::UI::Menu |
466 | items => [ |
492 | items => [ |
467 | ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }] |
493 | ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
468 | ], |
494 | ], |
469 | )->popup ($ev); |
495 | )->popup ($ev); |
470 | return 1; |
496 | return 1; |
471 | } |
497 | } |
472 | 0 |
498 | 0 |
… | |
… | |
487 | $self->hide; |
513 | $self->hide; |
488 | } |
514 | } |
489 | } elsif ($ev->{sym} == 27) { |
515 | } elsif ($ev->{sym} == 27) { |
490 | $self->{hist_ptr} = 0; |
516 | $self->{hist_ptr} = 0; |
491 | $self->hide; |
517 | $self->hide; |
492 | return; |
|
|
493 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
518 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
494 | if ($self->{hist_ptr} > 1) { |
519 | if ($self->{hist_ptr} > 1) { |
495 | $self->{hist_ptr}--; |
520 | $self->{hist_ptr}--; |
496 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
521 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
497 | } elsif ($self->{hist_ptr} > 0) { |
522 | } elsif ($self->{hist_ptr} > 0) { |
… | |
… | |
537 | |
562 | |
538 | $self->{entry}->set_text ($prefix); |
563 | $self->{entry}->set_text ($prefix); |
539 | $self->show; |
564 | $self->show; |
540 | } |
565 | } |
541 | |
566 | |
542 | sub size_allocate { |
567 | sub invoke_size_allocate { |
543 | my ($self, $w, $h) = @_; |
568 | my ($self, $w, $h) = @_; |
544 | |
569 | |
545 | $self->SUPER::size_allocate ($w, $h); |
|
|
546 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
570 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
|
|
571 | |
|
|
572 | $self->SUPER::invoke_size_allocate ($w, $h) |
547 | } |
573 | } |
548 | |
574 | |
549 | sub show { |
575 | sub show { |
550 | my ($self) = @_; |
576 | my ($self) = @_; |
551 | |
577 | |
552 | $self->SUPER::show; |
578 | $self->SUPER::show; |
553 | $self->{entry}->focus_in; |
579 | $self->{entry}->grab_focus; |
554 | } |
580 | } |
555 | |
581 | |
556 | sub hide { |
582 | sub hide { |
557 | my ($self) = @_; |
583 | my ($self) = @_; |
558 | |
584 | |
559 | $self->SUPER::hide; |
585 | $self->SUPER::hide; |
560 | $self->{entry}->set_text (""); |
586 | $self->{entry}->set_text (""); |
561 | } |
587 | } |
562 | |
588 | |
563 | sub key_down { |
589 | sub invoke_key_down { |
564 | my ($self, $ev) = @_; |
590 | my ($self, $ev) = @_; |
565 | |
591 | |
566 | $self->{entry}->key_down ($ev) |
592 | $self->{entry}->emit (key_down => $ev) |
567 | } |
593 | } |
568 | |
594 | |
569 | sub update_labels { |
595 | sub update_labels { |
570 | my ($self) = @_; |
596 | my ($self) = @_; |
571 | |
597 | |
… | |
… | |
658 | $label->set_text (""); |
684 | $label->set_text (""); |
659 | $label->set_tooltip (""); |
685 | $label->set_tooltip (""); |
660 | } |
686 | } |
661 | |
687 | |
662 | $self->update; |
688 | $self->update; |
663 | ### |
|
|
664 | } |
689 | } |
665 | |
690 | |
666 | sub _draw { |
691 | sub _draw { |
667 | my ($self) = @_; |
692 | my ($self) = @_; |
668 | |
693 | |