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.8 by root, Sat Apr 22 21:47:45 2006 UTC vs.
Revision 1.21 by root, Mon May 8 17:23:08 2006 UTC

1package CFClient::MapWidget; 1package CFClient::MapWidget;
2 2
3use strict; 3use strict;
4use utf8;
4 5
5use List::Util qw(min max); 6use List::Util qw(min max);
6 7
7use CFClient::OpenGL; 8use CFClient::OpenGL;
8 9
9our @ISA = CFClient::UI::Base::; 10our @ISA = CFClient::UI::Base::;
10 11
11sub new { 12sub new {
12 my $class = shift; 13 my $class = shift;
13 14
14 $class->SUPER::new ( 15 my $self = $class->SUPER::new (
15 z => -1, 16 z => -1,
16 can_focus => 1, 17 can_focus => 1,
17 list => glGenList, 18 list => glGenList,
18 @_ 19 @_
19 ) 20 );
21
22 $self->add_command ("killpets", "kills all your summoned and charmed creates");
23
24 $self
20} 25}
21 26
22sub DESTROY { 27sub DESTROY {
23 my $self = shift; 28 my $self = shift;
24 29
80 85
81 if (delete $self->{need_update}) { 86 if (delete $self->{need_update}) {
82 glNewList $self->{list}; 87 glNewList $self->{list};
83 88
84 if ($::MAP) { 89 if ($::MAP) {
85 my $sw = int $::WIDTH / 32; 90 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
86 my $sh = int $::HEIGHT / 32; 91 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
87 92
88 my $sx = $::CFG->{map_shift_x}; 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;
89 my $sy = $::CFG->{map_shift_y}; 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};
90 98
91 glTranslate $sx0 - 32, $sy0 - 32, 0; 99 glTranslate $sx0 - 32, $sy0 - 32, 0;
92 100
93 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);
94 102
127 135
128 glDisable GL_TEXTURE_2D; 136 glDisable GL_TEXTURE_2D;
129 glDisable GL_BLEND; 137 glDisable GL_BLEND;
130 } 138 }
131 139
132 # HACK BEGIN 140 glPopMatrix;
133 {
134 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
135
136 glTranslate 0, 30;
137 my ($w, $h) = (250, 250);
138
139 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
140
141 glEnable GL_BLEND;
142 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
143 glEnable GL_TEXTURE_2D;
144 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
145
146 $self->{mapmap_texture} =
147 new CFClient::Texture
148 w => $w,
149 h => $h,
150 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
151 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
152
153 $self->{mapmap_texture}->draw_quad (0, 0);
154
155 glDisable GL_TEXTURE_2D;
156
157 glTranslate 0.375, 0.375;
158
159 glColor 1, 1, 0, 1;
160 glBegin GL_LINE_LOOP;
161 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ;
162 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh;
163 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh;
164 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ;
165 glEnd;
166
167 glDisable GL_BLEND;
168 }
169 # HACK END
170 } 141 }
171 142
172 glEndList; 143 glEndList;
173 } 144 }
174 145
207); 178);
208 179
209sub key_down { 180sub key_down {
210 my ($self, $ev) = @_; 181 my ($self, $ev) = @_;
211 182
183 return unless $::CONN;
184
212 my $mod = $ev->{mod}; 185 my $mod = $ev->{mod};
213 my $sym = $ev->{sym}; 186 my $sym = $ev->{sym};
214 187
215 if ($sym == CFClient::SDLK_KP5) { 188 if ($sym == CFClient::SDLK_KP5) {
216 $::CONN->user_send ("stay fire"); 189 $::CONN->user_send ("stay fire");
190 } elsif ($sym == ord ",") {
191 $::CONN->user_send ("take");
217 } elsif ($sym == ord "a") { 192 } elsif ($sym == ord "a") {
218 $::CONN->user_send ("apply"); 193 $::CONN->user_send ("apply");
219 } elsif ($sym == ord "'") { 194 } elsif ($sym == ord "'") {
220 $self->emit ('activate_console'); 195 $self->emit ('activate_console');
221 } elsif ($sym == ord "/") { 196 } elsif ($sym == ord "/") {
234 $self->{command_widget} ||= 209 $self->{command_widget} ||=
235 new CFClient::MapWidget::Command:: 210 new CFClient::MapWidget::Command::
236 command => $self->{command}, 211 command => $self->{command},
237 can_focus => 1, 212 can_focus => 1,
238 connect_execute => sub { 213 connect_execute => sub {
214 # todo: support callback instead of user_send
239 $::CONN->user_send ($_[1]); 215 $::CONN->user_send ($_[1][1]);
240 }, 216 },
241 connect_close => sub { 217 connect_close => sub {
242 (delete $self->{command_widget})->hide; 218 (delete $self->{command_widget})->hide;
243 $self->focus_in; 219 $self->focus_in;
244 }, 220 },
245 ; 221 ;
246 $self->{command_widget}->key_down ($ev); 222 $self->{command_widget}->key_down ($ev);
223 return unless $self->{command_widget};
247 $self->{command_widget}->show; 224 $self->{command_widget}->show;
248 $self->{command_widget}->focus_in; 225 $self->{command_widget}->focus_in;
249 } 226 }
250} 227}
251 228
262 $::CONN->user_send ("run_stop"); 239 $::CONN->user_send ("run_stop");
263 } 240 }
264} 241}
265 242
266sub add_command { 243sub add_command {
267 my ($self, $command, $widget, $cb) = @_; 244 my ($self, $command, $tooltip, $widget, $cb) = @_;
268 245
269 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 246 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
270 247
271 push @{$self->{command}}, [$abbrev, $command]; 248 $self->{command} = [
272 #warn "$command|$abbrev|$widget\n";#d# 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;
273} 331}
274 332
275package CFClient::MapWidget::Command; 333package CFClient::MapWidget::Command;
276 334
277use strict; 335use strict;
285 343
286 my $self = $class->SUPER::new ( 344 my $self = $class->SUPER::new (
287 @_, 345 @_,
288 children => [map 346 children => [map
289 CFClient::UI::Label->new ( 347 CFClient::UI::Label->new (
290 can_hover => 1, 348 can_hover => 1,
349 can_events => 1,
291 fontsize => $_, 350 fontsize => $_,
292 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8 351 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8
293 ], 352 ],
294 ); 353 );
295 354
296 $self 355 $self
313 my @found; 372 my @found;
314 373
315 for (@$command) { 374 for (@$command) {
316 if ($_->[0] =~ $search_abbrev) { 375 if ($_->[0] =~ $search_abbrev) {
317 push @found, [$_->[0], $_]; 376 push @found, [$_->[0], $_];
318 } elsif ($_[1] =~ $search_full) { 377 } elsif (2 < length $self->{search} and $_->[1] =~ $search_full) {
319 push @found, [$_->[1], $_]; 378 push @found, [$_->[1], $_];
320 } 379 }
321 } 380 }
322 381
323 @found = sort { $a->[0] cmp $b->[0] } @found; 382 @found = sort { $a->[0] cmp $b->[0] } @found;
324 383
325 $self->{children}[0]->set_text ("$self->{search}_"); 384 $self->{children}[0]->set_text ("$self->{search}_");
326 385
327 for (0..5) { 386 for (0..5) {
328 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : ""); 387 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : "");
388 $self->{children}[$_ + 1]{tooltip} = ($found[$_] ? $found[$_][1][2] : "");
329 } 389 }
330 390
331 $self->{select} = $found[0][1][1] 391 $self->{select} = $found[0][1]
332 if @found; 392 if @found;
333 393
334 if (@found > 6) { 394 if (@found > 6) {
335 $self->{children}[6]->set_text ("..."); 395 $self->{children}[6]->set_text ("...");
336 } 396 }
349 $self->emit (execute => $self->{select}); 409 $self->emit (execute => $self->{select});
350 $self->emit ("close"); 410 $self->emit ("close");
351 } 411 }
352 } elsif ($ev->{sym} == 27) { 412 } elsif ($ev->{sym} == 27) {
353 $self->emit ("close"); 413 $self->emit ("close");
354 } elsif ($ev->{unicode}) { 414 return;
415 } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) {
355 $self->{search} .= chr $ev->{unicode}; 416 $self->{search} .= chr $ev->{unicode};
356 $self->update_labels; 417 $self->update_labels;
357 } 418 }
419
420 length $self->{search}
421 or $self->emit ("close");
358} 422}
359 423
3601 4241

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines