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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines