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.62 by root, Thu Jun 15 16:44:20 2006 UTC vs.
Revision 1.70 by elmex, Sun Jul 2 19:32:55 2006 UTC

38 . "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, "
39 . "followed by a space, and press return. " 39 . "followed by a space, and press return. "
40 . "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 "
41 . "for commands you might want to use.\n" 41 . "for commands you might want to use.\n"
42 . "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"
43 . "<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.",
44 ; 44 ;
45 45
46 $self 46 $self
47} 47}
48 48
62 my ($self) = @_; 62 my ($self) = @_;
63 63
64 %{$self->{completer}{command}} = (); 64 %{$self->{completer}{command}} = ();
65} 65}
66 66
67sub button_down { 67sub invoke_button_down {
68 my ($self, $ev, $x, $y) = @_; 68 my ($self, $ev, $x, $y) = @_;
69 69
70 return unless $::CONN; 70 return unless $::CONN;
71 71
72 $self->focus_in; 72 $self->grab_focus;
73 73
74 if ($ev->{button} == 1) { 74 if ($ev->{button} == 1) {
75 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};
76 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};
77 77
78 $x -= int 0.5 * $self->{sw}; 78 $x -= int 0.5 * $self->{sw};
79 $y -= int 0.5 * $self->{sh}; 79 $y -= int 0.5 * $self->{sh};
80 80
81 $::CONN->lookat ($x, $y) 81 $::CONN->lookat ($x, $y)
98 } 98 }
99 99
100 1 100 1
101} 101}
102 102
103sub button_up { 103sub invoke_button_up {
104 my ($self, $ev, $x, $y) = @_; 104 my ($self, $ev, $x, $y) = @_;
105 105
106 delete $self->{motion}; 106 delete $self->{motion};
107 107
108 1 108 1
109} 109}
110 110
111sub mouse_motion { 111sub invoke_mouse_motion {
112 my ($self, $ev, $x, $y) = @_; 112 my ($self, $ev, $x, $y) = @_;
113 113
114 if ($self->{motion}) { 114 if ($self->{motion}) {
115 $self->{motion}->($ev, $x, $y); 115 $self->{motion}->($ev, $x, $y);
116 } else { 116 } else {
120 1 120 1
121} 121}
122 122
123sub size_request { 123sub size_request {
124 ( 124 (
125 1 + 32 * int $::WIDTH / 32, 125 32 * CFClient::ceil $::WIDTH / 32,
126 1 + 32 * int $::HEIGHT / 32, 126 32 * CFClient::ceil $::HEIGHT / 32,
127 ) 127 )
128} 128}
129 129
130sub update { 130sub update {
131 my ($self) = @_; 131 my ($self) = @_;
148 CFClient::SDLK_RIGHT, [3, "east"], 148 CFClient::SDLK_RIGHT, [3, "east"],
149 CFClient::SDLK_DOWN, [5, "south"], 149 CFClient::SDLK_DOWN, [5, "south"],
150 CFClient::SDLK_LEFT, [7, "west"], 150 CFClient::SDLK_LEFT, [7, "west"],
151); 151);
152 152
153sub key_down { 153sub invoke_key_down {
154 my ($self, $ev) = @_; 154 my ($self, $ev) = @_;
155 155
156 return 0 unless $::CONN; 156 return 0 unless $::CONN;
157 157
158 my $mod = $ev->{mod}; 158 my $mod = $ev->{mod};
167 $::CONN->user_send ("apply"); 167 $::CONN->user_send ("apply");
168 } elsif ($uni == ord ".") { 168 } elsif ($uni == ord ".") {
169 $::CONN->user_send ($self->{completer}{last_command}) 169 $::CONN->user_send ($self->{completer}{last_command})
170 if exists $self->{completer}{last_command}; 170 if exists $self->{completer}{last_command};
171 } elsif ($uni == ord "\t") { 171 } elsif ($uni == ord "\t") {
172 $::INV_WINDOW->toggle_visibility; 172 $::PL_WINDOW->toggle_visibility;
173 $::PL_NOTEBOOK->set_current_page ("Inventory");
173 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 174 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
174 $::CONN->user_send ("rotateshoottype +"); 175 $::CONN->user_send ("rotateshoottype +");
175 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 176 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
176 $::CONN->user_send ("rotateshoottype -"); 177 $::CONN->user_send ("rotateshoottype -");
177 } elsif ($uni == ord '"') { 178 } elsif ($uni == ord '"') {
195 } 196 }
196 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { 197 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
197 $::BIND_EDITOR->set_binding (undef, undef, [], 198 $::BIND_EDITOR->set_binding (undef, undef, [],
198 sub { 199 sub {
199 my ($mod, $sym, $cmds) = @_; 200 my ($mod, $sym, $cmds) = @_;
200 $::CFG->{bindings}->{$mod}->{$sym} = $cmds; 201 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
201 }); 202 });
202 $::BIND_EDITOR->start; 203 $::BIND_EDITOR->start;
203 $::BIND_EDITOR->show; 204 $::BIND_EDITOR->show;
204 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { 205 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
205 $::BIND_EDITOR->stop; 206 $::BIND_EDITOR->stop;
206 $::BIND_EDITOR->ask_for_bind_and_commit; 207 $::BIND_EDITOR->ask_for_bind_and_commit;
207 $::BIND_EDITOR->hide; 208 $::BIND_EDITOR->hide;
208 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { 209 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
209 $::CONN->user_send ($_) for @$bind_cmd; 210 $::CONN->user_send ($_) for @$bind_cmd;
210 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 211 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
211 $self->{completer}->key_down ($ev); 212 $self->{completer}->invoke_key_down ($ev);
212 $self->{completer}->show; 213 $self->{completer}->show;
213 } else { 214 } else {
214 return 0; 215 return 0;
215 } 216 }
216 217
217 1 218 1
218} 219}
219 220
220sub key_up { 221sub invoke_key_up {
221 my ($self, $ev) = @_; 222 my ($self, $ev) = @_;
222 223
223 my $res = 0; 224 my $res = 0;
224 my $mod = $ev->{mod}; 225 my $mod = $ev->{mod};
225 my $sym = $ev->{sym}; 226 my $sym = $ev->{sym};
380 381
381sub size_request { 382sub size_request {
382 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 383 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
383} 384}
384 385
385sub size_allocate { 386sub invoke_size_allocate {
386 my ($self, $w, $h) = @_; 387 my ($self, $w, $h) = @_;
387 388
388 $self->SUPER::size_allocate ($w, $h);
389 $self->update; 389 $self->update;
390
391 1
390} 392}
391 393
392sub update { 394sub update {
393 my ($self) = @_; 395 my ($self) = @_;
394 396
479 ]; 481 ];
480 482
481 $self->{entry} = new CFClient::UI::Entry 483 $self->{entry} = new CFClient::UI::Entry
482 on_changed => sub { 484 on_changed => sub {
483 $self->update_labels; 485 $self->update_labels;
486 0
484 }, 487 },
485 on_button_down => sub { 488 on_button_down => sub {
486 my ($entry, $ev, $x, $y) = @_; 489 my ($entry, $ev, $x, $y) = @_;
487 490
488 if ($ev->{button} == 3) { 491 if ($ev->{button} == 3) {
489 (new CFClient::UI::Menu 492 (new CFClient::UI::Menu
490 items => [ 493 items => [
494 ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key"
491 ["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 }) }]
492 ], 496 ],
493 )->popup ($ev); 497 )->popup ($ev);
494 return 1; 498 return 1;
495 } 499 }
496 0 500 0
503 if ($ev->{sym} == 13) { 507 if ($ev->{sym} == 13) {
504 if (exists $self->{select}) { 508 if (exists $self->{select}) {
505 $self->{last_command} = $self->{select}; 509 $self->{last_command} = $self->{select};
506 $::CONN->user_send ($self->{select}); 510 $::CONN->user_send ($self->{select});
507 511
508 unshift @{$self->{history}}, $self->{select}; 512 unshift @{$self->{history}}, $self->{entry}->get_text;
509 $self->{hist_ptr} = 0; 513 $self->{hist_ptr} = 0;
510 514
511 $self->hide; 515 $self->hide;
512 } 516 }
513 } elsif ($ev->{sym} == 27) { 517 } elsif ($ev->{sym} == 27) {
514 $self->{hist_ptr} = 0; 518 $self->{hist_ptr} = 0;
515 $self->hide; 519 $self->hide;
516 return;
517 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 520 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
518 if ($self->{hist_ptr} > 1) { 521 if ($self->{hist_ptr} > 1) {
519 $self->{hist_ptr}--; 522 $self->{hist_ptr}--;
520 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 523 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
521 } elsif ($self->{hist_ptr} > 0) { 524 } elsif ($self->{hist_ptr} > 0) {
561 564
562 $self->{entry}->set_text ($prefix); 565 $self->{entry}->set_text ($prefix);
563 $self->show; 566 $self->show;
564} 567}
565 568
566sub size_allocate { 569sub invoke_size_allocate {
567 my ($self, $w, $h) = @_; 570 my ($self, $w, $h) = @_;
568 571
569 $self->SUPER::size_allocate ($w, $h);
570 $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)
571} 575}
572 576
573sub show { 577sub show {
574 my ($self) = @_; 578 my ($self) = @_;
575 579
576 $self->SUPER::show; 580 $self->SUPER::show;
577 $self->{entry}->focus_in; 581 $self->{entry}->grab_focus;
578} 582}
579 583
580sub hide { 584sub hide {
581 my ($self) = @_; 585 my ($self) = @_;
582 586
583 $self->SUPER::hide; 587 $self->SUPER::hide;
584 $self->{entry}->set_text (""); 588 $self->{entry}->set_text ("");
585} 589}
586 590
587sub key_down { 591sub invoke_key_down {
588 my ($self, $ev) = @_; 592 my ($self, $ev) = @_;
589 593
590 $self->{entry}->key_down ($ev) 594 $self->{entry}->emit (key_down => $ev)
591} 595}
592 596
593sub update_labels { 597sub update_labels {
594 my ($self) = @_; 598 my ($self) = @_;
595 599
682 $label->set_text (""); 686 $label->set_text ("");
683 $label->set_tooltip (""); 687 $label->set_tooltip ("");
684 } 688 }
685 689
686 $self->update; 690 $self->update;
687 ###
688} 691}
689 692
690sub _draw { 693sub _draw {
691 my ($self) = @_; 694 my ($self) = @_;
692 695

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines