ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/gde/GCE/StackView.pm
Revision: 1.16
Committed: Thu Apr 20 08:58:29 2006 UTC (20 years, 6 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

# User Rev Content
1 elmex 1.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 elmex 1.10 use GCE::Util;
18 elmex 1.1
19     use Glib::Object::Subclass Gtk2::VBox;
20    
21 elmex 1.12 use Storable qw/dclone/;
22    
23 elmex 1.1 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 elmex 1.7 $sw->set_policy ('automatic', 'automatic');
31 elmex 1.1 }
32    
33     sub set_stack {
34 elmex 1.4 my ($self, $mapedit, $x, $y) = @_;
35 elmex 1.1
36     for ($self->{stackbox}->get_children) {
37    
38     $self->{stackbox}->remove ($_);
39     }
40    
41 elmex 1.4 my $stack = $mapedit->get ($x, $y);
42 elmex 1.10 my $idx = $stack ? (@$stack - 1) : 0;
43 elmex 1.1
44 elmex 1.11 if ($stack) {
45     for (reverse @$stack) {
46     # FIXME: How to change a stack with a virtual arch????
47 elmex 1.16 if ($_->{_virtual}) {
48     $idx--;
49     next
50     }
51 elmex 1.12 my $ownidx = $idx;
52 elmex 1.1
53 elmex 1.11 #my $a = $_->{_virtual} || $_;
54     my $a = $_;
55 elmex 1.1
56 elmex 1.11 # this is awful, is this really the best way?
57     my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
58 elmex 1.1
59 elmex 1.11 fill_pb_from_arch ($pb, $a);
60 elmex 1.1
61 elmex 1.11 $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 elmex 1.1
71 elmex 1.11 # XXX: force an update ? maybe some more intelligent update later?
72     $self->set_stack ($mapedit, $x, $y);
73 elmex 1.1 });
74 elmex 1.11
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 elmex 1.14 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 elmex 1.15 $::MAINWIN->update_attr_editor ($ar)
95 elmex 1.11 });
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 elmex 1.1
103 elmex 1.11 $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 elmex 1.1
110 elmex 1.12 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 elmex 1.11 $idx--;
136     }
137 elmex 1.1 }
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