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.2 by elmex, Fri Mar 10 20:32:47 2006 UTC vs.
Revision 1.9 by elmex, Mon Mar 20 02:53:49 2006 UTC

15use Storable; 15use Storable;
16use List::Util qw(min max); 16use List::Util qw(min max);
17 17
18use Crossfire; 18use Crossfire;
19use Crossfire::MapWidget; 19use Crossfire::MapWidget;
20use File::Spec::Functions;
20 21
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); 22our @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 quick_msg def arch_is_exit map2abs);
23
24sub map2abs {
25 my ($dest, $mape) = @_;
26
27 my $dir;
28 if (File::Spec->file_name_is_absolute($dest)) {
29 $dir = catdir ($CFG->{MAPDIR}, $dest);
30 } else {
31 my ($v, $p, $f) = File::Spec->splitpath ($mape->{path});
32 $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p));
33 }
34 return $dir;
35}
36
37sub def($$) {
38 return defined ($_[0]) ? $_[0] : $_[1];
39}
40
41sub quick_msg {
42 my $wid = shift;
43 my $msg;
44 my $win = $::MAINWIN;
45 if (ref $wid) {
46 $win = $wid;
47 $msg = shift;
48 } else {
49 $msg = $wid;
50 }
51 my $dia = Gtk2::Dialog->new ('Message', $win, 'destroy-with-parent', 'gtk-ok' => 'none');
52
53 my $lbl = Gtk2::Label->new ($msg);
54 $dia->vbox->add ($lbl);
55 $dia->signal_connect (response => sub { $_[0]->destroy });
56
57 unless (defined $_[0]) {
58 Glib::Timeout->add (1000, sub { $dia->destroy; 0 });
59 }
60
61 $dia->show_all;
62}
22 63
23sub new_arch_pb { 64sub new_arch_pb {
24 # this is awful, is this really the best way? 65 # this is awful, is this really the best way?
25 my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; 66 my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
26 return $pb; 67 return $pb;
27} 68}
28 69
29sub fill_pb_from_arch { 70sub fill_pb_from_arch {
30 my ($pb, $arch) = @_; 71 my ($pb, $a) = @_;
72
73 my $o = $Crossfire::ARCH{$a->{_name}};
74 my $face = $Crossfire::FACE{$a->{face} || $o->{face} || "blank.111"}
75 or warn "no gfx found for arch '$a->{_name}' at ($x|$y)\n";
76
77 $face or return;
31 78
32 $pb->fill (0x00000000); 79 $pb->fill (0x00000000);
33 $TILE->composite ($pb, 80 $TILE->composite ($pb,
34 0, 0, 81 0, 0,
35 TILESIZE, TILESIZE, 82 TILESIZE, TILESIZE,
36 - ($arch->{_face} % 64) * TILESIZE, - TILESIZE * int $arch->{_face} / 64, 83 - ($face->{idx} % 64) * TILESIZE, - TILESIZE * int $face->{idx} / 64,
37 1, 1, 'nearest', 255 84 1, 1, 'nearest', 255
38 ); 85 );
39} 86}
40 87
41sub classify_arch_layer { 88sub classify_arch_layer {
53 100
54 return 'between'; 101 return 'between';
55 } 102 }
56} 103}
57 104
105sub arch_is_exit {
106 my ($a) = @_;
107 my $type = $Crossfire::ARCH{$a->{_name}}->{type};
108 return $type eq '66' || $type eq '41';
109}
110
58sub arch_is_floor { 111sub arch_is_floor {
59 my ($a) = @_; 112 my ($a) = @_;
60 return $Crossfire::ARCH{$a->{_name}}->{is_floor}; 113 return $Crossfire::ARCH{$a->{_name}}->{is_floor};
61} 114}
62 115
63sub arch_is_wall { 116sub arch_is_wall {
64 my ($a) = @_; 117 my ($a) = @_;
65 return $Crossfire::ARCH{$a->{_name}}->{no_pass}; 118 return $Crossfire::ARCH{$a->{_name}}->{no_pass};
119}
120
121sub arch_is_monster {
122 my ($a) = @_;
123 my $arch = $Crossfire::ARCH{$a->{_name}};
124 return $arch->{alive} and ($arch->{monster} or $arch->{generator});
66} 125}
67 126
68sub stack_find { 127sub stack_find {
69 my ($stack, $dir, $pred) = @_; 128 my ($stack, $dir, $pred) = @_;
70 129
156 } 215 }
157 216
158 return \@outstack; 217 return \@outstack;
159} 218}
160 219
220sub add_table_widget {
221 my ($table, $row, $data, $type, $cb) = @_;
222 my $edwid;
223
224 if ($type eq 'string') {
225 $table->attach_defaults (my $lbl = Gtk2::Label->new ($data->[0]), 0, 1, $row, $row + 1);
226 $edwid = Gtk2::Entry->new;
227 $edwid->set_text ($data->[1]);
228 $edwid->signal_connect (changed => sub {
229 $data->[1] = $_[0]->get_text;
230 $cb->($data->[1]) if $cb;
231 });
232 $table->attach_defaults ($edwid, 1, 2, $row, $row + 1);
233
234 } elsif ($type eq 'button') {
235 $table->attach_defaults (my $b = Gtk2::Button->new_with_label ($data), 0, 2, $row, $row + 1);
236 $b->signal_connect (clicked => ($cb || sub {}));
237
238 } elsif ($type eq 'label') {
239 $table->attach_defaults (my $lbl = Gtk2::Label->new ($data->[0]), 0, 1, $row, $row + 1);
240 $edwid = Gtk2::Label->new ($data->[1]);
241 $table->attach_defaults ($edwid, 1, 2, $row, $row + 1);
242
243 } else {
244 $edwid = Gtk2::Label->new ("FOO");
245 }
246}
247
161sub replace_arch_stack_layer { 248sub replace_arch_stack_layer {
162 my ($stack, $arch) = @_; 249 my ($stack, $arch) = @_;
163 250
164 my @outstack; 251 my @outstack;
165 252

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines