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, $stack, $x, $y) = @_; |
31 |
|
32 |
for ($self->{stackbox}->get_children) { |
33 |
|
34 |
$self->{stackbox}->remove ($_); |
35 |
} |
36 |
|
37 |
my $idx = (@$stack - 1); |
38 |
|
39 |
for my $a (reverse @$stack) { |
40 |
|
41 |
my $tile = $FACE{ $a->{face} || $ARCH{$a->{_name}}{face} }; |
42 |
|
43 |
# this is awful, is this really the best way? |
44 |
my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; |
45 |
$pb->fill (0x00000000); |
46 |
|
47 |
$TILE->composite ($pb, |
48 |
0, 0, |
49 |
TILESIZE, TILESIZE, |
50 |
- ($tile->{idx} % 64) * TILESIZE, - TILESIZE * int $tile->{idx} / 64, |
51 |
1, 1, 'nearest', 255 |
52 |
); |
53 |
|
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 |
my $oldstack = [ @$stack ]; |
62 |
splice @$stack, $ownidx, 1; |
63 |
$self->set_stack ($mapedit, $stack, $x, $y); |
64 |
|
65 |
$GCE::MainWindow::MAINWIN->change_map_tile ($mapedit, $x, $y, $stack, $oldstack); |
66 |
}); |
67 |
}; |
68 |
|
69 |
|
70 |
$hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
71 |
$elemhdl->add (my $hb2 = Gtk2::HBox->new); |
72 |
|
73 |
$hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
74 |
$img->set_alignment (0, 0.5); |
75 |
|
76 |
$hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0); |
77 |
$lbl->set_alignment (0, 0.5); |
78 |
|
79 |
$elemhdl->drag_source_set (['button1_mask'], ['move'], |
80 |
{ target => 'STRING', flags => [], info => 'TARGET_STRING' } |
81 |
); |
82 |
$elemhdl->drag_dest_set (all => ['move'], |
83 |
{ target => 'STRING', flags => [], info => 'TARGET_STRING' } |
84 |
); |
85 |
|
86 |
do { |
87 |
my $ownidx = $idx; |
88 |
|
89 |
$elemhdl->signal_connect (drag_data_get => sub { |
90 |
my ($widget, $context, $data, $info, $time) = @_; |
91 |
|
92 |
$data->set ($data->target, 8, $ownidx); |
93 |
}); |
94 |
|
95 |
# XXX: I'm unsure here, do i have to issue a get request? |
96 |
# And what if i get the data twice? Wait for transaction end? |
97 |
$elemhdl->signal_connect (drag_data_received => sub { |
98 |
my ($widget, $context, $wx, $wy, $data, $info, $time) = @_; |
99 |
|
100 |
if (($data->length >= 0) && ($data->format == 8)) { |
101 |
|
102 |
$context->finish (1, 0, $time); |
103 |
|
104 |
my $oldstack = [ @$stack ]; |
105 |
my $swapidx = int $data->data; |
106 |
|
107 |
($stack->[$swapidx], $stack->[$ownidx]) |
108 |
= ($stack->[$ownidx], $stack->[$swapidx]); |
109 |
|
110 |
$self->set_stack ($mapedit, $stack, $x, $y); |
111 |
$GCE::MainWindow::MAINWIN->change_map_tile ($mapedit, $x, $y, $stack, $oldstack); |
112 |
|
113 |
return; |
114 |
} |
115 |
$context->finish (0, 0, $time); |
116 |
}); |
117 |
}; |
118 |
$idx--; |
119 |
} |
120 |
$self->show_all; |
121 |
|
122 |
} |
123 |
|
124 |
=head1 AUTHOR |
125 |
|
126 |
Marc Lehmann <schmorp@schmorp.de> |
127 |
http://home.schmorp.de/ |
128 |
|
129 |
Robin Redeker <elmex@ta-sa.org> |
130 |
http://www.ta-sa.org/ |
131 |
|
132 |
=cut |
133 |
1; |
134 |
|