ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/StackView.pm
Revision: 1.9
Committed: Thu Mar 16 01:13:57 2006 UTC (18 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.8: +1 -0 lines
Log Message:
removed face checking and implemented pick editing

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