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 |
|
|
} |
28 |
|
|
|
29 |
|
|
sub set_stack { |
30 |
elmex |
1.4 |
my ($self, $mapedit, $x, $y) = @_; |
31 |
elmex |
1.1 |
|
32 |
|
|
for ($self->{stackbox}->get_children) { |
33 |
|
|
|
34 |
|
|
$self->{stackbox}->remove ($_); |
35 |
|
|
} |
36 |
|
|
|
37 |
elmex |
1.4 |
my $stack = $mapedit->get ($x, $y); |
38 |
elmex |
1.1 |
my $idx = (@$stack - 1); |
39 |
|
|
|
40 |
root |
1.3 |
for (reverse @$stack) { |
41 |
elmex |
1.4 |
# FIXME: How to change a stack with a virtual arch???? |
42 |
|
|
next if $_->{_virtual}; |
43 |
|
|
|
44 |
|
|
#my $a = $_->{_virtual} || $_; |
45 |
|
|
my $a = $_; |
46 |
elmex |
1.1 |
|
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 |
root |
1.2 |
$TILE->composite ($pb, |
52 |
elmex |
1.1 |
0, 0, |
53 |
|
|
TILESIZE, TILESIZE, |
54 |
root |
1.3 |
- ($a->{_face} % 64) * TILESIZE, - TILESIZE * int $a->{_face} / 64, |
55 |
elmex |
1.1 |
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 |
elmex |
1.4 |
#my $oldstack = [ @$stack ]; |
66 |
elmex |
1.1 |
splice @$stack, $ownidx, 1; |
67 |
|
|
|
68 |
elmex |
1.4 |
# 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 |
elmex |
1.1 |
}); |
74 |
|
|
}; |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
$hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
78 |
|
|
$elemhdl->add (my $hb2 = Gtk2::HBox->new); |
79 |
|
|
|
80 |
|
|
$hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
81 |
|
|
$img->set_alignment (0, 0.5); |
82 |
|
|
|
83 |
|
|
$hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0); |
84 |
|
|
$lbl->set_alignment (0, 0.5); |
85 |
|
|
|
86 |
|
|
$elemhdl->drag_source_set (['button1_mask'], ['move'], |
87 |
|
|
{ target => 'STRING', flags => [], info => 'TARGET_STRING' } |
88 |
|
|
); |
89 |
|
|
$elemhdl->drag_dest_set (all => ['move'], |
90 |
|
|
{ target => 'STRING', flags => [], info => 'TARGET_STRING' } |
91 |
|
|
); |
92 |
|
|
|
93 |
|
|
do { |
94 |
|
|
my $ownidx = $idx; |
95 |
|
|
|
96 |
|
|
$elemhdl->signal_connect (drag_data_get => sub { |
97 |
|
|
my ($widget, $context, $data, $info, $time) = @_; |
98 |
|
|
|
99 |
|
|
$data->set ($data->target, 8, $ownidx); |
100 |
|
|
}); |
101 |
|
|
|
102 |
|
|
# XXX: I'm unsure here, do i have to issue a get request? |
103 |
|
|
# And what if i get the data twice? Wait for transaction end? |
104 |
|
|
$elemhdl->signal_connect (drag_data_received => sub { |
105 |
|
|
my ($widget, $context, $wx, $wy, $data, $info, $time) = @_; |
106 |
|
|
|
107 |
|
|
if (($data->length >= 0) && ($data->format == 8)) { |
108 |
|
|
|
109 |
|
|
$context->finish (1, 0, $time); |
110 |
|
|
|
111 |
elmex |
1.4 |
#my $oldstack = [ @$stack ]; |
112 |
elmex |
1.1 |
my $swapidx = int $data->data; |
113 |
|
|
|
114 |
|
|
($stack->[$swapidx], $stack->[$ownidx]) |
115 |
|
|
= ($stack->[$ownidx], $stack->[$swapidx]); |
116 |
|
|
|
117 |
elmex |
1.4 |
# XXX: Insert undo here! |
118 |
|
|
$mapedit->set ($x, $y, $stack); |
119 |
|
|
|
120 |
|
|
$self->set_stack ($mapedit, $x, $y); |
121 |
elmex |
1.1 |
|
122 |
|
|
return; |
123 |
|
|
} |
124 |
|
|
$context->finish (0, 0, $time); |
125 |
|
|
}); |
126 |
|
|
}; |
127 |
|
|
$idx--; |
128 |
|
|
} |
129 |
|
|
$self->show_all; |
130 |
|
|
|
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
=head1 AUTHOR |
134 |
|
|
|
135 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
136 |
|
|
http://home.schmorp.de/ |
137 |
|
|
|
138 |
|
|
Robin Redeker <elmex@ta-sa.org> |
139 |
|
|
http://www.ta-sa.org/ |
140 |
|
|
|
141 |
|
|
=cut |
142 |
|
|
1; |
143 |
|
|
|