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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines