--- deliantra/Deliantra-Client/DC/MapWidget.pm 2006/10/01 18:17:38 1.84
+++ deliantra/Deliantra-Client/DC/MapWidget.pm 2007/04/04 02:43:29 1.104
@@ -8,6 +8,7 @@
use CFPlus;
use CFPlus::OpenGL;
use CFPlus::UI;
+use CFPlus::Macro;
our @ISA = CFPlus::UI::Base::;
@@ -22,6 +23,7 @@
z => -1,
can_focus => 1,
list => glGenList,
+ tilesize => 32,
smooth_matrix => [
0.05, 0.13, 0.05,
@@ -40,6 +42,12 @@
$self
}
+sub set_tilesize {
+ my ($self, $tilesize) = @_;
+
+ $self->{tilesize} = $tilesize;
+}
+
sub add_command {
my ($self, $command, $tooltip, $widget, $cb) = @_;
@@ -61,87 +69,113 @@
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::set_proxy;
-
- my $map = "map:$::CONN->{map_info}[0]";
-
- if (fork == 0) {
- $SIG{__DIE__} = sub {
- warn "@_";
- CFPlus::_exit 99;
- };
+ CFPlus::background {
+ print "preparing editor startup...\n";
- # TODO: move into editor
- require LWP::UserAgent;
+ my $server = $editsup->{gameserver} || "default";
+ $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
- my $ua = LWP::UserAgent->new (
- agent => "cfplus $CFPlus::VERSION",
- keep_alive => 1,
- env_proxy => 1,
- );
+ 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";
- if ($map =~ /^map:(.*)/) {
- my $mapname = $1;
- # try to get the most recent head revision, what a hack
- my $log = $ua->get ("$ENV{CROSSFIRE_MAPDIR}/$mapname?view=log&logsort=rev")->decoded_content;
+ -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;
- my $map = $ua->get ("$ENV{CROSSFIRE_MAPDIR}/$mapname?rev=$rev")->decoded_content;
- warn "revision is $rev " .(length $map)."\n";#d#
- # now upload it
- my $comment = "some comment";
+ print "downloading revision $rev...\n";
- require HTTP::Request::Common;
+ my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
- 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 => "",
- ]
- );
+ 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;
- 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;
- }
+ 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 {
- # error, could not detect revision
+ die "viewvc parse error, unable to detect revision\n";
}
}
-
- CFPlus::_exit;
}
}
@@ -152,14 +186,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;
@@ -179,8 +218,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) }],
@@ -194,24 +232,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 (" . (CFPlus::asxml $::CONN->{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);
}
@@ -239,9 +294,11 @@
}
sub size_request {
+ my ($self) = @_;
+
(
- 32 * CFPlus::ceil $::WIDTH / 32,
- 32 * CFPlus::ceil $::HEIGHT / 32,
+ $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize},
+ $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize},
)
}
@@ -277,8 +334,8 @@
$mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
- if ($uni == ord "\t") {
- $::PL_WINDOW->toggle_visibility;
+ if ($sym == 9) {
+ ($mod & CFPlus::KMOD_SHIFT ? $::CONSOLE->{window} : $::PL_WINDOW)->toggle_visibility;
} elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
$::HELP_WINDOW->toggle_visibility;
} elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
@@ -291,19 +348,6 @@
::toggle_player_page ($::INVENTORY_PAGE);
} elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
$::SETUP_DIALOG->toggle_visibility;
- } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) {
- $::BIND_EDITOR->set_binding (undef, undef, [],
- sub {
- my ($mod, $sym, $cmds) = @_;
- $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
- });
- $::BIND_EDITOR->start;
- $::BIND_EDITOR->show;
-#TODO: elmex, what was this supposed to do? it currently crashes the client.
-# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
-# $::BIND_EDITOR->stop;
-# $::BIND_EDITOR->ask_for_bind_and_commit;
-# $::BIND_EDITOR->hide;
} elsif (!$::CONN) {
return 0; # bindings further down need a valid connection
@@ -318,12 +362,15 @@
} elsif ($uni == ord ".") {
$::CONN->user_send ($self->{completer}{last_command})
if exists $self->{completer}{last_command};
- } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) {
- $::CONN->user_send ($_) for @$bind_cmd;
+ } elsif (my @macros = CFPlus::Macro::match_event $ev) {
+ $::CONN->macro_send ($_) for @macros;
} elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
$::CONN->user_send ("rotateshoottype +");
} elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
$::CONN->user_send ("rotateshoottype -");
+ } elsif ($uni == ord '!') {
+ $self->{completer}->set_prefix ("shout ");
+ $self->{completer}->show;
} elsif ($uni == ord '"') {
$self->{completer}->set_prefix ("$::CFG->{say_command} ");
$self->{completer}->show;
@@ -389,8 +436,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];
@@ -409,19 +456,22 @@
unless $focused || !$::FAST;
if (delete $self->{need_update}) {
- my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
+ my $tilesize = $self->{tilesize} = int $self->{tilesize} * $::CFG->{map_scale};
+
+ my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
+ my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
- my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
- my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $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);
@@ -453,9 +503,9 @@
glTranslate $sx0, $sy0;
glScale $::CFG->{map_scale}, $::CFG->{map_scale};
- $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
+ $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
- glScale 32, 32;
+ glScale $self->{tilesize}, $self->{tilesize};
if (my $tex = $self->{fow_texture}) {
glEnable GL_TEXTURE_2D;
@@ -470,8 +520,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};
@@ -540,11 +590,11 @@
my ($w, $h) = @$self{qw(w h)};
- my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
- my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
+ my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
+ my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
- my $sx = int $::CFG->{map_shift_x} / 32;
- my $sy = int $::CFG->{map_shift_y} / 32;
+ my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize};
+ my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize};
my $ox = 0.5 * ($w - $sw);
my $oy = 0.5 * ($h - $sh);
@@ -627,7 +677,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;
@@ -838,3 +888,4 @@
}
1
+