ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/StackView.pm
Revision: 1.8
Committed: Wed Mar 15 19:04:07 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.7: +9 -8 lines
Log Message:
added inventory editor and fixed some bugs in the attr editor

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