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.75 by root, Tue Jul 18 06:56:35 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 if ($ev->{button} == 1) { 67 if ($ev->{button} == 1) {
71 $self->grab_focus; 68 $self->grab_focus;
72 return unless $::CONN; 69 return unless $::CONN;
73 70
74 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};
75 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};
76 73
77 $x -= int 0.5 * $self->{sw}; 74 $x -= int 0.5 * $self->{sw};
78 $y -= int 0.5 * $self->{sh}; 75 $y -= int 0.5 * $self->{sh};
79 76
80 $::CONN->lookat ($x, $y) 77 $::CONN->lookat ($x, $y)
96 $::CFG->{map_shift_y} = $bh + $y - $oy; 93 $::CFG->{map_shift_y} = $bh + $y - $oy;
97 94
98 $self->update; 95 $self->update;
99 }; 96 };
100 } elsif ($ev->{button} == 3) { 97 } elsif ($ev->{button} == 3) {
101 (new CFClient::UI::Menu 98 (new CFPlus::UI::Menu
102 items => [ 99 items => [
103 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], 100 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
104 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], 101 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
105 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 102 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
106 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 103 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
111 $::PICKUP_ENABLE->{state} 108 $::PICKUP_ENABLE->{state}
112 ? "Disable automatic pickup" 109 ? "Disable automatic pickup"
113 : "Enable automatic pickup", 110 : "Enable automatic pickup",
114 sub { $::PICKUP_ENABLE->toggle } 111 sub { $::PICKUP_ENABLE->toggle }
115 ], 112 ],
113 ["Quit",
114 sub {
115 if ($::CONN) {
116 &::open_quit_dialog;
117 } else {
118 exit;
119 }
120 }
121 ],
116 ], 122 ],
117 )->popup ($ev); 123 )->popup ($ev);
118 } 124 }
119 125
120 1 126 1
140 1 146 1
141} 147}
142 148
143sub size_request { 149sub size_request {
144 ( 150 (
145 32 * CFClient::ceil $::WIDTH / 32, 151 32 * CFPlus::ceil $::WIDTH / 32,
146 32 * CFClient::ceil $::HEIGHT / 32, 152 32 * CFPlus::ceil $::HEIGHT / 32,
147 ) 153 )
148} 154}
149 155
150sub update { 156sub update {
151 my ($self) = @_; 157 my ($self) = @_;
153 $self->{need_update} = 1; 159 $self->{need_update} = 1;
154 $self->SUPER::update; 160 $self->SUPER::update;
155} 161}
156 162
157my %DIR = ( 163my %DIR = (
158 CFClient::SDLK_KP8, [1, "north"], 164 CFPlus::SDLK_KP8, [1, "north"],
159 CFClient::SDLK_KP9, [2, "northeast"], 165 CFPlus::SDLK_KP9, [2, "northeast"],
160 CFClient::SDLK_KP6, [3, "east"], 166 CFPlus::SDLK_KP6, [3, "east"],
161 CFClient::SDLK_KP3, [4, "southeast"], 167 CFPlus::SDLK_KP3, [4, "southeast"],
162 CFClient::SDLK_KP2, [5, "south"], 168 CFPlus::SDLK_KP2, [5, "south"],
163 CFClient::SDLK_KP1, [6, "southwest"], 169 CFPlus::SDLK_KP1, [6, "southwest"],
164 CFClient::SDLK_KP4, [7, "west"], 170 CFPlus::SDLK_KP4, [7, "west"],
165 CFClient::SDLK_KP7, [8, "northwest"], 171 CFPlus::SDLK_KP7, [8, "northwest"],
166 172
167 CFClient::SDLK_UP, [1, "north"], 173 CFPlus::SDLK_UP, [1, "north"],
168 CFClient::SDLK_RIGHT, [3, "east"], 174 CFPlus::SDLK_RIGHT, [3, "east"],
169 CFClient::SDLK_DOWN, [5, "south"], 175 CFPlus::SDLK_DOWN, [5, "south"],
170 CFClient::SDLK_LEFT, [7, "west"], 176 CFPlus::SDLK_LEFT, [7, "west"],
171); 177);
172 178
173sub invoke_key_down { 179sub invoke_key_down {
174 my ($self, $ev) = @_; 180 my ($self, $ev) = @_;
175 181
176 my $mod = $ev->{mod}; 182 my $mod = $ev->{mod};
177 my $sym = $ev->{sym}; 183 my $sym = $ev->{sym};
178 my $uni = $ev->{unicode}; 184 my $uni = $ev->{unicode};
179 185
180 $mod &= CFClient::KMOD_CTRL | CFClient::KMOD_ALT | CFClient::KMOD_SHIFT; 186 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
181 187
182 if ($uni == ord "\t") { 188 if ($uni == ord "\t") {
183 $::PL_WINDOW->toggle_visibility; 189 $::PL_WINDOW->toggle_visibility;
184 } elsif ($sym == CFClient::SDLK_F1 && !$mod) { 190 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
185 $::HELP_WINDOW->toggle_visibility; 191 $::HELP_WINDOW->toggle_visibility;
186 } elsif ($sym == CFClient::SDLK_F2 && !$mod) { 192 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
187 ::toggle_player_page ($::STATS_PAGE); 193 ::toggle_player_page ($::STATS_PAGE);
188 } elsif ($sym == CFClient::SDLK_F3 && !$mod) { 194 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
189 ::toggle_player_page ($::SKILL_PAGE); 195 ::toggle_player_page ($::SKILL_PAGE);
190 } elsif ($sym == CFClient::SDLK_F4 && !$mod) { 196 } elsif ($sym == CFPlus::SDLK_F4 && !$mod) {
191 ::toggle_player_page ($::SPELL_PAGE); 197 ::toggle_player_page ($::SPELL_PAGE);
192 } elsif ($sym == CFClient::SDLK_F5 && !$mod) { 198 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
193 ::toggle_player_page ($::INVENTORY_PAGE); 199 ::toggle_player_page ($::INVENTORY_PAGE);
194 } elsif ($sym == CFClient::SDLK_F9 && !$mod) { 200 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
195 $::SETUP_DIALOG->toggle_visibility; 201 $::SETUP_DIALOG->toggle_visibility;
196 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { 202 } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) {
197 $::BIND_EDITOR->set_binding (undef, undef, [], 203 $::BIND_EDITOR->set_binding (undef, undef, [],
198 sub { 204 sub {
199 my ($mod, $sym, $cmds) = @_; 205 my ($mod, $sym, $cmds) = @_;
200 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); 206 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
201 }); 207 });
202 $::BIND_EDITOR->start; 208 $::BIND_EDITOR->start;
203 $::BIND_EDITOR->show; 209 $::BIND_EDITOR->show;
210#TODO: elmex, what was this supposed to do? it currently crashes the client.
204 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { 211# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
205 $::BIND_EDITOR->stop; 212# $::BIND_EDITOR->stop;
206 $::BIND_EDITOR->ask_for_bind_and_commit; 213# $::BIND_EDITOR->ask_for_bind_and_commit;
207 $::BIND_EDITOR->hide; 214# $::BIND_EDITOR->hide;
208 } elsif (!$::CONN) { 215 } elsif (!$::CONN) {
209 return 0; # bindings further down need a valid connection 216 return 0; # bindings further down need a valid connection
210 217
211 } elsif ($sym == CFClient::SDLK_KP5 && !$mod) { 218 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
212 $::CONN->user_send ("stay fire"); 219 $::CONN->user_send ("stay fire");
213 } elsif ($uni == ord ",") { 220 } elsif ($uni == ord ",") {
214 $::CONN->user_send ("take"); 221 $::CONN->user_send ("take");
215 } elsif ($uni == ord " ") { 222 } elsif ($uni == ord " ") {
216 $::CONN->user_send ("apply"); 223 $::CONN->user_send ("apply");
224 } elsif ($uni == 13) {
225 $::CONN->user_send ("examine");
217 } elsif ($uni == ord ".") { 226 } elsif ($uni == ord ".") {
218 $::CONN->user_send ($self->{completer}{last_command}) 227 $::CONN->user_send ($self->{completer}{last_command})
219 if exists $self->{completer}{last_command}; 228 if exists $self->{completer}{last_command};
220 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { 229 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
221 $::CONN->user_send ($_) for @$bind_cmd; 230 $::CONN->user_send ($_) for @$bind_cmd;
222 } elsif (($sym == CFClient::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { 231 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
223 $::CONN->user_send ("rotateshoottype +"); 232 $::CONN->user_send ("rotateshoottype +");
224 } elsif (($sym == CFClient::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { 233 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
225 $::CONN->user_send ("rotateshoottype -"); 234 $::CONN->user_send ("rotateshoottype -");
226 } elsif ($uni == ord '"') { 235 } elsif ($uni == ord '"') {
227 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 236 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
228 $self->{completer}->show; 237 $self->{completer}->show;
229 } elsif ($uni == ord "'") { 238 } elsif ($uni == ord "'") {
230 $self->{completer}->set_prefix (""); 239 $self->{completer}->set_prefix ("");
231 $self->{completer}->show; 240 $self->{completer}->show;
232 } elsif (exists $DIR{$sym}) { 241 } elsif (exists $DIR{$sym}) {
233 if ($mod & CFClient::KMOD_SHIFT) { 242 if ($mod & CFPlus::KMOD_SHIFT) {
234 $self->{shft}++; 243 $self->{shft}++;
235 if ($DIR{$sym}[0] != $self->{fire_dir}) { 244 if ($DIR{$sym}[0] != $self->{fire_dir}) {
236 $::CONN->user_send ("fire $DIR{$sym}[0]"); 245 $::CONN->user_send ("fire $DIR{$sym}[0]");
237 } 246 }
238 $self->{fire_dir} = $DIR{$sym}[0]; 247 $self->{fire_dir} = $DIR{$sym}[0];
239 } elsif ($mod & CFClient::KMOD_CTRL) { 248 } elsif ($mod & CFPlus::KMOD_CTRL) {
240 $self->{ctrl}++; 249 $self->{ctrl}++;
241 $::CONN->user_send ("run $DIR{$sym}[0]"); 250 $::CONN->user_send ("run $DIR{$sym}[0]");
242 } else { 251 } else {
243 $::CONN->user_send ("$DIR{$sym}[1]"); 252 $::CONN->user_send ("$DIR{$sym}[1]");
244 } 253 }
245 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 254 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
246 $self->{completer}->invoke_key_down ($ev); 255 $self->{completer}->inject_key_down ($ev);
247 $self->{completer}->show; 256 $self->{completer}->show;
248 } else { 257 } else {
249 return 0; 258 return 0;
250 } 259 }
251 260
258 my $res = 0; 267 my $res = 0;
259 my $mod = $ev->{mod}; 268 my $mod = $ev->{mod};
260 my $sym = $ev->{sym}; 269 my $sym = $ev->{sym};
261 270
262 if ($::CFG->{shift_fire_stop}) { 271 if ($::CFG->{shift_fire_stop}) {
263 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 272 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) {
264 $::CONN->user_send ("fire_stop"); 273 $::CONN->user_send ("fire_stop");
265 delete $self->{fire_dir}; 274 delete $self->{fire_dir};
266 $res = 1; 275 $res = 1;
267 } 276 }
268 } else { 277 } else {
269 if (exists $DIR{$sym} && delete $self->{shft}) { 278 if (exists $DIR{$sym} && delete $self->{shft}) {
270 $::CONN->user_send ("fire_stop"); 279 $::CONN->user_send ("fire_stop");
271 delete $self->{fire_dir}; 280 delete $self->{fire_dir};
272 $res = 1; 281 $res = 1;
273 } 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?
274 $::CONN->user_send ("fire_stop"); 283 $::CONN->user_send ("fire_stop");
275 delete $self->{fire_dir}; 284 delete $self->{fire_dir};
276 $res = 1; 285 $res = 1;
277 } 286 }
278 } 287 }
279 288
280 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 289 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) {
281 $::CONN->user_send ("run_stop"); 290 $::CONN->user_send ("run_stop");
282 $res = 1; 291 $res = 1;
283 } 292 }
284 293
285 $res 294 $res
299sub draw { 308sub draw {
300 my ($self) = @_; 309 my ($self) = @_;
301 310
302 return unless $::MAP; 311 return unless $::MAP;
303 312
304 my $focused = $CFClient::UI::FOCUS == $self 313 my $focused = $CFPlus::UI::FOCUS == $self
305 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 314 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
306 315
307 return 316 return
308 unless $focused || !$::FAST; 317 unless $focused || !$::FAST;
309 318
310 if (delete $self->{need_update}) { 319 if (delete $self->{need_update}) {
311 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 320 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
312 321
313 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize; 322 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
314 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 323 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
315 324
316 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 325 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
317 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 326 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
318 327
319 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize; 328 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
320 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize; 329 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
321 330
322 if ($::CFG->{fow_enable}) { 331 if ($::CFG->{fow_enable}) {
323 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);
324 333
325 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
326 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 335 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
327 glConvolutionFilter2D ( 336 glConvolutionFilter2D (
328 GL_CONVOLUTION_2D, 337 GL_CONVOLUTION_2D,
329 GL_ALPHA, 338 GL_ALPHA,
330 3, 3, 339 3, 3,
332 (pack "f*", @{ $self->{smooth_matrix} }), 341 (pack "f*", @{ $self->{smooth_matrix} }),
333 ); 342 );
334 glEnable GL_CONVOLUTION_2D; 343 glEnable GL_CONVOLUTION_2D;
335 } 344 }
336 345
337 $self->{fow_texture} = new CFClient::Texture 346 $self->{fow_texture} = new CFPlus::Texture
338 w => $w, 347 w => $w,
339 h => $h, 348 h => $h,
340 data => $data, 349 data => $data,
341 internalformat => GL_ALPHA, 350 internalformat => GL_ALPHA,
342 format => GL_ALPHA; 351 format => GL_ALPHA;
404 glDeleteList $self->{list}; 413 glDeleteList $self->{list};
405 414
406 $self->SUPER::DESTROY; 415 $self->SUPER::DESTROY;
407} 416}
408 417
409package CFClient::MapWidget::MapMap; 418package CFPlus::MapWidget::MapMap;
410 419
411our @ISA = CFClient::UI::Base::; 420our @ISA = CFPlus::UI::Base::;
412 421
413use Time::HiRes qw(time); 422use Time::HiRes qw(time);
414use CFClient::OpenGL; 423use CFPlus::OpenGL;
415 424
416sub size_request { 425sub size_request {
417 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 426 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
418} 427}
419 428
455 464
456 if ($self->{texture_atime} < time) { 465 if ($self->{texture_atime} < time) {
457 $self->{texture_atime} = time + 1/3; 466 $self->{texture_atime} = time + 1/3;
458 467
459 $self->{texture} = 468 $self->{texture} =
460 new CFClient::Texture 469 new CFPlus::Texture
461 w => $w, 470 w => $w,
462 h => $h, 471 h => $h,
463 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 472 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
464 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;
465 } 474 }
466 475
467 $self->{texture}->draw_quad (0, 0); 476 $self->{texture}->draw_quad (0, 0);
468 477
469 glDisable GL_TEXTURE_2D; 478 glDisable GL_TEXTURE_2D;
484 glEnd; 493 glEnd;
485 494
486 glDisable GL_BLEND; 495 glDisable GL_BLEND;
487} 496}
488 497
489package CFClient::MapWidget::Command; 498package CFPlus::MapWidget::Command;
490 499
491use strict; 500use strict;
492 501
493use CFClient::OpenGL; 502use CFPlus::OpenGL;
494 503
495our @ISA = CFClient::UI::Frame::; 504our @ISA = CFPlus::UI::Frame::;
496 505
497sub new { 506sub new {
498 my $class = shift; 507 my $class = shift;
499 508
500 my $self = $class->SUPER::new ( 509 my $self = $class->SUPER::new (
501 bg => [0, 0, 0, 0.8], 510 bg => [0, 0, 0, 0.8],
502 @_, 511 @_,
503 ); 512 );
504 513
505 $self->add ($self->{vbox} = new CFClient::UI::VBox); 514 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
506 515
507 $self->{label} = [ 516 $self->{label} = [
508 map 517 map
509 CFClient::UI::Label->new ( 518 CFPlus::UI::Label->new (
510 can_hover => 1, 519 can_hover => 1,
511 can_events => 1, 520 can_events => 1,
512 tooltip_width => 0.33, 521 tooltip_width => 0.33,
513 fontsize => $_, 522 fontsize => $_,
514 ), (0.8) x 16 523 ), (0.8) x 16
515 ]; 524 ];
516 525
517 $self->{entry} = new CFClient::UI::Entry 526 $self->{entry} = new CFPlus::UI::Entry
518 on_changed => sub { 527 on_changed => sub {
519 $self->update_labels; 528 $self->update_labels;
520 0 529 0
521 }, 530 },
522 on_button_down => sub { 531 on_button_down => sub {
523 my ($entry, $ev, $x, $y) = @_; 532 my ($entry, $ev, $x, $y) = @_;
524 533
525 if ($ev->{button} == 3) { 534 if ($ev->{button} == 3) {
526 (new CFClient::UI::Menu 535 (new CFPlus::UI::Menu
527 items => [ 536 items => [
528 ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key" 537 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key"
529 => 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 }) }]
530 ], 539 ],
531 )->popup ($ev); 540 )->popup ($ev);
532 return 1; 541 return 1;
533 } 542 }
549 $self->hide; 558 $self->hide;
550 } 559 }
551 } elsif ($ev->{sym} == 27) { 560 } elsif ($ev->{sym} == 27) {
552 $self->{hist_ptr} = 0; 561 $self->{hist_ptr} = 0;
553 $self->hide; 562 $self->hide;
554 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 563 } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) {
555 if ($self->{hist_ptr} > 1) { 564 if ($self->{hist_ptr} > 1) {
556 $self->{hist_ptr}--; 565 $self->{hist_ptr}--;
557 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 566 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
558 } elsif ($self->{hist_ptr} > 0) { 567 } elsif ($self->{hist_ptr} > 0) {
559 $self->{hist_ptr}--; 568 $self->{hist_ptr}--;
561 } else { 570 } else {
562 ++$self->{select_offset} 571 ++$self->{select_offset}
563 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 572 if $self->{select_offset} < $#{ $self->{last_match} || [] };
564 } 573 }
565 $self->update_labels; 574 $self->update_labels;
566 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 575 } elsif ($ev->{sym} == CFPlus::SDLK_UP) {
567 if ($self->{select_offset}) { 576 if ($self->{select_offset}) {
568 --$self->{select_offset} 577 --$self->{select_offset}
569 } else { 578 } else {
570 unless ($self->{hist_ptr}) { 579 unless ($self->{hist_ptr}) {
571 $self->{hist_saveback} = $self->{entry}->get_text; 580 $self->{hist_saveback} = $self->{entry}->get_text;
616} 625}
617 626
618sub hide { 627sub hide {
619 my ($self) = @_; 628 my ($self) = @_;
620 629
630 $self->{hist_ptr} = 0;
631
621 $self->SUPER::hide; 632 $self->SUPER::hide;
622 $self->{entry}->set_text (""); 633 $self->{entry}->set_text ("");
623} 634}
624 635
625sub invoke_key_down { 636sub inject_key_down {
626 my ($self, $ev) = @_; 637 my ($self, $ev) = @_;
627 638
639 $self->{entry}->grab_focus;
628 $self->{entry}->emit (key_down => $ev) 640 $self->{entry}->emit (key_down => $ev);
629} 641}
630 642
631sub update_labels { 643sub update_labels {
632 my ($self) = @_; 644 my ($self) = @_;
633 645
726 738
727sub _draw { 739sub _draw {
728 my ($self) = @_; 740 my ($self) = @_;
729 741
730 # hack 742 # hack
731 local $CFClient::UI::FOCUS = $self->{entry}; 743 local $CFPlus::UI::FOCUS = $self->{entry};
732 744
733 $self->SUPER::_draw; 745 $self->SUPER::_draw;
734} 746}
735 747
7361 7481

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines