Insert stat snippets inside crate

This commit is contained in:
hodasemi 2024-08-25 13:48:16 +02:00
parent de9136dfd8
commit eb543bab61
19 changed files with 281 additions and 20 deletions

View file

@ -102,10 +102,6 @@ impl GameHandle {
} }
impl ToolTipBuilder for GameHandle { impl ToolTipBuilder for GameHandle {
fn asset_path(&self, s: &str) -> AssetPath {
self.build_data_path(s)
}
fn gui_handler(&self) -> Arc<GuiHandler> { fn gui_handler(&self) -> Arc<GuiHandler> {
self.upgrade().engine().gui_handler().clone() self.upgrade().engine().gui_handler().clone()
} }

View file

@ -0,0 +1,20 @@
<?xml-model href="../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="addon_grid" x_dim="1" y_dim="3" padding="4" margin="2"
x_offset="0" y_offset="0" vert_align="top" hori_align="left"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
width="300" height="120">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="3" y_dim="1">
<icon id="addon_icon" x_slot="0" y_slot="0"></icon>
<label x_slot="1" y_slot="0" text_color="black">Addon</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="2" y_dim="1" padding="3" margin="3">
<label id="type" x_slot="0" y_slot="0" text_color="black">Type</label>
<label id="value" x_slot="1" y_slot="0" text_color="black">Value</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,28 @@
<?xml-model href="../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" y_dim="4" margin="2" padding="4" x_offset="0" y_offset="0" vert_align="top" hori_align="left"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
width="300" height="160">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="5" y_dim="1">
<icon id="ability_icon" x_slot="0" y_slot="0"></icon>
<label id="rarity_label" x_slot="1" y_slot="0" x_size="2" text_color="black" text_alignment="left">Ability Name</label>
<label id="level" x_slot="3" y_slot="0" x_size="2" text_color="black" text_alignment="left">Lvl: 1</label>
</grid>
<grid x_slot="0" y_slot="1" x_dim="5" y_dim="1">
<label id="ability_name" x_slot="0" y_slot="0" x_size="3" text_color="black" text_alignment="left">Rarity</label>
<label id="slot_info" x_slot="3" y_slot="0" x_size="2" text_color="black" text_alignment="left">SlotInfo</label>
</grid>
<grid x_slot="0" y_slot="2" x_dim="2" y_dim="1">
<label id="mana_costs" x_slot="0" y_slot="0" text_color="blue">1</label>
<label id="damage" x_slot="1" y_slot="0" text_color="black">62</label>
</grid>
<grid x_slot="0" y_slot="3" x_dim="2" y_dim="1">
<label x_slot="0" y_slot="0" text_color="black">Cooldown</label>
<label id="cooldown" x_slot="1" y_slot="0" text_color="black">3.0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,7 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="4" y_dim="1">
<icon id="socket_icon" x_slot="0" y_slot="0" icon="textures/abilities/circle.png"></icon>
<label id="stat_type" x_slot="1" y_slot="0" x_size="3" text_color="black" text_alignment="left">StatType</label>
</grid>
</root>

View file

@ -0,0 +1,21 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
hori_align="left" y_dim="3" width="300" height="120">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1">
<icon id="item_icon" x_slot="0" y_slot="0"></icon>
<label id="slot_label" x_slot="1" y_slot="0" x_size="3" text_color="black">Slot</label>
<label id="level_label" x_slot="4" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="3" y_dim="1" padding="3" margin="3">
<label x_slot="0" y_slot="0" text_color="#C23519" id="strength_field" text_ratio="0.9">0</label>
<label x_slot="1" y_slot="0" text_color="#65D01E" id="agility_field" text_ratio="0.9">0</label>
<label x_slot="2" y_slot="0" text_color="#1D63B3" id="intelligence_field" text_ratio="0.9">0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,22 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top"
hori_align="left" width="300" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
y_dim="4" height="160">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1">
<icon id="item_icon" x_slot="0" y_slot="0"></icon>
<label id="slot_label" x_slot="1" y_slot="0" x_size="3" text_color="black">Slot</label>
<label id="level_label" x_slot="4" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="3" y_dim="1" padding="3" margin="3">
<label x_slot="0" y_slot="0" text_color="#C23519" id="strength_field" text_ratio="0.9">0</label>
<label x_slot="1" y_slot="0" text_color="#65D01E" id="agility_field" text_ratio="0.9">0</label>
<label x_slot="2" y_slot="0" text_color="#1D63B3" id="intelligence_field" text_ratio="0.9">0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,22 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top"
hori_align="left" width="300" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
y_dim="5" height="200">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1">
<icon id="item_icon" x_slot="0" y_slot="0"></icon>
<label id="slot_label" x_slot="1" y_slot="0" x_size="3" text_color="black">Slot</label>
<label id="level_label" x_slot="4" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="3" y_dim="1" padding="3" margin="3">
<label x_slot="0" y_slot="0" text_color="#C23519" id="strength_field" text_ratio="0.9">0</label>
<label x_slot="1" y_slot="0" text_color="#65D01E" id="agility_field" text_ratio="0.9">0</label>
<label x_slot="2" y_slot="0" text_color="#1D63B3" id="intelligence_field" text_ratio="0.9">0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,22 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top"
hori_align="left" width="300" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
y_dim="6" height="240">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1">
<icon id="item_icon" x_slot="0" y_slot="0"></icon>
<label id="slot_label" x_slot="1" y_slot="0" x_size="3" text_color="black">Slot</label>
<label id="level_label" x_slot="4" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="3" y_dim="1" padding="3" margin="3">
<label x_slot="0" y_slot="0" text_color="#C23519" id="strength_field" text_ratio="0.9">0</label>
<label x_slot="1" y_slot="0" text_color="#65D01E" id="agility_field" text_ratio="0.9">0</label>
<label x_slot="2" y_slot="0" text_color="#1D63B3" id="intelligence_field" text_ratio="0.9">0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,22 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top"
hori_align="left" width="300" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
y_dim="7" height="280">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1">
<icon id="item_icon" x_slot="0" y_slot="0"></icon>
<label id="slot_label" x_slot="1" y_slot="0" x_size="3" text_color="black">Slot</label>
<label id="level_label" x_slot="4" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="3" y_dim="1" padding="3" margin="3">
<label x_slot="0" y_slot="0" text_color="#C23519" id="strength_field" text_ratio="0.9">0</label>
<label x_slot="1" y_slot="0" text_color="#65D01E" id="agility_field" text_ratio="0.9">0</label>
<label x_slot="2" y_slot="0" text_color="#1D63B3" id="intelligence_field" text_ratio="0.9">0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,22 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top"
hori_align="left" width="300" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
y_dim="8" height="320">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1">
<icon id="item_icon" x_slot="0" y_slot="0"></icon>
<label id="slot_label" x_slot="1" y_slot="0" x_size="3" text_color="black">Slot</label>
<label id="level_label" x_slot="4" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="3" y_dim="1" padding="3" margin="3">
<label x_slot="0" y_slot="0" text_color="#C23519" id="strength_field" text_ratio="0.9">0</label>
<label x_slot="1" y_slot="0" text_color="#65D01E" id="agility_field" text_ratio="0.9">0</label>
<label x_slot="2" y_slot="0" text_color="#1D63B3" id="intelligence_field" text_ratio="0.9">0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,22 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top"
hori_align="left" width="300" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
y_dim="9" height="360">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1">
<icon id="item_icon" x_slot="0" y_slot="0"></icon>
<label id="slot_label" x_slot="1" y_slot="0" x_size="3" text_color="black">Slot</label>
<label id="level_label" x_slot="4" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="3" y_dim="1" padding="3" margin="3">
<label x_slot="0" y_slot="0" text_color="#C23519" id="strength_field" text_ratio="0.9">0</label>
<label x_slot="1" y_slot="0" text_color="#65D01E" id="agility_field" text_ratio="0.9">0</label>
<label x_slot="2" y_slot="0" text_color="#1D63B3" id="intelligence_field" text_ratio="0.9">0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,22 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="item_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top"
hori_align="left" width="300" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
y_dim="10" height="400">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1">
<icon id="item_icon" x_slot="0" y_slot="0"></icon>
<label id="slot_label" x_slot="1" y_slot="0" x_size="3" text_color="black">Slot</label>
<label id="level_label" x_slot="4" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<label id="rarity_label" x_slot="0" y_slot="1">Rarity</label>
<grid x_slot="0" y_slot="2" x_dim="3" y_dim="1" padding="3" margin="3">
<label x_slot="0" y_slot="0" text_color="#C23519" id="strength_field" text_ratio="0.9">0</label>
<label x_slot="1" y_slot="0" text_color="#65D01E" id="agility_field" text_ratio="0.9">0</label>
<label x_slot="2" y_slot="0" text_color="#1D63B3" id="intelligence_field" text_ratio="0.9">0</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,22 @@
<?xml-model href="../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="11">
<grid id="main_grid" x_dim="1" x_offset="0" y_offset="0" vert_align="top" padding="4" margin="2"
background='{"background_color":"#794c0a","border_color":"#543919","border_thickness":{"Pixel":2}}'
hori_align="left" y_dim="3" width="300" height="120">
<!-- header -->
<grid x_slot="0" y_slot="0" x_dim="3" y_dim="1">
<icon id="jewel_icon" x_slot="0" y_slot="0"></icon>
<label id="rarity_label" x_slot="1" y_slot="0" x_size="2" text_color="black">Level</label>
</grid>
<grid x_slot="0" y_slot="1" x_dim="4" y_dim="1" padding="3" margin="3">
<label id="attribute_type" x_slot="0" y_slot="0" x_size="3" text_color="black">Attribute</label>
<label id="attribute_value" x_slot="3" y_slot="0" text_color="black">Value</label>
</grid>
<grid x_slot="0" y_slot="2" x_dim="4" y_dim="1" padding="3" margin="3">
<label id="stat_type" x_slot="0" y_slot="0" x_size="3" text_color="black">Stat</label>
<label id="stat_value" x_slot="3" y_slot="0" text_color="black">Value</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,6 @@
<root>
<grid x_dim="3" y_dim="1">
<label id="stat_type" x_slot="0" y_slot="0" x_size="2" text_color="black" text_alignment="left">StatType</label>
<label id="stat_value" x_slot="2" y_slot="0" text_color="black" text_alignment="right">StatValue</label>
</grid>
</root>

View file

@ -277,9 +277,9 @@ impl AbilityAddon {
tooltip_builder: &impl ToolTipBuilder, tooltip_builder: &impl ToolTipBuilder,
position: (i32, i32), position: (i32, i32),
) -> Result<Tooltip> { ) -> Result<Tooltip> {
let gui = GuiBuilder::new( let gui = GuiBuilder::from_str(
&tooltip_builder.gui_handler(), &tooltip_builder.gui_handler(),
&tooltip_builder.asset_path("gui/xml/ingame/loot/addon_snippet.xml"), include_str!("../../resources/addon_snippet.xml"),
)?; )?;
let icon: Arc<Icon> = gui.element("addon_icon")?; let icon: Arc<Icon> = gui.element("addon_icon")?;

View file

@ -286,9 +286,9 @@ impl AbilityBook {
statistics: &Statistics, statistics: &Statistics,
position: (i32, i32), position: (i32, i32),
) -> Result<Tooltip> { ) -> Result<Tooltip> {
let gui = GuiBuilder::new( let gui = GuiBuilder::from_str(
&tooltip_builder.gui_handler(), &tooltip_builder.gui_handler(),
&tooltip_builder.asset_path("gui/xml/ingame/loot/book_snippet.xml"), include_str!("../../resources/book_snippet.xml"),
)?; )?;
let ability_name: Arc<Label> = gui.element("ability_name")?; let ability_name: Arc<Label> = gui.element("ability_name")?;

View file

@ -18,6 +18,17 @@ use crate::{
use super::{ItemSlots, ItemSystem, Jewel, Rarities, ToolTipBuilder, Tooltip}; use super::{ItemSlots, ItemSystem, Jewel, Rarities, ToolTipBuilder, Tooltip};
const ITEM_SNIPPETS: [&'static str; 8] = [
include_str!("../../resources/items/slots_0.xml"),
include_str!("../../resources/items/slots_1.xml"),
include_str!("../../resources/items/slots_2.xml"),
include_str!("../../resources/items/slots_3.xml"),
include_str!("../../resources/items/slots_4.xml"),
include_str!("../../resources/items/slots_5.xml"),
include_str!("../../resources/items/slots_6.xml"),
include_str!("../../resources/items/slots_7.xml"),
];
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum ItemAffix { pub enum ItemAffix {
Socket(Option<Jewel>), Socket(Option<Jewel>),
@ -229,10 +240,8 @@ impl Item {
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::new( let inspector_snippet =
&tooltip_builder.gui_handler(), GuiBuilder::from_str(&tooltip_builder.gui_handler(), &ITEM_SNIPPETS[count])?;
&tooltip_builder.asset_path(&format!("gui/xml/ingame/loot/items/slots_{}.xml", count)),
)?;
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")?;
@ -268,9 +277,9 @@ 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 = GuiSnippet::new( let stat_type_snippet = GuiSnippet::from_str(
&tooltip_builder.gui_handler(), &tooltip_builder.gui_handler(),
&tooltip_builder.asset_path("gui/xml/ingame/loot/snippets/stat_type_snippet.xml"), 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")?;
@ -285,9 +294,9 @@ impl Item {
} }
for jewel in jewels { for jewel in jewels {
let socket_snippet = GuiSnippet::new( let socket_snippet = GuiSnippet::from_str(
&tooltip_builder.gui_handler(), &tooltip_builder.gui_handler(),
&tooltip_builder.asset_path("gui/xml/ingame/loot/snippets/item_socket_snippet.xml"), include_str!("../../resources/item_socket_snippet.xml"),
)?; )?;
let socket_icon: Arc<Icon> = socket_snippet.element("socket_icon")?; let socket_icon: Arc<Icon> = socket_snippet.element("socket_icon")?;

View file

@ -64,9 +64,9 @@ impl Jewel {
item_settings: &ItemSettings, item_settings: &ItemSettings,
position: (i32, i32), position: (i32, i32),
) -> Result<Tooltip> { ) -> Result<Tooltip> {
let inspector_snippet: Arc<GuiBuilder> = GuiBuilder::new( let inspector_snippet: Arc<GuiBuilder> = GuiBuilder::from_str(
&tooltip_builder.gui_handler(), &tooltip_builder.gui_handler(),
&tooltip_builder.asset_path("gui/xml/ingame/loot/jewel_tooltip.xml"), 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")?;

View file

@ -1,10 +1,8 @@
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use assetpath::AssetPath;
use engine::prelude::*; use engine::prelude::*;
use std::sync::Arc; use std::sync::Arc;
pub trait ToolTipBuilder { pub trait ToolTipBuilder {
fn asset_path(&self, s: &str) -> AssetPath;
fn gui_handler(&self) -> Arc<GuiHandler>; fn gui_handler(&self) -> Arc<GuiHandler>;
} }