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.70 by elmex, Sun Jul 2 19:32:55 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 (
34 . "To enter a verbatim command to send to the server, just type the command, " 38 . "To enter a verbatim command to send to the server, just type the command, "
35 . "followed by a space, and press return. " 39 . "followed by a space, and press return. "
36 . "Typing the initial letters of words (or just any letters) displays guesses " 40 . "Typing the initial letters of words (or just any letters) displays guesses "
37 . "for commands you might want to use.\n" 41 . "for commands you might want to use.\n"
38 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" 42 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n"
39 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.", 43 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining key bindings.",
40 ; 44 ;
41 45
42 $self 46 $self
43} 47}
44 48
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 = 1 + 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 = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
73 77
74 $x -= int 0.5 * $self->{sw}; 78 $x -= int 0.5 * $self->{sw};
75 $y -= int 0.5 * $self->{sh}; 79 $y -= int 0.5 * $self->{sh};
76 80
77 $::CONN->lookat ($x, $y) 81 $::CONN->lookat ($x, $y)
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 {
116 1 120 1
117} 121}
118 122
119sub size_request { 123sub size_request {
120 ( 124 (
121 1 + 32 * int $::WIDTH / 32, 125 32 * CFClient::ceil $::WIDTH / 32,
122 1 + 32 * int $::HEIGHT / 32, 126 32 * CFClient::ceil $::HEIGHT / 32,
123 ) 127 )
124} 128}
125 129
126sub update { 130sub update {
127 my ($self) = @_; 131 my ($self) = @_;
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};
163 $::CONN->user_send ("apply"); 167 $::CONN->user_send ("apply");
164 } elsif ($uni == ord ".") { 168 } elsif ($uni == ord ".") {
165 $::CONN->user_send ($self->{completer}{last_command}) 169 $::CONN->user_send ($self->{completer}{last_command})
166 if exists $self->{completer}{last_command}; 170 if exists $self->{completer}{last_command};
167 } elsif ($uni == ord "\t") { 171 } elsif ($uni == ord "\t") {
168 $::INV_WINDOW->toggle_visibility; 172 $::PL_WINDOW->toggle_visibility;
173 $::PL_NOTEBOOK->set_current_page ("Inventory");
169 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 174 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
170 $::CONN->user_send ("rotateshoottype +"); 175 $::CONN->user_send ("rotateshoottype +");
171 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 176 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
172 $::CONN->user_send ("rotateshoottype -"); 177 $::CONN->user_send ("rotateshoottype -");
173 } elsif ($uni == ord '"') { 178 } elsif ($uni == ord '"') {
191 } 196 }
192 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { 197 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
193 $::BIND_EDITOR->set_binding (undef, undef, [], 198 $::BIND_EDITOR->set_binding (undef, undef, [],
194 sub { 199 sub {
195 my ($mod, $sym, $cmds) = @_; 200 my ($mod, $sym, $cmds) = @_;
196 $::CFG->{bindings}->{$mod}->{$sym} = $cmds; 201 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
197 }); 202 });
198 $::BIND_EDITOR->start; 203 $::BIND_EDITOR->start;
199 $::BIND_EDITOR->show; 204 $::BIND_EDITOR->show;
200 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { 205 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
201 $::BIND_EDITOR->stop; 206 $::BIND_EDITOR->stop;
202 $::BIND_EDITOR->ask_for_bind_and_commit; 207 $::BIND_EDITOR->ask_for_bind_and_commit;
203 $::BIND_EDITOR->hide; 208 $::BIND_EDITOR->hide;
204 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { 209 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
205 $::CONN->user_send ($_) for @$bind_cmd; 210 $::CONN->user_send ($_) for @$bind_cmd;
206 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 211 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
207 $self->{completer}->key_down ($ev); 212 $self->{completer}->invoke_key_down ($ev);
208 $self->{completer}->show; 213 $self->{completer}->show;
209 } else { 214 } else {
210 return 0; 215 return 0;
211 } 216 }
212 217
213 1 218 1
214} 219}
215 220
216sub key_up { 221sub invoke_key_up {
217 my ($self, $ev) = @_; 222 my ($self, $ev) = @_;
218 223
219 my $res = 0; 224 my $res = 0;
220 my $mod = $ev->{mod}; 225 my $mod = $ev->{mod};
221 my $sym = $ev->{sym}; 226 my $sym = $ev->{sym};
244 } 249 }
245 250
246 $res 251 $res
247} 252}
248 253
254sub set_magicmap {
255 my ($self, $w, $h, $x, $y, $data) = @_;
256
257 $x -= $::MAP->ox + int 0.5 * $::MAP->w;
258 $y -= $::MAP->oy + int 0.5 * $::MAP->h;
259
260 $self->{magicmap} = [$x, $y, $w, $h, $data];
261
262 $self->update;
263}
264
249sub draw { 265sub draw {
250 my ($self) = @_; 266 my ($self) = @_;
251 267
252 return unless $::MAP; 268 return unless $::MAP;
253 269
264 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 280 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize;
265 281
266 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 282 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
267 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 283 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
268 284
269 my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize; 285 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize;
270 my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize; 286 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize;
271 287
272 if ($::CFG->{fow_enable}) { 288 if ($::CFG->{fow_enable}) {
273 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 289 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
274 290
275 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 291 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
302 glTranslate $sx0, $sy0; 318 glTranslate $sx0, $sy0;
303 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 319 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
304 320
305 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 321 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
306 322
323 glScale 32, 32;
324
307 if (my $tex = $self->{fow_texture}) { 325 if (my $tex = $self->{fow_texture}) {
308 glEnable GL_TEXTURE_2D; 326 glEnable GL_TEXTURE_2D;
309 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 327 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
310 328
311 glScale 32, 32;
312 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 329 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
313 $self->{fow_texture}->draw_quad_alpha (0, 0); 330 $self->{fow_texture}->draw_quad_alpha (0, 0);
314 331
315 glDisable GL_TEXTURE_2D; 332 glDisable GL_TEXTURE_2D;
316 } 333 }
317 334
335 if ($self->{magicmap}) {
336 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
337
338 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1);
339 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1);
340
341 glTranslate - $x - 1, - $y - 1;
342 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
343 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
344 }
345
318 glPopMatrix; 346 glPopMatrix;
319
320 glEndList; 347 glEndList;
321 } 348 }
322 349
323 glPushMatrix;
324 glCallList $self->{list}; 350 glCallList $self->{list};
325 glPopMatrix;
326 351
327 # TNT2 emulates logops in software (or worse :) 352 # TNT2 emulates logops in software (or worse :)
328 unless ($focused) { 353 unless ($focused) {
329 glColor 0.4, 0.2, 0.2, 0.6; 354 glColor 0.4, 0.2, 0.2, 0.6;
330 glEnable GL_BLEND; 355 glEnable GL_BLEND;
356 381
357sub size_request { 382sub size_request {
358 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 383 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
359} 384}
360 385
361sub size_allocate { 386sub invoke_size_allocate {
362 my ($self, $w, $h) = @_; 387 my ($self, $w, $h) = @_;
363 388
364 $self->SUPER::size_allocate ($w, $h);
365 $self->update; 389 $self->update;
390
391 1
366} 392}
367 393
368sub update { 394sub update {
369 my ($self) = @_; 395 my ($self) = @_;
370 396
455 ]; 481 ];
456 482
457 $self->{entry} = new CFClient::UI::Entry 483 $self->{entry} = new CFClient::UI::Entry
458 on_changed => sub { 484 on_changed => sub {
459 $self->update_labels; 485 $self->update_labels;
486 0
460 }, 487 },
461 on_button_down => sub { 488 on_button_down => sub {
462 my ($entry, $ev, $x, $y) = @_; 489 my ($entry, $ev, $x, $y) = @_;
463 490
464 if ($ev->{button} == 3) { 491 if ($ev->{button} == 3) {
465 (new CFClient::UI::Menu 492 (new CFClient::UI::Menu
466 items => [ 493 items => [
494 ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key"
467 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }] 495 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
468 ], 496 ],
469 )->popup ($ev); 497 )->popup ($ev);
470 return 1; 498 return 1;
471 } 499 }
472 0 500 0
479 if ($ev->{sym} == 13) { 507 if ($ev->{sym} == 13) {
480 if (exists $self->{select}) { 508 if (exists $self->{select}) {
481 $self->{last_command} = $self->{select}; 509 $self->{last_command} = $self->{select};
482 $::CONN->user_send ($self->{select}); 510 $::CONN->user_send ($self->{select});
483 511
484 unshift @{$self->{history}}, $self->{select}; 512 unshift @{$self->{history}}, $self->{entry}->get_text;
485 $self->{hist_ptr} = 0; 513 $self->{hist_ptr} = 0;
486 514
487 $self->hide; 515 $self->hide;
488 } 516 }
489 } elsif ($ev->{sym} == 27) { 517 } elsif ($ev->{sym} == 27) {
490 $self->{hist_ptr} = 0; 518 $self->{hist_ptr} = 0;
491 $self->hide; 519 $self->hide;
492 return;
493 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 520 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
494 if ($self->{hist_ptr} > 1) { 521 if ($self->{hist_ptr} > 1) {
495 $self->{hist_ptr}--; 522 $self->{hist_ptr}--;
496 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 523 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
497 } elsif ($self->{hist_ptr} > 0) { 524 } elsif ($self->{hist_ptr} > 0) {
537 564
538 $self->{entry}->set_text ($prefix); 565 $self->{entry}->set_text ($prefix);
539 $self->show; 566 $self->show;
540} 567}
541 568
542sub size_allocate { 569sub invoke_size_allocate {
543 my ($self, $w, $h) = @_; 570 my ($self, $w, $h) = @_;
544 571
545 $self->SUPER::size_allocate ($w, $h);
546 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 572 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
573
574 $self->SUPER::invoke_size_allocate ($w, $h)
547} 575}
548 576
549sub show { 577sub show {
550 my ($self) = @_; 578 my ($self) = @_;
551 579
552 $self->SUPER::show; 580 $self->SUPER::show;
553 $self->{entry}->focus_in; 581 $self->{entry}->grab_focus;
554} 582}
555 583
556sub hide { 584sub hide {
557 my ($self) = @_; 585 my ($self) = @_;
558 586
559 $self->SUPER::hide; 587 $self->SUPER::hide;
560 $self->{entry}->set_text (""); 588 $self->{entry}->set_text ("");
561} 589}
562 590
563sub key_down { 591sub invoke_key_down {
564 my ($self, $ev) = @_; 592 my ($self, $ev) = @_;
565 593
566 $self->{entry}->key_down ($ev) 594 $self->{entry}->emit (key_down => $ev)
567} 595}
568 596
569sub update_labels { 597sub update_labels {
570 my ($self) = @_; 598 my ($self) = @_;
571 599
658 $label->set_text (""); 686 $label->set_text ("");
659 $label->set_tooltip (""); 687 $label->set_tooltip ("");
660 } 688 }
661 689
662 $self->update; 690 $self->update;
663 ###
664} 691}
665 692
666sub _draw { 693sub _draw {
667 my ($self) = @_; 694 my ($self) = @_;
668 695

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines