1 |
elmex |
1.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 |
elmex |
1.6 |
$self->init; |
23 |
elmex |
1.1 |
return $self; |
24 |
|
|
} |
25 |
|
|
|
26 |
elmex |
1.10 |
sub name { } # a unique name for this tool (for storing it in a hash in the main window) |
27 |
|
|
|
28 |
elmex |
1.7 |
sub tool_widget { if ($_[1]) { $_[0]->{widget} = $_[1] } $_[0]->{widget} } |
29 |
elmex |
1.6 |
sub init { } |
30 |
|
|
|
31 |
elmex |
1.1 |
sub want_cursor { 1 } |
32 |
|
|
|
33 |
|
|
sub special_arrow { } |
34 |
|
|
|
35 |
|
|
# edits one tile of the map |
36 |
|
|
sub edit_one { |
37 |
|
|
my ($self, $x, $y) = @_; |
38 |
|
|
# do one edition |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
# edits a selection |
42 |
|
|
sub edit_selection { |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
# abstraction for edit_one and edit_selection ? |
46 |
|
|
# takes selection if present |
47 |
|
|
sub edit { |
48 |
elmex |
1.10 |
my ($self, $map, $x, $y) = @_; |
49 |
elmex |
1.1 |
} |
50 |
|
|
|
51 |
|
|
sub begin { |
52 |
elmex |
1.10 |
my ($self, $map, $x, $y) = @_; |
53 |
root |
1.3 |
|
54 |
|
|
$map->change_begin (ref $self); |
55 |
elmex |
1.1 |
} |
56 |
root |
1.3 |
|
57 |
elmex |
1.1 |
sub end { |
58 |
root |
1.3 |
my ($self, $map) = @_; |
59 |
|
|
|
60 |
|
|
if (my $changeset = $map->change_end) { |
61 |
|
|
splice @{ $map->{undo_stack} ||= [] }, |
62 |
root |
1.4 |
$map->{undo_stack_pos}++, 1e6, |
63 |
root |
1.3 |
$changeset; |
64 |
|
|
|
65 |
|
|
#TODO: limit undo stack size to some preconfigured limit |
66 |
|
|
} |
67 |
elmex |
1.1 |
} |
68 |
|
|
|
69 |
elmex |
1.7 |
package GCE::EditAction::RadioModed; |
70 |
|
|
|
71 |
|
|
our @ISA = qw/GCE::EditAction/; |
72 |
|
|
|
73 |
|
|
sub add_mode_button { |
74 |
|
|
my ($self, $vb, $lbl, $mode, $default) = @_; |
75 |
|
|
|
76 |
|
|
$vb->pack_start (my $b = Gtk2::RadioButton->new ($self->{place_radio_grp}, $lbl), 0, 1, 0); |
77 |
|
|
unless (defined $self->{place_radio_grp}) { |
78 |
|
|
$self->{place_radio_grp} = $b->get_group; |
79 |
|
|
|
80 |
|
|
unless (defined $default) { |
81 |
|
|
$b->set_active (1); |
82 |
|
|
$self->set_mode ($mode); |
83 |
|
|
} |
84 |
|
|
} |
85 |
|
|
if ($default) { |
86 |
|
|
$b->set_active (1); |
87 |
|
|
$self->set_mode ($mode); |
88 |
|
|
} |
89 |
|
|
$b->signal_connect (clicked => sub { |
90 |
|
|
$self->set_mode ($mode); |
91 |
|
|
}); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
sub set_mode { |
95 |
|
|
my ($self, $mode) = @_; |
96 |
|
|
$self->{place_mode} = $mode; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
sub get_mode { |
100 |
|
|
my ($self) = @_; |
101 |
|
|
$self->{place_mode} |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
sub init { |
105 |
|
|
my ($self) = @_; |
106 |
|
|
|
107 |
|
|
die "Implement me!!"; |
108 |
|
|
|
109 |
|
|
# my $vb = new Gtk2::VBox; |
110 |
|
|
# $self->_add_mode_button ($vb, "auto", "auto"); |
111 |
|
|
# $self->_add_mode_button ($vb, "top", "top"); |
112 |
|
|
# $self->_add_mode_button ($vb, "above floor", "above"); |
113 |
|
|
# $self->_add_mode_button ($vb, "below floor", "below"); |
114 |
|
|
# $self->_add_mode_button ($vb, "bottom", "bottom"); |
115 |
|
|
# |
116 |
|
|
# $self->{widget} = $vb; |
117 |
|
|
} |
118 |
elmex |
1.1 |
|
119 |
|
|
package GCE::EditAction::Pick; |
120 |
elmex |
1.7 |
use strict; |
121 |
elmex |
1.1 |
|
122 |
|
|
our @ISA = qw/GCE::EditAction/; |
123 |
|
|
|
124 |
elmex |
1.10 |
sub name { 'pick' } |
125 |
|
|
|
126 |
elmex |
1.7 |
sub want_cursor { 0 } |
127 |
|
|
|
128 |
elmex |
1.1 |
sub special_arrow { 'GDK_HAND2' } |
129 |
|
|
|
130 |
|
|
sub begin { |
131 |
elmex |
1.10 |
my ($self, $map, $x, $y) = @_; |
132 |
elmex |
1.1 |
|
133 |
elmex |
1.10 |
$self->SUPER::begin ($map, $x, $y); |
134 |
|
|
$self->edit ($map, $x, $y); |
135 |
elmex |
1.1 |
} |
136 |
|
|
|
137 |
|
|
sub edit { |
138 |
elmex |
1.10 |
my ($self, $map, $x, $y) = @_; |
139 |
elmex |
1.1 |
|
140 |
|
|
my $cstack = $map->get ($x, $y); |
141 |
|
|
|
142 |
|
|
my $arch = $cstack->[-1]; |
143 |
|
|
|
144 |
|
|
# virtual... grmbl.... |
145 |
|
|
# FIXME: I have to patch the stack of the real arch??? argl.. how?? |
146 |
|
|
if ($arch->{_virtual}) { |
147 |
root |
1.3 |
$x = $arch->{virtual_x}; |
148 |
|
|
$y = $arch->{virtual_y}; |
149 |
elmex |
1.1 |
$arch = $arch->{_virtual}; |
150 |
elmex |
1.6 |
$cstack = $map->get ($x, $y); |
151 |
elmex |
1.1 |
} |
152 |
|
|
|
153 |
root |
1.5 |
$::MAINWIN->set_pick ($arch) |
154 |
elmex |
1.10 |
if @$cstack; |
155 |
elmex |
1.1 |
|
156 |
root |
1.5 |
$::MAINWIN->update_attr_editor ($arch, sub { |
157 |
elmex |
1.8 |
$map->change_begin (ref $self); |
158 |
root |
1.3 |
$map->change_stack ($x, $y, $cstack); |
159 |
elmex |
1.8 |
# XXX: Put this into a generic function!!! See also EditTools.pm |
160 |
|
|
# FIXME: Fix the automatic update on undo here! |
161 |
|
|
if (my $changeset = $map->change_end) { |
162 |
|
|
splice @{ $map->{undo_stack} ||= [] }, |
163 |
|
|
$map->{undo_stack_pos}++, 1e6, |
164 |
|
|
$changeset; |
165 |
|
|
} |
166 |
elmex |
1.1 |
}); |
167 |
|
|
|
168 |
root |
1.5 |
$::MAINWIN->update_stack_view ($map, $x, $y); |
169 |
elmex |
1.1 |
} |
170 |
|
|
|
171 |
elmex |
1.13 |
package GCE::EditAction::Perl; |
172 |
|
|
|
173 |
|
|
use GCE::Util; |
174 |
|
|
use Gtk2; |
175 |
|
|
use strict; |
176 |
|
|
|
177 |
|
|
our @ISA = qw/GCE::EditAction/; |
178 |
|
|
|
179 |
|
|
sub name { 'perl' } |
180 |
|
|
|
181 |
elmex |
1.15 |
sub special_arrow { 'GDK_HEART' } |
182 |
|
|
|
183 |
elmex |
1.13 |
sub init { |
184 |
|
|
my ($self) = @_; |
185 |
|
|
|
186 |
|
|
my $vb = new Gtk2::VBox; |
187 |
elmex |
1.20 |
$vb->pack_start (my $combo = Gtk2::ComboBox->new_text, 0, 1, 0); |
188 |
elmex |
1.13 |
$vb->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); |
189 |
|
|
$sw->add ($self->{txt} = Gtk2::TextView->new); |
190 |
|
|
|
191 |
elmex |
1.20 |
my $code = {}; |
192 |
|
|
for (['unique floor' => 'my $i = 0; for (@$os) { $_->{is_floor} and $as->[$i]->{unique} = 1; $i++ }']) { |
193 |
|
|
$combo->append_text ($_->[0]); |
194 |
|
|
$code->{$_->[0]} = $_->[1]; |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
$combo->signal_connect (changed => sub { |
198 |
|
|
my ($combo) = @_; |
199 |
|
|
my $str = $combo->get_active_text; |
200 |
|
|
$self->{txt}->get_buffer->set_text ($code->{$str}); |
201 |
|
|
}); |
202 |
|
|
|
203 |
elmex |
1.13 |
$self->tool_widget ($vb); |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
sub want_cursor { 0 } |
207 |
|
|
|
208 |
|
|
sub begin { |
209 |
|
|
my ($self, $map, $x, $y) = @_; |
210 |
|
|
|
211 |
|
|
$self->SUPER::begin ($map, $x, $y); |
212 |
|
|
$self->edit ($map, $x, $y); |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
sub edit { |
216 |
|
|
my ($self, $map, $x, $y) = @_; |
217 |
|
|
|
218 |
|
|
my $pick = $::MAINWIN->get_pick; |
219 |
|
|
my $as = $map->get ($x, $y); |
220 |
|
|
|
221 |
|
|
$as = $self->eval ($map, $pick, $as, $x, $y); |
222 |
|
|
$map->change_stack ($x, $y, $as); # insert_arch_stack_layer ($as, $arch)); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
sub eval { |
226 |
elmex |
1.20 |
my ($self, $map, $pick, $as, $x, $y) = @_; |
227 |
elmex |
1.13 |
my $buf = $self->{txt}->get_buffer; |
228 |
|
|
my $code = $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0); |
229 |
elmex |
1.20 |
my $f_idx = stack_find_floor ($as, 'from_top'); |
230 |
|
|
my $w_idx = stack_find_wall ($as, 'from_top'); |
231 |
|
|
my $os = [ map { $Crossfire::ARCH{$_->{_name}} } @$as ]; |
232 |
|
|
|
233 |
|
|
unless (arch_is_floor ($as->[$f_idx])) { $f_idx = undef; } |
234 |
|
|
unless (arch_is_floor ($as->[$w_idx])) { $w_idx = undef; } |
235 |
elmex |
1.13 |
|
236 |
|
|
eval $code; |
237 |
elmex |
1.20 |
return $as; |
238 |
elmex |
1.13 |
} |
239 |
|
|
|
240 |
elmex |
1.18 |
package GCE::EditAction::FollowExit; |
241 |
|
|
use Storable qw/dclone/; |
242 |
|
|
use File::Spec::Functions; |
243 |
|
|
use GCE::Util; |
244 |
|
|
use Gtk2; |
245 |
|
|
use strict; |
246 |
|
|
|
247 |
|
|
our @ISA = qw/GCE::EditAction/; |
248 |
|
|
|
249 |
|
|
sub name { 'place' } |
250 |
|
|
|
251 |
|
|
sub init { |
252 |
|
|
my ($self) = @_; |
253 |
|
|
|
254 |
|
|
my $vb = new Gtk2::VBox; |
255 |
|
|
|
256 |
|
|
$self->tool_widget ($vb); |
257 |
|
|
} |
258 |
|
|
|
259 |
|
|
sub want_cursor { 0 } |
260 |
|
|
|
261 |
|
|
sub begin { |
262 |
elmex |
1.21 |
my ($self, $map, $x, $y, $mape) = @_; |
263 |
elmex |
1.18 |
|
264 |
|
|
# $self->SUPER::begin ($map, $x, $y); |
265 |
elmex |
1.21 |
$self->edit ($map, $x, $y, $mape); |
266 |
elmex |
1.18 |
} |
267 |
|
|
|
268 |
|
|
sub edit { |
269 |
elmex |
1.21 |
my ($self, $map, $x, $y, $mape) = @_; |
270 |
elmex |
1.18 |
|
271 |
|
|
my $as = $map->get ($x, $y); |
272 |
|
|
|
273 |
|
|
my $exit; |
274 |
|
|
for (@$as) { |
275 |
|
|
my $a = $Crossfire::ARCH{$_->{_name}}; |
276 |
elmex |
1.21 |
if (arch_is_exit ($_)) { |
277 |
elmex |
1.18 |
$exit = $_; |
278 |
|
|
} |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
if ($exit) { |
282 |
|
|
my $dest = $exit->{slaying}; |
283 |
|
|
my $dir; |
284 |
|
|
if (File::Spec->file_name_is_absolute($dest)) { |
285 |
|
|
$dir = catdir ($Crossfire::LIB, 'maps', $dest); |
286 |
|
|
} else { |
287 |
elmex |
1.21 |
my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); |
288 |
|
|
$dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); |
289 |
elmex |
1.18 |
} |
290 |
|
|
$::MAINWIN->open_map_editor ($dir); |
291 |
|
|
} |
292 |
|
|
} |
293 |
|
|
|
294 |
|
|
sub end { |
295 |
|
|
my ($self, $map, $x, $y, $mape) = @_; |
296 |
|
|
# $::MAINWIN->{edit_collection}{pick}->edit ($map, $x, $y); |
297 |
|
|
#$self->SUPER::end ($map, $x, $y, $mape); |
298 |
|
|
} |
299 |
|
|
|
300 |
elmex |
1.1 |
package GCE::EditAction::Place; |
301 |
elmex |
1.14 |
use Storable qw/dclone/; |
302 |
elmex |
1.2 |
use GCE::Util; |
303 |
elmex |
1.6 |
use Gtk2; |
304 |
|
|
use strict; |
305 |
elmex |
1.2 |
|
306 |
elmex |
1.7 |
our @ISA = qw/GCE::EditAction::RadioModed/; |
307 |
elmex |
1.6 |
|
308 |
elmex |
1.10 |
sub name { 'place' } |
309 |
|
|
|
310 |
elmex |
1.6 |
sub init { |
311 |
|
|
my ($self) = @_; |
312 |
|
|
|
313 |
|
|
my $vb = new Gtk2::VBox; |
314 |
elmex |
1.7 |
$self->add_mode_button ($vb, "auto", "auto"); |
315 |
|
|
$self->add_mode_button ($vb, "top", "top"); |
316 |
|
|
$self->add_mode_button ($vb, "above floor", "above"); |
317 |
|
|
$self->add_mode_button ($vb, "below floor", "below"); |
318 |
|
|
$self->add_mode_button ($vb, "bottom", "bottom"); |
319 |
elmex |
1.6 |
|
320 |
elmex |
1.17 |
$vb->pack_start ($self->{place_clean} = Gtk2::CheckButton->new ('place clean'), 0, 1, 0); |
321 |
|
|
|
322 |
elmex |
1.7 |
$self->tool_widget ($vb); |
323 |
elmex |
1.6 |
} |
324 |
|
|
|
325 |
elmex |
1.1 |
sub want_cursor { 0 } |
326 |
|
|
|
327 |
|
|
sub begin { |
328 |
elmex |
1.10 |
my ($self, $map, $x, $y) = @_; |
329 |
elmex |
1.1 |
|
330 |
elmex |
1.10 |
$self->SUPER::begin ($map, $x, $y); |
331 |
|
|
$self->edit ($map, $x, $y); |
332 |
elmex |
1.1 |
} |
333 |
|
|
|
334 |
|
|
sub edit { |
335 |
elmex |
1.10 |
my ($self, $map, $x, $y) = @_; |
336 |
elmex |
1.1 |
|
337 |
elmex |
1.10 |
my $pick = $::MAINWIN->get_pick; |
338 |
|
|
my $as = $map->get ($x, $y); |
339 |
elmex |
1.1 |
|
340 |
elmex |
1.17 |
if ($self->{place_clean}->get_active) { |
341 |
|
|
$pick = { _name => $pick->{_name} }; |
342 |
|
|
} |
343 |
|
|
|
344 |
elmex |
1.14 |
$self->stack_action ($as, dclone ($pick)); |
345 |
elmex |
1.10 |
$map->change_stack ($x, $y, $as); # insert_arch_stack_layer ($as, $arch)); |
346 |
elmex |
1.1 |
} |
347 |
|
|
|
348 |
elmex |
1.17 |
sub end { |
349 |
|
|
my ($self, $map, $x, $y, $mape) = @_; |
350 |
|
|
$::MAINWIN->{edit_collection}{pick}->edit ($map, $x, $y); |
351 |
|
|
$self->SUPER::end ($map, $x, $y, $mape); |
352 |
|
|
} |
353 |
|
|
|
354 |
elmex |
1.6 |
sub stack_action { |
355 |
|
|
my ($self, $stack, $arch) = @_; |
356 |
|
|
|
357 |
elmex |
1.7 |
my $m = $self->get_mode; |
358 |
elmex |
1.6 |
|
359 |
|
|
if ($m eq 'top') { |
360 |
|
|
if (@$stack == 0 or $stack->[-1]->{_name} ne $arch->{_name}) { |
361 |
|
|
push @$stack, $arch; |
362 |
|
|
} |
363 |
|
|
|
364 |
|
|
} elsif ($m eq 'bottom') { |
365 |
|
|
if (@$stack == 0 or $stack->[0]->{_name} ne $arch->{_name}) { |
366 |
|
|
unshift @$stack, $arch; |
367 |
|
|
} |
368 |
|
|
|
369 |
|
|
} elsif ($m eq 'above') { |
370 |
|
|
my $fidx = stack_find_floor ($stack, 'from_top'); |
371 |
|
|
|
372 |
|
|
if (@$stack == 0 |
373 |
|
|
or not ($stack->[$fidx + 1]) |
374 |
|
|
or $stack->[$fidx + 1]->{_name} ne $arch->{_name}) |
375 |
|
|
{ |
376 |
|
|
splice (@$stack, $fidx + 1, 0, $arch); |
377 |
|
|
} |
378 |
|
|
|
379 |
|
|
} elsif ($m eq 'below') { |
380 |
|
|
my $fidx = stack_find_floor ($stack, 'from_bottom'); |
381 |
|
|
|
382 |
|
|
if (@$stack == 0 |
383 |
|
|
or $fidx == 0 |
384 |
|
|
or not ($stack->[$fidx - 1]) |
385 |
|
|
or $stack->[$fidx - 1]->{_name} ne $arch->{_name}) |
386 |
|
|
{ |
387 |
|
|
splice (@$stack, $fidx, 0, $arch); |
388 |
|
|
} |
389 |
|
|
|
390 |
|
|
} elsif ($m eq 'auto') { |
391 |
|
|
my $fidx = stack_find_floor ($stack, 'from_top'); |
392 |
|
|
my $widx = stack_find_wall ($stack); |
393 |
|
|
|
394 |
|
|
if (arch_is_floor ($arch)) { # we want to place a floor tile |
395 |
|
|
|
396 |
|
|
if (arch_is_floor ($stack->[$fidx])) { # replace |
397 |
|
|
$stack->[$fidx] = $arch; |
398 |
|
|
|
399 |
|
|
} else { # insert on bottom |
400 |
|
|
unshift @$stack, $arch; |
401 |
|
|
} |
402 |
|
|
|
403 |
|
|
} elsif (arch_is_wall ($arch)) { # we want to place a wall |
404 |
|
|
|
405 |
|
|
if (arch_is_wall ($stack->[$widx])) { # replace |
406 |
|
|
$stack->[$widx] = $arch; |
407 |
|
|
|
408 |
|
|
} else { # insert above floor |
409 |
|
|
splice (@$stack, $fidx + 1, 0, $arch); |
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
} else { |
413 |
|
|
|
414 |
|
|
if (arch_is_wall ($stack->[$widx])) { |
415 |
elmex |
1.9 |
# if we have a wall above the floor, replace it with the to place item |
416 |
|
|
$stack->[$widx] = $arch; |
417 |
elmex |
1.6 |
return; |
418 |
|
|
} |
419 |
|
|
|
420 |
|
|
if (@$stack == 0 |
421 |
|
|
or not ($stack->[-1]) |
422 |
|
|
or $stack->[-1]->{_name} ne $arch->{_name}) |
423 |
|
|
{ |
424 |
|
|
push @$stack, $arch; |
425 |
|
|
} |
426 |
|
|
} |
427 |
|
|
} |
428 |
|
|
} |
429 |
|
|
|
430 |
elmex |
1.12 |
package GCE::EditAction::Select; |
431 |
elmex |
1.11 |
use GCE::Util; |
432 |
|
|
use Gtk2; |
433 |
elmex |
1.12 |
use Crossfire; |
434 |
|
|
use Storable qw/dclone/; |
435 |
elmex |
1.11 |
use strict; |
436 |
|
|
|
437 |
|
|
our @ISA = qw/GCE::EditAction::RadioModed/; |
438 |
|
|
|
439 |
elmex |
1.12 |
sub name { 'select' } |
440 |
elmex |
1.11 |
|
441 |
elmex |
1.15 |
sub special_arrow { 'GDK_CIRCLE' } |
442 |
|
|
|
443 |
elmex |
1.11 |
sub init { |
444 |
|
|
my ($self) = @_; |
445 |
|
|
|
446 |
|
|
my $vb = new Gtk2::VBox; |
447 |
|
|
|
448 |
elmex |
1.19 |
$vb->pack_start (my $bt = Gtk2::Button->new_with_mnemonic ("_copy"), 0, 1, 0); |
449 |
elmex |
1.12 |
$bt->signal_connect (clicked => sub { $self->copy }); |
450 |
|
|
$vb->pack_start ($self->{paste_top} = Gtk2::CheckButton->new ('paste on top'), 0, 1, 0); |
451 |
elmex |
1.19 |
$vb->pack_start (my $bt = Gtk2::Button->new_with_mnemonic ("paste (_v)"), 0, 1, 0); |
452 |
elmex |
1.12 |
$bt->signal_connect (clicked => sub { $self->paste }); |
453 |
|
|
$vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); |
454 |
|
|
$self->add_mode_button ($vb, "place", "place"); |
455 |
|
|
$self->add_mode_button ($vb, "erase", "erase"); |
456 |
elmex |
1.15 |
$self->add_mode_button ($vb, "perl", "perl"); |
457 |
elmex |
1.19 |
$vb->pack_start (my $bt = Gtk2::Button->new_with_mnemonic ("i_nvoke"), 0, 1, 0); |
458 |
elmex |
1.12 |
$bt->signal_connect (clicked => sub { $self->invoke }); |
459 |
elmex |
1.11 |
|
460 |
|
|
$self->tool_widget ($vb); |
461 |
|
|
} |
462 |
|
|
|
463 |
elmex |
1.12 |
sub copy { |
464 |
|
|
my ($self) = @_; |
465 |
|
|
|
466 |
|
|
return unless $self->{selection}->{a}; |
467 |
|
|
my ($x1, $y1) = @{$self->{selection}->{a}}; |
468 |
|
|
my ($x2, $y2) = @{$self->{selection}->{b}}; |
469 |
|
|
|
470 |
|
|
if ($x1 > $x2) { ($x2, $x1) = ($x1, $x2) } |
471 |
|
|
if ($y1 > $y2) { ($y2, $y1) = ($y1, $y2) } |
472 |
|
|
|
473 |
|
|
my $map = $self->{selection}->{map}; |
474 |
|
|
|
475 |
|
|
$self->{copy_coords} = [$x1, $y1, $x2, $y2]; |
476 |
|
|
$self->{copy}; |
477 |
|
|
for (my $x = $x1; $x <= $x2; $x++) { |
478 |
|
|
for (my $y = $y1; $y <= $y2; $y++) { |
479 |
|
|
$self->{copy}->[$x - $x1]->[$y - $y1] = $map->get ($x, $y); |
480 |
|
|
} |
481 |
|
|
} |
482 |
|
|
} |
483 |
|
|
|
484 |
|
|
sub paste { |
485 |
|
|
my ($self, $xp, $yp) = @_; |
486 |
|
|
|
487 |
|
|
return unless $self->{selection}->{a}; |
488 |
|
|
|
489 |
|
|
my ($x1, $y1); |
490 |
|
|
|
491 |
elmex |
1.15 |
if (defined $xp) { |
492 |
elmex |
1.12 |
($x1, $y1) = ($xp, $yp); |
493 |
|
|
} else { |
494 |
|
|
($x1, $y1) = @{$self->{selection}->{a}}; |
495 |
|
|
} |
496 |
|
|
|
497 |
|
|
my $map = $self->{selection}->{map}; |
498 |
|
|
|
499 |
|
|
my $p_o_top = $self->{paste_top}->get_active * 1; |
500 |
|
|
|
501 |
|
|
my $w = $self->{copy_coords}->[2] - $self->{copy_coords}->[0]; |
502 |
|
|
my $h = $self->{copy_coords}->[3] - $self->{copy_coords}->[1]; |
503 |
|
|
$self->{copy}; |
504 |
|
|
$self->SUPER::begin ($map, $x1, $y1); |
505 |
|
|
for (my $x = $x1; $x <= ($x1 + $w); $x++) { |
506 |
|
|
for (my $y = $y1; $y <= ($y1 + $h); $y++) { |
507 |
|
|
my $cstck = $map->get ($x, $y); |
508 |
|
|
|
509 |
|
|
if ($p_o_top) { |
510 |
|
|
push @$cstck, @{dclone ($self->{copy}->[$x - $x1]->[$y - $y1] || [])}; |
511 |
|
|
$map->change_stack ($x, $y, $cstck); |
512 |
|
|
} else { |
513 |
|
|
$map->change_stack ($x, $y, dclone ($self->{copy}->[$x - $x1]->[$y - $y1] || [])); |
514 |
|
|
} |
515 |
|
|
} |
516 |
|
|
} |
517 |
|
|
$self->SUPER::end ($map); |
518 |
|
|
$map->invalidate_all; |
519 |
|
|
} |
520 |
|
|
|
521 |
|
|
sub invoke { |
522 |
|
|
my ($self) = @_; |
523 |
|
|
|
524 |
|
|
return unless $self->{selection}->{a}; |
525 |
|
|
my ($x1, $y1) = @{$self->{selection}->{a}}; |
526 |
|
|
my ($x2, $y2) = @{$self->{selection}->{b}}; |
527 |
|
|
|
528 |
|
|
if ($x1 > $x2) { ($x2, $x1) = ($x1, $x2) } |
529 |
|
|
if ($y1 > $y2) { ($y2, $y1) = ($y1, $y2) } |
530 |
|
|
|
531 |
|
|
my $map = $self->{selection}->{map}; |
532 |
|
|
|
533 |
|
|
my $m = $self->get_mode; |
534 |
|
|
$self->SUPER::begin ($map, $x1, $y1); |
535 |
|
|
for (my $x = $x1; $x <= $x2; $x++) { |
536 |
|
|
for (my $y = $y1; $y <= $y2; $y++) { |
537 |
|
|
if ($m eq 'place') { |
538 |
|
|
$::MAINWIN->{edit_collection}{place}->edit ($map, $x, $y); |
539 |
|
|
} elsif ($m eq 'erase') { |
540 |
|
|
$::MAINWIN->{edit_collection}{erase}->edit ($map, $x, $y); |
541 |
elmex |
1.15 |
} elsif ($m eq 'perl') { |
542 |
|
|
$::MAINWIN->{edit_collection}{perl}->edit ($map, $x, $y); |
543 |
elmex |
1.12 |
} |
544 |
|
|
} |
545 |
|
|
} |
546 |
|
|
$self->SUPER::end ($map); |
547 |
|
|
} |
548 |
|
|
|
549 |
elmex |
1.11 |
sub want_cursor { 0 } |
550 |
|
|
|
551 |
|
|
sub begin { |
552 |
|
|
my ($self, $map, $x, $y) = @_; |
553 |
|
|
|
554 |
|
|
delete $self->{selection}; |
555 |
|
|
|
556 |
elmex |
1.12 |
$self->{selection}->{a} = [$x, $y]; |
557 |
elmex |
1.11 |
$self->edit ($map, $x, $y); |
558 |
elmex |
1.12 |
} |
559 |
elmex |
1.11 |
|
560 |
elmex |
1.12 |
sub end { |
561 |
elmex |
1.11 |
} |
562 |
|
|
|
563 |
|
|
sub edit { |
564 |
|
|
my ($self, $map, $x, $y) = @_; |
565 |
|
|
|
566 |
|
|
$self->{selection}->{b} = [$x, $y]; |
567 |
elmex |
1.12 |
$self->{selection}->{map} = $map; |
568 |
elmex |
1.11 |
$self->update_overlay ($map); |
569 |
|
|
} |
570 |
|
|
|
571 |
|
|
sub update_overlay { |
572 |
|
|
my ($self, $map) = @_; |
573 |
|
|
|
574 |
elmex |
1.12 |
my ($x1, $y1) = @{$self->{selection}->{a}}; |
575 |
|
|
my ($x2, $y2) = @{$self->{selection}->{b}}; |
576 |
|
|
|
577 |
|
|
if ($x1 > $x2) { ($x2, $x1) = ($x1, $x2) } |
578 |
|
|
if ($y1 > $y2) { ($y2, $y1) = ($y1, $y2) } |
579 |
elmex |
1.11 |
|
580 |
elmex |
1.12 |
my $w = ($x2 - $x1) + 1; |
581 |
|
|
my $h = ($y2 - $y1) + 1; |
582 |
|
|
|
583 |
|
|
$map->overlay (selection => |
584 |
|
|
$x1 * TILESIZE, $y1 * TILESIZE, |
585 |
|
|
$w * TILESIZE, $h * TILESIZE, |
586 |
|
|
sub { |
587 |
|
|
my ($self, $x, $y) = @_; |
588 |
|
|
$self->{window}->draw_rectangle ( |
589 |
|
|
$_ & 1 ? $self->style->black_gc : $self->style->white_gc, |
590 |
|
|
0, |
591 |
|
|
$x + $_, $y + $_, |
592 |
|
|
($w * TILESIZE) - 1 - $_ * 2, |
593 |
|
|
($h * TILESIZE) - 1 - $_ * 2 |
594 |
|
|
) for 0..3; |
595 |
|
|
} |
596 |
|
|
); |
597 |
elmex |
1.11 |
} |
598 |
|
|
|
599 |
elmex |
1.1 |
package GCE::EditAction::Erase; |
600 |
elmex |
1.7 |
use GCE::Util; |
601 |
|
|
use Gtk2; |
602 |
|
|
use strict; |
603 |
elmex |
1.1 |
|
604 |
elmex |
1.7 |
our @ISA = qw/GCE::EditAction::RadioModed/; |
605 |
elmex |
1.1 |
|
606 |
elmex |
1.10 |
sub name { 'erase' } |
607 |
|
|
|
608 |
elmex |
1.1 |
sub want_cursor { 0 } |
609 |
|
|
|
610 |
elmex |
1.15 |
sub special_arrow { 'GDK_DIAMOND_CROSS' } |
611 |
elmex |
1.10 |
|
612 |
elmex |
1.7 |
sub init { |
613 |
|
|
my ($self) = @_; |
614 |
|
|
|
615 |
|
|
my $vb = new Gtk2::VBox; |
616 |
|
|
$self->add_mode_button ($vb, "top", "top"); |
617 |
|
|
$self->add_mode_button ($vb, "walls", "walls"); |
618 |
|
|
$self->add_mode_button ($vb, "above floor", "above", 'default'); |
619 |
|
|
$self->add_mode_button ($vb, "floor", "floor"); |
620 |
|
|
$self->add_mode_button ($vb, "below floor", "below"); |
621 |
|
|
$self->add_mode_button ($vb, "bottom", "bottom"); |
622 |
|
|
$self->add_mode_button ($vb, "pick match", "match"); |
623 |
|
|
|
624 |
|
|
$self->tool_widget ($vb); |
625 |
|
|
|
626 |
|
|
$vb->pack_start ($self->{no_wall_check} = Gtk2::CheckButton->new ("exclude walls"), 0, 1, 0); |
627 |
|
|
$vb->pack_start ($self->{no_monsters_check} = Gtk2::CheckButton->new ("exclude monsters"), 0, 1, 0); |
628 |
|
|
} |
629 |
|
|
|
630 |
|
|
sub check_excluded { |
631 |
|
|
my ($self, $arch) = @_; |
632 |
|
|
|
633 |
|
|
my $a1 = $self->{no_monsters_check}->get_active; |
634 |
|
|
my $a2 = $self->{no_wall_check}->get_active; |
635 |
|
|
|
636 |
|
|
my $r = ($self->{no_wall_check}->get_active && arch_is_wall ($arch)) |
637 |
|
|
|| ($self->{no_monsters_check}->get_active && arch_is_monster ($arch)); |
638 |
|
|
return $r; |
639 |
|
|
} |
640 |
|
|
|
641 |
elmex |
1.1 |
sub begin { |
642 |
elmex |
1.10 |
my ($self, $map, $x, $y) = @_; |
643 |
elmex |
1.1 |
|
644 |
elmex |
1.10 |
$self->SUPER::begin ($map, $x, $y); |
645 |
|
|
$self->edit ($map, $x, $y); |
646 |
elmex |
1.1 |
} |
647 |
|
|
|
648 |
|
|
sub edit { |
649 |
elmex |
1.10 |
my ($self, $map, $x, $y) = @_; |
650 |
elmex |
1.1 |
|
651 |
|
|
my $as = $map->get ($x, $y); |
652 |
elmex |
1.7 |
$self->stack_action ($as); |
653 |
root |
1.3 |
$map->change_stack ($x, $y, $as); |
654 |
elmex |
1.1 |
} |
655 |
|
|
|
656 |
elmex |
1.7 |
sub stack_action { |
657 |
|
|
my ($self, $stack) = @_; |
658 |
|
|
|
659 |
|
|
my $m = $self->get_mode; |
660 |
|
|
|
661 |
|
|
if ($m eq 'top') { |
662 |
|
|
pop @$stack; |
663 |
|
|
|
664 |
|
|
} elsif ($m eq 'bottom') { |
665 |
|
|
shift @$stack; |
666 |
|
|
|
667 |
|
|
} elsif ($m eq 'above') { |
668 |
|
|
my $fidx = stack_find_floor ($stack, 'from_top'); |
669 |
|
|
|
670 |
|
|
if (arch_is_floor ($stack->[$fidx]) and $stack->[$fidx + 1]) { |
671 |
|
|
splice (@$stack, $fidx + 1, 1) |
672 |
|
|
unless $self->check_excluded ($stack->[$fidx + 1]) |
673 |
|
|
|
674 |
|
|
} elsif (not arch_is_floor ($stack->[$fidx])) { |
675 |
|
|
splice (@$stack, $fidx, 1) |
676 |
|
|
unless $self->check_excluded ($stack->[$fidx]) |
677 |
|
|
|
678 |
|
|
} |
679 |
|
|
|
680 |
|
|
} elsif ($m eq 'below') { |
681 |
|
|
my $fidx = stack_find_floor ($stack, 'from_bottom'); |
682 |
|
|
|
683 |
|
|
if ($fidx > 0 and not arch_is_floor ($stack->[$fidx - 1])) { |
684 |
|
|
splice (@$stack, $fidx - 1, 1) |
685 |
|
|
unless $self->check_excluded ($stack->[$fidx - 1]) |
686 |
|
|
|
687 |
|
|
} elsif (not arch_is_floor ($stack->[$fidx])) { # no floor found |
688 |
|
|
splice (@$stack, $fidx, 1) |
689 |
|
|
unless $self->check_excluded ($stack->[$fidx]) |
690 |
|
|
|
691 |
|
|
} |
692 |
|
|
|
693 |
|
|
} elsif ($m eq 'walls') { |
694 |
|
|
my $widx = stack_find_wall ($stack, 'from_top'); |
695 |
|
|
|
696 |
|
|
while (arch_is_wall ($stack->[$widx])) { |
697 |
|
|
splice (@$stack, $widx, 1); |
698 |
|
|
$widx = stack_find_wall ($stack, 'from_top') |
699 |
|
|
} |
700 |
|
|
|
701 |
|
|
} elsif ($m eq 'floor') { |
702 |
|
|
my $fidx = stack_find_floor ($stack, 'from_top'); |
703 |
|
|
|
704 |
|
|
while (arch_is_floor ($stack->[$fidx])) { |
705 |
|
|
splice (@$stack, $fidx, 1); |
706 |
|
|
$fidx = stack_find_floor ($stack, 'from_top') |
707 |
|
|
} |
708 |
|
|
|
709 |
|
|
} elsif ($m eq 'match') { |
710 |
|
|
my $pick_name = $::MAINWIN->get_pick ()->{_name}; |
711 |
|
|
my $idx = stack_find ($stack, 'from_top', sub { $_[0]->{_name} eq $pick_name }); |
712 |
|
|
|
713 |
|
|
while ($stack->[$idx] and $stack->[$idx]->{_name} eq $pick_name) { |
714 |
|
|
splice (@$stack, $idx, 1); |
715 |
|
|
$idx = stack_find ($stack, 'from_top', sub { $_[0]->{_name} eq $pick_name }); |
716 |
|
|
} |
717 |
|
|
} |
718 |
|
|
} |
719 |
|
|
|
720 |
elmex |
1.18 |
package GCE::EditAction::ConnectExit; |
721 |
elmex |
1.16 |
use Storable qw/dclone/; |
722 |
|
|
use GCE::Util; |
723 |
|
|
use Gtk2; |
724 |
|
|
use File::Spec::Functions; |
725 |
|
|
use strict; |
726 |
|
|
|
727 |
|
|
our @ISA = qw/GCE::EditAction::RadioModed/; |
728 |
|
|
|
729 |
elmex |
1.18 |
sub name { 'connectexit' } |
730 |
elmex |
1.16 |
|
731 |
|
|
sub init { |
732 |
|
|
my ($self) = @_; |
733 |
|
|
|
734 |
|
|
my $vb = new Gtk2::VBox; |
735 |
|
|
$self->add_mode_button ($vb, "exit", "exit"); |
736 |
|
|
# $self->add_mode_button ($vb, "triggers", "trig"); |
737 |
elmex |
1.18 |
$vb->pack_start ($self->{sel_edt} = Gtk2::Entry->new, 0, 1, 0); |
738 |
|
|
$self->{sel_edt}->set_text (catfile ($Crossfire::LIB, 'maps')); |
739 |
|
|
|
740 |
elmex |
1.16 |
$vb->pack_start ($self->{sel_lbl} = Gtk2::Label->new, 0, 0, 0); |
741 |
|
|
$self->tool_widget ($vb); |
742 |
|
|
} |
743 |
|
|
|
744 |
|
|
sub want_cursor { 0 } |
745 |
|
|
|
746 |
|
|
sub begin { |
747 |
|
|
my ($self, $map, $x, $y, $mapedit) = @_; |
748 |
|
|
|
749 |
|
|
$self->edit ($map, $x, $y, $mapedit); |
750 |
|
|
} |
751 |
|
|
|
752 |
|
|
sub edit { |
753 |
|
|
my ($self, $map, $x, $y, $mapedit) = @_; |
754 |
|
|
|
755 |
|
|
my $pick = $::MAINWIN->get_pick; |
756 |
|
|
my $as = $map->get ($x, $y); |
757 |
|
|
|
758 |
|
|
my $exit; |
759 |
|
|
for (@$as) { |
760 |
elmex |
1.21 |
if (arch_is_exit ($_)) { |
761 |
elmex |
1.16 |
$exit = $_; |
762 |
|
|
} |
763 |
|
|
} |
764 |
|
|
|
765 |
elmex |
1.18 |
my $ent = $self->{sel_edt}->get_text; |
766 |
elmex |
1.16 |
if ($exit) { |
767 |
|
|
if ($self->{sel_exit}) { |
768 |
|
|
|
769 |
|
|
$exit->{hp} = $self->{sel_exit}->[3]; |
770 |
|
|
$exit->{sp} = $self->{sel_exit}->[4]; |
771 |
|
|
$exit->{slaying} = File::Spec->abs2rel ($self->{sel_exit}->[5], $ent); |
772 |
|
|
|
773 |
|
|
my $exit2 = $self->{sel_exit}->[0]; |
774 |
|
|
|
775 |
|
|
$exit2->{hp} = $x; |
776 |
|
|
$exit2->{sp} = $y; |
777 |
|
|
$exit2->{slaying} = File::Spec->abs2rel ($mapedit->{path}, $ent); |
778 |
|
|
|
779 |
|
|
unless ($exit2->{slaying} =~ m/^\.\./) { |
780 |
|
|
$exit2->{slaying} = '/' . $exit2->{slaying}; |
781 |
|
|
} |
782 |
|
|
unless ($exit->{slaying} =~ m/^\.\./) { |
783 |
|
|
$exit->{slaying} = '/' . $exit->{slaying}; |
784 |
|
|
} |
785 |
|
|
|
786 |
|
|
$self->SUPER::begin ($map, $x, $y, $mapedit); |
787 |
|
|
$map->change_stack ($x, $y, $as); |
788 |
|
|
$self->SUPER::end ($map); |
789 |
|
|
$self->SUPER::begin ($self->{sel_exit}->[1], $exit->{hp}, $exit->{sp}); |
790 |
|
|
$self->{sel_exit}->[1]->change_stack ($exit->{hp}, $exit->{sp}, $self->{sel_exit}->[2]); |
791 |
|
|
$self->SUPER::end ($self->{sel_exit}->[1]); |
792 |
|
|
|
793 |
|
|
quick_msg ($mapedit, "$exit->{slaying} ($x:$y) $exit->{_name} <=> $exit2->{slaying} ($exit2->{hp}:$exit2->{sp}) $exit2->{_name}", 0); |
794 |
|
|
|
795 |
|
|
$::MAINWIN->{edit_collection}{pick}->edit ($map, $x, $y); |
796 |
|
|
|
797 |
|
|
$self->{sel_exit} = undef; |
798 |
|
|
$self->{sel_lbl}->set_text (''); |
799 |
|
|
} else { |
800 |
|
|
$self->{sel_lbl}->set_text ("src: ($x:$y) $exit->{_name}"); |
801 |
|
|
$self->{sel_exit} = [$exit, $map, $as, $x, $y, $mapedit->{path}]; |
802 |
|
|
} |
803 |
|
|
} else { |
804 |
elmex |
1.18 |
if ($self->{sel_exit}) { |
805 |
|
|
|
806 |
|
|
my $exit2 = $self->{sel_exit}->[0]; |
807 |
|
|
|
808 |
|
|
$exit2->{hp} = $x; |
809 |
|
|
$exit2->{sp} = $y; |
810 |
|
|
$exit2->{slaying} = File::Spec->abs2rel ($mapedit->{path}, $ent); |
811 |
|
|
print "TO: $x:$y => $exit2->{slaying}\n"; |
812 |
|
|
|
813 |
|
|
unless ($exit2->{slaying} =~ m/^\.\./) { |
814 |
|
|
$exit2->{slaying} = '/' . $exit2->{slaying}; |
815 |
|
|
} |
816 |
|
|
|
817 |
|
|
$self->SUPER::begin ($self->{sel_exit}->[1], $exit->{hp}, $exit->{sp}); |
818 |
|
|
$self->{sel_exit}->[1]->change_stack ($self->{sel_exit}->[3], $self->{sel_exit}->[4], $self->{sel_exit}->[2]); |
819 |
|
|
$self->SUPER::end ($self->{sel_exit}->[1]); |
820 |
|
|
|
821 |
|
|
quick_msg ($mapedit, "$self->{sel_exit}->[5] ($self->{sel_exit}->[3]:$self->{sel_exit}->[4]) $self->{sel_exit}->[0]->{_name} => $exit2->{slaying} ($x:$y) $exit2->{_name}", 0); |
822 |
|
|
|
823 |
|
|
$::MAINWIN->{edit_collection}{pick}->edit ($map, $x, $y); |
824 |
|
|
|
825 |
|
|
$self->{sel_exit} = undef; |
826 |
|
|
$self->{sel_lbl}->set_text (''); |
827 |
|
|
} else { |
828 |
|
|
quick_msg ($mapedit, "no exit object found"); |
829 |
|
|
} |
830 |
elmex |
1.16 |
} |
831 |
|
|
|
832 |
|
|
# $self->stack_action ($as, dclone ($pick)); |
833 |
|
|
#$map->change_stack ($x, $y, $as); # insert_arch_stack_layer ($as, $arch)); |
834 |
|
|
} |
835 |
|
|
|
836 |
|
|
sub end {} |
837 |
elmex |
1.7 |
|
838 |
|
|
|
839 |
elmex |
1.1 |
=head1 AUTHOR |
840 |
|
|
|
841 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
842 |
|
|
http://home.schmorp.de/ |
843 |
|
|
|
844 |
|
|
Robin Redeker <elmex@ta-sa.org> |
845 |
|
|
http://www.ta-sa.org/ |
846 |
|
|
|
847 |
|
|
=cut |
848 |
root |
1.5 |
|
849 |
|
|
1 |
850 |
elmex |
1.1 |
|