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.3 by root, Wed Apr 19 20:46:44 2006 UTC vs.
Revision 1.12 by root, Mon Apr 24 06:05:35 2006 UTC

2 2
3use strict; 3use strict;
4 4
5use List::Util qw(min max); 5use List::Util qw(min max);
6 6
7use SDL::OpenGL; 7use CFClient::OpenGL;
8 8
9our @ISA = CFClient::UI::Base::; 9our @ISA = CFClient::UI::Base::;
10 10
11sub new { 11sub new {
12 my $class = shift; 12 my $class = shift;
13 13
14 $class->SUPER::new ( 14 $class->SUPER::new (
15 z => -1, 15 z => -1,
16 can_focus => 1, 16 can_focus => 1,
17 list => (glGenLists 1), 17 list => glGenList,
18 @_ 18 @_
19 ) 19 )
20} 20}
21 21
22sub key_down { 22sub DESTROY {
23 print "MAPKEYDOWN\n"; 23 my $self = shift;
24}
25 24
26sub key_up { 25 glDeleteList $self->{list};
26
27 $self->SUPER::DESTROY;
27} 28}
28 29
29sub button_down { 30sub button_down {
30 my ($self, $ev, $x, $y) = @_; 31 my ($self, $ev, $x, $y) = @_;
31 32
32 $self->focus_in; 33 $self->focus_in;
33 34
34 if ($ev->button == 2) { 35 if ($ev->{button} == 2) {
35 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 36 my ($ox, $oy) = ($ev->{x}, $ev->{y});
36 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 37 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
37 38
38 $self->{motion} = sub { 39 $self->{motion} = sub {
39 my ($ev, $x, $y) = @_; 40 my ($ev, $x, $y) = @_;
40 41
41 ($x, $y) = ($ev->motion_x, $ev->motion_y); 42 ($x, $y) = ($ev->{x}, $ev->{y});
42 43
43 $::CFG->{map_shift_x} = $bw + $x - $ox; 44 $::CFG->{map_shift_x} = $bw + $x - $ox;
44 $::CFG->{map_shift_y} = $bh + $y - $oy; 45 $::CFG->{map_shift_y} = $bh + $y - $oy;
45 46
46 $self->update; 47 $self->update;
76 77
77sub draw { 78sub draw {
78 my ($self) = @_; 79 my ($self) = @_;
79 80
80 if (delete $self->{need_update}) { 81 if (delete $self->{need_update}) {
81 glNewList $self->{list}, GL_COMPILE; 82 glNewList $self->{list};
82 83
83 if ($::MAP) { 84 if ($::MAP) {
84 my $sw = int $::WIDTH / 32; 85 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale});
85 my $sh = int $::HEIGHT / 32; 86 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale});
86 87
88 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
89
87 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;
88 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;
89 92
90 glTranslate $sx0 - 32, $sy0 - 32, 0; 93 glTranslate $sx0 - 32, $sy0 - 32, 0;
91 94
92 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);
93 96
98 GL_CONVOLUTION_2D, 101 GL_CONVOLUTION_2D,
99 GL_ALPHA, 102 GL_ALPHA,
100 3, 3, 103 3, 3,
101 GL_ALPHA, GL_FLOAT, 104 GL_ALPHA, GL_FLOAT,
102 pack "f*", 105 pack "f*",
103 0.1, 0.1, 0.1, 106 0.05, 0.13, 0.05,
104 0.1, 0.2, 0.1, 107 0.13, 0.30, 0.13,
105 0.1, 0.1, 0.1, 108 0.05, 0.13, 0.05,
106 ); 109 );
107 glEnable GL_CONVOLUTION_2D; 110 glEnable GL_CONVOLUTION_2D;
108 } 111 }
109 112
110 $self->{fow_texture} = new CFClient::Texture 113 $self->{fow_texture} = new CFClient::Texture
119 glEnable GL_BLEND; 122 glEnable GL_BLEND;
120 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 123 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
121 glEnable GL_TEXTURE_2D; 124 glEnable GL_TEXTURE_2D;
122 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 125 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
123 126
124 glColor +($::CFG->{fow_intensity}) x 3, 1; 127 glColor +($::CFG->{fow_intensity}) x 3, 0.8;
125 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); 128 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
126 129
127 glDisable GL_TEXTURE_2D; 130 glDisable GL_TEXTURE_2D;
128 glDisable GL_BLEND; 131 glDisable GL_BLEND;
129 } 132 }
130 133
131 # HACK BEGIN 134 # HACK BEGIN
132 { 135 {
133 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove 136 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
137
138 glTranslate 0, 30;
134 my ($w, $h) = (250, 250); 139 my ($w, $h) = (250, 250);
140
141 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
135 142
136 glEnable GL_BLEND; 143 glEnable GL_BLEND;
137 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 144 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
138 glEnable GL_TEXTURE_2D; 145 glEnable GL_TEXTURE_2D;
139 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 146 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
140 147
141 $self->{mapmap_texture} = 148 $self->{mapmap_texture} =
142 new CFClient::Texture 149 new CFClient::Texture
143 w => $w, 150 w => $w,
144 h => $h, 151 h => $h,
145 data => $::MAP->mapmap ($w, $h), 152 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
146 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;
147 154
148 $self->{mapmap_texture}->draw_quad (100, 100); 155 $self->{mapmap_texture}->draw_quad (0, 0);
149 156
150 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
151 glDisable GL_BLEND; 169 glDisable GL_BLEND;
152 } 170 }
153 # HACK END 171 # HACK END
154 } 172 }
155 173
191); 209);
192 210
193sub key_down { 211sub key_down {
194 my ($self, $ev) = @_; 212 my ($self, $ev) = @_;
195 213
196 my $mod = $ev->key_mod; 214 my $mod = $ev->{mod};
197 my $sym = $ev->key_sym; 215 my $sym = $ev->{sym};
198 216
199 if ($sym == CFClient::SDLK_KP5) { 217 if ($sym == CFClient::SDLK_KP5) {
200 $::CONN->user_send ("stay fire"); 218 $::CONN->user_send ("stay fire");
201 } elsif ($sym == ord "a") { 219 } elsif ($sym == ord "a") {
202 $::CONN->user_send ("apply"); 220 $::CONN->user_send ("apply");
203 } elsif ($sym == ord "'") { 221 } elsif ($sym == ord "'") {
204 $self->emit ('activate_console'); 222 $self->emit ('activate_console');
205 } elsif ($sym == ord "/") { 223 } elsif ($sym == ord "/") {
206 $self->emit ('activate_console' => '/'); 224 $self->emit (activate_console => '/');
207 } elsif (exists $DIR{$sym}) { 225 } elsif (exists $DIR{$sym}) {
208 if ($mod & CFClient::KMOD_SHIFT) { 226 if ($mod & CFClient::KMOD_SHIFT) {
209 $self->{shft}++; 227 $self->{shft}++;
210 $::CONN->user_send ("fire $DIR{$sym}[0]"); 228 $::CONN->user_send ("fire $DIR{$sym}[0]");
211 } elsif ($mod & CFClient::KMOD_CTRL) { 229 } elsif ($mod & CFClient::KMOD_CTRL) {
212 $self->{ctrl}++; 230 $self->{ctrl}++;
213 $::CONN->user_send ("run $DIR{$sym}[0]"); 231 $::CONN->user_send ("run $DIR{$sym}[0]");
214 } else { 232 } else {
215 $::CONN->user_send ("$DIR{$sym}[1]"); 233 $::CONN->user_send ("$DIR{$sym}[1]");
216 } 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 # todo: support callback instead of user_send
242 $::CONN->user_send ($_[1][1]);
243 },
244 connect_close => sub {
245 (delete $self->{command_widget})->hide;
246 $self->focus_in;
247 },
248 ;
249 $self->{command_widget}->key_down ($ev);
250 return unless $self->{command_widget};
251 $self->{command_widget}->show;
252 $self->{command_widget}->focus_in;
217 } 253 }
218} 254}
219 255
220sub key_up { 256sub key_up {
221 my ($self, $ev) = @_; 257 my ($self, $ev) = @_;
222 258
223 my $mod = $ev->key_mod; 259 my $mod = $ev->{mod};
224 my $sym = $ev->key_sym; 260 my $sym = $ev->{sym};
225 261
226 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 262 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
227 $::CONN->user_send ("fire_stop"); 263 $::CONN->user_send ("fire_stop");
228 } 264 }
229 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 265 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
230 $::CONN->user_send ("run_stop"); 266 $::CONN->user_send ("run_stop");
231 } 267 }
232} 268}
233 269
234sub add_command { 270sub add_command {
235 my ($self, $command, $widget, $cb) = @_; 271 my ($self, $command, $tooltip, $widget, $cb) = @_;
236 272
237 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 273 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
238 warn "$command|$abbrev|$widget\n";#d# 274
275 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb];
276}
277
278package CFClient::MapWidget::Command;
279
280use strict;
281
282use CFClient::OpenGL;
283
284our @ISA = CFClient::UI::VBox::;
285
286sub new {
287 my $class = shift;
288
289 my $self = $class->SUPER::new (
290 @_,
291 children => [map
292 CFClient::UI::Label->new (
293 can_hover => 1,
294 can_events => 1,
295 fontsize => $_,
296 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8
297 ],
298 );
299
300 $self
301}
302
303sub size_allocate {
304 my ($self, $w, $h) = @_;
305
306 $self->SUPER::size_allocate ($w, $h);
307 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
308}
309
310sub update_labels {
311 my ($self) = @_;
312
313 my $command = $self->{command};
314 my $search_abbrev = qr/^\Q$self->{search}/;
315 my $search_full = qr/\Q$self->{search}/;
316
317 my @found;
318
319 for (@$command) {
320 if ($_->[0] =~ $search_abbrev) {
321 push @found, [$_->[0], $_];
322 } elsif ($_[1] =~ $search_full) {
323 push @found, [$_->[1], $_];
324 }
325 }
326
327 @found = sort { $a->[0] cmp $b->[0] } @found;
328
329 $self->{children}[0]->set_text ("$self->{search}_");
330
331 for (0..5) {
332 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : "");
333 $self->{children}[$_ + 1]{tooltip} = ($found[$_] ? $found[$_][1][2] : "");
334 }
335
336 $self->{select} = $found[0][1]
337 if @found;
338
339 if (@found > 6) {
340 $self->{children}[6]->set_text ("...");
341 }
342
343 $self->check_size;
344}
345
346sub key_down {
347 my ($self, $ev) = @_;
348
349 if ($ev->{sym} == 8) {
350 substr $self->{search}, -1, 1, "";
351 $self->update_labels;
352 } elsif ($ev->{sym} == 13) {
353 if (exists $self->{select}) {
354 $self->emit (execute => $self->{select});
355 $self->emit ("close");
356 }
357 } elsif ($ev->{sym} == 27) {
358 $self->emit ("close");
359 } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) {
360 $self->{search} .= chr $ev->{unicode};
361 $self->update_labels;
362 }
363
364 length $self->{search}
365 or $self->emit ("close");
239} 366}
240 367
2411 3681

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines