ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/InventoryEditor.pm
Revision: 1.2
Committed: Wed Mar 15 21:45:54 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.1: +36 -4 lines
Log Message:
fixed cursors

File Contents

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