Games-RolePlay-MapGen
view release on metacpan or search on metacpan
MapGen/Editor.pm view on Meta::CPAN
my $menu = new Gtk2::Menu->new;
@_ = @{$_[0]} if ref $_[0];
# TODO: this should become a module like _MForm.pm
my @a;
while( my($name, $opts) = splice @_, 0, 2 ) {
my $item = Gtk2::MenuItem->new_with_mnemonic($name);
push @a, sub { my @r = $opts->{enable}->(@_); $item->set_sensitive( $r[-1] ? 1 : 0 ); $opts->{result} = \@r; } if $opts->{enable};
push @a, sub { my @r = $opts->{disable}->(@_); $item->set_sensitive( $r[-1] ? 0 : 1 ); $opts->{result} = \@r; } if $opts->{disable};
$item->signal_connect( activate => $opts->{activate}, $opts ) if exists $opts->{activate};
$menu->append( $item );
}
$menu->{_a} = \@a;
$menu->show_all;
$menu;
}
# }}}
# right_click_map {{{
sub right_click_map {
my ($this, $event) = @_;
my @a;
if( my $s = $this->[SELECTION] ) {
my %already;
for my $r (@$s) {
for my $x ($r->[0] .. $r->[2]) {
for my $y ($r->[1] .. $r->[3]) {
next if $already{$x,$y};
$already{$x,$y} = push @a, [$x,$y];
}}
}
} else {
my @b;
if( my @o = (@{ $this->[O_LT] }) ) {
if( my $s2 = @{$this->[S_ARG]}[2] ) {
@b = (@o, $s2->[0]);
} else {
@b = @o;
}
} else {
return FALSE;
}
@a = (\@b);
}
$this->_build_rccm unless $this->[RCCM];
my @menus = @{ $this->[RCCM] };
my $menu = $menus[@{$a[0]}==3 ? 1:0];
$_->(@a) for @{$menu->{_a}};
$menu->popup(
undef, # parent menu shell
undef, # parent menu item
undef, # menu pos func
undef, # data
$event->button,
$event->time
);
}
# }}}
# OPTS AND PREFS
# blank_map {{{
sub blank_map {
my $this = shift;
# NOTE: This is just the blank map generator, it has no settings.
# Later, we'll have a generate_map() that has all kinds of configuations options.
$this->[FNAME] = undef;
$this->[WINDOW]->set_title("GRM Editor");
my $map = $this->[MAP] = new Games::RolePlay::MapGen({
tile_size => 10,
cell_size => "23x23",
bounding_box => "25x25",
});
$this->[MQ] = new Games::RolePlay::MapGen::MapQueue( $map );
$map->set_generator("Blank");
$map->generate;
$this->draw_map;
$map;
}
# }}}
# get_generate_opts {{{
sub get_generate_opts {
my $this = shift;
my $i = $this->[SETTINGS]{GENERATE_OPTS};
$i = thaw $i if $i;
$i = {} unless $i;
my $options = [[ # column 1
{ mnemonic => "_Tile Size: ",
type => "text",
desc => "The size of each tile (in Square Feet or Square Units or whatever)",
name => 'tile_size',
default => 10, # NOTE: fixes and matches must exist and must be arrrefs
fixes => [sub { $_[0] =~ s/\s+//g }],
matches => [qr/^\d+$/] },
{ mnemonic => "Cell Size: ",
type => "text",
desc => "The size of each tile in the image (in pixels)",
name => 'cell_size',
default => '23x23',
( run in 1.597 second using v1.01-cache-2.11-cpan-364913b4093 )