Fixing pokemon with alternative forms.

This commit is contained in:
sergiotarxz 2024-03-08 03:54:27 +01:00
parent dfc2abf809
commit fe98d9a8d9
5 changed files with 100 additions and 60 deletions

View File

@ -14,9 +14,18 @@ $shiny_dir->mkpath;
for my $pokemon_dir ( $pokemons_dir->children ) { for my $pokemon_dir ( $pokemons_dir->children ) {
my $bpp = $tempdir->child( $pokemon_dir->basename . '.4bpp' ); my $bpp = $tempdir->child( $pokemon_dir->basename . '.4bpp' );
say $pokemon_dir->basename; say $pokemon_dir->basename;
my $front = $pokemon_dir->child('front.png');
my $shiny = $pokemon_dir->child('shiny.pal');
if ($pokemon_dir->basename eq 'unown') {
$front = $pokemon_dir->child('z/front.png');
}
if ($pokemon_dir->basename eq 'castform') {
$front = $pokemon_dir->child('normal/front.png');
$shiny = $pokemon_dir->child('normal/shiny.pal');
}
system './pokeemerald/tools/gbagfx/gbagfx', system './pokeemerald/tools/gbagfx/gbagfx',
$pokemon_dir->child('front.png'), $bpp; $front, $bpp;
system './pokeemerald/tools/gbagfx/gbagfx', system './pokeemerald/tools/gbagfx/gbagfx',
$bpp, $shiny_dir->child( $pokemon_dir->basename . '.png' ), $bpp, $shiny_dir->child( $pokemon_dir->basename . '.png' ),
'-palette', $pokemon_dir->child('shiny.pal'), '-mwidth', 8, '-object'; '-palette', $shiny, '-mwidth', 8, '-object';
} }

View File

@ -23,6 +23,9 @@ sub species {
sub get_icon { sub get_icon {
my $self = shift; my $self = shift;
my $pokemon_name = $Rsaves::Constants::Emerald::Species::SPECIES[$self->species]; my $pokemon_name = $Rsaves::Constants::Emerald::Species::SPECIES[$self->species];
if (lc($pokemon_name) eq 'unown') {
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/z/icon.png";
}
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/icon.png"; return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/icon.png";
} }
@ -32,6 +35,12 @@ sub get_front {
if (Rsaves::pokemon_is_shiny($self->_pokemon)) { if (Rsaves::pokemon_is_shiny($self->_pokemon)) {
return "resources/shiny/@{[lc($pokemon_name)]}.png"; return "resources/shiny/@{[lc($pokemon_name)]}.png";
} }
if (lc($pokemon_name) eq 'castform') {
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/normal/front.png";
}
if (lc($pokemon_name) eq 'unown') {
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/z/front.png";
}
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/front.png"; return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/front.png";
} }
1; 1;

View File

