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