From cb02e978e27816773173ee761b2ad59d4753383b Mon Sep 17 00:00:00 2001 From: Orchaldir Date: Sat, 23 Sep 2023 19:24:17 +0200 Subject: [PATCH] [#42] Boots over pants --- .../rendering/config/equipment/footwear.rs | 22 +++++++++++++++++++ .../src/rendering/config/equipment/pants.rs | 2 +- .../src/rendering/equipment/footwear.rs | 2 +- .../src/rendering/equipment/mod.rs | 7 ++++-- .../src/rendering/equipment/pants.rs | 15 ++++++++++--- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/rpg_tools_rendering/src/rendering/config/equipment/footwear.rs b/rpg_tools_rendering/src/rendering/config/equipment/footwear.rs index 686309b7..d3459c84 100644 --- a/rpg_tools_rendering/src/rendering/config/equipment/footwear.rs +++ b/rpg_tools_rendering/src/rendering/config/equipment/footwear.rs @@ -1,3 +1,7 @@ +use crate::rendering::config::body::BodyConfig; +use rpg_tools_core::model::character::appearance::body::Body; +use rpg_tools_core::model::equipment::appearance::footwear::FootwearStyle; + /// The rendering config of the [`footwear`](rpg_tools_core::model::equipment::appearance::footwear::Footwear). #[derive(Debug, PartialEq)] pub struct FootwearConfig { @@ -7,3 +11,21 @@ pub struct FootwearConfig { pub width_shaft: f32, pub width_sole: f32, } + +impl FootwearConfig { + pub fn get_shaft_y( + &self, + config: &BodyConfig, + body: &Body, + style: FootwearStyle, + ) -> Option { + match style { + FootwearStyle::KneeHighBoots => Some(self.to_y(config, body, self.height_knee)), + _ => None, + } + } + + pub fn to_y(&self, config: &BodyConfig, body: &Body, height: f32) -> f32 { + config.y_foot - height - config.get_foot_radius_factor(body) + } +} diff --git a/rpg_tools_rendering/src/rendering/config/equipment/pants.rs b/rpg_tools_rendering/src/rendering/config/equipment/pants.rs index c53b0b49..81660174 100644 --- a/rpg_tools_rendering/src/rendering/config/equipment/pants.rs +++ b/rpg_tools_rendering/src/rendering/config/equipment/pants.rs @@ -30,6 +30,6 @@ impl PantsConfig { } pub fn get_bottom_y(&self, config: &BodyConfig, body: &Body) -> f32 { - 1.0 - config.get_foot_radius_factor(body) - self.offset_bottom + config.y_foot - config.get_foot_radius_factor(body) - self.offset_bottom } } diff --git a/rpg_tools_rendering/src/rendering/equipment/footwear.rs b/rpg_tools_rendering/src/rendering/equipment/footwear.rs index 01d83280..36dab311 100644 --- a/rpg_tools_rendering/src/rendering/equipment/footwear.rs +++ b/rpg_tools_rendering/src/rendering/equipment/footwear.rs @@ -76,7 +76,7 @@ fn render_shaft( ) { let width = config.body.get_leg_width(body) * config.footwear.width_shaft; let y_end = config.body.y_foot; - let y_start = y_end - height - config.body.get_foot_radius_factor(body); + let y_start = config.footwear.to_y(&config.body, body, height); let mut builder = Polygon2dBuilder::new(); builder.add_horizontal_pair(aabb, width, center_x, y_start, true); diff --git a/rpg_tools_rendering/src/rendering/equipment/mod.rs b/rpg_tools_rendering/src/rendering/equipment/mod.rs index 4fbeaba4..17675100 100644 --- a/rpg_tools_rendering/src/rendering/equipment/mod.rs +++ b/rpg_tools_rendering/src/rendering/equipment/mod.rs @@ -27,11 +27,14 @@ pub fn render_clothing( render_shirt(renderer, config, aabb, body, shirt, from_front); if footwear.style.is_over_pants() { - render_pants(renderer, config, aabb, body, pants); + let shaft_y = config + .footwear + .get_shaft_y(&config.body, body, footwear.style); + render_pants(renderer, config, aabb, body, pants, shaft_y); render_footwear(renderer, config, aabb, body, footwear, from_front); } else { render_footwear(renderer, config, aabb, body, footwear, from_front); - render_pants(renderer, config, aabb, body, pants); + render_pants(renderer, config, aabb, body, pants, None); } } } diff --git a/rpg_tools_rendering/src/rendering/equipment/pants.rs b/rpg_tools_rendering/src/rendering/equipment/pants.rs index 9fd0485a..af88f9e5 100644 --- a/rpg_tools_rendering/src/rendering/equipment/pants.rs +++ b/rpg_tools_rendering/src/rendering/equipment/pants.rs @@ -12,13 +12,14 @@ pub fn render_pants( aabb: &AABB, body: &Body, pants: &Pants, + shaft_y: Option, ) { let options = config.get_options(pants.color); let polygon = match pants.style { PantsStyle::Balloon => get_balloon(config, aabb, body), PantsStyle::Bermuda => get_bermuda(config, aabb, body), PantsStyle::HotPants => get_hot_pants(config, aabb, body), - PantsStyle::Regular => get_regular_pants(config, aabb, body), + PantsStyle::Regular => get_regular_pants(config, aabb, body, shaft_y), PantsStyle::Shorts => get_shorts(config, aabb, body), }; @@ -38,8 +39,16 @@ fn get_hot_pants(config: &RenderConfig, aabb: &AABB, body: &Body) -> Polygon2d { get_base(config, aabb, body).build() } -fn get_regular_pants(config: &RenderConfig, aabb: &AABB, body: &Body) -> Polygon2d { - let bottom_y = config.pants.get_bottom_y(&config.body, body); +fn get_regular_pants( + config: &RenderConfig, + aabb: &AABB, + body: &Body, + shaft_y: Option, +) -> Polygon2d { + let bottom_y = config + .pants + .get_bottom_y(&config.body, body) + .min(shaft_y.unwrap_or(1.0)); get_pants(config, aabb, body, bottom_y, false) }