Add leader board config

This commit is contained in:
hodasemi 2023-01-20 22:31:43 +01:00
parent caf49fe528
commit f5c8ae5c2c
3 changed files with 33 additions and 8 deletions

View file

@ -2,6 +2,7 @@ mod bg_generator;
mod leaderboard_entry;
use leaderboard_entry::*;
use serde::{Deserialize, Serialize};
use std::{
ffi::{c_char, CStr},
@ -11,7 +12,6 @@ use std::{
use anyhow::Result;
use rfactor_sm_reader::{rF2VehicleTelemetry, VehicleScoringInfoV01};
use ui::prelude::*;
use utilities::prelude::Color;
use vulkan_rs::prelude::*;
use crate::overlay::{
@ -20,7 +20,24 @@ use crate::overlay::{
};
use crate::write_log;
use self::bg_generator::BackgroundGenerator;
use bg_generator::BackgroundGenerator;
#[derive(Default, Deserialize, Serialize, Clone, Copy)]
pub struct LeaderBoardConfig {
first_board_color: [f32; 3],
second_board_color: [f32; 3],
player_board_color: [f32; 3],
}
impl LeaderBoardConfig {
pub const fn new() -> Self {
Self {
first_board_color: [0.33; 3],
second_board_color: [0.51; 3],
player_board_color: [0.7, 0.75, 0.15],
}
}
}
pub struct LeaderBoard {
gui_handler: Arc<GuiHandler>,
@ -44,7 +61,10 @@ impl LeaderBoard {
const LEADERBOARD: &str = include_str!("leaderboard_grid.xml");
const DELTABOARD: &str = include_str!("deltaboard_grid.xml");
pub fn new(gui_handler: &Arc<GuiHandler>) -> Result<Self> {
pub fn new(
gui_handler: &Arc<GuiHandler>,
leader_board_config: LeaderBoardConfig,
) -> Result<Self> {
let leaderboard = GuiBuilder::from_str(gui_handler, Self::LEADERBOARD)?;
let deltaboard = GuiBuilder::from_str(gui_handler, Self::DELTABOARD)?;
@ -64,15 +84,15 @@ impl LeaderBoard {
let colors = [
{
let a: [f32; 3] = Color::try_from("#545454")?.into();
let a = leader_board_config.first_board_color;
[a[0], a[1], a[2], 1.0]
},
{
let a: [f32; 3] = Color::try_from("#838383")?.into();
let a = leader_board_config.second_board_color;
[a[0], a[1], a[2], 1.0]
},
{
let a: [f32; 3] = Color::try_from("#b4bf26")?.into();
let a = leader_board_config.player_board_color;
[a[0], a[1], a[2], 1.0]
},
];

View file

@ -42,7 +42,7 @@ impl RadarConfig {
Self {
radar_scale: 1.0,
radar_center_factor: 0.25,
radar_transparency: 0.5,
radar_transparency: 0.3,
height_scale: 0.15,
width_scale: 0.4,
radar_car_distance: 20.0,

View file

@ -49,6 +49,7 @@ impl UiSelectorConfig {
pub struct OverlayConfig {
pub ui_config: UiSelectorConfig,
pub radar_config: RadarConfig,
pub leader_board_config: LeaderBoardConfig,
}
impl OverlayConfig {
@ -56,6 +57,7 @@ impl OverlayConfig {
Self {
ui_config: UiSelectorConfig::new(),
radar_config: RadarConfig::new(),
leader_board_config: LeaderBoardConfig::new(),
}
}
}
@ -208,7 +210,10 @@ impl Overlay {
// create leaderboard
if self.config.ui_config.enable_leaderboard {
let leaderboard = Rc::new(RefCell::new(LeaderBoard::new(&gui_handler)?));
let leaderboard = Rc::new(RefCell::new(LeaderBoard::new(
&gui_handler,
self.config.leader_board_config,
)?));
self.ui_elements.push(leaderboard);
write_log!("Leader Board successfully created");