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.66 by root, Sun Jun 18 19:13:20 2006 UTC vs.
Revision 1.77 by root, Sun Jul 23 02:44:05 2006 UTC

30 @_ 30 @_
31 ); 31 );
32 32
33 $self->{completer} = new CFClient::MapWidget::Command:: 33 $self->{completer} = new CFClient::MapWidget::Command::
34 command => $self->{command}, 34 command => $self->{command},
35 can_focus => 1,
36 tooltip => "<b>The Command Completer</b>\n\n" 35 tooltip => "<b>The Command Completer</b>\n\n"
37 . "This is your central interface to send text commands to the server. " 36 . "This is your central interface to send text commands to the server. "
38 . "To enter a verbatim command to send to the server, just type the command, " 37 . "To enter a verbatim command to send to the server, just type the command, "
39 . "followed by a space, and press return. " 38 . "followed by a space, and press return. "
40 . "Typing the initial letters of words (or just any letters) displays guesses " 39 . "Typing the initial letters of words (or just any letters) displays guesses "
60 59
61sub clr_commands { 60sub clr_commands {
62 my ($self) = @_; 61 my ($self) = @_;
63 62
64 %{$self->{completer}{command}} = (); 63 %{$self->{completer}{command}} = ();
64
65 $self->{completer}->hide
66 if $self->{completer};
65} 67}
66 68
67sub invoke_button_down { 69sub invoke_button_down {
68 my ($self, $ev, $x, $y) = @_; 70 my ($self, $ev, $x, $y) = @_;
69 71
70 return unless $::CONN;
71
72 $self->grab_focus;
73
74 if ($ev->{button} == 1) { 72 if ($ev->{button} == 1) {
73 $self->grab_focus;
74 return unless $::CONN;
75
75 my $x = 1 + CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 76 my $x = 1 + CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
76 my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 77 my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
77 78
78 $x -= int 0.5 * $self->{sw}; 79 $x -= int 0.5 * $self->{sw};
79 $y -= int 0.5 * $self->{sh}; 80 $y -= int 0.5 * $self->{sh};
80 81
81 $::CONN->lookat ($x, $y) 82 $::CONN->lookat ($x, $y)
82 if $::CONN; 83 if $::CONN;
83 84
84 } elsif ($ev->{button} == 2) { 85 } elsif ($ev->{button} == 2) {
86 $self->grab_focus;
87 return unless $::CONN;
88
85 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 89 my ($ox, $oy) = ($ev->{x}, $ev->{y});
86 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 90 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
87 91
88 $self->{motion} = sub { 92 $self->{motion} = sub {
89 my ($ev, $x, $y) = @_; 93 my ($ev, $x, $y) = @_;
93 $::CFG->{map_shift_x} = $bw + $x - $ox; 97 $::CFG->{map_shift_x} = $bw + $x - $ox;
94 $::CFG->{map_shift_y} = $bh + $y - $oy; 98 $::CFG->{map_shift_y} = $bh + $y - $oy;
95 99
96 $self->update; 100 $self->update;
97 }; 101 };
102 } elsif ($ev->{button} == 3) {
103 (new CFClient::UI::Menu
104 items => [
105 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
106 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
107 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
108 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
109 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
110 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }],
111 ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }],
112 [
113 $::PICKUP_ENABLE->{state}
114 ? "Disable automatic pickup"
115 : "Enable automatic pickup",
116 sub { $::PICKUP_ENABLE->toggle }
117 ],
118 ],
119 )->popup ($ev);
98 } 120 }
99 121
100 1 122 1
101} 123}
102 124
151); 173);
152 174
153sub invoke_key_down { 175sub invoke_key_down {
154 my ($self, $ev) = @_; 176 my ($self, $ev) = @_;
155 177
156 return 0 unless $::CONN;
157
158 my $mod = $ev->{mod}; 178 my $mod = $ev->{mod};
159 my $sym = $ev->{sym}; 179 my $sym = $ev->{sym};
160 my $uni = $ev->{unicode}; 180 my $uni = $ev->{unicode};
161 181
182 $mod &= CFClient::KMOD_CTRL | CFClient::KMOD_ALT | CFClient::KMOD_SHIFT;
183
184 if ($uni == ord "\t") {
185 $::PL_WINDOW->toggle_visibility;
186 } elsif ($sym == CFClient::SDLK_F1 && !$mod) {
187 $::HELP_WINDOW->toggle_visibility;
188 } elsif ($sym == CFClient::SDLK_F2 && !$mod) {
189 ::toggle_player_page ($::STATS_PAGE);
190 } elsif ($sym == CFClient::SDLK_F3 && !$mod) {
191 ::toggle_player_page ($::SKILL_PAGE);
192 } elsif ($sym == CFClient::SDLK_F4 && !$mod) {
193 ::toggle_player_page ($::SPELL_PAGE);
194 } elsif ($sym == CFClient::SDLK_F5 && !$mod) {
195 ::toggle_player_page ($::INVENTORY_PAGE);
196 } elsif ($sym == CFClient::SDLK_F9 && !$mod) {
197 $::SETUP_DIALOG->toggle_visibility;
198 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
199 $::BIND_EDITOR->set_binding (undef, undef, [],
200 sub {
201 my ($mod, $sym, $cmds) = @_;
202 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
203 });
204 $::BIND_EDITOR->start;
205 $::BIND_EDITOR->show;
206 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
207 $::BIND_EDITOR->stop;
208 $::BIND_EDITOR->ask_for_bind_and_commit;
209 $::BIND_EDITOR->hide;
210 } elsif (!$::CONN) {
211 return 0; # bindings further down need a valid connection
212
162 if ($sym == CFClient::SDLK_KP5) { 213 } elsif ($sym == CFClient::SDLK_KP5 && !$mod) {
163 $::CONN->user_send ("stay fire"); 214 $::CONN->user_send ("stay fire");
164 } elsif ($uni == ord ",") { 215 } elsif ($uni == ord ",") {
165 $::CONN->user_send ("take"); 216 $::CONN->user_send ("take");
166 } elsif ($uni == ord " ") { 217 } elsif ($uni == ord " ") {
167 $::CONN->user_send ("apply"); 218 $::CONN->user_send ("apply");
168 } elsif ($uni == ord ".") { 219 } elsif ($uni == ord ".") {
169 $::CONN->user_send ($self->{completer}{last_command}) 220 $::CONN->user_send ($self->{completer}{last_command})
170 if exists $self->{completer}{last_command}; 221 if exists $self->{completer}{last_command};
171 } elsif ($uni == ord "\t") { 222 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
172 $::INV_WINDOW->toggle_visibility; 223 $::CONN->user_send ($_) for @$bind_cmd;
173 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 224 } elsif (($sym == CFClient::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
174 $::CONN->user_send ("rotateshoottype +"); 225 $::CONN->user_send ("rotateshoottype +");
175 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 226 } elsif (($sym == CFClient::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
176 $::CONN->user_send ("rotateshoottype -"); 227 $::CONN->user_send ("rotateshoottype -");
177 } elsif ($uni == ord '"') { 228 } elsif ($uni == ord '"') {
178 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 229 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
179 $self->{completer}->show; 230 $self->{completer}->show;
180 } elsif ($uni == ord "'") { 231 } elsif ($uni == ord "'") {
191 $self->{ctrl}++; 242 $self->{ctrl}++;
192 $::CONN->user_send ("run $DIR{$sym}[0]"); 243 $::CONN->user_send ("run $DIR{$sym}[0]");
193 } else { 244 } else {
194 $::CONN->user_send ("$DIR{$sym}[1]"); 245 $::CONN->user_send ("$DIR{$sym}[1]");
195 } 246 }
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 $::CFG->{profile}{default}{bindings}{$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 (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
209 $::CONN->user_send ($_) for @$bind_cmd;
210 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 247 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
211 $self->{completer}->invoke_key_down ($ev); 248 $self->{completer}->inject_key_down ($ev);
212 $self->{completer}->show; 249 $self->{completer}->show;
213 } else { 250 } else {
214 return 0; 251 return 0;
215 } 252 }
216 253
488 my ($entry, $ev, $x, $y) = @_; 525 my ($entry, $ev, $x, $y) = @_;
489 526
490 if ($ev->{button} == 3) { 527 if ($ev->{button} == 3) {
491 (new CFClient::UI::Menu 528 (new CFClient::UI::Menu
492 items => [ 529 items => [
530 ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key"
493 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] 531 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
494 ], 532 ],
495 )->popup ($ev); 533 )->popup ($ev);
496 return 1; 534 return 1;
497 } 535 }
498 0 536 0
505 if ($ev->{sym} == 13) { 543 if ($ev->{sym} == 13) {
506 if (exists $self->{select}) { 544 if (exists $self->{select}) {
507 $self->{last_command} = $self->{select}; 545 $self->{last_command} = $self->{select};
508 $::CONN->user_send ($self->{select}); 546 $::CONN->user_send ($self->{select});
509 547
510 unshift @{$self->{history}}, $self->{select}; 548 unshift @{$self->{history}}, $self->{entry}->get_text;
511 $self->{hist_ptr} = 0; 549 $self->{hist_ptr} = 0;
512 550
513 $self->hide; 551 $self->hide;
514 } 552 }
515 } elsif ($ev->{sym} == 27) { 553 } elsif ($ev->{sym} == 27) {
580} 618}
581 619
582sub hide { 620sub hide {
583 my ($self) = @_; 621 my ($self) = @_;
584 622
623 $self->{hist_ptr} = 0;
624
585 $self->SUPER::hide; 625 $self->SUPER::hide;
586 $self->{entry}->set_text (""); 626 $self->{entry}->set_text ("");
587} 627}
588 628
589sub invoke_key_down { 629sub inject_key_down {
590 my ($self, $ev) = @_; 630 my ($self, $ev) = @_;
591 631
632 $self->{entry}->grab_focus;
592 $self->{entry}->emit (key_down => $ev) 633 $self->{entry}->emit (key_down => $ev);
593} 634}
594 635
595sub update_labels { 636sub update_labels {
596 my ($self) = @_; 637 my ($self) = @_;
597 638

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines