Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made collecting scorer cap number optional #193

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions refbox/src/app/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub enum Message {
},
StartPlayNow,
EditScores,
AddNewScore(GameColor),
ChangeScore {
color: GameColor,
increase: bool,
Expand Down Expand Up @@ -102,6 +103,7 @@ impl Message {
| Self::TimeEditComplete { .. }
| Self::StartPlayNow
| Self::EditScores
| Self::AddNewScore(_)
| Self::ScoreEditComplete { .. }
| Self::PenaltyOverview
| Self::PenaltyOverviewComplete { .. }
Expand Down Expand Up @@ -172,6 +174,7 @@ pub enum BoolGameParameter {
AutoSoundStartPlay,
AutoSoundStopPlay,
HideTime,
ScorerCapNum,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
26 changes: 26 additions & 0 deletions refbox/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,23 @@ impl Application for RefBoxApp {
};
trace!("AppState changed to {:?}", self.app_state);
}
Message::AddNewScore(color) => {
if self.config.collect_scorer_cap_num {
self.app_state = AppState::KeypadPage(KeypadPage::AddScore(color), 0);
trace!("AppState changed to {:?}", self.app_state);
} else {
let mut tm = self.tm.lock().unwrap();
let now = Instant::now();
match color {
GameColor::Black => tm.add_b_score(0, now),
GameColor::White => tm.add_w_score(0, now),
}
let snapshot = tm.generate_snapshot(now).unwrap(); // TODO: Remove this unwrap
std::mem::drop(tm);
self.apply_snapshot(snapshot);
}
}

Message::ChangeScore { color, increase } => {
if let AppState::ScoreEdit { ref mut scores, .. } = self.app_state {
if increase {
Expand Down Expand Up @@ -914,6 +931,7 @@ impl Application for RefBoxApp {
sound: self.config.sound.clone(),
mode: self.config.mode,
hide_time: self.config.hide_time,
collect_scorer_cap_num: self.config.collect_scorer_cap_num,
};

self.edited_settings = Some(edited_settings);
Expand Down Expand Up @@ -1009,6 +1027,8 @@ impl Application for RefBoxApp {
self.config.sound = edited_settings.sound;
self.sound.update_settings(self.config.sound.clone());
self.config.mode = edited_settings.mode;
self.config.collect_scorer_cap_num =
edited_settings.collect_scorer_cap_num;

if self.config.hide_time != edited_settings.hide_time {
self.config.hide_time = edited_settings.hide_time;
Expand All @@ -1033,6 +1053,8 @@ impl Application for RefBoxApp {
self.config.sound = edited_settings.sound;
self.sound.update_settings(self.config.sound.clone());
self.config.mode = edited_settings.mode;
self.config.collect_scorer_cap_num =
edited_settings.collect_scorer_cap_num;

if self.config.hide_time != edited_settings.hide_time {
self.config.hide_time = edited_settings.hide_time;
Expand Down Expand Up @@ -1082,6 +1104,7 @@ impl Application for RefBoxApp {
self.config.sound = edited_settings.sound;
self.sound.update_settings(self.config.sound.clone());
self.config.mode = edited_settings.mode;
self.config.collect_scorer_cap_num = edited_settings.collect_scorer_cap_num;

if self.config.hide_time != edited_settings.hide_time {
self.config.hide_time = edited_settings.hide_time;
Expand Down Expand Up @@ -1270,6 +1293,9 @@ impl Application for RefBoxApp {
edited_settings.sound.auto_sound_stop_play ^= true
}
BoolGameParameter::HideTime => edited_settings.hide_time ^= true,
BoolGameParameter::ScorerCapNum => {
edited_settings.collect_scorer_cap_num ^= true
}
}
}
Message::CycleParameter(param) => {
Expand Down
13 changes: 11 additions & 2 deletions refbox/src/app/view_builders/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(in super::super) struct EditableSettings {
pub sound: SoundSettings,
pub mode: Mode,
pub hide_time: bool,
pub collect_scorer_cap_num: bool,
}

pub(in super::super) trait Cyclable
Expand Down Expand Up @@ -201,16 +202,24 @@ fn make_main_config_page<'a>(
.width(Length::Fill)
.height(Length::Fill)
.push(make_value_button(
"MODE",
"APP\nMODE",
settings.mode.to_string().to_uppercase(),
(true, true),
(false, true),
Some(Message::CycleParameter(CyclingParameter::Mode)),
))
.push(make_value_button(
"HIDE TIME FOR\nLAST 15 SECONDS",
bool_string(settings.hide_time),
(false, true),
Some(Message::ToggleBoolParameter(BoolGameParameter::HideTime)),
))
.push(make_value_button(
"TRACK CAP NUMBER\nOF SCORER",
bool_string(settings.collect_scorer_cap_num),
(false, true),
Some(Message::ToggleBoolParameter(
BoolGameParameter::ScorerCapNum,
)),
)),
)
.push(
Expand Down
6 changes: 2 additions & 4 deletions refbox/src/app/view_builders/main_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,9 @@ pub(in super::super) fn build_main_view<'a>(

if snapshot.current_period != GamePeriod::BetweenGames {
black_score_btn = black_score_btn.on_press(Message::EditScores);
black_new_score_btn = black_new_score_btn
.on_press(Message::KeypadPage(KeypadPage::AddScore(GameColor::Black)));
black_new_score_btn = black_new_score_btn.on_press(Message::AddNewScore(GameColor::Black));
white_score_btn = white_score_btn.on_press(Message::EditScores);
white_new_score_btn = white_new_score_btn
.on_press(Message::KeypadPage(KeypadPage::AddScore(GameColor::White)));
white_new_score_btn = white_new_score_btn.on_press(Message::AddNewScore(GameColor::White));
}

let black_col = column()
Expand Down
1 change: 1 addition & 0 deletions refbox/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl Default for UwhScores {
pub struct Config {
pub mode: Mode,
pub hide_time: bool,
pub collect_scorer_cap_num: bool,
pub game: Game,
pub hardware: Hardware,
pub uwhscores: UwhScores,
Expand Down