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.14 by elmex, Tue Apr 4 21:12:08 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;
28 $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); 28 $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0);
29 $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'); 30 $sw->set_policy ('automatic', 'automatic');
31} 31}
32 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
33sub set_stack { 42sub set_stack {
34 my ($self, $mapedit, $x, $y) = @_; 43 my ($self, $mapedit, $x, $y) = @_;
35 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
36 for ($self->{stackbox}->get_children) { 53 for ($self->{stackbox}->get_children) {
37
38 $self->{stackbox}->remove ($_); 54 $self->{stackbox}->remove ($_);
39 } 55 }
40 56
41 my $stack = $mapedit->get ($x, $y); 57 my $stack = $mapedit->get ($x, $y);
42 my $idx = $stack ? (@$stack - 1) : 0; 58 my $idx = $stack ? (@$stack - 1) : 0;
43 59
44 if ($stack) { 60 if ($stack) {
45 for (reverse @$stack) { 61 for (reverse @$stack) {
46 # FIXME: How to change a stack with a virtual arch???? 62 # FIXME: How to change a stack with a virtual arch????
47 next if $_->{_virtual}; 63 if ($_->{_virtual}) {
64 $idx--;
65 next
66 }
48 my $ownidx = $idx; 67 my $ownidx = $idx;
49 68
50 #my $a = $_->{_virtual} || $_; 69 #my $a = $_->{_virtual} || $_;
51 my $a = $_; 70 my $a = $_;
52 71
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 96
73 $elemhdl->add (my $hb2 = Gtk2::HBox->new); 98 $elemhdl->add (my $hb2 = Gtk2::HBox->new);
74 $elemhdl->signal_connect (clicked => sub { 99 $elemhdl->signal_connect (clicked => sub {
75 my $ar = 100 my $ar =
76 GCE::ArchRef->new ( 101 GCE::ArchRef->new (
77 arch => $a, 102 arch => $a,
103 source => 'map',
78 cb => sub { 104 cb => sub {
79 $mapedit->change_begin (ref $self); 105 $mapedit->change_begin (ref $self);
80 $mapedit->change_stack ($x, $y, $stack); 106 $mapedit->change_stack ($x, $y, $stack);
81 # XXX: Put this into a generic function!!! See also EditTools.pm 107 # XXX: Put this into a generic function!!! See also EditTools.pm
82 # FIXME: Fix the automatic update on undo here! 108 # FIXME: Fix the automatic update on undo here!
86 $changeset; 112 $changeset;
87 } 113 }
88 } 114 }
89 ); 115 );
90 116
91 $::MAINWIN->update_attr_editor ($a) 117 $::MAINWIN->update_attr_editor ($ar)
92 }); 118 });
93 119
94 $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);
95 $img->set_alignment (0, 0.5); 121 $img->set_alignment (0, 0.5);
96 122

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines