ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/gde/GCE/StackView.pm
Revision: 1.13
Committed: Tue Apr 4 11:29:54 2006 UTC (20 years, 6 months ago) by elmex
Branch: MAIN
Changes since 1.12: +0 -1 lines
Log Message:
Removed pick and made the attribut editor 'the current pick'.
Added context menu to map view with an follow item in it.

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     next if $_->{_virtual};
48 elmex 1.12 my $ownidx = $idx;
49 elmex 1.1
50 elmex 1.11 #my $a = $_->{_virtual} || $_;
51     my $a = $_;
52 elmex 1.1
53 elmex 1.11 # this is awful, is this really the best way?
54     my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
55 elmex 1.1
56 elmex 1.11 fill_pb_from_arch ($pb, $a);
57 elmex 1.1
58 elmex 1.11 $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);
60     $delbtn->signal_connect (clicked => sub {
61    
62     #my $oldstack = [ @$stack ];
63     splice @$stack, $ownidx, 1;
64    
65     # XXX: Insert undo here!
66     $mapedit->set ($x, $y, $stack);
67 elmex 1.1
68 elmex 1.11 # XXX: force an update ? maybe some more intelligent update later?
69     $self->set_stack ($mapedit, $x, $y);
70 elmex 1.1 });
71 elmex 1.11
72     $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
73     $elemhdl->add (my $hb2 = Gtk2::HBox->new);
74     $elemhdl->signal_connect (clicked => sub {
75     $::MAINWIN->update_attr_editor ($a, sub {
76     $mapedit->change_begin (ref $self);
77     $mapedit->change_stack ($x, $y, $stack);
78     # XXX: Put this into a generic function!!! See also EditTools.pm
79     # FIXME: Fix the automatic update on undo here!
80     if (my $changeset = $mapedit->change_end) {
81     splice @{ $mapedit->{undo_stack} ||= [] },
82     $mapedit->{undo_stack_pos}++, 1e6,
83     $changeset;
84     }
85     });
86     });
87    
88     $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
89     $img->set_alignment (0, 0.5);
90    
91     $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0);
92     $lbl->set_alignment (0, 0.5);
93 elmex 1.1
94 elmex 1.11 $elemhdl->drag_source_set (['button1_mask'], ['move'],
95     { target => 'STRING', flags => [], info => 'TARGET_STRING' }
96     );
97     $elemhdl->drag_dest_set (all => ['move'],
98     { target => 'STRING', flags => [], info => 'TARGET_STRING' }
99     );
100 elmex 1.1
101 elmex 1.12 GCE::DragHelper::set_drag_source (
102     $elemhdl, arch => sub {
103     { arch => $stack->[$ownidx], stk => $stack, stk_idx => $ownidx }
104     }
105     );
106    
107     GCE::DragHelper::set_drag_sink (
108     $elemhdl, arch => sub {
109     my ($darch) = @_;
110    
111     if (defined $darch->{stk_idx} and $darch->{stk} == $stack) {
112     my $swapidx = $darch->{stk_idx};
113     ($stack->[$swapidx], $stack->[$ownidx])
114     = ($stack->[$ownidx], $stack->[$swapidx]);
115    
116     } else {
117     splice @$stack, $ownidx, 1, (dclone $darch->{arch});
118     }
119    
120     # XXX: Insert undo here!
121     $mapedit->set ($x, $y, $stack);
122    
123     $self->set_stack ($mapedit, $x, $y);
124     }
125     );
126 elmex 1.11 $idx--;
127     }
128 elmex 1.1 }
129     $self->show_all;
130     }
131    
132     =head1 AUTHOR
133    
134     Marc Lehmann <schmorp@schmorp.de>
135     http://home.schmorp.de/
136    
137     Robin Redeker <elmex@ta-sa.org>
138     http://www.ta-sa.org/
139    
140     =cut
141     1;
142