use crate::hud::HudViewMode;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct NormRect {
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
}
impl NormRect {
pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self {
Self { x, y, w, h }
}
pub fn pixel_rect(self, width: f32, height: f32) -> (f32, f32, f32, f32) {
(
self.x * width,
self.y * height,
self.w * width,
self.h * height,
)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct HudLayout {
pub world: NormRect,
pub combat: Option<NormRect>,
pub status: Option<NormRect>,
pub sidebar: Option<NormRect>,
pub log: Option<NormRect>,
}
pub fn hud_layout(combat_visible: bool, mode: HudViewMode) -> HudLayout {
match (mode, combat_visible) {
(HudViewMode::Normal, true) => HudLayout {
world: NormRect::new(0.0, 0.0, 1.0, 0.52),
combat: Some(NormRect::new(0.0, 0.52, 1.0, 0.10)),
status: Some(NormRect::new(0.0, 0.62, 1.0, 0.04)),
sidebar: Some(NormRect::new(0.0, 0.66, 1.0, 0.27)),
log: Some(NormRect::new(0.0, 0.93, 1.0, 0.07)),
},
(HudViewMode::Normal, false) => HudLayout {
world: NormRect::new(0.0, 0.0, 1.0, 0.56),
combat: None,
status: Some(NormRect::new(0.0, 0.56, 1.0, 0.04)),
sidebar: Some(NormRect::new(0.0, 0.60, 1.0, 0.33)),
log: Some(NormRect::new(0.0, 0.93, 1.0, 0.07)),
},
(HudViewMode::Compact, true) => HudLayout {
world: NormRect::new(0.0, 0.0, 1.0, 0.70),
combat: Some(NormRect::new(0.0, 0.70, 1.0, 0.08)),
status: Some(NormRect::new(0.0, 0.78, 1.0, 0.04)),
sidebar: None,
log: Some(NormRect::new(0.0, 0.82, 1.0, 0.04)),
},
(HudViewMode::Compact, false) => HudLayout {
world: NormRect::new(0.0, 0.0, 1.0, 0.88),
combat: None,
status: Some(NormRect::new(0.0, 0.88, 1.0, 0.04)),
sidebar: None,
log: Some(NormRect::new(0.0, 0.92, 1.0, 0.04)),
},
(HudViewMode::Map, true) => HudLayout {
world: NormRect::new(0.0, 0.0, 1.0, 0.84),
combat: Some(NormRect::new(0.0, 0.84, 1.0, 0.10)),
status: Some(NormRect::new(0.0, 0.94, 1.0, 0.02)),
sidebar: None,
log: None,
},
(HudViewMode::Map, false) => HudLayout {
world: NormRect::new(0.0, 0.0, 1.0, 0.96),
combat: None,
status: Some(NormRect::new(0.0, 0.96, 1.0, 0.02)),
sidebar: None,
log: None,
},
}
}