Skip to content

Commit

Permalink
Add comparison next/prev
Browse files Browse the repository at this point in the history
  • Loading branch information
dagit committed Jun 13, 2023
1 parent c748575 commit 4ab7b85
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ struct AppConfig {
hot_key_skip: Option<HotKey>,
#[clap(skip)]
hot_key_pause: Option<HotKey>,
#[clap(skip)]
hot_key_comparison_next: Option<HotKey>,
#[clap(skip)]
hot_key_comparison_prev: Option<HotKey>,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, Serialize, Deserialize, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -116,6 +120,14 @@ impl AppConfig {
key: egui::Key::Num5,
modifiers,
}),
hot_key_comparison_next: Some(HotKey {
key: egui::Key::Num6,
modifiers,
}),
hot_key_comparison_prev: Some(HotKey {
key: egui::Key::Num4,
modifiers,
}),
use_autosplitter: Some(YesOrNo::Yes),
frame_rate: Some(DEFAULT_FRAME_RATE),
polling_rate: Some(DEFAULT_POLLING_RATE),
Expand Down Expand Up @@ -327,8 +339,8 @@ impl LiveSplitCoreRenderer {
// TODO: fix this unwrap
if self.timer.read().unwrap().run().has_been_modified() {
let save_requested = MessageDialog::new()
.set_level(MessageLevel::Error)
.set_title("Error")
.set_level(MessageLevel::Warning)
.set_title("Save Splits")
.set_description("Splits have been modified. Save splits?")
.set_buttons(MessageButtons::YesNo)
.show();
Expand All @@ -338,8 +350,8 @@ impl LiveSplitCoreRenderer {
}
if self.settings.read().has_been_modified() {
let save_requested = MessageDialog::new()
.set_level(MessageLevel::Error)
.set_title("Error")
.set_level(MessageLevel::Warning)
.set_title("Save Autosplitter Config")
.set_description(
"Autosplit config may have been modified. Save autosplitter config?",
)
Expand Down Expand Up @@ -840,6 +852,42 @@ impl LiveSplitCoreRenderer {
})?;
}
}
let timer = self.timer.clone();
if let Some(hot_key) = self.app_config.hot_key_comparison_next {
hook.register(hot_key.to_livesplit_hotkey(), move || {
// TODO: fix this unwrap
timer.write().unwrap().switch_to_next_comparison();
})?;
if let Some(alt_key) = to_livesplit_keycode_alternative(&hot_key.key) {
let alternative = livesplit_hotkey::Hotkey {
key_code: alt_key,
modifiers: to_livesplit_modifiers(&hot_key.modifiers),
};
let timer = self.timer.clone();
hook.register(alternative, move || {
// TODO: fix this unwrap
timer.write().unwrap().switch_to_next_comparison();
})?;
}
}
let timer = self.timer.clone();
if let Some(hot_key) = self.app_config.hot_key_comparison_prev {
hook.register(hot_key.to_livesplit_hotkey(), move || {
// TODO: fix this unwrap
timer.write().unwrap().switch_to_previous_comparison();
})?;
if let Some(alt_key) = to_livesplit_keycode_alternative(&hot_key.key) {
let alternative = livesplit_hotkey::Hotkey {
key_code: alt_key,
modifiers: to_livesplit_modifiers(&hot_key.modifiers),
};
let timer = self.timer.clone();
hook.register(alternative, move || {
// TODO: fix this unwrap
timer.write().unwrap().switch_to_previous_comparison();
})?;
}
}
println!("registered");
Ok(())
}
Expand Down Expand Up @@ -1326,6 +1374,18 @@ void main() {
self.timer.write().unwrap().toggle_pause();
}
}
if let Some(hot_key) = self.app_config.hot_key_comparison_next {
if input.consume_key(hot_key.modifiers, hot_key.key) {
// TODO: fix this unwrap
self.timer.write().unwrap().switch_to_next_comparison();
}
}
if let Some(hot_key) = self.app_config.hot_key_comparison_prev {
if input.consume_key(hot_key.modifiers, hot_key.key) {
// TODO: fix this unwrap
self.timer.write().unwrap().switch_to_previous_comparison();
}
}
});
}

Expand Down

0 comments on commit 4ab7b85

Please sign in to comment.