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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines