redesign features::force_close internals a bit

This commit is contained in:
2025-04-20 01:42:06 +01:00
parent ccc27b1944
commit da2b15a0b6
+21 -15
View File
@@ -7,8 +7,8 @@ const INTERVAL: Duration = Duration::from_secs(3);
#[derive(Debug)] #[derive(Debug)]
pub struct ForceClose { pub struct ForceClose {
pub button_text: String, pub button_text: String,
prompting: bool, timer: Instant,
interval: Instant, counting: bool,
current_frame: bool, current_frame: bool,
} }
@@ -16,8 +16,8 @@ impl Default for ForceClose {
fn default() -> Self { fn default() -> Self {
Self { Self {
button_text: "Force close game".to_owned(), button_text: "Force close game".to_owned(),
prompting: false, timer: Instant::now(),
interval: Instant::now(), counting: false,
current_frame: false, current_frame: false,
} }
} }
@@ -25,22 +25,28 @@ impl Default for ForceClose {
impl ForceClose { impl ForceClose {
pub fn prompt(&mut self, force_close_button_clicked: bool, sysinfo: &mut System) { pub fn prompt(&mut self, force_close_button_clicked: bool, sysinfo: &mut System) {
if force_close_button_clicked && !self.prompting { if force_close_button_clicked && !self.counting {
*self = Self { self.button_text = "Are you sure?".to_owned();
button_text: "Are you sure?".to_owned(), self.timer = Instant::now();
prompting: true, self.counting = true;
interval: Instant::now(), self.current_frame = true;
current_frame: true,
}
} }
if self.prompting && self.interval.elapsed() <= INTERVAL { if self.counting && self.timer.elapsed() >= INTERVAL {
self.reset();
} else {
if force_close_button_clicked && !self.current_frame { if force_close_button_clicked && !self.current_frame {
activate(sysinfo); activate(sysinfo);
*self = Self::default(); self.reset();
} }
} else {
*self = Self::default();
} }
self.finish_current_frame();
}
fn reset(&mut self) {
*self = Self::default();
}
fn finish_current_frame(&mut self) {
if self.current_frame { if self.current_frame {
self.current_frame = false; self.current_frame = false;
} }