--- deliantra/Deliantra-Client/DC/MapWidget.pm 2006/10/01 14:48:51 1.83
+++ deliantra/Deliantra-Client/DC/MapWidget.pm 2006/12/09 02:21:25 1.95
@@ -8,6 +8,7 @@
use CFPlus;
use CFPlus::OpenGL;
use CFPlus::UI;
+use CFPlus::Macro;
our @ISA = CFPlus::UI::Base::;
@@ -61,29 +62,114 @@
if $self->{completer};
}
-sub test_server_login {
- return unless
- $::CONN && length $::CONN->{test_server};
+sub server_login {
+ my ($server) = @_;
- my $server = $::CONN->{test_server};
::stop_game ();
local $::PROFILE->{host} = $server;
::start_game ();
}
sub editor_invoke {
- return unless $::CONN;
+ my $editsup = $::CONN && $::CONN->{editor_support}
+ or return;
- # putting the password into the env is somewhat tasteless
- local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user};
- local $ENV{CFPLUS_PASSWORD} = $::PROFILE->{password};
- local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload};
- local $ENV{CROSSFIRE_MAPDIR} = $::CONN->{cvs_root};
+ CFPlus::background {
+ print "preparing editor startup...\n";
-# CFPlus::set_proxy;
+ my $server = $editsup->{gameserver} || "default";
+ $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
- # TODO: move into editor
- require LWP::Simple;
+ local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir;
+ local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir;
+
+ print "map directory is $mapdir\n";
+ print "lib directory is $libdir\n";
+
+ my $ua = CFPlus::lwp_useragent;
+
+ for my $file (qw(archetypes crossfire.0)) {
+ my $url = "$editsup->{lib_root}$file";
+ print "mirroring $url...\n";
+ CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file");
+ printf "%s size %d octets\n", $file, -s "$libdir/$file";
+ }
+
+ if (1) { # upload a map
+ my $mapname = $::CONN->{map_info}[0];
+
+ my $mappath = "$mapdir/$mapname";
+
+ -e $mappath and die "$mappath already exists\n";
+
+ print "getting map revision for $mapname...\n";
+
+ # try to get the most recent head revision, what a hack,
+ # this should have been returned while downloading *sigh*
+ my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
+
+ if ($log =~ /\?rev=(\d+\.\d+)"/) {
+ my $rev = $1;
+
+ print "downloading revision $rev...\n";
+
+ my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
+
+ my $meta = {
+ %$editsup,
+ path => $mapname,
+ revision => $rev,
+ cf_login => $::PROFILE->{user},
+ };
+
+ require File::Basename;
+ require File::Path;
+
+ File::Path::mkpath (File::Basename::dirname ($mappath));
+ open my $fh, ">:raw:perlio", "$mappath.meta"
+ or die "$mappath.meta: $!\n";
+ print $fh CFPlus::to_json $meta;
+ close $fh;
+ open my $fh, ">:raw:perlio:utf8", $mappath
+ or die "$mappath: $!\n";
+ print $fh $map;
+ close $fh;
+
+ print "saved as $mappath\n";
+
+ print "invoking editor...\n";
+ exec "/root/s2/gce $mappath";#d#
+
+ # now upload it
+# require HTTP::Request::Common;
+#
+# my $res = $ua->post (
+# $ENV{CFPLUS_UPLOAD},
+# Content_Type => 'multipart/form-data',
+# Content => [
+# path => $mapname,
+# mapdir => $ENV{CROSSFIRE_MAPDIR},
+# map => $map,
+# revision => $rev,
+# cf_login => $ENV{CFPLUS_LOGIN},
+# cf_password => $ENV{CFPLUS_PASSWORD},
+# comment => "",
+# ]
+# );
+#
+# if ($res->is_error) {
+# # fatal condition
+# warn $res->status_line;
+# } else {
+# # script replies are marked as {{..}}
+# my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
+# warn map "$_\n", @msgs;
+# }
+ } else {
+ die "viewvc parse error, unable to detect revision\n";
+ }
+ }
+ }
}
sub invoke_button_down {
@@ -93,14 +179,19 @@
$self->grab_focus;
return unless $::CONN;
- my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
- my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
+ my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize};
+ my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize};
- $x -= int 0.5 * $self->{sw};
- $y -= int 0.5 * $self->{sh};
+ $x -= CFPlus::floor $::MAP->w * 0.5;
+ $y -= CFPlus::floor $::MAP->h * 0.5;
- $::CONN->lookat ($x, $y)
- if $::CONN;
+ if ($::CONN) {
+ if ($::IN_BUILD_MODE) {
+ $::CONN->buildat ($::IN_BUILD_MODE, $x, $y);
+ } else {
+ $::CONN->lookat ($x, $y)
+ }
+ }
} elsif ($ev->{button} == 2) {
$self->grab_focus;
@@ -120,8 +211,7 @@
$self->update;
};
} elsif ($ev->{button} == 3) {
- (new CFPlus::UI::Menu
- items => [
+ my @items = (
["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
@@ -135,22 +225,41 @@
: "Enable automatic pickup",
sub { $::PICKUP_ENABLE->toggle }
],
- $::CONN && length $::CONN->{cvs_root}
- ? ["Edit this map (" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")", \&editor_invoke]
- : (),
- $::CONN && length $::CONN->{test_server}
- ? ["Login on Test Server", \&test_server_login]
- : (),
- ["Quit",
- sub {
- if ($::CONN) {
- &::open_quit_dialog;
- } else {
- exit;
- }
+ );
+
+ if ($::CONN && $::CONN->{editor_support}) {
+ push @items, [
+ "Edit this map (" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")",
+ \&editor_invoke,
+ ];
+
+ for my $type (qw(test name)) {
+ $::CONN->{editor_support}{type} ne $type
+ or next;
+ my $server = $::CONN->{editor_support}{"${type}server"}
+ or next;
+
+ push @items, [
+ "Login on $type server (" . (CFPlus::asxml $server) . ")",
+ sub { server_login $server },
+ ];
+ }
+ }
+
+ push @items,
+ ["Quit",
+ sub {
+ if ($::CONN) {
+ &::open_quit_dialog;
+ } else {
+ exit;
}
- ],
+ }
],
+ ;
+
+ (new CFPlus::UI::Menu
+ items => \@items,
)->popup ($ev);
}
@@ -328,8 +437,8 @@
sub set_magicmap {
my ($self, $w, $h, $x, $y, $data) = @_;
- $x -= $::MAP->ox + int 0.5 * $::MAP->w;
- $y -= $::MAP->oy + int 0.5 * $::MAP->h;
+ $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
+ $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
$self->{magicmap} = [$x, $y, $w, $h, $data];
@@ -350,17 +459,20 @@
if (delete $self->{need_update}) {
my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
- my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
- my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
+ my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
+ my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
+
+ my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
+ my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
- my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
- my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
+ my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
+ my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
if ($::CFG->{fow_enable}) {
- my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
+ my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
@@ -392,7 +504,7 @@
glTranslate $sx0, $sy0;
glScale $::CFG->{map_scale}, $::CFG->{map_scale};
- $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
+ $::MAP->draw ($dx, $dy, $sw, $sh);
glScale 32, 32;
@@ -409,8 +521,8 @@
if ($self->{magicmap}) {
my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
- $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1);
- $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1);
+ $x += $::MAP->ox + $self->{dx};
+ $y += $::MAP->oy + $self->{dy};
glTranslate - $x - 1, - $y - 1;
glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
@@ -566,7 +678,7 @@
(new CFPlus::UI::Menu
items => [
["bind " . (CFPlus::asxml $self->{select}) . " to a key"
- => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
+ => sub { CFPlus::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }]
],
)->popup ($ev);
return 1;
@@ -777,3 +889,4 @@
}
1
+