ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/StackView.pm
(Generate patch)

Comparing deliantra/gde/GCE/StackView.pm (file contents):
Revision 1.11 by elmex, Sun Mar 19 19:30:38 2006 UTC vs.
Revision 1.16 by elmex, Thu Apr 20 08:58:29 2006 UTC

15 15
16use GCE::AttrEdit; 16use GCE::AttrEdit;
17use GCE::Util; 17use GCE::Util;
18 18
19use Glib::Object::Subclass Gtk2::VBox; 19use Glib::Object::Subclass Gtk2::VBox;
20
21use Storable qw/dclone/;
20 22
21use strict; 23use strict;
22 24
23sub INIT_INSTANCE { 25sub INIT_INSTANCE {
24 my ($self) = @_; 26 my ($self) = @_;
40 my $idx = $stack ? (@$stack - 1) : 0; 42 my $idx = $stack ? (@$stack - 1) : 0;
41 43
42 if ($stack) { 44 if ($stack) {
43 for (reverse @$stack) { 45 for (reverse @$stack) {
44 # FIXME: How to change a stack with a virtual arch???? 46 # FIXME: How to change a stack with a virtual arch????
45 next if $_->{_virtual}; 47 if ($_->{_virtual}) {
48 $idx--;
49 next
50 }
51 my $ownidx = $idx;
46 52
47 #my $a = $_->{_virtual} || $_; 53 #my $a = $_->{_virtual} || $_;
48 my $a = $_; 54 my $a = $_;
49 55
50 # this is awful, is this really the best way? 56 # this is awful, is this really the best way?
52 58
53 fill_pb_from_arch ($pb, $a); 59 fill_pb_from_arch ($pb, $a);
54 60
55 $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); 61 $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0);
56 $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); 62 $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0);
57 do {
58 my $ownidx = $idx;
59
60 $delbtn->signal_connect (clicked => sub { 63 $delbtn->signal_connect (clicked => sub {
61 64
62 #my $oldstack = [ @$stack ]; 65 #my $oldstack = [ @$stack ];
63 splice @$stack, $ownidx, 1; 66 splice @$stack, $ownidx, 1;
64 67
66 $mapedit->set ($x, $y, $stack); 69 $mapedit->set ($x, $y, $stack);
67 70
68 # XXX: force an update ? maybe some more intelligent update later? 71 # XXX: force an update ? maybe some more intelligent update later?
69 $self->set_stack ($mapedit, $x, $y); 72 $self->set_stack ($mapedit, $x, $y);
70 }); 73 });
71 };
72 74
73 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); 75 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
74 $elemhdl->add (my $hb2 = Gtk2::HBox->new); 76 $elemhdl->add (my $hb2 = Gtk2::HBox->new);
75 $elemhdl->signal_connect (clicked => sub { 77 $elemhdl->signal_connect (clicked => sub {
76 $::MAINWIN->set_pick ($a); 78 my $ar =
77 $::MAINWIN->update_attr_editor ($a, sub { 79 GCE::ArchRef->new (
80 arch => $a,
81 cb => sub {
78 $mapedit->change_begin (ref $self); 82 $mapedit->change_begin (ref $self);
79 $mapedit->change_stack ($x, $y, $stack); 83 $mapedit->change_stack ($x, $y, $stack);
80 # XXX: Put this into a generic function!!! See also EditTools.pm 84 # XXX: Put this into a generic function!!! See also EditTools.pm
81 # FIXME: Fix the automatic update on undo here! 85 # FIXME: Fix the automatic update on undo here!
82 if (my $changeset = $mapedit->change_end) { 86 if (my $changeset = $mapedit->change_end) {
83 splice @{ $mapedit->{undo_stack} ||= [] }, 87 splice @{ $mapedit->{undo_stack} ||= [] },
84 $mapedit->{undo_stack_pos}++, 1e6, 88 $mapedit->{undo_stack_pos}++, 1e6,
85 $changeset; 89 $changeset;
90 }
86 } 91 }
87 }); 92 );
93
94 $::MAINWIN->update_attr_editor ($ar)
88 }); 95 });
89 96
90 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); 97 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
91 $img->set_alignment (0, 0.5); 98 $img->set_alignment (0, 0.5);
92 99
98 ); 105 );
99 $elemhdl->drag_dest_set (all => ['move'], 106 $elemhdl->drag_dest_set (all => ['move'],
100 { target => 'STRING', flags => [], info => 'TARGET_STRING' } 107 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
101 ); 108 );
102 109
110 GCE::DragHelper::set_drag_source (
111 $elemhdl, arch => sub {
112 { arch => $stack->[$ownidx], stk => $stack, stk_idx => $ownidx }
103 do { 113 }
104 my $ownidx = $idx; 114 );
105 115
106 $elemhdl->signal_connect (drag_data_get => sub { 116 GCE::DragHelper::set_drag_sink (
107 my ($widget, $context, $data, $info, $time) = @_; 117 $elemhdl, arch => sub {
118 my ($darch) = @_;
108 119
109 $data->set ($data->target, 8, "stack:$ownidx"); 120 if (defined $darch->{stk_idx} and $darch->{stk} == $stack) {
110 }); 121 my $swapidx = $darch->{stk_idx};
122 ($stack->[$swapidx], $stack->[$ownidx])
123 = ($stack->[$ownidx], $stack->[$swapidx]);
111 124
112 # XXX: I'm unsure here, do i have to issue a get request? 125 } else {
113 # And what if i get the data twice? Wait for transaction end? 126 splice @$stack, $ownidx, 1, (dclone $darch->{arch});
114 $elemhdl->signal_connect (drag_data_received => sub { 127 }
115 my ($widget, $context, $wx, $wy, $data, $info, $time) = @_;
116 128
117 if (($data->length >= 0) && ($data->format == 8)) { 129 # XXX: Insert undo here!
130 $mapedit->set ($x, $y, $stack);
118 131
119 $context->finish (1, 0, $time);
120
121 if ($data->data =~ m/stack:(\d+)/) {
122 my $swapidx = int $1;
123
124 ($stack->[$swapidx], $stack->[$ownidx])
125 = ($stack->[$ownidx], $stack->[$swapidx]);
126
127 # XXX: Insert undo here!
128 $mapedit->set ($x, $y, $stack);
129
130 $self->set_stack ($mapedit, $x, $y); 132 $self->set_stack ($mapedit, $x, $y);
131 }
132
133 return;
134 }
135 $context->finish (0, 0, $time);
136 });
137 }; 133 }
134 );
138 $idx--; 135 $idx--;
139 } 136 }
140 } 137 }
141 $self->show_all; 138 $self->show_all;
142
143} 139}
144 140
145=head1 AUTHOR 141=head1 AUTHOR
146 142
147 Marc Lehmann <schmorp@schmorp.de> 143 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines