1 |
elmex |
1.1 |
package GCE::InventoryEditor; |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
|
|
GCE::StackView - the stack window class for gce |
6 |
|
|
|
7 |
|
|
=cut |
8 |
|
|
|
9 |
|
|
use Gtk2; |
10 |
|
|
use Gtk2::Gdk::Keysyms; |
11 |
|
|
use Gtk2::SimpleMenu; |
12 |
|
|
|
13 |
root |
1.11 |
use Deliantra; |
14 |
|
|
use Deliantra::MapWidget; |
15 |
elmex |
1.4 |
use Storable qw/dclone/; |
16 |
elmex |
1.1 |
|
17 |
|
|
use Glib::Object::Subclass Gtk2::VBox; |
18 |
|
|
use GCE::Util; |
19 |
elmex |
1.7 |
use GCE::DragHelper; |
20 |
elmex |
1.9 |
use GCE::ArchRef; |
21 |
elmex |
1.1 |
|
22 |
|
|
use strict; |
23 |
|
|
|
24 |
|
|
sub INIT_INSTANCE { |
25 |
|
|
my ($self) = @_; |
26 |
|
|
|
27 |
|
|
$self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); |
28 |
|
|
$sw->add_with_viewport (my $vb = Gtk2::VBox->new); |
29 |
|
|
$vb->pack_start ($self->{invarch} = Gtk2::VBox->new, 0, 1, 0); |
30 |
|
|
$vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); |
31 |
|
|
$vb->pack_start ($self->{stackbox} = Gtk2::VBox->new, 1, 1, 0); |
32 |
|
|
|
33 |
|
|
$sw->set_policy ('automatic', 'automatic'); |
34 |
|
|
} |
35 |
|
|
|
36 |
elmex |
1.8 |
sub push_inv_hist { |
37 |
|
|
my ($self, $arch) = @_; |
38 |
|
|
push @{$self->{inv_hist}}, $arch; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
sub clear_inv_hist { |
42 |
|
|
my ($self) = @_; |
43 |
|
|
delete $self->{inv_hist}; |
44 |
|
|
} |
45 |
|
|
|
46 |
elmex |
1.1 |
sub set_arch { |
47 |
elmex |
1.9 |
my ($self, $ar) = @_; |
48 |
|
|
|
49 |
|
|
if ((defined $self->{cur_arch}) && ($self->{cur_arch} != $ar)) { |
50 |
|
|
$self->{cur_arch}->remove_on_change ('invedit') |
51 |
|
|
if defined $self->{cur_arch}; |
52 |
|
|
$ar->add_on_change (invedit => sub { $self->set_arch ($_[0]) }); |
53 |
|
|
|
54 |
|
|
} elsif (not defined $self->{cur_arch}) { |
55 |
|
|
$ar->add_on_change (invedit => sub { $self->set_arch ($_[0]) }); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
$self->{cur_arch} = $ar; |
59 |
elmex |
1.1 |
|
60 |
|
|
$self->{invarch}->remove ($_) for $self->{invarch}->get_children; |
61 |
elmex |
1.2 |
|
62 |
elmex |
1.9 |
if (($self->{inv_hist} || [])->[-1] != $ar) { |
63 |
|
|
# unless (@{$self->{inv_hist} || []}) { |
64 |
|
|
push @{$self->{inv_hist}}, $ar; |
65 |
elmex |
1.8 |
} |
66 |
|
|
|
67 |
|
|
for my $invar (@{$self->{inv_hist}}) { |
68 |
|
|
my $pba = new_arch_pb; |
69 |
elmex |
1.9 |
fill_pb_from_arch ($pba, $invar->getarch); |
70 |
elmex |
1.8 |
my $hb = Gtk2::HBox->new; |
71 |
|
|
$hb->pack_start ((new_from_pixbuf Gtk2::Image $pba), 0, 0, 0); |
72 |
elmex |
1.9 |
$hb->pack_start (my $elemhdl = Gtk2::Button->new ($invar->get ('_name')), 0, 1, 0); |
73 |
elmex |
1.8 |
$elemhdl->signal_connect (clicked => sub { |
74 |
|
|
while (pop @{$self->{inv_hist}} != $invar) { 1 } |
75 |
|
|
push @{$self->{inv_hist}}, $invar; |
76 |
elmex |
1.9 |
$::MAINWIN->{attr_edit}->set_arch ($invar); |
77 |
elmex |
1.8 |
}); |
78 |
|
|
GCE::DragHelper::set_drag_source ( |
79 |
elmex |
1.9 |
$elemhdl, arch => sub { { arch => $invar } } |
80 |
elmex |
1.8 |
); |
81 |
|
|
|
82 |
|
|
GCE::DragHelper::set_drag_sink ( |
83 |
|
|
$elemhdl, arch => sub { |
84 |
|
|
return unless $_[0]->{arch}; |
85 |
elmex |
1.9 |
$invar->add_inv (dclone ($_[0]->{arch}->getarch)); |
86 |
|
|
$self->set_arch ($invar) #XXX: untested yet |
87 |
elmex |
1.8 |
} |
88 |
|
|
); |
89 |
|
|
|
90 |
|
|
$self->{invarch}->add ($hb); |
91 |
|
|
} |
92 |
elmex |
1.1 |
|
93 |
|
|
$self->{stackbox}->remove ($_) for $self->{stackbox}->get_children; |
94 |
|
|
|
95 |
elmex |
1.11.2.1 |
warn "NOT YET IMPLEMENTED"; |
96 |
|
|
return; |
97 |
elmex |
1.9 |
my $inv = $ar->get_inv_refs; |
98 |
elmex |
1.1 |
my $idx = 0; |
99 |
|
|
|
100 |
|
|
for my $ia (@$inv) { |
101 |
|
|
my $pb = new_arch_pb; |
102 |
elmex |
1.7 |
my $ownidx = $idx; |
103 |
elmex |
1.1 |
|
104 |
elmex |
1.9 |
my $a = $ia->archetype; |
105 |
|
|
fill_pb_from_arch ($pb, $ia->getarch); |
106 |
elmex |
1.1 |
|
107 |
|
|
$self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
108 |
|
|
$hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); |
109 |
|
|
$delbtn->signal_connect (clicked => sub { |
110 |
|
|
|
111 |
|
|
#my $oldstack = [ @$stack ]; |
112 |
elmex |
1.9 |
$ar->remove_inv ($ownidx); #splice @$inv, $ownidx, 1; |
113 |
|
|
$self->set_arch ($ar); |
114 |
elmex |
1.1 |
}); |
115 |
|
|
|
116 |
|
|
$hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
117 |
|
|
$elemhdl->add (my $hb2 = Gtk2::HBox->new); |
118 |
|
|
$elemhdl->signal_connect (clicked => sub { |
119 |
elmex |
1.9 |
push @{$self->{inv_hist}}, $ia; |
120 |
|
|
$::MAINWIN->{attr_edit}->set_arch ($ia); |
121 |
elmex |
1.1 |
}); |
122 |
|
|
|
123 |
|
|
$hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
124 |
|
|
$img->set_alignment (0, 0.5); |
125 |
|
|
|
126 |
elmex |
1.10 |
$hb2->pack_start (my $lbl = Gtk2::Label->new ($ia->get ('_name')), 0, 0, 0); |
127 |
elmex |
1.1 |
$lbl->set_alignment (0, 0.5); |
128 |
|
|
|
129 |
elmex |
1.7 |
GCE::DragHelper::set_drag_source ( |
130 |
|
|
$elemhdl, arch => sub { |
131 |
|
|
{ arch => $inv->[$ownidx], inv => $inv, inv_idx => $ownidx } |
132 |
|
|
} |
133 |
|
|
); |
134 |
|
|
|
135 |
|
|
GCE::DragHelper::set_drag_sink ( |
136 |
|
|
$elemhdl, arch => sub { |
137 |
|
|
my ($darch) = @_; |
138 |
|
|
|
139 |
|
|
if (defined $darch->{inv_idx} && $darch->{inv} == $inv) { |
140 |
|
|
my $swapidx = $darch->{inv_idx}; |
141 |
elmex |
1.9 |
$ar->{arch}->swap_inv ($swapidx, $ownidx); |
142 |
elmex |
1.7 |
} else { |
143 |
elmex |
1.9 |
$darch->{arch}->replace_inv ($ownidx, dclone $darch->{arch}); |
144 |
elmex |
1.7 |
} |
145 |
|
|
|
146 |
elmex |
1.9 |
$self->set_arch ($ar); |
147 |
elmex |
1.7 |
} |
148 |
|
|
); |
149 |
elmex |
1.1 |
$idx++; |
150 |
|
|
} |
151 |
|
|
$self->show_all; |
152 |
|
|
|
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
=head1 AUTHOR |
156 |
|
|
|
157 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
158 |
|
|
http://home.schmorp.de/ |
159 |
|
|
|
160 |
|
|
Robin Redeker <elmex@ta-sa.org> |
161 |
|
|
http://www.ta-sa.org/ |
162 |
|
|
|
163 |
|
|
=cut |
164 |
|
|
1; |
165 |
|
|
|