… | |
… | |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
5 | use List::Util qw(min max); |
5 | use List::Util qw(min max); |
6 | |
6 | |
7 | use SDL; |
7 | use CFClient::OpenGL; |
8 | use SDL::OpenGL; |
|
|
9 | |
8 | |
10 | our @ISA = CFClient::UI::Base::; |
9 | our @ISA = CFClient::UI::Base::; |
11 | |
10 | |
12 | sub new { |
11 | sub new { |
13 | my $class = shift; |
12 | my $class = shift; |
14 | |
13 | |
15 | $class->SUPER::new ( |
14 | $class->SUPER::new ( |
16 | z => -1, |
15 | z => -1, |
17 | can_focus => 1, |
16 | can_focus => 1, |
18 | list => (glGenLists 1), |
17 | list => glGenList, |
19 | @_ |
18 | @_ |
20 | ) |
19 | ) |
|
|
20 | } |
|
|
21 | |
|
|
22 | sub DESTROY { |
|
|
23 | my $self = shift; |
|
|
24 | |
|
|
25 | glDeleteList $self->{list}; |
|
|
26 | |
|
|
27 | $self->SUPER::DESTROY; |
21 | } |
28 | } |
22 | |
29 | |
23 | sub key_down { |
30 | sub key_down { |
24 | print "MAPKEYDOWN\n"; |
31 | print "MAPKEYDOWN\n"; |
25 | } |
32 | } |
… | |
… | |
77 | |
84 | |
78 | sub draw { |
85 | sub draw { |
79 | my ($self) = @_; |
86 | my ($self) = @_; |
80 | |
87 | |
81 | if (delete $self->{need_update}) { |
88 | if (delete $self->{need_update}) { |
82 | glNewList $self->{list}, GL_COMPILE; |
89 | glNewList $self->{list}; |
83 | |
90 | |
84 | if ($::MAP) { |
91 | if ($::MAP) { |
85 | my $sw = int $::WIDTH / 32; |
92 | my $sw = int $::WIDTH / 32; |
86 | my $sh = int $::HEIGHT / 32; |
93 | my $sh = int $::HEIGHT / 32; |
87 | |
94 | |
… | |
… | |
174 | glDisable GL_COLOR_LOGIC_OP; |
181 | glDisable GL_COLOR_LOGIC_OP; |
175 | } |
182 | } |
176 | } |
183 | } |
177 | |
184 | |
178 | my %DIR = ( |
185 | my %DIR = ( |
179 | SDLK_KP8, [1, "north"], |
186 | CFClient::SDLK_KP8, [1, "north"], |
180 | SDLK_KP9, [2, "northeast"], |
187 | CFClient::SDLK_KP9, [2, "northeast"], |
181 | SDLK_KP6, [3, "east"], |
188 | CFClient::SDLK_KP6, [3, "east"], |
182 | SDLK_KP3, [4, "southeast"], |
189 | CFClient::SDLK_KP3, [4, "southeast"], |
183 | SDLK_KP2, [5, "south"], |
190 | CFClient::SDLK_KP2, [5, "south"], |
184 | SDLK_KP1, [6, "southwest"], |
191 | CFClient::SDLK_KP1, [6, "southwest"], |
185 | SDLK_KP4, [7, "west"], |
192 | CFClient::SDLK_KP4, [7, "west"], |
186 | SDLK_KP7, [8, "northwest"], |
193 | CFClient::SDLK_KP7, [8, "northwest"], |
187 | |
194 | |
188 | SDLK_UP, [1, "north"], |
195 | CFClient::SDLK_UP, [1, "north"], |
189 | SDLK_RIGHT, [3, "east"], |
196 | CFClient::SDLK_RIGHT, [3, "east"], |
190 | SDLK_DOWN, [5, "south"], |
197 | CFClient::SDLK_DOWN, [5, "south"], |
191 | SDLK_LEFT, [7, "west"], |
198 | CFClient::SDLK_LEFT, [7, "west"], |
192 | ); |
199 | ); |
193 | |
200 | |
194 | sub key_down { |
201 | sub key_down { |
195 | my ($self, $ev) = @_; |
202 | my ($self, $ev) = @_; |
196 | |
203 | |
197 | my $mod = $ev->key_mod; |
204 | my $mod = $ev->key_mod; |
198 | my $sym = $ev->key_sym; |
205 | my $sym = $ev->key_sym; |
199 | |
206 | |
200 | if ($sym == SDLK_KP5) { |
207 | if ($sym == CFClient::SDLK_KP5) { |
201 | $::CONN->user_send ("stay fire"); |
208 | $::CONN->user_send ("stay fire"); |
202 | } elsif ($sym == SDLK_a) { |
209 | } elsif ($sym == ord "a") { |
203 | $::CONN->user_send ("apply"); |
210 | $::CONN->user_send ("apply"); |
204 | } elsif ($sym == SDLK_QUOTE) { |
211 | } elsif ($sym == ord "'") { |
205 | $self->emit ('activate_console'); |
212 | $self->emit ('activate_console'); |
206 | } elsif ($sym == SDLK_SLASH) { |
213 | } elsif ($sym == ord "/") { |
207 | $self->emit ('activate_console' => '/'); |
214 | $self->emit ('activate_console' => '/'); |
208 | } elsif (exists $DIR{$sym}) { |
215 | } elsif (exists $DIR{$sym}) { |
209 | if ($mod & KMOD_SHIFT) { |
216 | if ($mod & CFClient::KMOD_SHIFT) { |
210 | $self->{shft}++; |
217 | $self->{shft}++; |
211 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
218 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
212 | } elsif ($mod & KMOD_CTRL) { |
219 | } elsif ($mod & CFClient::KMOD_CTRL) { |
213 | $self->{ctrl}++; |
220 | $self->{ctrl}++; |
214 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
221 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
215 | } else { |
222 | } else { |
216 | $::CONN->user_send ("$DIR{$sym}[1]"); |
223 | $::CONN->user_send ("$DIR{$sym}[1]"); |
217 | } |
224 | } |
… | |
… | |
222 | my ($self, $ev) = @_; |
229 | my ($self, $ev) = @_; |
223 | |
230 | |
224 | my $mod = $ev->key_mod; |
231 | my $mod = $ev->key_mod; |
225 | my $sym = $ev->key_sym; |
232 | my $sym = $ev->key_sym; |
226 | |
233 | |
227 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
234 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
228 | $::CONN->user_send ("fire_stop"); |
235 | $::CONN->user_send ("fire_stop"); |
229 | } |
236 | } |
230 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
237 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
231 | $::CONN->user_send ("run_stop"); |
238 | $::CONN->user_send ("run_stop"); |
232 | } |
239 | } |
233 | } |
240 | } |
234 | |
241 | |
|
|
242 | sub add_command { |
|
|
243 | my ($self, $command, $widget, $cb) = @_; |
|
|
244 | |
|
|
245 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
|
|
246 | warn "$command|$abbrev|$widget\n";#d# |
|
|
247 | } |
|
|
248 | |
235 | 1 |
249 | 1 |