clean up car/track lists

This commit is contained in:
Scott Pruett 2022-05-24 21:40:48 -04:00
parent 9923b95deb
commit c4d9cf341a
4 changed files with 43 additions and 32 deletions

View File

@ -1,4 +1,3 @@
Piccino
Superlight
Eurotruck

View File

@ -1,4 +1,3 @@
Whistle Valley
Sugar Hill
Maple Ridge

View File

@ -81,16 +81,22 @@ fn format_time(time: Duration) -> String {
fn label_time_delta(ui: &mut Ui, time: Duration, old: Option<Duration>) {
if let Some(old) = old {
if time > old {
ui.colored_label(
Color32::LIGHT_RED,
"+".to_owned() + &format_time(time - old),
);
} else {
ui.colored_label(
Color32::LIGHT_GREEN,
"-".to_owned() + &format_time(old - time),
);
match time.cmp(&old) {
std::cmp::Ordering::Less => {
ui.colored_label(
Color32::LIGHT_GREEN,
"-".to_owned() + &format_time(old - time),
);
}
std::cmp::Ordering::Equal => {
ui.colored_label(
Color32::LIGHT_RED,
"+".to_owned() + &format_time(time - old),
);
}
std::cmp::Ordering::Greater => {
ui.label("--");
}
}
} else {
ui.label("--");
@ -119,11 +125,20 @@ struct UiData {
}
fn split_lines(data: &str) -> Vec<String> {
data.split('\n').map(|line| line.trim().to_owned()).collect()
let mut lines: Vec<String> = data
.split('\n')
.map(|line| line.trim().to_owned())
.collect();
lines.push("".to_owned());
lines.reverse();
lines
}
impl UiData {
fn load() -> Self {
Self { cars: split_lines(include_str!("data/car-classes.txt")), tracks: split_lines(include_str!("data/tracklist.txt")) }
Self {
cars: split_lines(include_str!("data/car-classes.txt")),
tracks: split_lines(include_str!("data/tracklist.txt")),
}
}
}
@ -169,7 +184,7 @@ fn show_race_state(
ui.label(format!("#{}", lap.lap.unwrap_or(i + 1)));
if Some(lap_time) == fastest_lap {
ui.colored_label(Color32::from_rgb(255, 0, 255), format_time(lap_time));
ui.colored_label(Color32::GREEN, format_time(lap_time));
} else {
ui.label(format_time(lap_time));
};
@ -281,12 +296,7 @@ fn open_debug_lap(
ocr_cache: Arc<OcrCache>,
) {
if let Some(screenshot) = &lap.screenshot {
let ocr_results = ocr::ocr_all_regions(
screenshot,
config.clone(),
learned,
ocr_cache,
);
let ocr_results = ocr::ocr_all_regions(screenshot, config.clone(), learned, ocr_cache);
let debug_lap = DebugLap {
screenshot: RetainedImage::from_image_bytes("debug-lap", &to_png_bytes(screenshot))
.unwrap(),
@ -297,15 +307,10 @@ fn open_debug_lap(
}
}
fn show_combo_box(
ui: &mut Ui,
name: &str,
label: &str,
options: &[String],
value: &mut String
) {
fn show_combo_box(ui: &mut Ui, name: &str, label: &str, options: &[String], value: &mut String) {
let mut index = options.iter().position(|e| e == value).unwrap_or(0);
egui::ComboBox::new(name, label).show_index(ui, &mut index, options.len(), |i| options[i].clone());
egui::ComboBox::new(name, label)
.show_index(ui, &mut index, options.len(), |i| options[i].clone());
*value = options[index].clone();
}
@ -397,7 +402,13 @@ impl eframe::App for AppUi {
}
if !race.exported {
show_combo_box(ui, "car-combo", "Car", &self.data.cars, &mut race.car);
show_combo_box(ui, "track-combo", "Track", &self.data.tracks, &mut race.track);
show_combo_box(
ui,
"track-combo",
"Track",
&self.data.tracks,
&mut race.track,
);
ui.label("Comments:");
ui.text_edit_singleline(&mut race.comments);
if ui.button("Export").clicked() {

View File

@ -1,5 +1,7 @@
- Recognize
- Penalties
- Pit stops
- ComboBox for car/track
- [DONE] Global best time not current best
- [DONE] ComboBox for car/track
- [DONE] Global best time not current best
- Best time from other racers
- Editable lap stats