From: Jan "Yenya" Kasprzak Date: Mon, 6 Dec 2010 22:42:49 +0000 (+0100) Subject: Race setup, car reordering. X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=9aec101d497a8b3549b7150b0371e18c4c843f6a;p=slotcarman.git Race setup, car reordering. --- diff --git a/SCX/Car.pm b/SCX/Car.pm index 8446592..d48cbd3 100644 --- a/SCX/Car.pm +++ b/SCX/Car.pm @@ -79,7 +79,7 @@ sub set_lap { && $self->{lap} == $lap_nr); $self->{lap} = $lap_nr; - $self->gui->set_lap($self->{order}, defined $lap_nr ? $lap_nr : 'N/A'); + $self->gui->set_lap($self->{order}, defined $lap_nr ? $lap_nr : '--'); } sub set_laptime { @@ -97,7 +97,7 @@ sub set_laptime { } } else { - $self->gui->set_best_lap($self->{order}, 'N/A'); + $self->gui->set_best_lap($self->{order}, '--'); $self->{best_lap} = undef; } @@ -108,7 +108,7 @@ sub set_laptime { $self->{laptime} = $lap_time; $self->gui->set_laptime($self->{order}, defined $lap_time - ? $lap_time : 'N/A'); + ? $lap_time : '--'); } sub set_driver { @@ -119,7 +119,7 @@ sub set_driver { && $self->{driver} == $driver_name); $self->{driver} = $driver_name; - $self->gui->set_driver($self->{order}, $driver_name || 'N/A'); + $self->gui->set_driver($self->{order}, $driver_name || '--'); } sub enter_pit_lane { @@ -129,5 +129,23 @@ sub enter_pit_lane { $self->gui->enter_pit_lane; } +sub set_order { + my ($self, $pos) = @_; + + $self->{order} = $pos; + + $self->gui->set_driver($self->{order}, $self->{driver} + || '--'); + $self->gui->set_car_icon($self->{order}, $self->{car_icon}); + $self->gui->set_throttle($self->{order}, $self->{throttle}); + $self->gui->set_lap($self->{order}, defined $self->{lap} + ? $self->{lap} : '--'); + $self->gui->set_laptime($self->{order}, defined $self->{laptime} + ? $self->{laptime} : '--'); + $self->gui->set_best_lap($self->{order}, defined $self->{best_lap} + ? $self->{best_lap} : '--'); + $self->gui->set_fuel($self->{order}, $self->{fuel}); +} + 1; diff --git a/SCX/GUI.pm b/SCX/GUI.pm index 5738431..e782ba7 100755 --- a/SCX/GUI.pm +++ b/SCX/GUI.pm @@ -195,5 +195,29 @@ sub show_semaphore { } } +sub rounds { + my ($self, $text) = @_; + + my $label = $self->get_object("label_lap_global") + or die "Can't get label_lap_global"; + $label->set_markup('Lap '.$text.''); +} + +sub time { + my ($self, $text) = @_; + + my $label = $self->get_object("label_time_global") + or die "Can't get label_time_global"; + $label->set_markup('Time '.$text.''); +} + +sub best_lap { + my ($self, $text) = @_; + + my $label = $self->get_object("label_best_lap_global") + or die "Can't get label_best_lap_global"; + $label->set_markup('Best lap '.$text.''); +} + 1; diff --git a/SCX/Reader.pm b/SCX/Reader.pm index 8d9f42d..565af0f 100644 --- a/SCX/Reader.pm +++ b/SCX/Reader.pm @@ -265,10 +265,16 @@ sub race_setup_packet { || $bytes[5] != 0xFF; for my $car (0..5) { - $self->track->car($car)->set_lap(undef); + $self->track->car($car)->set_lap(0); $self->track->car($car)->set_laptime(undef); } + $self->track->race_setup($bytes[0] == 0x00 + ? 0 + : $bytes[1] & 0x0F * 256 + + $bytes[2] & 0x0F * 16 + + $bytes[3] & 0x0F); + return $msg; # FIXME - to be implemented } @@ -408,7 +414,6 @@ sub finish_line_packet { return $msg; # FIXME - to be implemented } - sub controller_status_packet { my ($self, @bytes) = @_; diff --git a/SCX/Track.pm b/SCX/Track.pm index c756592..32f03f4 100644 --- a/SCX/Track.pm +++ b/SCX/Track.pm @@ -45,7 +45,7 @@ sub race_start { sub semaphore_step { my ($self) = @_; - return if !$self->{start_in_progress} && !$self->{race_running}; + return FALSE if !$self->{start_in_progress} && !$self->{race_running}; $self->{semaphore}++; if ($self->{semaphore} <= 5) { @@ -56,6 +56,7 @@ sub semaphore_step { Glib::Timeout->add($timeout, \&semaphore_step, $self); } elsif ($self->{semaphore} == 6) { $self->{race_running} = 1; + $self->{race_running_since} = gettimeofday; $self->{start_in_progress} = undef; $self->{gui}->show_semaphore(0); Glib::Timeout->add(3*$SEMAPHORE_STEP, \&semaphore_step, $self); @@ -72,6 +73,30 @@ sub race_end { $self->{race_running} = 0; } +sub race_setup { + my ($self, $rounds) = @_; + + if ($rounds) { + $self->{gui}->rounds('0/' . $rounds); + $self->{race_rounds} = $rounds; + } else { + $self->{gui}->rounds('0'); + $self->{race_rounds} = 0; + } + $self->{race_time} = 0; + $self->{best_lap} = undef; + + $self->{gui}->show_semaphore(undef); + $self->{race_running} = 0; + $self->{start_in_progress} = 0; + + $self->{gui}->time('00:00'); + $self->{gui}->best_lap('0.00'); + + for my $car (0..5) { + $self->car($car)->set_order($car); + } +} 1; diff --git a/slotcarman.glade b/slotcarman.glade index aa67219..ca13b1a 100644 --- a/slotcarman.glade +++ b/slotcarman.glade @@ -161,6 +161,47 @@ 0 + + + True + + + True + label + + + 0 + + + + + True + label + + + 1 + + + + + True + label + + + 2 + + + + + + + + + + + 1 + + True @@ -721,40 +762,148 @@ - + + True + label + right + 12 + + + 5 + 6 + 1 + 2 + - + + True + label + right + 12 + + + 5 + 6 + 2 + 3 + - + + True + label + right + 12 + + + 5 + 6 + 3 + 4 + - + + True + label + right + 12 + + + 5 + 6 + 4 + 5 + - + + True + label + right + 12 + + + 5 + 6 + 5 + 6 + - + + True + label + right + 12 + + + 5 + 6 + 6 + 7 + - + + True + Name + + + 1 + 2 + - + + True + Lap + + + 3 + 4 + - + + True + Last lap + + + 4 + 5 + - + + True + Best lap + + + 5 + 6 + - + + True + Throttle + + + 9 + 10 + - + + True + Fuel + + + 10 + 11 + @@ -808,92 +957,26 @@ - - True - label - right - 12 - - - 5 - 6 - 1 - 2 - + - - True - label - right - 12 - - - 5 - 6 - 2 - 3 - + - - True - label - right - 12 - - - 5 - 6 - 3 - 4 - + - - True - label - right - 12 - - - 5 - 6 - 4 - 5 - + - - True - label - right - 12 - - - 5 - 6 - 5 - 6 - + - - True - label - right - 12 - - - 5 - 6 - 6 - 7 - + - 1 + 2 @@ -904,7 +987,7 @@ False - 2 + 3