ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/StackView.pm
Revision: 1.16
Committed: Thu Apr 20 08:58:29 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
CVS Tags: rel-2_0, rel-2_1
Changes since 1.15: +4 -1 lines
Log Message:
fixed two bugs: stack view wasn't correctly updated when picking a stack with a
virtual tile. And the msg/lore textviews in the attreditor were broken.

File Contents

# Content
1 package GCE::StackView;
2
3 =head1 NAME
4
5 GCE::StackView - the stack window class for gce
6
7 =cut
8
9 use Gtk2;
10 use Gtk2::Gdk::Keysyms;
11 use Gtk2::SimpleMenu;
12
13 use Crossfire;
14 use Crossfire::MapWidget;
15
16 use GCE::AttrEdit;
17 use GCE::Util;
18
19 use Glib::Object::Subclass Gtk2::VBox;
20
21 use Storable qw/dclone/;
22
23 use strict;
24
25 sub INIT_INSTANCE {
26 my ($self) = @_;
27
28 $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0);
29 $sw->add_with_viewport ($self->{stackbox} = Gtk2::VBox->new);
30 $sw->set_policy ('automatic', 'automatic');
31 }
32
33 sub set_stack {
34 my ($self, $mapedit, $x, $y) = @_;
35
36 for ($self->{stackbox}->get_children) {
37
38 $self->{stackbox}->remove ($_);
39 }
40
41 my $stack = $mapedit->get ($x, $y);
42 my $idx = $stack ? (@$stack - 1) : 0;
43
44 if ($stack) {
45 for (reverse @$stack) {
46 # FIXME: How to change a stack with a virtual arch????
47 if ($_->{_virtual}) {
48 $idx--;
49 next
50 }
51 my $ownidx = $idx;
52
53 #my $a = $_->{_virtual} || $_;
54 my $a = $_;
55
56 # this is awful, is this really the best way?
57 my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
58
59 fill_pb_from_arch ($pb, $a);
60
61 $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0);
62 $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0);
63 $delbtn->signal_connect (clicked => sub {
64
65 #my $oldstack = [ @$stack ];
66 splice @$stack, $ownidx, 1;
67
68 # XXX: Insert undo here!
69 $mapedit->set ($x, $y, $stack);
70
71 # XXX: force an update ? maybe some more intelligent update later?
72 $self->set_stack ($mapedit, $x, $y);
73 });
74
75 $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
76 $elemhdl->add (my $hb2 = Gtk2::HBox->new);
77 $elemhdl->signal_connect (clicked => sub {
78 my $ar =
79 GCE::ArchRef->new (
80 arch => $a,
81 cb => sub {
82 $mapedit->change_begin (ref $self);
83 $mapedit->change_stack ($x, $y, $stack);
84 # XXX: Put this into a generic function!!! See also EditTools.pm
85 # FIXME: Fix the automatic update on undo here!
86 if (my $changeset = $mapedit->change_end) {
87 splice @{ $mapedit->{undo_stack} ||= [] },
88 $mapedit->{undo_stack_pos}++, 1e6,
89 $changeset;
90 }
91 }
92 );
93
94 $::MAINWIN->update_attr_editor ($ar)
95 });
96
97 $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
98 $img->set_alignment (0, 0.5);
99
100 $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0);
101 $lbl->set_alignment (0, 0.5);
102
103 $elemhdl->drag_source_set (['button1_mask'], ['move'],
104 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
105 );
106 $elemhdl->drag_dest_set (all => ['move'],
107 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
108 );
109
110 GCE::DragHelper::set_drag_source (
111 $elemhdl, arch => sub {
112 { arch => $stack->[$ownidx], stk => $stack, stk_idx => $ownidx }
113 }
114 );
115
116 GCE::DragHelper::set_drag_sink (
117 $elemhdl, arch => sub {
118 my ($darch) = @_;
119
120 if (defined $darch->{stk_idx} and $darch->{stk} == $stack) {
121 my $swapidx = $darch->{stk_idx};
122 ($stack->[$swapidx], $stack->[$ownidx])
123 = ($stack->[$ownidx], $stack->[$swapidx]);
124
125 } else {
126 splice @$stack, $ownidx, 1, (dclone $darch->{arch});
127 }
128
129 # XXX: Insert undo here!
130 $mapedit->set ($x, $y, $stack);
131
132 $self->set_stack ($mapedit, $x, $y);
133 }
134 );
135 $idx--;
136 }
137 }
138 $self->show_all;
139 }
140
141 =head1 AUTHOR
142
143 Marc Lehmann <schmorp@schmorp.de>
144 http://home.schmorp.de/
145
146 Robin Redeker <elmex@ta-sa.org>
147 http://www.ta-sa.org/
148
149 =cut
150 1;
151