Start applying changes
This commit is contained in:
parent
78088cecfe
commit
1367be0c0e
14 changed files with 229 additions and 128 deletions
|
@ -28,23 +28,22 @@ impl<A: Ability + 'static> AbilityPageRightSide<A> {
|
||||||
"fourth_ability",
|
"fourth_ability",
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn new(world: &mut World, hero: Entity, reference: &Weak<CharacterWindow>) -> Result<Self> {
|
pub fn new(
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
item_settings: &mut ItemSettings,
|
||||||
|
engine_settings: &mut EngineSettings,
|
||||||
|
context: &mut Context,
|
||||||
|
hero: Entity,
|
||||||
|
reference: &Weak<CharacterWindow>,
|
||||||
|
) -> Result<Self> {
|
||||||
let snippet = GuiSnippet::from_str(
|
let snippet = GuiSnippet::from_str(
|
||||||
world,
|
commands,
|
||||||
|
gui_handler,
|
||||||
include_str!("../../resources/abilities/right_side.xml"),
|
include_str!("../../resources/abilities/right_side.xml"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let color_settings = world
|
let color_settings = item_settings.rarity_color_settings.clone();
|
||||||
.resources
|
|
||||||
.get::<ItemSettings>()
|
|
||||||
.rarity_color_settings
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
let (gui_handler, engine_settings, context): (
|
|
||||||
&mut GuiHandler,
|
|
||||||
&mut EngineSettings,
|
|
||||||
&mut Context,
|
|
||||||
) = world.resources.get_mut()?;
|
|
||||||
|
|
||||||
Self::rarity_icon_background(gui_handler, &snippet, "common", color_settings.common)?;
|
Self::rarity_icon_background(gui_handler, &snippet, "common", color_settings.common)?;
|
||||||
Self::rarity_icon_background(gui_handler, &snippet, "uncommon", color_settings.uncommon)?;
|
Self::rarity_icon_background(gui_handler, &snippet, "uncommon", color_settings.uncommon)?;
|
||||||
|
@ -64,7 +63,7 @@ impl<A: Ability + 'static> AbilityPageRightSide<A> {
|
||||||
button.set_callback({
|
button.set_callback({
|
||||||
let reference = reference.clone();
|
let reference = reference.clone();
|
||||||
|
|
||||||
move |world: &mut World| {
|
move |commands, gui_handler| {
|
||||||
if let Some(menu) = reference.upgrade() {
|
if let Some(menu) = reference.upgrade() {
|
||||||
let mut tabs = menu.tabs_mut();
|
let mut tabs = menu.tabs_mut();
|
||||||
let abilities = tabs.abilities::<A>();
|
let abilities = tabs.abilities::<A>();
|
||||||
|
|
|
@ -17,7 +17,8 @@ use super::AbilityPage;
|
||||||
|
|
||||||
impl<A: Ability + 'static> Content<A, AbilityAddon> {
|
impl<A: Ability + 'static> Content<A, AbilityAddon> {
|
||||||
fn show_addon_tooltip(
|
fn show_addon_tooltip(
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
hero: Entity,
|
hero: Entity,
|
||||||
addon_index: usize,
|
addon_index: usize,
|
||||||
reference: &Weak<CharacterWindow>,
|
reference: &Weak<CharacterWindow>,
|
||||||
|
@ -30,7 +31,7 @@ impl<A: Ability + 'static> Content<A, AbilityAddon> {
|
||||||
let target_y = y;
|
let target_y = y;
|
||||||
|
|
||||||
let addon = inventory.addon_at(addon_index);
|
let addon = inventory.addon_at(addon_index);
|
||||||
let gui = addon.create_tooltip(world, (target_x, target_y))?;
|
let gui = addon.create_tooltip(commands, gui_handler, (target_x, target_y))?;
|
||||||
gui.enable(world)?;
|
gui.enable(world)?;
|
||||||
gui.perform_single_check(world.resources.get_mut()?, x, y)?;
|
gui.perform_single_check(world.resources.get_mut()?, x, y)?;
|
||||||
|
|
||||||
|
|
|
@ -35,20 +35,21 @@ pub struct AbilityPage<A: Ability + 'static> {
|
||||||
|
|
||||||
impl<A: Ability + 'static> AbilityPage<A> {
|
impl<A: Ability + 'static> AbilityPage<A> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
hero: Entity,
|
hero: Entity,
|
||||||
reference: Weak<CharacterWindow>,
|
reference: Weak<CharacterWindow>,
|
||||||
close: &Arc<Button>,
|
close: &Arc<Button>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let gui_handler = world.resources.get_mut_unchecked::<GuiHandler>();
|
|
||||||
let grid = Grid::new(gui_handler, 2, 1, false)?;
|
let grid = Grid::new(gui_handler, 2, 1, false)?;
|
||||||
|
|
||||||
let left_base = GuiSnippet::from_str(
|
let left_base = GuiSnippet::from_str(
|
||||||
world,
|
commands,
|
||||||
|
gui_handler,
|
||||||
include_str!("../../resources/abilities/left_side.xml"),
|
include_str!("../../resources/abilities/left_side.xml"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
grid.attach(world, left_base.clone(), 0, 0, 1, 1)?;
|
grid.attach(commands, gui_handler, left_base.clone(), 0, 0, 1, 1)?;
|
||||||
|
|
||||||
Self::setup_content_switch(&left_base, reference.clone())?;
|
Self::setup_content_switch(&left_base, reference.clone())?;
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ impl<A: Ability + 'static> AbilityPage<A> {
|
||||||
|
|
||||||
// abilities
|
// abilities
|
||||||
let ability_mode = PageContent::new(
|
let ability_mode = PageContent::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| {
|
||||||
|
@ -71,16 +72,11 @@ impl<A: Ability + 'static> AbilityPage<A> {
|
||||||
})?,
|
})?,
|
||||||
{
|
{
|
||||||
let ui = GuiSnippet::from_str(
|
let ui = GuiSnippet::from_str(
|
||||||
world,
|
commands,
|
||||||
|
gui_handler,
|
||||||
include_str!("../../resources/abilities/ability_tooltip.xml"),
|
include_str!("../../resources/abilities/ability_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,
|
||||||
|
@ -179,7 +175,7 @@ impl<A: Ability + 'static> AbilityPage<A> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_page(&mut self, world: &mut World) -> Result<()> {
|
fn update_page(&mut self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||||
match self.current_mode {
|
match self.current_mode {
|
||||||
0 => println!("update ability view"),
|
0 => println!("update ability view"),
|
||||||
1 => println!("update addon view"),
|
1 => println!("update addon view"),
|
||||||
|
@ -191,13 +187,27 @@ impl<A: Ability + 'static> AbilityPage<A> {
|
||||||
mode.content_mut().update(world, self.hero)?;
|
mode.content_mut().update(world, self.hero)?;
|
||||||
|
|
||||||
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
|
self.content.attach(
|
||||||
.attach(world, mode.content_mut().base().clone(), 0, 0, 1, 1)?;
|
commands,
|
||||||
|
gui_handler,
|
||||||
|
mode.content_mut().base().clone(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
)?;
|
||||||
|
|
||||||
self.right_side.refresh(world, self.hero)?;
|
self.right_side.refresh(commands, gui_handler, self.hero)?;
|
||||||
self.grid
|
self.grid.attach(
|
||||||
.attach(world, self.right_side.base().clone(), 1, 0, 1, 1)?;
|
commands,
|
||||||
|
gui_handler,
|
||||||
|
self.right_side.base().clone(),
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ pub struct CharacterPage {
|
||||||
|
|
||||||
impl CharacterPage {
|
impl CharacterPage {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
hero: Entity,
|
hero: Entity,
|
||||||
hero_name: &str,
|
hero_name: &str,
|
||||||
reference: &Weak<CharacterWindow>,
|
reference: &Weak<CharacterWindow>,
|
||||||
|
|
|
@ -33,7 +33,8 @@ pub struct Content<A: Ability + 'static, T: Send + Sync> {
|
||||||
|
|
||||||
impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
||||||
pub fn new<F, P>(
|
pub fn new<F, P>(
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
reference: Weak<CharacterWindow>,
|
reference: Weak<CharacterWindow>,
|
||||||
on_enable: F,
|
on_enable: F,
|
||||||
) -> Result<Self>
|
) -> Result<Self>
|
||||||
|
@ -41,7 +42,11 @@ impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
||||||
F: Fn(&mut World) -> Result<Vec<T>> + Send + Sync + 'static,
|
F: Fn(&mut World) -> Result<Vec<T>> + Send + Sync + 'static,
|
||||||
P: Page,
|
P: Page,
|
||||||
{
|
{
|
||||||
let base = GuiSnippet::from_str(world, include_str!("../resources/content.xml"))?;
|
let base = GuiSnippet::from_str(
|
||||||
|
commands,
|
||||||
|
gui_handler,
|
||||||
|
include_str!("../resources/content.xml"),
|
||||||
|
)?;
|
||||||
|
|
||||||
let (gui_handler, engine_settings, context): (
|
let (gui_handler, engine_settings, context): (
|
||||||
&mut GuiHandler,
|
&mut GuiHandler,
|
||||||
|
@ -58,12 +63,12 @@ impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
||||||
left.set_callback({
|
left.set_callback({
|
||||||
let reference = reference.clone();
|
let reference = reference.clone();
|
||||||
|
|
||||||
move |world| {
|
move |commands, gui_handler| {
|
||||||
if let Some(window) = reference.upgrade() {
|
if let Some(window) = reference.upgrade() {
|
||||||
let mut tab = window.tab_mut();
|
let mut tab = window.tab_mut();
|
||||||
let page = tab.downcast_mut::<P>();
|
let page = tab.downcast_mut::<P>();
|
||||||
|
|
||||||
page.previous_tab(world)?;
|
page.previous_tab(commands, gui_handler)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -79,12 +84,12 @@ impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
||||||
right.set_callback({
|
right.set_callback({
|
||||||
let reference = reference.clone();
|
let reference = reference.clone();
|
||||||
|
|
||||||
move |world| {
|
move |commands, gui_handler| {
|
||||||
if let Some(window) = reference.upgrade() {
|
if let Some(window) = reference.upgrade() {
|
||||||
let mut tab = window.tab_mut();
|
let mut tab = window.tab_mut();
|
||||||
let page = tab.downcast_mut::<P>();
|
let page = tab.downcast_mut::<P>();
|
||||||
|
|
||||||
page.next_tab(world)?;
|
page.next_tab(commands, gui_handler)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -105,12 +110,16 @@ impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_grid(world: &mut World, grid: &Arc<Grid>) -> Result<()> {
|
fn clear_grid(
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
grid: &Arc<Grid>,
|
||||||
|
) -> Result<()> {
|
||||||
let (rows, columns) = grid.dimensions();
|
let (rows, columns) = grid.dimensions();
|
||||||
|
|
||||||
for x in 0..columns {
|
for x in 0..columns {
|
||||||
for y in 0..rows {
|
for y in 0..rows {
|
||||||
grid.detach(world, x, y)?;
|
grid.detach(commands, gui_handler, x, y)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,18 +130,23 @@ impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
||||||
label.set_text(gui_handler, format!("{} / {}", self.page + 1, self.pages))
|
label.set_text(gui_handler, format!("{} / {}", self.page + 1, self.pages))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_base<F>(&mut self, world: &mut World, setup: F) -> Result<()>
|
pub fn update_base<F>(
|
||||||
|
&mut self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
setup: F,
|
||||||
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
Self: ContentWrapper,
|
Self: ContentWrapper,
|
||||||
F: Fn(&mut World, &Arc<Button>, &T, usize) -> Result<()>,
|
F: Fn(&mut Commands, &mut GuiHandler, &Arc<Button>, &T, usize) -> Result<()>,
|
||||||
{
|
{
|
||||||
self.refresh(world)?;
|
self.refresh(world)?;
|
||||||
|
|
||||||
let grid: Arc<Grid> = self.base.element("content")?;
|
let grid: Arc<Grid> = self.base.element("content")?;
|
||||||
let label: Arc<Label> = self.base.element("tab_info")?;
|
let label: Arc<Label> = self.base.element("tab_info")?;
|
||||||
|
|
||||||
Self::clear_grid(world, &grid)?;
|
Self::clear_grid(commands, gui_handler, &grid)?;
|
||||||
self.set_tab(world.resources.get_mut()?, &label)?;
|
self.set_tab(gui_handler, &label)?;
|
||||||
|
|
||||||
let (rows, columns) = grid.dimensions();
|
let (rows, columns) = grid.dimensions();
|
||||||
|
|
||||||
|
@ -143,13 +157,14 @@ impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
||||||
match self.data.get(index) {
|
match self.data.get(index) {
|
||||||
Some(t) => {
|
Some(t) => {
|
||||||
let snippet = GuiSnippet::from_str(
|
let snippet = GuiSnippet::from_str(
|
||||||
world,
|
commands,
|
||||||
|
gui_handler,
|
||||||
include_str!("../resources/content_button.xml"),
|
include_str!("../resources/content_button.xml"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let button: Arc<Button> = snippet.element("button")?;
|
let button: Arc<Button> = snippet.element("button")?;
|
||||||
setup(world, &button, t, index)?;
|
setup(commands, gui_handler, &button, t, index)?;
|
||||||
grid.attach(world, button, x, y, 1, 1)?;
|
grid.attach(commands, gui_handler, button, x, y, 1, 1)?;
|
||||||
}
|
}
|
||||||
None => break 'outer,
|
None => break 'outer,
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,20 +38,21 @@ pub struct InventoryPage<A: Ability + 'static> {
|
||||||
|
|
||||||
impl<A: Ability + 'static> InventoryPage<A> {
|
impl<A: Ability + 'static> InventoryPage<A> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
hero: Entity,
|
hero: Entity,
|
||||||
reference: Weak<CharacterWindow>,
|
reference: Weak<CharacterWindow>,
|
||||||
close: &Arc<Button>,
|
close: &Arc<Button>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
|
||||||
let grid = Grid::new(gui_handler, 2, 1, false)?;
|
let grid = Grid::new(gui_handler, 2, 1, false)?;
|
||||||
|
|
||||||
let left_base = GuiSnippet::from_str(
|
let left_base = GuiSnippet::from_str(
|
||||||
world,
|
commands,
|
||||||
|
gui_handler,
|
||||||
include_str!("../../resources/inventory/left_side.xml"),
|
include_str!("../../resources/inventory/left_side.xml"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
grid.attach(world, left_base.clone(), 0, 0, 1, 1)?;
|
grid.attach(commands, gui_handler, left_base.clone(), 0, 0, 1, 1)?;
|
||||||
Self::setup_content_switch(&left_base, reference.clone())?;
|
Self::setup_content_switch(&left_base, reference.clone())?;
|
||||||
|
|
||||||
let tooltip = left_base.element("tooltip")?;
|
let tooltip = left_base.element("tooltip")?;
|
||||||
|
@ -59,10 +60,10 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
||||||
|
|
||||||
// items
|
// items
|
||||||
let item_mode = PageContent::<A, _>::new(
|
let item_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: &mut 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>>()?;
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,22 @@ use std::{
|
||||||
use self::{abilities::AbilityPage, character::CharacterPage, inventory::InventoryPage};
|
use self::{abilities::AbilityPage, character::CharacterPage, inventory::InventoryPage};
|
||||||
|
|
||||||
trait Page: Any + Send + Sync + Downcast {
|
trait Page: Any + Send + Sync + Downcast {
|
||||||
fn enable(&mut self, world: &mut World) -> Result<Arc<Grid>>;
|
fn enable(
|
||||||
fn disable(&mut self, world: &mut World) -> Result<()>;
|
&mut self,
|
||||||
fn select(&self, world: &mut World) -> Result<()>;
|
commands: &mut Commands,
|
||||||
fn next_tab(&mut self, world: &mut World) -> Result<()>;
|
gui_handler: &mut GuiHandler,
|
||||||
fn previous_tab(&mut self, world: &mut World) -> Result<()>;
|
) -> Result<Arc<Grid>>;
|
||||||
fn event(&mut self, world: &mut World, button: ControllerButton) -> Result<bool>;
|
fn disable(&mut self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()>;
|
||||||
|
fn select(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()>;
|
||||||
|
fn next_tab(&mut self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()>;
|
||||||
|
fn previous_tab(&mut self, commands: &mut Commands, gui_handler: &mut GuiHandler)
|
||||||
|
-> Result<()>;
|
||||||
|
fn event(
|
||||||
|
&mut self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
button: ControllerButton,
|
||||||
|
) -> Result<bool>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_downcast!(Page);
|
impl_downcast!(Page);
|
||||||
|
@ -130,12 +140,14 @@ pub struct CharacterWindow {
|
||||||
|
|
||||||
impl CharacterWindow {
|
impl CharacterWindow {
|
||||||
pub fn new<A: Ability + 'static>(
|
pub fn new<A: Ability + 'static>(
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
hero: Entity,
|
hero: Entity,
|
||||||
name: &str,
|
name: &str,
|
||||||
close: Box<dyn FutureStateChange>,
|
close: Box<dyn FutureStateChange>,
|
||||||
) -> Result<Arc<Self>> {
|
) -> Result<Arc<Self>> {
|
||||||
let menu_gui = GuiBuilder::from_str(world, include_str!("../resources/menu.xml"))?;
|
let menu_gui =
|
||||||
|
GuiBuilder::from_str(commands, gui_handler, include_str!("../resources/menu.xml"))?;
|
||||||
|
|
||||||
let content_grid = menu_gui.element("tab_content")?;
|
let content_grid = menu_gui.element("tab_content")?;
|
||||||
let open_character_page: Arc<Button> = menu_gui.element("open_statistics")?;
|
let open_character_page: Arc<Button> = menu_gui.element("open_statistics")?;
|
||||||
|
@ -152,9 +164,15 @@ impl CharacterWindow {
|
||||||
tooltips: Mutex::default(),
|
tooltips: Mutex::default(),
|
||||||
|
|
||||||
tabs: RwLock::new([
|
tabs: RwLock::new([
|
||||||
Box::new(CharacterPage::new(world, hero, name, me).unwrap()),
|
Box::new(CharacterPage::new(commands, gui_handler, hero, name, me).unwrap()),
|
||||||
Box::new(InventoryPage::<A>::new(world, hero, me.clone(), &close_button).unwrap()),
|
Box::new(
|
||||||
Box::new(AbilityPage::<A>::new(world, hero, me.clone(), &close_button).unwrap()),
|
InventoryPage::<A>::new(commands, gui_handler, hero, me.clone(), &close_button)
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
Box::new(
|
||||||
|
AbilityPage::<A>::new(commands, gui_handler, hero, me.clone(), &close_button)
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
tab: AtomicUsize::new(0),
|
tab: AtomicUsize::new(0),
|
||||||
});
|
});
|
||||||
|
@ -162,13 +180,14 @@ impl CharacterWindow {
|
||||||
let open_tab = {
|
let open_tab = {
|
||||||
let weak_me = Arc::downgrade(&character_window);
|
let weak_me = Arc::downgrade(&character_window);
|
||||||
|
|
||||||
move |world: &mut World, index| {
|
move |commands: &mut Commands, gui_handler: &mut GuiHandler, index| {
|
||||||
if let Some(me) = weak_me.upgrade() {
|
if let Some(me) = weak_me.upgrade() {
|
||||||
me.tab.store(index, SeqCst);
|
me.tab.store(index, SeqCst);
|
||||||
|
|
||||||
let child = me.tab_mut().enable(world)?;
|
let child = me.tab_mut().enable(commands, gui_handler)?;
|
||||||
me.tab_content_grid.attach(world, child, 0, 0, 1, 1)?;
|
me.tab_content_grid
|
||||||
me.tab().select(world)?;
|
.attach(commands, gui_handler, child, 0, 0, 1, 1)?;
|
||||||
|
me.tab().select(commands, gui_handler)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -178,19 +197,19 @@ impl CharacterWindow {
|
||||||
open_character_page.set_callback({
|
open_character_page.set_callback({
|
||||||
let open_tab = open_tab.clone();
|
let open_tab = open_tab.clone();
|
||||||
|
|
||||||
move |world| open_tab(world, 0)
|
move |commands, gui_handler| open_tab(commands, gui_handler, 0)
|
||||||
});
|
});
|
||||||
|
|
||||||
open_inventory_page.set_callback({
|
open_inventory_page.set_callback({
|
||||||
let open_tab = open_tab.clone();
|
let open_tab = open_tab.clone();
|
||||||
|
|
||||||
move |world| open_tab(world, 1)
|
move |commands, gui_handler| open_tab(commands, gui_handler, 1)
|
||||||
});
|
});
|
||||||
|
|
||||||
open_ability_page.set_callback({
|
open_ability_page.set_callback({
|
||||||
let open_tab = open_tab.clone();
|
let open_tab = open_tab.clone();
|
||||||
|
|
||||||
move |world| open_tab(world, 2)
|
move |commands, gui_handler| open_tab(commands, gui_handler, 2)
|
||||||
});
|
});
|
||||||
|
|
||||||
Self::setup_menu(&character_window)?;
|
Self::setup_menu(&character_window)?;
|
||||||
|
@ -198,8 +217,13 @@ impl CharacterWindow {
|
||||||
Ok(character_window)
|
Ok(character_window)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn event(&self, world: &mut World, button: ControllerButton) -> Result<bool> {
|
pub fn event(
|
||||||
self.tabs.write().unwrap()[self.tab.load(SeqCst)].event(world, button)
|
&self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
button: ControllerButton,
|
||||||
|
) -> Result<bool> {
|
||||||
|
self.tabs.write().unwrap()[self.tab.load(SeqCst)].event(commands, gui_handler, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tabs<'a>(&'a self) -> Tabs<'a> {
|
pub fn tabs<'a>(&'a self) -> Tabs<'a> {
|
||||||
|
@ -235,9 +259,14 @@ impl CharacterWindow {
|
||||||
.insert(name.to_string(), gui.into());
|
.insert(name.to_string(), gui.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_tooltip(&self, world: &mut World, name: impl ToString) -> Result<()> {
|
pub fn remove_tooltip(
|
||||||
|
&self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
name: impl ToString,
|
||||||
|
) -> Result<()> {
|
||||||
if let Some(tooltip) = self.tooltips.lock().unwrap().remove(&name.to_string()) {
|
if let Some(tooltip) = self.tooltips.lock().unwrap().remove(&name.to_string()) {
|
||||||
tooltip.disable(world)?;
|
tooltip.disable(commands, gui_handler)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -280,12 +309,13 @@ impl TopLevelGui for CharacterWindow {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable(&self, world: &mut World) -> Result<()> {
|
fn enable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||||
self.menu_gui.enable(world)?;
|
self.menu_gui.enable(commands, gui_handler)?;
|
||||||
|
|
||||||
let child = self.tab_mut().enable(world)?;
|
let child = self.tab_mut().enable(commands, gui_handler)?;
|
||||||
self.tab_content_grid.attach(world, child, 0, 0, 1, 1)?;
|
self.tab_content_grid
|
||||||
self.tab().select(world)?;
|
.attach(commands, gui_handler, child, 0, 0, 1, 1)?;
|
||||||
|
self.tab().select(commands, gui_handler)?;
|
||||||
|
|
||||||
let (gui_handler, engine_settings, context): (
|
let (gui_handler, engine_settings, context): (
|
||||||
&mut GuiHandler,
|
&mut GuiHandler,
|
||||||
|
@ -314,8 +344,8 @@ impl TopLevelGui for CharacterWindow {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, world: &mut World) -> Result<()> {
|
fn disable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||||
self.menu_gui.disable(world)?;
|
self.menu_gui.disable(commands, gui_handler)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -336,37 +366,48 @@ impl GuiElementTraits for CharacterWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopGui for CharacterWindow {
|
impl TopGui for CharacterWindow {
|
||||||
fn decline(&self, world: &mut World) -> Result<()> {
|
fn decline(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||||
(self.close)(world)
|
(self.close)(commands, gui_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_tab(&self, world: &mut World, second_level: bool) -> Result<()> {
|
fn next_tab(
|
||||||
|
&self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
second_level: bool,
|
||||||
|
) -> Result<()> {
|
||||||
match second_level {
|
match second_level {
|
||||||
false => {
|
false => {
|
||||||
// disable old tab
|
// disable old tab
|
||||||
self.tab_mut().disable(world)?;
|
self.tab_mut().disable(commands, gui_handler)?;
|
||||||
|
|
||||||
// add to tab index
|
// add to tab index
|
||||||
self.tab.store((self.tab.load(SeqCst) + 1) % 3, SeqCst);
|
self.tab.store((self.tab.load(SeqCst) + 1) % 3, SeqCst);
|
||||||
|
|
||||||
// update tab content
|
// update tab content
|
||||||
let child = self.tab_mut().enable(world)?;
|
let child = self.tab_mut().enable(commands, gui_handler)?;
|
||||||
self.tab_content_grid.attach(world, child, 0, 0, 1, 1)?;
|
self.tab_content_grid
|
||||||
self.tab().select(world)?;
|
.attach(commands, gui_handler, child, 0, 0, 1, 1)?;
|
||||||
|
self.tab().select(commands, gui_handler)?;
|
||||||
}
|
}
|
||||||
true => {
|
true => {
|
||||||
self.tab_mut().next_tab(world)?;
|
self.tab_mut().next_tab(commands, gui_handler)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn previous_tab(&self, world: &mut World, second_level: bool) -> Result<()> {
|
fn previous_tab(
|
||||||
|
&self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
second_level: bool,
|
||||||
|
) -> Result<()> {
|
||||||
match second_level {
|
match second_level {
|
||||||
false => {
|
false => {
|
||||||
// disable old tab
|
// disable old tab
|
||||||
self.tab_mut().disable(world)?;
|
self.tab_mut().disable(commands, gui_handler)?;
|
||||||
|
|
||||||
// subtract from tab index
|
// subtract from tab index
|
||||||
if self.tab.load(SeqCst) == 0 {
|
if self.tab.load(SeqCst) == 0 {
|
||||||
|
@ -376,12 +417,13 @@ impl TopGui for CharacterWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update tab content
|
// update tab content
|
||||||
let child = self.tab_mut().enable(world)?;
|
let child = self.tab_mut().enable(commands, gui_handler)?;
|
||||||
self.tab_content_grid.attach(world, child, 0, 0, 1, 1)?;
|
self.tab_content_grid
|
||||||
self.tab().select(world)?;
|
.attach(commands, gui_handler, child, 0, 0, 1, 1)?;
|
||||||
|
self.tab().select(commands, gui_handler)?;
|
||||||
}
|
}
|
||||||
true => {
|
true => {
|
||||||
self.tab_mut().previous_tab(world)?;
|
self.tab_mut().previous_tab(commands, gui_handler)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +444,9 @@ impl CharacterWindow {
|
||||||
// .add("open_statistics", open_statistics)
|
// .add("open_statistics", open_statistics)
|
||||||
// .add("open_abilities", open_abilities)
|
// .add("open_abilities", open_abilities)
|
||||||
// .add("open_inventory", open_inventory)
|
// .add("open_inventory", open_inventory)
|
||||||
.add("close", move |world| close(world))
|
.add("close", move |commands, gui_handler| {
|
||||||
|
close(commands, gui_handler)
|
||||||
|
})
|
||||||
.into(),
|
.into(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,12 @@ use super::traits::*;
|
||||||
pub struct EmptyRightSide;
|
pub struct EmptyRightSide;
|
||||||
|
|
||||||
impl RightSide for EmptyRightSide {
|
impl RightSide for EmptyRightSide {
|
||||||
fn refresh(&mut self, _world: &mut World, _hero: Entity) -> Result<()> {
|
fn refresh(
|
||||||
|
&mut self,
|
||||||
|
_commands: &mut Commands,
|
||||||
|
_gui_handler: &mut GuiHandler,
|
||||||
|
_hero: Entity,
|
||||||
|
) -> Result<()> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,19 @@ pub trait PageContentWrapper: Send + Sync {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RightSide: Send + Sync {
|
pub trait RightSide: Send + Sync {
|
||||||
fn refresh(&mut self, world: &mut World, hero: Entity) -> Result<()>;
|
fn refresh(
|
||||||
|
&mut self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
|
hero: Entity,
|
||||||
|
) -> Result<()>;
|
||||||
|
|
||||||
fn disable(&mut self, _world: &mut World, _hero: Entity) -> Result<()> {
|
fn disable(
|
||||||
|
&mut self,
|
||||||
|
_commands: &mut Commands,
|
||||||
|
_gui_handler: &mut GuiHandler,
|
||||||
|
_hero: Entity,
|
||||||
|
) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,10 +245,17 @@ impl AbilityAddon {
|
||||||
Ok(item_system.addon(rarity, addon_type))
|
Ok(item_system.addon(rarity, addon_type))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_tooltip(&self, world: &mut World, position: (i32, i32)) -> Result<Tooltip> {
|
pub fn create_tooltip(
|
||||||
let gui = GuiBuilder::from_str(world, include_str!("../../resources/addon_snippet.xml"))?;
|
&self,
|
||||||
|
commands: &mut Commands,
|
||||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
gui_handler: &mut GuiHandler,
|
||||||
|
position: (i32, i32),
|
||||||
|
) -> Result<Tooltip> {
|
||||||
|
let gui = GuiBuilder::from_str(
|
||||||
|
commands,
|
||||||
|
gui_handler,
|
||||||
|
include_str!("../../resources/addon_snippet.xml"),
|
||||||
|
)?;
|
||||||
|
|
||||||
let icon: Arc<Icon> = gui.element("addon_icon")?;
|
let icon: Arc<Icon> = gui.element("addon_icon")?;
|
||||||
let rarity_label: Arc<Label> = gui.element("rarity_label")?;
|
let rarity_label: Arc<Label> = gui.element("rarity_label")?;
|
||||||
|
|
|
@ -298,13 +298,16 @@ impl<A: Ability> AbilityBook<A> {
|
||||||
|
|
||||||
pub fn create_tooltip(
|
pub fn create_tooltip(
|
||||||
&self,
|
&self,
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
statistics: &Statistics,
|
statistics: &Statistics,
|
||||||
position: (i32, i32),
|
position: (i32, i32),
|
||||||
) -> Result<Tooltip> {
|
) -> Result<Tooltip> {
|
||||||
let gui = GuiBuilder::from_str(world, include_str!("../../resources/book_snippet.xml"))?;
|
let gui = GuiBuilder::from_str(
|
||||||
|
commands,
|
||||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
gui_handler,
|
||||||
|
include_str!("../../resources/book_snippet.xml"),
|
||||||
|
)?;
|
||||||
|
|
||||||
let ability_name: Arc<Label> = gui.element("ability_name")?;
|
let ability_name: Arc<Label> = gui.element("ability_name")?;
|
||||||
let rarity_label: Arc<Label> = gui.element("rarity_label")?;
|
let rarity_label: Arc<Label> = gui.element("rarity_label")?;
|
||||||
|
|
|
@ -233,16 +233,15 @@ impl Item {
|
||||||
|
|
||||||
pub fn create_tooltip(
|
pub fn create_tooltip(
|
||||||
&self,
|
&self,
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
attributes: &Attributes,
|
attributes: &Attributes,
|
||||||
position: (i32, i32),
|
position: (i32, i32),
|
||||||
) -> Result<Tooltip> {
|
) -> Result<Tooltip> {
|
||||||
let (stats, jewels) = ItemAffix::squash(self.affixes.iter());
|
let (stats, jewels) = ItemAffix::squash(self.affixes.iter());
|
||||||
let count = stats.len() + jewels.len();
|
let count = stats.len() + jewels.len();
|
||||||
|
|
||||||
let inspector_snippet = GuiBuilder::from_str(world, &ITEM_SNIPPETS[count])?;
|
let inspector_snippet = GuiBuilder::from_str(commands, gui_handler, &ITEM_SNIPPETS[count])?;
|
||||||
|
|
||||||
let gui_handler = world.resources.get_mut_unchecked::<GuiHandler>();
|
|
||||||
|
|
||||||
let item_icon: Arc<Icon> = inspector_snippet.element("item_icon")?;
|
let item_icon: Arc<Icon> = inspector_snippet.element("item_icon")?;
|
||||||
let slot_label: Arc<Label> = inspector_snippet.element("slot_label")?;
|
let slot_label: Arc<Label> = inspector_snippet.element("slot_label")?;
|
||||||
|
@ -289,8 +288,11 @@ impl Item {
|
||||||
let mut index = Self::INSPECTOR_OFFSET;
|
let mut index = Self::INSPECTOR_OFFSET;
|
||||||
|
|
||||||
for stat in stats {
|
for stat in stats {
|
||||||
let stat_type_snippet =
|
let stat_type_snippet = GuiSnippet::from_str(
|
||||||
GuiSnippet::from_str(world, include_str!("../../resources/stat_type_snippet.xml"))?;
|
commands,
|
||||||
|
gui_handler,
|
||||||
|
include_str!("../../resources/stat_type_snippet.xml"),
|
||||||
|
)?;
|
||||||
|
|
||||||
let stat_type_label: Arc<Label> = stat_type_snippet.element("stat_type")?;
|
let stat_type_label: Arc<Label> = stat_type_snippet.element("stat_type")?;
|
||||||
let stat_value_label: Arc<Label> = stat_type_snippet.element("stat_value")?;
|
let stat_value_label: Arc<Label> = stat_type_snippet.element("stat_value")?;
|
||||||
|
@ -298,14 +300,15 @@ impl Item {
|
||||||
stat_type_label.set_text(gui_handler, &format!("{}", stat))?;
|
stat_type_label.set_text(gui_handler, &format!("{}", stat))?;
|
||||||
stat_value_label.set_text(gui_handler, &stat.display_value())?;
|
stat_value_label.set_text(gui_handler, &stat.display_value())?;
|
||||||
|
|
||||||
inspector_grid.attach(world, stat_type_snippet, 0, index, 1, 1)?;
|
inspector_grid.attach(commands, gui_handler, stat_type_snippet, 0, index, 1, 1)?;
|
||||||
|
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for jewel in jewels {
|
for jewel in jewels {
|
||||||
let socket_snippet = GuiSnippet::from_str(
|
let socket_snippet = GuiSnippet::from_str(
|
||||||
world,
|
commands,
|
||||||
|
gui_handler,
|
||||||
include_str!("../../resources/item_socket_snippet.xml"),
|
include_str!("../../resources/item_socket_snippet.xml"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -329,7 +332,7 @@ impl Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inspector_grid.attach(world, socket_snippet, 0, index, 1, 1)?;
|
inspector_grid.attach(commands, gui_handler, socket_snippet, 0, index, 1, 1)?;
|
||||||
|
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,14 +60,16 @@ impl Jewel {
|
||||||
|
|
||||||
pub fn create_tooltip(
|
pub fn create_tooltip(
|
||||||
&self,
|
&self,
|
||||||
world: &mut World,
|
commands: &mut Commands,
|
||||||
|
gui_handler: &mut GuiHandler,
|
||||||
item_settings: &ItemSettings,
|
item_settings: &ItemSettings,
|
||||||
position: (i32, i32),
|
position: (i32, i32),
|
||||||
) -> Result<Tooltip> {
|
) -> Result<Tooltip> {
|
||||||
let inspector_snippet: Arc<GuiBuilder> =
|
let inspector_snippet: Arc<GuiBuilder> = GuiBuilder::from_str(
|
||||||
GuiBuilder::from_str(world, include_str!("../../resources/jewel_tooltip.xml"))?;
|
commands,
|
||||||
|
gui_handler,
|
||||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
include_str!("../../resources/jewel_tooltip.xml"),
|
||||||
|
)?;
|
||||||
|
|
||||||
let main_grid: Arc<Grid> = inspector_snippet.element("main_grid")?;
|
let main_grid: Arc<Grid> = inspector_snippet.element("main_grid")?;
|
||||||
main_grid.change_position_unscaled(gui_handler, position.0, position.1)?;
|
main_grid.change_position_unscaled(gui_handler, position.0, position.1)?;
|
||||||
|
|
|
@ -18,8 +18,8 @@ impl Tooltip {
|
||||||
Self { grid, gui }
|
Self { grid, gui }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable(&self, world: &mut World) -> Result<()> {
|
pub fn enable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||||
self.gui.enable(world)
|
self.gui.enable(commands, gui_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_fitting(
|
pub fn check_fitting(
|
||||||
|
|
Loading…
Reference in a new issue