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.14 by root, Mon Apr 24 11:54:26 2006 UTC vs.
Revision 1.22 by root, Sat May 13 00:27: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
81 85
82 if (delete $self->{need_update}) { 86 if (delete $self->{need_update}) {
83 glNewList $self->{list}; 87 glNewList $self->{list};
84 88
85 if ($::MAP) { 89 if ($::MAP) {
86 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}); 90 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
87 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}); 91 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
88
89 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
90 92
91 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; 93 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
92 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; 94 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
95
96 glPushMatrix;
97 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
93 98
94 glTranslate $sx0 - 32, $sy0 - 32, 0; 99 glTranslate $sx0 - 32, $sy0 - 32, 0;
95 100
96 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);
97 102
130 135
131 glDisable GL_TEXTURE_2D; 136 glDisable GL_TEXTURE_2D;
132 glDisable GL_BLEND; 137 glDisable GL_BLEND;
133 } 138 }
134 139
135 # HACK BEGIN 140 glPopMatrix;
136 {
137 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
138
139 glTranslate 0, 30;
140 my ($w, $h) = (250, 250);
141
142 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
143
144 glEnable GL_BLEND;
145 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
146 glEnable GL_TEXTURE_2D;
147 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
148
149 $self->{mapmap_texture} =
150 new CFClient::Texture
151 w => $w,
152 h => $h,
153 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
154 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
155
156 $self->{mapmap_texture}->draw_quad (0, 0);
157
158 glDisable GL_TEXTURE_2D;
159
160 glTranslate 0.375, 0.375;
161
162 glColor 1, 1, 0, 1;
163 glBegin GL_LINE_LOOP;
164 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ;
165 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh;
166 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh;
167 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ;
168 glEnd;
169
170 glDisable GL_BLEND;
171 }
172 # HACK END
173 } 141 }
174 142
175 glEndList; 143 glEndList;
176 } 144 }
177 145
210); 178);
211 179
212sub key_down { 180sub key_down {
213 my ($self, $ev) = @_; 181 my ($self, $ev) = @_;
214 182
183 return unless $::CONN;
184
215 my $mod = $ev->{mod}; 185 my $mod = $ev->{mod};
216 my $sym = $ev->{sym}; 186 my $sym = $ev->{sym};
187 my $uni = $ev->{unicode};
217 188
218 if ($sym == CFClient::SDLK_KP5) { 189 if ($sym == CFClient::SDLK_KP5) {
219 $::CONN->user_send ("stay fire"); 190 $::CONN->user_send ("stay fire");
220 } elsif ($sym == ord ",") { 191 } elsif ($uni == ord ",") {
221 $::CONN->user_send ("take"); 192 $::CONN->user_send ("take");
222 } elsif ($sym == ord "a") { 193 } elsif ($uni == ord "a") {
223 $::CONN->user_send ("apply"); 194 $::CONN->user_send ("apply");
224 } elsif ($sym == ord "'") { 195 } elsif ($uni == ord "'") {
225 $self->emit ('activate_console'); 196 $self->emit ('activate_console');
226 } elsif ($sym == ord "/") { 197 } elsif ($uni == ord "/") {
227 $self->emit (activate_console => '/'); 198 $self->emit (activate_console => '/');
228 } elsif (exists $DIR{$sym}) { 199 } elsif (exists $DIR{$sym}) {
229 if ($mod & CFClient::KMOD_SHIFT) { 200 if ($mod & CFClient::KMOD_SHIFT) {
230 $self->{shft}++; 201 $self->{shft}++;
231 $::CONN->user_send ("fire $DIR{$sym}[0]"); 202 $::CONN->user_send ("fire $DIR{$sym}[0]");
273sub add_command { 244sub add_command {
274 my ($self, $command, $tooltip, $widget, $cb) = @_; 245 my ($self, $command, $tooltip, $widget, $cb) = @_;
275 246
276 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 247 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
277 248
249 $self->{command} = [
278 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb]; 250 [$abbrev, $command, $tooltip, $widget, $cb],
251 grep $_->[1] ne $command, @{ $self->{command} },
252 ];
253}
254
255package CFClient::MapWidget::MapMap;
256
257our @ISA = CFClient::UI::Base::;
258
259use Time::HiRes qw(time);
260use CFClient::OpenGL;
261
262sub size_request {
263 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
264}
265
266sub size_allocate {
267 my ($self, $w, $h) = @_;
268
269 $self->SUPER::size_allocate ($w, $h);
270 $self->update;
271}
272
273sub update {
274 my ($self) = @_;
275
276 delete $self->{texture_atime};
277 $self->SUPER::update;
278}
279
280sub _draw {
281 my ($self) = @_;
282
283 $::MAP or return;
284
285 my ($w, $h) = @$self{qw(w h)};
286
287 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
288 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
289
290 my $sx = int $::CFG->{map_shift_x} / 32;
291 my $sy = int $::CFG->{map_shift_y} / 32;
292
293 my $ox = 0.5 * ($w - $sw);
294 my $oy = 0.5 * ($h - $sh);
295
296 glEnable GL_BLEND;
297 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
298 glEnable GL_TEXTURE_2D;
299 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
300
301 if ($self->{texture_atime} < time) {
302 $self->{texture_atime} = time + 1/3;
303
304 $self->{texture} =
305 new CFClient::Texture
306 w => $w,
307 h => $h,
308 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
309 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
310 }
311
312 $self->{texture}->draw_quad (0, 0);
313
314 glDisable GL_TEXTURE_2D;
315
316 glTranslate 0.375, 0.375;
317
318 #TODO: map scale is completely borked
319
320 my $x0 = int $ox - $sx + 0.5;
321 my $y0 = int $oy - $sy + 0.5;
322
323 glColor 1, 1, 0, 1;
324 glBegin GL_LINE_LOOP;
325 glVertex $x0 , $y0 ;
326 glVertex $x0 , $y0 + $sh;
327 glVertex $x0 + $sw, $y0 + $sh;
328 glVertex $x0 + $sw, $y0 ;
329 glEnd;
330
331 glDisable GL_BLEND;
279} 332}
280 333
281package CFClient::MapWidget::Command; 334package CFClient::MapWidget::Command;
282 335
283use strict; 336use strict;
320 my @found; 373 my @found;
321 374
322 for (@$command) { 375 for (@$command) {
323 if ($_->[0] =~ $search_abbrev) { 376 if ($_->[0] =~ $search_abbrev) {
324 push @found, [$_->[0], $_]; 377 push @found, [$_->[0], $_];
325 } elsif ($_[1] =~ $search_full) { 378 } elsif (2 < length $self->{search} and $_->[1] =~ $search_full) {
326 push @found, [$_->[1], $_]; 379 push @found, [$_->[1], $_];
327 } 380 }
328 } 381 }
329 382
330 @found = sort { $a->[0] cmp $b->[0] } @found; 383 @found = sort { $a->[0] cmp $b->[0] } @found;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines