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.4 by elmex, Mon Feb 20 13:30:28 2006 UTC vs.
Revision 1.10 by elmex, Thu Mar 16 14:00:24 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;
19 20
20use strict; 21use strict;
21 22
22sub INIT_INSTANCE { 23sub INIT_INSTANCE {
23 my ($self) = @_; 24 my ($self) = @_;
24 25
25 $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); 26 $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0);
26 $sw->add_with_viewport ($self->{stackbox} = Gtk2::VBox->new); 27 $sw->add_with_viewport ($self->{stackbox} = Gtk2::VBox->new);
28 $sw->set_policy ('automatic', 'automatic');
27} 29}
28 30
29sub set_stack { 31sub set_stack {
30 my ($self, $mapedit, $x, $y) = @_; 32 my ($self, $mapedit, $x, $y) = @_;
31 33
33 35
34 $self->{stackbox}->remove ($_); 36 $self->{stackbox}->remove ($_);
35 } 37 }
36 38
37 my $stack = $mapedit->get ($x, $y); 39 my $stack = $mapedit->get ($x, $y);
38 my $idx = (@$stack - 1); 40 my $idx = $stack ? (@$stack - 1) : 0;
39 41
40 for (reverse @$stack) { 42 for (reverse @$stack) {
41 # FIXME: How to change a stack with a virtual arch???? 43 # FIXME: How to change a stack with a virtual arch????
42 next if $_->{_virtual}; 44 next if $_->{_virtual};
43 45
44 #my $a = $_->{_virtual} || $_; 46 #my $a = $_->{_virtual} || $_;
45 my $a = $_; 47 my $a = $_;
46 48
47 # this is awful, is this really the best way? 49 # this is awful, is this really the best way?
48 my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; 50 my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
49 $pb->fill (0x00000000);
50 51
51 $TILE->composite ($pb, 52 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 53
58 $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); 54 $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); 55 $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0);
60 do { 56 do {
61 my $ownidx = $idx; 57 my $ownidx = $idx;
71 # XXX: force an update ? maybe some more intelligent update later? 67 # XXX: force an update ? maybe some more intelligent update later?
72 $self->set_stack ($mapedit, $x, $y); 68 $self->set_stack ($mapedit, $x, $y);
73 }); 69 });
74 }; 70 };
75 71
76
77 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); 72 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
78 $elemhdl->add (my $hb2 = Gtk2::HBox->new); 73 $elemhdl->add (my $hb2 = Gtk2::HBox->new);
74 $elemhdl->signal_connect (clicked => sub {
75 $::MAINWIN->set_pick ($a);
76 $::MAINWIN->update_attr_editor ($a, sub {
77 $mapedit->change_begin (ref $self);
78 $mapedit->change_stack ($x, $y, $stack);
79 # XXX: Put this into a generic function!!! See also EditTools.pm
80 # FIXME: Fix the automatic update on undo here!
81 if (my $changeset = $mapedit->change_end) {
82 splice @{ $mapedit->{undo_stack} ||= [] },
83 $mapedit->{undo_stack_pos}++, 1e6,
84 $changeset;
85 }
86 });
87 });
79 88
80 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); 89 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
81 $img->set_alignment (0, 0.5); 90 $img->set_alignment (0, 0.5);
82 91
83 $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0); 92 $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0);
94 my $ownidx = $idx; 103 my $ownidx = $idx;
95 104
96 $elemhdl->signal_connect (drag_data_get => sub { 105 $elemhdl->signal_connect (drag_data_get => sub {
97 my ($widget, $context, $data, $info, $time) = @_; 106 my ($widget, $context, $data, $info, $time) = @_;
98 107
99 $data->set ($data->target, 8, $ownidx); 108 $data->set ($data->target, 8, "stack:$ownidx");
100 }); 109 });
101 110
102 # XXX: I'm unsure here, do i have to issue a get request? 111 # XXX: I'm unsure here, do i have to issue a get request?
103 # And what if i get the data twice? Wait for transaction end? 112 # And what if i get the data twice? Wait for transaction end?
104 $elemhdl->signal_connect (drag_data_received => sub { 113 $elemhdl->signal_connect (drag_data_received => sub {
106 115
107 if (($data->length >= 0) && ($data->format == 8)) { 116 if (($data->length >= 0) && ($data->format == 8)) {
108 117
109 $context->finish (1, 0, $time); 118 $context->finish (1, 0, $time);
110 119
111 #my $oldstack = [ @$stack ]; 120 if ($data->data =~ m/stack:(\d+)/) {
112 my $swapidx = int $data->data; 121 my $swapidx = int $1;
113 122
114 ($stack->[$swapidx], $stack->[$ownidx]) 123 ($stack->[$swapidx], $stack->[$ownidx])
115 = ($stack->[$ownidx], $stack->[$swapidx]); 124 = ($stack->[$ownidx], $stack->[$swapidx]);
116 125
117 # XXX: Insert undo here! 126 # XXX: Insert undo here!
118 $mapedit->set ($x, $y, $stack); 127 $mapedit->set ($x, $y, $stack);
119 128
120 $self->set_stack ($mapedit, $x, $y); 129 $self->set_stack ($mapedit, $x, $y);
130 }
121 131
122 return; 132 return;
123 } 133 }
124 $context->finish (0, 0, $time); 134 $context->finish (0, 0, $time);
125 }); 135 });

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines