load_image_set('img/fuel%d.svg', 8, 60)
],
car_images => load_image_dir('img/SCXCars', 100),
+ semaphore_images => [
+ load_image_set('img/semaphore%d.svg', 5, 200)
+ ],
builder => Gtk2::Builder->new,
+ semaphore_win => Gtk2::Window->new('popup'),
+ semaphore_img => Gtk2::Image->new,
};
bless $self, $class;
$self->{builder}->connect_signals(undef);
+ my $pixbuf = $self->{semaphore_images}->[0];
+ $self->{semaphore_img}->set_from_pixbuf($pixbuf);
+ $self->{semaphore_img}->show;
+ $self->{semaphore_win}->add($self->{semaphore_img});
+ $self->{semaphore_win}->set_type_hint('splashscreen');
+ $self->{semaphore_win}->set_position('center-on-parent');
+ $self->{semaphore_win}->set_transient_for(
+ $self->{builder}->get_object('slotcarman')
+ );
+
return $self;
}
$self->set_laptime($row, '--');
}
+sub show_semaphore {
+ my ($self, $num) = @_;
+
+ my $win = $self->{semaphore_win};
+ if (defined $num) {
+ my $img = $self->{semaphore_img};
+ my $pixbuf = $self->{semaphore_images}->[$num];
+ $img->set_from_pixbuf($pixbuf);
+ $win->show;
+ } else {
+ $win->hide;
+ }
+}
+
1;
use strict;
use Carp;
+use Glib qw(TRUE FALSE);
use SCX::Car;
+our $SEMAPHORE_STEP = 1000;
+
sub new {
my ($class, $args) = @_;
sub race_start {
my ($self) = @_;
- $self->{race_running} = 1;
+ return if $self->{race_running} || $self->{start_in_progress};
+ $self->{race_running} = 0;
+ $self->{start_in_progress} = 1;
+ $self->{semaphore} = 0;
+ $self->{gui}->show_semaphore(0);
+ Glib::Timeout->add($SEMAPHORE_STEP, \&semaphore_step, $self);
+}
+sub semaphore_step {
+ my ($self) = @_;
+
+ return if !$self->{start_in_progress} && !$self->{race_running};
+
+ $self->{semaphore}++;
+ if ($self->{semaphore} <= 5) {
+ $self->{gui}->show_semaphore($self->{semaphore});
+ my $timeout = $SEMAPHORE_STEP;
+ $timeout += $SEMAPHORE_STEP * rand()
+ if $self->{semaphore} == 5;
+ Glib::Timeout->add($timeout, \&semaphore_step, $self);
+ } elsif ($self->{semaphore} == 6) {
+ $self->{race_running} = 1;
+ $self->{start_in_progress} = undef;
+ $self->{gui}->show_semaphore(0);
+ Glib::Timeout->add(3*$SEMAPHORE_STEP, \&semaphore_step, $self);
+ } else {
+ $self->{gui}->show_semaphore(undef);
+ $self->{semaphore} = undef;
+ }
+ return FALSE;
}
sub race_end {
$self->{race_running} = 0;
}
+
1;