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.43 by elmex, Mon May 29 19:30:28 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::;
13
14my $magicmap_tex =
15 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png",
16 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
11 17
12sub new { 18sub new {
13 my $class = shift; 19 my $class = shift;
14 20
15 my $self = $class->SUPER::new ( 21 my $self = $class->SUPER::new (
16 z => -1, 22 z => -1,
17 can_focus => 1, 23 can_focus => 1,
18 list => glGenList, 24 list => glGenList,
25
26 smooth_matrix => [
27 0.05, 0.13, 0.05,
28 0.13, 0.30, 0.13,
29 0.05, 0.13, 0.05,
30 ],
31
19 @_ 32 @_
20 ); 33 );
21 34
22 $self->{completer} = new CFClient::MapWidget::Command:: 35 $self->{completer} = new CFPlus::MapWidget::Command::
23 command => $self->{command}, 36 command => $self->{command},
24 can_focus => 1, 37 tooltip => "#completer_help",
25 tooltip => "<b>The Command Completer</b>\n\n"
26 . "This is your central interface to send text commands to the server. "
27 . "To enter a verbatim command to send to the server, just type the command, "
28 . "followed by a space, and press return. "
29 . "Typing the initial letters of words (or just any letters) displays guesses "
30 . "for commands you might want to use.\n"
31 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n"
32 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.",
33 ; 38 ;
34 39
35 $self 40 $self
36} 41}
37 42
49 54
50sub clr_commands { 55sub clr_commands {
51 my ($self) = @_; 56 my ($self) = @_;
52 57
53 %{$self->{completer}{command}} = (); 58 %{$self->{completer}{command}} = ();
54}
55 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;
87}
88
56sub button_down { 89sub invoke_button_down {
57 my ($self, $ev, $x, $y) = @_; 90 my ($self, $ev, $x, $y) = @_;
58 91
59 $self->focus_in;
60
61 if ($ev->{button} == 2) { 92 if ($ev->{button} == 1) {
93 $self->grab_focus;
94 return unless $::CONN;
95
96 my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
97 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
98
99 $x -= int 0.5 * $self->{sw};
100 $y -= int 0.5 * $self->{sh};
101
102 $::CONN->lookat ($x, $y)
103 if $::CONN;
104
105 } elsif ($ev->{button} == 2) {
106 $self->grab_focus;
107 return unless $::CONN;
108
62 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 109 my ($ox, $oy) = ($ev->{x}, $ev->{y});
63 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 110 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
64 111
65 $self->{motion} = sub { 112 $self->{motion} = sub {
66 my ($ev, $x, $y) = @_; 113 my ($ev, $x, $y) = @_;
70 $::CFG->{map_shift_x} = $bw + $x - $ox; 117 $::CFG->{map_shift_x} = $bw + $x - $ox;
71 $::CFG->{map_shift_y} = $bh + $y - $oy; 118 $::CFG->{map_shift_y} = $bh + $y - $oy;
72 119
73 $self->update; 120 $self->update;
74 }; 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);
155 }
156
75 } 157 1
76} 158}
77 159
78sub button_up { 160sub invoke_button_up {
79 my ($self, $ev, $x, $y) = @_; 161 my ($self, $ev, $x, $y) = @_;
80 162
81 delete $self->{motion}; 163 delete $self->{motion};
82}
83 164
165 1
166}
167
84sub mouse_motion { 168sub invoke_mouse_motion {
85 my ($self, $ev, $x, $y) = @_; 169 my ($self, $ev, $x, $y) = @_;
86 170
171 if ($self->{motion}) {
87 $self->{motion}->($ev, $x, $y) if $self->{motion}; 172 $self->{motion}->($ev, $x, $y);
173 } else {
174 return 0;
175 }
176
177 1
88} 178}
89 179
90sub size_request { 180sub size_request {
91 ( 181 (
92 1 + 32 * int $::WIDTH / 32, 182 32 * CFPlus::ceil $::WIDTH / 32,
93 1 + 32 * int $::HEIGHT / 32, 183 32 * CFPlus::ceil $::HEIGHT / 32,
94 ) 184 )
95} 185}
96 186
97sub update { 187sub update {
98 my ($self) = @_; 188 my ($self) = @_;
100 $self->{need_update} = 1; 190 $self->{need_update} = 1;
101 $self->SUPER::update; 191 $self->SUPER::update;
102} 192}
103 193
104my %DIR = ( 194my %DIR = (
105 CFClient::SDLK_KP8, [1, "north"], 195 CFPlus::SDLK_KP8, [1, "north"],
106 CFClient::SDLK_KP9, [2, "northeast"], 196 CFPlus::SDLK_KP9, [2, "northeast"],
107 CFClient::SDLK_KP6, [3, "east"], 197 CFPlus::SDLK_KP6, [3, "east"],
108 CFClient::SDLK_KP3, [4, "southeast"], 198 CFPlus::SDLK_KP3, [4, "southeast"],
109 CFClient::SDLK_KP2, [5, "south"], 199 CFPlus::SDLK_KP2, [5, "south"],
110 CFClient::SDLK_KP1, [6, "southwest"], 200 CFPlus::SDLK_KP1, [6, "southwest"],
111 CFClient::SDLK_KP4, [7, "west"], 201 CFPlus::SDLK_KP4, [7, "west"],
112 CFClient::SDLK_KP7, [8, "northwest"], 202 CFPlus::SDLK_KP7, [8, "northwest"],
113 203
114 CFClient::SDLK_UP, [1, "north"], 204 CFPlus::SDLK_UP, [1, "north"],
115 CFClient::SDLK_RIGHT, [3, "east"], 205 CFPlus::SDLK_RIGHT, [3, "east"],
116 CFClient::SDLK_DOWN, [5, "south"], 206 CFPlus::SDLK_DOWN, [5, "south"],
117 CFClient::SDLK_LEFT, [7, "west"], 207 CFPlus::SDLK_LEFT, [7, "west"],
118); 208);
119 209
120sub key_down { 210sub invoke_key_down {
121 my ($self, $ev) = @_; 211 my ($self, $ev) = @_;
122
123 return unless $::CONN;
124 212
125 my $mod = $ev->{mod}; 213 my $mod = $ev->{mod};
126 my $sym = $ev->{sym}; 214 my $sym = $ev->{sym};
127 my $uni = $ev->{unicode}; 215 my $uni = $ev->{unicode};
128 216
129 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) {
130 $::CONN->user_send ("stay fire"); 250 $::CONN->user_send ("stay fire");
131 } elsif ($uni == ord ",") { 251 } elsif ($uni == ord ",") {
132 $::CONN->user_send ("take"); 252 $::CONN->user_send ("take");
133 } elsif ($uni == ord " ") { 253 } elsif ($uni == ord " ") {
134 $::CONN->user_send ("apply"); 254 $::CONN->user_send ("apply");
255 } elsif ($uni == 13) {
256 $::CONN->user_send ("examine");
135 } elsif ($uni == ord ".") { 257 } elsif ($uni == ord ".") {
136 $::CONN->user_send ($self->{completer}{last_command}) 258 $::CONN->user_send ($self->{completer}{last_command})
137 if exists $self->{completer}{last_command}; 259 if exists $self->{completer}{last_command};
138 } elsif ($uni == ord "\t") { 260 } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) {
139 $::INV_WINDOW->toggle_visibility; 261 $::CONN->user_send ($_) for @$bind_cmd;
140 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 262 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
141 $::CONN->user_send ("rotateshoottype +"); 263 $::CONN->user_send ("rotateshoottype +");
142 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 264 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
143 $::CONN->user_send ("rotateshoottype -"); 265 $::CONN->user_send ("rotateshoottype -");
144 } elsif ($uni == ord '"') { 266 } elsif ($uni == ord '"') {
145 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 267 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
146 $self->{completer}->show; 268 $self->{completer}->show;
147 } elsif ($uni == ord "'") { 269 } elsif ($uni == ord "'") {
148 $self->{completer}->set_prefix (""); 270 $self->{completer}->set_prefix ("");
149 $self->{completer}->show; 271 $self->{completer}->show;
150 } elsif (exists $DIR{$sym}) { 272 } elsif (exists $DIR{$sym}) {
151 if ($mod & CFClient::KMOD_SHIFT) { 273 if ($mod & CFPlus::KMOD_SHIFT) {
152 $self->{shft}++; 274 $self->{shft}++;
275 if ($DIR{$sym}[0] != $self->{fire_dir}) {
153 $::CONN->user_send ("fire $DIR{$sym}[0]"); 276 $::CONN->user_send ("fire $DIR{$sym}[0]");
277 }
278 $self->{fire_dir} = $DIR{$sym}[0];
154 } elsif ($mod & CFClient::KMOD_CTRL) { 279 } elsif ($mod & CFPlus::KMOD_CTRL) {
155 $self->{ctrl}++; 280 $self->{ctrl}++;
156 $::CONN->user_send ("run $DIR{$sym}[0]"); 281 $::CONN->user_send ("run $DIR{$sym}[0]");
157 } else { 282 } else {
158 $::CONN->user_send ("$DIR{$sym}[1]"); 283 $::CONN->user_send ("$DIR{$sym}[1]");
159 } 284 }
160 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
161 CFClient::Recorder::start (1);
162 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
163 CFClient::Recorder::stop (1);
164 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) {
165 $::CONN->user_send ($_) for @$bind_cmd;
166 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 285 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
167 $self->{completer}->key_down ($ev); 286 $self->{completer}->inject_key_down ($ev);
168 $self->{completer}->show; 287 $self->{completer}->show;
288 } else {
289 return 0;
290 }
291
169 } 292 1
170} 293}
171 294
172sub key_up { 295sub invoke_key_up {
173 my ($self, $ev) = @_; 296 my ($self, $ev) = @_;
174 297
298 my $res = 0;
175 my $mod = $ev->{mod}; 299 my $mod = $ev->{mod};
176 my $sym = $ev->{sym}; 300 my $sym = $ev->{sym};
177 301
302 if ($::CFG->{shift_fire_stop}) {
178 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 303 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) {
179 $::CONN->user_send ("fire_stop"); 304 $::CONN->user_send ("fire_stop");
305 delete $self->{fire_dir};
306 $res = 1;
307 }
308 } else {
309 if (exists $DIR{$sym} && delete $self->{shft}) {
310 $::CONN->user_send ("fire_stop");
311 delete $self->{fire_dir};
312 $res = 1;
313 } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
314 $::CONN->user_send ("fire_stop");
315 delete $self->{fire_dir};
316 $res = 1;
317 }
180 } 318 }
319
181 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 320 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) {
182 $::CONN->user_send ("run_stop"); 321 $::CONN->user_send ("run_stop");
322 $res = 1;
183 } 323 }
324
325 $res
326}
327
328sub set_magicmap {
329 my ($self, $w, $h, $x, $y, $data) = @_;
330
331 $x -= $::MAP->ox + int 0.5 * $::MAP->w;
332 $y -= $::MAP->oy + int 0.5 * $::MAP->h;
333
334 $self->{magicmap} = [$x, $y, $w, $h, $data];
335
336 $self->update;
184} 337}
185 338
186sub draw { 339sub draw {
187 my ($self) = @_; 340 my ($self) = @_;
188 341
342 return unless $::MAP;
343
189 my $focused = $CFClient::UI::FOCUS == $self 344 my $focused = $CFPlus::UI::FOCUS == $self
190 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 345 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
191 346
192 return 347 return
193 unless $focused || !$::FAST; 348 unless $focused || !$::FAST;
194 349
195 if (delete $self->{need_update}) { 350 if (delete $self->{need_update}) {
351 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
352
353 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
354 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
355
356 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
357 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
358
359 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
360 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
361
362 if ($::CFG->{fow_enable}) {
363 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
364
365 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
366 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
367 glConvolutionFilter2D (
368 GL_CONVOLUTION_2D,
369 GL_ALPHA,
370 3, 3,
371 GL_ALPHA, GL_FLOAT,
372 (pack "f*", @{ $self->{smooth_matrix} }),
373 );
374 glEnable GL_CONVOLUTION_2D;
375 }
376
377 $self->{fow_texture} = new CFPlus::Texture
378 w => $w,
379 h => $h,
380 data => $data,
381 internalformat => GL_ALPHA,
382 format => GL_ALPHA;
383
384 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
385 } else {
386 delete $self->{fow_texture};
387 }
388
196 glNewList $self->{list}; 389 glNewList $self->{list};
197 390
198 if ($::MAP) {
199 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
200 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
201
202 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
203 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
204
205 glPushMatrix; 391 glPushMatrix;
392 glTranslate $sx0, $sy0;
206 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 393 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
207 394
208 glTranslate $sx0 - 32, $sy0 - 32, 0; 395 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
209 396
210 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 397 glScale 32, 32;
211 398
212 if ($::CFG->{fow_enable}) { 399 if (my $tex = $self->{fow_texture}) {
213 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
214 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
215 glConvolutionFilter2D (
216 GL_CONVOLUTION_2D,
217 GL_ALPHA,
218 3, 3,
219 GL_ALPHA, GL_FLOAT,
220 pack "f*",
221 0.05, 0.13, 0.05,
222 0.13, 0.30, 0.13,
223 0.05, 0.13, 0.05,
224 );
225 glEnable GL_CONVOLUTION_2D;
226 }
227
228 $self->{fow_texture_name} ||= glGenTexture;
229 # try to re-use the texture name: TODO improve texture class instead
230
231 $self->{fow_texture} = new CFClient::Texture
232 w => $w,
233 h => $h,
234 data => $data,
235 name => $self->{fow_texture_name},
236 internalformat => GL_ALPHA,
237 format => GL_ALPHA;
238
239 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
240
241 glEnable GL_TEXTURE_2D; 400 glEnable GL_TEXTURE_2D;
242 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 401 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
243 402
244 glColor +($::CFG->{fow_intensity}) x 3, 0.8; 403 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
245 $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); 404 $self->{fow_texture}->draw_quad_alpha (0, 0);
246 405
247 glDisable GL_TEXTURE_2D; 406 glDisable GL_TEXTURE_2D;
248 } 407 }
249 408
409 if ($self->{magicmap}) {
410 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
411
412 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1);
413 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1);
414
415 glTranslate - $x - 1, - $y - 1;
416 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
417 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
418 }
419
250 glPopMatrix; 420 glPopMatrix;
251 }
252
253 glEndList; 421 glEndList;
254 } 422 }
255 423
256 glPushMatrix;
257 glCallList $self->{list}; 424 glCallList $self->{list};
258 glPopMatrix;
259 425
260 # TNT2 emulates logops in software (or worse :) 426 # TNT2 emulates logops in software (or worse :)
261 if ($focused) { 427 unless ($focused) {
262 (delete $self->{out_of_focus})->destroy
263 if $self->{out_of_focus};
264 } else {
265 glColor 0.4, 0.2, 0.2, 0.6; 428 glColor 0.4, 0.2, 0.2, 0.6;
266 glEnable GL_BLEND; 429 glEnable GL_BLEND;
267 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 430 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
268 glBegin GL_QUADS; 431 glBegin GL_QUADS;
269 glVertex 0, 0; 432 glVertex 0, 0;
270 glVertex 0, $::HEIGHT; 433 glVertex 0, $::HEIGHT;
271 glVertex $::WIDTH, $::HEIGHT; 434 glVertex $::WIDTH, $::HEIGHT;
272 glVertex $::WIDTH, 0; 435 glVertex $::WIDTH, 0;
273 glEnd; 436 glEnd;
274 glDisable GL_BLEND; 437 glDisable GL_BLEND;
275
276# $self->{out_of_focus} ||= do {
277# my $label = new CFClient::UI::Label
278# x => 0,
279# y => 0,
280# z => 1,
281# ellipsise => 0,
282# text => "map out of focus (click map to play)";
283#
284# $label->show;
285# $label->update;
286#
287# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
288# $label->move (
289# ($::WIDTH - $label->{w}) * 0.5,
290# ($::HEIGHT - $label->{h}) * 0.5,
291# );
292# });
293#
294# $label
295# };
296 } 438 }
297} 439}
298 440
299sub DESTROY { 441sub DESTROY {
300 my $self = shift; 442 my $self = shift;
302 glDeleteList $self->{list}; 444 glDeleteList $self->{list};
303 445
304 $self->SUPER::DESTROY; 446 $self->SUPER::DESTROY;
305} 447}
306 448
307package CFClient::MapWidget::MapMap; 449package CFPlus::MapWidget::MapMap;
308 450
309our @ISA = CFClient::UI::Base::; 451our @ISA = CFPlus::UI::Base::;
310 452
311use Time::HiRes qw(time); 453use Time::HiRes qw(time);
312use CFClient::OpenGL; 454use CFPlus::OpenGL;
313 455
314sub size_request { 456sub size_request {
315 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 457 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
316} 458}
317 459
318sub size_allocate { 460sub invoke_size_allocate {
319 my ($self, $w, $h) = @_; 461 my ($self, $w, $h) = @_;
320 462
321 $self->SUPER::size_allocate ($w, $h);
322 $self->update; 463 $self->update;
464
465 1
323} 466}
324 467
325sub update { 468sub update {
326 my ($self) = @_; 469 my ($self) = @_;
327 470
352 495
353 if ($self->{texture_atime} < time) { 496 if ($self->{texture_atime} < time) {
354 $self->{texture_atime} = time + 1/3; 497 $self->{texture_atime} = time + 1/3;
355 498
356 $self->{texture} = 499 $self->{texture} =
357 new CFClient::Texture 500 new CFPlus::Texture
358 w => $w, 501 w => $w,
359 h => $h, 502 h => $h,
360 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 503 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
361 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;
362 } 505 }
363 506
364 $self->{texture}->draw_quad (0, 0); 507 $self->{texture}->draw_quad (0, 0);
365 508
366 glDisable GL_TEXTURE_2D; 509 glDisable GL_TEXTURE_2D;
381 glEnd; 524 glEnd;
382 525
383 glDisable GL_BLEND; 526 glDisable GL_BLEND;
384} 527}
385 528
386package CFClient::MapWidget::Command; 529package CFPlus::MapWidget::Command;
387 530
388use strict; 531use strict;
389 532
390use CFClient::OpenGL; 533use CFPlus::OpenGL;
391 534
392our @ISA = CFClient::UI::Frame::; 535our @ISA = CFPlus::UI::Frame::;
393 536
394sub new { 537sub new {
395 my $class = shift; 538 my $class = shift;
396 539
397 my $self = $class->SUPER::new ( 540 my $self = $class->SUPER::new (
398 bg => [0, 0, 0, 0.8], 541 bg => [0, 0, 0, 0.8],
399 @_, 542 @_,
400 ); 543 );
401 544
402 $self->add ($self->{vbox} = new CFClient::UI::VBox); 545 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
403 546
404 $self->{label} = [ 547 $self->{label} = [
405 map 548 map
406 CFClient::UI::Label->new ( 549 CFPlus::UI::Label->new (
407 can_hover => 1, 550 can_hover => 1,
408 can_events => 1, 551 can_events => 1,
409 tooltip_width => 0.33, 552 tooltip_width => 0.33,
410 fontsize => $_, 553 fontsize => $_,
411 ), (0.8) x 16 554 ), (0.8) x 16
412 ]; 555 ];
413 556
414 $self->{entry} = new CFClient::UI::Entry 557 $self->{entry} = new CFPlus::UI::Entry
415 on_changed => sub { 558 on_changed => sub {
416 $self->update_labels; 559 $self->update_labels;
560 0
561 },
562 on_button_down => sub {
563 my ($entry, $ev, $x, $y) = @_;
564
565 if ($ev->{button} == 3) {
566 (new CFPlus::UI::Menu
567 items => [
568 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key"
569 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
570 ],
571 )->popup ($ev);
572 return 1;
573 }
574 0
417 }, 575 },
418 on_key_down => sub { 576 on_key_down => sub {
419 my ($entry, $ev) = @_; 577 my ($entry, $ev) = @_;
420 578
421 my $self = $entry->{parent}{parent}; 579 my $self = $entry->{parent}{parent};
422 580
423 if ($ev->{sym} == 13) { 581 if ($ev->{sym} == 13) {
424 if (exists $self->{select}) { 582 if (exists $self->{select}) {
425 $self->{last_command} = $self->{select}; 583 $self->{last_command} = $self->{select};
426 $::CONN->user_send ($self->{select}); 584 $::CONN->user_send ($self->{select});
585
586 unshift @{$self->{history}}, $self->{entry}->get_text;
587 $self->{hist_ptr} = 0;
588
427 $self->hide; 589 $self->hide;
428 } 590 }
429 } elsif ($ev->{sym} == 27) { 591 } elsif ($ev->{sym} == 27) {
592 $self->{hist_ptr} = 0;
430 $self->hide; 593 $self->hide;
431 return;
432 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 594 } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) {
595 if ($self->{hist_ptr} > 1) {
596 $self->{hist_ptr}--;
597 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
598 } elsif ($self->{hist_ptr} > 0) {
599 $self->{hist_ptr}--;
600 $self->{entry}->set_text ($self->{hist_saveback});
601 } else {
433 ++$self->{select_offset} 602 ++$self->{select_offset}
434 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 603 if $self->{select_offset} < $#{ $self->{last_match} || [] };
604 }
435 $self->update_labels; 605 $self->update_labels;
436 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 606 } elsif ($ev->{sym} == CFPlus::SDLK_UP) {
607 if ($self->{select_offset}) {
437 --$self->{select_offset} 608 --$self->{select_offset}
609 } else {
610 unless ($self->{hist_ptr}) {
611 $self->{hist_saveback} = $self->{entry}->get_text;
612 }
613 if ($self->{hist_ptr} <= $#{$self->{history}}) {
438 if $self->{select_offset}; 614 $self->{hist_ptr}++;
615 }
616 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
617 if exists $self->{history}->[$self->{hist_ptr} - 1];
618 }
439 $self->update_labels; 619 $self->update_labels;
440 } else { 620 } else {
441 return 0; 621 return 0;
442 } 622 }
443 623
458 638
459 $self->{entry}->set_text ($prefix); 639 $self->{entry}->set_text ($prefix);
460 $self->show; 640 $self->show;
461} 641}
462 642
463sub size_allocate { 643sub invoke_size_allocate {
464 my ($self, $w, $h) = @_; 644 my ($self, $w, $h) = @_;
465 645
466 $self->SUPER::size_allocate ($w, $h);
467 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 646 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
647
648 $self->SUPER::invoke_size_allocate ($w, $h)
468} 649}
469 650
470sub show { 651sub show {
471 my ($self) = @_; 652 my ($self) = @_;
472 653
473 $self->SUPER::show; 654 $self->SUPER::show;
474 $self->{entry}->focus_in; 655 $self->{entry}->grab_focus;
475} 656}
476 657
477sub hide { 658sub hide {
478 my ($self) = @_; 659 my ($self) = @_;
660
661 $self->{hist_ptr} = 0;
479 662
480 $self->SUPER::hide; 663 $self->SUPER::hide;
481 $self->{entry}->set_text (""); 664 $self->{entry}->set_text ("");
482} 665}
483 666
484sub key_down { 667sub inject_key_down {
485 my ($self, $ev) = @_; 668 my ($self, $ev) = @_;
486 669
670 $self->{entry}->grab_focus;
487 $self->{entry}->key_down ($ev); 671 $self->{entry}->emit (key_down => $ev);
488} 672}
489 673
490sub update_labels { 674sub update_labels {
491 my ($self) = @_; 675 my ($self) = @_;
492 676
579 $label->set_text (""); 763 $label->set_text ("");
580 $label->set_tooltip (""); 764 $label->set_tooltip ("");
581 } 765 }
582 766
583 $self->update; 767 $self->update;
584 ###
585} 768}
586 769
587sub _draw { 770sub _draw {
588 my ($self) = @_; 771 my ($self) = @_;
589 772
590 # hack 773 # hack
591 local $CFClient::UI::FOCUS = $self->{entry}; 774 local $CFPlus::UI::FOCUS = $self->{entry};
592 775
593 $self->SUPER::_draw; 776 $self->SUPER::_draw;
594} 777}
595 778
5961 7791

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines