ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/EditAction.pm
(Generate patch)

Comparing deliantra/gde/GCE/EditAction.pm (file contents):
Revision 1.27 by elmex, Sat Apr 1 19:23:58 2006 UTC vs.
Revision 1.28 by root, Sat Apr 1 19:50:32 2006 UTC

303# $::MAINWIN->{edit_collection}{pick}->edit ($map, $x, $y); 303# $::MAINWIN->{edit_collection}{pick}->edit ($map, $x, $y);
304#$self->SUPER::end ($map, $x, $y, $mape); 304#$self->SUPER::end ($map, $x, $y, $mape);
305} 305}
306 306
307package GCE::EditAction::Place; 307package GCE::EditAction::Place;
308
308use Storable qw/dclone/; 309use Storable qw/dclone/;
309use GCE::Util; 310use GCE::Util;
310use Gtk2; 311use Gtk2;
311use strict; 312use strict;
312 313
316 317
317sub init { 318sub init {
318 my ($self) = @_; 319 my ($self) = @_;
319 320
320 my $vb = new Gtk2::VBox; 321 my $vb = new Gtk2::VBox;
322
321 $self->add_mode_button ($vb, "auto", "auto"); 323 $self->add_mode_button ($vb, "auto", "auto");
322 $self->add_mode_button ($vb, "top", "top"); 324 $self->add_mode_button ($vb, "top", "top");
323 $self->add_mode_button ($vb, "above floor", "above"); 325 $self->add_mode_button ($vb, "above floor", "above");
324 $self->add_mode_button ($vb, "below floor", "below"); 326 $self->add_mode_button ($vb, "below floor", "below");
325 $self->add_mode_button ($vb, "bottom", "bottom"); 327 $self->add_mode_button ($vb, "bottom", "bottom");
334 336
335 $self->SUPER::begin ($map, $x, $y); 337 $self->SUPER::begin ($map, $x, $y);
336 $self->edit ($map, $x, $y); 338 $self->edit ($map, $x, $y);
337} 339}
338 340
341# 1 up 2 right 4 down 8 left
342my @join_ext = (
343 "0", # 0
344 "1_2", # 1
345 "1_4", # 2
346 "2_2_1", # 3
347 "1_1", # 4
348 "2_1_1", # 5
349 "2_2_2", # 6
350 "3_2", # 7
351 "1_3", # 8
352 "2_2_4", # 9
353 "2_1_2", # 10
354 "3_1", # 11
355 "2_2_3", # 12
356 "3_4", # 13
357 "3_3", # 14
358 "4", # 15
359);
360
361sub autojoin {
362 my ($map, $pick, $x1, $y1, $x2, $y2) = @_;
363
364 my $dx = $x2 - $x1;
365 my $dy = $y2 - $y1;
366
367 my $dir = $dy ? ($dy == -1 ? 1 : $dy == 1 ? 4 : return)
368 : ($dx == -1 ? 8 : $dx == 1 ? 2 : $dx == 0 ? 0 : return);
369
370 my $as = $map->get ($x1, $y1);
371
372 (my $base = $pick->{_name}) =~ s/_0$//;
373
374 for my $idx (0 .. $#$as) {
375 my $arch = $as->[$idx];
376 for my $dirs (0..15) {
377 my $name = $arch->{_name};
378
379 if ($arch->{_name} eq "$base\_$join_ext[$dirs]") {
380 $dirs |= $dir;
381
382 my $name = "$base\_$join_ext[$dirs]";
383
384 if ($Crossfire::ARCH{$name}) {
385 %$arch = ( _name => $name );
386 $map->change_stack ($x1, $y1, $as);
387
388 return 1;
389 }
390 }
391 }
392 }
393
394 return 0;
395}
396
339sub edit { 397sub edit {
340 my ($self, $map, $x, $y) = @_; 398 my ($self, $map, $x, $y) = @_;
341 399
342 my $pick = $::MAINWIN->get_pick; 400 my $pick = $::MAINWIN->get_pick;
343 my $as = $map->get ($x, $y); 401 my $as = $map->get ($x, $y);
344 402
403 if ($self->{place_clean}->get_active) {
404 $pick = { _name => $pick->{_name} };
405 }
406
407 my $autojoin = $pick->{_name} =~ /_0$/
408 && $self->get_mode eq "auto";
409
410 autojoin $map, $pick, @{$self->{last_pos}}, $x, $y
411 if $autojoin && $self->{last_pos};
412
413 if (!$autojoin
414 || !($self->{last_pos} ? autojoin $map, $pick, $x, $y, @{$self->{last_pos}},
415 : autojoin $map, $pick, $x, $y, $x, $y)) {
345 $self->stack_action ($as, dclone ($pick)); 416 $self->stack_action ($as, dclone $pick);
346 $map->change_stack ($x, $y, $as); # insert_arch_stack_layer ($as, $arch)); 417 $map->change_stack ($x, $y, $as);
418 autojoin $map, $pick, $x, $y, @{$self->{last_pos}}
419 if $autojoin && $self->{last_pos};
420 }
421
422 $self->{last_pos} = [$x, $y];
347} 423}
348 424
349sub end { 425sub end {
350 my ($self, $map, $x, $y, $mape) = @_; 426 my ($self, $map, $x, $y, $mape) = @_;
351# $::MAINWIN->{edit_collection}{pick}->edit ($map, $x, $y); 427# $::MAINWIN->{edit_collection}{pick}->edit ($map, $x, $y);
353 $::MAINWIN->update_stack_view ($map, $x, $y); 429 $::MAINWIN->update_stack_view ($map, $x, $y);
354 430
355 my $cstack = $map->get ($x, $y); 431 my $cstack = $map->get ($x, $y);
356 432
357 my $arch = $cstack->[-1]; 433 my $arch = $cstack->[-1];
434
435 delete $self->{last_pos};
358 436
359 # virtual... grmbl.... 437 # virtual... grmbl....
360 # FIXME: I have to patch the stack of the real arch??? argl.. how?? 438 # FIXME: I have to patch the stack of the real arch??? argl.. how??
361 if ($arch->{_virtual}) { 439 if ($arch->{_virtual}) {
362 $x = $arch->{virtual_x}; 440 $x = $arch->{virtual_x};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines