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.63 by root, Sun Jun 18 17:13:11 2006 UTC vs.
Revision 1.83 by root, Sun Oct 1 14:48:51 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 keybindings.",
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};
62}
63
64sub test_server_login {
65 return unless
66 $::CONN && length $::CONN->{test_server};
67
68 my $server = $::CONN->{test_server};
69 ::stop_game ();
70 local $::PROFILE->{host} = $server;
71 ::start_game ();
72}
73
74sub editor_invoke {
75 return unless $::CONN;
76
77 # putting the password into the env is somewhat tasteless
78 local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user};
79 local $ENV{CFPLUS_PASSWORD} = $::PROFILE->{password};
80 local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload};
81 local $ENV{CROSSFIRE_MAPDIR} = $::CONN->{cvs_root};
82
83# CFPlus::set_proxy;
84
85 # TODO: move into editor
86 require LWP::Simple;
65} 87}
66 88
67sub invoke_button_down { 89sub invoke_button_down {
68 my ($self, $ev, $x, $y) = @_; 90 my ($self, $ev, $x, $y) = @_;
69 91
70 return unless $::CONN;
71
72 $self->grab_focus;
73
74 if ($ev->{button} == 1) { 92 if ($ev->{button} == 1) {
93 $self->grab_focus;
94 return unless $::CONN;
95
75 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 96 my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
76 my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 97 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
77 98
78 $x -= int 0.5 * $self->{sw}; 99 $x -= int 0.5 * $self->{sw};
79 $y -= int 0.5 * $self->{sh}; 100 $y -= int 0.5 * $self->{sh};
80 101
81 $::CONN->lookat ($x, $y) 102 $::CONN->lookat ($x, $y)
82 if $::CONN; 103 if $::CONN;
83 104
84 } elsif ($ev->{button} == 2) { 105 } elsif ($ev->{button} == 2) {
106 $self->grab_focus;
107 return unless $::CONN;
108
85 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 109 my ($ox, $oy) = ($ev->{x}, $ev->{y});
86 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 110 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
87 111
88 $self->{motion} = sub { 112 $self->{motion} = sub {
89 my ($ev, $x, $y) = @_; 113 my ($ev, $x, $y) = @_;
93 $::CFG->{map_shift_x} = $bw + $x - $ox; 117 $::CFG->{map_shift_x} = $bw + $x - $ox;
94 $::CFG->{map_shift_y} = $bh + $y - $oy; 118 $::CFG->{map_shift_y} = $bh + $y - $oy;
95 119
96 $self->update; 120 $self->update;
97 }; 121 };
122 } elsif ($ev->{button} == 3) {
123 (new CFPlus::UI::Menu
124 items => [
125 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
126 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
127 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
128 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
129 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
130 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }],
131 ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }],
132 [
133 $::PICKUP_ENABLE->{state}
134 ? "Disable automatic pickup"
135 : "Enable automatic pickup",
136 sub { $::PICKUP_ENABLE->toggle }
137 ],
138 $::CONN && length $::CONN->{cvs_root}
139 ? ["Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", \&editor_invoke]
140 : (),
141 $::CONN && length $::CONN->{test_server}
142 ? ["Login on Test Server", \&test_server_login]
143 : (),
144 ["Quit",
145 sub {
146 if ($::CONN) {
147 &::open_quit_dialog;
148 } else {
149 exit;
150 }
151 }
152 ],
153 ],
154 )->popup ($ev);
98 } 155 }
99 156
100 1 157 1
101} 158}
102 159
120 1 177 1
121} 178}
122 179
123sub size_request { 180sub size_request {
124 ( 181 (
125 1 + 32 * int $::WIDTH / 32, 182 32 * CFPlus::ceil $::WIDTH / 32,
126 1 + 32 * int $::HEIGHT / 32, 183 32 * CFPlus::ceil $::HEIGHT / 32,
127 ) 184 )
128} 185}
129 186
130sub update { 187sub update {
131 my ($self) = @_; 188 my ($self) = @_;
133 $self->{need_update} = 1; 190 $self->{need_update} = 1;
134 $self->SUPER::update; 191 $self->SUPER::update;
135} 192}
136 193
137my %DIR = ( 194my %DIR = (
138 CFClient::SDLK_KP8, [1, "north"], 195 CFPlus::SDLK_KP8, [1, "north"],
139 CFClient::SDLK_KP9, [2, "northeast"], 196 CFPlus::SDLK_KP9, [2, "northeast"],
140 CFClient::SDLK_KP6, [3, "east"], 197 CFPlus::SDLK_KP6, [3, "east"],
141 CFClient::SDLK_KP3, [4, "southeast"], 198 CFPlus::SDLK_KP3, [4, "southeast"],
142 CFClient::SDLK_KP2, [5, "south"], 199 CFPlus::SDLK_KP2, [5, "south"],
143 CFClient::SDLK_KP1, [6, "southwest"], 200 CFPlus::SDLK_KP1, [6, "southwest"],
144 CFClient::SDLK_KP4, [7, "west"], 201 CFPlus::SDLK_KP4, [7, "west"],
145 CFClient::SDLK_KP7, [8, "northwest"], 202 CFPlus::SDLK_KP7, [8, "northwest"],
146 203
147 CFClient::SDLK_UP, [1, "north"], 204 CFPlus::SDLK_UP, [1, "north"],
148 CFClient::SDLK_RIGHT, [3, "east"], 205 CFPlus::SDLK_RIGHT, [3, "east"],
149 CFClient::SDLK_DOWN, [5, "south"], 206 CFPlus::SDLK_DOWN, [5, "south"],
150 CFClient::SDLK_LEFT, [7, "west"], 207 CFPlus::SDLK_LEFT, [7, "west"],
151); 208);
152 209
153sub invoke_key_down { 210sub invoke_key_down {
154 my ($self, $ev) = @_; 211 my ($self, $ev) = @_;
155
156 return 0 unless $::CONN;
157 212
158 my $mod = $ev->{mod}; 213 my $mod = $ev->{mod};
159 my $sym = $ev->{sym}; 214 my $sym = $ev->{sym};
160 my $uni = $ev->{unicode}; 215 my $uni = $ev->{unicode};
161 216
162 if ($sym == CFClient::SDLK_KP5) { 217 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
218
219 if ($uni == ord "\t") {
220 $::PL_WINDOW->toggle_visibility;
221 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
222 $::HELP_WINDOW->toggle_visibility;
223 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
224 ::toggle_player_page ($::STATS_PAGE);
225 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
226 ::toggle_player_page ($::SKILL_PAGE);
227 } elsif ($sym == CFPlus::SDLK_F4 && !$mod) {
228 ::toggle_player_page ($::SPELL_PAGE);
229 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
230 ::toggle_player_page ($::INVENTORY_PAGE);
231 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
232 $::SETUP_DIALOG->toggle_visibility;
233 } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) {
234 $::BIND_EDITOR->set_binding (undef, undef, [],
235 sub {
236 my ($mod, $sym, $cmds) = @_;
237 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
238 });
239 $::BIND_EDITOR->start;
240 $::BIND_EDITOR->show;
241#TODO: elmex, what was this supposed to do? it currently crashes the client.
242# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
243# $::BIND_EDITOR->stop;
244# $::BIND_EDITOR->ask_for_bind_and_commit;
245# $::BIND_EDITOR->hide;
246 } elsif (!$::CONN) {
247 return 0; # bindings further down need a valid connection
248
249 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
163 $::CONN->user_send ("stay fire"); 250 $::CONN->user_send ("stay fire");
164 } elsif ($uni == ord ",") { 251 } elsif ($uni == ord ",") {
165 $::CONN->user_send ("take"); 252 $::CONN->user_send ("take");
166 } elsif ($uni == ord " ") { 253 } elsif ($uni == ord " ") {
167 $::CONN->user_send ("apply"); 254 $::CONN->user_send ("apply");
255 } elsif ($uni == 13) {
256 $::CONN->user_send ("examine");
168 } elsif ($uni == ord ".") { 257 } elsif ($uni == ord ".") {
169 $::CONN->user_send ($self->{completer}{last_command}) 258 $::CONN->user_send ($self->{completer}{last_command})
170 if exists $self->{completer}{last_command}; 259 if exists $self->{completer}{last_command};
171 } elsif ($uni == ord "\t") { 260 } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) {
172 $::INV_WINDOW->toggle_visibility; 261 $::CONN->user_send ($_) for @$bind_cmd;
173 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 262 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
174 $::CONN->user_send ("rotateshoottype +"); 263 $::CONN->user_send ("rotateshoottype +");
175 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 264 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
176 $::CONN->user_send ("rotateshoottype -"); 265 $::CONN->user_send ("rotateshoottype -");
177 } elsif ($uni == ord '"') { 266 } elsif ($uni == ord '"') {
178 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 267 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
179 $self->{completer}->show; 268 $self->{completer}->show;
180 } elsif ($uni == ord "'") { 269 } elsif ($uni == ord "'") {
181 $self->{completer}->set_prefix (""); 270 $self->{completer}->set_prefix ("");
182 $self->{completer}->show; 271 $self->{completer}->show;
183 } elsif (exists $DIR{$sym}) { 272 } elsif (exists $DIR{$sym}) {
184 if ($mod & CFClient::KMOD_SHIFT) { 273 if ($mod & CFPlus::KMOD_SHIFT) {
185 $self->{shft}++; 274 $self->{shft}++;
186 if ($DIR{$sym}[0] != $self->{fire_dir}) { 275 if ($DIR{$sym}[0] != $self->{fire_dir}) {
187 $::CONN->user_send ("fire $DIR{$sym}[0]"); 276 $::CONN->user_send ("fire $DIR{$sym}[0]");
188 } 277 }
189 $self->{fire_dir} = $DIR{$sym}[0]; 278 $self->{fire_dir} = $DIR{$sym}[0];
190 } elsif ($mod & CFClient::KMOD_CTRL) { 279 } elsif ($mod & CFPlus::KMOD_CTRL) {
191 $self->{ctrl}++; 280 $self->{ctrl}++;
192 $::CONN->user_send ("run $DIR{$sym}[0]"); 281 $::CONN->user_send ("run $DIR{$sym}[0]");
193 } else { 282 } else {
194 $::CONN->user_send ("$DIR{$sym}[1]"); 283 $::CONN->user_send ("$DIR{$sym}[1]");
195 } 284 }
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 $::CFG->{bindings}->{$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->{bindings}->{$mod}->{$sym}) {
209 $::CONN->user_send ($_) for @$bind_cmd;
210 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 285 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
211 $self->{completer}->key_down ($ev); 286 $self->{completer}->inject_key_down ($ev);
212 $self->{completer}->show; 287 $self->{completer}->show;
213 } else { 288 } else {
214 return 0; 289 return 0;
215 } 290 }
216 291
223 my $res = 0; 298 my $res = 0;
224 my $mod = $ev->{mod}; 299 my $mod = $ev->{mod};
225 my $sym = $ev->{sym}; 300 my $sym = $ev->{sym};
226 301
227 if ($::CFG->{shift_fire_stop}) { 302 if ($::CFG->{shift_fire_stop}) {
228 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 303 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) {
229 $::CONN->user_send ("fire_stop"); 304 $::CONN->user_send ("fire_stop");
230 delete $self->{fire_dir}; 305 delete $self->{fire_dir};
231 $res = 1; 306 $res = 1;
232 } 307 }
233 } else { 308 } else {
234 if (exists $DIR{$sym} && delete $self->{shft}) { 309 if (exists $DIR{$sym} && delete $self->{shft}) {
235 $::CONN->user_send ("fire_stop"); 310 $::CONN->user_send ("fire_stop");
236 delete $self->{fire_dir}; 311 delete $self->{fire_dir};
237 $res = 1; 312 $res = 1;
238 } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? 313 } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
239 $::CONN->user_send ("fire_stop"); 314 $::CONN->user_send ("fire_stop");
240 delete $self->{fire_dir}; 315 delete $self->{fire_dir};
241 $res = 1; 316 $res = 1;
242 } 317 }
243 } 318 }
244 319
245 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 320 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) {
246 $::CONN->user_send ("run_stop"); 321 $::CONN->user_send ("run_stop");
247 $res = 1; 322 $res = 1;
248 } 323 }
249 324
250 $res 325 $res
264sub draw { 339sub draw {
265 my ($self) = @_; 340 my ($self) = @_;
266 341
267 return unless $::MAP; 342 return unless $::MAP;
268 343
269 my $focused = $CFClient::UI::FOCUS == $self 344 my $focused = $CFPlus::UI::FOCUS == $self
270 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 345 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
271 346
272 return 347 return
273 unless $focused || !$::FAST; 348 unless $focused || !$::FAST;
274 349
275 if (delete $self->{need_update}) { 350 if (delete $self->{need_update}) {
276 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 351 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
277 352
278 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize; 353 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
279 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 354 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
280 355
281 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 356 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
282 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 357 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
283 358
284 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize; 359 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
285 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize; 360 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
286 361
287 if ($::CFG->{fow_enable}) { 362 if ($::CFG->{fow_enable}) {
288 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 363 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
289 364
290 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 365 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); 366 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
292 glConvolutionFilter2D ( 367 glConvolutionFilter2D (
293 GL_CONVOLUTION_2D, 368 GL_CONVOLUTION_2D,
294 GL_ALPHA, 369 GL_ALPHA,
295 3, 3, 370 3, 3,
297 (pack "f*", @{ $self->{smooth_matrix} }), 372 (pack "f*", @{ $self->{smooth_matrix} }),
298 ); 373 );
299 glEnable GL_CONVOLUTION_2D; 374 glEnable GL_CONVOLUTION_2D;
300 } 375 }
301 376
302 $self->{fow_texture} = new CFClient::Texture 377 $self->{fow_texture} = new CFPlus::Texture
303 w => $w, 378 w => $w,
304 h => $h, 379 h => $h,
305 data => $data, 380 data => $data,
306 internalformat => GL_ALPHA, 381 internalformat => GL_ALPHA,
307 format => GL_ALPHA; 382 format => GL_ALPHA;
369 glDeleteList $self->{list}; 444 glDeleteList $self->{list};
370 445
371 $self->SUPER::DESTROY; 446 $self->SUPER::DESTROY;
372} 447}
373 448
374package CFClient::MapWidget::MapMap; 449package CFPlus::MapWidget::MapMap;
375 450
376our @ISA = CFClient::UI::Base::; 451our @ISA = CFPlus::UI::Base::;
377 452
378use Time::HiRes qw(time); 453use Time::HiRes qw(time);
379use CFClient::OpenGL; 454use CFPlus::OpenGL;
380 455
381sub size_request { 456sub size_request {
382 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 457 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
383} 458}
384 459
420 495
421 if ($self->{texture_atime} < time) { 496 if ($self->{texture_atime} < time) {
422 $self->{texture_atime} = time + 1/3; 497 $self->{texture_atime} = time + 1/3;
423 498
424 $self->{texture} = 499 $self->{texture} =
425 new CFClient::Texture 500 new CFPlus::Texture
426 w => $w, 501 w => $w,
427 h => $h, 502 h => $h,
428 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 503 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; 504 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
430 } 505 }
431 506
432 $self->{texture}->draw_quad (0, 0); 507 $self->{texture}->draw_quad (0, 0);
433 508
434 glDisable GL_TEXTURE_2D; 509 glDisable GL_TEXTURE_2D;
449 glEnd; 524 glEnd;
450 525
451 glDisable GL_BLEND; 526 glDisable GL_BLEND;
452} 527}
453 528
454package CFClient::MapWidget::Command; 529package CFPlus::MapWidget::Command;
455 530
456use strict; 531use strict;
457 532
458use CFClient::OpenGL; 533use CFPlus::OpenGL;
459 534
460our @ISA = CFClient::UI::Frame::; 535our @ISA = CFPlus::UI::Frame::;
461 536
462sub new { 537sub new {
463 my $class = shift; 538 my $class = shift;
464 539
465 my $self = $class->SUPER::new ( 540 my $self = $class->SUPER::new (
466 bg => [0, 0, 0, 0.8], 541 bg => [0, 0, 0, 0.8],
467 @_, 542 @_,
468 ); 543 );
469 544
470 $self->add ($self->{vbox} = new CFClient::UI::VBox); 545 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
471 546
472 $self->{label} = [ 547 $self->{label} = [
473 map 548 map
474 CFClient::UI::Label->new ( 549 CFPlus::UI::Label->new (
475 can_hover => 1, 550 can_hover => 1,
476 can_events => 1, 551 can_events => 1,
477 tooltip_width => 0.33, 552 tooltip_width => 0.33,
478 fontsize => $_, 553 fontsize => $_,
479 ), (0.8) x 16 554 ), (0.8) x 16
480 ]; 555 ];
481 556
482 $self->{entry} = new CFClient::UI::Entry 557 $self->{entry} = new CFPlus::UI::Entry
483 on_changed => sub { 558 on_changed => sub {
484 $self->update_labels; 559 $self->update_labels;
485 0 560 0
486 }, 561 },
487 on_button_down => sub { 562 on_button_down => sub {
488 my ($entry, $ev, $x, $y) = @_; 563 my ($entry, $ev, $x, $y) = @_;
489 564
490 if ($ev->{button} == 3) { 565 if ($ev->{button} == 3) {
491 (new CFClient::UI::Menu 566 (new CFPlus::UI::Menu
492 items => [ 567 items => [
568 ["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 }) }] 569 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
494 ], 570 ],
495 )->popup ($ev); 571 )->popup ($ev);
496 return 1; 572 return 1;
497 } 573 }
498 0 574 0
505 if ($ev->{sym} == 13) { 581 if ($ev->{sym} == 13) {
506 if (exists $self->{select}) { 582 if (exists $self->{select}) {
507 $self->{last_command} = $self->{select}; 583 $self->{last_command} = $self->{select};
508 $::CONN->user_send ($self->{select}); 584 $::CONN->user_send ($self->{select});
509 585
510 unshift @{$self->{history}}, $self->{select}; 586 unshift @{$self->{history}}, $self->{entry}->get_text;
511 $self->{hist_ptr} = 0; 587 $self->{hist_ptr} = 0;
512 588
513 $self->hide; 589 $self->hide;
514 } 590 }
515 } elsif ($ev->{sym} == 27) { 591 } elsif ($ev->{sym} == 27) {
516 $self->{hist_ptr} = 0; 592 $self->{hist_ptr} = 0;
517 $self->hide; 593 $self->hide;
518 return;
519 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 594 } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) {
520 if ($self->{hist_ptr} > 1) { 595 if ($self->{hist_ptr} > 1) {
521 $self->{hist_ptr}--; 596 $self->{hist_ptr}--;
522 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 597 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
523 } elsif ($self->{hist_ptr} > 0) { 598 } elsif ($self->{hist_ptr} > 0) {
524 $self->{hist_ptr}--; 599 $self->{hist_ptr}--;
526 } else { 601 } else {
527 ++$self->{select_offset} 602 ++$self->{select_offset}
528 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 603 if $self->{select_offset} < $#{ $self->{last_match} || [] };
529 } 604 }
530 $self->update_labels; 605 $self->update_labels;
531 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 606 } elsif ($ev->{sym} == CFPlus::SDLK_UP) {
532 if ($self->{select_offset}) { 607 if ($self->{select_offset}) {
533 --$self->{select_offset} 608 --$self->{select_offset}
534 } else { 609 } else {
535 unless ($self->{hist_ptr}) { 610 unless ($self->{hist_ptr}) {
536 $self->{hist_saveback} = $self->{entry}->get_text; 611 $self->{hist_saveback} = $self->{entry}->get_text;
581} 656}
582 657
583sub hide { 658sub hide {
584 my ($self) = @_; 659 my ($self) = @_;
585 660
661 $self->{hist_ptr} = 0;
662
586 $self->SUPER::hide; 663 $self->SUPER::hide;
587 $self->{entry}->set_text (""); 664 $self->{entry}->set_text ("");
588} 665}
589 666
590sub invoke_key_down { 667sub inject_key_down {
591 my ($self, $ev) = @_; 668 my ($self, $ev) = @_;
592 669
670 $self->{entry}->grab_focus;
593 $self->{entry}->key_down ($ev) 671 $self->{entry}->emit (key_down => $ev);
594} 672}
595 673
596sub update_labels { 674sub update_labels {
597 my ($self) = @_; 675 my ($self) = @_;
598 676
685 $label->set_text (""); 763 $label->set_text ("");
686 $label->set_tooltip (""); 764 $label->set_tooltip ("");
687 } 765 }
688 766
689 $self->update; 767 $self->update;
690 ###
691} 768}
692 769
693sub _draw { 770sub _draw {
694 my ($self) = @_; 771 my ($self) = @_;
695 772
696 # hack 773 # hack
697 local $CFClient::UI::FOCUS = $self->{entry}; 774 local $CFPlus::UI::FOCUS = $self->{entry};
698 775
699 $self->SUPER::_draw; 776 $self->SUPER::_draw;
700} 777}
701 778
7021 7791

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines