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.5 by elmex, Fri Mar 10 20:32:47 2006 UTC vs.
Revision 1.14 by elmex, Tue Apr 4 21:12:08 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines