package GCE::InventoryEditor; =head1 NAME GCE::StackView - the stack window class for gce =cut use Gtk2; use Gtk2::Gdk::Keysyms; use Gtk2::SimpleMenu; use Crossfire; use Crossfire::MapWidget; use Storable qw/dclone/; use Glib::Object::Subclass Gtk2::VBox; use GCE::Util; use GCE::DragHelper; use strict; sub INIT_INSTANCE { my ($self) = @_; $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); $sw->add_with_viewport (my $vb = Gtk2::VBox->new); $vb->pack_start ($self->{invarch} = Gtk2::VBox->new, 0, 1, 0); $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); $vb->pack_start ($self->{stackbox} = Gtk2::VBox->new, 1, 1, 0); $sw->set_policy ('automatic', 'automatic'); } sub set_arch { my ($self, $arch, $cb) = @_; $self->{invarch}->remove ($_) for $self->{invarch}->get_children; my $pba = new_arch_pb; fill_pb_from_arch ($pba, $arch); my $hb = Gtk2::HBox->new; $hb->pack_start ((new_from_pixbuf Gtk2::Image $pba), 0, 0, 0); $hb->pack_start (my $elemhdl = Gtk2::Button->new ($arch->{_name}), 0, 1, 0); $elemhdl->signal_connect (clicked => sub { $::MAINWIN->update_attr_editor ($arch, $cb); }); GCE::DragHelper::set_drag_source ( $elemhdl, arch => sub { { arch => $arch } } ); GCE::DragHelper::set_drag_sink ( $elemhdl, arch => sub { return unless $_[0]->{arch}; push @{$arch->{inventory}}, dclone $_[0]->{arch}; $cb->() if $cb; $self->set_arch ($arch, $cb) } ); $self->{invarch}->add ($hb); $self->{stackbox}->remove ($_) for $self->{stackbox}->get_children; my $inv = $arch->{inventory}; my $idx = 0; for my $ia (@$inv) { my $pb = new_arch_pb; my $ownidx = $idx; my $a = $Crossfire::ARCH{$ia->{_name}}; fill_pb_from_arch ($pb, $ia); $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); $delbtn->signal_connect (clicked => sub { #my $oldstack = [ @$stack ]; splice @$inv, $ownidx, 1; $cb->() if $cb; $self->set_arch ($arch, $cb); }); $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); $elemhdl->add (my $hb2 = Gtk2::HBox->new); $elemhdl->signal_connect (clicked => sub { $::MAINWIN->update_attr_editor ($ia, $cb); }); $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); $img->set_alignment (0, 0.5); $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0); $lbl->set_alignment (0, 0.5); GCE::DragHelper::set_drag_source ( $elemhdl, arch => sub { { arch => $inv->[$ownidx], inv => $inv, inv_idx => $ownidx } } ); GCE::DragHelper::set_drag_sink ( $elemhdl, arch => sub { my ($darch) = @_; if (defined $darch->{inv_idx} && $darch->{inv} == $inv) { my $swapidx = $darch->{inv_idx}; ($inv->[$swapidx], $inv->[$ownidx]) = ($inv->[$ownidx], $inv->[$swapidx]); } else { splice @$inv, $ownidx, 1, (dclone $darch->{arch}); } $cb->() if $cb; $self->set_arch ($arch, $cb); } ); $idx++; } $self->show_all; } =head1 AUTHOR Marc Lehmann http://home.schmorp.de/ Robin Redeker http://www.ta-sa.org/ =cut 1;