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.76 by elmex, Sat Jul 22 12:36:17 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines