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.80 by root, Sun Jul 30 13:16:44 2006 UTC vs.
Revision 1.95 by root, Sat Dec 9 02:21:25 2006 UTC

6use List::Util qw(min max); 6use List::Util qw(min max);
7 7
8use CFPlus; 8use CFPlus;
9use CFPlus::OpenGL; 9use CFPlus::OpenGL;
10use CFPlus::UI; 10use CFPlus::UI;
11use CFPlus::Macro;
11 12
12our @ISA = CFPlus::UI::Base::; 13our @ISA = CFPlus::UI::Base::;
13 14
14my $magicmap_tex = 15my $magicmap_tex =
15 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", 16 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png",
32 @_ 33 @_
33 ); 34 );
34 35
35 $self->{completer} = new CFPlus::MapWidget::Command:: 36 $self->{completer} = new CFPlus::MapWidget::Command::
36 command => $self->{command}, 37 command => $self->{command},
37 tooltip => "<b>The Command Completer</b>\n\n" 38 tooltip => "#completer_help",
38 . "This is your central interface to send text commands to the server. "
39 . "To enter a verbatim command to send to the server, just type the command, "
40 . "followed by a space, and press return. "
41 . "Typing the initial letters of words (or just any letters) displays guesses "
42 . "for commands you might want to use.\n"
43 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n"
44 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining key bindings.",
45 ; 39 ;
46 40
47 $self 41 $self
48} 42}
49 43
66 60
67 $self->{completer}->hide 61 $self->{completer}->hide
68 if $self->{completer}; 62 if $self->{completer};
69} 63}
70 64
65sub server_login {
66 my ($server) = @_;
67
68 ::stop_game ();
69 local $::PROFILE->{host} = $server;
70 ::start_game ();
71}
72
73sub editor_invoke {
74 my $editsup = $::CONN && $::CONN->{editor_support}
75 or return;
76
77 CFPlus::background {
78 print "preparing editor startup...\n";
79
80 my $server = $editsup->{gameserver} || "default";
81 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
82
83 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir;
84 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir;
85
86 print "map directory is $mapdir\n";
87 print "lib directory is $libdir\n";
88
89 my $ua = CFPlus::lwp_useragent;
90
91 for my $file (qw(archetypes crossfire.0)) {
92 my $url = "$editsup->{lib_root}$file";
93 print "mirroring $url...\n";
94 CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file");
95 printf "%s size %d octets\n", $file, -s "$libdir/$file";
96 }
97
98 if (1) { # upload a map
99 my $mapname = $::CONN->{map_info}[0];
100
101 my $mappath = "$mapdir/$mapname";
102
103 -e $mappath and die "$mappath already exists\n";
104
105 print "getting map revision for $mapname...\n";
106
107 # try to get the most recent head revision, what a hack,
108 # this should have been returned while downloading *sigh*
109 my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
110
111 if ($log =~ /\?rev=(\d+\.\d+)"/) {
112 my $rev = $1;
113
114 print "downloading revision $rev...\n";
115
116 my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
117
118 my $meta = {
119 %$editsup,
120 path => $mapname,
121 revision => $rev,
122 cf_login => $::PROFILE->{user},
123 };
124
125 require File::Basename;
126 require File::Path;
127
128 File::Path::mkpath (File::Basename::dirname ($mappath));
129 open my $fh, ">:raw:perlio", "$mappath.meta"
130 or die "$mappath.meta: $!\n";
131 print $fh CFPlus::to_json $meta;
132 close $fh;
133 open my $fh, ">:raw:perlio:utf8", $mappath
134 or die "$mappath: $!\n";
135 print $fh $map;
136 close $fh;
137
138 print "saved as $mappath\n";
139
140 print "invoking editor...\n";
141 exec "/root/s2/gce $mappath";#d#
142
143 # now upload it
144# require HTTP::Request::Common;
145#
146# my $res = $ua->post (
147# $ENV{CFPLUS_UPLOAD},
148# Content_Type => 'multipart/form-data',
149# Content => [
150# path => $mapname,
151# mapdir => $ENV{CROSSFIRE_MAPDIR},
152# map => $map,
153# revision => $rev,
154# cf_login => $ENV{CFPLUS_LOGIN},
155# cf_password => $ENV{CFPLUS_PASSWORD},
156# comment => "",
157# ]
158# );
159#
160# if ($res->is_error) {
161# # fatal condition
162# warn $res->status_line;
163# } else {
164# # script replies are marked as {{..}}
165# my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
166# warn map "$_\n", @msgs;
167# }
168 } else {
169 die "viewvc parse error, unable to detect revision\n";
170 }
171 }
172 }
173}
174
71sub invoke_button_down { 175sub invoke_button_down {
72 my ($self, $ev, $x, $y) = @_; 176 my ($self, $ev, $x, $y) = @_;
73 177
74 if ($ev->{button} == 1) { 178 if ($ev->{button} == 1) {
75 $self->grab_focus; 179 $self->grab_focus;
76 return unless $::CONN; 180 return unless $::CONN;
77 181
78 my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 182 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize};
79 my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 183 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize};
80 184
81 $x -= int 0.5 * $self->{sw}; 185 $x -= CFPlus::floor $::MAP->w * 0.5;
82 $y -= int 0.5 * $self->{sh}; 186 $y -= CFPlus::floor $::MAP->h * 0.5;
83 187
188 if ($::CONN) {
189 if ($::IN_BUILD_MODE) {
190 $::CONN->buildat ($::IN_BUILD_MODE, $x, $y);
191 } else {
84 $::CONN->lookat ($x, $y) 192 $::CONN->lookat ($x, $y)
85 if $::CONN; 193 }
194 }
86 195
87 } elsif ($ev->{button} == 2) { 196 } elsif ($ev->{button} == 2) {
88 $self->grab_focus; 197 $self->grab_focus;
89 return unless $::CONN; 198 return unless $::CONN;
90 199
100 $::CFG->{map_shift_y} = $bh + $y - $oy; 209 $::CFG->{map_shift_y} = $bh + $y - $oy;
101 210
102 $self->update; 211 $self->update;
103 }; 212 };
104 } elsif ($ev->{button} == 3) { 213 } elsif ($ev->{button} == 3) {
105 (new CFPlus::UI::Menu 214 my @items = (
106 items => [
107 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], 215 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
108 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], 216 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
109 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 217 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
110 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 218 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
111 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 219 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
115 $::PICKUP_ENABLE->{state} 223 $::PICKUP_ENABLE->{state}
116 ? "Disable automatic pickup" 224 ? "Disable automatic pickup"
117 : "Enable automatic pickup", 225 : "Enable automatic pickup",
118 sub { $::PICKUP_ENABLE->toggle } 226 sub { $::PICKUP_ENABLE->toggle }
119 ], 227 ],
228 );
229
230 if ($::CONN && $::CONN->{editor_support}) {
231 push @items, [
232 "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>",
233 \&editor_invoke,
234 ];
235
236 for my $type (qw(test name)) {
237 $::CONN->{editor_support}{type} ne $type
238 or next;
239 my $server = $::CONN->{editor_support}{"${type}server"}
240 or next;
241
242 push @items, [
243 "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>",
244 sub { server_login $server },
245 ];
246 }
247 }
248
249 push @items,
120 ["Quit", 250 ["Quit",
121 sub { 251 sub {
122 if ($::CONN) { 252 if ($::CONN) {
123 &::open_quit_dialog; 253 &::open_quit_dialog;
124 } else { 254 } else {
125 exit; 255 exit;
126 }
127 } 256 }
128 ], 257 }
129 ], 258 ],
259 ;
260
261 (new CFPlus::UI::Menu
262 items => \@items,
130 )->popup ($ev); 263 )->popup ($ev);
131 } 264 }
132 265
133 1 266 1
134} 267}
212 my ($mod, $sym, $cmds) = @_; 345 my ($mod, $sym, $cmds) = @_;
213 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); 346 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
214 }); 347 });
215 $::BIND_EDITOR->start; 348 $::BIND_EDITOR->start;
216 $::BIND_EDITOR->show; 349 $::BIND_EDITOR->show;
350#TODO: elmex, what was this supposed to do? it currently crashes the client.
217 } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { 351# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
218 $::BIND_EDITOR->stop; 352# $::BIND_EDITOR->stop;
219 $::BIND_EDITOR->ask_for_bind_and_commit; 353# $::BIND_EDITOR->ask_for_bind_and_commit;
220 $::BIND_EDITOR->hide; 354# $::BIND_EDITOR->hide;
221 } elsif (!$::CONN) { 355 } elsif (!$::CONN) {
222 return 0; # bindings further down need a valid connection 356 return 0; # bindings further down need a valid connection
223 357
224 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { 358 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
225 $::CONN->user_send ("stay fire"); 359 $::CONN->user_send ("stay fire");
226 } elsif ($uni == ord ",") { 360 } elsif ($uni == ord ",") {
227 $::CONN->user_send ("take"); 361 $::CONN->user_send ("take");
228 } elsif ($uni == ord " ") { 362 } elsif ($uni == ord " ") {
229 $::CONN->user_send ("apply"); 363 $::CONN->user_send ("apply");
364 } elsif ($uni == 13) {
365 $::CONN->user_send ("examine");
230 } elsif ($uni == ord ".") { 366 } elsif ($uni == ord ".") {
231 $::CONN->user_send ($self->{completer}{last_command}) 367 $::CONN->user_send ($self->{completer}{last_command})
232 if exists $self->{completer}{last_command}; 368 if exists $self->{completer}{last_command};
233 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { 369 } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) {
234 $::CONN->user_send ($_) for @$bind_cmd; 370 $::CONN->user_send ($_) for @$bind_cmd;
235 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { 371 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
236 $::CONN->user_send ("rotateshoottype +"); 372 $::CONN->user_send ("rotateshoottype +");
237 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { 373 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
238 $::CONN->user_send ("rotateshoottype -"); 374 $::CONN->user_send ("rotateshoottype -");
299} 435}
300 436
301sub set_magicmap { 437sub set_magicmap {
302 my ($self, $w, $h, $x, $y, $data) = @_; 438 my ($self, $w, $h, $x, $y, $data) = @_;
303 439
304 $x -= $::MAP->ox + int 0.5 * $::MAP->w; 440 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
305 $y -= $::MAP->oy + int 0.5 * $::MAP->h; 441 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
306 442
307 $self->{magicmap} = [$x, $y, $w, $h, $data]; 443 $self->{magicmap} = [$x, $y, $w, $h, $data];
308 444
309 $self->update; 445 $self->update;
310} 446}
321 unless $focused || !$::FAST; 457 unless $focused || !$::FAST;
322 458
323 if (delete $self->{need_update}) { 459 if (delete $self->{need_update}) {
324 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 460 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
325 461
462 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
463 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
464
326 my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 465 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
327 my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 466 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
328 467
329 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 468 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
330 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 469 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
331 470
332 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 471 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
333 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 472 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
334 473
335 if ($::CFG->{fow_enable}) { 474 if ($::CFG->{fow_enable}) {
336 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); 475 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
337 476
338 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 477 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
339 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); 478 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
340 glConvolutionFilter2D ( 479 glConvolutionFilter2D (
341 GL_CONVOLUTION_2D, 480 GL_CONVOLUTION_2D,
363 502
364 glPushMatrix; 503 glPushMatrix;
365 glTranslate $sx0, $sy0; 504 glTranslate $sx0, $sy0;
366 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 505 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
367 506
368 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); 507 $::MAP->draw ($dx, $dy, $sw, $sh);
369 508
370 glScale 32, 32; 509 glScale 32, 32;
371 510
372 if (my $tex = $self->{fow_texture}) { 511 if (my $tex = $self->{fow_texture}) {
373 glEnable GL_TEXTURE_2D; 512 glEnable GL_TEXTURE_2D;
380 } 519 }
381 520
382 if ($self->{magicmap}) { 521 if ($self->{magicmap}) {
383 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 522 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
384 523
385 $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); 524 $x += $::MAP->ox + $self->{dx};
386 $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); 525 $y += $::MAP->oy + $self->{dy};
387 526
388 glTranslate - $x - 1, - $y - 1; 527 glTranslate - $x - 1, - $y - 1;
389 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 528 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
390 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 529 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
391 } 530 }
537 676
538 if ($ev->{button} == 3) { 677 if ($ev->{button} == 3) {
539 (new CFPlus::UI::Menu 678 (new CFPlus::UI::Menu
540 items => [ 679 items => [
541 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" 680 ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key"
542 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] 681 => sub { CFPlus::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }]
543 ], 682 ],
544 )->popup ($ev); 683 )->popup ($ev);
545 return 1; 684 return 1;
546 } 685 }
547 0 686 0
748 887
749 $self->SUPER::_draw; 888 $self->SUPER::_draw;
750} 889}
751 890
7521 8911
892

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines