ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/InventoryEditor.pm
Revision: 1.1
Committed: Wed Mar 15 19:04:07 2006 UTC (20 years, 8 months ago) by elmex
Branch: MAIN
Log Message:
added inventory editor and fixed some bugs in the attr editor

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) = @_;
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 $self->{invarch}->add ($hb);
43
44 $self->{stackbox}->remove ($_) for $self->{stackbox}->get_children;
45
46 my $inv = $arch->{inventory};
47 my $idx = 0;
48
49 for my $ia (@$inv) {
50 my $pb = new_arch_pb;
51
52 fill_pb_from_arch ($pb, $ia);
53
54 $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);
56 do {
57 my $ownidx = $idx;
58
59 $delbtn->signal_connect (clicked => sub {
60
61 #my $oldstack = [ @$stack ];
62 splice @$inv, $ownidx, 1;
63
64 $self->set_arch ($arch);
65 });
66 };
67
68 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
69 $elemhdl->add (my $hb2 = Gtk2::HBox->new);
70 $elemhdl->signal_connect (clicked => sub {
71 $::MAINWIN->update_attr_editor ($a, sub {
72 # $mapedit->change_begin (ref $self);
73 # $mapedit->change_stack ($x, $y, $stack);
74 # # XXX: Put this into a generic function!!! See also EditTools.pm
75 # # FIXME: Fix the automatic update on undo here!
76 # if (my $changeset = $mapedit->change_end) {
77 # splice @{ $mapedit->{undo_stack} ||= [] },
78 # $mapedit->{undo_stack_pos}++, 1e6,
79 # $changeset;
80 # }
81 });
82 });
83
84 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
85 $img->set_alignment (0, 0.5);
86
87 $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0);
88 $lbl->set_alignment (0, 0.5);
89
90 $elemhdl->drag_source_set (['button1_mask'], ['move'],
91 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
92 );
93 $elemhdl->drag_dest_set (all => ['move'],
94 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
95 );
96
97 do {
98 my $ownidx = $idx;
99
100 $elemhdl->signal_connect (drag_data_get => sub {
101 my ($widget, $context, $data, $info, $time) = @_;
102
103 $data->set ($data->target, 8, "inventory:$ownidx");
104 });
105
106 # XXX: I'm unsure here, do i have to issue a get request?
107 # And what if i get the data twice? Wait for transaction end?
108 $elemhdl->signal_connect (drag_data_received => sub {
109 my ($widget, $context, $wx, $wy, $data, $info, $time) = @_;
110
111 if (($data->length >= 0) && ($data->format == 8)) {
112
113 $context->finish (1, 0, $time);
114
115 if ($data->data =~ m/inventory:(\d+)/) {
116 my $swapidx = int $1;
117
118 ($inv->[$swapidx], $inv->[$ownidx])
119 = ($inv->[$ownidx], $inv->[$swapidx]);
120
121 $self->set_arch ($arch);
122 }
123
124 return;
125 }
126 $context->finish (0, 0, $time);
127 });
128 };
129 $idx++;
130 }
131 $self->show_all;
132
133 }
134
135 =head1 AUTHOR
136
137 Marc Lehmann <schmorp@schmorp.de>
138 http://home.schmorp.de/
139
140 Robin Redeker <elmex@ta-sa.org>
141 http://www.ta-sa.org/
142
143 =cut
144 1;
145