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.39 by root, Sat May 27 19:49:07 2006 UTC vs.
Revision 1.50 by root, Sat Jun 3 23:47:47 2006 UTC

39 my ($self, $command, $tooltip, $widget, $cb) = @_; 39 my ($self, $command, $tooltip, $widget, $cb) = @_;
40 40
41 (my $data = $command) =~ s/\\//g; 41 (my $data = $command) =~ s/\\//g;
42 42
43 $tooltip =~ s/^\s+//; 43 $tooltip =~ s/^\s+//;
44
45 $tooltip = "<big>$data</big>\n\n$tooltip"; 44 $tooltip = "<big>$data</big>\n\n$tooltip";
46
47 $tooltip =~ s/\s+$//; 45 $tooltip =~ s/\s+$//;
48 46
49 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; 47 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
50} 48}
51 49
58sub button_down { 56sub button_down {
59 my ($self, $ev, $x, $y) = @_; 57 my ($self, $ev, $x, $y) = @_;
60 58
61 $self->focus_in; 59 $self->focus_in;
62 60
63 if ($ev->{button} == 2) { 61 if ($ev->{button} == 1) {
62 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
63 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
64
65 my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99;
66 my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99;
67
68 $::CONN->send (sprintf "lookat %d %d", $fx, $fy);
69
70 } elsif ($ev->{button} == 2) {
64 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 71 my ($ox, $oy) = ($ev->{x}, $ev->{y});
65 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 72 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
66 73
67 $self->{motion} = sub { 74 $self->{motion} = sub {
68 my ($ev, $x, $y) = @_; 75 my ($ev, $x, $y) = @_;
73 $::CFG->{map_shift_y} = $bh + $y - $oy; 80 $::CFG->{map_shift_y} = $bh + $y - $oy;
74 81
75 $self->update; 82 $self->update;
76 }; 83 };
77 } 84 }
85
86 1
78} 87}
79 88
80sub button_up { 89sub button_up {
81 my ($self, $ev, $x, $y) = @_; 90 my ($self, $ev, $x, $y) = @_;
82 91
83 delete $self->{motion}; 92 delete $self->{motion};
93
94 1
84} 95}
85 96
86sub mouse_motion { 97sub mouse_motion {
87 my ($self, $ev, $x, $y) = @_; 98 my ($self, $ev, $x, $y) = @_;
88 99
100 if ($self->{motion}) {
89 $self->{motion}->($ev, $x, $y) if $self->{motion}; 101 $self->{motion}->($ev, $x, $y);
102 } else {
103 return 0;
104 }
105
106 1
90} 107}
91 108
92sub size_request { 109sub size_request {
93 ( 110 (
94 1 + 32 * int $::WIDTH / 32, 111 1 + 32 * int $::WIDTH / 32,
120); 137);
121 138
122sub key_down { 139sub key_down {
123 my ($self, $ev) = @_; 140 my ($self, $ev) = @_;
124 141
125 return unless $::CONN; 142 return 0 unless $::CONN;
126 143
127 my $mod = $ev->{mod}; 144 my $mod = $ev->{mod};
128 my $sym = $ev->{sym}; 145 my $sym = $ev->{sym};
129 my $uni = $ev->{unicode}; 146 my $uni = $ev->{unicode};
130 147
136 $::CONN->user_send ("apply"); 153 $::CONN->user_send ("apply");
137 } elsif ($uni == ord ".") { 154 } elsif ($uni == ord ".") {
138 $::CONN->user_send ($self->{completer}{last_command}) 155 $::CONN->user_send ($self->{completer}{last_command})
139 if exists $self->{completer}{last_command}; 156 if exists $self->{completer}{last_command};
140 } elsif ($uni == ord "\t") { 157 } elsif ($uni == ord "\t") {
141 # TODO: toggle inventory 158 $::INV_WINDOW->toggle_visibility;
142 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 159 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") {
143 $::CONN->user_send ("rotateshoottype +"); 160 $::CONN->user_send ("rotateshoottype +");
144 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 161 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") {
145 $::CONN->user_send ("rotateshoottype -"); 162 $::CONN->user_send ("rotateshoottype -");
146 } elsif ($uni == ord '"') { 163 } elsif ($uni == ord '"') {
157 $self->{ctrl}++; 174 $self->{ctrl}++;
158 $::CONN->user_send ("run $DIR{$sym}[0]"); 175 $::CONN->user_send ("run $DIR{$sym}[0]");
159 } else { 176 } else {
160 $::CONN->user_send ("$DIR{$sym}[1]"); 177 $::CONN->user_send ("$DIR{$sym}[1]");
161 } 178 }
162 } elsif ($ev->{unicode}) { 179 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
180 $::BIND_EDITOR->set_binding (undef, undef, [],
181 sub {
182 my ($mod, $sym, $cmds) = @_;
183 $::CFG->{bindings}->{$mod}->{$sym} = $cmds;
184 });
185 $::BIND_EDITOR->start;
186 $::BIND_EDITOR->show;
187 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
188 $::BIND_EDITOR->stop;
189 $::BIND_EDITOR->ask_for_bind_and_commit;
190 $::BIND_EDITOR->hide;
191 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
192 $::CONN->user_send ($_) for @$bind_cmd;
193 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
163 $self->{completer}->key_down ($ev); 194 $self->{completer}->key_down ($ev);
164 $self->{completer}->show; 195 $self->{completer}->show;
196 } else {
197 return 0;
198 }
199
165 } 200 1
166} 201}
167 202
168sub key_up { 203sub key_up {
169 my ($self, $ev) = @_; 204 my ($self, $ev) = @_;
170 205
206 my $res = 0;
171 my $mod = $ev->{mod}; 207 my $mod = $ev->{mod};
172 my $sym = $ev->{sym}; 208 my $sym = $ev->{sym};
173 209
174 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 210 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
175 $::CONN->user_send ("fire_stop"); 211 $::CONN->user_send ("fire_stop");
212 $res = 1;
176 } 213 }
214
177 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 215 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
178 $::CONN->user_send ("run_stop"); 216 $::CONN->user_send ("run_stop");
217 $res = 1;
179 } 218 }
219
220 $res
180} 221}
181 222
182sub draw { 223sub draw {
183 my ($self) = @_; 224 my ($self) = @_;
184 225
279# 320#
280# $label->show; 321# $label->show;
281# $label->update; 322# $label->update;
282# 323#
283# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { 324# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
284# $label->move ( 325# $label->move_abs (
285# ($::WIDTH - $label->{w}) * 0.5, 326# ($::WIDTH - $label->{w}) * 0.5,
286# ($::HEIGHT - $label->{h}) * 0.5, 327# ($::HEIGHT - $label->{h}) * 0.5,
287# ); 328# );
288# }); 329# });
289# 330#
406 fontsize => $_, 447 fontsize => $_,
407 ), (0.8) x 16 448 ), (0.8) x 16
408 ]; 449 ];
409 450
410 $self->{entry} = new CFClient::UI::Entry 451 $self->{entry} = new CFClient::UI::Entry
411 connect_changed => sub { 452 on_changed => sub {
412 $self->update_labels; 453 $self->update_labels;
413 }, 454 },
414 connect_key_down => sub { 455 on_key_down => sub {
415 my ($entry, $ev) = @_; 456 my ($entry, $ev) = @_;
416 457
417 my $self = $entry->{parent}{parent}; 458 my $self = $entry->{parent}{parent};
418 459
419 if ($ev->{sym} == 13) { 460 if ($ev->{sym} == 13) {
458 499
459sub size_allocate { 500sub size_allocate {
460 my ($self, $w, $h) = @_; 501 my ($self, $w, $h) = @_;
461 502
462 $self->SUPER::size_allocate ($w, $h); 503 $self->SUPER::size_allocate ($w, $h);
463 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 504 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
464} 505}
465 506
466sub show { 507sub show {
467 my ($self) = @_; 508 my ($self) = @_;
468 509
478} 519}
479 520
480sub key_down { 521sub key_down {
481 my ($self, $ev) = @_; 522 my ($self, $ev) = @_;
482 523
483 $self->{entry}->key_down ($ev); 524 $self->{entry}->key_down ($ev)
484} 525}
485 526
486sub update_labels { 527sub update_labels {
487 my ($self) = @_; 528 my ($self) = @_;
488 529

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines