Load placeholder from settings

This commit is contained in:
hodasemi 2024-08-26 16:18:41 +02:00
parent 9c497a1fdb
commit 69c2353730
2 changed files with 42 additions and 42 deletions

View file

@ -30,7 +30,7 @@ impl ItemRightSide {
hero: Entity, hero: Entity,
) -> Result<Self> { ) -> Result<Self> {
let snippet = GuiSnippet::from_str(engine.gui_handler(), file)?; let snippet = GuiSnippet::from_str(engine.gui_handler(), file)?;
let icons = InventoryEmptyIcons::new(&snippet)?; let icons = InventoryEmptyIcons::new(engine)?;
let me = Self { let me = Self {
snippet, snippet,
@ -151,31 +151,34 @@ struct InventoryEmptyIcons {
} }
impl InventoryEmptyIcons { impl InventoryEmptyIcons {
fn new(ui: &GuiSnippet) -> Result<Self> { fn new(engine: &Engine) -> Result<Self> {
get_place_holder!(ui, helmet); let place_holder_settings = &engine
get_place_holder!(ui, chest); .scene()
get_place_holder!(ui, boots); .resources
get_place_holder!(ui, belt); .get::<ItemSettings>()
get_place_holder!(ui, gloves); .icon_place_holder_paths;
get_place_holder!(ui, primary_hand, "main hand");
get_place_holder!(ui, secondary_hand, "off hand");
get_place_holder!(ui, ring, "ring_0");
get_place_holder!(ui, amulet, "amulet_0");
Ok(Self { Ok(Self {
helmet, helmet: Image::from_file(place_holder_settings.helmet.clone())?
chest, .build(engine.device(), engine.queue())?,
belt, chest: Image::from_file(place_holder_settings.chest.clone())?
boots, .build(engine.device(), engine.queue())?,
gloves, belt: Image::from_file(place_holder_settings.belt.clone())?
.build(engine.device(), engine.queue())?,
boots: Image::from_file(place_holder_settings.boots.clone())?
.build(engine.device(), engine.queue())?,
gloves: Image::from_file(place_holder_settings.gloves.clone())?
.build(engine.device(), engine.queue())?,
primary_hand, primary_hand: Image::from_file(place_holder_settings.main_hand.clone())?
secondary_hand, .build(engine.device(), engine.queue())?,
secondary_hand: Image::from_file(place_holder_settings.off_hand.clone())?
.build(engine.device(), engine.queue())?,
ring, ring: Image::from_file(place_holder_settings.ring.clone())?
amulet, .build(engine.device(), engine.queue())?,
amulet: Image::from_file(place_holder_settings.amulet.clone())?
.build(engine.device(), engine.queue())?,
}) })
} }
} }
@ -516,24 +519,4 @@ mod macros {
} }
}}; }};
} }
#[macro_export]
macro_rules! get_place_holder {
($gui:ident, $name:ident) => {
let $name = {
let button: Arc<Button> = $gui.element(stringify!($name))?;
button
.icon()?
.expect(&format!("missing {} placeholder", stringify!($name)))
};
};
($gui:ident, $name:ident, $id:literal) => {
let $name = {
let button: Arc<Button> = $gui.element($id)?;
button
.icon()?
.expect(&format!("missing {} placeholder", $id))
};
};
}
} }

View file

@ -133,6 +133,22 @@ create_settings_section!(
} }
); );
create_settings_section!(
ItemPlaceHolderIconPaths,
"ItemPlaceHolderIcons",
{
amulet: AssetPath,
boots: AssetPath,
chest: AssetPath,
helmet: AssetPath,
ring: AssetPath,
belt: AssetPath,
gloves: AssetPath,
main_hand: AssetPath,
off_hand: AssetPath,
}
);
create_settings_section!( create_settings_section!(
JewelIconPaths, JewelIconPaths,
"JewelIcons", "JewelIcons",
@ -164,6 +180,7 @@ create_settings_container!(
{ {
general: GeneralItemSettings, general: GeneralItemSettings,
icon_paths: ItemIconPaths, icon_paths: ItemIconPaths,
icon_place_holder_paths: ItemPlaceHolderIconPaths,
jewel_paths: JewelIconPaths, jewel_paths: JewelIconPaths,
jewel_rarity_multiplier: JewelRarityMultiplier, jewel_rarity_multiplier: JewelRarityMultiplier,
rarity_color_settings: RarityColorSettings, rarity_color_settings: RarityColorSettings,