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.8 by root, Sat Apr 22 21:47:45 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;
85 my $sh = int $::HEIGHT / 32; 86 my $sh = int $::HEIGHT / 32;
86 87
98 GL_CONVOLUTION_2D, 99 GL_CONVOLUTION_2D,
99 GL_ALPHA, 100 GL_ALPHA,
100 3, 3, 101 3, 3,
101 GL_ALPHA, GL_FLOAT, 102 GL_ALPHA, GL_FLOAT,
102 pack "f*", 103 pack "f*",
103 0.1, 0.1, 0.1, 104 0.05, 0.13, 0.05,
104 0.1, 0.2, 0.1, 105 0.13, 0.30, 0.13,
105 0.1, 0.1, 0.1, 106 0.05, 0.13, 0.05,
106 ); 107 );
107 glEnable GL_CONVOLUTION_2D; 108 glEnable GL_CONVOLUTION_2D;
108 } 109 }
109 110
110 $self->{fow_texture} = new CFClient::Texture 111 $self->{fow_texture} = new CFClient::Texture
119 glEnable GL_BLEND; 120 glEnable GL_BLEND;
120 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 121 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
121 glEnable GL_TEXTURE_2D; 122 glEnable GL_TEXTURE_2D;
122 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 123 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
123 124
124 glColor +($::CFG->{fow_intensity}) x 3, 1; 125 glColor +($::CFG->{fow_intensity}) x 3, 0.8;
125 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); 126 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
126 127
127 glDisable GL_TEXTURE_2D; 128 glDisable GL_TEXTURE_2D;
128 glDisable GL_BLEND; 129 glDisable GL_BLEND;
129 } 130 }
130 131
131 # HACK BEGIN 132 # HACK BEGIN
132 { 133 {
133 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove 134 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
135
136 glTranslate 0, 30;
134 my ($w, $h) = (250, 250); 137 my ($w, $h) = (250, 250);
138
139 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
135 140
136 glEnable GL_BLEND; 141 glEnable GL_BLEND;
137 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 142 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
138 glEnable GL_TEXTURE_2D; 143 glEnable GL_TEXTURE_2D;
139 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 144 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
140 145
141 $self->{mapmap_texture} = 146 $self->{mapmap_texture} =
142 new CFClient::Texture 147 new CFClient::Texture
143 w => $w, 148 w => $w,
144 h => $h, 149 h => $h,
145 data => $::MAP->mapmap ($w, $h), 150 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; 151 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
147 152
148 $self->{mapmap_texture}->draw_quad (100, 100); 153 $self->{mapmap_texture}->draw_quad (0, 0);
149 154
150 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
151 glDisable GL_BLEND; 167 glDisable GL_BLEND;
152 } 168 }
153 # HACK END 169 # HACK END
154 } 170 }
155 171
191); 207);
192 208
193sub key_down { 209sub key_down {
194 my ($self, $ev) = @_; 210 my ($self, $ev) = @_;
195 211
196 my $mod = $ev->key_mod; 212 my $mod = $ev->{mod};
197 my $sym = $ev->key_sym; 213 my $sym = $ev->{sym};
198 214
199 if ($sym == CFClient::SDLK_KP5) { 215 if ($sym == CFClient::SDLK_KP5) {
200 $::CONN->user_send ("stay fire"); 216 $::CONN->user_send ("stay fire");
201 } elsif ($sym == ord "a") { 217 } elsif ($sym == ord "a") {
202 $::CONN->user_send ("apply"); 218 $::CONN->user_send ("apply");
203 } elsif ($sym == ord "'") { 219 } elsif ($sym == ord "'") {
204 $self->emit ('activate_console'); 220 $self->emit ('activate_console');
205 } elsif ($sym == ord "/") { 221 } elsif ($sym == ord "/") {
206 $self->emit ('activate_console' => '/'); 222 $self->emit (activate_console => '/');
207 } elsif (exists $DIR{$sym}) { 223 } elsif (exists $DIR{$sym}) {
208 if ($mod & CFClient::KMOD_SHIFT) { 224 if ($mod & CFClient::KMOD_SHIFT) {
209 $self->{shft}++; 225 $self->{shft}++;
210 $::CONN->user_send ("fire $DIR{$sym}[0]"); 226 $::CONN->user_send ("fire $DIR{$sym}[0]");
211 } elsif ($mod & CFClient::KMOD_CTRL) { 227 } elsif ($mod & CFClient::KMOD_CTRL) {
212 $self->{ctrl}++; 228 $self->{ctrl}++;
213 $::CONN->user_send ("run $DIR{$sym}[0]"); 229 $::CONN->user_send ("run $DIR{$sym}[0]");
214 } else { 230 } else {
215 $::CONN->user_send ("$DIR{$sym}[1]"); 231 $::CONN->user_send ("$DIR{$sym}[1]");
216 } 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;
217 } 249 }
218} 250}
219 251
220sub key_up { 252sub key_up {
221 my ($self, $ev) = @_; 253 my ($self, $ev) = @_;
222 254
223 my $mod = $ev->key_mod; 255 my $mod = $ev->{mod};
224 my $sym = $ev->key_sym; 256 my $sym = $ev->{sym};
225 257
226 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 258 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
227 $::CONN->user_send ("fire_stop"); 259 $::CONN->user_send ("fire_stop");
228 } 260 }
229 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 261 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
233 265
234sub add_command { 266sub add_command {
235 my ($self, $command, $widget, $cb) = @_; 267 my ($self, $command, $widget, $cb) = @_;
236 268
237 (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];
238 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 }
239} 358}
240 359
2411 3601

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines