… | |
… | |
15 | use Storable; |
15 | use Storable; |
16 | use List::Util qw(min max); |
16 | use List::Util qw(min max); |
17 | |
17 | |
18 | use Crossfire; |
18 | use Crossfire; |
19 | use Crossfire::MapWidget; |
19 | use Crossfire::MapWidget; |
|
|
20 | use File::Spec::Functions; |
20 | |
21 | |
21 | our @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 | our @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 | |
|
|
24 | sub map2abs { |
|
|
25 | my ($dest, $mape) = @_; |
|
|
26 | |
|
|
27 | my $dir; |
|
|
28 | if (File::Spec->file_name_is_absolute($dest)) { |
|
|
29 | $dir = catdir ($Crossfire::LIB, 'maps', $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 | |
|
|
37 | sub def($$) { |
|
|
38 | return defined ($_[0]) ? $_[0] : $_[1]; |
|
|
39 | } |
|
|
40 | |
|
|
41 | sub 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 | |
23 | sub new_arch_pb { |
64 | sub 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 | |
29 | sub fill_pb_from_arch { |
70 | sub 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 | |
41 | sub classify_arch_layer { |
88 | sub classify_arch_layer { |
… | |
… | |
51 | |
98 | |
52 | } else { # $arch->{is_floor} and all other arches are 'between' monsters and floor |
99 | } else { # $arch->{is_floor} and all other arches are 'between' monsters and floor |
53 | |
100 | |
54 | return 'between'; |
101 | return 'between'; |
55 | } |
102 | } |
|
|
103 | } |
|
|
104 | |
|
|
105 | sub arch_is_exit { |
|
|
106 | my ($a) = @_; |
|
|
107 | my $type = $Crossfire::ARCH{$a->{_name}}->{type}; |
|
|
108 | return $type eq '66' || $type eq '41'; |
56 | } |
109 | } |
57 | |
110 | |
58 | sub arch_is_floor { |
111 | sub 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}; |