@ -30,19 +30,16 @@ has _save => (
required => 1, required => 1,
); );
has _current_box => ( has _current_box => ( is => 'rw', );
is => 'rw',
);
my $BOX_X = 275;
my $BOX_X = 275; my $BOX_Y = 50;
my $BOX_Y = 50; my $BOX_WIDTH = 312;
my $BOX_WIDTH = 312;
my $BOX_HEIGHT = 340; my $BOX_HEIGHT = 340;
my $ARROW_X = 28; my $ARROW_X = 28;
my $ARROW_Y = 6; my $ARROW_Y = 6;
my $ARROW_WIDTH = 16; my $ARROW_WIDTH = 16;
my $ARROW_HEIGHT = 32; my $ARROW_HEIGHT = 32;
has _cursor_position => ( is => 'rw' ); has _cursor_position => ( is => 'rw' );
@ -50,13 +47,13 @@ has _cursor_position => ( is => 'rw' );
my $root = path(__FILE__)->parent->parent->parent->parent; my $root = path(__FILE__)->parent->parent->parent->parent;
sub start { sub start {
my $self = shift; my $self = shift;
my $gtk_window = Gtk4::Window->new; my $gtk_window = Gtk4::Window->new;
my $controller_motion = Gtk4::EventControllerMotion->new; my $controller_motion = Gtk4::EventControllerMotion->new;
my $controller_gesture = Gtk4::GestureClick->new; my $controller_gesture = Gtk4::GestureClick->new;
my $save = $self->_save; my $save = $self->_save;
my $pc = $save->get_pc_system; my $pc = $save->get_pc_system;
my $box = $pc->get_box(0); my $box = $pc->get_box(0);
$controller_gesture->set_button(1); $controller_gesture->set_button(1);
$self->_current_box($box); $self->_current_box($box);
$controller_gesture->signal_connect( $controller_gesture->signal_connect(
@ -74,7 +71,7 @@ sub start {
$canvas->add_controller($controller_motion); $canvas->add_controller($controller_motion);
$canvas->add_controller($controller_gesture); $canvas->add_controller($controller_gesture);
my $scale_factor_pc = 2.5; my $scale_factor_pc = 2.5;
my ($width, $height) = map { $_ * $scale_factor_pc } (256, 158); my ( $width, $height ) = map { $_ * $scale_factor_pc } ( 256, 158 );
$gtk_window->set_default_size( $width, $height ); $gtk_window->set_default_size( $width, $height );
$gtk_window->set_resizable(0); $gtk_window->set_resizable(0);
$canvas->set_draw_func( $canvas->set_draw_func(
@ -85,17 +82,19 @@ sub start {
my $height = shift; my $height = shift;
my $selected_pokemon = $self->get_selected_pokemon; my $selected_pokemon = $self->get_selected_pokemon;
$self->draw_pc($cairo, $scale_factor_pc); $self->draw_pc( $cairo, $scale_factor_pc );
{ {
my $output_box = Cairo::ImageSurface->create( 'argb32', $BOX_WIDTH, $BOX_HEIGHT ); my $output_box =
my $box_context = Cairo::Context->create($output_box); Cairo::ImageSurface->create( 'argb32', $BOX_WIDTH,
$BOX_HEIGHT );
my $box_context = Cairo::Context->create($output_box);
$self->draw_box($box_context); $self->draw_box($box_context);
$self->draw_pokemon( $box_context, $selected_pokemon ); $self->draw_pokemon( $box_context, $selected_pokemon );
$self->draw_box_name($box_context); $self->draw_box_name($box_context);
$cairo->set_source_surface( $output_box, $BOX_X, $BOX_Y ); $cairo->set_source_surface( $output_box, $BOX_X, $BOX_Y );
$cairo->paint; $cairo->paint;
} }
$self->draw_pokemon_details($cairo, $selected_pokemon); $self->draw_pokemon_details( $cairo, $selected_pokemon );
$self->draw_cursor($cairo); $self->draw_cursor($cairo);
} }
); );
@ -112,13 +111,13 @@ sub start {
sub _on_primary_click { sub _on_primary_click {
my $self = shift; my $self = shift;
my ($gesture, $n_press, $x, $y) = @_; my ( $gesture, $n_press, $x, $y ) = @_;
return if $self->_check_click_next_box($gesture, $n_press, $x, $y); return if $self->_check_click_next_prev_box( $gesture, $n_press, $x, $y );
} }
sub _check_click_next_box { sub _check_click_next_prev_box {
my $self = shift; my $self = shift;
my ($gesture, $n_press, $x, $y) = @_; my ( $gesture, $n_press, $x, $y ) = @_;
return if $x < $BOX_X; return if $x < $BOX_X;
return if $y < $BOX_Y; return if $y < $BOX_Y;
@ -129,44 +128,63 @@ sub _check_click_next_box {
return if $x >= $BOX_WIDTH; return if $x >= $BOX_WIDTH;
return if $y >= $BOX_HEIGHT; return if $y >= $BOX_HEIGHT;
my ($x_arrow, $width_arrow) = ($BOX_WIDTH - $ARROW_X, $BOX_WIDTH - $ARROW_X + $ARROW_WIDTH); my $x_matches =
my ($y_arrow, $height_arrow) = ($ARROW_Y, $ARROW_Y + $ARROW_HEIGHT); $x >= $BOX_WIDTH - $ARROW_X && $x <= $BOX_WIDTH - $ARROW_X + $ARROW_WIDTH;
my $x_matches = $x >= $BOX_WIDTH - $ARROW_X && $x <= $BOX_WIDTH - $ARROW_X + $ARROW_WIDTH; my $y_matches = $y >= $ARROW_Y && $y <= $ARROW_Y + $ARROW_HEIGHT;
my $y_matches = $y >= $ARROW_Y && $y <= $ARROW_Y + $ARROW_HEIGHT; if ( $x_matches && $y_matches ) {
if ($x_matches && $y_matches) { my $box = $self->_current_box;
my $box = $self->_current_box; my $save = $self->_save;
my $save = $self->_save; my $pc = $save->get_pc_system;
my $pc = $save->get_pc_system; if ( $box->number == 13 ) {
if ($box->number == 13) { $self->_current_box( $pc->get_box(0) );
$self->_current_box($pc->get_box(0));
return 1; return 1;
} }
$self->_current_box($pc->get_box($box->number+1)); $self->_current_box( $pc->get_box( $box->number + 1 ) );
return 1;
}
$x_matches = $x >= $ARROW_X - $ARROW_WIDTH && $x <= $ARROW_X;
$y_matches = $y >= $ARROW_Y && $y <= $ARROW_Y + $ARROW_HEIGHT;
if ( $x_matches && $y_matches ) {
my $box = $self->_current_box;
my $save = $self->_save;
my $pc = $save->get_pc_system;
if ( $box->number == 0 ) {
$self->_current_box( $pc->get_box(13) );
return 1;
}
$self->_current_box( $pc->get_box( $box->number - 1 ) );
return 1; return 1;
} }
} }
sub draw_pokemon_details { sub draw_pokemon_details {
my $self = shift; my $self = shift;
my $cairo = shift; my $cairo = shift;
my $selected_pokemon = shift; my $selected_pokemon = shift;
return if !defined $selected_pokemon; return if !defined $selected_pokemon;
my $surface = Cairo::ImageSurface->create_from_png($root->child($selected_pokemon->get_front)); my $output_image = Cairo::ImageSurface->create( 'argb32', 64, 64 );
my $image_context = Cairo::Context->create($output_image);
my $surface = Cairo::ImageSurface->create_from_png(
$root->child( $selected_pokemon->get_front ) );
my $scale_factor = 2; my $scale_factor = 2;
$cairo->scale( ($scale_factor) x 2 ); $cairo->scale( ($scale_factor) x 2 );
$cairo->set_source_surface( $surface, 20, 30 ); $image_context->set_source_surface( $surface, 0, 0 );
$image_context->get_source()->set_filter('nearest');
$image_context->paint;
$cairo->set_source_surface( $output_image, 20, 30 );
$cairo->get_source()->set_filter('nearest'); $cairo->get_source()->set_filter('nearest');
$cairo->scale( ( 1 / $scale_factor ) x 2 );
$cairo->paint; $cairo->paint;
$cairo->scale( (1/$scale_factor) x 2 );
} }
sub draw_pc { sub draw_pc {
my $self = shift; my $self = shift;
my $cairo = shift; my $cairo = shift;
my $scale_factor = shift; my $scale_factor = shift;
$cairo->scale( ($scale_factor) x 2 ); $cairo->scale( ($scale_factor) x 2 );
my $surface = Cairo::ImageSurface->create_from_png($root->child('resources/pc_background.png')); my $surface = Cairo::ImageSurface->create_from_png(
$root->child('resources/pc_background.png') );
$cairo->set_source_surface( $surface, 0, 0 ); $cairo->set_source_surface( $surface, 0, 0 );
$cairo->get_source()->set_filter('nearest'); $cairo->get_source()->set_filter('nearest');
$cairo->paint; $cairo->paint;
@ -240,7 +258,7 @@ sub draw_pokemon {
if ($is_selected) { if ($is_selected) {
$cairo->set_source_rgb( 1, 1, 0 ); $cairo->set_source_rgb( 1, 1, 0 );
$cairo->arc( $x + 5 + 11, $y + 10 + 11, 22/2, 0, pi*2 ); $cairo->arc( $x + 5 + 11, $y + 10 + 11, 22 / 2, 0, pi * 2 );
$cairo->fill; $cairo->fill;
} }
@ -262,7 +280,7 @@ sub get_selected_pokemon {
my $self = shift; my $self = shift;
my $cursor_position = $self->_cursor_position; my $cursor_position = $self->_cursor_position;
return if !defined $cursor_position; return if !defined $cursor_position;
my ($x, $y) = @$cursor_position; my ( $x, $y ) = @$cursor_position;
return if $x < $BOX_X; return if $x < $BOX_X;
return if $y < $BOX_Y; return if $y < $BOX_Y;
@ -274,17 +292,17 @@ sub get_selected_pokemon {
return if $y >= $BOX_HEIGHT; return if $y >= $BOX_HEIGHT;
my $scale_factor = 0.95 * 2; my $scale_factor = 0.95 * 2;
( $x, $y ) = map { $_ / $scale_factor } ($x, $y); ( $x, $y ) = map { $_ / $scale_factor } ( $x, $y );
return if $y <= 20; return if $y <= 20;
$y -= 20; $y -= 20;
my $p = 25; my $p = 25;
my $i = int( $y / ( $p - 3 ) ); my $i = int( $y / ( $p - 3 ) );
my $j = int( $x / ( $p + 1 ) ); my $j = int( $x / ( $p + 1 ) );
my $save = $self->_save; my $save = $self->_save;
my $pc = $save->get_pc_system; my $pc = $save->get_pc_system;
my $box = $self->_current_box; my $box = $self->_current_box;
my $number = $i * 6 + $j; my $number = $i * 6 + $j;
return if $number > 29; return if $number > 29;
my $pokemon = $box->get_pokemon($number); my $pokemon = $box->get_pokemon($number);
return $pokemon; return $pokemon;
@ -303,14 +321,18 @@ sub draw_box {
$cairo->paint; $cairo->paint;
$surface = Cairo::ImageSurface->create_from_png( $surface = Cairo::ImageSurface->create_from_png(
$root->child('resources/right_arrow_pc.png') ); $root->child('resources/right_arrow_pc.png') );
$cairo->set_source_surface( $surface, $BOX_WIDTH / 2 - $ARROW_X / 2, $ARROW_Y / 2); $cairo->set_source_surface(
$surface,
$BOX_WIDTH / 2 - $ARROW_X / 2,
$ARROW_Y / 2
);
$cairo->get_source()->set_filter('nearest'); $cairo->get_source()->set_filter('nearest');
$cairo->paint; $cairo->paint;
$cairo->scale(-1, 1); $cairo->scale( -1, 1 );
$cairo->set_source_surface( $surface, - $ARROW_X / 2, $ARROW_Y / 2); $cairo->set_source_surface( $surface, -$ARROW_X / 2, $ARROW_Y / 2 );
$cairo->get_source()->set_filter('nearest'); $cairo->get_source()->set_filter('nearest');
$cairo->paint; $cairo->paint;
$cairo->scale(-1, 1); $cairo->scale( -1, 1 );
$cairo->scale( 1 / 2, 1 / 2 ); $cairo->scale( 1 / 2, 1 / 2 );
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

BIN
resources/shiny/unown.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B