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 |
|
|
$hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
77 |
|
|
$elemhdl->add (my $hb2 = Gtk2::HBox->new); |
78 |
elmex |
1.6 |
$elemhdl->signal_connect (clicked => sub { |
79 |
|
|
$::MAINWIN->update_attr_editor ($a, sub { |
80 |
|
|
$mapedit->change_begin (ref $self); |
81 |
|
|
$mapedit->change_stack ($x, $y, $stack); |
82 |
|
|
# XXX: Put this into a generic function!!! See also EditTools.pm |
83 |
|
|
# FIXME: Fix the automatic update on undo here! |
84 |
|
|
if (my $changeset = $mapedit->change_end) { |
85 |
|
|
splice @{ $mapedit->{undo_stack} ||= [] }, |
86 |
|
|
$mapedit->{undo_stack_pos}++, 1e6, |
87 |
|
|
$changeset; |
88 |
|
|
} |
89 |
|
|
}); |
90 |
|
|
}); |
91 |
elmex |
1.1 |
|
92 |
|
|
$hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
93 |
|
|
$img->set_alignment (0, 0.5); |
94 |
|
|
|
95 |
|
|
$hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0); |
96 |
|
|
$lbl->set_alignment (0, 0.5); |
97 |
|
|
|
98 |
|
|
$elemhdl->drag_source_set (['button1_mask'], ['move'], |
99 |
|
|
{ target => 'STRING', flags => [], info => 'TARGET_STRING' } |
100 |
|
|
); |
101 |
|
|
$elemhdl->drag_dest_set (all => ['move'], |
102 |
|
|
{ target => 'STRING', flags => [], info => 'TARGET_STRING' } |
103 |
|
|
); |
104 |
|
|
|
105 |
|
|
do { |
106 |
|
|
my $ownidx = $idx; |
107 |
|
|
|
108 |
|
|
$elemhdl->signal_connect (drag_data_get => sub { |
109 |
|
|
my ($widget, $context, $data, $info, $time) = @_; |
110 |
|
|
|
111 |
|
|
$data->set ($data->target, 8, $ownidx); |
112 |
|
|
}); |
113 |
|
|
|
114 |
|
|
# XXX: I'm unsure here, do i have to issue a get request? |
115 |
|
|
# And what if i get the data twice? Wait for transaction end? |
116 |
|
|
$elemhdl->signal_connect (drag_data_received => sub { |
117 |
|
|
my ($widget, $context, $wx, $wy, $data, $info, $time) = @_; |
118 |
|
|
|
119 |
|
|
if (($data->length >= 0) && ($data->format == 8)) { |
120 |
|
|
|
121 |
|
|
$context->finish (1, 0, $time); |
122 |
|
|
|
123 |
elmex |
1.4 |
#my $oldstack = [ @$stack ]; |
124 |
elmex |
1.1 |
my $swapidx = int $data->data; |
125 |
|
|
|
126 |
|
|
($stack->[$swapidx], $stack->[$ownidx]) |
127 |
|
|
= ($stack->[$ownidx], $stack->[$swapidx]); |
128 |
|
|
|
129 |
elmex |
1.4 |
# XXX: Insert undo here! |
130 |
|
|
$mapedit->set ($x, $y, $stack); |
131 |
|
|
|
132 |
|
|
$self->set_stack ($mapedit, $x, $y); |
133 |
elmex |
1.1 |
|
134 |
|
|
return; |
135 |
|
|
} |
136 |
|
|
$context->finish (0, 0, $time); |
137 |
|
|
}); |
138 |
|
|
}; |
139 |
|
|
$idx--; |
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 |
|
|
|