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.2 by elmex, Mon Feb 20 18:21:04 2006 UTC vs.
Revision 1.3 by root, Mon Feb 20 23:22:03 2006 UTC

42 my ($self, $map, $x, $y, $btn) = @_; 42 my ($self, $map, $x, $y, $btn) = @_;
43} 43}
44 44
45sub begin { 45sub begin {
46 my ($self, $map, $x, $y, $btn) = @_; 46 my ($self, $map, $x, $y, $btn) = @_;
47 # prepare undo stack element 47
48 $map->change_begin (ref $self);
48} 49}
50
49sub end { 51sub end {
50 # push undo stack 52 my ($self, $map) = @_;
53
54 if (my $changeset = $map->change_end) {
55 splice @{ $map->{undo_stack} ||= [] },
56 $map->{undo_stack_pos}++, 1e99,
57 $changeset;
58
59 #TODO: limit undo stack size to some preconfigured limit
60 }
51} 61}
52 62
53 63
54package GCE::EditAction::Pick; 64package GCE::EditAction::Pick;
55 65
58sub special_arrow { 'GDK_HAND2' } 68sub special_arrow { 'GDK_HAND2' }
59 69
60sub begin { 70sub begin {
61 my ($self, $map, $x, $y, $btn) = @_; 71 my ($self, $map, $x, $y, $btn) = @_;
62 72
73 $self->SUPER::begin ($map, $x, $y, $btn);
63 $self->edit ($map, $x, $y, $btn); 74 $self->edit ($map, $x, $y, $btn);
64} 75}
65 76
66sub edit { 77sub edit {
67 my ($self, $map, $x, $y, $btn) = @_; 78 my ($self, $map, $x, $y, $btn) = @_;
71 my $arch = $cstack->[-1]; 82 my $arch = $cstack->[-1];
72 83
73 # virtual... grmbl.... 84 # virtual... grmbl....
74 # FIXME: I have to patch the stack of the real arch??? argl.. how?? 85 # FIXME: I have to patch the stack of the real arch??? argl.. how??
75 if ($arch->{_virtual}) { 86 if ($arch->{_virtual}) {
76
77 $x = $arch->{virtual_x}; 87 $x = $arch->{virtual_x};
78 $y = $arch->{virtual_y}; 88 $y = $arch->{virtual_y};
79 $arch = $arch->{_virtual}; 89 $arch = $arch->{_virtual};
80 } 90 }
81 91
82 if ($btn == 1) {
83
84 $GCE::MainWindow::MAINWIN->set_pick ($arch) 92 $GCE::MainWindow::MAINWIN->set_pick ($arch)
85 if @$cstack; 93 if @$cstack && $btn == 1;
86 }
87 94
88 $GCE::MainWindow::MAINWIN->update_attr_editor ($arch, sub { 95 $GCE::MainWindow::MAINWIN->update_attr_editor ($arch, sub {
89 $map->set ($x, $y, $cstack); 96 $map->change_stack ($x, $y, $cstack);
90 }); 97 });
91 98
92 $GCE::MainWindow::MAINWIN->update_stack_view ($map, $x, $y); 99 $GCE::MainWindow::MAINWIN->update_stack_view ($map, $x, $y);
93} 100}
94 101
101sub want_cursor { 0 } 108sub want_cursor { 0 }
102 109
103sub begin { 110sub begin {
104 my ($self, $map, $x, $y, $btn) = @_; 111 my ($self, $map, $x, $y, $btn) = @_;
105 112
113 $self->SUPER::begin ($map, $x, $y, $btn);
106 $self->edit ($map, $x, $y, $btn); 114 $self->edit ($map, $x, $y, $btn);
107} 115}
108 116
109sub edit { 117sub edit {
110 my ($self, $map, $x, $y, $btn) = @_; 118 my ($self, $map, $x, $y, $btn) = @_;
111 119
112 if ($btn == 3) { # btn 3 does pick 120 if ($btn == 3) { # btn 3 does pick
113 121
114 my $cstack = $map->get ($x, $y) or return; 122 my $cstack = $map->get ($x, $y) or return;
115 my $arch = $cstack->[-1]; 123 my $arch = $cstack->[-1];
116 124
117 $arch->{_virtual} 125 $arch->{_virtual}
118 and $arch = $arch->{_virtual}; 126 and $arch = $arch->{_virtual};
119 127
120 $GCE::MainWindow::MAINWIN->set_pick ($arch) 128 $GCE::MainWindow::MAINWIN->set_pick ($arch)
125 my $pick = $GCE::MainWindow::MAINWIN->get_pick; 133 my $pick = $GCE::MainWindow::MAINWIN->get_pick;
126 my $as = $map->get ($x, $y); 134 my $as = $map->get ($x, $y);
127 135
128 my $arch = { _name => $pick->{_name} }; 136 my $arch = { _name => $pick->{_name} };
129 137
130 $map->set ($x, $y, insert_arch_stack_layer ($as, $arch)); 138 $map->change_stack ($x, $y, insert_arch_stack_layer ($as, $arch));
131# push @$as, $arch 139# push @$as, $arch
132# unless @$as && $as->[-1]->{_name} eq $arch->{_name}; 140# unless @$as && $as->[-1]->{_name} eq $arch->{_name};
133 141
134 #$map->set ($x, $y, $as); 142 #$map->set ($x, $y, $as);
135 } 143 }
142sub want_cursor { 0 } 150sub want_cursor { 0 }
143 151
144sub begin { 152sub begin {
145 my ($self, $map, $x, $y, $btn) = @_; 153 my ($self, $map, $x, $y, $btn) = @_;
146 154
155 $self->SUPER::begin ($map, $x, $y, $btn);
147 $self->edit ($map, $x, $y, $btn); 156 $self->edit ($map, $x, $y, $btn);
148} 157}
149 158
150sub edit { 159sub edit {
151 my ($self, $map, $x, $y, $btn) = @_; 160 my ($self, $map, $x, $y, $btn) = @_;
152 161
153 my $as = $map->get ($x, $y); 162 my $as = $map->get ($x, $y);
154 pop @$as; 163 pop @$as;
155 $map->set ($x, $y, $as); 164 $map->change_stack ($x, $y, $as);
156} 165}
157 166
158=head1 AUTHOR 167=head1 AUTHOR
159 168
160 Marc Lehmann <schmorp@schmorp.de> 169 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines