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.81 by root, Sun Aug 13 15:14:17 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 } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
211 $::BIND_EDITOR->stop;
212 $::BIND_EDITOR->ask_for_bind_and_commit;
213 $::BIND_EDITOR->hide;
214 } elsif (!$::CONN) {
215 return 0; # bindings further down need a valid connection
216
217 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
163 $::CONN->user_send ("stay fire"); 218 $::CONN->user_send ("stay fire");
164 } elsif ($uni == ord ",") { 219 } elsif ($uni == ord ",") {
165 $::CONN->user_send ("take"); 220 $::CONN->user_send ("take");
166 } elsif ($uni == ord " ") { 221 } elsif ($uni == ord " ") {
167 $::CONN->user_send ("apply"); 222 $::CONN->user_send ("apply");
168 } elsif ($uni == ord ".") { 223 } elsif ($uni == ord ".") {
169 $::CONN->user_send ($self->{completer}{last_command}) 224 $::CONN->user_send ($self->{completer}{last_command})
170 if exists $self->{completer}{last_command}; 225 if exists $self->{completer}{last_command};
171 } elsif ($uni == ord "\t") { 226 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
172 $::PL_WINDOW->toggle_visibility; 227 $::CONN->user_send ($_) for @$bind_cmd;
173 $::PL_NOTEBOOK->set_current_page ("Inventory");
174 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 228 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
175 $::CONN->user_send ("rotateshoottype +"); 229 $::CONN->user_send ("rotateshoottype +");
176 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 230 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
177 $::CONN->user_send ("rotateshoottype -"); 231 $::CONN->user_send ("rotateshoottype -");
178 } elsif ($uni == ord '"') { 232 } elsif ($uni == ord '"') {
179 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 233 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
180 $self->{completer}->show; 234 $self->{completer}->show;
181 } elsif ($uni == ord "'") { 235 } elsif ($uni == ord "'") {
182 $self->{completer}->set_prefix (""); 236 $self->{completer}->set_prefix ("");
183 $self->{completer}->show; 237 $self->{completer}->show;
184 } elsif (exists $DIR{$sym}) { 238 } elsif (exists $DIR{$sym}) {
185 if ($mod & CFClient::KMOD_SHIFT) { 239 if ($mod & CFPlus::KMOD_SHIFT) {
186 $self->{shft}++; 240 $self->{shft}++;
187 if ($DIR{$sym}[0] != $self->{fire_dir}) { 241 if ($DIR{$sym}[0] != $self->{fire_dir}) {
188 $::CONN->user_send ("fire $DIR{$sym}[0]"); 242 $::CONN->user_send ("fire $DIR{$sym}[0]");
189 } 243 }
190 $self->{fire_dir} = $DIR{$sym}[0]; 244 $self->{fire_dir} = $DIR{$sym}[0];
191 } elsif ($mod & CFClient::KMOD_CTRL) { 245 } elsif ($mod & CFPlus::KMOD_CTRL) {
192 $self->{ctrl}++; 246 $self->{ctrl}++;
193 $::CONN->user_send ("run $DIR{$sym}[0]"); 247 $::CONN->user_send ("run $DIR{$sym}[0]");
194 } else { 248 } else {
195 $::CONN->user_send ("$DIR{$sym}[1]"); 249 $::CONN->user_send ("$DIR{$sym}[1]");
196 } 250 }
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')) { 251 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
212 $self->{completer}->invoke_key_down ($ev); 252 $self->{completer}->inject_key_down ($ev);
213 $self->{completer}->show; 253 $self->{completer}->show;
214 } else { 254 } else {
215 return 0; 255 return 0;
216 } 256 }
217 257
224 my $res = 0; 264 my $res = 0;
225 my $mod = $ev->{mod}; 265 my $mod = $ev->{mod};
226 my $sym = $ev->{sym}; 266 my $sym = $ev->{sym};
227 267
228 if ($::CFG->{shift_fire_stop}) { 268 if ($::CFG->{shift_fire_stop}) {
229 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 269 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) {
230 $::CONN->user_send ("fire_stop"); 270 $::CONN->user_send ("fire_stop");
231 delete $self->{fire_dir}; 271 delete $self->{fire_dir};
232 $res = 1; 272 $res = 1;
233 } 273 }
234 } else { 274 } else {
235 if (exists $DIR{$sym} && delete $self->{shft}) { 275 if (exists $DIR{$sym} && delete $self->{shft}) {
236 $::CONN->user_send ("fire_stop"); 276 $::CONN->user_send ("fire_stop");
237 delete $self->{fire_dir}; 277 delete $self->{fire_dir};
238 $res = 1; 278 $res = 1;
239 } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? 279 } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
240 $::CONN->user_send ("fire_stop"); 280 $::CONN->user_send ("fire_stop");
241 delete $self->{fire_dir}; 281 delete $self->{fire_dir};
242 $res = 1; 282 $res = 1;
243 } 283 }
244 } 284 }
245 285
246 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 286 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) {
247 $::CONN->user_send ("run_stop"); 287 $::CONN->user_send ("run_stop");
248 $res = 1; 288 $res = 1;
249 } 289 }
250 290
251 $res 291 $res
265sub draw { 305sub draw {
266 my ($self) = @_; 306 my ($self) = @_;
267 307
268 return unless $::MAP; 308 return unless $::MAP;
269 309
270 my $focused = $CFClient::UI::FOCUS == $self 310 my $focused = $CFPlus::UI::FOCUS == $self
271 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 311 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
272 312
273 return 313 return
274 unless $focused || !$::FAST; 314 unless $focused || !$::FAST;
275 315
276 if (delete $self->{need_update}) { 316 if (delete $self->{need_update}) {
277 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 317 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
278 318
279 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize; 319 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
280 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 320 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
281 321
282 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 322 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
283 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 323 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
284 324
285 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize; 325 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
286 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize; 326 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
287 327
288 if ($::CFG->{fow_enable}) { 328 if ($::CFG->{fow_enable}) {
289 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 329 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
290 330
291 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 331 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
292 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 332 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
293 glConvolutionFilter2D ( 333 glConvolutionFilter2D (
294 GL_CONVOLUTION_2D, 334 GL_CONVOLUTION_2D,
295 GL_ALPHA, 335 GL_ALPHA,
296 3, 3, 336 3, 3,
298 (pack "f*", @{ $self->{smooth_matrix} }), 338 (pack "f*", @{ $self->{smooth_matrix} }),
299 ); 339 );
300 glEnable GL_CONVOLUTION_2D; 340 glEnable GL_CONVOLUTION_2D;
301 } 341 }
302 342
303 $self->{fow_texture} = new CFClient::Texture 343 $self->{fow_texture} = new CFPlus::Texture
304 w => $w, 344 w => $w,
305 h => $h, 345 h => $h,
306 data => $data, 346 data => $data,
307 internalformat => GL_ALPHA, 347 internalformat => GL_ALPHA,
308 format => GL_ALPHA; 348 format => GL_ALPHA;
370 glDeleteList $self->{list}; 410 glDeleteList $self->{list};
371 411
372 $self->SUPER::DESTROY; 412 $self->SUPER::DESTROY;
373} 413}
374 414
375package CFClient::MapWidget::MapMap; 415package CFPlus::MapWidget::MapMap;
376 416
377our @ISA = CFClient::UI::Base::; 417our @ISA = CFPlus::UI::Base::;
378 418
379use Time::HiRes qw(time); 419use Time::HiRes qw(time);
380use CFClient::OpenGL; 420use CFPlus::OpenGL;
381 421
382sub size_request { 422sub size_request {
383 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 423 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
384} 424}
385 425
421 461
422 if ($self->{texture_atime} < time) { 462 if ($self->{texture_atime} < time) {
423 $self->{texture_atime} = time + 1/3; 463 $self->{texture_atime} = time + 1/3;
424 464
425 $self->{texture} = 465 $self->{texture} =
426 new CFClient::Texture 466 new CFPlus::Texture
427 w => $w, 467 w => $w,
428 h => $h, 468 h => $h,
429 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 469 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
430 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; 470 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
431 } 471 }
432 472
433 $self->{texture}->draw_quad (0, 0); 473 $self->{texture}->draw_quad (0, 0);
434 474
435 glDisable GL_TEXTURE_2D; 475 glDisable GL_TEXTURE_2D;
450 glEnd; 490 glEnd;
451 491
452 glDisable GL_BLEND; 492 glDisable GL_BLEND;
453} 493}
454 494
455package CFClient::MapWidget::Command; 495package CFPlus::MapWidget::Command;
456 496
457use strict; 497use strict;
458 498
459use CFClient::OpenGL; 499use CFPlus::OpenGL;
460 500
461our @ISA = CFClient::UI::Frame::; 501our @ISA = CFPlus::UI::Frame::;
462 502
463sub new { 503sub new {
464 my $class = shift; 504 my $class = shift;
465 505
466 my $self = $class->SUPER::new ( 506 my $self = $class->SUPER::new (
467 bg => [0, 0, 0, 0.8], 507 bg => [0, 0, 0, 0.8],
468 @_, 508 @_,
469 ); 509 );
470 510
471 $self->add ($self->{vbox} = new CFClient::UI::VBox); 511 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
472 512
473 $self->{label} = [ 513 $self->{label} = [
474 map 514 map
475 CFClient::UI::Label->new ( 515 CFPlus::UI::Label->new (
476 can_hover => 1, 516 can_hover => 1,
477 can_events => 1, 517 can_events => 1,
478 tooltip_width => 0.33, 518 tooltip_width => 0.33,
479 fontsize => $_, 519 fontsize => $_,
480 ), (0.8) x 16 520 ), (0.8) x 16
481 ]; 521 ];
482 522
483 $self->{entry} = new CFClient::UI::Entry 523 $self->{entry} = new CFPlus::UI::Entry
484 on_changed => sub { 524 on_changed => sub {
485 $self->update_labels; 525 $self->update_labels;
486 0 526 0
487 }, 527 },
488 on_button_down => sub { 528 on_button_down => sub {
489 my ($entry, $ev, $x, $y) = @_; 529 my ($entry, $ev, $x, $y) = @_;
490 530
491 if ($ev->{button} == 3) { 531 if ($ev->{button} == 3) {
492 (new CFClient::UI::Menu 532 (new CFPlus::UI::Menu
493 items => [ 533 items => [
494 ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key" 534 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key"
495 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] 535 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
496 ], 536 ],
497 )->popup ($ev); 537 )->popup ($ev);
498 return 1; 538 return 1;
499 } 539 }
515 $self->hide; 555 $self->hide;
516 } 556 }
517 } elsif ($ev->{sym} == 27) { 557 } elsif ($ev->{sym} == 27) {
518 $self->{hist_ptr} = 0; 558 $self->{hist_ptr} = 0;
519 $self->hide; 559 $self->hide;
520 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 560 } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) {
521 if ($self->{hist_ptr} > 1) { 561 if ($self->{hist_ptr} > 1) {
522 $self->{hist_ptr}--; 562 $self->{hist_ptr}--;
523 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 563 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
524 } elsif ($self->{hist_ptr} > 0) { 564 } elsif ($self->{hist_ptr} > 0) {
525 $self->{hist_ptr}--; 565 $self->{hist_ptr}--;
527 } else { 567 } else {
528 ++$self->{select_offset} 568 ++$self->{select_offset}
529 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 569 if $self->{select_offset} < $#{ $self->{last_match} || [] };
530 } 570 }
531 $self->update_labels; 571 $self->update_labels;
532 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 572 } elsif ($ev->{sym} == CFPlus::SDLK_UP) {
533 if ($self->{select_offset}) { 573 if ($self->{select_offset}) {
534 --$self->{select_offset} 574 --$self->{select_offset}
535 } else { 575 } else {
536 unless ($self->{hist_ptr}) { 576 unless ($self->{hist_ptr}) {
537 $self->{hist_saveback} = $self->{entry}->get_text; 577 $self->{hist_saveback} = $self->{entry}->get_text;
582} 622}
583 623
584sub hide { 624sub hide {
585 my ($self) = @_; 625 my ($self) = @_;
586 626
627 $self->{hist_ptr} = 0;
628
587 $self->SUPER::hide; 629 $self->SUPER::hide;
588 $self->{entry}->set_text (""); 630 $self->{entry}->set_text ("");
589} 631}
590 632
591sub invoke_key_down { 633sub inject_key_down {
592 my ($self, $ev) = @_; 634 my ($self, $ev) = @_;
593 635
636 $self->{entry}->grab_focus;
594 $self->{entry}->emit (key_down => $ev) 637 $self->{entry}->emit (key_down => $ev);
595} 638}
596 639
597sub update_labels { 640sub update_labels {
598 my ($self) = @_; 641 my ($self) = @_;
599 642
692 735
693sub _draw { 736sub _draw {
694 my ($self) = @_; 737 my ($self) = @_;
695 738
696 # hack 739 # hack
697 local $CFClient::UI::FOCUS = $self->{entry}; 740 local $CFPlus::UI::FOCUS = $self->{entry};
698 741
699 $self->SUPER::_draw; 742 $self->SUPER::_draw;
700} 743}
701 744
7021 7451

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines