ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/Util.pm
(Generate patch)

Comparing deliantra/gde/GCE/Util.pm (file contents):
Revision 1.1 by elmex, Mon Feb 20 18:21:04 2006 UTC vs.
Revision 1.4 by elmex, Sun Mar 12 23:32:58 2006 UTC

13 13
14use Carp (); 14use Carp ();
15use Storable; 15use Storable;
16use List::Util qw(min max); 16use List::Util qw(min max);
17 17
18our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer); 18use Crossfire;
19use Crossfire::MapWidget;
20
21our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall stack_find arch_is_wall arch_is_monster add_table_widget);
22
23sub new_arch_pb {
24 # this is awful, is this really the best way?
25 my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
26 return $pb;
27}
28
29sub fill_pb_from_arch {
30 my ($pb, $arch) = @_;
31
32 $pb->fill (0x00000000);
33 $TILE->composite ($pb,
34 0, 0,
35 TILESIZE, TILESIZE,
36 - ($arch->{_face} % 64) * TILESIZE, - TILESIZE * int $arch->{_face} / 64,
37 1, 1, 'nearest', 255
38 );
39}
19 40
20sub classify_arch_layer { 41sub classify_arch_layer {
21 my ($arch) = @_; 42 my ($arch) = @_;
22 43
23 if ($arch->{invisible}) { # just a heuristic for 'special' tiles (er. pedestals) 44 if ($arch->{invisible}) { # just a heuristic for 'special' tiles (er. pedestals)
30 51
31 } else { # $arch->{is_floor} and all other arches are 'between' monsters and floor 52 } else { # $arch->{is_floor} and all other arches are 'between' monsters and floor
32 53
33 return 'between'; 54 return 'between';
34 } 55 }
56}
57
58sub arch_is_floor {
59 my ($a) = @_;
60 return $Crossfire::ARCH{$a->{_name}}->{is_floor};
61}
62
63sub arch_is_wall {
64 my ($a) = @_;
65 return $Crossfire::ARCH{$a->{_name}}->{no_pass};
66}
67
68sub arch_is_monster {
69 my ($a) = @_;
70 my $arch = $Crossfire::ARCH{$a->{_name}};
71 return $arch->{alive} and ($arch->{monster} or $arch->{generator});
72}
73
74sub stack_find {
75 my ($stack, $dir, $pred) = @_;
76
77
78 if ($dir eq 'from_top') {
79 my $i = scalar (@$stack) - 1;
80 if ($i < 0) { $i = 0 }
81
82 for (reverse @$stack) {
83 $pred->($_)
84 and return $i;
85
86 $i--;
87 }
88
89 } else {
90 my $i = 0;
91
92 for (@$stack) {
93 $pred->($_)
94 and return $i;
95
96 $i++;
97 }
98 }
99
100 return 0;
101
102}
103
104sub stack_find_floor {
105 my ($stack, $dir) = @_;
106 return stack_find ($stack, $dir, \&arch_is_floor);
107}
108
109sub stack_find_wall {
110 my ($stack, $dir) = @_;
111 return stack_find ($stack, $dir, \&arch_is_wall);
35} 112}
36 113
37sub insert_arch_stack_layer { 114sub insert_arch_stack_layer {
38 my ($stack, $arch) = @_; 115 my ($stack, $arch) = @_;
39 116
85 } 162 }
86 163
87 return \@outstack; 164 return \@outstack;
88} 165}
89 166
167sub add_table_widget {
168 my ($table, $row, $data, $type, $cb) = @_;
169 my $edwid;
170
171 if ($type eq 'string') {
172 $table->attach_defaults (my $lbl = Gtk2::Label->new ($data->[0]), 0, 1, $row, $row + 1);
173 $edwid = Gtk2::Entry->new;
174 $edwid->set_text ($data->[1]);
175 $edwid->signal_connect (changed => sub {
176 $data->[1] = $_[0]->get_text;
177 $cb->($data->[1]) if $cb;
178 });
179 $table->attach_defaults ($edwid, 1, 2, $row, $row + 1);
180
181 } elsif ($type eq 'button') {
182 $table->attach_defaults (my $b = Gtk2::Button->new_with_label ($data), 0, 2, $row, $row + 1);
183 $b->signal_connect (clicked => ($cb || sub {}));
184
185 } elsif ($type eq 'label') {
186 $table->attach_defaults (my $lbl = Gtk2::Label->new ($data->[0]), 0, 1, $row, $row + 1);
187 $edwid = Gtk2::Label->new ($data->[1]);
188 $table->attach_defaults ($edwid, 1, 2, $row, $row + 1);
189
190 } else {
191 $edwid = Gtk2::Label->new ("FOO");
192 }
193}
194
90sub replace_arch_stack_layer { 195sub replace_arch_stack_layer {
91 my ($stack, $arch) = @_; 196 my ($stack, $arch) = @_;
92 197
93 my @outstack; 198 my @outstack;
94 199

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines