… | |
… | |
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 | |
20 | |
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); |
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 quick_msg def arch_is_exit); |
|
|
22 | |
|
|
23 | sub def($$) { |
|
|
24 | return defined ($_[0]) ? $_[0] : $_[1]; |
|
|
25 | } |
|
|
26 | |
|
|
27 | sub quick_msg { |
|
|
28 | my $wid = shift; |
|
|
29 | my $msg; |
|
|
30 | my $win = $::MAINWIN; |
|
|
31 | if (ref $wid) { |
|
|
32 | $win = $wid; |
|
|
33 | $msg = shift; |
|
|
34 | } else { |
|
|
35 | $msg = $wid; |
|
|
36 | } |
|
|
37 | my $dia = Gtk2::Dialog->new ('Message', $win, 'destroy-with-parent', 'gtk-ok' => 'none'); |
|
|
38 | |
|
|
39 | my $lbl = Gtk2::Label->new ($msg); |
|
|
40 | $dia->vbox->add ($lbl); |
|
|
41 | $dia->signal_connect (response => sub { $_[0]->destroy }); |
|
|
42 | |
|
|
43 | unless (defined $_[0]) { |
|
|
44 | Glib::Timeout->add (1000, sub { $dia->destroy; 0 }); |
|
|
45 | } |
|
|
46 | |
|
|
47 | $dia->show_all; |
|
|
48 | } |
22 | |
49 | |
23 | sub new_arch_pb { |
50 | sub new_arch_pb { |
24 | # this is awful, is this really the best way? |
51 | # this is awful, is this really the best way? |
25 | my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; |
52 | my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE; |
26 | return $pb; |
53 | return $pb; |
27 | } |
54 | } |
28 | |
55 | |
29 | sub fill_pb_from_arch { |
56 | sub fill_pb_from_arch { |
30 | my ($pb, $arch) = @_; |
57 | my ($pb, $a) = @_; |
|
|
58 | |
|
|
59 | my $o = $Crossfire::ARCH{$a->{_name}}; |
|
|
60 | my $face = $Crossfire::FACE{$a->{face} || $o->{face} || "blank.111"} |
|
|
61 | or warn "no gfx found for arch '$a->{_name}' at ($x|$y)\n"; |
|
|
62 | |
|
|
63 | $face or return; |
31 | |
64 | |
32 | $pb->fill (0x00000000); |
65 | $pb->fill (0x00000000); |
33 | $TILE->composite ($pb, |
66 | $TILE->composite ($pb, |
34 | 0, 0, |
67 | 0, 0, |
35 | TILESIZE, TILESIZE, |
68 | TILESIZE, TILESIZE, |
36 | - ($arch->{_face} % 64) * TILESIZE, - TILESIZE * int $arch->{_face} / 64, |
69 | - ($face->{idx} % 64) * TILESIZE, - TILESIZE * int $face->{idx} / 64, |
37 | 1, 1, 'nearest', 255 |
70 | 1, 1, 'nearest', 255 |
38 | ); |
71 | ); |
39 | } |
72 | } |
40 | |
73 | |
41 | sub classify_arch_layer { |
74 | sub classify_arch_layer { |
… | |
… | |
51 | |
84 | |
52 | } else { # $arch->{is_floor} and all other arches are 'between' monsters and floor |
85 | } else { # $arch->{is_floor} and all other arches are 'between' monsters and floor |
53 | |
86 | |
54 | return 'between'; |
87 | return 'between'; |
55 | } |
88 | } |
|
|
89 | } |
|
|
90 | |
|
|
91 | sub arch_is_exit { |
|
|
92 | my ($a) = @_; |
|
|
93 | my $type = $Crossfire::ARCH{$a->{_name}}->{type}; |
|
|
94 | return $type eq '66' || $type eq '41'; |
56 | } |
95 | } |
57 | |
96 | |
58 | sub arch_is_floor { |
97 | sub arch_is_floor { |
59 | my ($a) = @_; |
98 | my ($a) = @_; |
60 | return $Crossfire::ARCH{$a->{_name}}->{is_floor}; |
99 | return $Crossfire::ARCH{$a->{_name}}->{is_floor}; |