Able to read the pokemon boxes and put them in a canvas!!

This commit is contained in:
Sergiotarxz 2024-03-06 21:00:52 +01:00
parent 129e20ffd6
commit e274f22aba
2 changed files with 138 additions and 111 deletions

View File

@ -15,6 +15,7 @@ use Moo;
use GEmeTool::Log qw/logger/;
use namespace::clean;
use GEmeTool::Save::PokemonPC;
has __saves => ( is => 'rw' );
@ -217,4 +218,13 @@ sub _get_flags_hash_by_id {
);
return @final_hash;
}
sub get_pc_system {
my $self = shift;
my $pc = Rsaves::read_pc_storage($self->_get_current_save);
return GEmeTool::Save::PokemonPC->new(_pc => $pc, _save => sub {
my $pc = shift;
Rsaves::save_pc_changes($self->_get_current_save, $pc)
});
}
1;

View File

@ -32,65 +32,58 @@ Glib::Object::Introspection->setup(
use namespace::clean;
has _win => (
is => 'rw',
);
has _win => ( is => 'rw', );
has _options => (
is => 'rw',
);
has _options => ( is => 'rw', );
has _app => (
is => 'rw',
);
has _app => ( is => 'rw', );
has _save => (
is => 'rw',
);
has _save => ( is => 'rw', );
has _save_as => (
is => 'rw',
);
has _save_as_action => ( is => 'rw', );
has _pc_action => ( is => 'rw', );
has _file => (
is => 'rw',
);
has _file => ( is => 'rw', );
sub start {
my $self = shift;
my $self = shift;
my $options = GEmeTool::Options->new;
$self->_options($options);
my $app = Gtk4::Application->new( 'tech.owlcode.GEmeTool', 'default-flags' );
my $app =
Gtk4::Application->new( 'tech.owlcode.GEmeTool', 'default-flags' );
$self->_app($app);
$app->signal_connect( activate => sub {
$self->activate;
} );
$app->signal_connect(
activate => sub {
$self->activate;
}
);
$app->run;
}
sub activate {
my $self = shift;
my $self = shift;
my $display = Gdk::Display::get_default();
my $icon_theme = Gtk4::IconTheme::get_for_display($display);
$icon_theme->set_search_path(
path(__FILE__)->parent->parent->child('resources/icons')->absolute );
Gtk4::Window::set_default_icon_name('gemetool');
my $menu = Glib::IO::Menu->new;
my $about = Glib::IO::SimpleAction->new( 'about', undef );
my $open = Glib::IO::SimpleAction->new( 'open', undef );
my $logs = Glib::IO::SimpleAction->new( 'view_logs', undef );
my $pc = Glib::IO::SimpleAction->new( 'view_pc', undef );
my $save_as = Glib::IO::SimpleAction->new( 'save_as', undef );
$save_as->set_enabled(0);
my $menu = Glib::IO::Menu->new;
my $about = Glib::IO::SimpleAction->new( 'about', undef );
my $open = Glib::IO::SimpleAction->new( 'open', undef );
my $logs = Glib::IO::SimpleAction->new( 'view_logs', undef );
my $pc_action = Glib::IO::SimpleAction->new( 'view_pc', undef );
my $save_as_action = Glib::IO::SimpleAction->new( 'save_as', undef );
$save_as_action->set_enabled(0);
$pc_action->set_enabled(0);
my $app = $self->_app;
$app->add_action($about);
$app->add_action($open);
$app->add_action($logs);
$app->add_action($pc);
$app->add_action($save_as);
$self->_save_as($save_as);
$app->add_action($pc_action);
$app->add_action($save_as_action);
$self->_save_as_action($save_as_action);
$self->_pc_action($pc_action);
my $save;
my $extra;
my $save_menu_item = Glib::IO::MenuItem->new( 'Save as', 'app.save_as' );
@ -99,12 +92,12 @@ sub activate {
$self->activate_open;
}
);
$save_as->signal_connect(
$save_as_action->signal_connect(
activate => sub {
$self->activate_save;
}
);
$pc->signal_connect(
$pc_action->signal_connect(
activate => sub {
$self->activate_view_pc;
}
@ -112,7 +105,10 @@ sub activate {
$logs->signal_connect(
activate => sub {
my $win = $self->_win;
GEmeTool::View::LogWindow->new(app => $self->_app, main_window => $self)->start;
GEmeTool::View::LogWindow->new(
app => $self->_app,
main_window => $self
)->start;
}
);
@ -120,11 +116,12 @@ sub activate {
my $about_menu_item = Glib::IO::MenuItem->new( 'About', 'app.about' );
my $open_menu_item = Glib::IO::MenuItem->new( 'Open', 'app.open' );
my $logs_menu_item = Glib::IO::MenuItem->new( 'View logs', 'app.view_logs' );
my $pc_menu_item = Glib::IO::MenuItem->new( 'View pc', 'app.view_pc' );
my $submenu_file = Glib::IO::Menu->new;
my $submenu_view = Glib::IO::Menu->new;
my $submenu_help = Glib::IO::Menu->new;
my $logs_menu_item =
Glib::IO::MenuItem->new( 'View logs', 'app.view_logs' );
my $pc_menu_item = Glib::IO::MenuItem->new( 'View pc', 'app.view_pc' );
my $submenu_file = Glib::IO::Menu->new;
my $submenu_view = Glib::IO::Menu->new;
my $submenu_help = Glib::IO::Menu->new;
$submenu_help->append_item($about_menu_item);
$submenu_view->append_item($pc_menu_item);
$submenu_view->append_item($logs_menu_item);
@ -149,56 +146,57 @@ sub activate {
}
sub activate_open {
my $self = shift;
my $self = shift;
my $cancellable = Glib::IO::Cancellable->new;
my $dialog = Gtk4::FileDialog->new;
my $options = $self->_options;
my $win = $self->_win;
my $last_dir = $options->get_last_dir_open;
if (defined $last_dir && -d $last_dir) {
my $dialog = Gtk4::FileDialog->new;
my $options = $self->_options;
my $win = $self->_win;
my $last_dir = $options->get_last_dir_open;
if ( defined $last_dir && -d $last_dir ) {
my $curdir = Glib::IO::File::new_for_path($last_dir);
$dialog->set_initial_folder($curdir);
}
$dialog->open(
$win, $cancellable,
$win,
$cancellable,
sub {
my ( $self_dialog, $res ) = @_;
if ($res->had_error) {
if ( $res->had_error ) {
return;
}
my $file = $dialog->open_finish($res);
return if !defined $file;
$file = path( $file->get_path );
$self->_file($file);
$options->set_last_dir_open($file->parent.'');
$options->set_last_dir_open( $file->parent . '' );
$self->start_editing_file;
}
);
}
sub activate_save {
my $self = shift;
my $win = $self->_win;
my $dialog = Gtk4::FileDialog->new;
my $options = $self->_options;
my $self = shift;
my $win = $self->_win;
my $dialog = Gtk4::FileDialog->new;
my $options = $self->_options;
my $last_dir = $options->get_last_dir_open;
if (defined $last_dir && -d $last_dir) {
if ( defined $last_dir && -d $last_dir ) {
my $curdir = Glib::IO::File::new_for_path($last_dir);
$dialog->set_initial_folder($curdir);
$dialog->set_initial_name( path($self->_file)->basename );
$dialog->set_initial_name( path( $self->_file )->basename );
}
$dialog->save(
$win, undef,
sub {
my ( $self_dialog, $res ) = @_;
if ($res->had_error) {
if ( $res->had_error ) {
return;
}
my $file = $dialog->save_finish($res);
return if !defined $file;
$file = path( $file->get_path );
$options->set_last_dir_save($file->parent.'');
$self->_save->save( $file);
$options->set_last_dir_save( $file->parent . '' );
$self->_save->save($file);
}
);
}
@ -212,20 +210,21 @@ sub save {
sub open_file {
my $self = shift;
my $file = shift;
if (!-e $file) {
if ( !-e $file ) {
return;
}
$file = path( $file );
$file = path($file);
$self->_file($file);
$self->start_editing_file;
}
sub start_editing_file {
my $self = shift;
my $file = $self->_file;
my $save_as = $self->_save_as;
my $box_app = Gtk4::Box->new( 'vertical', 0 );
$self->_save(GEmeTool::Save->instance($file));
my $self = shift;
my $file = $self->_file;
my $save_as_action = $self->_save_as_action;
my $pc_action = $self->_pc_action;
my $box_app = Gtk4::Box->new( 'vertical', 0 );
$self->_save( GEmeTool::Save->instance($file) );
my $save_obj = $self->_save;
my $search = Gtk4::SearchBar->new;
@ -239,11 +238,10 @@ sub start_editing_file {
my $populate_func = sub {
my $box_flags = Gtk4::Box->new( 'vertical', 0 );
for my $rematch (@{$self->_save->get_rematches_save})
{
my $name = $rematch->{name};
my $value = $rematch->{value};
my $id = $rematch->{id};
for my $rematch ( @{ $self->_save->get_rematches_save } ) {
my $name = $rematch->{name};
my $value = $rematch->{value};
my $id = $rematch->{id};
my $buffer = $entry->get_buffer;
my $search_text = uc( $buffer->get_text );
next unless index( $name, $search_text ) >= 0;
@ -252,24 +250,24 @@ sub start_editing_file {
$toggle->signal_connect(
toggled => sub {
my $active = $toggle->get_active;
$self->_save->set_rematch($id, $active);
$self->_save->set_rematch( $id, $active );
}
);
$box_flags->append($toggle);
}
for my $flag (@{$self->_save->get_flags_save}) {
my $name = $flag->{name};
my $value = $flag->{value};
my $id = $flag->{id};
for my $flag ( @{ $self->_save->get_flags_save } ) {
my $name = $flag->{name};
my $value = $flag->{value};
my $id = $flag->{id};
my $buffer = $entry->get_buffer;
my $search_text = uc( $buffer->get_text );
next unless index( $name, $search_text ) >= 0;
my $toggle = Gtk4::ToggleButton->new_with_label($name);
$toggle->set_active( $value );
$toggle->set_active($value);
$toggle->signal_connect(
toggled => sub {
my $active = $toggle->get_active;
$self->_save->set_flag($id, $active);
$self->_save->set_flag( $id, $active );
}
);
@ -286,7 +284,8 @@ sub start_editing_file {
$box_app->append($scroll);
my $win = $self->_win;
$win->set_child($box_app);
$save_as->set_enabled(1);
$save_as_action->set_enabled(1);
$pc_action->set_enabled(1);
}
@ -323,47 +322,65 @@ sub activate_about {
}
my $root = path(__FILE__)->parent->parent->parent->parent;
sub activate_view_pc {
my $self = shift;
my $gtk_window = Gtk4::Window->new;
my $canvas = Gtk4::DrawingArea->new;
$gtk_window->set_default_size(312,340);
$gtk_window->set_resizable(0);
$canvas->set_draw_func(sub {
my $canvas = shift;
my $cairo = shift;
my $width = shift;
my $height = shift;
$self->draw_box($cairo);
$self->draw_pokemon($cairo);
});
sub activate_view_pc {
my $self = shift;
my $gtk_window = Gtk4::Window->new;
my $canvas = Gtk4::DrawingArea->new;
$gtk_window->set_default_size( 312, 340 );
$gtk_window->set_resizable(0);
$canvas->set_draw_func(
sub {
my $canvas = shift;
my $cairo = shift;
my $width = shift;
my $height = shift;
$self->draw_box($cairo);
$self->draw_pokemon($cairo);
}
);
$gtk_window->set_child($canvas);
$gtk_window->present;
}
sub draw_pokemon {
my $self = shift;
my $self = shift;
my $cairo = shift;
my $pokemon = $root->child('pokeemerald/graphics/pokemon/bulbasaur/icon.png');
my $surface = Cairo::ImageSurface->create_from_png($pokemon);
my $output_image = Cairo::ImageSurface->create('argb32', 32, 32);
my $image_context = Cairo::Context->create($output_image);
$image_context->set_source_surface($surface, 0, 0);
$image_context->get_source()->set_filter('nearest');
$image_context->paint;
$cairo->set_source_surface($output_image, 0, 20);
$cairo->get_source()->set_filter('nearest');
$cairo->paint;
my $save = $self->_save;
my $pc = $save->get_pc_system;
my $box = $pc->get_box(0);
$cairo->scale(0.95, 0.95);
for ( my $i = 0 ; $i < 5 ; $i++ ) {
# ROW
for ( my $j = 0 ; $j < 6 ; $j++ ) {
# COLUMN
my $pokemon = $box->get_pokemon($i*6 + $j);
my $pokemon_image =
$root->child($pokemon->get_image);
my $surface = Cairo::ImageSurface->create_from_png($pokemon_image);
my $output_image = Cairo::ImageSurface->create( 'argb32', 32, 32 );
my $image_context = Cairo::Context->create($output_image);
$image_context->set_source_surface( $surface, 0, 0 );
$image_context->get_source()->set_filter('nearest');
$image_context->paint;
my $p = 25;
$cairo->set_source_surface( $output_image, $j * ($p + 1),
20 + ( ( $p - 3 ) * $i ) );
$cairo->get_source()->set_filter('nearest');
$cairo->paint;
}
}
}
sub draw_box {
my $self = shift;
my $cairo = shift;
my $surface = Cairo::ImageSurface->create_from_png($root->child('resources/forest.png'));
my $self = shift;
my $cairo = shift;
my $surface = Cairo::ImageSurface->create_from_png(
$root->child('resources/forest.png') );
$cairo->scale(2, 2);
$cairo->set_source_surface($surface, 0, 0);
$cairo->scale( 2, 2 );
$cairo->set_source_surface( $surface, 0, 0 );
$cairo->get_source()->set_filter('nearest');
$cairo->paint;