1 |
package GCE::EditAction; |
2 |
|
3 |
=head1 NAME |
4 |
|
5 |
GCE::EditActions - this is the abstraction of edit actions (placing, deleting, etc.) |
6 |
|
7 |
=cut |
8 |
|
9 |
use Gtk2; |
10 |
use Gtk2::Gdk::Keysyms; |
11 |
use Gtk2::SimpleMenu; |
12 |
|
13 |
use Crossfire; |
14 |
use Crossfire::MapWidget; |
15 |
|
16 |
use strict; |
17 |
|
18 |
sub new { |
19 |
my $class = shift; |
20 |
my $self = { @_ }; |
21 |
bless $self, $class; |
22 |
return $self; |
23 |
} |
24 |
|
25 |
sub want_cursor { 1 } |
26 |
|
27 |
sub special_arrow { } |
28 |
|
29 |
# edits one tile of the map |
30 |
sub edit_one { |
31 |
my ($self, $x, $y) = @_; |
32 |
# do one edition |
33 |
} |
34 |
|
35 |
# edits a selection |
36 |
sub edit_selection { |
37 |
} |
38 |
|
39 |
# abstraction for edit_one and edit_selection ? |
40 |
# takes selection if present |
41 |
sub edit { |
42 |
my ($self, $map, $x, $y, $btn) = @_; |
43 |
} |
44 |
|
45 |
sub begin { |
46 |
my ($self, $map, $x, $y, $btn) = @_; |
47 |
|
48 |
$map->change_begin (ref $self); |
49 |
} |
50 |
|
51 |
sub end { |
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 |
} |
61 |
} |
62 |
|
63 |
|
64 |
package GCE::EditAction::Pick; |
65 |
|
66 |
our @ISA = qw/GCE::EditAction/; |
67 |
|
68 |
sub special_arrow { 'GDK_HAND2' } |
69 |
|
70 |
sub begin { |
71 |
my ($self, $map, $x, $y, $btn) = @_; |
72 |
|
73 |
$self->SUPER::begin ($map, $x, $y, $btn); |
74 |
$self->edit ($map, $x, $y, $btn); |
75 |
} |
76 |
|
77 |
sub edit { |
78 |
my ($self, $map, $x, $y, $btn) = @_; |
79 |
|
80 |
my $cstack = $map->get ($x, $y); |
81 |
|
82 |
my $arch = $cstack->[-1]; |
83 |
|
84 |
# virtual... grmbl.... |
85 |
# FIXME: I have to patch the stack of the real arch??? argl.. how?? |
86 |
if ($arch->{_virtual}) { |
87 |
$x = $arch->{virtual_x}; |
88 |
$y = $arch->{virtual_y}; |
89 |
$arch = $arch->{_virtual}; |
90 |
} |
91 |
|
92 |
$GCE::MainWindow::MAINWIN->set_pick ($arch) |
93 |
if @$cstack && $btn == 1; |
94 |
|
95 |
$GCE::MainWindow::MAINWIN->update_attr_editor ($arch, sub { |
96 |
$map->change_stack ($x, $y, $cstack); |
97 |
}); |
98 |
|
99 |
$GCE::MainWindow::MAINWIN->update_stack_view ($map, $x, $y); |
100 |
} |
101 |
|
102 |
package GCE::EditAction::Place; |
103 |
|
104 |
use GCE::Util; |
105 |
|
106 |
our @ISA = qw/GCE::EditAction/; |
107 |
|
108 |
sub want_cursor { 0 } |
109 |
|
110 |
sub begin { |
111 |
my ($self, $map, $x, $y, $btn) = @_; |
112 |
|
113 |
$self->SUPER::begin ($map, $x, $y, $btn); |
114 |
$self->edit ($map, $x, $y, $btn); |
115 |
} |
116 |
|
117 |
sub edit { |
118 |
my ($self, $map, $x, $y, $btn) = @_; |
119 |
|
120 |
if ($btn == 3) { # btn 3 does pick |
121 |
|
122 |
my $cstack = $map->get ($x, $y) or return; |
123 |
my $arch = $cstack->[-1]; |
124 |
|
125 |
$arch->{_virtual} |
126 |
and $arch = $arch->{_virtual}; |
127 |
|
128 |
$GCE::MainWindow::MAINWIN->set_pick ($arch) |
129 |
if @$cstack;; |
130 |
|
131 |
} else { |
132 |
|
133 |
my $pick = $GCE::MainWindow::MAINWIN->get_pick; |
134 |
my $as = $map->get ($x, $y); |
135 |
|
136 |
my $arch = { _name => $pick->{_name} }; |
137 |
|
138 |
$map->change_stack ($x, $y, insert_arch_stack_layer ($as, $arch)); |
139 |
# push @$as, $arch |
140 |
# unless @$as && $as->[-1]->{_name} eq $arch->{_name}; |
141 |
|
142 |
#$map->set ($x, $y, $as); |
143 |
} |
144 |
} |
145 |
|
146 |
package GCE::EditAction::Erase; |
147 |
|
148 |
our @ISA = qw/GCE::EditAction/; |
149 |
|
150 |
sub want_cursor { 0 } |
151 |
|
152 |
sub begin { |
153 |
my ($self, $map, $x, $y, $btn) = @_; |
154 |
|
155 |
$self->SUPER::begin ($map, $x, $y, $btn); |
156 |
$self->edit ($map, $x, $y, $btn); |
157 |
} |
158 |
|
159 |
sub edit { |
160 |
my ($self, $map, $x, $y, $btn) = @_; |
161 |
|
162 |
my $as = $map->get ($x, $y); |
163 |
pop @$as; |
164 |
$map->change_stack ($x, $y, $as); |
165 |
} |
166 |
|
167 |
=head1 AUTHOR |
168 |
|
169 |
Marc Lehmann <schmorp@schmorp.de> |
170 |
http://home.schmorp.de/ |
171 |
|
172 |
Robin Redeker <elmex@ta-sa.org> |
173 |
http://www.ta-sa.org/ |
174 |
|
175 |
=cut |
176 |
1; |
177 |
|