package GCE::EditAction; =head1 NAME GCE::EditActions - this is the abstraction of edit actions (placing, deleting, etc.) =cut use Gtk2; use Gtk2::Gdk::Keysyms; use Gtk2::SimpleMenu; use Crossfire; use Crossfire::MapWidget; use strict; sub new { my $class = shift; my $self = { @_ }; bless $self, $class; return $self; } sub want_cursor { 1 } sub special_arrow { } # edits one tile of the map sub edit_one { my ($self, $x, $y) = @_; # do one edition } # edits a selection sub edit_selection { } # abstraction for edit_one and edit_selection ? # takes selection if present sub edit { my ($self, $map, $x, $y, $btn) = @_; } sub begin { my ($self, $map, $x, $y, $btn) = @_; $map->change_begin (ref $self); } sub end { my ($self, $map) = @_; if (my $changeset = $map->change_end) { splice @{ $map->{undo_stack} ||= [] }, $map->{undo_stack_pos}++, 1e99, $changeset; #TODO: limit undo stack size to some preconfigured limit } } package GCE::EditAction::Pick; our @ISA = qw/GCE::EditAction/; sub special_arrow { 'GDK_HAND2' } sub begin { my ($self, $map, $x, $y, $btn) = @_; $self->SUPER::begin ($map, $x, $y, $btn); $self->edit ($map, $x, $y, $btn); } sub edit { my ($self, $map, $x, $y, $btn) = @_; my $cstack = $map->get ($x, $y); my $arch = $cstack->[-1]; # virtual... grmbl.... # FIXME: I have to patch the stack of the real arch??? argl.. how?? if ($arch->{_virtual}) { $x = $arch->{virtual_x}; $y = $arch->{virtual_y}; $arch = $arch->{_virtual}; } $GCE::MainWindow::MAINWIN->set_pick ($arch) if @$cstack && $btn == 1; $GCE::MainWindow::MAINWIN->update_attr_editor ($arch, sub { $map->change_stack ($x, $y, $cstack); }); $GCE::MainWindow::MAINWIN->update_stack_view ($map, $x, $y); } package GCE::EditAction::Place; use GCE::Util; our @ISA = qw/GCE::EditAction/; sub want_cursor { 0 } sub begin { my ($self, $map, $x, $y, $btn) = @_; $self->SUPER::begin ($map, $x, $y, $btn); $self->edit ($map, $x, $y, $btn); } sub edit { my ($self, $map, $x, $y, $btn) = @_; if ($btn == 3) { # btn 3 does pick my $cstack = $map->get ($x, $y) or return; my $arch = $cstack->[-1]; $arch->{_virtual} and $arch = $arch->{_virtual}; $GCE::MainWindow::MAINWIN->set_pick ($arch) if @$cstack;; } else { my $pick = $GCE::MainWindow::MAINWIN->get_pick; my $as = $map->get ($x, $y); my $arch = { _name => $pick->{_name} }; $map->change_stack ($x, $y, insert_arch_stack_layer ($as, $arch)); # push @$as, $arch # unless @$as && $as->[-1]->{_name} eq $arch->{_name}; #$map->set ($x, $y, $as); } } package GCE::EditAction::Erase; our @ISA = qw/GCE::EditAction/; sub want_cursor { 0 } sub begin { my ($self, $map, $x, $y, $btn) = @_; $self->SUPER::begin ($map, $x, $y, $btn); $self->edit ($map, $x, $y, $btn); } sub edit { my ($self, $map, $x, $y, $btn) = @_; my $as = $map->get ($x, $y); pop @$as; $map->change_stack ($x, $y, $as); } =head1 AUTHOR Marc Lehmann http://home.schmorp.de/ Robin Redeker http://www.ta-sa.org/ =cut 1;