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

Add details to center button and make new game summary page #190

Merged
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
2 changes: 2 additions & 0 deletions refbox/src/app/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum Message {
AddScoreComplete {
canceled: bool,
},
ShowGameDetails,
EditGameConfig,
ChangeConfigPage(ConfigPage),
ConfigEditComplete {
Expand Down Expand Up @@ -110,6 +111,7 @@ impl Message {
| Self::KeypadPage(_)
| Self::ChangeColor(_)
| Self::AddScoreComplete { .. }
| Self::ShowGameDetails
| Self::EditGameConfig
| Self::ChangeConfigPage(_)
| Self::ConfigEditComplete { .. }
Expand Down
13 changes: 13 additions & 0 deletions refbox/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum AppState {
},
PenaltyOverview(BlackWhiteBundle<usize>),
KeypadPage(KeypadPage, u16),
GameDetailsPage,
EditGameConfig(ConfigPage),
ParameterEditor(LengthParameter, Duration),
ParameterList(ListableParameter, usize),
Expand Down Expand Up @@ -898,6 +899,10 @@ impl Application for RefBoxApp {
};
trace!("AppState changed to {:?}", self.app_state);
}
Message::ShowGameDetails => {
self.app_state = AppState::GameDetailsPage;
trace!("AppState changed to {:?}", self.app_state);
}
Message::EditGameConfig => {
let edited_settings = EditableSettings {
config: self.tm.lock().unwrap().config().clone(),
Expand Down Expand Up @@ -1673,6 +1678,14 @@ impl Application for RefBoxApp {
self.config.mode,
clock_running,
),
AppState::GameDetailsPage => build_game_info_page(
&self.snapshot,
&self.config.game,
self.using_uwhscores,
&self.games,
self.config.mode,
clock_running,
),
AppState::EditGameConfig(page) => build_game_config_edit_page(
&self.snapshot,
self.edited_settings.as_ref().unwrap(),
Expand Down
233 changes: 233 additions & 0 deletions refbox/src/app/view_builders/game_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
use super::{
style::{self, SMALL_TEXT, SPACING},
*,
};
use iced::{
alignment::{Horizontal, Vertical},
pure::{column, horizontal_space, row, text, Element},
Length,
};

use std::fmt::Write;

use uwh_common::game_snapshot::GameSnapshot;

pub(in super::super) fn build_game_info_page<'a>(
snapshot: &GameSnapshot,
config: &GameConfig,
using_uwhscores: bool,
games: &Option<BTreeMap<u32, GameInfo>>,
mode: Mode,
clock_running: bool,
) -> Element<'a, Message> {
let (left_details, right_details) = details_strings(snapshot, config, using_uwhscores, games);
column()
.spacing(SPACING)
.height(Length::Fill)
.push(make_game_time_button(
snapshot,
false,
false,
mode,
clock_running,
))
.push(
row()
.spacing(SPACING)
.width(Length::Fill)
.height(Length::Fill)
.push(
text(left_details)
.size(SMALL_TEXT)
.vertical_alignment(Vertical::Top)
.horizontal_alignment(Horizontal::Left)
.width(Length::Fill),
)
.push(
text(right_details)
.size(SMALL_TEXT)
.vertical_alignment(Vertical::Top)
.horizontal_alignment(Horizontal::Left)
.width(Length::Fill),
),
)
.push(
row()
.spacing(SPACING)
.width(Length::Fill)
.push(
make_button("BACK")
.style(style::Button::Red)
.width(Length::Fill)
.on_press(Message::ConfigEditComplete { canceled: true }),
)
.push(horizontal_space(Length::Fill))
.push(
make_button("SETTINGS")
.style(style::Button::Gray)
.width(Length::Fill)
.on_press(Message::EditGameConfig),
),
)
.into()
}

fn details_strings(
snapshot: &GameSnapshot,
config: &GameConfig,
using_uwhscores: bool,
games: &Option<BTreeMap<u32, GameInfo>>,
) -> (String, String) {
const TEAM_NAME_LEN_LIMIT: usize = 40;
let mut left_string = String::new();
let mut right_string = String::new();
let game_number = if snapshot.current_period == GamePeriod::BetweenGames {
let prev_game;
let next_game;
if using_uwhscores {
if let Some(games) = games {
prev_game = match games.get(&snapshot.game_number) {
Some(game) => game_string_short(game),
None if snapshot.game_number == 0 => "None".to_string(),
None => format!("Error ({})", snapshot.game_number),
};
next_game = match games.get(&snapshot.next_game_number) {
Some(game) => game_string_short(game),
None => format!("Error ({})", snapshot.next_game_number),
};
} else {
prev_game = if snapshot.game_number == 0 {
"None".to_string()
} else {
format!("Error ({})", snapshot.game_number)
};
next_game = format!("Error ({})", snapshot.next_game_number);
}
} else {
prev_game = if snapshot.game_number == 0 {
"None".to_string()
} else {
snapshot.game_number.to_string()
};
next_game = snapshot.next_game_number.to_string();
}

write!(
&mut left_string,
"Last Game: {}, \nNext Game: {}\n",
prev_game, next_game
)
.unwrap();
snapshot.next_game_number
} else {
let game;
if using_uwhscores {
if let Some(games) = games {
game = match games.get(&snapshot.game_number) {
Some(game) => game_string_short(game),
None => format!("Error ({})", snapshot.game_number),
};
} else {
game = format!("Error ({})", snapshot.game_number);
}
} else {
game = snapshot.game_number.to_string();
}
writeln!(&mut left_string, "Game: {}", game).unwrap();
snapshot.game_number
};

if using_uwhscores {
if let Some(games) = games {
if let Some(game) = games.get(&game_number) {
write!(
&mut left_string,
"Black Team: {}\nWhite Team: {}\n",
limit_team_name_len(&game.black, TEAM_NAME_LEN_LIMIT),
limit_team_name_len(&game.white, TEAM_NAME_LEN_LIMIT)
)
.unwrap()
}
}
}

write!(
&mut left_string,
"Half Length: {}\n\
Half Time Length: {}\n\
Overtime Allowed: {}\n",
time_string(config.half_play_duration),
time_string(config.half_time_duration),
bool_string(config.overtime_allowed),
)
.unwrap();
if config.overtime_allowed {
write!(
&mut left_string,
"Pre-Overtime Break Length: {}\n\
Overtime Half Length: {}\n\
Overtime Half Time Length: {}\n",
time_string(config.pre_overtime_break),
time_string(config.ot_half_play_duration),
time_string(config.ot_half_time_duration),
)
.unwrap()
};
writeln!(
&mut left_string,
"Sudden Death Allowed: {}",
bool_string(config.sudden_death_allowed)
)
.unwrap();

if config.sudden_death_allowed {
writeln!(
&mut left_string,
"Pre-Sudden-Death Break Length: {}",
time_string(config.pre_sudden_death_duration)
)
.unwrap()
};
writeln!(
&mut left_string,
"Team Timeouts Allowed Per Half: {}",
config.team_timeouts_per_half
)
.unwrap();
if config.team_timeouts_per_half != 0 {
writeln!(
&mut left_string,
"Team Timeout Duration: {}",
time_string(config.team_timeout_duration)
)
.unwrap()
};
if !using_uwhscores {
writeln!(
&mut left_string,
"Nominal Time Between Games: {}",
time_string(config.nominal_break),
)
.unwrap();
}
writeln!(
&mut left_string,
"Minimum Time Between Games: {}",
time_string(config.minimum_break),
)
.unwrap();

writeln!(&mut left_string, "Stop clock in last 2 minutes: UNKNOWN").unwrap();

write!(
&mut right_string,
"Cheif ref: UNKNOWN\n\
Timer: UNKNOWN\n\
Water ref 1: UNKNOWN\n\
Water ref 2: UNKNOWN\n\
Water ref 3: UNKNOWN",
)
.unwrap();

(left_string, right_string)
}
2 changes: 1 addition & 1 deletion refbox/src/app/view_builders/main_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(in super::super) fn build_main_view<'a>(
.style(style::Button::LightGray)
.width(Length::Fill)
.height(Length::Fill)
.on_press(Message::EditGameConfig),
.on_press(Message::ShowGameDetails),
);

let make_penalty_button = |snapshot: &GameSnapshot, color: GameColor| {
Expand Down
3 changes: 3 additions & 0 deletions refbox/src/app/view_builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub(super) use configuration::*;
pub mod confirmation;
pub(super) use confirmation::*;

pub mod game_info;
pub(super) use game_info::*;

pub mod list_selector;
pub(super) use list_selector::*;

Expand Down
Loading