Finish character window
This commit is contained in:
parent
cdb4bc2d69
commit
fc19aad393
7 changed files with 78 additions and 39 deletions
|
@ -4,6 +4,7 @@ use rpg_components::components::ability_slots::AbilitySlots;
|
|||
use rpg_components::components::crafting_materials::CraftingMaterials;
|
||||
use rpg_components::components::inventory::Storable;
|
||||
use rpg_components::components::statistics::Statistics;
|
||||
use rpg_components::config::items::ItemSettings;
|
||||
use rpg_components::items::Rarities;
|
||||
|
||||
use crate::*;
|
||||
|
@ -34,7 +35,11 @@ impl AbilityPageRightSide {
|
|||
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, "uncommon", color_settings.uncommon)?;
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
use std::sync::{Arc, Weak};
|
||||
|
||||
use anyhow::Result;
|
||||
use rpg_components::components::{
|
||||
attributes::{Agility, Attributes, Intelligence, Strength},
|
||||
item_slots::ItemSlotContainer,
|
||||
level::Level,
|
||||
statistics::Statistics,
|
||||
use rpg_components::{
|
||||
components::{
|
||||
attributes::{Agility, Attributes, Intelligence, Strength},
|
||||
item_slots::ItemSlotContainer,
|
||||
level::Level,
|
||||
statistics::Statistics,
|
||||
},
|
||||
config::attributes::AttributeSettings,
|
||||
};
|
||||
|
||||
use super::{CharacterWindow, Page};
|
||||
|
@ -156,7 +159,11 @@ impl CharacterPage {
|
|||
|
||||
attributes_label.set_text(format!(
|
||||
"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())?;
|
||||
|
@ -168,13 +175,13 @@ impl CharacterPage {
|
|||
}
|
||||
|
||||
fn available_attribute_points(
|
||||
engine: &Arc<Engine>,
|
||||
settings: &AttributeSettings,
|
||||
attributes: &Attributes,
|
||||
level: &Level,
|
||||
) -> u32 {
|
||||
let total_attribute_points = game.attribute_settings.meta_settings.starting_skill_points
|
||||
+ level.level() * game.attribute_settings.meta_settings.skill_points_per_level
|
||||
+ game.attribute_settings.starting_attributes.sum();
|
||||
let total_attribute_points = settings.meta_settings.starting_skill_points
|
||||
+ level.level() * settings.meta_settings.skill_points_per_level
|
||||
+ settings.starting_attributes.sum();
|
||||
|
||||
let attributes_spent = attributes.sum();
|
||||
|
||||
|
@ -196,19 +203,21 @@ impl CharacterPage {
|
|||
let mut upgraded = false;
|
||||
|
||||
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 attribute_settings = resources.get::<AttributeSettings>();
|
||||
|
||||
let level = multi_mut.get::<Level>()?;
|
||||
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);
|
||||
|
||||
let statistics = multi_mut.get::<Statistics>()?;
|
||||
let items = multi_mut.get::<ItemSlotContainer>()?;
|
||||
|
||||
statistics.update(attributes, &engine.attribute_settings, &*items);
|
||||
statistics.update(attributes, attribute_settings, &*items);
|
||||
|
||||
upgraded = true;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ use rpg_components::components::attributes::Attributes;
|
|||
use rpg_components::components::inventory::{Inventory, Storable};
|
||||
use rpg_components::components::item_slots::ItemSlotContainer;
|
||||
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 crate::*;
|
||||
|
@ -68,7 +70,7 @@ impl Content<Item> {
|
|||
|
||||
fn equip_item(engine: &Arc<Engine>, hero: Entity, item_index: usize) -> Result<()> {
|
||||
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();
|
||||
|
||||
|
@ -87,7 +89,11 @@ impl Content<Item> {
|
|||
// update hero stats
|
||||
let statistics = multi_mut.get::<Statistics>()?;
|
||||
|
||||
statistics.update(attributes, &engine.attribute_settings, &*hero_items);
|
||||
statistics.update(
|
||||
attributes,
|
||||
resources.get::<AttributeSettings>(),
|
||||
&*hero_items,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
@ -259,7 +265,7 @@ impl Content<Jewel> {
|
|||
let jewel = inventory.jewel_at(item_index);
|
||||
let gui = jewel.create_tooltip(
|
||||
engine.gui_handler(),
|
||||
&engine.upgrade().item_settings,
|
||||
scene.resources.get::<ItemSettings>(),
|
||||
(target_x, target_y),
|
||||
)?;
|
||||
gui.enable()?;
|
||||
|
|
|
@ -3,6 +3,7 @@ use rpg_components::{
|
|||
attributes::Attributes, character_status::CharacterStatus, inventory::Inventory,
|
||||
item_slots::ItemSlotContainer, statistics::Statistics,
|
||||
},
|
||||
config::attributes::AttributeSettings,
|
||||
items::{Item, ItemAffix, Tooltip},
|
||||
};
|
||||
|
||||
|
@ -236,7 +237,7 @@ mod macros {
|
|||
let mut found_item = false;
|
||||
|
||||
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 items = multi_mut.get::<ItemSlotContainer>()?;
|
||||
|
@ -255,7 +256,7 @@ mod macros {
|
|||
|
||||
statistics.update(
|
||||
attributes,
|
||||
&engine.upgrade().attribute_settings,
|
||||
resources.get::<AttributeSettings>(),
|
||||
&*items
|
||||
);
|
||||
|
||||
|
@ -388,7 +389,7 @@ mod macros {
|
|||
let mut found_item = false;
|
||||
|
||||
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 items = multi_mut.get::<ItemSlotContainer>()?;
|
||||
|
@ -407,7 +408,7 @@ mod macros {
|
|||
|
||||
statistics.update(
|
||||
attributes,
|
||||
&engine.upgrade().attribute_settings,
|
||||
resources.get::<AttributeSettings>(),
|
||||
&*items
|
||||
);
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ use rpg_components::{
|
|||
item_slots::ItemSlotContainer,
|
||||
statistics::Statistics,
|
||||
},
|
||||
items::{Item, ItemAffix, Jewel},
|
||||
config::{attributes::AttributeSettings, items::ItemSettings},
|
||||
items::{Item, ItemAffix, ItemSystem, Jewel},
|
||||
};
|
||||
|
||||
use crate::*;
|
||||
|
@ -107,7 +108,7 @@ impl JewelRightSide {
|
|||
)?,
|
||||
ReferenceObject::Jewel { jewel, .. } => jewel.create_tooltip(
|
||||
engine.gui_handler(),
|
||||
&engine.upgrade().item_settings,
|
||||
scene.resources.get::<ItemSettings>(),
|
||||
(x + w as i32, y),
|
||||
)?,
|
||||
};
|
||||
|
@ -148,7 +149,7 @@ impl JewelRightSide {
|
|||
if let Some((lower_jewel, _)) = &lower_info.jewels[index] {
|
||||
let tooltip = lower_jewel.create_tooltip(
|
||||
engine.gui_handler(),
|
||||
&engine.upgrade().item_settings,
|
||||
scene.resources.get::<ItemSettings>(),
|
||||
(x + w as i32, y),
|
||||
)?;
|
||||
|
||||
|
@ -220,7 +221,9 @@ impl JewelRightSide {
|
|||
|
||||
pub fn combine(engine: &Arc<Engine>, hero: Entity) -> Result<bool> {
|
||||
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>>();
|
||||
|
||||
|
@ -241,8 +244,7 @@ impl JewelRightSide {
|
|||
|
||||
match source {
|
||||
ReferenceItemSource::Inventory(index) => {
|
||||
let inventory =
|
||||
scene.entity_mut(hero)?.get_component_mut::<Inventory>()?;
|
||||
let inventory = entity.get_component_mut::<Inventory>()?;
|
||||
|
||||
let item = inventory.item_mut_at(*index);
|
||||
|
||||
|
@ -269,7 +271,8 @@ impl JewelRightSide {
|
|||
}
|
||||
}
|
||||
ReferenceItemSource::Slots(opt_index) => {
|
||||
let entity = scene.entity_mut(hero)?;
|
||||
let attribute_settings = resources.get::<AttributeSettings>();
|
||||
|
||||
let mut multi_mut = entity.multi_mut();
|
||||
|
||||
let inventory = multi_mut.get::<Inventory>()?;
|
||||
|
@ -303,7 +306,7 @@ impl JewelRightSide {
|
|||
let statistics = multi_mut.get::<Statistics>()?;
|
||||
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);
|
||||
}
|
||||
|
||||
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 upper_jewel = inventory.jewel_mut_at(*index);
|
||||
|
@ -329,8 +334,8 @@ impl JewelRightSide {
|
|||
}
|
||||
|
||||
upper_jewel.level += 1;
|
||||
upper_jewel.update_stat(&engine.item_settings);
|
||||
upper_jewel.icon = Some(game.item_system().jewel_icon(
|
||||
upper_jewel.update_stat(item_settings);
|
||||
upper_jewel.icon = Some(item_system.jewel_icon(
|
||||
upper_jewel.rarity,
|
||||
upper_jewel.level,
|
||||
upper_jewel.attribute,
|
||||
|
|
|
@ -123,7 +123,7 @@ impl<'a> TabsMut<'a> {
|
|||
}
|
||||
|
||||
pub struct CharacterWindow {
|
||||
hud: Box<dyn FutureStateChange>,
|
||||
close: Box<dyn FutureStateChange>,
|
||||
|
||||
menu_gui: Arc<GuiBuilder>,
|
||||
tab_content_grid: Arc<Grid>,
|
||||
|
@ -137,7 +137,12 @@ pub struct 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 =
|
||||
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 close_button: Arc<Button> = menu_gui.element("close")?;
|
||||
|
||||
let hud = ingame.ui().future_state_change("hud")?;
|
||||
|
||||
let character_window = Arc::new_cyclic(|me| CharacterWindow {
|
||||
hud: Box::new(hud),
|
||||
close: Box::new(close),
|
||||
|
||||
menu_gui,
|
||||
tab_content_grid: content_grid,
|
||||
|
@ -329,7 +332,7 @@ impl GuiElementTraits for CharacterWindow {
|
|||
|
||||
impl TopGui for CharacterWindow {
|
||||
fn decline(&self) -> Result<()> {
|
||||
(self.hud)()
|
||||
(self.close)()
|
||||
}
|
||||
|
||||
fn next_tab(&self, second_level: bool) -> Result<()> {
|
||||
|
@ -387,7 +390,7 @@ impl CharacterWindow {
|
|||
// let open_abilities = self.switch_tab(ABILITY_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(
|
||||
ClickCallbacks::default()
|
||||
|
|
|
@ -227,6 +227,16 @@ impl Scene {
|
|||
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue