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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines