Finish character window

This commit is contained in:
hodasemi 2024-08-26 11:22:59 +02:00
parent cdb4bc2d69
commit fc19aad393
7 changed files with 78 additions and 39 deletions

View file

@ -4,6 +4,7 @@ use rpg_components::components::ability_slots::AbilitySlots;
use rpg_components::components::crafting_materials::CraftingMaterials; use rpg_components::components::crafting_materials::CraftingMaterials;
use rpg_components::components::inventory::Storable; use rpg_components::components::inventory::Storable;
use rpg_components::components::statistics::Statistics; use rpg_components::components::statistics::Statistics;
use rpg_components::config::items::ItemSettings;
use rpg_components::items::Rarities; use rpg_components::items::Rarities;
use crate::*; use crate::*;
@ -34,7 +35,11 @@ impl AbilityPageRightSide {
include_str!("../../resources/abilities/right_side.xml"), include_str!("../../resources/abilities/right_side.xml"),
)?; )?;
let color_settings = &engine.item_settings.rarity_color_settings; let color_settings = &engine
.scene()
.resources
.get::<ItemSettings>()
.rarity_color_settings;
Self::rarity_icon_background(&snippet, "common", color_settings.common)?; Self::rarity_icon_background(&snippet, "common", color_settings.common)?;
Self::rarity_icon_background(&snippet, "uncommon", color_settings.uncommon)?; Self::rarity_icon_background(&snippet, "uncommon", color_settings.uncommon)?;

View file

