ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/InventoryEditor.pm
Revision: 1.3
Committed: Thu Mar 16 00:12:06 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.2: +0 -1 lines
Log Message:
added perl eval tool and removed debugging output

File Contents

# Content
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 use Crossfire;
14 use Crossfire::MapWidget;
15
16 use Glib::Object::Subclass Gtk2::VBox;
17 use GCE::Util;
18
19 use strict;
20
21 sub INIT_INSTANCE {
22 my ($self) = @_;
23
24 $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0);
25 $sw->add_with_viewport (my $vb = Gtk2::VBox->new);
26 $vb->pack_start ($self->{invarch} = Gtk2::VBox->new, 0, 1, 0);
27 $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0);
28 $vb->pack_start ($self->{stackbox} = Gtk2::VBox->new, 1, 1, 0);
29
30 $sw->set_policy ('automatic', 'automatic');
31 }
32
33 sub set_arch {
34 my ($self, $arch, $cb) = @_;
35
36 $self->{invarch}->remove ($_) for $self->{invarch}->get_children;
37 my $pba = new_arch_pb;
38 fill_pb_from_arch ($pba, $arch);
39 my $hb = Gtk2::HBox->new;
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);
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
61 $cb->() if $cb;
62 $self->set_arch ($arch, $cb);
63 }
64
65 return;
66 }
67 $context->finish (0, 0, $time);
68 });
69
70 $self->{invarch}->add ($hb);
71
72 $self->{stackbox}->remove ($_) for $self->{stackbox}->get_children;
73
74 my $inv = $arch->{inventory};
75 my $idx = 0;
76
77 for my $ia (@$inv) {
78 my $pb = new_arch_pb;
79
80 my $a = $Crossfire::ARCH{$ia->{_name}};
81 fill_pb_from_arch ($pb, $a);
82
83 $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0);
84 $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0);
85 do {
86 my $ownidx = $idx;
87
88 $delbtn->signal_connect (clicked => sub {
89
90 #my $oldstack = [ @$stack ];
91 splice @$inv, $ownidx, 1;
92
93 $cb->() if $cb;
94 $self->set_arch ($arch, $cb);
95 });
96 };
97
98 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
99 $elemhdl->add (my $hb2 = Gtk2::HBox->new);
100 $elemhdl->signal_connect (clicked => sub {
101 $::MAINWIN->update_attr_editor ($a, sub {
102 # $mapedit->change_begin (ref $self);
103 # $mapedit->change_stack ($x, $y, $stack);
104 # # XXX: Put this into a generic function!!! See also EditTools.pm
105 # # FIXME: Fix the automatic update on undo here!
106 # if (my $changeset = $mapedit->change_end) {
107 # splice @{ $mapedit->{undo_stack} ||= [] },
108 # $mapedit->{undo_stack_pos}++, 1e6,
109 # $changeset;
110 # }
111 });
112 });
113
114 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
115 $img->set_alignment (0, 0.5);
116
117 $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0);
118 $lbl->set_alignment (0, 0.5);
119
120 $elemhdl->drag_source_set (['button1_mask'], ['move'],
121 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
122 );
123 $elemhdl->drag_dest_set (all => ['move'],
124 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
125 );
126
127 do {
128 my $ownidx = $idx;
129
130 $elemhdl->signal_connect (drag_data_get => sub {
131 my ($widget, $context, $data, $info, $time) = @_;
132
133 $data->set ($data->target, 8, "inventory:$ownidx");
134 });
135
136 # XXX: I'm unsure here, do i have to issue a get request?
137 # And what if i get the data twice? Wait for transaction end?
138 $elemhdl->signal_connect (drag_data_received => sub {
139 my ($widget, $context, $wx, $wy, $data, $info, $time) = @_;
140
141 if (($data->length >= 0) && ($data->format == 8)) {
142
143 $context->finish (1, 0, $time);
144
145 if ($data->data =~ m/inventory:(\d+)/) {
146 my $swapidx = int $1;
147
148 ($inv->[$swapidx], $inv->[$ownidx])
149 = ($inv->[$ownidx], $inv->[$swapidx]);
150
151 $cb->() if $cb;
152 $self->set_arch ($arch, $cb);
153 }
154
155 return;
156 }
157 $context->finish (0, 0, $time);
158 });
159 };
160 $idx++;
161 }
162 $self->show_all;
163
164 }
165
166 =head1 AUTHOR
167
168 Marc Lehmann <schmorp@schmorp.de>
169 http://home.schmorp.de/
170
171 Robin Redeker <elmex@ta-sa.org>
172 http://www.ta-sa.org/
173
174 =cut
175 1;
176