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.70 by elmex, Sun Jul 2 19:32:55 2006 UTC vs.
Revision 1.78 by root, Sun Jul 23 16:11:12 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines