Skip to content

Commit

Permalink
Merge #177
Browse files Browse the repository at this point in the history
177: Time play pause r=TristanDebrunner a=TristanDebrunner

Add a play/pause button for the time while in rugby mode

Co-authored-by: Tristan Debrunner <tdebrunner@atlantissports.org>
  • Loading branch information
bors[bot] and TristanDebrunner authored Jul 20, 2023
2 parents 1ba56b4 + 933780f commit a074adb
Show file tree
Hide file tree
Showing 13 changed files with 498 additions and 72 deletions.
Binary file modified refbox/resources/Roboto-Medium.ttf
Binary file not shown.
6 changes: 5 additions & 1 deletion refbox/src/app/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub enum Message {
RecvTournament(TournamentInfo),
RecvGameList(Vec<GameInfo>),
RecvGame(GameInfo),
StopClock,
StartClock,
NoAction, // TODO: Remove once UI is functional
}

Expand Down Expand Up @@ -125,7 +127,9 @@ impl Message {
| Self::PenaltyShot(_)
| Self::EndTimeout
| Self::ConfirmScores(_)
| Self::ScoreConfirmation { .. } => false,
| Self::ScoreConfirmation { .. }
| Self::StopClock
| Self::StartClock => false,
}
}
}
Expand Down
103 changes: 84 additions & 19 deletions refbox/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,17 +607,20 @@ impl Application for RefBoxApp {
Message::TimeEditComplete { canceled } => {
if let AppState::TimeEdit(was_running, game_time, timeout_time) = self.app_state {
let mut tm = self.tm.lock().unwrap();
let now = Instant::now();
if !canceled {
tm.set_game_clock_time(game_time).unwrap();
if let Some(time) = timeout_time {
tm.set_timeout_clock_time(time).unwrap();
}
}
if was_running {
let now = Instant::now();
tm.start_clock(now);
tm.update(now).unwrap();
}
let snapshot = tm.generate_snapshot(now).unwrap();
drop(tm);
self.apply_snapshot(snapshot);
self.app_state = self.last_app_state.clone();
trace!("AppState changed to {:?}", self.app_state);
} else {
Expand Down Expand Up @@ -751,6 +754,13 @@ impl Application for RefBoxApp {
} else {
self.app_state = AppState::MainPage;
}
let snapshot = self
.tm
.lock()
.unwrap()
.generate_snapshot(Instant::now())
.unwrap();
self.apply_snapshot(snapshot);
trace!("AppState changed to {:?}", self.app_state);
}
Message::ChangeKind(new_kind) => {
Expand Down Expand Up @@ -1478,10 +1488,28 @@ impl Application for RefBoxApp {
}
Message::EndTimeout => {
let mut tm = self.tm.lock().unwrap();
tm.end_timeout(Instant::now()).unwrap();
let snapshot = tm.generate_snapshot(Instant::now()).unwrap();
let now = Instant::now();
let would_end = tm.timeout_end_would_end_game(now).unwrap();
if would_end {
tm.halt_clock(now, true).unwrap();
} else {
tm.end_timeout(now).unwrap();
tm.update(now).unwrap();
}
let snapshot = tm.generate_snapshot(now).unwrap();
std::mem::drop(tm);
self.apply_snapshot(snapshot);

if would_end {
let scores = BlackWhiteBundle {
black: self.snapshot.b_score,
white: self.snapshot.w_score,
};

self.app_state = AppState::ConfirmScores(scores);
trace!("AppState changed to {:?}", self.app_state);
}

if let AppState::TimeEdit(_, _, ref mut timeout) = self.app_state {
*timeout = None;
}
Expand Down Expand Up @@ -1545,6 +1573,8 @@ impl Application for RefBoxApp {
self.games = Some(BTreeMap::from([(game.gid, game)]));
}
}
Message::StartClock => self.tm.lock().unwrap().start_clock(Instant::now()),
Message::StopClock => self.tm.lock().unwrap().stop_clock(Instant::now()).unwrap(),
Message::NoAction => {}
};

Expand All @@ -1556,6 +1586,7 @@ impl Application for RefBoxApp {
}

fn view(&self) -> Element<Message> {
let clock_running = self.tm.lock().unwrap().clock_is_running();
let mut main_view = column()
.spacing(SPACING)
.padding(PADDING)
Expand All @@ -1578,45 +1609,79 @@ impl Application for RefBoxApp {
&self.config.game
};

build_main_view(&self.snapshot, config, self.using_uwhscores, &self.games)
}
AppState::TimeEdit(_, time, timeout_time) => {
build_time_edit_view(&self.snapshot, time, timeout_time)
build_main_view(
&self.snapshot,
config,
self.using_uwhscores,
&self.games,
self.config.mode,
clock_running,
)
}
AppState::TimeEdit(_, time, timeout_time) => build_time_edit_view(
&self.snapshot,
time,
timeout_time,
self.config.mode,
clock_running,
),
AppState::ScoreEdit {
scores,
is_confirmation,
} => build_score_edit_view(&self.snapshot, scores, is_confirmation),
} => build_score_edit_view(
&self.snapshot,
scores,
is_confirmation,
self.config.mode,
clock_running,
),
AppState::PenaltyOverview(indices) => build_penalty_overview_page(
&self.snapshot,
self.pen_edit.get_printable_lists(Instant::now()).unwrap(),
indices,
self.config.mode,
clock_running,
),
AppState::KeypadPage(page, player_num) => build_keypad_page(
&self.snapshot,
page,
player_num,
self.config.mode,
clock_running,
),
AppState::KeypadPage(page, player_num) => {
build_keypad_page(&self.snapshot, page, player_num, self.config.mode)
}
AppState::EditGameConfig(page) => build_game_config_edit_page(
&self.snapshot,
self.edited_settings.as_ref().unwrap(),
&self.tournaments,
page,
self.config.mode,
clock_running,
),
AppState::ParameterEditor(param, dur) => build_game_parameter_editor(
&self.snapshot,
param,
dur,
self.config.mode,
clock_running,
),
AppState::ParameterEditor(param, dur) => {
build_game_parameter_editor(&self.snapshot, param, dur)
}
AppState::ParameterList(param, index) => build_list_selector_page(
&self.snapshot,
param,
index,
self.edited_settings.as_ref().unwrap(),
&self.tournaments,
self.config.mode,
clock_running,
),
AppState::ConfirmationPage(ref kind) => {
build_confirmation_page(&self.snapshot, kind)
}
AppState::ConfirmScores(scores) => {
build_score_confirmation_page(&self.snapshot, scores)
build_confirmation_page(&self.snapshot, kind, self.config.mode, clock_running)
}
AppState::ConfirmScores(scores) => build_score_confirmation_page(
&self.snapshot,
scores,
self.config.mode,
clock_running,
),
});

match self.app_state {
Expand Down Expand Up @@ -1706,7 +1771,7 @@ impl<H: Hasher, I> Recipe<H, I> for TimeUpdater {
let now = Instant::now();

let msg_type = if tm.would_end_game(now).unwrap() {
tm.halt_clock(now).unwrap();
tm.halt_clock(now, false).unwrap();
clock_running = false;
Message::ConfirmScores
} else {
Expand Down
62 changes: 53 additions & 9 deletions refbox/src/app/view_builders/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,26 @@ pub(in super::super) fn build_game_config_edit_page<'a>(
settings: &EditableSettings,
tournaments: &Option<BTreeMap<u32, TournamentInfo>>,
page: ConfigPage,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
match page {
ConfigPage::Main => make_main_config_page(snapshot, settings),
ConfigPage::Tournament => make_tournament_config_page(snapshot, settings, tournaments),
ConfigPage::Sound => make_sound_config_page(snapshot, settings),
ConfigPage::Main => make_main_config_page(snapshot, settings, mode, clock_running),
ConfigPage::Tournament => {
make_tournament_config_page(snapshot, settings, tournaments, mode, clock_running)
}
ConfigPage::Sound => make_sound_config_page(snapshot, settings, mode, clock_running),
ConfigPage::Remotes(index, listening) => {
make_remote_config_page(snapshot, settings, index, listening)
make_remote_config_page(snapshot, settings, index, listening, mode, clock_running)
}
}
}

fn make_main_config_page<'a>(
snapshot: &GameSnapshot,
settings: &EditableSettings,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
let EditableSettings {
game_number,
Expand Down Expand Up @@ -161,7 +167,13 @@ fn make_main_config_page<'a>(
column()
.spacing(SPACING)
.height(Length::Fill)
.push(make_game_time_button(snapshot, false, true).on_press(Message::EditTime))
.push(make_game_time_button(
snapshot,
false,
false,
mode,
clock_running,
))
.push(make_value_button(
"GAME:",
game_label,
Expand Down Expand Up @@ -213,6 +225,8 @@ fn make_tournament_config_page<'a>(
snapshot: &GameSnapshot,
settings: &EditableSettings,
tournaments: &Option<BTreeMap<u32, TournamentInfo>>,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
let EditableSettings {
config,
Expand Down Expand Up @@ -410,7 +424,13 @@ fn make_tournament_config_page<'a>(
let mut col = column()
.spacing(SPACING)
.height(Length::Fill)
.push(make_game_time_button(snapshot, false, true).on_press(Message::EditTime))
.push(make_game_time_button(
snapshot,
false,
false,
mode,
clock_running,
))
.push(
make_value_button(
"USING UWHPORTAL:",
Expand All @@ -433,6 +453,8 @@ fn make_tournament_config_page<'a>(
fn make_sound_config_page<'a>(
snapshot: &GameSnapshot,
settings: &EditableSettings,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
let EditableSettings {
white_on_right,
Expand Down Expand Up @@ -481,7 +503,13 @@ fn make_sound_config_page<'a>(
column()
.spacing(SPACING)
.height(Length::Fill)
.push(make_game_time_button(snapshot, false, true).on_press(Message::EditTime))
.push(make_game_time_button(
snapshot,
false,
false,
mode,
clock_running,
))
.push(sides_btn)
.push(
row()
Expand Down Expand Up @@ -611,6 +639,8 @@ fn make_remote_config_page<'a>(
settings: &EditableSettings,
index: usize,
listening: bool,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
const REMOTES_LIST_LEN: usize = 4;

Expand Down Expand Up @@ -692,7 +722,13 @@ fn make_remote_config_page<'a>(
column()
.spacing(SPACING)
.height(Length::Fill)
.push(make_game_time_button(snapshot, false, true).on_press(Message::EditTime))
.push(make_game_time_button(
snapshot,
false,
false,
mode,
clock_running,
))
.push(
row()
.spacing(SPACING)
Expand Down Expand Up @@ -733,6 +769,8 @@ pub(in super::super) fn build_game_parameter_editor<'a>(
snapshot: &GameSnapshot,
param: LengthParameter,
length: Duration,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
let (title, hint) = match param {
LengthParameter::Half => ("HALF LEN", "The length of a half during regular play"),
Expand Down Expand Up @@ -772,7 +810,13 @@ pub(in super::super) fn build_game_parameter_editor<'a>(
.align_items(Alignment::Center)
.width(Length::Fill)
.height(Length::Fill)
.push(make_game_time_button(snapshot, false, true).on_press(Message::EditTime))
.push(make_game_time_button(
snapshot,
false,
false,
mode,
clock_running,
))
.push(vertical_space(Length::Fill))
.push(make_time_editor(title, length, false))
.push(vertical_space(Length::Fill))
Expand Down
20 changes: 18 additions & 2 deletions refbox/src/app/view_builders/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use uwh_common::game_snapshot::GameSnapshot;
pub(in super::super) fn build_confirmation_page<'a>(
snapshot: &GameSnapshot,
kind: &ConfirmationKind,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
let header_text = match kind {
ConfirmationKind::GameConfigChanged(_) => "The game configuration can not be changed while a game is in progress.\n\nWhat would you like to do?",
Expand Down Expand Up @@ -99,7 +101,13 @@ pub(in super::super) fn build_confirmation_page<'a>(
.width(Length::Fill)
.height(Length::Fill)
.align_items(Alignment::Center)
.push(make_game_time_button(snapshot, false, true).on_press(Message::EditTime))
.push(make_game_time_button(
snapshot,
false,
false,
mode,
clock_running,
))
.push(vertical_space(Length::Fill))
.push(
row()
Expand All @@ -126,6 +134,8 @@ pub(in super::super) fn build_confirmation_page<'a>(
pub(in super::super) fn build_score_confirmation_page<'a>(
snapshot: &GameSnapshot,
scores: BlackWhiteBundle<u8>,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
let header = text(format!(
"Is this score correct?\n\nBlack: {} White: {}\n",
Expand All @@ -151,7 +161,13 @@ pub(in super::super) fn build_score_confirmation_page<'a>(
.width(Length::Fill)
.height(Length::Fill)
.align_items(Alignment::Center)
.push(make_game_time_button(snapshot, false, true).on_press(Message::EditTime))
.push(make_game_time_button(
snapshot,
false,
false,
mode,
clock_running,
))
.push(vertical_space(Length::Fill))
.push(
row()
Expand Down
Loading

0 comments on commit a074adb

Please sign in to comment.