Further steps towards new ecs
This commit is contained in:
parent
1367be0c0e
commit
324af987a3
6 changed files with 113 additions and 70 deletions
|
@ -30,20 +30,21 @@ impl CharacterPage {
|
|||
reference: &Weak<CharacterWindow>,
|
||||
) -> Result<Self> {
|
||||
let snippet = GuiSnippet::from_str(
|
||||
world,
|
||||
commands,
|
||||
gui_handler,
|
||||
include_str!("../../resources/character/statistics.xml"),
|
||||
)?;
|
||||
|
||||
let grid: Arc<Grid> = snippet.element("statistic_tab")?;
|
||||
let name: Arc<Label> = snippet.element("character_name")?;
|
||||
|
||||
name.set_text(world.resources.get_mut()?, hero_name)?;
|
||||
name.set_text(gui_handler, hero_name)?;
|
||||
|
||||
let strength: Arc<Button> = snippet.element("strength_field")?;
|
||||
strength.set_callback({
|
||||
let update_stats = Self::create_update_stats(hero, reference.clone());
|
||||
|
||||
move |world| {
|
||||
move |commands, gui_handler| {
|
||||
update_stats(world, |attributes: &mut Attributes| {
|
||||
attributes.add_strength(Strength::from(1));
|
||||
})
|
||||
|
|
|
@ -27,13 +27,16 @@ pub struct ItemRightSide {
|
|||
|
||||
impl ItemRightSide {
|
||||
pub fn new<A: Ability + 'static>(
|
||||
world: &mut World,
|
||||
commands: &mut Commands,
|
||||
gui_handler: &mut GuiHandler,
|
||||
item_settings: &ItemSettings,
|
||||
context: &Context,
|
||||
file: &str,
|
||||
reference: &Weak<CharacterWindow>,
|
||||
hero: Entity,
|
||||
) -> Result<Self> {
|
||||
let snippet = GuiSnippet::from_str(world, file)?;
|
||||
let icons = InventoryEmptyIcons::new(world)?;
|
||||
let snippet = GuiSnippet::from_str(commands, gui_handler, file)?;
|
||||
let icons = InventoryEmptyIcons::new(context, item_settings)?;
|
||||
|
||||
let me = Self {
|
||||
snippet,
|
||||
|
@ -121,7 +124,12 @@ impl ItemRightSide {
|
|||
}
|
||||
|
||||
impl RightSide for ItemRightSide {
|
||||
fn refresh(&mut self, world: &mut World, hero: Entity) -> Result<()> {
|
||||
fn refresh(
|
||||
&mut self,
|
||||
commands: &mut Commands,
|
||||
gui_handler: &mut GuiHandler,
|
||||
hero: Entity,
|
||||
) -> Result<()> {
|
||||
let (hero_object, resources) = world.entity_resources(hero)?;
|
||||
let items = hero_object.get_component::<ItemSlotContainer>()?;
|
||||
|
||||
|
@ -148,13 +156,8 @@ struct InventoryEmptyIcons {
|
|||
}
|
||||
|
||||
impl InventoryEmptyIcons {
|
||||
fn new(world: &World) -> Result<Self> {
|
||||
let place_holder_settings = &world
|
||||
.resources
|
||||
.get::<ItemSettings>()
|
||||
.icon_place_holder_paths;
|
||||
|
||||
let context = world.resources.get::<Context>();
|
||||
fn new(context: &Context, item_settings: &ItemSettings) -> Result<Self> {
|
||||
let place_holder_settings = &item_settings.icon_place_holder_paths;
|
||||
|
||||
Ok(Self {
|
||||
helmet: Self::image(context, &place_holder_settings.helmet)?,
|
||||
|
|
|
@ -59,19 +59,19 @@ pub struct JewelRightSide {
|
|||
|
||||
impl JewelRightSide {
|
||||
pub fn new<A: Ability + 'static>(
|
||||
world: &mut World,
|
||||
commands: &mut Commands,
|
||||
gui_handler: &mut GuiHandler,
|
||||
engine_settings: &EngineSettings,
|
||||
context: &Context,
|
||||
file: &str,
|
||||
hero: Entity,
|
||||
reference: &Weak<CharacterWindow>,
|
||||
) -> Result<Self> {
|
||||
let snippet = GuiSnippet::from_str(world, file)?;
|
||||
let snippet = GuiSnippet::from_str(commands, gui_handler, file)?;
|
||||
|
||||
let combine: Arc<Label> = snippet.element("combine")?;
|
||||
let icon = world.resources.get::<EngineSettings>().controller_icon(
|
||||
world.resources.get::<Context>(),
|
||||
ControllerButton::RightStick,
|
||||
)?;
|
||||
combine.set_info_icon(world.resources.get_mut()?, &icon)?;
|
||||
let icon = engine_settings.controller_icon(context, ControllerButton::RightStick)?;
|
||||
combine.set_info_icon(gui_handler, &icon)?;
|
||||
|
||||
world.resources.insert_if_not_exists::<ReferenceObject>();
|
||||
world.resources.insert_if_not_exists::<LowerJewels>();
|
||||
|
@ -93,7 +93,7 @@ impl JewelRightSide {
|
|||
let weak_top = Arc::downgrade(&top);
|
||||
let reference = reference.clone();
|
||||
|
||||
move |world, selected| {
|
||||
move |commands, gui_handler, selected| {
|
||||
let menu = reference.upgrade().unwrap();
|
||||
|
||||
if selected {
|
||||
|
@ -108,27 +108,37 @@ impl JewelRightSide {
|
|||
if let Some(reference_info) = reference_info.some() {
|
||||
let tooltip = match reference_info {
|
||||
ReferenceObject::Item { item, .. } => {
|
||||
let attributes = unsafe { remove_life_time(world.entity(hero)?) }
|
||||
.get_component::<Attributes>()?;
|
||||
let attributes =
|
||||
world.entity(hero)?.get_component::<Attributes>()?;
|
||||
|
||||
item.create_tooltip(world, attributes, (x + w as i32, y))?
|
||||
item.create_tooltip(
|
||||
commands,
|
||||
gui_handler,
|
||||
attributes,
|
||||
(x + w as i32, y),
|
||||
)?
|
||||
}
|
||||
ReferenceObject::Jewel { jewel, .. } => {
|
||||
let item_settings = world.resources.get_unchecked::<ItemSettings>();
|
||||
|
||||
jewel.create_tooltip(world, item_settings, (x + w as i32, y))?
|
||||
jewel.create_tooltip(
|
||||
commands,
|
||||
gui_handler,
|
||||
item_settings,
|
||||
(x + w as i32, y),
|
||||
)?
|
||||
}
|
||||
|
||||
ReferenceObject::Empty => unreachable!(),
|
||||
};
|
||||
|
||||
tooltip.enable(world)?;
|
||||
tooltip.perform_single_check(world.resources.get_mut()?, x, y)?;
|
||||
tooltip.enable(commands, gui_handler)?;
|
||||
tooltip.perform_single_check(gui_handler, x, y)?;
|
||||
|
||||
menu.add_tooltip("upper", tooltip);
|
||||
}
|
||||
} else {
|
||||
menu.remove_tooltip(world, "upper")?;
|
||||
menu.remove_tooltip(commands, gui_handler, "upper")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -140,7 +150,7 @@ impl JewelRightSide {
|
|||
let weak_top = Arc::downgrade(&lower);
|
||||
let reference = reference.clone();
|
||||
|
||||
move |world, selected| {
|
||||
move |commands, gui_handler, selected| {
|
||||
let menu = reference.upgrade().unwrap();
|
||||
|
||||
if selected {
|
||||
|
@ -167,7 +177,7 @@ impl JewelRightSide {
|
|||
menu.add_tooltip(format!("lower_{index}",), tooltip);
|
||||
}
|
||||
} else {
|
||||
menu.remove_tooltip(world, format!("lower_{index}"))?;
|
||||
menu.remove_tooltip(commands, gui_handler, format!("lower_{index}"))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -177,7 +187,7 @@ impl JewelRightSide {
|
|||
lower.set_callback({
|
||||
let reference = reference.clone();
|
||||
|
||||
move |world| {
|
||||
move |commands, gui_handler| {
|
||||
let lower_info: &mut LowerJewels = world.resources.get_mut()?;
|
||||
|
||||
if lower_info.jewels[index].is_some() {
|
||||
|
@ -187,7 +197,7 @@ impl JewelRightSide {
|
|||
let mut tabs = menu.tabs_mut();
|
||||
let inventory = tabs.inventory::<A>();
|
||||
|
||||
inventory.update_page(world, true)?;
|
||||
inventory.update_page(commands, gui_handler, true)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,15 +9,20 @@ pub struct MapRightSide {
|
|||
}
|
||||
|
||||
impl MapRightSide {
|
||||
pub fn new(world: &mut World, file: &str) -> Result<Self> {
|
||||
let snippet = GuiSnippet::from_str(world, file)?;
|
||||
pub fn new(commands: &mut Commands, gui_handler: &mut GuiHandler, file: &str) -> Result<Self> {
|
||||
let snippet = GuiSnippet::from_str(commands, gui_handler, file)?;
|
||||
|
||||
Ok(Self { snippet })
|
||||
}
|
||||
}
|
||||
|
||||
impl RightSide for MapRightSide {
|
||||
fn refresh(&mut self, _world: &mut World, _hero: Entity) -> Result<()> {
|
||||
fn refresh(
|
||||
&mut self,
|
||||
_commands: &mut Commands,
|
||||
_gui_handler: &mut GuiHandler,
|
||||
_hero: Entity,
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use anyhow::Result;
|
|||
use ecs::*;
|
||||
use engine::prelude::*;
|
||||
use rpg_components::components::inventory::Inventory;
|
||||
use rpg_components::config::items::ItemSettings;
|
||||
use rpg_components::items::ability_book::Ability;
|
||||
|
||||
use super::page_content::PageContent;
|
||||
|
@ -40,6 +41,9 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
pub fn new(
|
||||
commands: &mut Commands,
|
||||
gui_handler: &mut GuiHandler,
|
||||
engine_settings: &EngineSettings,
|
||||
item_settings: &ItemSettings,
|
||||
context: &Context,
|
||||
hero: Entity,
|
||||
reference: Weak<CharacterWindow>,
|
||||
close: &Arc<Button>,
|
||||
|
@ -74,16 +78,11 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
})?,
|
||||
{
|
||||
let ui = GuiSnippet::from_str(
|
||||
world,
|
||||
commands,
|
||||
gui_handler,
|
||||
include_str!("../../resources/inventory/items/tooltip.xml"),
|
||||
)?;
|
||||
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let equip: Arc<Label> = ui.element("equip")?;
|
||||
equip.set_info_icon(
|
||||
gui_handler,
|
||||
|
@ -111,7 +110,10 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
ui
|
||||
},
|
||||
ItemRightSide::new::<A>(
|
||||
world,
|
||||
commands,
|
||||
gui_handler,
|
||||
item_settings,
|
||||
context,
|
||||
include_str!("../../resources/inventory/items/right_side.xml"),
|
||||
&reference,
|
||||
hero,
|
||||
|
@ -120,7 +122,7 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
|
||||
// jewels
|
||||
let jewel_mode = PageContent::<A, _>::new(
|
||||
Content::new::<_, Self>(world, reference.clone(), {
|
||||
Content::new::<_, Self>(commands, gui_handler, reference.clone(), {
|
||||
let hero = hero.clone();
|
||||
|
||||
move |world| {
|
||||
|
@ -134,16 +136,11 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
})?,
|
||||
{
|
||||
let ui = GuiSnippet::from_str(
|
||||
world,
|
||||
commands,
|
||||
gui_handler,
|
||||
include_str!("../../resources/inventory/jewels/tooltip.xml"),
|
||||
)?;
|
||||
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let socket: Arc<Label> = ui.element("socket")?;
|
||||
socket.set_info_icon(
|
||||
gui_handler,
|
||||
|
@ -165,7 +162,10 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
ui
|
||||
},
|
||||
JewelRightSide::new::<A>(
|
||||
world,
|
||||
commands,
|
||||
gui_handler,
|
||||
engine_settings,
|
||||
context,
|
||||
include_str!("../../resources/inventory/jewels/right_side.xml"),
|
||||
hero,
|
||||
&reference,
|
||||
|
@ -174,7 +174,7 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
|
||||
// maps
|
||||
let map_mode = PageContent::<A, _>::new(
|
||||
Content::new::<_, Self>(world, reference.clone(), {
|
||||
Content::new::<_, Self>(commands, gui_handler, reference.clone(), {
|
||||
move |world| {
|
||||
let hero_object = world.entity(hero)?;
|
||||
let inventory = hero_object.get_component::<Inventory<A>>()?;
|
||||
|
@ -186,16 +186,11 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
})?,
|
||||
{
|
||||
let ui = GuiSnippet::from_str(
|
||||
world,
|
||||
commands,
|
||||
gui_handler,
|
||||
include_str!("../../resources/inventory/maps/tooltip.xml"),
|
||||
)?;
|
||||
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let select: Arc<Label> = ui.element("select")?;
|
||||
select.set_info_icon(
|
||||
gui_handler,
|
||||
|
@ -217,7 +212,8 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
ui
|
||||
},
|
||||
MapRightSide::new(
|
||||
world,
|
||||
commands,
|
||||
gui_handler,
|
||||
include_str!("../../resources/inventory/maps/right_side.xml"),
|
||||
)?,
|
||||
);
|
||||
|
@ -244,12 +240,21 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
})
|
||||
}
|
||||
|
||||
fn switch_to_jewels(&mut self, world: &mut World) -> Result<()> {
|
||||
fn switch_to_jewels(
|
||||
&mut self,
|
||||
commands: &mut Commands,
|
||||
gui_handler: &mut GuiHandler,
|
||||
) -> Result<()> {
|
||||
self.current_mode = 1;
|
||||
self.update_page(world, true)
|
||||
self.update_page(commands, gui_handler, true)
|
||||
}
|
||||
|
||||
fn update_page(&mut self, world: &mut World, select: bool) -> Result<()> {
|
||||
fn update_page(
|
||||
&mut self,
|
||||
commands: &mut Commands,
|
||||
gui_handler: &mut GuiHandler,
|
||||
select: bool,
|
||||
) -> Result<()> {
|
||||
match self.current_mode {
|
||||
0 => println!("update item view"),
|
||||
1 => println!("update jewel view"),
|
||||
|
@ -262,11 +267,27 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
let mode = &mut self.modes[self.current_mode];
|
||||
|
||||
self.tooltip
|
||||
.attach(world, mode.tooltip().clone(), 0, 0, 1, 1)?;
|
||||
self.content
|
||||
.attach(world, mode.content_mut().base().clone(), 0, 0, 1, 1)?;
|
||||
self.grid
|
||||
.attach(world, mode.right_side_mut().base().clone(), 1, 0, 1, 1)?;
|
||||
.attach(commands, gui_handler, mode.tooltip().clone(), 0, 0, 1, 1)?;
|
||||
|
||||
self.content.attach(
|
||||
commands,
|
||||
gui_handler,
|
||||
mode.content_mut().base().clone(),
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
)?;
|
||||
|
||||
self.grid.attach(
|
||||
commands,
|
||||
gui_handler,
|
||||
mode.right_side_mut().base().clone(),
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
)?;
|
||||
|
||||
mode.content_mut().update(world, self.hero)?;
|
||||
mode.right_side_mut().refresh(world, self.hero)?;
|
||||
|
|
|
@ -142,6 +142,9 @@ impl CharacterWindow {
|
|||
pub fn new<A: Ability + 'static>(
|
||||
commands: &mut Commands,
|
||||
gui_handler: &mut GuiHandler,
|
||||
engine_settings: &EngineSettings,
|
||||
item_settings: &ItemSettings,
|
||||
context: &Context,
|
||||
hero: Entity,
|
||||
name: &str,
|
||||
close: Box<dyn FutureStateChange>,
|
||||
|
|
Loading…
Reference in a new issue