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.60 by root, Thu Jun 15 08:29:18 2006 UTC vs.
Revision 1.63 by root, Sun Jun 18 17:13:11 2006 UTC

6use List::Util qw(min max); 6use List::Util qw(min max);
7 7
8use CFClient::OpenGL; 8use CFClient::OpenGL;
9 9
10our @ISA = CFClient::UI::Base::; 10our @ISA = CFClient::UI::Base::;
11
12my $magicmap_tex =
13 new_from_file CFClient::Texture CFClient::find_rcfile "magicmap.png",
14 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
11 15
12sub new { 16sub new {
13 my $class = shift; 17 my $class = shift;
14 18
15 my $self = $class->SUPER::new ( 19 my $self = $class->SUPER::new (
58 my ($self) = @_; 62 my ($self) = @_;
59 63
60 %{$self->{completer}{command}} = (); 64 %{$self->{completer}{command}} = ();
61} 65}
62 66
63sub button_down { 67sub invoke_button_down {
64 my ($self, $ev, $x, $y) = @_; 68 my ($self, $ev, $x, $y) = @_;
65 69
66 return unless $::CONN; 70 return unless $::CONN;
67 71
68 $self->focus_in; 72 $self->grab_focus;
69 73
70 if ($ev->{button} == 1) { 74 if ($ev->{button} == 1) {
71 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 75 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
72 my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 76 my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
73 77
94 } 98 }
95 99
96 1 100 1
97} 101}
98 102
99sub button_up { 103sub invoke_button_up {
100 my ($self, $ev, $x, $y) = @_; 104 my ($self, $ev, $x, $y) = @_;
101 105
102 delete $self->{motion}; 106 delete $self->{motion};
103 107
104 1 108 1
105} 109}
106 110
107sub mouse_motion { 111sub invoke_mouse_motion {
108 my ($self, $ev, $x, $y) = @_; 112 my ($self, $ev, $x, $y) = @_;
109 113
110 if ($self->{motion}) { 114 if ($self->{motion}) {
111 $self->{motion}->($ev, $x, $y); 115 $self->{motion}->($ev, $x, $y);
112 } else { 116 } else {
144 CFClient::SDLK_RIGHT, [3, "east"], 148 CFClient::SDLK_RIGHT, [3, "east"],
145 CFClient::SDLK_DOWN, [5, "south"], 149 CFClient::SDLK_DOWN, [5, "south"],
146 CFClient::SDLK_LEFT, [7, "west"], 150 CFClient::SDLK_LEFT, [7, "west"],
147); 151);
148 152
149sub key_down { 153sub invoke_key_down {
150 my ($self, $ev) = @_; 154 my ($self, $ev) = @_;
151 155
152 return 0 unless $::CONN; 156 return 0 unless $::CONN;
153 157
154 my $mod = $ev->{mod}; 158 my $mod = $ev->{mod};
211 } 215 }
212 216
213 1 217 1
214} 218}
215 219
216sub key_up { 220sub invoke_key_up {
217 my ($self, $ev) = @_; 221 my ($self, $ev) = @_;
218 222
219 my $res = 0; 223 my $res = 0;
220 my $mod = $ev->{mod}; 224 my $mod = $ev->{mod};
221 my $sym = $ev->{sym}; 225 my $sym = $ev->{sym};
244 } 248 }
245 249
246 $res 250 $res
247} 251}
248 252
253sub set_magicmap {
254 my ($self, $w, $h, $x, $y, $data) = @_;
255
256 $x -= $::MAP->ox + int 0.5 * $::MAP->w;
257 $y -= $::MAP->oy + int 0.5 * $::MAP->h;
258
259 $self->{magicmap} = [$x, $y, $w, $h, $data];
260
261 $self->update;
262}
263
249sub draw { 264sub draw {
250 my ($self) = @_; 265 my ($self) = @_;
251 266
252 return unless $::MAP; 267 return unless $::MAP;
253 268
264 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 279 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize;
265 280
266 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 281 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
267 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 282 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
268 283
269 my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize; 284 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize;
270 my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize; 285 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize;
271 286
272 if ($::CFG->{fow_enable}) { 287 if ($::CFG->{fow_enable}) {
273 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 288 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
274 289
275 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 290 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
302 glTranslate $sx0, $sy0; 317 glTranslate $sx0, $sy0;
303 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 318 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
304 319
305 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 320 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
306 321
322 glScale 32, 32;
323
307 if (my $tex = $self->{fow_texture}) { 324 if (my $tex = $self->{fow_texture}) {
308 glEnable GL_TEXTURE_2D; 325 glEnable GL_TEXTURE_2D;
309 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 326 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
310 327
311 glScale 32, 32;
312 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 328 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
313 $self->{fow_texture}->draw_quad_alpha (0, 0); 329 $self->{fow_texture}->draw_quad_alpha (0, 0);
314 330
315 glDisable GL_TEXTURE_2D; 331 glDisable GL_TEXTURE_2D;
316 } 332 }
317 333
334 if ($self->{magicmap}) {
335 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
336
337 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1);
338 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1);
339
340 glTranslate - $x - 1, - $y - 1;
341 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
342 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
343 }
344
318 glPopMatrix; 345 glPopMatrix;
319
320 glEndList; 346 glEndList;
321 } 347 }
322 348
323 glPushMatrix;
324 glCallList $self->{list}; 349 glCallList $self->{list};
325 glPopMatrix;
326 350
327 # TNT2 emulates logops in software (or worse :) 351 # TNT2 emulates logops in software (or worse :)
328 unless ($focused) { 352 unless ($focused) {
329 glColor 0.4, 0.2, 0.2, 0.6; 353 glColor 0.4, 0.2, 0.2, 0.6;
330 glEnable GL_BLEND; 354 glEnable GL_BLEND;
356 380
357sub size_request { 381sub size_request {
358 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 382 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
359} 383}
360 384
361sub size_allocate { 385sub invoke_size_allocate {
362 my ($self, $w, $h) = @_; 386 my ($self, $w, $h) = @_;
363 387
364 $self->SUPER::size_allocate ($w, $h);
365 $self->update; 388 $self->update;
389
390 1
366} 391}
367 392
368sub update { 393sub update {
369 my ($self) = @_; 394 my ($self) = @_;
370 395
455 ]; 480 ];
456 481
457 $self->{entry} = new CFClient::UI::Entry 482 $self->{entry} = new CFClient::UI::Entry
458 on_changed => sub { 483 on_changed => sub {
459 $self->update_labels; 484 $self->update_labels;
485 0
460 }, 486 },
461 on_button_down => sub { 487 on_button_down => sub {
462 my ($entry, $ev, $x, $y) = @_; 488 my ($entry, $ev, $x, $y) = @_;
463 489
464 if ($ev->{button} == 3) { 490 if ($ev->{button} == 3) {
465 (new CFClient::UI::Menu 491 (new CFClient::UI::Menu
466 items => [ 492 items => [
467 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }] 493 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
468 ], 494 ],
469 )->popup ($ev); 495 )->popup ($ev);
470 return 1; 496 return 1;
471 } 497 }
472 0 498 0
537 563
538 $self->{entry}->set_text ($prefix); 564 $self->{entry}->set_text ($prefix);
539 $self->show; 565 $self->show;
540} 566}
541 567
542sub size_allocate { 568sub invoke_size_allocate {
543 my ($self, $w, $h) = @_; 569 my ($self, $w, $h) = @_;
544 570
545 $self->SUPER::size_allocate ($w, $h);
546 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 571 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
572
573 $self->SUPER::invoke_size_allocate ($w, $h)
547} 574}
548 575
549sub show { 576sub show {
550 my ($self) = @_; 577 my ($self) = @_;
551 578
552 $self->SUPER::show; 579 $self->SUPER::show;
553 $self->{entry}->focus_in; 580 $self->{entry}->grab_focus;
554} 581}
555 582
556sub hide { 583sub hide {
557 my ($self) = @_; 584 my ($self) = @_;
558 585
559 $self->SUPER::hide; 586 $self->SUPER::hide;
560 $self->{entry}->set_text (""); 587 $self->{entry}->set_text ("");
561} 588}
562 589
563sub key_down { 590sub invoke_key_down {
564 my ($self, $ev) = @_; 591 my ($self, $ev) = @_;
565 592
566 $self->{entry}->key_down ($ev) 593 $self->{entry}->key_down ($ev)
567} 594}
568 595

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines