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.37 by root, Thu May 25 01:26:53 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
39 my ($self, $command, $tooltip, $widget, $cb) = @_; 44 my ($self, $command, $tooltip, $widget, $cb) = @_;
40 45
41 (my $data = $command) =~ s/\\//g; 46 (my $data = $command) =~ s/\\//g;
42 47
43 $tooltip =~ s/^\s+//; 48 $tooltip =~ s/^\s+//;
44
45 $tooltip = "<big>$data</big>\n\n$tooltip"; 49 $tooltip = "<big>$data</big>\n\n$tooltip";
46
47 $tooltip =~ s/\s+$//; 50 $tooltip =~ s/\s+$//;
48 51
49 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; 52 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
50} 53}
51 54
52sub clr_commands { 55sub clr_commands {
53 my ($self) = @_; 56 my ($self) = @_;
54 57
55 %{$self->{completer}{command}} = (); 58 %{$self->{completer}{command}} = ();
56}
57 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
58sub button_down { 89sub invoke_button_down {
59 my ($self, $ev, $x, $y) = @_; 90 my ($self, $ev, $x, $y) = @_;
60 91
61 $self->focus_in;
62
63 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
64 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 109 my ($ox, $oy) = ($ev->{x}, $ev->{y});
65 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 110 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
66 111
67 $self->{motion} = sub { 112 $self->{motion} = sub {
68 my ($ev, $x, $y) = @_; 113 my ($ev, $x, $y) = @_;
72 $::CFG->{map_shift_x} = $bw + $x - $ox; 117 $::CFG->{map_shift_x} = $bw + $x - $ox;
73 $::CFG->{map_shift_y} = $bh + $y - $oy; 118 $::CFG->{map_shift_y} = $bh + $y - $oy;
74 119
75 $self->update; 120 $self->update;
76 }; 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
77 } 157 1
78} 158}
79 159
80sub button_up { 160sub invoke_button_up {
81 my ($self, $ev, $x, $y) = @_; 161 my ($self, $ev, $x, $y) = @_;
82 162
83 delete $self->{motion}; 163 delete $self->{motion};
84}
85 164
165 1
166}
167
86sub mouse_motion { 168sub invoke_mouse_motion {
87 my ($self, $ev, $x, $y) = @_; 169 my ($self, $ev, $x, $y) = @_;
88 170
171 if ($self->{motion}) {
89 $self->{motion}->($ev, $x, $y) if $self->{motion}; 172 $self->{motion}->($ev, $x, $y);
173 } else {
174 return 0;
175 }
176
177 1
90} 178}
91 179
92sub size_request { 180sub size_request {
93 ( 181 (
94 1 + 32 * int $::WIDTH / 32, 182 32 * CFPlus::ceil $::WIDTH / 32,
95 1 + 32 * int $::HEIGHT / 32, 183 32 * CFPlus::ceil $::HEIGHT / 32,
96 ) 184 )
97} 185}
98 186
99sub update { 187sub update {
100 my ($self) = @_; 188 my ($self) = @_;
102 $self->{need_update} = 1; 190 $self->{need_update} = 1;
103 $self->SUPER::update; 191 $self->SUPER::update;
104} 192}
105 193
106my %DIR = ( 194my %DIR = (
107 CFClient::SDLK_KP8, [1, "north"], 195 CFPlus::SDLK_KP8, [1, "north"],
108 CFClient::SDLK_KP9, [2, "northeast"], 196 CFPlus::SDLK_KP9, [2, "northeast"],
109 CFClient::SDLK_KP6, [3, "east"], 197 CFPlus::SDLK_KP6, [3, "east"],
110 CFClient::SDLK_KP3, [4, "southeast"], 198 CFPlus::SDLK_KP3, [4, "southeast"],
111 CFClient::SDLK_KP2, [5, "south"], 199 CFPlus::SDLK_KP2, [5, "south"],
112 CFClient::SDLK_KP1, [6, "southwest"], 200 CFPlus::SDLK_KP1, [6, "southwest"],
113 CFClient::SDLK_KP4, [7, "west"], 201 CFPlus::SDLK_KP4, [7, "west"],
114 CFClient::SDLK_KP7, [8, "northwest"], 202 CFPlus::SDLK_KP7, [8, "northwest"],
115 203
116 CFClient::SDLK_UP, [1, "north"], 204 CFPlus::SDLK_UP, [1, "north"],
117 CFClient::SDLK_RIGHT, [3, "east"], 205 CFPlus::SDLK_RIGHT, [3, "east"],
118 CFClient::SDLK_DOWN, [5, "south"], 206 CFPlus::SDLK_DOWN, [5, "south"],
119 CFClient::SDLK_LEFT, [7, "west"], 207 CFPlus::SDLK_LEFT, [7, "west"],
120); 208);
121 209
122sub key_down { 210sub invoke_key_down {
123 my ($self, $ev) = @_; 211 my ($self, $ev) = @_;
124
125 return unless $::CONN;
126 212
127 my $mod = $ev->{mod}; 213 my $mod = $ev->{mod};
128 my $sym = $ev->{sym}; 214 my $sym = $ev->{sym};
129 my $uni = $ev->{unicode}; 215 my $uni = $ev->{unicode};
130 216
131 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) {
132 $::CONN->user_send ("stay fire"); 250 $::CONN->user_send ("stay fire");
133 } elsif ($uni == ord ",") { 251 } elsif ($uni == ord ",") {
134 $::CONN->user_send ("take"); 252 $::CONN->user_send ("take");
135 } elsif ($uni == ord " ") { 253 } elsif ($uni == ord " ") {
136 $::CONN->user_send ("apply"); 254 $::CONN->user_send ("apply");
255 } elsif ($uni == 13) {
256 $::CONN->user_send ("examine");
137 } elsif ($uni == ord ".") { 257 } elsif ($uni == ord ".") {
138 $::CONN->user_send ($self->{completer}{last_command}) 258 $::CONN->user_send ($self->{completer}{last_command})
139 if exists $self->{completer}{last_command}; 259 if exists $self->{completer}{last_command};
140 } elsif ($uni == ord "\t") { 260 } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) {
141 # TODO: toggle inventory 261 $::CONN->user_send ($_) for @$bind_cmd;
142 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 262 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
143 $::CONN->user_send ("rotateshoottype +"); 263 $::CONN->user_send ("rotateshoottype +");
144 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 264 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
145 $::CONN->user_send ("rotateshoottype -"); 265 $::CONN->user_send ("rotateshoottype -");
146 } elsif ($uni == ord '"') { 266 } elsif ($uni == ord '"') {
147 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 267 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
148 $self->{completer}->show; 268 $self->{completer}->show;
149 } elsif ($uni == ord "'") { 269 } elsif ($uni == ord "'") {
150 $self->{completer}->set_prefix (""); 270 $self->{completer}->set_prefix ("");
151 $self->{completer}->show; 271 $self->{completer}->show;
152 } elsif (exists $DIR{$sym}) { 272 } elsif (exists $DIR{$sym}) {
153 if ($mod & CFClient::KMOD_SHIFT) { 273 if ($mod & CFPlus::KMOD_SHIFT) {
154 $self->{shft}++; 274 $self->{shft}++;
275 if ($DIR{$sym}[0] != $self->{fire_dir}) {
155 $::CONN->user_send ("fire $DIR{$sym}[0]"); 276 $::CONN->user_send ("fire $DIR{$sym}[0]");
277 }
278 $self->{fire_dir} = $DIR{$sym}[0];
156 } elsif ($mod & CFClient::KMOD_CTRL) { 279 } elsif ($mod & CFPlus::KMOD_CTRL) {
157 $self->{ctrl}++; 280 $self->{ctrl}++;
158 $::CONN->user_send ("run $DIR{$sym}[0]"); 281 $::CONN->user_send ("run $DIR{$sym}[0]");
159 } else { 282 } else {
160 $::CONN->user_send ("$DIR{$sym}[1]"); 283 $::CONN->user_send ("$DIR{$sym}[1]");
161 } 284 }
162 } elsif ($ev->{unicode}) { 285 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
163 $self->{completer}->key_down ($ev); 286 $self->{completer}->inject_key_down ($ev);
164 $self->{completer}->show; 287 $self->{completer}->show;
288 } else {
289 return 0;
290 }
291
165 } 292 1
166} 293}
167 294
168sub key_up { 295sub invoke_key_up {
169 my ($self, $ev) = @_; 296 my ($self, $ev) = @_;
170 297
298 my $res = 0;
171 my $mod = $ev->{mod}; 299 my $mod = $ev->{mod};
172 my $sym = $ev->{sym}; 300 my $sym = $ev->{sym};
173 301
302 if ($::CFG->{shift_fire_stop}) {
174 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 303 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) {
175 $::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 }
176 } 318 }
319
177 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 320 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) {
178 $::CONN->user_send ("run_stop"); 321 $::CONN->user_send ("run_stop");
322 $res = 1;
179 } 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;
180} 337}
181 338
182sub draw { 339sub draw {
183 my ($self) = @_; 340 my ($self) = @_;
184 341
342 return unless $::MAP;
343
185 my $focused = $CFClient::UI::FOCUS == $self 344 my $focused = $CFPlus::UI::FOCUS == $self
186 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 345 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
187 346
188 return 347 return
189 unless $focused || !$::FAST; 348 unless $focused || !$::FAST;
190 349
191 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
192 glNewList $self->{list}; 389 glNewList $self->{list};
193 390
194 if ($::MAP) {
195 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
196 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
197
198 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
199 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
200
201 glPushMatrix; 391 glPushMatrix;
392 glTranslate $sx0, $sy0;
202 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 393 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
203 394
204 glTranslate $sx0 - 32, $sy0 - 32, 0; 395 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
205 396
206 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 397 glScale 32, 32;
207 398
208 if ($::CFG->{fow_enable}) { 399 if (my $tex = $self->{fow_texture}) {
209 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war
210 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
211 glConvolutionFilter2D (
212 GL_CONVOLUTION_2D,
213 GL_ALPHA,
214 3, 3,
215 GL_ALPHA, GL_FLOAT,
216 pack "f*",
217 0.05, 0.13, 0.05,
218 0.13, 0.30, 0.13,
219 0.05, 0.13, 0.05,
220 );
221 glEnable GL_CONVOLUTION_2D;
222 }
223
224 $self->{fow_texture_name} ||= glGenTexture;
225 # try to re-use the texture name: TODO improve texture class instead
226
227 $self->{fow_texture} = new CFClient::Texture
228 w => $w,
229 h => $h,
230 data => $data,
231 name => $self->{fow_texture_name},
232 internalformat => GL_ALPHA,
233 format => GL_ALPHA;
234
235 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
236
237 glEnable GL_TEXTURE_2D; 400 glEnable GL_TEXTURE_2D;
238 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 401 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
239 402
240 glColor +($::CFG->{fow_intensity}) x 3, 0.8; 403 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
241 $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); 404 $self->{fow_texture}->draw_quad_alpha (0, 0);
242 405
243 glDisable GL_TEXTURE_2D; 406 glDisable GL_TEXTURE_2D;
244 } 407 }
245 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
246 glPopMatrix; 420 glPopMatrix;
247 }
248
249 glEndList; 421 glEndList;
250 } 422 }
251 423
252 glPushMatrix;
253 glCallList $self->{list}; 424 glCallList $self->{list};
254 glPopMatrix;
255 425
256 # TNT2 emulates logops in software (or worse :) 426 # TNT2 emulates logops in software (or worse :)
257 if ($focused) { 427 unless ($focused) {
258 (delete $self->{out_of_focus})->destroy
259 if $self->{out_of_focus};
260 } else {
261 glColor 0.4, 0.2, 0.2, 0.6; 428 glColor 0.4, 0.2, 0.2, 0.6;
262 glEnable GL_BLEND; 429 glEnable GL_BLEND;
263 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 430 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
264 glBegin GL_QUADS; 431 glBegin GL_QUADS;
265 glVertex 0, 0; 432 glVertex 0, 0;
266 glVertex 0, $::HEIGHT; 433 glVertex 0, $::HEIGHT;
267 glVertex $::WIDTH, $::HEIGHT; 434 glVertex $::WIDTH, $::HEIGHT;
268 glVertex $::WIDTH, 0; 435 glVertex $::WIDTH, 0;
269 glEnd; 436 glEnd;
270 glDisable GL_BLEND; 437 glDisable GL_BLEND;
271
272 $self->{out_of_focus} ||= do {
273 my $label = new CFClient::UI::Label
274 x => 0,
275 y => 0,
276 z => 1,
277 ellipsise => 0,
278 text => "map out of focus (click map to play)";
279
280 $label->show;
281 $label->update;
282
283 $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
284 $label->move (
285 ($::WIDTH - $label->{w}) * 0.5,
286 ($::HEIGHT - $label->{h}) * 0.5,
287 );
288 });
289
290 $label
291 };
292 } 438 }
293} 439}
294 440
295sub DESTROY { 441sub DESTROY {
296 my $self = shift; 442 my $self = shift;
298 glDeleteList $self->{list}; 444 glDeleteList $self->{list};
299 445
300 $self->SUPER::DESTROY; 446 $self->SUPER::DESTROY;
301} 447}
302 448
303package CFClient::MapWidget::MapMap; 449package CFPlus::MapWidget::MapMap;
304 450
305our @ISA = CFClient::UI::Base::; 451our @ISA = CFPlus::UI::Base::;
306 452
307use Time::HiRes qw(time); 453use Time::HiRes qw(time);
308use CFClient::OpenGL; 454use CFPlus::OpenGL;
309 455
310sub size_request { 456sub size_request {
311 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 457 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
312} 458}
313 459
314sub size_allocate { 460sub invoke_size_allocate {
315 my ($self, $w, $h) = @_; 461 my ($self, $w, $h) = @_;
316 462
317 $self->SUPER::size_allocate ($w, $h);
318 $self->update; 463 $self->update;
464
465 1
319} 466}
320 467
321sub update { 468sub update {
322 my ($self) = @_; 469 my ($self) = @_;
323 470
348 495
349 if ($self->{texture_atime} < time) { 496 if ($self->{texture_atime} < time) {
350 $self->{texture_atime} = time + 1/3; 497 $self->{texture_atime} = time + 1/3;
351 498
352 $self->{texture} = 499 $self->{texture} =
353 new CFClient::Texture 500 new CFPlus::Texture
354 w => $w, 501 w => $w,
355 h => $h, 502 h => $h,
356 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 503 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
357 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;
358 } 505 }
359 506
360 $self->{texture}->draw_quad (0, 0); 507 $self->{texture}->draw_quad (0, 0);
361 508
362 glDisable GL_TEXTURE_2D; 509 glDisable GL_TEXTURE_2D;
377 glEnd; 524 glEnd;
378 525
379 glDisable GL_BLEND; 526 glDisable GL_BLEND;
380} 527}
381 528
382package CFClient::MapWidget::Command; 529package CFPlus::MapWidget::Command;
383 530
384use strict; 531use strict;
385 532
386use CFClient::OpenGL; 533use CFPlus::OpenGL;
387 534
388our @ISA = CFClient::UI::Frame::; 535our @ISA = CFPlus::UI::Frame::;
389 536
390sub new { 537sub new {
391 my $class = shift; 538 my $class = shift;
392 539
393 my $self = $class->SUPER::new ( 540 my $self = $class->SUPER::new (
394 bg => [0, 0, 0, 0.8], 541 bg => [0, 0, 0, 0.8],
395 @_, 542 @_,
396 ); 543 );
397 544
398 $self->add ($self->{vbox} = new CFClient::UI::VBox); 545 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
399 546
400 $self->{label} = [ 547 $self->{label} = [
401 map 548 map
402 CFClient::UI::Label->new ( 549 CFPlus::UI::Label->new (
403 can_hover => 1, 550 can_hover => 1,
404 can_events => 1, 551 can_events => 1,
405 tooltip_width => 0.33, 552 tooltip_width => 0.33,
406 fontsize => $_, 553 fontsize => $_,
407 ), (0.8) x 16 554 ), (0.8) x 16
408 ]; 555 ];
409 556
410 $self->{entry} = new CFClient::UI::Entry 557 $self->{entry} = new CFPlus::UI::Entry
411 connect_changed => sub { 558 on_changed => sub {
412 $self->update_labels; 559 $self->update_labels;
560 0
413 }, 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
575 },
414 connect_key_down => sub { 576 on_key_down => sub {
415 my ($entry, $ev) = @_; 577 my ($entry, $ev) = @_;
416 578
417 my $self = $entry->{parent}{parent}; 579 my $self = $entry->{parent}{parent};
418 580
419 if ($ev->{sym} == 13) { 581 if ($ev->{sym} == 13) {
420 if (exists $self->{select}) { 582 if (exists $self->{select}) {
421 $self->{last_command} = $self->{select}; 583 $self->{last_command} = $self->{select};
422 $::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
423 $self->hide; 589 $self->hide;
424 } 590 }
425 } elsif ($ev->{sym} == 27) { 591 } elsif ($ev->{sym} == 27) {
592 $self->{hist_ptr} = 0;
426 $self->hide; 593 $self->hide;
427 return;
428 } 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 {
429 ++$self->{select_offset} 602 ++$self->{select_offset}
430 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 603 if $self->{select_offset} < $#{ $self->{last_match} || [] };
604 }
431 $self->update_labels; 605 $self->update_labels;
432 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 606 } elsif ($ev->{sym} == CFPlus::SDLK_UP) {
607 if ($self->{select_offset}) {
433 --$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}}) {
434 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 }
435 $self->update_labels; 619 $self->update_labels;
436 } else { 620 } else {
437 return 0; 621 return 0;
438 } 622 }
439 623
454 638
455 $self->{entry}->set_text ($prefix); 639 $self->{entry}->set_text ($prefix);
456 $self->show; 640 $self->show;
457} 641}
458 642
459sub size_allocate { 643sub invoke_size_allocate {
460 my ($self, $w, $h) = @_; 644 my ($self, $w, $h) = @_;
461 645
462 $self->SUPER::size_allocate ($w, $h);
463 $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)
464} 649}
465 650
466sub show { 651sub show {
467 my ($self) = @_; 652 my ($self) = @_;
468 653
469 $self->SUPER::show; 654 $self->SUPER::show;
470 $self->{entry}->focus_in; 655 $self->{entry}->grab_focus;
471} 656}
472 657
473sub hide { 658sub hide {
474 my ($self) = @_; 659 my ($self) = @_;
660
661 $self->{hist_ptr} = 0;
475 662
476 $self->SUPER::hide; 663 $self->SUPER::hide;
477 $self->{entry}->set_text (""); 664 $self->{entry}->set_text ("");
478} 665}
479 666
480sub key_down { 667sub inject_key_down {
481 my ($self, $ev) = @_; 668 my ($self, $ev) = @_;
482 669
670 $self->{entry}->grab_focus;
483 $self->{entry}->key_down ($ev); 671 $self->{entry}->emit (key_down => $ev);
484} 672}
485 673
486sub update_labels { 674sub update_labels {
487 my ($self) = @_; 675 my ($self) = @_;
488 676
521 709
522 @match = map $self->{command}{$_->[0]}, 710 @match = map $self->{command}{$_->[0]},
523 sort { 711 sort {
524 $a->[1] <=> $b->[1] 712 $a->[1] <=> $b->[1]
525 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 713 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
526 or (length $a->[0]) <=> (length $b->[0]) 714 or (length $b->[0]) <=> (length $a->[0])
527 } @match; 715 } @match;
528 } 716 }
529 717
530 $self->{last_search} = $cmd; 718 $self->{last_search} = $text;
531 $self->{last_match} = \@match; 719 $self->{last_match} = \@match;
532 720
533 $self->{select_offset} = 0; 721 $self->{select_offset} = 0;
534 } 722 }
535 723
575 $label->set_text (""); 763 $label->set_text ("");
576 $label->set_tooltip (""); 764 $label->set_tooltip ("");
577 } 765 }
578 766
579 $self->update; 767 $self->update;
580 ###
581} 768}
582 769
583sub _draw { 770sub _draw {
584 my ($self) = @_; 771 my ($self) = @_;
585 772
586 # hack 773 # hack
587 local $CFClient::UI::FOCUS = $self->{entry}; 774 local $CFPlus::UI::FOCUS = $self->{entry};
588 775
589 $self->SUPER::_draw; 776 $self->SUPER::_draw;
590} 777}
591 778
5921 7791

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines