ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/gde/GCE/StackView.pm
Revision: 1.10
Committed: Thu Mar 16 14:00:24 2006 UTC (20 years, 7 months ago) by elmex
Branch: MAIN
Changes since 1.9: +3 -8 lines
Log Message:
bugfixes all around

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     use strict;
22    
23     sub INIT_INSTANCE {
24     my ($self) = @_;
25    
26     $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0);
27     $sw->add_with_viewport ($self->{stackbox} = Gtk2::VBox->new);
28 elmex 1.7 $sw->set_policy ('automatic', 'automatic');
29 elmex 1.1 }
30    
31     sub set_stack {
32 elmex 1.4 my ($self, $mapedit, $x, $y) = @_;
33 elmex 1.1
34     for ($self->{stackbox}->get_children) {
35    
36     $self->{stackbox}->remove ($_);
37     }
38    
39 elmex 1.4 my $stack = $mapedit->get ($x, $y);
40 elmex 1.10 my $idx = $stack ? (@$stack - 1) : 0;
41 elmex 1.1
42 root 1.3 for (reverse @$stack) {
43 elmex 1.4 # FIXME: How to change a stack with a virtual arch????
44     next if $_->{_virtual};
45    
46     #my $a = $_->{_virtual} || $_;
47     my $a = $_;
48 elmex 1.1
49     # this is awful, is this really the best way?
50     my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
51    
52 elmex 1.10 fill_pb_from_arch ($pb, $a);
53 elmex 1.1
54     $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0);
55     $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0);
56     do {
57     my $ownidx = $idx;
58    
59     $delbtn->signal_connect (clicked => sub {
60    
61 elmex 1.4 #my $oldstack = [ @$stack ];
62 elmex 1.1 splice @$stack, $ownidx, 1;
63    
64 elmex 1.4 # XXX: Insert undo here!
65     $mapedit->set ($x, $y, $stack);
66    
67     # XXX: force an update ? maybe some more intelligent update later?
68     $self->set_stack ($mapedit, $x, $y);
69 elmex 1.1 });
70     };
71    
72     $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
73     $elemhdl->add (my $hb2 = Gtk2::HBox->new);
74 elmex 1.6 $elemhdl->signal_connect (clicked => sub {
75 elmex 1.9 $::MAINWIN->set_pick ($a);
76 elmex 1.6 $::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     });
88 elmex 1.1
89     $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
90     $img->set_alignment (0, 0.5);
91    
92     $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0);
93     $lbl->set_alignment (0, 0.5);
94    
95     $elemhdl->drag_source_set (['button1_mask'], ['move'],
96     { target => 'STRING', flags => [], info => 'TARGET_STRING' }
97     );
98     $elemhdl->drag_dest_set (all => ['move'],
99     { target => 'STRING', flags => [], info => 'TARGET_STRING' }
100     );
101    
102     do {
103     my $ownidx = $idx;
104    
105     $elemhdl->signal_connect (drag_data_get => sub {
106     my ($widget, $context, $data, $info, $time) = @_;
107    
108 elmex 1.8 $data->set ($data->target, 8, "stack:$ownidx");
109 elmex 1.1 });
110    
111     # XXX: I'm unsure here, do i have to issue a get request?
112     # And what if i get the data twice? Wait for transaction end?
113     $elemhdl->signal_connect (drag_data_received => sub {
114     my ($widget, $context, $wx, $wy, $data, $info, $time) = @_;
115    
116     if (($data->length >= 0) && ($data->format == 8)) {
117    
118     $context->finish (1, 0, $time);
119    
120 elmex 1.8 if ($data->data =~ m/stack:(\d+)/) {
121     my $swapidx = int $1;
122 elmex 1.1
123 elmex 1.8 ($stack->[$swapidx], $stack->[$ownidx])
124     = ($stack->[$ownidx], $stack->[$swapidx]);
125 elmex 1.1
126 elmex 1.8 # XXX: Insert undo here!
127     $mapedit->set ($x, $y, $stack);
128 elmex 1.4
129 elmex 1.8 $self->set_stack ($mapedit, $x, $y);
130     }
131 elmex 1.1
132     return;
133     }
134     $context->finish (0, 0, $time);
135     });
136     };
137     $idx--;
138     }
139     $self->show_all;
140    
141     }
142    
143     =head1 AUTHOR
144    
145     Marc Lehmann <schmorp@schmorp.de>
146     http://home.schmorp.de/
147    
148     Robin Redeker <elmex@ta-sa.org>
149     http://www.ta-sa.org/
150    
151     =cut
152     1;
153