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.5 by root, Wed Apr 19 23:43:07 2006 UTC vs.
Revision 1.17 by root, Mon Apr 24 13:12:32 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines