… | |
… | |
12 | |
12 | |
13 | use Crossfire; |
13 | use Crossfire; |
14 | use Crossfire::MapWidget; |
14 | use Crossfire::MapWidget; |
15 | |
15 | |
16 | use GCE::AttrEdit; |
16 | use GCE::AttrEdit; |
|
|
17 | use GCE::Util; |
17 | |
18 | |
18 | use Glib::Object::Subclass Gtk2::VBox; |
19 | use Glib::Object::Subclass Gtk2::VBox; |
|
|
20 | |
|
|
21 | use Storable qw/dclone/; |
19 | |
22 | |
20 | use strict; |
23 | use strict; |
21 | |
24 | |
22 | sub INIT_INSTANCE { |
25 | sub INIT_INSTANCE { |
23 | my ($self) = @_; |
26 | my ($self) = @_; |
… | |
… | |
34 | |
37 | |
35 | $self->{stackbox}->remove ($_); |
38 | $self->{stackbox}->remove ($_); |
36 | } |
39 | } |
37 | |
40 | |
38 | my $stack = $mapedit->get ($x, $y); |
41 | my $stack = $mapedit->get ($x, $y); |
39 | my $idx = (@$stack - 1); |
42 | my $idx = $stack ? (@$stack - 1) : 0; |
40 | |
43 | |
|
|
44 | if ($stack) { |
41 | for (reverse @$stack) { |
45 | for (reverse @$stack) { |
42 | # FIXME: How to change a stack with a virtual arch???? |
46 | # FIXME: How to change a stack with a virtual arch???? |
43 | next if $_->{_virtual}; |
47 | next if $_->{_virtual}; |
|
|
48 | my $ownidx = $idx; |
44 | |
49 | |
45 | #my $a = $_->{_virtual} || $_; |
50 | #my $a = $_->{_virtual} || $_; |
46 | my $a = $_; |
51 | my $a = $_; |
47 | |
52 | |
48 | # this is awful, is this really the best way? |
53 | # this is awful, is this really the best way? |
49 | my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; |
54 | my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; |
50 | $pb->fill (0x00000000); |
|
|
51 | |
55 | |
52 | $TILE->composite ($pb, |
56 | fill_pb_from_arch ($pb, $a); |
53 | 0, 0, |
|
|
54 | TILESIZE, TILESIZE, |
|
|
55 | - ($a->{_face} % 64) * TILESIZE, - TILESIZE * int $a->{_face} / 64, |
|
|
56 | 1, 1, 'nearest', 255 |
|
|
57 | ); |
|
|
58 | |
57 | |
59 | $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
58 | $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
60 | $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); |
59 | $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); |
61 | do { |
60 | $delbtn->signal_connect (clicked => sub { |
62 | my $ownidx = $idx; |
|
|
63 | |
61 | |
64 | $delbtn->signal_connect (clicked => sub { |
62 | #my $oldstack = [ @$stack ]; |
|
|
63 | splice @$stack, $ownidx, 1; |
65 | |
64 | |
66 | #my $oldstack = [ @$stack ]; |
65 | # XXX: Insert undo here! |
67 | splice @$stack, $ownidx, 1; |
66 | $mapedit->set ($x, $y, $stack); |
68 | |
67 | |
69 | # XXX: Insert undo here! |
|
|
70 | $mapedit->set ($x, $y, $stack); |
|
|
71 | |
|
|
72 | # XXX: force an update ? maybe some more intelligent update later? |
68 | # XXX: force an update ? maybe some more intelligent update later? |
73 | $self->set_stack ($mapedit, $x, $y); |
69 | $self->set_stack ($mapedit, $x, $y); |
74 | }); |
|
|
75 | }; |
|
|
76 | |
|
|
77 | $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
|
|
78 | $elemhdl->add (my $hb2 = Gtk2::HBox->new); |
|
|
79 | $elemhdl->signal_connect (clicked => sub { |
|
|
80 | $::MAINWIN->set_pick ($a); |
|
|
81 | $::MAINWIN->update_attr_editor ($a, sub { |
|
|
82 | $mapedit->change_begin (ref $self); |
|
|
83 | $mapedit->change_stack ($x, $y, $stack); |
|
|
84 | # XXX: Put this into a generic function!!! See also EditTools.pm |
|
|
85 | # FIXME: Fix the automatic update on undo here! |
|
|
86 | if (my $changeset = $mapedit->change_end) { |
|
|
87 | splice @{ $mapedit->{undo_stack} ||= [] }, |
|
|
88 | $mapedit->{undo_stack_pos}++, 1e6, |
|
|
89 | $changeset; |
|
|
90 | } |
|
|
91 | }); |
|
|
92 | }); |
|
|
93 | |
|
|
94 | $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
|
|
95 | $img->set_alignment (0, 0.5); |
|
|
96 | |
|
|
97 | $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0); |
|
|
98 | $lbl->set_alignment (0, 0.5); |
|
|
99 | |
|
|
100 | $elemhdl->drag_source_set (['button1_mask'], ['move'], |
|
|
101 | { target => 'STRING', flags => [], info => 'TARGET_STRING' } |
|
|
102 | ); |
|
|
103 | $elemhdl->drag_dest_set (all => ['move'], |
|
|
104 | { target => 'STRING', flags => [], info => 'TARGET_STRING' } |
|
|
105 | ); |
|
|
106 | |
|
|
107 | do { |
|
|
108 | my $ownidx = $idx; |
|
|
109 | |
|
|
110 | $elemhdl->signal_connect (drag_data_get => sub { |
|
|
111 | my ($widget, $context, $data, $info, $time) = @_; |
|
|
112 | |
|
|
113 | $data->set ($data->target, 8, "stack:$ownidx"); |
|
|
114 | }); |
70 | }); |
115 | |
71 | |
116 | # XXX: I'm unsure here, do i have to issue a get request? |
72 | $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
117 | # And what if i get the data twice? Wait for transaction end? |
73 | $elemhdl->add (my $hb2 = Gtk2::HBox->new); |
118 | $elemhdl->signal_connect (drag_data_received => sub { |
74 | $elemhdl->signal_connect (clicked => sub { |
119 | my ($widget, $context, $wx, $wy, $data, $info, $time) = @_; |
75 | my $ar = |
|
|
76 | GCE::ArchRef->new ( |
|
|
77 | arch => $a, |
|
|
78 | cb => sub { |
|
|
79 | $mapedit->change_begin (ref $self); |
|
|
80 | $mapedit->change_stack ($x, $y, $stack); |
|
|
81 | # XXX: Put this into a generic function!!! See also EditTools.pm |
|
|
82 | # FIXME: Fix the automatic update on undo here! |
|
|
83 | if (my $changeset = $mapedit->change_end) { |
|
|
84 | splice @{ $mapedit->{undo_stack} ||= [] }, |
|
|
85 | $mapedit->{undo_stack_pos}++, 1e6, |
|
|
86 | $changeset; |
|
|
87 | } |
|
|
88 | } |
|
|
89 | ); |
120 | |
90 | |
121 | if (($data->length >= 0) && ($data->format == 8)) { |
91 | $::MAINWIN->update_attr_editor ($a) |
|
|
92 | }); |
122 | |
93 | |
123 | $context->finish (1, 0, $time); |
94 | $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
|
|
95 | $img->set_alignment (0, 0.5); |
124 | |
96 | |
125 | if ($data->data =~ m/stack:(\d+)/) { |
97 | $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0); |
126 | my $swapidx = int $1; |
98 | $lbl->set_alignment (0, 0.5); |
127 | |
99 | |
128 | ($stack->[$swapidx], $stack->[$ownidx]) |
100 | $elemhdl->drag_source_set (['button1_mask'], ['move'], |
129 | = ($stack->[$ownidx], $stack->[$swapidx]); |
101 | { target => 'STRING', flags => [], info => 'TARGET_STRING' } |
|
|
102 | ); |
|
|
103 | $elemhdl->drag_dest_set (all => ['move'], |
|
|
104 | { target => 'STRING', flags => [], info => 'TARGET_STRING' } |
|
|
105 | ); |
130 | |
106 | |
131 | # XXX: Insert undo here! |
107 | GCE::DragHelper::set_drag_source ( |
132 | $mapedit->set ($x, $y, $stack); |
108 | $elemhdl, arch => sub { |
|
|
109 | { arch => $stack->[$ownidx], stk => $stack, stk_idx => $ownidx } |
|
|
110 | } |
|
|
111 | ); |
133 | |
112 | |
134 | $self->set_stack ($mapedit, $x, $y); |
113 | GCE::DragHelper::set_drag_sink ( |
135 | } |
114 | $elemhdl, arch => sub { |
|
|
115 | my ($darch) = @_; |
136 | |
116 | |
137 | return; |
117 | if (defined $darch->{stk_idx} and $darch->{stk} == $stack) { |
|
|
118 | my $swapidx = $darch->{stk_idx}; |
|
|
119 | ($stack->[$swapidx], $stack->[$ownidx]) |
|
|
120 | = ($stack->[$ownidx], $stack->[$swapidx]); |
|
|
121 | |
138 | } |
122 | } else { |
139 | $context->finish (0, 0, $time); |
123 | splice @$stack, $ownidx, 1, (dclone $darch->{arch}); |
140 | }); |
124 | } |
|
|
125 | |
|
|
126 | # XXX: Insert undo here! |
|
|
127 | $mapedit->set ($x, $y, $stack); |
|
|
128 | |
|
|
129 | $self->set_stack ($mapedit, $x, $y); |
141 | }; |
130 | } |
|
|
131 | ); |
142 | $idx--; |
132 | $idx--; |
|
|
133 | } |
143 | } |
134 | } |
144 | $self->show_all; |
135 | $self->show_all; |
145 | |
|
|
146 | } |
136 | } |
147 | |
137 | |
148 | =head1 AUTHOR |
138 | =head1 AUTHOR |
149 | |
139 | |
150 | Marc Lehmann <schmorp@schmorp.de> |
140 | Marc Lehmann <schmorp@schmorp.de> |