Skip to content

Commit

Permalink
Add error modal and retake screenshots option
Browse files Browse the repository at this point in the history
  • Loading branch information
addiswebb committed Jul 29, 2024
1 parent 930f1fe commit 6418deb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "automate"
version = "3.0.0"
version = "3.1.0"
edition = "2021"
rust-version = "1.76"

Expand Down
5 changes: 3 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct App {
#[serde(skip)]
// weird name, basically determines whether the save before exiting dialog closes the window or creates a new file
dialog_purpose: DialogPurpose,
#[serde(skip)]
settings: Settings,
}

Expand Down Expand Up @@ -365,7 +366,6 @@ impl eframe::App for App {
}
});


if self.show_save_dialog {
egui::Window::new("Automate")
.resizable(false)
Expand Down Expand Up @@ -750,9 +750,10 @@ impl eframe::App for App {
.update(&mut self.last_instant, ctx, &self.settings);

self.sequencer.show(ctx);
self.sequencer.debug_panel(ctx);
self.sequencer.debug_panel(ctx, &mut self.settings);
self.sequencer.selected_panel(ctx, &self.settings);
self.sequencer.central_panel(ctx);
self.sequencer.modal(ctx);

// If sequencer has changed or the file is not uptodate
self.file_uptodate = !self.sequencer.changed.load(Ordering::Relaxed);
Expand Down
56 changes: 42 additions & 14 deletions src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub struct Sequencer {
pub recording_keyframes: Arc<Mutex<Vec<Keyframe>>>,
#[serde(skip)]
mouse_pos: Arc<Mutex<Vec2>>,
modal: (bool, String, String),
}

impl Sequencer {
Expand Down Expand Up @@ -345,6 +346,7 @@ impl Sequencer {
failsafe_edge,
changes: (Vec::new(), Vec::new()),
mouse_pos,
modal: (false, "".to_string(), "".to_string()),
}
}
// Handles cleanup after changes were made
Expand Down Expand Up @@ -1402,7 +1404,7 @@ impl Sequencer {
);
}
/// Renders a debug panel with relevant information
pub fn debug_panel(&mut self, ctx: &egui::Context) {
pub fn debug_panel(&mut self, ctx: &egui::Context, settings: &mut Settings) {
egui::SidePanel::right("Debug")
.max_width(200.0)
.resizable(false)
Expand All @@ -1415,7 +1417,7 @@ impl Sequencer {
self.mouse_pos.lock().unwrap()
));
ui.checkbox(&mut self.clear_before_recording, "Overwrite Recording");
if ui.button("debug").clicked() {}
ui.checkbox(&mut settings.retake_screenshots, "Retake screenshots");
});
}
/// Renders the editable data of the selected keyframe
Expand Down Expand Up @@ -1850,18 +1852,34 @@ impl Sequencer {
// If so and the sequencer is playing
if play {
// When fail detection is enabled check if the keyframe has a screenshot
if settings.fail_detection {
if let Some(src1) = self.images.lock().unwrap().get(&uid) {
if let Some(src2) = screenshot() {
let percentage_err = image_dif_opencv(src1, &src2);
if percentage_err > settings.max_fail_error {
self.play.swap(false, Ordering::Relaxed);
ctx.send_viewport_cmd(egui::ViewportCommand::Focus);
log::warn!(
"Fail Detected: {:?}% err",
percentage_err * 100.
);
break;
if settings.fail_detection || settings.retake_screenshots {
if let Some(src1) = screenshot() {
let mut images = self.images.lock().unwrap();
if settings.retake_screenshots {
// Replace the current screenshot with a new one
images.remove(&uid);
images.insert(uid, src1);
} else {
if let Some(src2) = images.get(&uid) {
let percentage_err = image_dif_opencv(&src1, src2);
if percentage_err > settings.max_fail_error {
self.play.swap(false, Ordering::Relaxed);
ctx.send_viewport_cmd(egui::ViewportCommand::Focus);
self.modal = (
true,
format!(
"Fail Detected: {:?}%",
percentage_err * 100.
)
.to_string(),
"Paused playback as a result.".to_string(),
);
log::warn!(
"Fail Detected: {:?}% err",
percentage_err * 100.
);
break;
}
}
}
}
Expand Down Expand Up @@ -2127,6 +2145,16 @@ impl Sequencer {
ui.close_menu();
}
}
pub fn modal(&mut self, ctx: &egui::Context) {
egui::Window::new(self.modal.1.clone())
.movable(true)
.collapsible(false)
.resizable(false)
.open(&mut self.modal.0)
.show(ctx, |ui| {
ui.label(self.modal.2.clone());
});
}
}

impl Default for Sequencer {
Expand Down
2 changes: 2 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct Settings {
pub fail_detection: bool,
pub max_fail_error: f32,
pub offset: Vec2,
pub retake_screenshots: bool,
#[serde(skip)]
pub page: SettingsPage,
#[serde(skip)]
Expand Down Expand Up @@ -145,6 +146,7 @@ impl Default for Settings {
fail_detection: true,
max_fail_error: 0.2,
offset: Vec2::NAN,
retake_screenshots: false,
page: SettingsPage::Preferences,
show: false,
}
Expand Down

0 comments on commit 6418deb

Please sign in to comment.