… | |
… | |
29 | |
29 | |
30 | $sw->set_policy ('automatic', 'automatic'); |
30 | $sw->set_policy ('automatic', 'automatic'); |
31 | } |
31 | } |
32 | |
32 | |
33 | sub set_arch { |
33 | sub set_arch { |
34 | my ($self, $arch) = @_; |
34 | my ($self, $arch, $cb) = @_; |
35 | |
35 | |
36 | $self->{invarch}->remove ($_) for $self->{invarch}->get_children; |
36 | $self->{invarch}->remove ($_) for $self->{invarch}->get_children; |
37 | my $pba = new_arch_pb; |
37 | my $pba = new_arch_pb; |
38 | fill_pb_from_arch ($pba, $arch); |
38 | fill_pb_from_arch ($pba, $arch); |
39 | my $hb = Gtk2::HBox->new; |
39 | my $hb = Gtk2::HBox->new; |
40 | $hb->pack_start ((new_from_pixbuf Gtk2::Image $pba), 0, 0, 0); |
40 | $hb->pack_start ((new_from_pixbuf Gtk2::Image $pba), 0, 0, 0); |
41 | $hb->pack_start (my $elemhdl = Gtk2::Button->new ($arch->{_name}), 0, 1, 0); |
41 | $hb->pack_start (my $elemhdl = Gtk2::Button->new ($arch->{_name}), 0, 1, 0); |
|
|
42 | $elemhdl->drag_dest_set (all => ['move'], |
|
|
43 | { target => 'STRING', flags => [], info => 'TARGET_STRING' } |
|
|
44 | ); |
|
|
45 | # XXX: I'm unsure here, do i have to issue a get request? |
|
|
46 | # And what if i get the data twice? Wait for transaction end? |
|
|
47 | $elemhdl->signal_connect (drag_data_received => sub { |
|
|
48 | my ($widget, $context, $wx, $wy, $data, $info, $time) = @_; |
|
|
49 | |
|
|
50 | if (($data->length >= 0) && ($data->format == 8)) { |
|
|
51 | |
|
|
52 | $context->finish (1, 0, $time); |
|
|
53 | |
|
|
54 | if ($data->data =~ m/pick/) { |
|
|
55 | my $swapidx = int $1; |
|
|
56 | |
|
|
57 | # FIXME: do a deep clone |
|
|
58 | push @{$arch->{inventory}}, |
|
|
59 | { _name => $::MAINWIN->get_pick->{_name} }; |
|
|
60 | print "PUSH: " . $::MAINWIN->get_pick->{_name} . "\n"; |
|
|
61 | |
|
|
62 | $cb->() if $cb; |
|
|
63 | $self->set_arch ($arch, $cb); |
|
|
64 | } |
|
|
65 | |
|
|
66 | return; |
|
|
67 | } |
|
|
68 | $context->finish (0, 0, $time); |
|
|
69 | }); |
|
|
70 | |
42 | $self->{invarch}->add ($hb); |
71 | $self->{invarch}->add ($hb); |
43 | |
72 | |
44 | $self->{stackbox}->remove ($_) for $self->{stackbox}->get_children; |
73 | $self->{stackbox}->remove ($_) for $self->{stackbox}->get_children; |
45 | |
74 | |
46 | my $inv = $arch->{inventory}; |
75 | my $inv = $arch->{inventory}; |
47 | my $idx = 0; |
76 | my $idx = 0; |
48 | |
77 | |
49 | for my $ia (@$inv) { |
78 | for my $ia (@$inv) { |
50 | my $pb = new_arch_pb; |
79 | my $pb = new_arch_pb; |
51 | |
80 | |
|
|
81 | my $a = $Crossfire::ARCH{$ia->{_name}}; |
52 | fill_pb_from_arch ($pb, $ia); |
82 | fill_pb_from_arch ($pb, $a); |
53 | |
83 | |
54 | $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
84 | $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
55 | $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); |
85 | $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); |
56 | do { |
86 | do { |
57 | my $ownidx = $idx; |
87 | my $ownidx = $idx; |
… | |
… | |
59 | $delbtn->signal_connect (clicked => sub { |
89 | $delbtn->signal_connect (clicked => sub { |
60 | |
90 | |
61 | #my $oldstack = [ @$stack ]; |
91 | #my $oldstack = [ @$stack ]; |
62 | splice @$inv, $ownidx, 1; |
92 | splice @$inv, $ownidx, 1; |
63 | |
93 | |
|
|
94 | $cb->() if $cb; |
64 | $self->set_arch ($arch); |
95 | $self->set_arch ($arch, $cb); |
65 | }); |
96 | }); |
66 | }; |
97 | }; |
67 | |
98 | |
68 | $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
99 | $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
69 | $elemhdl->add (my $hb2 = Gtk2::HBox->new); |
100 | $elemhdl->add (my $hb2 = Gtk2::HBox->new); |
… | |
… | |
116 | my $swapidx = int $1; |
147 | my $swapidx = int $1; |
117 | |
148 | |
118 | ($inv->[$swapidx], $inv->[$ownidx]) |
149 | ($inv->[$swapidx], $inv->[$ownidx]) |
119 | = ($inv->[$ownidx], $inv->[$swapidx]); |
150 | = ($inv->[$ownidx], $inv->[$swapidx]); |
120 | |
151 | |
|
|
152 | $cb->() if $cb; |
121 | $self->set_arch ($arch); |
153 | $self->set_arch ($arch, $cb); |
122 | } |
154 | } |
123 | |
155 | |
124 | return; |
156 | return; |
125 | } |
157 | } |
126 | $context->finish (0, 0, $time); |
158 | $context->finish (0, 0, $time); |