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.3 by elmex, Sun Mar 12 12:18:55 2006 UTC vs.
Revision 1.6 by elmex, Thu Mar 16 14:00:24 2006 UTC

16use List::Util qw(min max); 16use List::Util qw(min max);
17 17
18use Crossfire; 18use Crossfire;
19use Crossfire::MapWidget; 19use Crossfire::MapWidget;
20 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); 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 quick_msg def);
22
23sub def($$) {
24 return defined ($_[0]) ? $_[0] : $_[1];
25}
26
27sub 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
23sub new_arch_pb { 50sub 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
29sub fill_pb_from_arch { 56sub 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
41sub classify_arch_layer { 74sub classify_arch_layer {
162 } 195 }
163 196
164 return \@outstack; 197 return \@outstack;
165} 198}
166 199
200sub add_table_widget {
201 my ($table, $row, $data, $type, $cb) = @_;
202 my $edwid;
203
204 if ($type eq 'string') {
205 $table->attach_defaults (my $lbl = Gtk2::Label->new ($data->[0]), 0, 1, $row, $row + 1);
206 $edwid = Gtk2::Entry->new;
207 $edwid->set_text ($data->[1]);
208 $edwid->signal_connect (changed => sub {
209 $data->[1] = $_[0]->get_text;
210 $cb->($data->[1]) if $cb;
211 });
212 $table->attach_defaults ($edwid, 1, 2, $row, $row + 1);
213
214 } elsif ($type eq 'button') {
215 $table->attach_defaults (my $b = Gtk2::Button->new_with_label ($data), 0, 2, $row, $row + 1);
216 $b->signal_connect (clicked => ($cb || sub {}));
217
218 } elsif ($type eq 'label') {
219 $table->attach_defaults (my $lbl = Gtk2::Label->new ($data->[0]), 0, 1, $row, $row + 1);
220 $edwid = Gtk2::Label->new ($data->[1]);
221 $table->attach_defaults ($edwid, 1, 2, $row, $row + 1);
222
223 } else {
224 $edwid = Gtk2::Label->new ("FOO");
225 }
226}
227
167sub replace_arch_stack_layer { 228sub replace_arch_stack_layer {
168 my ($stack, $arch) = @_; 229 my ($stack, $arch) = @_;
169 230
170 my @outstack; 231 my @outstack;
171 232

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines