… | |
… | |
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::OpenGL; |
7 | use CFClient::OpenGL; |
8 | |
8 | |
9 | our @ISA = CFClient::UI::Base::; |
9 | our @ISA = CFClient::UI::Base::; |
10 | |
10 | |
11 | sub new { |
11 | sub new { |
12 | my $class = shift; |
12 | my $class = shift; |
13 | |
13 | |
14 | $class->SUPER::new ( |
14 | $class->SUPER::new ( |
15 | z => -1, |
15 | z => -1, |
16 | can_focus => 1, |
16 | can_focus => 1, |
17 | list => (glGenLists 1), |
17 | list => glGenList, |
18 | @_ |
18 | @_ |
19 | ) |
19 | ) |
20 | } |
20 | } |
21 | |
21 | |
|
|
22 | sub DESTROY { |
|
|
23 | my $self = shift; |
|
|
24 | |
|
|
25 | glDeleteList $self->{list}; |
|
|
26 | |
|
|
27 | $self->SUPER::DESTROY; |
|
|
28 | } |
|
|
29 | |
22 | sub key_down { |
30 | sub key_down { |
23 | print "MAPKEYDOWN\n"; |
31 | print "MAPKEYDOWN\n"; |
24 | } |
32 | } |
25 | |
33 | |
26 | sub key_up { |
34 | sub key_up { |
… | |
… | |
29 | sub button_down { |
37 | sub button_down { |
30 | my ($self, $ev, $x, $y) = @_; |
38 | my ($self, $ev, $x, $y) = @_; |
31 | |
39 | |
32 | $self->focus_in; |
40 | $self->focus_in; |
33 | |
41 | |
34 | if ($ev->button == 2) { |
42 | if ($ev->{button} == 2) { |
35 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
43 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
36 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
44 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
37 | |
45 | |
38 | $self->{motion} = sub { |
46 | $self->{motion} = sub { |
39 | my ($ev, $x, $y) = @_; |
47 | my ($ev, $x, $y) = @_; |
40 | |
48 | |
41 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
49 | ($x, $y) = ($ev->{x}, $ev->{y}); |
42 | |
50 | |
43 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
51 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
44 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
52 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
45 | |
53 | |
46 | $self->update; |
54 | $self->update; |
… | |
… | |
76 | |
84 | |
77 | sub draw { |
85 | sub draw { |
78 | my ($self) = @_; |
86 | my ($self) = @_; |
79 | |
87 | |
80 | if (delete $self->{need_update}) { |
88 | if (delete $self->{need_update}) { |
81 | glNewList $self->{list}, GL_COMPILE; |
89 | glNewList $self->{list}; |
82 | |
90 | |
83 | if ($::MAP) { |
91 | if ($::MAP) { |
84 | my $sw = int $::WIDTH / 32; |
92 | my $sw = int $::WIDTH / 32; |
85 | my $sh = int $::HEIGHT / 32; |
93 | my $sh = int $::HEIGHT / 32; |
86 | |
94 | |
… | |
… | |
129 | } |
137 | } |
130 | |
138 | |
131 | # HACK BEGIN |
139 | # HACK BEGIN |
132 | { |
140 | { |
133 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
141 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
142 | |
|
|
143 | glTranslate 0, 30; |
134 | my ($w, $h) = (250, 250); |
144 | my ($w, $h) = (250, 250); |
|
|
145 | |
|
|
146 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
135 | |
147 | |
136 | glEnable GL_BLEND; |
148 | glEnable GL_BLEND; |
137 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
149 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
138 | glEnable GL_TEXTURE_2D; |
150 | glEnable GL_TEXTURE_2D; |
139 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
151 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
140 | |
152 | |
141 | $self->{mapmap_texture} = |
153 | $self->{mapmap_texture} = |
142 | new CFClient::Texture |
154 | new CFClient::Texture |
143 | w => $w, |
155 | w => $w, |
144 | h => $h, |
156 | h => $h, |
145 | data => $::MAP->mapmap ($w, $h), |
157 | data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h), |
146 | 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; |
147 | |
159 | |
148 | $self->{mapmap_texture}->draw_quad (100, 100); |
160 | $self->{mapmap_texture}->draw_quad (0, 0); |
149 | |
161 | |
150 | 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 | |
151 | glDisable GL_BLEND; |
174 | glDisable GL_BLEND; |
152 | } |
175 | } |
153 | # HACK END |
176 | # HACK END |
154 | } |
177 | } |
155 | |
178 | |
… | |
… | |
191 | ); |
214 | ); |
192 | |
215 | |
193 | sub key_down { |
216 | sub key_down { |
194 | my ($self, $ev) = @_; |
217 | my ($self, $ev) = @_; |
195 | |
218 | |
196 | my $mod = $ev->key_mod; |
219 | my $mod = $ev->{mod}; |
197 | my $sym = $ev->key_sym; |
220 | my $sym = $ev->{sym}; |
198 | |
221 | |
199 | if ($sym == CFClient::SDLK_KP5) { |
222 | if ($sym == CFClient::SDLK_KP5) { |
200 | $::CONN->user_send ("stay fire"); |
223 | $::CONN->user_send ("stay fire"); |
201 | } elsif ($sym == ord "a") { |
224 | } elsif ($sym == ord "a") { |
202 | $::CONN->user_send ("apply"); |
225 | $::CONN->user_send ("apply"); |
… | |
… | |
218 | } |
241 | } |
219 | |
242 | |
220 | sub key_up { |
243 | sub key_up { |
221 | my ($self, $ev) = @_; |
244 | my ($self, $ev) = @_; |
222 | |
245 | |
223 | my $mod = $ev->key_mod; |
246 | my $mod = $ev->{mod}; |
224 | my $sym = $ev->key_sym; |
247 | my $sym = $ev->{sym}; |
225 | |
248 | |
226 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
249 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
227 | $::CONN->user_send ("fire_stop"); |
250 | $::CONN->user_send ("fire_stop"); |
228 | } |
251 | } |
229 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
252 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |