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.86 by root, Sun Oct 8 21:54:20 2006 UTC

32 @_ 32 @_
33 ); 33 );
34 34
35 $self->{completer} = new CFPlus::MapWidget::Command:: 35 $self->{completer} = new CFPlus::MapWidget::Command::
36 command => $self->{command}, 36 command => $self->{command},
37 tooltip => "<b>The Command Completer</b>\n\n" 37 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 ; 38 ;
46 39
47 $self 40 $self
48} 41}
49 42
64 57
65 %{$self->{completer}{command}} = (); 58 %{$self->{completer}{command}} = ();
66 59
67 $self->{completer}->hide 60 $self->{completer}->hide
68 if $self->{completer}; 61 if $self->{completer};
62}
63
64sub server_login {
65 my ($server) = @_;
66
67 ::stop_game ();
68 local $::PROFILE->{host} = $server;
69 ::start_game ();
70}
71
72sub check_lwp($) {
73 my ($res) = @_;
74
75 $res->is_error
76 and die $res->status_line;
77
78 $res
79}
80
81sub editor_invoke {
82 my $editsup = $::CONN && $::CONN->{editor_support}
83 or return;
84
85 my ($pid, $fh);
86 unless ($pid = open $fh, "-|:utf8", "-") {
87 $SIG{__DIE__} = sub {
88 warn "FATAL: @_\n";
89 CFPlus::_exit 99;
90 };
91
92 open STDERR, ">&STDOUT";
93 binmode STDOUT, ":utf8";
94 binmode STDERR, ":utf8";
95 close $fh;
96
97 $| = 1;
98 print "preparing editor startup...\n";
99 CFPlus::set_proxy;
100
101 my $server = $editsup->{gameserver} || "default";
102 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
103
104 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir;
105 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir;
106
107 print "map directory is $mapdir\n";
108 print "lib directory is $libdir\n";
109
110 require LWP::UserAgent;
111
112 my $ua = LWP::UserAgent->new (
113 agent => "cfplus $CFPlus::VERSION",
114 keep_alive => 1,
115 env_proxy => 1,
116 timeout => 30,
117 );
118
119 for my $file (qw(archetypes crossfire.0)) {
120 my $url = "$editsup->{lib_root}$file";
121 print "mirroring $url...\n";
122 check_lwp $ua->mirror ($url, "$libdir/$file");
123 printf "%s size %d octets\n", $file, -s "$libdir/$file";
124 }
125
126 if (1) { # upload a map
127 my $mapname = $::CONN->{map_info}[0];
128
129 print "getting map revision for $mapname...\n";
130
131 # try to get the most recent head revision, what a hack,
132 # this should have been returned while downloading *sigh*
133 my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
134
135 if ($log =~ /\?rev=(\d+\.\d+)"/) {
136 my $rev = $1;
137
138 print "downloading revision $rev...\n";
139
140 my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
141
142 my $meta = {
143 %$editsup,
144 path => $mapname,
145 revision => $rev,
146 cf_login => $::PROFILE->{user},
147 };
148
149 my $mappath = "$mapdir/$mapname";
150
151 require File::Basename;
152 require File::Path;
153
154 File::Path::mkpath (File::Basename::dirname ($mappath));
155 open my $fh, ">:raw:perlio", "$mappath.meta"
156 or die "$mappath.meta: $!";
157 print $fh CFPlus::to_json $meta;
158 close $fh;
159 open my $fh, ">:raw:perlio:utf8", $mappath
160 or die "$mappath: $!";
161 print $fh $map;
162 close $fh;
163
164 print "saved as $mappath\n";
165
166 print "invoking editor...\n";
167 exec "/root/s2/gce $mappath";#d#
168
169 # now upload it
170# require HTTP::Request::Common;
171#
172# my $res = $ua->post (
173# $ENV{CFPLUS_UPLOAD},
174# Content_Type => 'multipart/form-data',
175# Content => [
176# path => $mapname,
177# mapdir => $ENV{CROSSFIRE_MAPDIR},
178# map => $map,
179# revision => $rev,
180# cf_login => $ENV{CFPLUS_LOGIN},
181# cf_password => $ENV{CFPLUS_PASSWORD},
182# comment => "",
183# ]
184# );
185#
186# if ($res->is_error) {
187# # fatal condition
188# warn $res->status_line;
189# } else {
190# # script replies are marked as {{..}}
191# my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
192# warn map "$_\n", @msgs;
193# }
194 } else {
195 die "viewvc parse error, unable to detect revision\n";
196 }
197 }
198
199 CFPlus::_exit;
200 }
201
202 my $buffer;
203
204 Event->io (fd => $fh, poll => 'r', cb => sub {
205 unless (sysread $fh, $buffer, 4096, length $buffer) {
206 $_[0]->w->cancel;
207 $buffer .= "done\n";
208 }
209
210 while ($buffer =~ s/^(.*)\n//) {
211 ::message ({
212 markup => "editor($pid): " . CFPlus::asxml $1,
213 });
214 }
215 });
69} 216}
70 217
71sub invoke_button_down { 218sub invoke_button_down {
72 my ($self, $ev, $x, $y) = @_; 219 my ($self, $ev, $x, $y) = @_;
73 220
100 $::CFG->{map_shift_y} = $bh + $y - $oy; 247 $::CFG->{map_shift_y} = $bh + $y - $oy;
101 248
102 $self->update; 249 $self->update;
103 }; 250 };
104 } elsif ($ev->{button} == 3) { 251 } elsif ($ev->{button} == 3) {
105 (new CFPlus::UI::Menu 252 my @items = (
106 items => [
107 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], 253 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
108 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], 254 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
109 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 255 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
110 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 256 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
111 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 257 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
115 $::PICKUP_ENABLE->{state} 261 $::PICKUP_ENABLE->{state}
116 ? "Disable automatic pickup" 262 ? "Disable automatic pickup"
117 : "Enable automatic pickup", 263 : "Enable automatic pickup",
118 sub { $::PICKUP_ENABLE->toggle } 264 sub { $::PICKUP_ENABLE->toggle }
119 ], 265 ],
266 );
267
268 if ($::CONN && $::CONN->{editor_support}) {
269 push @items, [
270 "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>",
271 \&editor_invoke,
272 ];
273
274 for my $type (qw(test name)) {
275 $::CONN->{editor_support}{type} ne $type
276 or next;
277 my $server = $::CONN->{editor_support}{"${type}server"}
278 or next;
279
280 push @items, [
281 "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>",
282 sub { server_login $server },
283 ];
284 }
285 }
286
287 push @items,
120 ["Quit", 288 ["Quit",
121 sub { 289 sub {
122 if ($::CONN) { 290 if ($::CONN) {
123 &::open_quit_dialog; 291 &::open_quit_dialog;
124 } else { 292 } else {
125 exit; 293 exit;
126 }
127 } 294 }
128 ], 295 }
129 ], 296 ],
297 ;
298
299 (new CFPlus::UI::Menu
300 items => \@items,
130 )->popup ($ev); 301 )->popup ($ev);
131 } 302 }
132 303
133 1 304 1
134} 305}
212 my ($mod, $sym, $cmds) = @_; 383 my ($mod, $sym, $cmds) = @_;
213 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); 384 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
214 }); 385 });
215 $::BIND_EDITOR->start; 386 $::BIND_EDITOR->start;
216 $::BIND_EDITOR->show; 387 $::BIND_EDITOR->show;
388#TODO: elmex, what was this supposed to do? it currently crashes the client.
217 } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { 389# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) {
218 $::BIND_EDITOR->stop; 390# $::BIND_EDITOR->stop;
219 $::BIND_EDITOR->ask_for_bind_and_commit; 391# $::BIND_EDITOR->ask_for_bind_and_commit;
220 $::BIND_EDITOR->hide; 392# $::BIND_EDITOR->hide;
221 } elsif (!$::CONN) { 393 } elsif (!$::CONN) {
222 return 0; # bindings further down need a valid connection 394 return 0; # bindings further down need a valid connection
223 395
224 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { 396 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
225 $::CONN->user_send ("stay fire"); 397 $::CONN->user_send ("stay fire");
226 } elsif ($uni == ord ",") { 398 } elsif ($uni == ord ",") {
227 $::CONN->user_send ("take"); 399 $::CONN->user_send ("take");
228 } elsif ($uni == ord " ") { 400 } elsif ($uni == ord " ") {
229 $::CONN->user_send ("apply"); 401 $::CONN->user_send ("apply");
402 } elsif ($uni == 13) {
403 $::CONN->user_send ("examine");
230 } elsif ($uni == ord ".") { 404 } elsif ($uni == ord ".") {
231 $::CONN->user_send ($self->{completer}{last_command}) 405 $::CONN->user_send ($self->{completer}{last_command})
232 if exists $self->{completer}{last_command}; 406 if exists $self->{completer}{last_command};
233 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { 407 } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) {
234 $::CONN->user_send ($_) for @$bind_cmd; 408 $::CONN->user_send ($_) for @$bind_cmd;
235 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { 409 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
236 $::CONN->user_send ("rotateshoottype +"); 410 $::CONN->user_send ("rotateshoottype +");
237 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { 411 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
238 $::CONN->user_send ("rotateshoottype -"); 412 $::CONN->user_send ("rotateshoottype -");
748 922
749 $self->SUPER::_draw; 923 $self->SUPER::_draw;
750} 924}
751 925
7521 9261
927

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines