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.74 by root, Sun Jul 16 23:30:08 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;
67
68 $self->focus_in;
69
70 if ($ev->{button} == 1) { 70 if ($ev->{button} == 1) {
71 $self->grab_focus;
72 return unless $::CONN;
73
71 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 74 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}; 75 my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
73 76
74 $x -= int 0.5 * $self->{sw}; 77 $x -= int 0.5 * $self->{sw};
75 $y -= int 0.5 * $self->{sh}; 78 $y -= int 0.5 * $self->{sh};
76 79
77 $::CONN->lookat ($x, $y) 80 $::CONN->lookat ($x, $y)
78 if $::CONN; 81 if $::CONN;
79 82
80 } elsif ($ev->{button} == 2) { 83 } elsif ($ev->{button} == 2) {
84 $self->grab_focus;
85 return unless $::CONN;
86
81 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 87 my ($ox, $oy) = ($ev->{x}, $ev->{y});
82 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 88 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
83 89
84 $self->{motion} = sub { 90 $self->{motion} = sub {
85 my ($ev, $x, $y) = @_; 91 my ($ev, $x, $y) = @_;
89 $::CFG->{map_shift_x} = $bw + $x - $ox; 95 $::CFG->{map_shift_x} = $bw + $x - $ox;
90 $::CFG->{map_shift_y} = $bh + $y - $oy; 96 $::CFG->{map_shift_y} = $bh + $y - $oy;
91 97
92 $self->update; 98 $self->update;
93 }; 99 };
100 } elsif ($ev->{button} == 3) {
101 (new CFClient::UI::Menu
102 items => [
103 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
104 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
105 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
106 ["Inventory…\tF4", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
107 ["Spells…\tF5", sub { ::toggle_player_page ($::SPELL_PAGE) }],
108 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }],
109 ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }],
110 [
111 $::PICKUP_ENABLE->{state}
112 ? "Disable automatic pickup"
113 : "Enable automatic pickup",
114 sub { $::PICKUP_ENABLE->toggle }
115 ],
116 ],
117 )->popup ($ev);
94 } 118 }
95 119
96 1 120 1
97} 121}
98 122
99sub button_up { 123sub invoke_button_up {
100 my ($self, $ev, $x, $y) = @_; 124 my ($self, $ev, $x, $y) = @_;
101 125
102 delete $self->{motion}; 126 delete $self->{motion};
103 127
104 1 128 1
105} 129}
106 130
107sub mouse_motion { 131sub invoke_mouse_motion {
108 my ($self, $ev, $x, $y) = @_; 132 my ($self, $ev, $x, $y) = @_;
109 133
110 if ($self->{motion}) { 134 if ($self->{motion}) {
111 $self->{motion}->($ev, $x, $y); 135 $self->{motion}->($ev, $x, $y);
112 } else { 136 } else {
116 1 140 1
117} 141}
118 142
119sub size_request { 143sub size_request {
120 ( 144 (
121 1 + 32 * int $::WIDTH / 32, 145 32 * CFClient::ceil $::WIDTH / 32,
122 1 + 32 * int $::HEIGHT / 32, 146 32 * CFClient::ceil $::HEIGHT / 32,
123 ) 147 )
124} 148}
125 149
126sub update { 150sub update {
127 my ($self) = @_; 151 my ($self) = @_;
144 CFClient::SDLK_RIGHT, [3, "east"], 168 CFClient::SDLK_RIGHT, [3, "east"],
145 CFClient::SDLK_DOWN, [5, "south"], 169 CFClient::SDLK_DOWN, [5, "south"],
146 CFClient::SDLK_LEFT, [7, "west"], 170 CFClient::SDLK_LEFT, [7, "west"],
147); 171);
148 172
149sub key_down { 173sub invoke_key_down {
150 my ($self, $ev) = @_; 174 my ($self, $ev) = @_;
151
152 return 0 unless $::CONN;
153 175
154 my $mod = $ev->{mod}; 176 my $mod = $ev->{mod};
155 my $sym = $ev->{sym}; 177 my $sym = $ev->{sym};
156 my $uni = $ev->{unicode}; 178 my $uni = $ev->{unicode};
157 179
180 $mod &= CFClient::KMOD_CTRL | CFClient::KMOD_ALT | CFClient::KMOD_SHIFT;
181
182 if ($uni == ord "\t") {
183 $::PL_WINDOW->toggle_visibility;
184 } elsif ($sym == CFClient::SDLK_F1 && !$mod) {
185 $::HELP_WINDOW->toggle_visibility;
186 } elsif ($sym == CFClient::SDLK_F2 && !$mod) {
187 ::toggle_player_page ($::STATS_PAGE);
188 } elsif ($sym == CFClient::SDLK_F3 && !$mod) {
189 ::toggle_player_page ($::SKILL_PAGE);
190 } elsif ($sym == CFClient::SDLK_F4 && !$mod) {
191 ::toggle_player_page ($::INVENTORY_PAGE);
192 } elsif ($sym == CFClient::SDLK_F5 && !$mod) {
193 ::toggle_player_page ($::SPELL_PAGE);
194 } elsif ($sym == CFClient::SDLK_F9 && !$mod) {
195 $::SETUP_DIALOG->toggle_visibility;
196 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
197 $::BIND_EDITOR->set_binding (undef, undef, [],
198 sub {
199 my ($mod, $sym, $cmds) = @_;
200 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
201 });
202 $::BIND_EDITOR->start;
203 $::BIND_EDITOR->show;
204 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
205 $::BIND_EDITOR->stop;
206 $::BIND_EDITOR->ask_for_bind_and_commit;
207 $::BIND_EDITOR->hide;
208 } elsif (!$::CONN) {
209 return 0; # bindings further down need a valid connection
210
158 if ($sym == CFClient::SDLK_KP5) { 211 } elsif ($sym == CFClient::SDLK_KP5 && !$mod) {
159 $::CONN->user_send ("stay fire"); 212 $::CONN->user_send ("stay fire");
160 } elsif ($uni == ord ",") { 213 } elsif ($uni == ord ",") {
161 $::CONN->user_send ("take"); 214 $::CONN->user_send ("take");
162 } elsif ($uni == ord " ") { 215 } elsif ($uni == ord " ") {
163 $::CONN->user_send ("apply"); 216 $::CONN->user_send ("apply");
164 } elsif ($uni == ord ".") { 217 } elsif ($uni == ord ".") {
165 $::CONN->user_send ($self->{completer}{last_command}) 218 $::CONN->user_send ($self->{completer}{last_command})
166 if exists $self->{completer}{last_command}; 219 if exists $self->{completer}{last_command};
167 } elsif ($uni == ord "\t") { 220 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
168 $::INV_WINDOW->toggle_visibility; 221 $::CONN->user_send ($_) for @$bind_cmd;
169 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 222 } elsif (($sym == CFClient::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
170 $::CONN->user_send ("rotateshoottype +"); 223 $::CONN->user_send ("rotateshoottype +");
171 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 224 } elsif (($sym == CFClient::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
172 $::CONN->user_send ("rotateshoottype -"); 225 $::CONN->user_send ("rotateshoottype -");
173 } elsif ($uni == ord '"') { 226 } elsif ($uni == ord '"') {
174 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 227 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
175 $self->{completer}->show; 228 $self->{completer}->show;
176 } elsif ($uni == ord "'") { 229 } elsif ($uni == ord "'") {
187 $self->{ctrl}++; 240 $self->{ctrl}++;
188 $::CONN->user_send ("run $DIR{$sym}[0]"); 241 $::CONN->user_send ("run $DIR{$sym}[0]");
189 } else { 242 } else {
190 $::CONN->user_send ("$DIR{$sym}[1]"); 243 $::CONN->user_send ("$DIR{$sym}[1]");
191 } 244 }
192 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
193 $::BIND_EDITOR->set_binding (undef, undef, [],
194 sub {
195 my ($mod, $sym, $cmds) = @_;
196 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
197 });
198 $::BIND_EDITOR->start;
199 $::BIND_EDITOR->show;
200 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
201 $::BIND_EDITOR->stop;
202 $::BIND_EDITOR->ask_for_bind_and_commit;
203 $::BIND_EDITOR->hide;
204 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
205 $::CONN->user_send ($_) for @$bind_cmd;
206 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 245 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
207 $self->{completer}->key_down ($ev); 246 $self->{completer}->invoke_key_down ($ev);
208 $self->{completer}->show; 247 $self->{completer}->show;
209 } else { 248 } else {
210 return 0; 249 return 0;
211 } 250 }
212 251
213 1 252 1
214} 253}
215 254
216sub key_up { 255sub invoke_key_up {
217 my ($self, $ev) = @_; 256 my ($self, $ev) = @_;
218 257
219 my $res = 0; 258 my $res = 0;
220 my $mod = $ev->{mod}; 259 my $mod = $ev->{mod};
221 my $sym = $ev->{sym}; 260 my $sym = $ev->{sym};
244 } 283 }
245 284
246 $res 285 $res
247} 286}
248 287
288sub set_magicmap {
289 my ($self, $w, $h, $x, $y, $data) = @_;
290
291 $x -= $::MAP->ox + int 0.5 * $::MAP->w;
292 $y -= $::MAP->oy + int 0.5 * $::MAP->h;
293
294 $self->{magicmap} = [$x, $y, $w, $h, $data];
295
296 $self->update;
297}
298
249sub draw { 299sub draw {
250 my ($self) = @_; 300 my ($self) = @_;
251 301
252 return unless $::MAP; 302 return unless $::MAP;
253 303
264 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 314 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize;
265 315
266 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 316 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
267 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 317 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
268 318
269 my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize; 319 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize;
270 my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize; 320 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize;
271 321
272 if ($::CFG->{fow_enable}) { 322 if ($::CFG->{fow_enable}) {
273 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 323 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
274 324
275 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 325 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
302 glTranslate $sx0, $sy0; 352 glTranslate $sx0, $sy0;
303 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 353 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
304 354
305 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 355 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
306 356
357 glScale 32, 32;
358
307 if (my $tex = $self->{fow_texture}) { 359 if (my $tex = $self->{fow_texture}) {
308 glEnable GL_TEXTURE_2D; 360 glEnable GL_TEXTURE_2D;
309 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 361 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
310 362
311 glScale 32, 32;
312 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 363 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
313 $self->{fow_texture}->draw_quad_alpha (0, 0); 364 $self->{fow_texture}->draw_quad_alpha (0, 0);
314 365
315 glDisable GL_TEXTURE_2D; 366 glDisable GL_TEXTURE_2D;
316 } 367 }
317 368
369 if ($self->{magicmap}) {
370 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
371
372 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1);
373 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1);
374
375 glTranslate - $x - 1, - $y - 1;
376 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
377 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
378 }
379
318 glPopMatrix; 380 glPopMatrix;
319
320 glEndList; 381 glEndList;
321 } 382 }
322 383
323 glPushMatrix;
324 glCallList $self->{list}; 384 glCallList $self->{list};
325 glPopMatrix;
326 385
327 # TNT2 emulates logops in software (or worse :) 386 # TNT2 emulates logops in software (or worse :)
328 unless ($focused) { 387 unless ($focused) {
329 glColor 0.4, 0.2, 0.2, 0.6; 388 glColor 0.4, 0.2, 0.2, 0.6;
330 glEnable GL_BLEND; 389 glEnable GL_BLEND;
356 415
357sub size_request { 416sub size_request {
358 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 417 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
359} 418}
360 419
361sub size_allocate { 420sub invoke_size_allocate {
362 my ($self, $w, $h) = @_; 421 my ($self, $w, $h) = @_;
363 422
364 $self->SUPER::size_allocate ($w, $h);
365 $self->update; 423 $self->update;
424
425 1
366} 426}
367 427
368sub update { 428sub update {
369 my ($self) = @_; 429 my ($self) = @_;
370 430
455 ]; 515 ];
456 516
457 $self->{entry} = new CFClient::UI::Entry 517 $self->{entry} = new CFClient::UI::Entry
458 on_changed => sub { 518 on_changed => sub {
459 $self->update_labels; 519 $self->update_labels;
520 0
460 }, 521 },
461 on_button_down => sub { 522 on_button_down => sub {
462 my ($entry, $ev, $x, $y) = @_; 523 my ($entry, $ev, $x, $y) = @_;
463 524
464 if ($ev->{button} == 3) { 525 if ($ev->{button} == 3) {
465 (new CFClient::UI::Menu 526 (new CFClient::UI::Menu
466 items => [ 527 items => [
528 ["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 }) }] 529 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
468 ], 530 ],
469 )->popup ($ev); 531 )->popup ($ev);
470 return 1; 532 return 1;
471 } 533 }
472 0 534 0
479 if ($ev->{sym} == 13) { 541 if ($ev->{sym} == 13) {
480 if (exists $self->{select}) { 542 if (exists $self->{select}) {
481 $self->{last_command} = $self->{select}; 543 $self->{last_command} = $self->{select};
482 $::CONN->user_send ($self->{select}); 544 $::CONN->user_send ($self->{select});
483 545
484 unshift @{$self->{history}}, $self->{select}; 546 unshift @{$self->{history}}, $self->{entry}->get_text;
485 $self->{hist_ptr} = 0; 547 $self->{hist_ptr} = 0;
486 548
487 $self->hide; 549 $self->hide;
488 } 550 }
489 } elsif ($ev->{sym} == 27) { 551 } elsif ($ev->{sym} == 27) {
490 $self->{hist_ptr} = 0; 552 $self->{hist_ptr} = 0;
491 $self->hide; 553 $self->hide;
492 return;
493 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 554 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
494 if ($self->{hist_ptr} > 1) { 555 if ($self->{hist_ptr} > 1) {
495 $self->{hist_ptr}--; 556 $self->{hist_ptr}--;
496 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 557 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
497 } elsif ($self->{hist_ptr} > 0) { 558 } elsif ($self->{hist_ptr} > 0) {
537 598
538 $self->{entry}->set_text ($prefix); 599 $self->{entry}->set_text ($prefix);
539 $self->show; 600 $self->show;
540} 601}
541 602
542sub size_allocate { 603sub invoke_size_allocate {
543 my ($self, $w, $h) = @_; 604 my ($self, $w, $h) = @_;
544 605
545 $self->SUPER::size_allocate ($w, $h);
546 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 606 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
607
608 $self->SUPER::invoke_size_allocate ($w, $h)
547} 609}
548 610
549sub show { 611sub show {
550 my ($self) = @_; 612 my ($self) = @_;
551 613
552 $self->SUPER::show; 614 $self->SUPER::show;
553 $self->{entry}->focus_in; 615 $self->{entry}->grab_focus;
554} 616}
555 617
556sub hide { 618sub hide {
557 my ($self) = @_; 619 my ($self) = @_;
558 620
559 $self->SUPER::hide; 621 $self->SUPER::hide;
560 $self->{entry}->set_text (""); 622 $self->{entry}->set_text ("");
561} 623}
562 624
563sub key_down { 625sub invoke_key_down {
564 my ($self, $ev) = @_; 626 my ($self, $ev) = @_;
565 627
566 $self->{entry}->key_down ($ev) 628 $self->{entry}->emit (key_down => $ev)
567} 629}
568 630
569sub update_labels { 631sub update_labels {
570 my ($self) = @_; 632 my ($self) = @_;
571 633
658 $label->set_text (""); 720 $label->set_text ("");
659 $label->set_tooltip (""); 721 $label->set_tooltip ("");
660 } 722 }
661 723
662 $self->update; 724 $self->update;
663 ###
664} 725}
665 726
666sub _draw { 727sub _draw {
667 my ($self) = @_; 728 my ($self) = @_;
668 729

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines