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.82 by root, Fri Sep 29 00:56:06 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
63sub button_down { 64sub invoke_button_down {
64 my ($self, $ev, $x, $y) = @_; 65 my ($self, $ev, $x, $y) = @_;
65 66
66 return unless $::CONN;
67
68 $self->focus_in;
69
70 if ($ev->{button} == 1) { 67 if ($ev->{button} == 1) {
68 $self->grab_focus;
69 return unless $::CONN;
70
71 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 71 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}; 72 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
73 73
74 $x -= int 0.5 * $self->{sw}; 74 $x -= int 0.5 * $self->{sw};
75 $y -= int 0.5 * $self->{sh}; 75 $y -= int 0.5 * $self->{sh};
76 76
77 $::CONN->lookat ($x, $y) 77 $::CONN->lookat ($x, $y)
78 if $::CONN; 78 if $::CONN;
79 79
80 } elsif ($ev->{button} == 2) { 80 } elsif ($ev->{button} == 2) {
81 $self->grab_focus;
82 return unless $::CONN;
83
81 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 84 my ($ox, $oy) = ($ev->{x}, $ev->{y});
82 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 85 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
83 86
84 $self->{motion} = sub { 87 $self->{motion} = sub {
85 my ($ev, $x, $y) = @_; 88 my ($ev, $x, $y) = @_;
89 $::CFG->{map_shift_x} = $bw + $x - $ox; 92 $::CFG->{map_shift_x} = $bw + $x - $ox;
90 $::CFG->{map_shift_y} = $bh + $y - $oy; 93 $::CFG->{map_shift_y} = $bh + $y - $oy;
91 94
92 $self->update; 95 $self->update;
93 }; 96 };
97 } elsif ($ev->{button} == 3) {
98 (new CFPlus::UI::Menu
99 items => [
100 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
101 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
102 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
103 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
104 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
105 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }],
106 ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }],
107 [
108 $::PICKUP_ENABLE->{state}
109 ? "Disable automatic pickup"
110 : "Enable automatic pickup",
111 sub { $::PICKUP_ENABLE->toggle }
112 ],
113 ["Quit",
114 sub {
115 if ($::CONN) {
116 &::open_quit_dialog;
117 } else {
118 exit;
119 }
120 }
121 ],
122 ],
123 )->popup ($ev);
94 } 124 }
95 125
96 1 126 1
97} 127}
98 128
99sub button_up { 129sub invoke_button_up {
100 my ($self, $ev, $x, $y) = @_; 130 my ($self, $ev, $x, $y) = @_;
101 131
102 delete $self->{motion}; 132 delete $self->{motion};
103 133
104 1 134 1
105} 135}
106 136
107sub mouse_motion { 137sub invoke_mouse_motion {
108 my ($self, $ev, $x, $y) = @_; 138 my ($self, $ev, $x, $y) = @_;
109 139
110 if ($self->{motion}) { 140 if ($self->{motion}) {
111 $self->{motion}->($ev, $x, $y); 141 $self->{motion}->($ev, $x, $y);
112 } else { 142 } else {
116 1 146 1
117} 147}
118 148
119sub size_request { 149sub size_request {
120 ( 150 (
121 1 + 32 * int $::WIDTH / 32, 151 32 * CFPlus::ceil $::WIDTH / 32,
122 1 + 32 * int $::HEIGHT / 32, 152 32 * CFPlus::ceil $::HEIGHT / 32,
123 ) 153 )
124} 154}
125 155
126sub update { 156sub update {
127 my ($self) = @_; 157 my ($self) = @_;
129 $self->{need_update} = 1; 159 $self->{need_update} = 1;
130 $self->SUPER::update; 160 $self->SUPER::update;
131} 161}
132 162
133my %DIR = ( 163my %DIR = (
134 CFClient::SDLK_KP8, [1, "north"], 164 CFPlus::SDLK_KP8, [1, "north"],
135 CFClient::SDLK_KP9, [2, "northeast"], 165 CFPlus::SDLK_KP9, [2, "northeast"],
136 CFClient::SDLK_KP6, [3, "east"], 166 CFPlus::SDLK_KP6, [3, "east"],
137 CFClient::SDLK_KP3, [4, "southeast"], 167 CFPlus::SDLK_KP3, [4, "southeast"],
138 CFClient::SDLK_KP2, [5, "south"], 168 CFPlus::SDLK_KP2, [5, "south"],
139 CFClient::SDLK_KP1, [6, "southwest"], 169 CFPlus::SDLK_KP1, [6, "southwest"],
140 CFClient::SDLK_KP4, [7, "west"], 170 CFPlus::SDLK_KP4, [7, "west"],
141 CFClient::SDLK_KP7, [8, "northwest"], 171 CFPlus::SDLK_KP7, [8, "northwest"],
142 172
143 CFClient::SDLK_UP, [1, "north"], 173 CFPlus::SDLK_UP, [1, "north"],
144 CFClient::SDLK_RIGHT, [3, "east"], 174 CFPlus::SDLK_RIGHT, [3, "east"],
145 CFClient::SDLK_DOWN, [5, "south"], 175 CFPlus::SDLK_DOWN, [5, "south"],
146 CFClient::SDLK_LEFT, [7, "west"], 176 CFPlus::SDLK_LEFT, [7, "west"],
147); 177);
148 178
149sub key_down { 179sub invoke_key_down {
150 my ($self, $ev) = @_; 180 my ($self, $ev) = @_;
151
152 return 0 unless $::CONN;
153 181
154 my $mod = $ev->{mod}; 182 my $mod = $ev->{mod};
155 my $sym = $ev->{sym}; 183 my $sym = $ev->{sym};
156 my $uni = $ev->{unicode}; 184 my $uni = $ev->{unicode};
157 185
158 if ($sym == CFClient::SDLK_KP5) { 186 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
187
188 if ($uni == ord "\t") {
189 $::PL_WINDOW->toggle_visibility;
190 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
191 $::HELP_WINDOW->toggle_visibility;
192 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
193 ::toggle_player_page ($::STATS_PAGE);
194 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
195 ::toggle_player_page ($::SKILL_PAGE);
196 } elsif ($sym == CFPlus::SDLK_F4 && !$mod) {
197 ::toggle_player_page ($::SPELL_PAGE);
198 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
199 ::toggle_player_page ($::INVENTORY_PAGE);
200 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
201 $::SETUP_DIALOG->toggle_visibility;
202 } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) {
203 $::BIND_EDITOR->set_binding (undef, undef, [],
204 sub {
205 my ($mod, $sym, $cmds) = @_;
206 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
207 });
208 $::BIND_EDITOR->start;
209 $::BIND_EDITOR->show;
210#TODO: elmex, what was this supposed to do? it currently crashes the client.
211# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
212# $::BIND_EDITOR->stop;
213# $::BIND_EDITOR->ask_for_bind_and_commit;
214# $::BIND_EDITOR->hide;
215 } elsif (!$::CONN) {
216 return 0; # bindings further down need a valid connection
217
218 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
159 $::CONN->user_send ("stay fire"); 219 $::CONN->user_send ("stay fire");
160 } elsif ($uni == ord ",") { 220 } elsif ($uni == ord ",") {
161 $::CONN->user_send ("take"); 221 $::CONN->user_send ("take");
162 } elsif ($uni == ord " ") { 222 } elsif ($uni == ord " ") {
163 $::CONN->user_send ("apply"); 223 $::CONN->user_send ("apply");
224 } elsif ($uni == 13) {
225 $::CONN->user_send ("examine");
164 } elsif ($uni == ord ".") { 226 } elsif ($uni == ord ".") {
165 $::CONN->user_send ($self->{completer}{last_command}) 227 $::CONN->user_send ($self->{completer}{last_command})
166 if exists $self->{completer}{last_command}; 228 if exists $self->{completer}{last_command};
167 } elsif ($uni == ord "\t") { 229 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
168 $::INV_WINDOW->toggle_visibility; 230 $::CONN->user_send ($_) for @$bind_cmd;
169 } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { 231 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
170 $::CONN->user_send ("rotateshoottype +"); 232 $::CONN->user_send ("rotateshoottype +");
171 } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { 233 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
172 $::CONN->user_send ("rotateshoottype -"); 234 $::CONN->user_send ("rotateshoottype -");
173 } elsif ($uni == ord '"') { 235 } elsif ($uni == ord '"') {
174 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 236 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
175 $self->{completer}->show; 237 $self->{completer}->show;
176 } elsif ($uni == ord "'") { 238 } elsif ($uni == ord "'") {
177 $self->{completer}->set_prefix (""); 239 $self->{completer}->set_prefix ("");
178 $self->{completer}->show; 240 $self->{completer}->show;
179 } elsif (exists $DIR{$sym}) { 241 } elsif (exists $DIR{$sym}) {
180 if ($mod & CFClient::KMOD_SHIFT) { 242 if ($mod & CFPlus::KMOD_SHIFT) {
181 $self->{shft}++; 243 $self->{shft}++;
182 if ($DIR{$sym}[0] != $self->{fire_dir}) { 244 if ($DIR{$sym}[0] != $self->{fire_dir}) {
183 $::CONN->user_send ("fire $DIR{$sym}[0]"); 245 $::CONN->user_send ("fire $DIR{$sym}[0]");
184 } 246 }
185 $self->{fire_dir} = $DIR{$sym}[0]; 247 $self->{fire_dir} = $DIR{$sym}[0];
186 } elsif ($mod & CFClient::KMOD_CTRL) { 248 } elsif ($mod & CFPlus::KMOD_CTRL) {
187 $self->{ctrl}++; 249 $self->{ctrl}++;
188 $::CONN->user_send ("run $DIR{$sym}[0]"); 250 $::CONN->user_send ("run $DIR{$sym}[0]");
189 } else { 251 } else {
190 $::CONN->user_send ("$DIR{$sym}[1]"); 252 $::CONN->user_send ("$DIR{$sym}[1]");
191 } 253 }
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')) { 254 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
207 $self->{completer}->key_down ($ev); 255 $self->{completer}->inject_key_down ($ev);
208 $self->{completer}->show; 256 $self->{completer}->show;
209 } else { 257 } else {
210 return 0; 258 return 0;
211 } 259 }
212 260
213 1 261 1
214} 262}
215 263
216sub key_up { 264sub invoke_key_up {
217 my ($self, $ev) = @_; 265 my ($self, $ev) = @_;
218 266
219 my $res = 0; 267 my $res = 0;
220 my $mod = $ev->{mod}; 268 my $mod = $ev->{mod};
221 my $sym = $ev->{sym}; 269 my $sym = $ev->{sym};
222 270
223 if ($::CFG->{shift_fire_stop}) { 271 if ($::CFG->{shift_fire_stop}) {
224 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 272 if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) {
225 $::CONN->user_send ("fire_stop"); 273 $::CONN->user_send ("fire_stop");
226 delete $self->{fire_dir}; 274 delete $self->{fire_dir};
227 $res = 1; 275 $res = 1;
228 } 276 }
229 } else { 277 } else {
230 if (exists $DIR{$sym} && delete $self->{shft}) { 278 if (exists $DIR{$sym} && delete $self->{shft}) {
231 $::CONN->user_send ("fire_stop"); 279 $::CONN->user_send ("fire_stop");
232 delete $self->{fire_dir}; 280 delete $self->{fire_dir};
233 $res = 1; 281 $res = 1;
234 } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? 282 } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
235 $::CONN->user_send ("fire_stop"); 283 $::CONN->user_send ("fire_stop");
236 delete $self->{fire_dir}; 284 delete $self->{fire_dir};
237 $res = 1; 285 $res = 1;
238 } 286 }
239 } 287 }
240 288
241 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 289 if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) {
242 $::CONN->user_send ("run_stop"); 290 $::CONN->user_send ("run_stop");
243 $res = 1; 291 $res = 1;
244 } 292 }
245 293
246 $res 294 $res
247} 295}
248 296
297sub set_magicmap {
298 my ($self, $w, $h, $x, $y, $data) = @_;
299
300 $x -= $::MAP->ox + int 0.5 * $::MAP->w;
301 $y -= $::MAP->oy + int 0.5 * $::MAP->h;
302
303 $self->{magicmap} = [$x, $y, $w, $h, $data];
304
305 $self->update;
306}
307
249sub draw { 308sub draw {
250 my ($self) = @_; 309 my ($self) = @_;
251 310
252 return unless $::MAP; 311 return unless $::MAP;
253 312
254 my $focused = $CFClient::UI::FOCUS == $self 313 my $focused = $CFPlus::UI::FOCUS == $self
255 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 314 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
256 315
257 return 316 return
258 unless $focused || !$::FAST; 317 unless $focused || !$::FAST;
259 318
260 if (delete $self->{need_update}) { 319 if (delete $self->{need_update}) {
261 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 320 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
262 321
263 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize; 322 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
264 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; 323 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
265 324
266 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 325 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
267 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 326 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
268 327
269 my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize; 328 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
270 my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize; 329 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
271 330
272 if ($::CFG->{fow_enable}) { 331 if ($::CFG->{fow_enable}) {
273 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 332 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
274 333
275 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 334 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); 335 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
277 glConvolutionFilter2D ( 336 glConvolutionFilter2D (
278 GL_CONVOLUTION_2D, 337 GL_CONVOLUTION_2D,
279 GL_ALPHA, 338 GL_ALPHA,
280 3, 3, 339 3, 3,
282 (pack "f*", @{ $self->{smooth_matrix} }), 341 (pack "f*", @{ $self->{smooth_matrix} }),
283 ); 342 );
284 glEnable GL_CONVOLUTION_2D; 343 glEnable GL_CONVOLUTION_2D;
285 } 344 }
286 345
287 $self->{fow_texture} = new CFClient::Texture 346 $self->{fow_texture} = new CFPlus::Texture
288 w => $w, 347 w => $w,
289 h => $h, 348 h => $h,
290 data => $data, 349 data => $data,
291 internalformat => GL_ALPHA, 350 internalformat => GL_ALPHA,
292 format => GL_ALPHA; 351 format => GL_ALPHA;
302 glTranslate $sx0, $sy0; 361 glTranslate $sx0, $sy0;
303 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 362 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
304 363
305 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 364 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
306 365
366 glScale 32, 32;
367
307 if (my $tex = $self->{fow_texture}) { 368 if (my $tex = $self->{fow_texture}) {
308 glEnable GL_TEXTURE_2D; 369 glEnable GL_TEXTURE_2D;
309 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 370 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
310 371
311 glScale 32, 32;
312 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 372 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
313 $self->{fow_texture}->draw_quad_alpha (0, 0); 373 $self->{fow_texture}->draw_quad_alpha (0, 0);
314 374
315 glDisable GL_TEXTURE_2D; 375 glDisable GL_TEXTURE_2D;
316 } 376 }
317 377
378 if ($self->{magicmap}) {
379 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
380
381 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1);
382 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1);
383
384 glTranslate - $x - 1, - $y - 1;
385 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
386 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
387 }
388
318 glPopMatrix; 389 glPopMatrix;
319
320 glEndList; 390 glEndList;
321 } 391 }
322 392
323 glPushMatrix;
324 glCallList $self->{list}; 393 glCallList $self->{list};
325 glPopMatrix;
326 394
327 # TNT2 emulates logops in software (or worse :) 395 # TNT2 emulates logops in software (or worse :)
328 unless ($focused) { 396 unless ($focused) {
329 glColor 0.4, 0.2, 0.2, 0.6; 397 glColor 0.4, 0.2, 0.2, 0.6;
330 glEnable GL_BLEND; 398 glEnable GL_BLEND;
345 glDeleteList $self->{list}; 413 glDeleteList $self->{list};
346 414
347 $self->SUPER::DESTROY; 415 $self->SUPER::DESTROY;
348} 416}
349 417
350package CFClient::MapWidget::MapMap; 418package CFPlus::MapWidget::MapMap;
351 419
352our @ISA = CFClient::UI::Base::; 420our @ISA = CFPlus::UI::Base::;
353 421
354use Time::HiRes qw(time); 422use Time::HiRes qw(time);
355use CFClient::OpenGL; 423use CFPlus::OpenGL;
356 424
357sub size_request { 425sub size_request {
358 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 426 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
359} 427}
360 428
361sub size_allocate { 429sub invoke_size_allocate {
362 my ($self, $w, $h) = @_; 430 my ($self, $w, $h) = @_;
363 431
364 $self->SUPER::size_allocate ($w, $h);
365 $self->update; 432 $self->update;
433
434 1
366} 435}
367 436
368sub update { 437sub update {
369 my ($self) = @_; 438 my ($self) = @_;
370 439
395 464
396 if ($self->{texture_atime} < time) { 465 if ($self->{texture_atime} < time) {
397 $self->{texture_atime} = time + 1/3; 466 $self->{texture_atime} = time + 1/3;
398 467
399 $self->{texture} = 468 $self->{texture} =
400 new CFClient::Texture 469 new CFPlus::Texture
401 w => $w, 470 w => $w,
402 h => $h, 471 h => $h,
403 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 472 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; 473 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
405 } 474 }
406 475
407 $self->{texture}->draw_quad (0, 0); 476 $self->{texture}->draw_quad (0, 0);
408 477
409 glDisable GL_TEXTURE_2D; 478 glDisable GL_TEXTURE_2D;
424 glEnd; 493 glEnd;
425 494
426 glDisable GL_BLEND; 495 glDisable GL_BLEND;
427} 496}
428 497
429package CFClient::MapWidget::Command; 498package CFPlus::MapWidget::Command;
430 499
431use strict; 500use strict;
432 501
433use CFClient::OpenGL; 502use CFPlus::OpenGL;
434 503
435our @ISA = CFClient::UI::Frame::; 504our @ISA = CFPlus::UI::Frame::;
436 505
437sub new { 506sub new {
438 my $class = shift; 507 my $class = shift;
439 508
440 my $self = $class->SUPER::new ( 509 my $self = $class->SUPER::new (
441 bg => [0, 0, 0, 0.8], 510 bg => [0, 0, 0, 0.8],
442 @_, 511 @_,
443 ); 512 );
444 513
445 $self->add ($self->{vbox} = new CFClient::UI::VBox); 514 $self->add ($self->{vbox} = new CFPlus::UI::VBox);
446 515
447 $self->{label} = [ 516 $self->{label} = [
448 map 517 map
449 CFClient::UI::Label->new ( 518 CFPlus::UI::Label->new (
450 can_hover => 1, 519 can_hover => 1,
451 can_events => 1, 520 can_events => 1,
452 tooltip_width => 0.33, 521 tooltip_width => 0.33,
453 fontsize => $_, 522 fontsize => $_,
454 ), (0.8) x 16 523 ), (0.8) x 16
455 ]; 524 ];
456 525
457 $self->{entry} = new CFClient::UI::Entry 526 $self->{entry} = new CFPlus::UI::Entry
458 on_changed => sub { 527 on_changed => sub {
459 $self->update_labels; 528 $self->update_labels;
529 0
460 }, 530 },
461 on_button_down => sub { 531 on_button_down => sub {
462 my ($entry, $ev, $x, $y) = @_; 532 my ($entry, $ev, $x, $y) = @_;
463 533
464 if ($ev->{button} == 3) { 534 if ($ev->{button} == 3) {
465 (new CFClient::UI::Menu 535 (new CFPlus::UI::Menu
466 items => [ 536 items => [
537 ["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 }) }] 538 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
468 ], 539 ],
469 )->popup ($ev); 540 )->popup ($ev);
470 return 1; 541 return 1;
471 } 542 }
472 0 543 0
479 if ($ev->{sym} == 13) { 550 if ($ev->{sym} == 13) {
480 if (exists $self->{select}) { 551 if (exists $self->{select}) {
481 $self->{last_command} = $self->{select}; 552 $self->{last_command} = $self->{select};
482 $::CONN->user_send ($self->{select}); 553 $::CONN->user_send ($self->{select});
483 554
484 unshift @{$self->{history}}, $self->{select}; 555 unshift @{$self->{history}}, $self->{entry}->get_text;
485 $self->{hist_ptr} = 0; 556 $self->{hist_ptr} = 0;
486 557
487 $self->hide; 558 $self->hide;
488 } 559 }
489 } elsif ($ev->{sym} == 27) { 560 } elsif ($ev->{sym} == 27) {
490 $self->{hist_ptr} = 0; 561 $self->{hist_ptr} = 0;
491 $self->hide; 562 $self->hide;
492 return;
493 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 563 } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) {
494 if ($self->{hist_ptr} > 1) { 564 if ($self->{hist_ptr} > 1) {
495 $self->{hist_ptr}--; 565 $self->{hist_ptr}--;
496 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 566 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
497 } elsif ($self->{hist_ptr} > 0) { 567 } elsif ($self->{hist_ptr} > 0) {
498 $self->{hist_ptr}--; 568 $self->{hist_ptr}--;
500 } else { 570 } else {
501 ++$self->{select_offset} 571 ++$self->{select_offset}
502 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 572 if $self->{select_offset} < $#{ $self->{last_match} || [] };
503 } 573 }
504 $self->update_labels; 574 $self->update_labels;
505 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 575 } elsif ($ev->{sym} == CFPlus::SDLK_UP) {
506 if ($self->{select_offset}) { 576 if ($self->{select_offset}) {
507 --$self->{select_offset} 577 --$self->{select_offset}
508 } else { 578 } else {
509 unless ($self->{hist_ptr}) { 579 unless ($self->{hist_ptr}) {
510 $self->{hist_saveback} = $self->{entry}->get_text; 580 $self->{hist_saveback} = $self->{entry}->get_text;
537 607
538 $self->{entry}->set_text ($prefix); 608 $self->{entry}->set_text ($prefix);
539 $self->show; 609 $self->show;
540} 610}
541 611
542sub size_allocate { 612sub invoke_size_allocate {
543 my ($self, $w, $h) = @_; 613 my ($self, $w, $h) = @_;
544 614
545 $self->SUPER::size_allocate ($w, $h);
546 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 615 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
616
617 $self->SUPER::invoke_size_allocate ($w, $h)
547} 618}
548 619
549sub show { 620sub show {
550 my ($self) = @_; 621 my ($self) = @_;
551 622
552 $self->SUPER::show; 623 $self->SUPER::show;
553 $self->{entry}->focus_in; 624 $self->{entry}->grab_focus;
554} 625}
555 626
556sub hide { 627sub hide {
557 my ($self) = @_; 628 my ($self) = @_;
629
630 $self->{hist_ptr} = 0;
558 631
559 $self->SUPER::hide; 632 $self->SUPER::hide;
560 $self->{entry}->set_text (""); 633 $self->{entry}->set_text ("");
561} 634}
562 635
563sub key_down { 636sub inject_key_down {
564 my ($self, $ev) = @_; 637 my ($self, $ev) = @_;
565 638
639 $self->{entry}->grab_focus;
566 $self->{entry}->key_down ($ev) 640 $self->{entry}->emit (key_down => $ev);
567} 641}
568 642
569sub update_labels { 643sub update_labels {
570 my ($self) = @_; 644 my ($self) = @_;
571 645
658 $label->set_text (""); 732 $label->set_text ("");
659 $label->set_tooltip (""); 733 $label->set_tooltip ("");
660 } 734 }
661 735
662 $self->update; 736 $self->update;
663 ###
664} 737}
665 738
666sub _draw { 739sub _draw {
667 my ($self) = @_; 740 my ($self) = @_;
668 741
669 # hack 742 # hack
670 local $CFClient::UI::FOCUS = $self->{entry}; 743 local $CFPlus::UI::FOCUS = $self->{entry};
671 744
672 $self->SUPER::_draw; 745 $self->SUPER::_draw;
673} 746}
674 747
6751 7481

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines