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.71 by root, Sun Jul 2 21:07:26 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 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};
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 if ($ev->{button} == 1) { 92 if ($ev->{button} == 1) {
71 $self->grab_focus; 93 $self->grab_focus;
72 return unless $::CONN; 94 return unless $::CONN;
73 95
74 my $x = 1 + CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 96 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}; 97 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
76 98
77 $x -= int 0.5 * $self->{sw}; 99 $x -= int 0.5 * $self->{sw};
78 $y -= int 0.5 * $self->{sh}; 100 $y -= int 0.5 * $self->{sh};
79 101
80 $::CONN->lookat ($x, $y) 102 $::CONN->lookat ($x, $y)
96 $::CFG->{map_shift_y} = $bh + $y - $oy; 118 $::CFG->{map_shift_y} = $bh + $y - $oy;
97 119
98 $self->update; 120 $self->update;
99 }; 121 };
100 } elsif ($ev->{button} == 3) { 122 } elsif ($ev->{button} == 3) {
101 (new CFClient::UI::Menu 123 (new CFPlus::UI::Menu
102 items => [ 124 items => [
103 ["Help Browser… (F1)", sub { $::HELP_WINDOW->toggle_visibility }], 125 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
104 ["Stats &amp; Skills… (F2)", sub { ::toggle_player_page ($::STATS_PAGE) }], 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) }],
105 ["Inventory… (F3)", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 129 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
106 ["Spells… (F4)", sub { ::toggle_player_page ($::SPELL_PAGE) }],
107 ["Setup… (F5)", sub { $::SETUP_DIALOG->toggle_visibility }], 130 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }],
108 ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], 131 ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }],
109 [ 132 [
110 $::PICKUP_ENABLE->{state} 133 $::PICKUP_ENABLE->{state}
111 ? "Disable automatic pickup" 134 ? "Disable automatic pickup"
112 : "Enable automatic pickup", 135 : "Enable automatic pickup",
113 sub { $::PICKUP_ENABLE->toggle } 136 sub { $::PICKUP_ENABLE->toggle }
114 ], 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 ],
115 ], 153 ],
116 )->popup ($ev); 154 )->popup ($ev);
117 } 155 }
118 156
119 1 157 1
139 1 177 1
140} 178}
141 179
142sub size_request { 180sub size_request {
143 ( 181 (
144 32 * CFClient::ceil $::WIDTH / 32, 182 32 * CFPlus::ceil $::WIDTH / 32,
145 32 * CFClient::ceil $::HEIGHT / 32, 183 32 * CFPlus::ceil $::HEIGHT / 32,
146 ) 184 )
147} 185}
148 186
149sub update { 187sub update {
150 my ($self) = @_; 188 my ($self) = @_;
152 $self->{need_update} = 1; 190 $self->{need_update} = 1;
153 $self->SUPER::update; 191 $self->SUPER::update;
154} 192}
155 193
156my %DIR = ( 194my %DIR = (
157 CFClient::SDLK_KP8, [1, "north"], 195 CFPlus::SDLK_KP8, [1, "north"],
158 CFClient::SDLK_KP9, [2, "northeast"], 196 CFPlus::SDLK_KP9, [2, "northeast"],
159 CFClient::SDLK_KP6, [3, "east"], 197 CFPlus::SDLK_KP6, [3, "east"],
160 CFClient::SDLK_KP3, [4, "southeast"], 198 CFPlus::SDLK_KP3, [4, "southeast"],
161 CFClient::SDLK_KP2, [5, "south"], 199 CFPlus::SDLK_KP2, [5, "south"],
162 CFClient::SDLK_KP1, [6, "southwest"], 200 CFPlus::SDLK_KP1, [6, "southwest"],
163 CFClient::SDLK_KP4, [7, "west"], 201 CFPlus::SDLK_KP4, [7, "west"],
164 CFClient::SDLK_KP7, [8, "northwest"], 202 CFPlus::SDLK_KP7, [8, "northwest"],
165 203
166 CFClient::SDLK_UP, [1, "north"], 204 CFPlus::SDLK_UP, [1, "north"],
167 CFClient::SDLK_RIGHT, [3, "east"], 205 CFPlus::SDLK_RIGHT, [3, "east"],
168 CFClient::SDLK_DOWN, [5, "south"], 206 CFPlus::SDLK_DOWN, [5, "south"],
169 CFClient::SDLK_LEFT, [7, "west"], 207 CFPlus::SDLK_LEFT, [7, "west"],
170); 208);
171 209
172sub invoke_key_down { 210sub invoke_key_down {
173 my ($self, $ev) = @_; 211 my ($self, $ev) = @_;
174 212
175 my $mod = $ev->{mod}; 213 my $mod = $ev->{mod};
176 my $sym = $ev->{sym}; 214 my $sym = $ev->{sym};
177 my $uni = $ev->{unicode}; 215 my $uni = $ev->{unicode};
178 216
179 $mod &= CFClient::KMOD_CTRL | CFClient::KMOD_ALT | CFClient::KMOD_SHIFT; 217 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
180 218
181 if ($uni == ord "\t") { 219 if ($uni == ord "\t") {
182 $::PL_WINDOW->toggle_visibility; 220 $::PL_WINDOW->toggle_visibility;
183 } elsif ($sym == CFClient::SDLK_F1 && !$mod) { 221 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
184 $::HELP_WINDOW->toggle_visibility; 222 $::HELP_WINDOW->toggle_visibility;
185 } elsif ($sym == CFClient::SDLK_F2 && !$mod) { 223 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
186 ::toggle_player_page ($::STATS_PAGE); 224 ::toggle_player_page ($::STATS_PAGE);
187 } elsif ($sym == CFClient::SDLK_F3 && !$mod) { 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) {
188 ::toggle_player_page ($::INVENTORY_PAGE); 230 ::toggle_player_page ($::INVENTORY_PAGE);
189 } elsif ($sym == CFClient::SDLK_F4 && !$mod) { 231 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
190 ::toggle_player_page ($::SPELL_PAGE);
191 } elsif ($sym == CFClient::SDLK_F5 && !$mod) {
192 $::SETUP_DIALOG->toggle_visibility; 232 $::SETUP_DIALOG->toggle_visibility;
193 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { 233 } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) {
194 $::BIND_EDITOR->set_binding (undef, undef, [], 234 $::BIND_EDITOR->set_binding (undef, undef, [],
195 sub { 235 sub {
196 my ($mod, $sym, $cmds) = @_; 236 my ($mod, $sym, $cmds) = @_;
197 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); 237 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
198 }); 238 });
199 $::BIND_EDITOR->start; 239 $::BIND_EDITOR->start;
200 $::BIND_EDITOR->show; 240 $::BIND_EDITOR->show;
241#TODO: elmex, what was this supposed to do? it currently crashes the client.
201 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { 242# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
202 $::BIND_EDITOR->stop; 243# $::BIND_EDITOR->stop;
203 $::BIND_EDITOR->ask_for_bind_and_commit; 244# $::BIND_EDITOR->ask_for_bind_and_commit;
204 $::BIND_EDITOR->hide; 245# $::BIND_EDITOR->hide;
205 } elsif (!$::CONN) { 246 } elsif (!$::CONN) {
206 return 0; # bindings further down need a valid connection 247 return 0; # bindings further down need a valid connection
207 248
208 } elsif ($sym == CFClient::SDLK_KP5 && !$mod) { 249 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
209 $::CONN->user_send ("stay fire"); 250 $::CONN->user_send ("stay fire");
210 } elsif ($uni == ord ",") { 251 } elsif ($uni == ord ",") {
211 $::CONN->user_send ("take"); 252 $::CONN->user_send ("take");
212 } elsif ($uni == ord " ") { 253 } elsif ($uni == ord " ") {
213 $::CONN->user_send ("apply"); 254 $::CONN->user_send ("apply");
255 } elsif ($uni == 13) {
256 $::CONN->user_send ("examine");
214 } elsif ($uni == ord ".") { 257 } elsif ($uni == ord ".") {
215 $::CONN->user_send ($self->{completer}{last_command}) 258 $::CONN->user_send ($self->{completer}{last_command})
216 if exists $self->{completer}{last_command}; 259 if exists $self->{completer}{last_command};
217 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { 260 } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) {
218 $::CONN->user_send ($_) for @$bind_cmd; 261 $::CONN->user_send ($_) for @$bind_cmd;
219 } elsif (($sym == CFClient::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { 262 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
220 $::CONN->user_send ("rotateshoottype +"); 263 $::CONN->user_send ("rotateshoottype +");
221 } elsif (($sym == CFClient::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { 264 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
222 $::CONN->user_send ("rotateshoottype -"); 265 $::CONN->user_send ("rotateshoottype -");
223 } elsif ($uni == ord '"') { 266 } elsif ($uni == ord '"') {
224 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 267 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
225 $self->{completer}->show; 268 $self->{completer}->show;
226 } elsif ($uni == ord "'") { 269 } elsif ($uni == ord "'") {
227 $self->{completer}->set_prefix (""); 270 $self->{completer}->set_prefix ("");
228 $self->{completer}->show; 271 $self->{completer}->show;
229 } elsif (exists $DIR{$sym}) { 272 } elsif (exists $DIR{$sym}) {
230 if ($mod & CFClient::KMOD_SHIFT) { 273 if ($mod & CFPlus::KMOD_SHIFT) {
231 $self->{shft}++; 274 $self->{shft}++;
232 if ($DIR{$sym}[0] != $self->{fire_dir}) { 275 if ($DIR{$sym}[0] != $self->{fire_dir}) {
233 $::CONN->user_send ("fire $DIR{$sym}[0]"); 276 $::CONN->user_send ("fire $DIR{$sym}[0]");
234 } 277 }
235 $self->{fire_dir} = $DIR{$sym}[0]; 278 $self->{fire_dir} = $DIR{$sym}[0];
236 } elsif ($mod & CFClient::KMOD_CTRL) { 279 } elsif ($mod & CFPlus::KMOD_CTRL) {
237 $self->{ctrl}++; 280 $self->{ctrl}++;
238 $::CONN->user_send ("run $DIR{$sym}[0]"); 281 $::CONN->user_send ("run $DIR{$sym}[0]");
239 } else { 282 } else {
240 $::CONN->user_send ("$DIR{$sym}[1]"); 283 $::CONN->user_send ("$DIR{$sym}[1]");
241 } 284 }
242 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 285 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
243 $self->{completer}->invoke_key_down ($ev); 286 $self->{completer}->inject_key_down ($ev);
244 $self->{completer}->show; 287 $self->{completer}->show;
245 } else { 288 } else {
246 return 0; 289 return 0;
247 } 290 }
248 291
255 my $res = 0; 298 my $res = 0;
256 my $mod = $ev->{mod}; 299 my $mod = $ev->{mod};
257 my $sym = $ev->{sym}; 300 my $sym = $ev->{sym};
258 301
259 if ($::CFG->{shift_fire_stop}) { 302 if ($::CFG->{shift_fire_stop}) {
260 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 303 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) {
261 $::CONN->user_send ("fire_stop"); 304 $::CONN->user_send ("fire_stop");
262 delete $self->{fire_dir}; 305 delete $self->{fire_dir};
263 $res = 1; 306 $res = 1;
264 } 307 }
265 } else { 308 } else {
266 if (exists $DIR{$sym} && delete $self->{shft}) { 309 if (exists $DIR{$sym} && delete $self->{shft}) {
267 $::CONN->user_send ("fire_stop"); 310 $::CONN->user_send ("fire_stop");
268 delete $self->{fire_dir}; 311 delete $self->{fire_dir};
269 $res = 1; 312 $res = 1;
270 } 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?
271 $::CONN->user_send ("fire_stop"); 314 $::CONN->user_send ("fire_stop");
272 delete $self->{fire_dir}; 315 delete $self->{fire_dir};
273 $res = 1; 316 $res = 1;
274 } 317 }
275 } 318 }
276 319
277 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 320 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) {
278 $::CONN->user_send ("run_stop"); 321 $::CONN->user_send ("run_stop");
279 $res = 1; 322 $res = 1;
280 } 323 }
281 324
282 $res 325 $res
296sub draw { 339sub draw {
297 my ($self) = @_; 340 my ($self) = @_;
298 341
299 return unless $::MAP; 342 return unless $::MAP;
300 343
301 my $focused = $CFClient::UI::FOCUS == $self 344 my $focused = $CFPlus::UI::FOCUS == $self
302 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 345 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
303 346
304 return 347 return
305 unless $focused || !$::FAST; 348 unless $focused || !$::FAST;
306 349
307 if (delete $self->{need_update}) { 350 if (delete $self->{need_update}) {
308 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 351 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
309 352
310 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize; 353 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
311 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 354 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
312 355
313 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 356 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
314 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 357 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
315 358
316 my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize; 359 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
317 my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize; 360 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
318 361
319 if ($::CFG->{fow_enable}) { 362 if ($::CFG->{fow_enable}) {
320 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);
321 364
322 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
323 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 366 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
324 glConvolutionFilter2D ( 367 glConvolutionFilter2D (
325 GL_CONVOLUTION_2D, 368 GL_CONVOLUTION_2D,
326 GL_ALPHA, 369 GL_ALPHA,
327 3, 3, 370 3, 3,
329 (pack "f*", @{ $self->{smooth_matrix} }), 372 (pack "f*", @{ $self->{smooth_matrix} }),
330 ); 373 );
331 glEnable GL_CONVOLUTION_2D; 374 glEnable GL_CONVOLUTION_2D;
332 } 375 }
333 376
334 $self->{fow_texture} = new CFClient::Texture 377 $self->{fow_texture} = new CFPlus::Texture
335 w => $w, 378 w => $w,
336 h => $h, 379 h => $h,
337 data => $data, 380 data => $data,
338 internalformat => GL_ALPHA, 381 internalformat => GL_ALPHA,
339 format => GL_ALPHA; 382 format => GL_ALPHA;
401 glDeleteList $self->{list}; 444 glDeleteList $self->{list};
402 445
403 $self->SUPER::DESTROY; 446 $self->SUPER::DESTROY;
404} 447}
405 448
406package CFClient::MapWidget::MapMap; 449package CFPlus::MapWidget::MapMap;
407 450
408our @ISA = CFClient::UI::Base::; 451our @ISA = CFPlus::UI::Base::;
409 452
410use Time::HiRes qw(time); 453use Time::HiRes qw(time);
411use CFClient::OpenGL; 454use CFPlus::OpenGL;
412 455
413sub size_request { 456sub size_request {
414 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 457 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
415} 458}
416 459
452 495
453 if ($self->{texture_atime} < time) { 496 if ($self->{texture_atime} < time) {
454 $self->{texture_atime} = time + 1/3; 497 $self->{texture_atime} = time + 1/3;
455 498
456 $self->{texture} = 499 $self->{texture} =
457 new CFClient::Texture 500 new CFPlus::Texture
458 w => $w, 501 w => $w,
459 h => $h, 502 h => $h,
460 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 503 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; 504 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
462 } 505 }
463 506
464 $self->{texture}->draw_quad (0, 0); 507 $self->{texture}->draw_quad (0, 0);
465 508
466 glDisable GL_TEXTURE_2D; 509 glDisable GL_TEXTURE_2D;
481 glEnd; 524 glEnd;
482 525
483 glDisable GL_BLEND; 526 glDisable GL_BLEND;
484} 527}
485 528
486package CFClient::MapWidget::Command; 529package CFPlus::MapWidget::Command;
487 530
488use strict; 531use strict;
489 532
490use CFClient::OpenGL; 533use CFPlus::OpenGL;
491 534
492our @ISA = CFClient::UI::Frame::; 535our @ISA = CFPlus::UI::Frame::;
493 536
494sub new { 537sub new {
495 my $class = shift; 538 my $class = shift;
496 539
497 my $self = $class->SUPER::new ( 540 my $self = $class->SUPER::new (
498 bg => [0, 0, 0, 0.8], 541 bg => [0, 0, 0, 0.8],
499 @_, 542 @_,
500 ); 543 );
501 544
502 $self->add ($self->{vbox} = new CFClient::UI::VBox); 545 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
503 546
504 $self->{label} = [ 547 $self->{label} = [
505 map 548 map
506 CFClient::UI::Label->new ( 549 CFPlus::UI::Label->new (
507 can_hover => 1, 550 can_hover => 1,
508 can_events => 1, 551 can_events => 1,
509 tooltip_width => 0.33, 552 tooltip_width => 0.33,
510 fontsize => $_, 553 fontsize => $_,
511 ), (0.8) x 16 554 ), (0.8) x 16
512 ]; 555 ];
513 556
514 $self->{entry} = new CFClient::UI::Entry 557 $self->{entry} = new CFPlus::UI::Entry
515 on_changed => sub { 558 on_changed => sub {
516 $self->update_labels; 559 $self->update_labels;
517 0 560 0
518 }, 561 },
519 on_button_down => sub { 562 on_button_down => sub {
520 my ($entry, $ev, $x, $y) = @_; 563 my ($entry, $ev, $x, $y) = @_;
521 564
522 if ($ev->{button} == 3) { 565 if ($ev->{button} == 3) {
523 (new CFClient::UI::Menu 566 (new CFPlus::UI::Menu
524 items => [ 567 items => [
525 ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key" 568 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key"
526 => 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 }) }]
527 ], 570 ],
528 )->popup ($ev); 571 )->popup ($ev);
529 return 1; 572 return 1;
530 } 573 }
546 $self->hide; 589 $self->hide;
547 } 590 }
548 } elsif ($ev->{sym} == 27) { 591 } elsif ($ev->{sym} == 27) {
549 $self->{hist_ptr} = 0; 592 $self->{hist_ptr} = 0;
550 $self->hide; 593 $self->hide;
551 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 594 } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) {
552 if ($self->{hist_ptr} > 1) { 595 if ($self->{hist_ptr} > 1) {
553 $self->{hist_ptr}--; 596 $self->{hist_ptr}--;
554 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 597 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
555 } elsif ($self->{hist_ptr} > 0) { 598 } elsif ($self->{hist_ptr} > 0) {
556 $self->{hist_ptr}--; 599 $self->{hist_ptr}--;
558 } else { 601 } else {
559 ++$self->{select_offset} 602 ++$self->{select_offset}
560 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 603 if $self->{select_offset} < $#{ $self->{last_match} || [] };
561 } 604 }
562 $self->update_labels; 605 $self->update_labels;
563 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 606 } elsif ($ev->{sym} == CFPlus::SDLK_UP) {
564 if ($self->{select_offset}) { 607 if ($self->{select_offset}) {
565 --$self->{select_offset} 608 --$self->{select_offset}
566 } else { 609 } else {
567 unless ($self->{hist_ptr}) { 610 unless ($self->{hist_ptr}) {
568 $self->{hist_saveback} = $self->{entry}->get_text; 611 $self->{hist_saveback} = $self->{entry}->get_text;
613} 656}
614 657
615sub hide { 658sub hide {
616 my ($self) = @_; 659 my ($self) = @_;
617 660
661 $self->{hist_ptr} = 0;
662
618 $self->SUPER::hide; 663 $self->SUPER::hide;
619 $self->{entry}->set_text (""); 664 $self->{entry}->set_text ("");
620} 665}
621 666
622sub invoke_key_down { 667sub inject_key_down {
623 my ($self, $ev) = @_; 668 my ($self, $ev) = @_;
624 669
670 $self->{entry}->grab_focus;
625 $self->{entry}->emit (key_down => $ev) 671 $self->{entry}->emit (key_down => $ev);
626} 672}
627 673
628sub update_labels { 674sub update_labels {
629 my ($self) = @_; 675 my ($self) = @_;
630 676
723 769
724sub _draw { 770sub _draw {
725 my ($self) = @_; 771 my ($self) = @_;
726 772
727 # hack 773 # hack
728 local $CFClient::UI::FOCUS = $self->{entry}; 774 local $CFPlus::UI::FOCUS = $self->{entry};
729 775
730 $self->SUPER::_draw; 776 $self->SUPER::_draw;
731} 777}
732 778
7331 7791

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines