… | |
… | |
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 | ) |
21 | } |
20 | } |
22 | |
21 | |
|
|
22 | sub DESTROY { |
|
|
23 | my $self = shift; |
|
|
24 | |
|
|
25 | glDeleteList $self->{list}; |
|
|
26 | |
|
|
27 | $self->SUPER::DESTROY; |
|
|
28 | } |
|
|
29 | |
23 | sub key_down { |
30 | sub key_down { |
24 | print "MAPKEYDOWN\n"; |
31 | print "MAPKEYDOWN\n"; |
25 | } |
32 | } |
26 | |
33 | |
27 | sub key_up { |
34 | sub key_up { |
… | |
… | |
30 | sub button_down { |
37 | sub button_down { |
31 | my ($self, $ev, $x, $y) = @_; |
38 | my ($self, $ev, $x, $y) = @_; |
32 | |
39 | |
33 | $self->focus_in; |
40 | $self->focus_in; |
34 | |
41 | |
35 | if ($ev->button == 2) { |
42 | if ($ev->{button} == 2) { |
36 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
43 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
37 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
44 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
38 | |
45 | |
39 | $self->{motion} = sub { |
46 | $self->{motion} = sub { |
40 | my ($ev, $x, $y) = @_; |
47 | my ($ev, $x, $y) = @_; |
41 | |
48 | |
42 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
49 | ($x, $y) = ($ev->{x}, $ev->{y}); |
43 | |
50 | |
44 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
51 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
45 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
52 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
46 | |
53 | |
47 | $self->update; |
54 | $self->update; |
… | |
… | |
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 | |
… | |
… | |
130 | } |
137 | } |
131 | |
138 | |
132 | # HACK BEGIN |
139 | # HACK BEGIN |
133 | { |
140 | { |
134 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
141 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
142 | |
|
|
143 | glTranslate 0, 30; |
135 | my ($w, $h) = (250, 250); |
144 | my ($w, $h) = (250, 250); |
|
|
145 | |
|
|
146 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
136 | |
147 | |
137 | glEnable GL_BLEND; |
148 | glEnable GL_BLEND; |
138 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
149 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
139 | glEnable GL_TEXTURE_2D; |
150 | glEnable GL_TEXTURE_2D; |
140 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
151 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
141 | |
152 | |
142 | $self->{mapmap_texture} = |
153 | $self->{mapmap_texture} = |
143 | new CFClient::Texture |
154 | new CFClient::Texture |
144 | w => $w, |
155 | w => $w, |
145 | h => $h, |
156 | h => $h, |
146 | data => $::MAP->mapmap ($w, $h), |
157 | data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h), |
147 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
158 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
148 | |
159 | |
149 | $self->{mapmap_texture}->draw_quad (100, 100); |
160 | $self->{mapmap_texture}->draw_quad (0, 0); |
150 | |
161 | |
151 | glDisable GL_TEXTURE_2D; |
162 | glDisable GL_TEXTURE_2D; |
|
|
163 | |
|
|
164 | glTranslate 0.375, 0.375; |
|
|
165 | |
|
|
166 | glColor 1, 1, 0, 1; |
|
|
167 | glBegin GL_LINE_LOOP; |
|
|
168 | glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ; |
|
|
169 | glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh; |
|
|
170 | glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh; |
|
|
171 | glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ; |
|
|
172 | glEnd; |
|
|
173 | |
152 | glDisable GL_BLEND; |
174 | glDisable GL_BLEND; |
153 | } |
175 | } |
154 | # HACK END |
176 | # HACK END |
155 | } |
177 | } |
156 | |
178 | |
… | |
… | |
174 | glDisable GL_COLOR_LOGIC_OP; |
196 | glDisable GL_COLOR_LOGIC_OP; |
175 | } |
197 | } |
176 | } |
198 | } |
177 | |
199 | |
178 | my %DIR = ( |
200 | my %DIR = ( |
179 | SDLK_KP8, [1, "north"], |
201 | CFClient::SDLK_KP8, [1, "north"], |
180 | SDLK_KP9, [2, "northeast"], |
202 | CFClient::SDLK_KP9, [2, "northeast"], |
181 | SDLK_KP6, [3, "east"], |
203 | CFClient::SDLK_KP6, [3, "east"], |
182 | SDLK_KP3, [4, "southeast"], |
204 | CFClient::SDLK_KP3, [4, "southeast"], |
183 | SDLK_KP2, [5, "south"], |
205 | CFClient::SDLK_KP2, [5, "south"], |
184 | SDLK_KP1, [6, "southwest"], |
206 | CFClient::SDLK_KP1, [6, "southwest"], |
185 | SDLK_KP4, [7, "west"], |
207 | CFClient::SDLK_KP4, [7, "west"], |
186 | SDLK_KP7, [8, "northwest"], |
208 | CFClient::SDLK_KP7, [8, "northwest"], |
187 | |
209 | |
188 | SDLK_UP, [1, "north"], |
210 | CFClient::SDLK_UP, [1, "north"], |
189 | SDLK_RIGHT, [3, "east"], |
211 | CFClient::SDLK_RIGHT, [3, "east"], |
190 | SDLK_DOWN, [5, "south"], |
212 | CFClient::SDLK_DOWN, [5, "south"], |
191 | SDLK_LEFT, [7, "west"], |
213 | CFClient::SDLK_LEFT, [7, "west"], |
192 | ); |
214 | ); |
193 | |
215 | |
194 | sub key_down { |
216 | sub key_down { |
195 | my ($self, $ev) = @_; |
217 | my ($self, $ev) = @_; |
196 | |
218 | |
197 | my $mod = $ev->key_mod; |
219 | my $mod = $ev->{mod}; |
198 | my $sym = $ev->key_sym; |
220 | my $sym = $ev->{sym}; |
199 | |
221 | |
200 | if ($sym == SDLK_KP5) { |
222 | if ($sym == CFClient::SDLK_KP5) { |
201 | $::CONN->user_send ("stay fire"); |
223 | $::CONN->user_send ("stay fire"); |
202 | } elsif ($sym == SDLK_a) { |
224 | } elsif ($sym == ord "a") { |
203 | $::CONN->user_send ("apply"); |
225 | $::CONN->user_send ("apply"); |
204 | } elsif ($sym == SDLK_QUOTE) { |
226 | } elsif ($sym == ord "'") { |
205 | $self->emit ('activate_console'); |
227 | $self->emit ('activate_console'); |
206 | } elsif ($sym == SDLK_SLASH) { |
228 | } elsif ($sym == ord "/") { |
207 | $self->emit ('activate_console' => '/'); |
229 | $self->emit ('activate_console' => '/'); |
208 | } elsif (exists $DIR{$sym}) { |
230 | } elsif (exists $DIR{$sym}) { |
209 | if ($mod & KMOD_SHIFT) { |
231 | if ($mod & CFClient::KMOD_SHIFT) { |
210 | $self->{shft}++; |
232 | $self->{shft}++; |
211 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
233 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
212 | } elsif ($mod & KMOD_CTRL) { |
234 | } elsif ($mod & CFClient::KMOD_CTRL) { |
213 | $self->{ctrl}++; |
235 | $self->{ctrl}++; |
214 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
236 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
215 | } else { |
237 | } else { |
216 | $::CONN->user_send ("$DIR{$sym}[1]"); |
238 | $::CONN->user_send ("$DIR{$sym}[1]"); |
217 | } |
239 | } |
… | |
… | |
219 | } |
241 | } |
220 | |
242 | |
221 | sub key_up { |
243 | sub key_up { |
222 | my ($self, $ev) = @_; |
244 | my ($self, $ev) = @_; |
223 | |
245 | |
224 | my $mod = $ev->key_mod; |
246 | my $mod = $ev->{mod}; |
225 | my $sym = $ev->key_sym; |
247 | my $sym = $ev->{sym}; |
226 | |
248 | |
227 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
249 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
228 | $::CONN->user_send ("fire_stop"); |
250 | $::CONN->user_send ("fire_stop"); |
229 | } |
251 | } |
230 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
252 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
231 | $::CONN->user_send ("run_stop"); |
253 | $::CONN->user_send ("run_stop"); |
232 | } |
254 | } |
233 | } |
255 | } |
234 | |
256 | |
|
|
257 | sub add_command { |
|
|
258 | my ($self, $command, $widget, $cb) = @_; |
|
|
259 | |
|
|
260 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
|
|
261 | warn "$command|$abbrev|$widget\n";#d# |
|
|
262 | } |
|
|
263 | |
235 | 1 |
264 | 1 |