ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/StackView.pm
Revision: 1.11
Committed: Sun Mar 19 19:30:38 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.10: +81 -79 lines
Log Message:
many changes. fixed a bug in stack view with virtual tiles.

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