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.68 by elmex, Sun Jun 25 13:42:45 2006 UTC vs.
Revision 1.82 by root, Fri Sep 29 00:56:06 2006 UTC

1package CFClient::MapWidget; 1package CFPlus::MapWidget;
2 2
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 CFPlus;
8use CFClient::OpenGL; 9use CFPlus::OpenGL;
10use CFPlus::UI;
9 11
10our @ISA = CFClient::UI::Base::; 12our @ISA = CFPlus::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 CFPlus::Texture CFPlus::find_rcfile "magicmap.png",
14 mipmap => 1, wrap => 0, internalformat => GL_ALPHA; 16 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
15 17
16sub new { 18sub new {
17 my $class = shift; 19 my $class = shift;
18 20
28 ], 30 ],
29 31
30 @_ 32 @_
31 ); 33 );
32 34
33 $self->{completer} = new CFClient::MapWidget::Command:: 35 $self->{completer} = new CFPlus::MapWidget::Command::
34 command => $self->{command}, 36 command => $self->{command},
35 can_focus => 1, 37 tooltip => "#completer_help",
36 tooltip => "<b>The Command Completer</b>\n\n"
37 . "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 . "followed by a space, and press return. "
40 . "Typing the initial letters of words (or just any letters) displays guesses "
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"
43 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining key bindings.",
44 ; 38 ;
45 39
46 $self 40 $self
47} 41}
48 42
60 54
61sub clr_commands { 55sub clr_commands {
62 my ($self) = @_; 56 my ($self) = @_;
63 57
64 %{$self->{completer}{command}} = (); 58 %{$self->{completer}{command}} = ();
59
60 $self->{completer}->hide
61 if $self->{completer};
65} 62}
66 63
67sub invoke_button_down { 64sub invoke_button_down {
68 my ($self, $ev, $x, $y) = @_; 65 my ($self, $ev, $x, $y) = @_;
69 66
70 return unless $::CONN;
71
72 $self->grab_focus;
73
74 if ($ev->{button} == 1) { 67 if ($ev->{button} == 1) {
68 $self->grab_focus;
69 return unless $::CONN;
70
75 my $x = 1 + CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 71 my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
76 my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 72 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
77 73
78 $x -= int 0.5 * $self->{sw}; 74 $x -= int 0.5 * $self->{sw};
79 $y -= int 0.5 * $self->{sh}; 75 $y -= int 0.5 * $self->{sh};
80 76
81 $::CONN->lookat ($x, $y) 77 $::CONN->lookat ($x, $y)
82 if $::CONN; 78 if $::CONN;
83 79
84 } elsif ($ev->{button} == 2) { 80 } elsif ($ev->{button} == 2) {
81 $self->grab_focus;
82 return unless $::CONN;
83
85 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 84 my ($ox, $oy) = ($ev->{x}, $ev->{y});
86 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 85 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
87 86
88 $self->{motion} = sub { 87 $self->{motion} = sub {
89 my ($ev, $x, $y) = @_; 88 my ($ev, $x, $y) = @_;
93 $::CFG->{map_shift_x} = $bw + $x - $ox; 92 $::CFG->{map_shift_x} = $bw + $x - $ox;
94 $::CFG->{map_shift_y} = $bh + $y - $oy; 93 $::CFG->{map_shift_y} = $bh + $y - $oy;
95 94
96 $self->update; 95 $self->update;
97 }; 96 };
97 } elsif ($ev->{button} == 3) {
98 (new CFPlus::UI::Menu
99 items => [
100 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
101 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
102 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
103 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
104 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
105 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }],
106 ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }],
107 [
108 $::PICKUP_ENABLE->{state}
109 ? "Disable automatic pickup"
110 : "Enable automatic pickup",
111 sub { $::PICKUP_ENABLE->toggle }
112 ],
113 ["Quit",
114 sub {
115 if ($::CONN) {
116 &::open_quit_dialog;
117 } else {
118 exit;
119 }
120 }
121 ],
122 ],
123 )->popup ($ev);
98 } 124 }
99 125
100 1 126 1
101} 127}
102 128
120 1 146 1
121} 147}
122 148
123sub size_request { 149sub size_request {
124 ( 150 (
125 32 * CFClient::ceil $::WIDTH / 32, 151 32 * CFPlus::ceil $::WIDTH / 32,
126 32 * CFClient::ceil $::HEIGHT / 32, 152 32 * CFPlus::ceil $::HEIGHT / 32,
127 ) 153 )
128} 154}
129 155
130sub update { 156sub update {
131 my ($self) = @_; 157 my ($self) = @_;
133 $self->{need_update} = 1; 159 $self->{need_update} = 1;
134 $self->SUPER::update; 160 $self->SUPER::update;
135} 161}
136 162
137my %DIR = ( 163my %DIR = (
138 CFClient::SDLK_KP8, [1, "north"], 164 CFPlus::SDLK_KP8, [1, "north"],
139 CFClient::SDLK_KP9, [2, "northeast"], 165 CFPlus::SDLK_KP9, [2, "northeast"],
140 CFClient::SDLK_KP6, [3, "east"], 166 CFPlus::SDLK_KP6, [3, "east"],
141 CFClient::SDLK_KP3, [4, "southeast"], 167 CFPlus::SDLK_KP3, [4, "southeast"],
142 CFClient::SDLK_KP2, [5, "south"], 168 CFPlus::SDLK_KP2, [5, "south"],
143 CFClient::SDLK_KP1, [6, "southwest"], 169 CFPlus::SDLK_KP1, [6, "southwest"],
144 CFClient::SDLK_KP4, [7, "west"], 170 CFPlus::SDLK_KP4, [7, "west"],
145 CFClient::SDLK_KP7, [8, "northwest"], 171 CFPlus::SDLK_KP7, [8, "northwest"],
146 172
147 CFClient::SDLK_UP, [1, "north"], 173 CFPlus::SDLK_UP, [1, "north"],
148 CFClient::SDLK_RIGHT, [3, "east"], 174 CFPlus::SDLK_RIGHT, [3, "east"],
149 CFClient::SDLK_DOWN, [5, "south"], 175 CFPlus::SDLK_DOWN, [5, "south"],
150 CFClient::SDLK_LEFT, [7, "west"], 176 CFPlus::SDLK_LEFT, [7, "west"],
151); 177);
152 178
153sub invoke_key_down { 179sub invoke_key_down {
154 my ($self, $ev) = @_; 180 my ($self, $ev) = @_;
155
156 return 0 unless $::CONN;
157 181
158 my $mod = $ev->{mod}; 182 my $mod = $ev->{mod};
159 my $sym = $ev->{sym}; 183 my $sym = $ev->{sym};
160 my $uni = $ev->{unicode}; 184 my $uni = $ev->{unicode};
161 185
162 if ($sym == CFClient::SDLK_KP5) { 186 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
187
188 if ($uni == ord "\t") {
189 $::PL_WINDOW->toggle_visibility;
190 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
191 $::HELP_WINDOW->toggle_visibility;
192 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
193 ::toggle_player_page ($::STATS_PAGE);
194 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
195 ::toggle_player_page ($::SKILL_PAGE);
196 } elsif ($sym == CFPlus::SDLK_F4 && !$mod) {
197 ::toggle_player_page ($::SPELL_PAGE);
198 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
199 ::toggle_player_page ($::INVENTORY_PAGE);
200 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
201 $::SETUP_DIALOG->toggle_visibility;
202 } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) {
203 $::BIND_EDITOR->set_binding (undef, undef, [],
204 sub {
205 my ($mod, $sym, $cmds) = @_;
206 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
207 });
208 $::BIND_EDITOR->start;
209 $::BIND_EDITOR->show;
210#TODO: elmex, what was this supposed to do? it currently crashes the client.
211# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
212# $::BIND_EDITOR->stop;
213# $::BIND_EDITOR->ask_for_bind_and_commit;
214# $::BIND_EDITOR->hide;
215 } elsif (!$::CONN) {
216 return 0; # bindings further down need a valid connection
217
218 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
163 $::CONN->user_send ("stay fire"); 219 $::CONN->user_send ("stay fire");
164 } elsif ($uni == ord ",") { 220 } elsif ($uni == ord ",") {
165 $::CONN->user_send ("take"); 221 $::CONN->user_send ("take");
166 } elsif ($uni == ord " ") { 222 } elsif ($uni == ord " ") {
167 $::CONN->user_send ("apply"); 223 $::CONN->user_send ("apply");
224 } elsif ($uni == 13) {
225 $::CONN->user_send ("examine");
168 } elsif ($uni == ord ".") { 226 } elsif ($uni == ord ".") {
169 $::CONN->user_send ($self->{completer}{last_command}) 227 $::CONN->user_send ($self->{completer}{last_command})
170 if exists $self->{completer}{last_command}; 228 if exists $self->{completer}{last_command};
171 } elsif ($uni == ord "\t") { 229 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
172 $::INV_WINDOW->toggle_visibility; 230 $::CONN->user_send ($_) for @$bind_cmd;
173 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 231 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
174 $::CONN->user_send ("rotateshoottype +"); 232 $::CONN->user_send ("rotateshoottype +");
175 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 233 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
176 $::CONN->user_send ("rotateshoottype -"); 234 $::CONN->user_send ("rotateshoottype -");
177 } elsif ($uni == ord '"') { 235 } elsif ($uni == ord '"') {
178 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 236 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
179 $self->{completer}->show; 237 $self->{completer}->show;
180 } elsif ($uni == ord "'") { 238 } elsif ($uni == ord "'") {
181 $self->{completer}->set_prefix (""); 239 $self->{completer}->set_prefix ("");
182 $self->{completer}->show; 240 $self->{completer}->show;
183 } elsif (exists $DIR{$sym}) { 241 } elsif (exists $DIR{$sym}) {
184 if ($mod & CFClient::KMOD_SHIFT) { 242 if ($mod & CFPlus::KMOD_SHIFT) {
185 $self->{shft}++; 243 $self->{shft}++;
186 if ($DIR{$sym}[0] != $self->{fire_dir}) { 244 if ($DIR{$sym}[0] != $self->{fire_dir}) {
187 $::CONN->user_send ("fire $DIR{$sym}[0]"); 245 $::CONN->user_send ("fire $DIR{$sym}[0]");
188 } 246 }
189 $self->{fire_dir} = $DIR{$sym}[0]; 247 $self->{fire_dir} = $DIR{$sym}[0];
190 } elsif ($mod & CFClient::KMOD_CTRL) { 248 } elsif ($mod & CFPlus::KMOD_CTRL) {
191 $self->{ctrl}++; 249 $self->{ctrl}++;
192 $::CONN->user_send ("run $DIR{$sym}[0]"); 250 $::CONN->user_send ("run $DIR{$sym}[0]");
193 } else { 251 } else {
194 $::CONN->user_send ("$DIR{$sym}[1]"); 252 $::CONN->user_send ("$DIR{$sym}[1]");
195 } 253 }
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 $::BIND_EDITOR->cfg_bind ($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')) { 254 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
211 $self->{completer}->invoke_key_down ($ev); 255 $self->{completer}->inject_key_down ($ev);
212 $self->{completer}->show; 256 $self->{completer}->show;
213 } else { 257 } else {
214 return 0; 258 return 0;
215 } 259 }
216 260
223 my $res = 0; 267 my $res = 0;
224 my $mod = $ev->{mod}; 268 my $mod = $ev->{mod};
225 my $sym = $ev->{sym}; 269 my $sym = $ev->{sym};
226 270
227 if ($::CFG->{shift_fire_stop}) { 271 if ($::CFG->{shift_fire_stop}) {
228 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 272 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) {
229 $::CONN->user_send ("fire_stop"); 273 $::CONN->user_send ("fire_stop");
230 delete $self->{fire_dir}; 274 delete $self->{fire_dir};
231 $res = 1; 275 $res = 1;
232 } 276 }
233 } else { 277 } else {
234 if (exists $DIR{$sym} && delete $self->{shft}) { 278 if (exists $DIR{$sym} && delete $self->{shft}) {
235 $::CONN->user_send ("fire_stop"); 279 $::CONN->user_send ("fire_stop");
236 delete $self->{fire_dir}; 280 delete $self->{fire_dir};
237 $res = 1; 281 $res = 1;
238 } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? 282 } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
239 $::CONN->user_send ("fire_stop"); 283 $::CONN->user_send ("fire_stop");
240 delete $self->{fire_dir}; 284 delete $self->{fire_dir};
241 $res = 1; 285 $res = 1;
242 } 286 }
243 } 287 }
244 288
245 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 289 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) {
246 $::CONN->user_send ("run_stop"); 290 $::CONN->user_send ("run_stop");
247 $res = 1; 291 $res = 1;
248 } 292 }
249 293
250 $res 294 $res
264sub draw { 308sub draw {
265 my ($self) = @_; 309 my ($self) = @_;
266 310
267 return unless $::MAP; 311 return unless $::MAP;
268 312
269 my $focused = $CFClient::UI::FOCUS == $self 313 my $focused = $CFPlus::UI::FOCUS == $self
270 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 314 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
271 315
272 return 316 return
273 unless $focused || !$::FAST; 317 unless $focused || !$::FAST;
274 318
275 if (delete $self->{need_update}) { 319 if (delete $self->{need_update}) {
276 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 320 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
277 321
278 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize; 322 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
279 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 323 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
280 324
281 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 325 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
282 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 326 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
283 327
284 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize; 328 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
285 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize; 329 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
286 330
287 if ($::CFG->{fow_enable}) { 331 if ($::CFG->{fow_enable}) {
288 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 332 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
289 333
290 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 334 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
291 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 335 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
292 glConvolutionFilter2D ( 336 glConvolutionFilter2D (
293 GL_CONVOLUTION_2D, 337 GL_CONVOLUTION_2D,
294 GL_ALPHA, 338 GL_ALPHA,
295 3, 3, 339 3, 3,
297 (pack "f*", @{ $self->{smooth_matrix} }), 341 (pack "f*", @{ $self->{smooth_matrix} }),
298 ); 342 );
299 glEnable GL_CONVOLUTION_2D; 343 glEnable GL_CONVOLUTION_2D;
300 } 344 }
301 345
302 $self->{fow_texture} = new CFClient::Texture 346 $self->{fow_texture} = new CFPlus::Texture
303 w => $w, 347 w => $w,
304 h => $h, 348 h => $h,
305 data => $data, 349 data => $data,
306 internalformat => GL_ALPHA, 350 internalformat => GL_ALPHA,
307 format => GL_ALPHA; 351 format => GL_ALPHA;
369 glDeleteList $self->{list}; 413 glDeleteList $self->{list};
370 414
371 $self->SUPER::DESTROY; 415 $self->SUPER::DESTROY;
372} 416}
373 417
374package CFClient::MapWidget::MapMap; 418package CFPlus::MapWidget::MapMap;
375 419
376our @ISA = CFClient::UI::Base::; 420our @ISA = CFPlus::UI::Base::;
377 421
378use Time::HiRes qw(time); 422use Time::HiRes qw(time);
379use CFClient::OpenGL; 423use CFPlus::OpenGL;
380 424
381sub size_request { 425sub size_request {
382 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 426 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
383} 427}
384 428
420 464
421 if ($self->{texture_atime} < time) { 465 if ($self->{texture_atime} < time) {
422 $self->{texture_atime} = time + 1/3; 466 $self->{texture_atime} = time + 1/3;
423 467
424 $self->{texture} = 468 $self->{texture} =
425 new CFClient::Texture 469 new CFPlus::Texture
426 w => $w, 470 w => $w,
427 h => $h, 471 h => $h,
428 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 472 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
429 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; 473 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
430 } 474 }
431 475
432 $self->{texture}->draw_quad (0, 0); 476 $self->{texture}->draw_quad (0, 0);
433 477
434 glDisable GL_TEXTURE_2D; 478 glDisable GL_TEXTURE_2D;
449 glEnd; 493 glEnd;
450 494
451 glDisable GL_BLEND; 495 glDisable GL_BLEND;
452} 496}
453 497
454package CFClient::MapWidget::Command; 498package CFPlus::MapWidget::Command;
455 499
456use strict; 500use strict;
457 501
458use CFClient::OpenGL; 502use CFPlus::OpenGL;
459 503
460our @ISA = CFClient::UI::Frame::; 504our @ISA = CFPlus::UI::Frame::;
461 505
462sub new { 506sub new {
463 my $class = shift; 507 my $class = shift;
464 508
465 my $self = $class->SUPER::new ( 509 my $self = $class->SUPER::new (
466 bg => [0, 0, 0, 0.8], 510 bg => [0, 0, 0, 0.8],
467 @_, 511 @_,
468 ); 512 );
469 513
470 $self->add ($self->{vbox} = new CFClient::UI::VBox); 514 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
471 515
472 $self->{label} = [ 516 $self->{label} = [
473 map 517 map
474 CFClient::UI::Label->new ( 518 CFPlus::UI::Label->new (
475 can_hover => 1, 519 can_hover => 1,
476 can_events => 1, 520 can_events => 1,
477 tooltip_width => 0.33, 521 tooltip_width => 0.33,
478 fontsize => $_, 522 fontsize => $_,
479 ), (0.8) x 16 523 ), (0.8) x 16
480 ]; 524 ];
481 525
482 $self->{entry} = new CFClient::UI::Entry 526 $self->{entry} = new CFPlus::UI::Entry
483 on_changed => sub { 527 on_changed => sub {
484 $self->update_labels; 528 $self->update_labels;
485 0 529 0
486 }, 530 },
487 on_button_down => sub { 531 on_button_down => sub {
488 my ($entry, $ev, $x, $y) = @_; 532 my ($entry, $ev, $x, $y) = @_;
489 533
490 if ($ev->{button} == 3) { 534 if ($ev->{button} == 3) {
491 (new CFClient::UI::Menu 535 (new CFPlus::UI::Menu
492 items => [ 536 items => [
537 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key"
493 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] 538 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
494 ], 539 ],
495 )->popup ($ev); 540 )->popup ($ev);
496 return 1; 541 return 1;
497 } 542 }
498 0 543 0
513 $self->hide; 558 $self->hide;
514 } 559 }
515 } elsif ($ev->{sym} == 27) { 560 } elsif ($ev->{sym} == 27) {
516 $self->{hist_ptr} = 0; 561 $self->{hist_ptr} = 0;
517 $self->hide; 562 $self->hide;
518 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 563 } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) {
519 if ($self->{hist_ptr} > 1) { 564 if ($self->{hist_ptr} > 1) {
520 $self->{hist_ptr}--; 565 $self->{hist_ptr}--;
521 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 566 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
522 } elsif ($self->{hist_ptr} > 0) { 567 } elsif ($self->{hist_ptr} > 0) {
523 $self->{hist_ptr}--; 568 $self->{hist_ptr}--;
525 } else { 570 } else {
526 ++$self->{select_offset} 571 ++$self->{select_offset}
527 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 572 if $self->{select_offset} < $#{ $self->{last_match} || [] };
528 } 573 }
529 $self->update_labels; 574 $self->update_labels;
530 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 575 } elsif ($ev->{sym} == CFPlus::SDLK_UP) {
531 if ($self->{select_offset}) { 576 if ($self->{select_offset}) {
532 --$self->{select_offset} 577 --$self->{select_offset}
533 } else { 578 } else {
534 unless ($self->{hist_ptr}) { 579 unless ($self->{hist_ptr}) {
535 $self->{hist_saveback} = $self->{entry}->get_text; 580 $self->{hist_saveback} = $self->{entry}->get_text;
580} 625}
581 626
582sub hide { 627sub hide {
583 my ($self) = @_; 628 my ($self) = @_;
584 629
630 $self->{hist_ptr} = 0;
631
585 $self->SUPER::hide; 632 $self->SUPER::hide;
586 $self->{entry}->set_text (""); 633 $self->{entry}->set_text ("");
587} 634}
588 635
589sub invoke_key_down { 636sub inject_key_down {
590 my ($self, $ev) = @_; 637 my ($self, $ev) = @_;
591 638
639 $self->{entry}->grab_focus;
592 $self->{entry}->emit (key_down => $ev) 640 $self->{entry}->emit (key_down => $ev);
593} 641}
594 642
595sub update_labels { 643sub update_labels {
596 my ($self) = @_; 644 my ($self) = @_;
597 645
690 738
691sub _draw { 739sub _draw {
692 my ($self) = @_; 740 my ($self) = @_;
693 741
694 # hack 742 # hack
695 local $CFClient::UI::FOCUS = $self->{entry}; 743 local $CFPlus::UI::FOCUS = $self->{entry};
696 744
697 $self->SUPER::_draw; 745 $self->SUPER::_draw;
698} 746}
699 747
7001 7481

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines