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.19 by root, Thu Dec 27 22:28:01 2007 UTC

8 8
9use Gtk2; 9use Gtk2;
10use Gtk2::Gdk::Keysyms; 10use Gtk2::Gdk::Keysyms;
11use Gtk2::SimpleMenu; 11use Gtk2::SimpleMenu;
12 12
13use Crossfire; 13use Deliantra;
14use Crossfire::MapWidget; 14use Deliantra::MapWidget;
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) = @_;
26 $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); 28 $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0);
27 $sw->add_with_viewport ($self->{stackbox} = Gtk2::VBox->new); 29 $sw->add_with_viewport ($self->{stackbox} = Gtk2::VBox->new);
28 $sw->set_policy ('automatic', 'automatic'); 30 $sw->set_policy ('automatic', 'automatic');
29} 31}
30 32
33sub maybe_update_stack_for {
34 my ($self, $mapedit, $x, $y) = @_;
35 if (my $d = $self->{stack_dest}) {
36 if ($d->[0] eq $mapedit && $d->[1] == $x && $d->[2] == $y) {
37 $self->set_stack
38 }
39 }
40}
41
31sub set_stack { 42sub set_stack {
32 my ($self, $mapedit, $x, $y) = @_; 43 my ($self, $mapedit, $x, $y) = @_;
33 44
45 if (defined $mapedit) {
46 $self->{stack_dest} = [$mapedit, $x, $y];
47 } else {
48 $self->set_stack (@{$self->{stack_dest}})
49 if defined $self->{stack_dest};
50 return;
51 }
52
34 for ($self->{stackbox}->get_children) { 53 for ($self->{stackbox}->get_children) {
35
36 $self->{stackbox}->remove ($_); 54 $self->{stackbox}->remove ($_);
37 } 55 }
38 56
39 my $stack = $mapedit->get ($x, $y); 57 my $stack = $mapedit->get ($x, $y);
40 my $idx = $stack ? (@$stack - 1) : 0; 58 my $idx = $stack ? (@$stack - 1) : 0;
41 59
42 if ($stack) { 60 if ($stack) {
43 for (reverse @$stack) { 61 for (reverse @$stack) {
44 # FIXME: How to change a stack with a virtual arch???? 62 # FIXME: How to change a stack with a virtual arch????
45 next if $_->{_virtual}; 63 if ($_->{_virtual}) {
64 $idx--;
65 next
66 }
67 my $ownidx = $idx;
46 68
47 #my $a = $_->{_virtual} || $_; 69 #my $a = $_->{_virtual} || $_;
48 my $a = $_; 70 my $a = $_;
49 71
50 # this is awful, is this really the best way? 72 # this is awful, is this really the best way?
52 74
53 fill_pb_from_arch ($pb, $a); 75 fill_pb_from_arch ($pb, $a);
54 76
55 $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); 77 $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); 78 $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 { 79 $delbtn->signal_connect (clicked => sub {
61 80
62 #my $oldstack = [ @$stack ]; 81 #my $oldstack = [ @$stack ];
63 splice @$stack, $ownidx, 1; 82 splice @$stack, $ownidx, 1;
64 83
65 # XXX: Insert undo here! 84 $mapedit->change_begin ('stackedit');
66 $mapedit->set ($x, $y, $stack); 85 $mapedit->change_stack ($x, $y, $stack);
86
87 if (my $changeset = $mapedit->change_end) {
88 splice @{ $mapedit->{undo_stack} ||= [] },
89 $mapedit->{undo_stack_pos}++, 1e6,
90 $changeset;
91 }
67 92
68 # XXX: force an update ? maybe some more intelligent update later? 93 # XXX: force an update ? maybe some more intelligent update later?
69 $self->set_stack ($mapedit, $x, $y); 94 $self->set_stack ($mapedit, $x, $y);
70 }); 95 });
71 };
72 96
73 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); 97 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
74 $elemhdl->add (my $hb2 = Gtk2::HBox->new); 98 $elemhdl->add (my $hb2 = Gtk2::HBox->new);
75 $elemhdl->signal_connect (clicked => sub { 99 $elemhdl->signal_connect (clicked => sub {
76 $::MAINWIN->set_pick ($a); 100 my $ar =
77 $::MAINWIN->update_attr_editor ($a, sub { 101 GCE::ArchRef->new (
102 arch => $a,
103 source => 'map',
104 cb => sub {
78 $mapedit->change_begin (ref $self); 105 $mapedit->change_begin (ref $self);
79 $mapedit->change_stack ($x, $y, $stack); 106 $mapedit->change_stack ($x, $y, $stack);
80 # XXX: Put this into a generic function!!! See also EditTools.pm 107 # XXX: Put this into a generic function!!! See also EditTools.pm
81 # FIXME: Fix the automatic update on undo here! 108 # FIXME: Fix the automatic update on undo here!
82 if (my $changeset = $mapedit->change_end) { 109 if (my $changeset = $mapedit->change_end) {
83 splice @{ $mapedit->{undo_stack} ||= [] }, 110 splice @{ $mapedit->{undo_stack} ||= [] },
84 $mapedit->{undo_stack_pos}++, 1e6, 111 $mapedit->{undo_stack_pos}++, 1e6,
85 $changeset; 112 $changeset;
113 }
86 } 114 }
87 }); 115 );
116
117 $::MAINWIN->update_attr_editor ($ar)
88 }); 118 });
89 119
90 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); 120 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
91 $img->set_alignment (0, 0.5); 121 $img->set_alignment (0, 0.5);
92 122
98 ); 128 );
99 $elemhdl->drag_dest_set (all => ['move'], 129 $elemhdl->drag_dest_set (all => ['move'],
100 { target => 'STRING', flags => [], info => 'TARGET_STRING' } 130 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
101 ); 131 );
102 132
133 GCE::DragHelper::set_drag_source (
134 $elemhdl, arch => sub {
135 { arch => $stack->[$ownidx], stk => $stack, stk_idx => $ownidx }
103 do { 136 }
104 my $ownidx = $idx; 137 );
105 138
106 $elemhdl->signal_connect (drag_data_get => sub { 139 GCE::DragHelper::set_drag_sink (
107 my ($widget, $context, $data, $info, $time) = @_; 140 $elemhdl, arch => sub {
141 my ($darch) = @_;
108 142
109 $data->set ($data->target, 8, "stack:$ownidx"); 143 if (defined $darch->{stk_idx} and $darch->{stk} == $stack) {
110 }); 144 my $swapidx = $darch->{stk_idx};
145 ($stack->[$swapidx], $stack->[$ownidx])
146 = ($stack->[$ownidx], $stack->[$swapidx]);
111 147
112 # XXX: I'm unsure here, do i have to issue a get request? 148 } else {
113 # And what if i get the data twice? Wait for transaction end? 149 splice @$stack, $ownidx, 1, (dclone $darch->{arch});
114 $elemhdl->signal_connect (drag_data_received => sub { 150 }
115 my ($widget, $context, $wx, $wy, $data, $info, $time) = @_;
116 151
117 if (($data->length >= 0) && ($data->format == 8)) { 152 # XXX: Insert undo here!
153 $mapedit->set ($x, $y, $stack);
118 154
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); 155 $self->set_stack ($mapedit, $x, $y);
131 }
132
133 return;
134 }
135 $context->finish (0, 0, $time);
136 });
137 }; 156 }
157 );
138 $idx--; 158 $idx--;
139 } 159 }
140 } 160 }
141 $self->show_all; 161 $self->show_all;
142
143} 162}
144 163
145=head1 AUTHOR 164=head1 AUTHOR
146 165
147 Marc Lehmann <schmorp@schmorp.de> 166 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines