ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.17 by root, Mon Apr 24 13:12:32 2006 UTC vs.
Revision 1.21 by root, Mon May 8 17:23:08 2006 UTC

10our @ISA = CFClient::UI::Base::; 10our @ISA = CFClient::UI::Base::;
11 11
12sub new { 12sub new {
13 my $class = shift; 13 my $class = shift;
14 14
15 $class->SUPER::new ( 15 my $self = $class->SUPER::new (
16 z => -1, 16 z => -1,
17 can_focus => 1, 17 can_focus => 1,
18 list => glGenList, 18 list => glGenList,
19 @_ 19 @_
20 ) 20 );
21
22 $self->add_command ("killpets", "kills all your summoned and charmed creates");
23
24 $self
21} 25}
22 26
23sub DESTROY { 27sub DESTROY {
24 my $self = shift; 28 my $self = shift;
25 29
84 88
85 if ($::MAP) { 89 if ($::MAP) {
86 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 90 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
87 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 91 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
88 92
93 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
94 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
95
89 glPushMatrix; 96 glPushMatrix;
90 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 97 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
91
92 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
93 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
94 98
95 glTranslate $sx0 - 32, $sy0 - 32, 0; 99 glTranslate $sx0 - 32, $sy0 - 32, 0;
96 100
97 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 101 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
98 102
131 135
132 glDisable GL_TEXTURE_2D; 136 glDisable GL_TEXTURE_2D;
133 glDisable GL_BLEND; 137 glDisable GL_BLEND;
134 } 138 }
135 139
136 # HACK BEGIN
137 {
138 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
139
140 glTranslate 0, 30;
141 my ($w, $h) = (250, 250);
142
143 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
144
145 glEnable GL_BLEND;
146 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
147 glEnable GL_TEXTURE_2D;
148 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
149
150 glPopMatrix; 140 glPopMatrix;
151
152 $self->{mapmap_texture} =
153 new CFClient::Texture
154 w => $w,
155 h => $h,
156 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
157 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
158
159 $self->{mapmap_texture}->draw_quad (0, 0);
160
161 glDisable GL_TEXTURE_2D;
162
163 glTranslate 0.375, 0.375;
164
165 glColor 1, 1, 0, 1;
166 glBegin GL_LINE_LOOP;
167 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ;
168 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh;
169 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh;
170 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ;
171 glEnd;
172
173 glDisable GL_BLEND;
174 }
175 # HACK END
176 } 141 }
177 142
178 glEndList; 143 glEndList;
179 } 144 }
180 145
212 CFClient::SDLK_LEFT, [7, "west"], 177 CFClient::SDLK_LEFT, [7, "west"],
213); 178);
214 179
215sub key_down { 180sub key_down {
216 my ($self, $ev) = @_; 181 my ($self, $ev) = @_;
182
183 return unless $::CONN;
217 184
218 my $mod = $ev->{mod}; 185 my $mod = $ev->{mod};
219 my $sym = $ev->{sym}; 186 my $sym = $ev->{sym};
220 187
221 if ($sym == CFClient::SDLK_KP5) { 188 if ($sym == CFClient::SDLK_KP5) {
276sub add_command { 243sub add_command {
277 my ($self, $command, $tooltip, $widget, $cb) = @_; 244 my ($self, $command, $tooltip, $widget, $cb) = @_;
278 245
279 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 246 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
280 247
248 $self->{command} = [
281 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb]; 249 [$abbrev, $command, $tooltip, $widget, $cb],
250 grep $_->[1] ne $command, @{ $self->{command} },
251 ];
252}
253
254package CFClient::MapWidget::MapMap;
255
256our @ISA = CFClient::UI::Base::;
257
258use Time::HiRes qw(time);
259use CFClient::OpenGL;
260
261sub size_request {
262 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
263}
264
265sub size_allocate {
266 my ($self, $w, $h) = @_;
267
268 $self->SUPER::size_allocate ($w, $h);
269 $self->update;
270}
271
272sub update {
273 my ($self) = @_;
274
275 delete $self->{texture_atime};
276 $self->SUPER::update;
277}
278
279sub _draw {
280 my ($self) = @_;
281
282 $::MAP or return;
283
284 my ($w, $h) = @$self{qw(w h)};
285
286 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
287 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
288
289 my $sx = int $::CFG->{map_shift_x} / 32;
290 my $sy = int $::CFG->{map_shift_y} / 32;
291
292 my $ox = 0.5 * ($w - $sw);
293 my $oy = 0.5 * ($h - $sh);
294
295 glEnable GL_BLEND;
296 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
297 glEnable GL_TEXTURE_2D;
298 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
299
300 if ($self->{texture_atime} < time) {
301 $self->{texture_atime} = time + 1/3;
302
303 $self->{texture} =
304 new CFClient::Texture
305 w => $w,
306 h => $h,
307 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
308 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
309 }
310
311 $self->{texture}->draw_quad (0, 0);
312
313 glDisable GL_TEXTURE_2D;
314
315 glTranslate 0.375, 0.375;
316
317 #TODO: map scale is completely borked
318
319 my $x0 = int $ox - $sx + 0.5;
320 my $y0 = int $oy - $sy + 0.5;
321
322 glColor 1, 1, 0, 1;
323 glBegin GL_LINE_LOOP;
324 glVertex $x0 , $y0 ;
325 glVertex $x0 , $y0 + $sh;
326 glVertex $x0 + $sw, $y0 + $sh;
327 glVertex $x0 + $sw, $y0 ;
328 glEnd;
329
330 glDisable GL_BLEND;
282} 331}
283 332
284package CFClient::MapWidget::Command; 333package CFClient::MapWidget::Command;
285 334
286use strict; 335use strict;
323 my @found; 372 my @found;
324 373
325 for (@$command) { 374 for (@$command) {
326 if ($_->[0] =~ $search_abbrev) { 375 if ($_->[0] =~ $search_abbrev) {
327 push @found, [$_->[0], $_]; 376 push @found, [$_->[0], $_];
328 } elsif ($_->[1] =~ $search_full) { 377 } elsif (2 < length $self->{search} and $_->[1] =~ $search_full) {
329 push @found, [$_->[1], $_]; 378 push @found, [$_->[1], $_];
330 } 379 }
331 } 380 }
332 381
333 @found = sort { $a->[0] cmp $b->[0] } @found; 382 @found = sort { $a->[0] cmp $b->[0] } @found;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines