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 |
} |
28 |
|
29 |
sub set_stack { |
30 |
my ($self, $mapedit, $x, $y) = @_; |
31 |
|
32 |
for ($self->{stackbox}->get_children) { |
33 |
|
34 |
$self->{stackbox}->remove ($_); |
35 |
} |
36 |
|
37 |
my $stack = $mapedit->get ($x, $y); |
38 |
my $idx = (@$stack - 1); |
39 |
|
40 |
for (reverse @$stack) { |
41 |
# FIXME: How to change a stack with a virtual arch???? |
42 |
next if $_->{_virtual}; |
43 |
|
44 |
#my $a = $_->{_virtual} || $_; |
45 |
my $a = $_; |
46 |
|
47 |
# this is awful, is this really the best way? |
48 |
my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; |
49 |
$pb->fill (0x00000000); |
50 |
|
51 |
$TILE->composite ($pb, |
52 |
0, 0, |
53 |
TILESIZE, TILESIZE, |
54 |
- ($a->{_face} % 64) * TILESIZE, - TILESIZE * int $a->{_face} / 64, |
55 |
1, 1, 'nearest', 255 |
56 |
); |
57 |
|
58 |
$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 |
do { |
61 |
my $ownidx = $idx; |
62 |
|
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 |
|
71 |
# XXX: force an update ? maybe some more intelligent update later? |
72 |
$self->set_stack ($mapedit, $x, $y); |
73 |
}); |
74 |
}; |
75 |
|
76 |
$hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
77 |
$elemhdl->add (my $hb2 = Gtk2::HBox->new); |
78 |
|
79 |
$hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
80 |
$img->set_alignment (0, 0.5); |
81 |
|
82 |
$hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0); |
83 |
$lbl->set_alignment (0, 0.5); |
84 |
|
85 |
$elemhdl->drag_source_set (['button1_mask'], ['move'], |
86 |
{ target => 'STRING', flags => [], info => 'TARGET_STRING' } |
87 |
); |
88 |
$elemhdl->drag_dest_set (all => ['move'], |
89 |
{ target => 'STRING', flags => [], info => 'TARGET_STRING' } |
90 |
); |
91 |
|
92 |
do { |
93 |
my $ownidx = $idx; |
94 |
|
95 |
$elemhdl->signal_connect (drag_data_get => sub { |
96 |
my ($widget, $context, $data, $info, $time) = @_; |
97 |
|
98 |
$data->set ($data->target, 8, $ownidx); |
99 |
}); |
100 |
|
101 |
# XXX: I'm unsure here, do i have to issue a get request? |
102 |
# And what if i get the data twice? Wait for transaction end? |
103 |
$elemhdl->signal_connect (drag_data_received => sub { |
104 |
my ($widget, $context, $wx, $wy, $data, $info, $time) = @_; |
105 |
|
106 |
if (($data->length >= 0) && ($data->format == 8)) { |
107 |
|
108 |
$context->finish (1, 0, $time); |
109 |
|
110 |
#my $oldstack = [ @$stack ]; |
111 |
my $swapidx = int $data->data; |
112 |
|
113 |
($stack->[$swapidx], $stack->[$ownidx]) |
114 |
= ($stack->[$ownidx], $stack->[$swapidx]); |
115 |
|
116 |
# XXX: Insert undo here! |
117 |
$mapedit->set ($x, $y, $stack); |
118 |
|
119 |
$self->set_stack ($mapedit, $x, $y); |
120 |
|
121 |
return; |
122 |
} |
123 |
$context->finish (0, 0, $time); |
124 |
}); |
125 |
}; |
126 |
$idx--; |
127 |
} |
128 |
$self->show_all; |
129 |
|
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 |
|