@ -1,11 +1,14 @@
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use anyhow::Result; use anyhow::Result;
use rpg_components::components::{ use rpg_components::{
components::{
attributes::{Agility, Attributes, Intelligence, Strength}, attributes::{Agility, Attributes, Intelligence, Strength},
item_slots::ItemSlotContainer, item_slots::ItemSlotContainer,
level::Level, level::Level,
statistics::Statistics, statistics::Statistics,
},
config::attributes::AttributeSettings,
}; };
use super::{CharacterWindow, Page}; use super::{CharacterWindow, Page};
@ -156,7 +159,11 @@ impl CharacterPage {
attributes_label.set_text(format!( attributes_label.set_text(format!(
"Attributes ({})", "Attributes ({})",
Self::available_attribute_points(&self.engine, attributes, level) Self::available_attribute_points(
&scene.resources.get::<AttributeSettings>(),
attributes,
level
)
))?; ))?;
strength.set_text(attributes.strength().raw())?; strength.set_text(attributes.strength().raw())?;
@ -168,13 +175,13 @@ impl CharacterPage {
} }
fn available_attribute_points( fn available_attribute_points(
engine: &Arc<Engine>, settings: &AttributeSettings,
attributes: &Attributes, attributes: &Attributes,
level: &Level, level: &Level,
) -> u32 { ) -> u32 {
let total_attribute_points = game.attribute_settings.meta_settings.starting_skill_points let total_attribute_points = settings.meta_settings.starting_skill_points
+ level.level() * game.attribute_settings.meta_settings.skill_points_per_level + level.level() * settings.meta_settings.skill_points_per_level
+ game.attribute_settings.starting_attributes.sum(); + settings.starting_attributes.sum();
let attributes_spent = attributes.sum(); let attributes_spent = attributes.sum();
@ -196,19 +203,21 @@ impl CharacterPage {
let mut upgraded = false; let mut upgraded = false;
engine.on_scene_mut(|scene| { engine.on_scene_mut(|scene| {
let entity = scene.entity_mut(hero)?; let (resources, entity) = scene.entity_resource(hero)?;
let mut multi_mut = entity.multi_mut(); let mut multi_mut = entity.multi_mut();
let attribute_settings = resources.get::<AttributeSettings>();
let level = multi_mut.get::<Level>()?; let level = multi_mut.get::<Level>()?;
let attributes = multi_mut.get::<Attributes>()?; let attributes = multi_mut.get::<Attributes>()?;
if Self::available_attribute_points(&engine, attributes, level) > 0 { if Self::available_attribute_points(attribute_settings, attributes, level) > 0 {
upgrade(attributes); upgrade(attributes);
let statistics = multi_mut.get::<Statistics>()?; let statistics = multi_mut.get::<Statistics>()?;
let items = multi_mut.get::<ItemSlotContainer>()?; let items = multi_mut.get::<ItemSlotContainer>()?;
statistics.update(attributes, &engine.attribute_settings, &*items); statistics.update(attributes, attribute_settings, &*items);
upgraded = true; upgraded = true;
} }

View file

@ -4,6 +4,8 @@ use rpg_components::components::attributes::Attributes;
use rpg_components::components::inventory::{Inventory, Storable}; use rpg_components::components::inventory::{Inventory, Storable};
use rpg_components::components::item_slots::ItemSlotContainer; use rpg_components::components::item_slots::ItemSlotContainer;
use rpg_components::components::statistics::Statistics; use rpg_components::components::statistics::Statistics;
use rpg_components::config::attributes::AttributeSettings;
use rpg_components::config::items::ItemSettings;
use rpg_components::items::{Item, ItemAffix, Jewel, MapItem}; use rpg_components::items::{Item, ItemAffix, Jewel, MapItem};
use crate::*; use crate::*;
@ -68,7 +70,7 @@ impl Content<Item> {
fn equip_item(engine: &Arc<Engine>, hero: Entity, item_index: usize) -> Result<()> { fn equip_item(engine: &Arc<Engine>, hero: Entity, item_index: usize) -> Result<()> {
engine.on_scene_mut(|scene| { engine.on_scene_mut(|scene| {
let entity = scene.entity_mut(hero)?; let (resources, entity) = scene.entity_resource(hero)?;
let mut multi_mut = entity.multi_mut(); let mut multi_mut = entity.multi_mut();
@ -87,7 +89,11 @@ impl Content<Item> {
// update hero stats // update hero stats
let statistics = multi_mut.get::<Statistics>()?; let statistics = multi_mut.get::<Statistics>()?;
statistics.update(attributes, &engine.attribute_settings, &*hero_items); statistics.update(
attributes,
resources.get::<AttributeSettings>(),
&*hero_items,
);
Ok(()) Ok(())
}) })
@ -259,7 +265,7 @@ impl Content<Jewel> {
let jewel = inventory.jewel_at(item_index); let jewel = inventory.jewel_at(item_index);
let gui = jewel.create_tooltip( let gui = jewel.create_tooltip(
engine.gui_handler(), engine.gui_handler(),
&engine.upgrade().item_settings, scene.resources.get::<ItemSettings>(),
(target_x, target_y), (target_x, target_y),
)?; )?;
gui.enable()?; gui.enable()?;

View file

@ -3,6 +3,7 @@ use rpg_components::{
attributes::Attributes, character_status::CharacterStatus, inventory::Inventory, attributes::Attributes, character_status::CharacterStatus, inventory::Inventory,
item_slots::ItemSlotContainer, statistics::Statistics, item_slots::ItemSlotContainer, statistics::Statistics,
}, },
config::attributes::AttributeSettings,
items::{Item, ItemAffix, Tooltip}, items::{Item, ItemAffix, Tooltip},
}; };
@ -236,7 +237,7 @@ mod macros {
let mut found_item = false; let mut found_item = false;
engine.on_scene_mut(|scene| { engine.on_scene_mut(|scene| {
let entity = scene.entity_mut($hero)?; let (resources, entity) = scene.entity_resource($hero)?;
let mut multi_mut = entity.multi_mut(); let mut multi_mut = entity.multi_mut();
let items = multi_mut.get::<ItemSlotContainer>()?; let items = multi_mut.get::<ItemSlotContainer>()?;
@ -255,7 +256,7 @@ mod macros {
statistics.update( statistics.update(
attributes, attributes,
&engine.upgrade().attribute_settings, resources.get::<AttributeSettings>(),
&*items &*items
); );
@ -388,7 +389,7 @@ mod macros {
let mut found_item = false; let mut found_item = false;
engine.on_scene_mut(|scene| { engine.on_scene_mut(|scene| {
let entity = scene.entity_mut($hero)?; let (resources, entity) = scene.entity_resource($hero)?;
let mut multi_mut = entity.multi_mut(); let mut multi_mut = entity.multi_mut();
let items = multi_mut.get::<ItemSlotContainer>()?; let items = multi_mut.get::<ItemSlotContainer>()?;
@ -407,7 +408,7 @@ mod macros {
statistics.update( statistics.update(
attributes, attributes,
&engine.upgrade().attribute_settings, resources.get::<AttributeSettings>(),
&*items &*items
); );

View file

@ -5,7 +5,8 @@ use rpg_components::{
item_slots::ItemSlotContainer, item_slots::ItemSlotContainer,
statistics::Statistics, statistics::Statistics,
}, },
items::{Item, ItemAffix, Jewel}, config::{attributes::AttributeSettings, items::ItemSettings},
items::{Item, ItemAffix, ItemSystem, Jewel},
}; };
use crate::*; use crate::*;
@ -107,7 +108,7 @@ impl JewelRightSide {
)?, )?,
ReferenceObject::Jewel { jewel, .. } => jewel.create_tooltip( ReferenceObject::Jewel { jewel, .. } => jewel.create_tooltip(
engine.gui_handler(), engine.gui_handler(),
&engine.upgrade().item_settings, scene.resources.get::<ItemSettings>(),
(x + w as i32, y), (x + w as i32, y),
)?, )?,
}; };
@ -148,7 +149,7 @@ impl JewelRightSide {
if let Some((lower_jewel, _)) = &lower_info.jewels[index] { if let Some((lower_jewel, _)) = &lower_info.jewels[index] {
let tooltip = lower_jewel.create_tooltip( let tooltip = lower_jewel.create_tooltip(
engine.gui_handler(), engine.gui_handler(),
&engine.upgrade().item_settings, scene.resources.get::<ItemSettings>(),
(x + w as i32, y), (x + w as i32, y),
)?; )?;
@ -220,7 +221,9 @@ impl JewelRightSide {
pub fn combine(engine: &Arc<Engine>, hero: Entity) -> Result<bool> { pub fn combine(engine: &Arc<Engine>, hero: Entity) -> Result<bool> {
let scene = engine.scene_mut(); let scene = engine.scene_mut();
let mut resources = unsafe { remove_life_time_mut(scene) }.resources.multi_mut();
let (resources, entity) = scene.entity_resource(hero)?;
let mut resources = resources.multi_mut();
let reference_info = resources.get::<Option<ReferenceObject>>(); let reference_info = resources.get::<Option<ReferenceObject>>();
@ -241,8 +244,7 @@ impl JewelRightSide {
match source { match source {
ReferenceItemSource::Inventory(index) => { ReferenceItemSource::Inventory(index) => {
let inventory = let inventory = entity.get_component_mut::<Inventory>()?;
scene.entity_mut(hero)?.get_component_mut::<Inventory>()?;
let item = inventory.item_mut_at(*index); let item = inventory.item_mut_at(*index);
@ -269,7 +271,8 @@ impl JewelRightSide {
} }
} }
ReferenceItemSource::Slots(opt_index) => { ReferenceItemSource::Slots(opt_index) => {
let entity = scene.entity_mut(hero)?; let attribute_settings = resources.get::<AttributeSettings>();
let mut multi_mut = entity.multi_mut(); let mut multi_mut = entity.multi_mut();
let inventory = multi_mut.get::<Inventory>()?; let inventory = multi_mut.get::<Inventory>()?;
@ -303,7 +306,7 @@ impl JewelRightSide {
let statistics = multi_mut.get::<Statistics>()?; let statistics = multi_mut.get::<Statistics>()?;
let attributes = multi_mut.get::<Attributes>()?; let attributes = multi_mut.get::<Attributes>()?;
statistics.update(attributes, &engine.attribute_settings, &*item_slots); statistics.update(attributes, attribute_settings, &*item_slots);
} }
} }
} }
@ -319,7 +322,9 @@ impl JewelRightSide {
return Ok(false); return Ok(false);
} }
let entity = scene.entity_mut(hero)?; let item_settings = resources.get::<ItemSettings>();
let item_system = resources.get::<Arc<ItemSystem>>();
let inventory = entity.get_component_mut::<Inventory>()?; let inventory = entity.get_component_mut::<Inventory>()?;
let upper_jewel = inventory.jewel_mut_at(*index); let upper_jewel = inventory.jewel_mut_at(*index);
@ -329,8 +334,8 @@ impl JewelRightSide {
} }
upper_jewel.level += 1; upper_jewel.level += 1;
upper_jewel.update_stat(&engine.item_settings); upper_jewel.update_stat(item_settings);
upper_jewel.icon = Some(game.item_system().jewel_icon( upper_jewel.icon = Some(item_system.jewel_icon(
upper_jewel.rarity, upper_jewel.rarity,
upper_jewel.level, upper_jewel.level,
upper_jewel.attribute, upper_jewel.attribute,

View file

@ -123,7 +123,7 @@ impl<'a> TabsMut<'a> {
} }
pub struct CharacterWindow { pub struct CharacterWindow {
hud: Box<dyn FutureStateChange>, close: Box<dyn FutureStateChange>,
menu_gui: Arc<GuiBuilder>, menu_gui: Arc<GuiBuilder>,
tab_content_grid: Arc<Grid>, tab_content_grid: Arc<Grid>,
@ -137,7 +137,12 @@ pub struct CharacterWindow {
} }
impl CharacterWindow { impl CharacterWindow {
pub fn new(engine: Arc<Engine>, hero: Entity, name: &str) -> Result<Arc<Self>> { pub fn new(
engine: Arc<Engine>,
hero: Entity,
name: &str,
close: &'static dyn FutureStateChange,
) -> Result<Arc<Self>> {
let menu_gui = let menu_gui =
GuiBuilder::from_str(engine.gui_handler(), include_str!("../resources/menu.xml"))?; GuiBuilder::from_str(engine.gui_handler(), include_str!("../resources/menu.xml"))?;
@ -147,10 +152,8 @@ impl CharacterWindow {
let open_ability_page: Arc<Button> = menu_gui.element("open_abilities")?; let open_ability_page: Arc<Button> = menu_gui.element("open_abilities")?;
let close_button: Arc<Button> = menu_gui.element("close")?; let close_button: Arc<Button> = menu_gui.element("close")?;
let hud = ingame.ui().future_state_change("hud")?;
let character_window = Arc::new_cyclic(|me| CharacterWindow { let character_window = Arc::new_cyclic(|me| CharacterWindow {
hud: Box::new(hud), close: Box::new(close),
menu_gui, menu_gui,
tab_content_grid: content_grid, tab_content_grid: content_grid,
@ -329,7 +332,7 @@ impl GuiElementTraits for CharacterWindow {
impl TopGui for CharacterWindow { impl TopGui for CharacterWindow {
fn decline(&self) -> Result<()> { fn decline(&self) -> Result<()> {
(self.hud)() (self.close)()
} }
fn next_tab(&self, second_level: bool) -> Result<()> { fn next_tab(&self, second_level: bool) -> Result<()> {
@ -387,7 +390,7 @@ impl CharacterWindow {
// let open_abilities = self.switch_tab(ABILITY_TAB); // let open_abilities = self.switch_tab(ABILITY_TAB);
// let open_inventory = self.switch_tab(INVENTORY_TAB); // let open_inventory = self.switch_tab(INVENTORY_TAB);
let close = self.hud.clone(); let close = self.close.clone();
self.menu_gui.set_click_callbacks( self.menu_gui.set_click_callbacks(
ClickCallbacks::default() ClickCallbacks::default()

View file

@ -227,6 +227,16 @@ impl Scene {
Ok(()) Ok(())
} }
pub fn entity_resource(
&mut self,
entity: Entity,
) -> Result<(&mut Resources, &mut EntityObject)> {
Ok((
unsafe { remove_life_time_mut(&mut self.resources) },
self.entity_mut(entity)?,
))
}
} }
impl Scene { impl Scene {