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.4 by root, Wed Apr 19 23:37:49 2006 UTC vs.
Revision 1.8 by root, Sat Apr 22 21:47:45 2006 UTC

25 glDeleteList $self->{list}; 25 glDeleteList $self->{list};
26 26
27 $self->SUPER::DESTROY; 27 $self->SUPER::DESTROY;
28} 28}
29 29
30sub key_down {
31 print "MAPKEYDOWN\n";
32}
33
34sub key_up {
35}
36
37sub button_down { 30sub button_down {
38 my ($self, $ev, $x, $y) = @_; 31 my ($self, $ev, $x, $y) = @_;
39 32
40 $self->focus_in; 33 $self->focus_in;
41 34
42 if ($ev->button == 2) { 35 if ($ev->{button} == 2) {
43 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 36 my ($ox, $oy) = ($ev->{x}, $ev->{y});
44 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 37 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
45 38
46 $self->{motion} = sub { 39 $self->{motion} = sub {
47 my ($ev, $x, $y) = @_; 40 my ($ev, $x, $y) = @_;
48 41
49 ($x, $y) = ($ev->motion_x, $ev->motion_y); 42 ($x, $y) = ($ev->{x}, $ev->{y});
50 43
51 $::CFG->{map_shift_x} = $bw + $x - $ox; 44 $::CFG->{map_shift_x} = $bw + $x - $ox;
52 $::CFG->{map_shift_y} = $bh + $y - $oy; 45 $::CFG->{map_shift_y} = $bh + $y - $oy;
53 46
54 $self->update; 47 $self->update;
106 GL_CONVOLUTION_2D, 99 GL_CONVOLUTION_2D,
107 GL_ALPHA, 100 GL_ALPHA,
108 3, 3, 101 3, 3,
109 GL_ALPHA, GL_FLOAT, 102 GL_ALPHA, GL_FLOAT,
110 pack "f*", 103 pack "f*",
111 0.1, 0.1, 0.1, 104 0.05, 0.13, 0.05,
112 0.1, 0.2, 0.1, 105 0.13, 0.30, 0.13,
113 0.1, 0.1, 0.1, 106 0.05, 0.13, 0.05,
114 ); 107 );
115 glEnable GL_CONVOLUTION_2D; 108 glEnable GL_CONVOLUTION_2D;
116 } 109 }
117 110
118 $self->{fow_texture} = new CFClient::Texture 111 $self->{fow_texture} = new CFClient::Texture
127 glEnable GL_BLEND; 120 glEnable GL_BLEND;
128 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 121 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
129 glEnable GL_TEXTURE_2D; 122 glEnable GL_TEXTURE_2D;
130 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 123 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
131 124
132 glColor +($::CFG->{fow_intensity}) x 3, 1; 125 glColor +($::CFG->{fow_intensity}) x 3, 0.8;
133 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); 126 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
134 127
135 glDisable GL_TEXTURE_2D; 128 glDisable GL_TEXTURE_2D;
136 glDisable GL_BLEND; 129 glDisable GL_BLEND;
137 } 130 }
138 131
139 # HACK BEGIN 132 # HACK BEGIN
140 { 133 {
141 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove 134 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
135
136 glTranslate 0, 30;
142 my ($w, $h) = (250, 250); 137 my ($w, $h) = (250, 250);
138
139 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
143 140
144 glEnable GL_BLEND; 141 glEnable GL_BLEND;
145 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 142 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
146 glEnable GL_TEXTURE_2D; 143 glEnable GL_TEXTURE_2D;
147 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 144 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
148 145
149 $self->{mapmap_texture} = 146 $self->{mapmap_texture} =
150 new CFClient::Texture 147 new CFClient::Texture
151 w => $w, 148 w => $w,
152 h => $h, 149 h => $h,
153 data => $::MAP->mapmap ($w, $h), 150 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
154 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; 151 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
155 152
156 $self->{mapmap_texture}->draw_quad (100, 100); 153 $self->{mapmap_texture}->draw_quad (0, 0);
157 154
158 glDisable GL_TEXTURE_2D; 155 glDisable GL_TEXTURE_2D;
156
157 glTranslate 0.375, 0.375;
158
159 glColor 1, 1, 0, 1;
160 glBegin GL_LINE_LOOP;
161 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ;
162 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh;
163 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh;
164 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ;
165 glEnd;
166
159 glDisable GL_BLEND; 167 glDisable GL_BLEND;
160 } 168 }
161 # HACK END 169 # HACK END
162 } 170 }
163 171
199); 207);
200 208
201sub key_down { 209sub key_down {
202 my ($self, $ev) = @_; 210 my ($self, $ev) = @_;
203 211
204 my $mod = $ev->key_mod; 212 my $mod = $ev->{mod};
205 my $sym = $ev->key_sym; 213 my $sym = $ev->{sym};
206 214
207 if ($sym == CFClient::SDLK_KP5) { 215 if ($sym == CFClient::SDLK_KP5) {
208 $::CONN->user_send ("stay fire"); 216 $::CONN->user_send ("stay fire");
209 } elsif ($sym == ord "a") { 217 } elsif ($sym == ord "a") {
210 $::CONN->user_send ("apply"); 218 $::CONN->user_send ("apply");
211 } elsif ($sym == ord "'") { 219 } elsif ($sym == ord "'") {
212 $self->emit ('activate_console'); 220 $self->emit ('activate_console');
213 } elsif ($sym == ord "/") { 221 } elsif ($sym == ord "/") {
214 $self->emit ('activate_console' => '/'); 222 $self->emit (activate_console => '/');
215 } elsif (exists $DIR{$sym}) { 223 } elsif (exists $DIR{$sym}) {
216 if ($mod & CFClient::KMOD_SHIFT) { 224 if ($mod & CFClient::KMOD_SHIFT) {
217 $self->{shft}++; 225 $self->{shft}++;
218 $::CONN->user_send ("fire $DIR{$sym}[0]"); 226 $::CONN->user_send ("fire $DIR{$sym}[0]");
219 } elsif ($mod & CFClient::KMOD_CTRL) { 227 } elsif ($mod & CFClient::KMOD_CTRL) {
220 $self->{ctrl}++; 228 $self->{ctrl}++;
221 $::CONN->user_send ("run $DIR{$sym}[0]"); 229 $::CONN->user_send ("run $DIR{$sym}[0]");
222 } else { 230 } else {
223 $::CONN->user_send ("$DIR{$sym}[1]"); 231 $::CONN->user_send ("$DIR{$sym}[1]");
224 } 232 }
233 } elsif ($ev->{unicode}) {
234 $self->{command_widget} ||=
235 new CFClient::MapWidget::Command::
236 command => $self->{command},
237 can_focus => 1,
238 connect_execute => sub {
239 $::CONN->user_send ($_[1]);
240 },
241 connect_close => sub {
242 (delete $self->{command_widget})->hide;
243 $self->focus_in;
244 },
245 ;
246 $self->{command_widget}->key_down ($ev);
247 $self->{command_widget}->show;
248 $self->{command_widget}->focus_in;
225 } 249 }
226} 250}
227 251
228sub key_up { 252sub key_up {
229 my ($self, $ev) = @_; 253 my ($self, $ev) = @_;
230 254
231 my $mod = $ev->key_mod; 255 my $mod = $ev->{mod};
232 my $sym = $ev->key_sym; 256 my $sym = $ev->{sym};
233 257
234 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 258 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
235 $::CONN->user_send ("fire_stop"); 259 $::CONN->user_send ("fire_stop");
236 } 260 }
237 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 261 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
241 265
242sub add_command { 266sub add_command {
243 my ($self, $command, $widget, $cb) = @_; 267 my ($self, $command, $widget, $cb) = @_;
244 268
245 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 269 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
270
271 push @{$self->{command}}, [$abbrev, $command];
246 warn "$command|$abbrev|$widget\n";#d# 272 #warn "$command|$abbrev|$widget\n";#d#
273}
274
275package CFClient::MapWidget::Command;
276
277use strict;
278
279use CFClient::OpenGL;
280
281our @ISA = CFClient::UI::VBox::;
282
283sub new {
284 my $class = shift;
285
286 my $self = $class->SUPER::new (
287 @_,
288 children => [map
289 CFClient::UI::Label->new (
290 can_hover => 1,
291 fontsize => $_,
292 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8
293 ],
294 );
295
296 $self
297}
298
299sub size_allocate {
300 my ($self, $w, $h) = @_;
301
302 $self->SUPER::size_allocate ($w, $h);
303 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
304}
305
306sub update_labels {
307 my ($self) = @_;
308
309 my $command = $self->{command};
310 my $search_abbrev = qr/^\Q$self->{search}/;
311 my $search_full = qr/\Q$self->{search}/;
312
313 my @found;
314
315 for (@$command) {
316 if ($_->[0] =~ $search_abbrev) {
317 push @found, [$_->[0], $_];
318 } elsif ($_[1] =~ $search_full) {
319 push @found, [$_->[1], $_];
320 }
321 }
322
323 @found = sort { $a->[0] cmp $b->[0] } @found;
324
325 $self->{children}[0]->set_text ("$self->{search}_");
326
327 for (0..5) {
328 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : "");
329 }
330
331 $self->{select} = $found[0][1][1]
332 if @found;
333
334 if (@found > 6) {
335 $self->{children}[6]->set_text ("...");
336 }
337
338 $self->check_size;
339}
340
341sub key_down {
342 my ($self, $ev) = @_;
343
344 if ($ev->{sym} == 8) {
345 substr $self->{search}, -1, 1, "";
346 $self->update_labels;
347 } elsif ($ev->{sym} == 13) {
348 if (exists $self->{select}) {
349 $self->emit (execute => $self->{select});
350 $self->emit ("close");
351 }
352 } elsif ($ev->{sym} == 27) {
353 $self->emit ("close");
354 } elsif ($ev->{unicode}) {
355 $self->{search} .= chr $ev->{unicode};
356 $self->update_labels;
357 }
247} 358}
248 359
2491 3601

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines