Fix a lot of porting issues

This commit is contained in:
hodasemi 2024-08-26 10:08:03 +02:00
parent 1449a73d2c
commit cdb4bc2d69
32 changed files with 604 additions and 353 deletions

View file

@ -0,0 +1,13 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="4" y_dim="1">
<label id="equip" x_slot="0" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Equip</label>
<label id="upgrade" x_slot="1" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Upgrade</label>
<label id="salvage" x_slot="2" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Salvage</label>
<label id="switch_mode" x_slot="3" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Switch</label>
</grid>
</root>

View file

@ -0,0 +1,11 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="3" y_dim="1">
<label id="socket" x_slot="0" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Socket</label>
<label id="salvage" x_slot="1" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Salvage</label>
<label id="switch_mode" x_slot="2" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Switch</label>
</grid>
</root>

View file

@ -0,0 +1,9 @@
<root>
<grid x_dim="1" y_dim="1" padding="2">
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1" background="#919191">
<icon id="addon_icon" x_slot="0" y_slot="0"></icon>
<label id="addon_type" x_slot="1" y_slot="0" x_size="3" text_color="black" text_alignment="left">StatType</label>
<label id="addon_value" x_slot="4" y_slot="0" x_size="2" text_color="black">StatValue</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,8 @@
<root>
<grid x_dim="1" y_dim="1" padding="2">
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1" background="#919191">
<icon x_slot="0" y_slot="0" icon="textures/abilities/circle.png"></icon>
<label id="info" x_slot="1" y_slot="0" x_size="3" text_color="black"></label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,16 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="1" y_dim="10" margin="4" padding="4"
background='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'>
<grid x_slot="0" y_slot="0" x_dim="6" y_dim="1"
button_normal='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'
button_selected='{"background_color":"#835219","border_color":"#c37417","border_thickness":{"Pixel":5}}'>
<button id="abilities" x_slot="1" y_slot="0" x_size="2" text_color="black">Abilities</button>
<button id="addons" x_slot="3" y_slot="0" x_size="2" text_color="black">Addons</button>
</grid>
<grid id="content" x_slot="0" y_slot="1" x_dim="1" y_dim="1" y_size="8"></grid>
<grid id="tooltip" x_slot="0" y_slot="9" x_dim="1" y_dim="1"></grid>
</grid>
</root>

View file

@ -0,0 +1,35 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="1" y_dim="10" padding="5" margin="5"
background='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'
button_normal='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'
button_selected='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'>
<grid x_slot="0" y_slot="0" x_dim="1" y_dim="9" y_size="9" padding="0" margin="0">
<grid x_slot="0" y_slot="0" x_dim="4" y_dim="1" padding="0" margin="0">
<button id="first_ability" x_slot="0" y_slot="0" fill_type="square" select_mode="none">0</button>
<button id="second_ability" x_slot="1" y_slot="0" fill_type="square" select_mode="none">0</button>
<button id="third_ability" x_slot="2" y_slot="0" fill_type="square" select_mode="none">0</button>
<button id="fourth_ability" x_slot="3" y_slot="0" fill_type="square" select_mode="none">0</button>
</grid>
<grid id="ability_content" x_slot="0" y_slot="1" x_dim="1" y_dim="8" y_size="8"
background='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'></grid>
</grid>
<grid x_slot="0" y_slot="9" x_dim="6" y_dim="1"
background='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'>
<icon id="common" x_slot="0" y_slot="0" fill_type="square"
background='{"background_color":"white","border_color":"black","border_thickness":{"Pixel":2}}'>0</icon>
<icon id="uncommon" x_slot="1" y_slot="0" fill_type="square"
background='{"background_color":"white","border_color":"black","border_thickness":{"Pixel":2}}'>0</icon>
<icon id="magical" x_slot="2" y_slot="0" fill_type="square"
background='{"background_color":"white","border_color":"black","border_thickness":{"Pixel":2}}'>0</icon>
<icon id="rare" x_slot="3" y_slot="0" fill_type="square"
background='{"background_color":"white","border_color":"black","border_thickness":{"Pixel":2}}'>0</icon>
<icon id="epic" x_slot="4" y_slot="0" fill_type="square"
background='{"background_color":"white","border_color":"black","border_thickness":{"Pixel":2}}'>0</icon>
<icon id="legendary" x_slot="5" y_slot="0" fill_type="square"
background='{"background_color":"white","border_color":"black","border_thickness":{"Pixel":2}}'>0</icon>
</grid>
</grid>
</root>

View file

@ -0,0 +1,14 @@
<?xml-model href="../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="1" y_dim="7" margin="0" padding="0">
<grid x_slot="0" y_slot="0" x_dim="3" y_dim="1"
button_normal='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'
button_selected='{"background_color":"#835219","border_color":"#c37417","border_thickness":{"Pixel":5}}'>
<button id="left" x_slot="0" y_slot="0" text_color="black" isolate="true">prev</button>
<label id="tab_info" x_slot="1" y_slot="0" text_color="black">1 / 1</label>
<button id="right" x_slot="2" y_slot="0" text_color="black" isolate="true">next</button>
</grid>
<grid id="content" x_slot="0" y_slot="1" x_dim="4" y_dim="4" y_size="6"></grid>
</grid>
</root>

View file

@ -0,0 +1,8 @@
<?xml-model href="../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="1" y_dim="1" margin="0" padding="0"
button_normal='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":0}}'
button_selected='{"background_color":"#bd7000","border_color":"#c37417","border_thickness":{"Pixel":0}}'>
<button id="button" x_slot="0" y_slot="0" select_mode="none" fill_type="square"></button>
</grid>
</root>

View file

@ -0,0 +1,45 @@
<?xml-model href="../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root reference_width="1280" reference_height="720" layer="10">
<grid x_dim="2" y_dim="1" x_offset="-400" y_offset="-240" width="800" height="540" vert_align="middle" hori_align="middle" background="#919191" padding="10">
<grid id="inventory" x_slot="0" y_slot="0" x_dim="1" y_dim="8" background="#aaaaaa" padding="2" margin="2">
<grid x_slot="0" y_slot="0" x_dim="3" y_dim="1" background="#919191" button_normal="#919191" button_selected="#919191">
<button id="left" x_slot="0" y_slot="0" select_mode="none"></button>
<label id="tab_info" x_slot="1" y_slot="0" text_color="black" text_ratio="0.5">1 / 1</label>
<button id="right" x_slot="2" y_slot="0" select_mode="none"></button>
</grid>
</grid>
<grid id="equipment" x_slot="1" y_slot="0" x_dim="3" y_dim="5" background="#aaaaaa" button_normal="#aaaaaa" button_selected="#919191" padding="2">
<!-- amulets -->
<button id="amulet_0" x_slot="0" y_slot="0" icon="textures/items/amulet_placeholder.png" icon_margin="5" select_mode="none"></button>
<button id="amulet_1" x_slot="2" y_slot="0" icon="textures/items/amulet_placeholder.png" icon_margin="5" select_mode="none"></button>
<!-- helmet -->
<button id="helmet" x_slot="1" y_slot="0" icon="textures/items/helmet_placeholder.png" icon_margin="5" select_mode="none"></button>
<!-- chest plate -->
<button id="chest" x_slot="1" y_slot="1" icon="textures/items/chest_placeholder.png" icon_margin="5" select_mode="none"></button>
<!-- gloves -->
<button id="gloves" x_slot="0" y_slot="1" icon="textures/items/gloves_placeholder.png" icon_margin="5" select_mode="none"></button>
<!-- belt -->
<button id="belt" x_slot="1" y_slot="2" icon="textures/items/belt_placeholder.png" icon_margin="5" select_mode="none"></button>
<!-- boots -->
<button id="boots" x_slot="1" y_slot="4" icon="textures/items/boots_placeholder.png" icon_margin="5" select_mode="none"></button>
<!-- main hand -->
<button id="main hand" x_slot="0" y_slot="4" icon="textures/items/sword_placeholder.png" icon_margin="5" select_mode="none"></button>
<!-- off hand -->
<button id="off hand" x_slot="2" y_slot="4" icon="textures/items/shield_placeholder.png" icon_margin="5" select_mode="none"></button>
<!-- rings -->
<button id="ring_0" x_slot="0" y_slot="2" icon="textures/items/ring_placeholder.png" icon_margin="5" select_mode="none"></button>
<button id="ring_1" x_slot="2" y_slot="2" icon="textures/items/ring_placeholder.png" icon_margin="5" select_mode="none"></button>
<button id="ring_2" x_slot="0" y_slot="3" icon="textures/items/ring_placeholder.png" icon_margin="5" select_mode="none"></button>
<button id="ring_3" x_slot="2" y_slot="3" icon="textures/items/ring_placeholder.png" icon_margin="5" select_mode="none"></button>
</grid>
</grid>
</root>

View file

@ -0,0 +1,38 @@
<?xml-model href="../../../../../../gui.xsd" type="application/xml" schematypes="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid id="equipment" x_dim="3" y_dim="5" padding="7" margin="5"
background='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'
button_normal='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'
button_selected='{"background_color":"#6c440b","border_color":"#543919","border_thickness":{"Pixel":2}}'>
<!-- amulets -->
<button id="amulet_0" x_slot="0" y_slot="0" icon="textures/items/amulet_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<button id="amulet_1" x_slot="2" y_slot="0" icon="textures/items/amulet_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<!-- helmet -->
<button id="helmet" x_slot="1" y_slot="0" icon="textures/items/helmet_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<!-- chest plate -->
<button id="chest" x_slot="1" y_slot="1" icon="textures/items/chest_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<!-- gloves -->
<button id="gloves" x_slot="0" y_slot="1" icon="textures/items/gloves_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<!-- belt -->
<button id="belt" x_slot="1" y_slot="2" icon="textures/items/belt_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<!-- boots -->
<button id="boots" x_slot="1" y_slot="4" icon="textures/items/boots_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<!-- main hand -->
<button id="main hand" x_slot="0" y_slot="4" icon="textures/items/sword_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<!-- off hand -->
<button id="off hand" x_slot="2" y_slot="4" icon="textures/items/shield_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<!-- rings -->
<button id="ring_0" x_slot="0" y_slot="2" icon="textures/items/ring_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<button id="ring_1" x_slot="2" y_slot="2" icon="textures/items/ring_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<button id="ring_2" x_slot="0" y_slot="3" icon="textures/items/ring_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
<button id="ring_3" x_slot="2" y_slot="3" icon="textures/items/ring_placeholder.png" icon_margin="5" fill_type="square" select_mode="none"></button>
</grid>
</root>

View file

@ -0,0 +1,13 @@
<?xml-model href="../../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="4" y_dim="1">
<label id="equip" x_slot="0" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Equip</label>
<label id="salvage" x_slot="1" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Salvage</label>
<label id="socket" x_slot="2" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Socket</label>
<label id="switch_mode" x_slot="3" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Switch</label>
</grid>
</root>

View file

@ -0,0 +1,23 @@
<?xml-model href="../../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="1" y_dim="10" padding="5" margin="5"
background='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'
button_normal='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'
button_selected='{"background_color":"#c47503","border_color":"#543919","border_thickness":{"Pixel":2}}'>
<grid x_slot="0" y_slot="0" x_dim="5" y_dim="5" y_size="9">
<button id="reference" x_slot="2" y_slot="1" fill_type="square"></button>
<button id="first" x_slot="1" y_slot="3" fill_type="square"></button>
<button id="second" x_slot="2" y_slot="3" fill_type="square"></button>
<button id="third" x_slot="3" y_slot="3" fill_type="square"></button>
</grid>
<grid x_slot="0" y_slot="9" x_dim="3" y_dim="1">
<label id="combine" x_slot="1" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Combine</label>
</grid>
</grid>
</root>

View file

@ -0,0 +1,11 @@
<?xml-model href="../../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="3" y_dim="1">
<label id="socket" x_slot="0" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Socket</label>
<label id="combine" x_slot="1" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Combine</label>
<label id="switch_mode" x_slot="2" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Switch</label>
</grid>
</root>

View file

@ -0,0 +1,17 @@
<?xml-model href="../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="1" y_dim="10" margin="4" padding="4"
background='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'>
<grid x_slot="0" y_slot="0" x_dim="3" y_dim="1"
button_normal='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'
button_selected='{"background_color":"#835219","border_color":"#c37417","border_thickness":{"Pixel":5}}'>
<button id="items" x_slot="0" y_slot="0" text_color="black" isolate="true">Items</button>
<button id="jewels" x_slot="1" y_slot="0" text_color="black" isolate="true">Jewels</button>
<button id="maps" x_slot="2" y_slot="0" text_color="black" isolate="true">Maps</button>
</grid>
<grid id="content" x_slot="0" y_slot="1" x_dim="1" y_dim="1" y_size="8"></grid>
<grid id="tooltip" x_slot="0" y_slot="9" x_dim="1" y_dim="1"></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="1" y_dim="1"
background='{"background_color":"#945b09","border_color":"#543919","border_thickness":{"Pixel":2}}'>
<label x_slot="0" y_slot="0" text_color="black">work in progress</label>
</grid>
</root>

View file

@ -0,0 +1,11 @@
<?xml-model href="../../../../../../gui.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<root>
<grid x_dim="3" y_dim="1">
<label id="select" x_slot="0" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Select</label>
<label id="start" x_slot="1" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Start</label>
<label id="switch_mode" x_slot="2" y_slot="0" text_color="black"
background='{"background_color":"#835219","border_color":"#543919","border_thickness":{"Pixel":5}}'>Switch</label>
</grid>
</root>

View file

@ -0,0 +1,15 @@
<root>
<!-- loot slot -->
<grid x_dim="1" y_dim="1" padding="5">
<grid id="snippet_grid" x_slot="0" y_slot="0" x_dim="5" y_dim="1" background="#919191" button_normal="#919191" button_selected="#aaaaaa" margin="0">
<button id="item_icon" x_slot="0" y_slot="0" select_mode="none"></button>
<!-- stats -->
<label id="strength_info" x_slot="1" y_slot="0" text_ratio="0.7" text_color="#C23519">0</label>
<label id="agility_info" x_slot="2" y_slot="0" text_ratio="0.7" text_color="#65D01E">0</label>
<label id="intelligence_info" x_slot="3" y_slot="0" text_ratio="0.7" text_color="#1D63B3">0</label>
<button id="disassemble" x_slot="4" y_slot="0" icon="textures/icons/crafting.png" select_mode="none"></button>
</grid>
</grid>
</root>

View file

@ -25,15 +25,16 @@ impl AbilityPageRightSide {
];
pub fn new(
game_handle: &GameHandle,
engine: &Arc<Engine>,
reference: &Weak<CharacterWindow>,
hero: Entity,
) -> Result<Self> {
let snippet =
game_handle.gui_snippet("gui/xml/ingame/character_menu/abilities/right_side.xml")?;
let snippet = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/abilities/right_side.xml"),
)?;
let game = game_handle.upgrade();
let color_settings = &game.item_settings.rarity_color_settings;
let color_settings = &engine.item_settings.rarity_color_settings;
Self::rarity_icon_background(&snippet, "common", color_settings.common)?;
Self::rarity_icon_background(&snippet, "uncommon", color_settings.uncommon)?;
@ -45,7 +46,7 @@ impl AbilityPageRightSide {
for (index, name) in Self::ABILITY_BUTTON_NAMES.iter().enumerate() {
let button: Arc<Button> = snippet.element(name)?;
button.set_info_icon(&game_handle.controller_icon(ControllerButton::RightStick)?)?;
button.set_info_icon(&engine.controller_icon(ControllerButton::RightStick)?)?;
button.set_callback({
let reference = reference.clone();
@ -64,14 +65,14 @@ impl AbilityPageRightSide {
});
button.set_select_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
let weak_button = Arc::downgrade(&button);
move |selected| {
if let Some(menu) = reference.upgrade() {
if selected {
game_handle.upgrade().engine().on_scene(|scene| {
engine.on_scene(|scene| {
let entity = scene.entity(hero)?;
let abilities = entity.get_component::<AbilitySlots>()?;
@ -85,7 +86,7 @@ impl AbilityPageRightSide {
let statistics = entity.get_component::<Statistics>()?;
let gui = book.create_tooltip(
&game_handle,
engine.gui_handler(),
statistics,
(target_x, target_y),
)?;
@ -107,12 +108,12 @@ impl AbilityPageRightSide {
});
button.set_custom_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move |button| match button {
ControllerButton::Y => {
game_handle.upgrade().engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
let entity = scene.entity_mut(hero)?;
let mut multi_mut = entity.multi_mut();
@ -127,7 +128,7 @@ impl AbilityPageRightSide {
menu.tabs_mut()
.abilities()
.right_side
.refresh(&game_handle, hero)?;
.refresh(&engine, hero)?;
}
}
@ -183,11 +184,7 @@ impl AbilityPageRightSide {
Ok(())
}
fn update_active_ability(
&self,
game_handle: &GameHandle,
abilities: &AbilitySlots,
) -> Result<()> {
fn update_active_ability(&self, engine: &Engine, abilities: &AbilitySlots) -> Result<()> {
let grid: Arc<Grid> = self.snippet.element("ability_content")?;
let (_, rows) = grid.dimensions();
@ -199,8 +196,9 @@ impl AbilityPageRightSide {
for (index, addon) in ability.addons().iter().enumerate() {
match addon.as_ref() {
Some(addon) => {
let addon_type_snippet = game_handle.gui_snippet(
"gui/xml/ingame/character_menu/abilities/addon_type_snippet.xml",
let addon_type_snippet = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/abilities/addon_type_snippet.xml"),
)?;
let addon_icon: Arc<Icon> = addon_type_snippet.element("addon_icon")?;
@ -214,8 +212,9 @@ impl AbilityPageRightSide {
grid.attach(addon_type_snippet, 0, index, 1, 1)?;
}
None => {
let empty_addon = game_handle.gui_snippet(
"gui/xml/ingame/character_menu/abilities/empty_addon_snippet.xml",
let empty_addon = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/abilities/empty_addon_snippet.xml"),
)?;
grid.attach(empty_addon, 0, index, 1, 1)?;
@ -227,15 +226,15 @@ impl AbilityPageRightSide {
Ok(())
}
pub fn next_ability(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
pub fn next_ability(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()> {
self.ability_index = (self.ability_index + 1) % 4;
self.refresh(game_handle, hero)
self.refresh(engine, hero)
}
}
impl RightSide for AbilityPageRightSide {
fn refresh(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
game_handle.upgrade().engine().on_scene(|scene| {
fn refresh(&mut self, engine: &Engine, hero: Entity) -> Result<()> {
engine.on_scene(|scene| {
let entity = scene.entity(hero)?;
let crafting = entity.get_component::<CraftingMaterials>()?;
@ -253,7 +252,7 @@ impl RightSide for AbilityPageRightSide {
self.update_ability_icon(name, abilities.book(index).map(|book| book.icon()))?;
}
self.update_active_ability(game_handle, abilities)?;
self.update_active_ability(engine, abilities)?;
Ok(())
})

View file

@ -17,13 +17,13 @@ use super::AbilityPage;
impl Content<AbilityAddon> {
fn show_addon_tooltip(
game_handle: &GameHandle,
engine: &Arc<Engine>,
hero: Entity,
addon_index: usize,
reference: &Weak<CharacterWindow>,
(x, y, w, _h): (i32, i32, u32, u32),
) -> Result<()> {
game_handle.upgrade().engine().on_scene(|scene| {
engine.on_scene(|scene| {
let entity = scene.entity(hero)?;
let inventory = entity.get_component::<Inventory>()?;
@ -31,7 +31,7 @@ impl Content<AbilityAddon> {
let target_y = y;
let addon = inventory.addon_at(addon_index);
let gui = addon.create_tooltip(game_handle, (target_x, target_y))?;
let gui = addon.create_tooltip(engine.gui_handler(), (target_x, target_y))?;
gui.enable()?;
gui.perform_single_check(x, y)?;
@ -43,12 +43,12 @@ impl Content<AbilityAddon> {
}
fn insert_addon(
game_handle: &GameHandle,
engine: &Arc<Engine>,
hero: Entity,
addon_index: usize,
ability_page: &AbilityPage,
) -> Result<()> {
game_handle.upgrade().engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
let entity = scene.entity_mut(hero)?;
let mut multi_mut = entity.multi_mut();
@ -68,21 +68,19 @@ impl Content<AbilityAddon> {
}
impl ContentUpdate for Content<AbilityAddon> {
fn update(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
fn update(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()> {
let reference = self.reference.clone();
self.update_base(game_handle, |button, t, index| {
self.update_base(engine, |button, t, index| {
button.set_icon(&t.icon())?;
button.set_custom_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move |controller_button| {
if let ControllerButton::X = controller_button {
let game = game_handle.upgrade();
CharacterWindow::salvage_from_inventory(&game, hero, |inventory| {
CharacterWindow::salvage_from_inventory(&engine, hero, |inventory| {
inventory.remove_addon(index)
})?;
@ -101,7 +99,7 @@ impl ContentUpdate for Content<AbilityAddon> {
});
button.set_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move || {
@ -109,7 +107,7 @@ impl ContentUpdate for Content<AbilityAddon> {
let mut tabs = menu.tabs_mut();
let abilities = tabs.abilities();
Self::insert_addon(&game_handle, hero, index, abilities)?;
Self::insert_addon(&engine, hero, index, abilities)?;
abilities.update_page()?;
}
@ -120,20 +118,14 @@ impl ContentUpdate for Content<AbilityAddon> {
button.set_select_callback({
let weak_button = Arc::downgrade(&button);
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move |selected| {
if selected {
let button_pos = weak_button.upgrade().unwrap().position_extent();
Self::show_addon_tooltip(
&game_handle,
hero,
index,
&reference,
button_pos,
)?;
Self::show_addon_tooltip(&engine, hero, index, &reference, button_pos)?;
} else {
let window = reference.upgrade().unwrap();
@ -155,12 +147,12 @@ impl ContentUpdate for Content<AbilityAddon> {
impl Content<AbilityBook> {
fn equip_book(
game_handle: &GameHandle,
engine: &Arc<Engine>,
hero: Entity,
book_index: usize,
ability_page: &AbilityPage,
) -> Result<()> {
game_handle.upgrade().engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
let entity = scene.entity_mut(hero)?;
let mut multi_mut = entity.multi_mut();
@ -179,13 +171,13 @@ impl Content<AbilityBook> {
}
fn show_book_tooltip(
game_handle: &GameHandle,
engine: &Arc<Engine>,
hero: Entity,
book_index: usize,
reference: &Weak<CharacterWindow>,
(x, y, w, _h): (i32, i32, u32, u32),
) -> Result<()> {
game_handle.upgrade().engine().on_scene(|scene| {
engine.on_scene(|scene| {
let entity = scene.entity(hero)?;
let inventory = entity.get_component::<Inventory>()?;
let statistics = entity.get_component::<Statistics>()?;
@ -194,7 +186,8 @@ impl Content<AbilityBook> {
let target_y = y;
let book = inventory.book_at(book_index);
let gui = book.create_tooltip(game_handle, statistics, (target_x, target_y))?;
let gui =
book.create_tooltip(engine.gui_handler(), statistics, (target_x, target_y))?;
gui.enable()?;
let window = reference.upgrade().unwrap();
@ -208,7 +201,7 @@ impl Content<AbilityBook> {
let target_y = button_pos.1;
let compare_gui = selected_book.create_tooltip(
game_handle,
engine.gui_handler(),
statistics,
(target_x, target_y),
)?;
@ -230,21 +223,19 @@ impl Content<AbilityBook> {
}
impl ContentUpdate for Content<AbilityBook> {
fn update(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
fn update(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()> {
let reference = self.reference.clone();
self.update_base(game_handle, |button, t, index| {
self.update_base(engine, |button, t, index| {
button.set_icon(&t.icon())?;
button.set_custom_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move |controller_button| {
if let ControllerButton::X = controller_button {
let game = game_handle.upgrade();
CharacterWindow::salvage_from_inventory(&game, hero, |inventory| {
CharacterWindow::salvage_from_inventory(&engine, hero, |inventory| {
inventory.remove_book(index)
})?;
@ -263,7 +254,7 @@ impl ContentUpdate for Content<AbilityBook> {
});
button.set_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move || {
@ -271,7 +262,7 @@ impl ContentUpdate for Content<AbilityBook> {
let mut tabs = menu.tabs_mut();
let abilities = tabs.abilities();
Self::equip_book(&game_handle, hero, index, abilities)?;
Self::equip_book(&engine, hero, index, abilities)?;
abilities.update_page()?;
}
@ -282,14 +273,14 @@ impl ContentUpdate for Content<AbilityBook> {
button.set_select_callback({
let weak_button = Arc::downgrade(&button);
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move |selected| {
if selected {
let button_pos = weak_button.upgrade().unwrap().position_extent();
Self::show_book_tooltip(&game_handle, hero, index, &reference, button_pos)?;
Self::show_book_tooltip(&engine, hero, index, &reference, button_pos)?;
} else {
let window = reference.upgrade().unwrap();

View file

@ -19,7 +19,7 @@ use crate::*;
pub struct AbilityPage {
close: Weak<Button>,
game_handle: GameHandle,
engine: Arc<Engine>,
hero: Entity,
grid: Arc<Grid>,
@ -36,16 +36,17 @@ pub struct AbilityPage {
impl AbilityPage {
pub fn new(
game: GameHandle,
engine: &Arc<Engine>,
hero: Entity,
reference: Weak<CharacterWindow>,
close: &Arc<Button>,
) -> Result<Self> {
let base = "gui/xml/ingame/character_menu/abilities/".to_string();
let grid = Grid::new(engine.gui_handler().clone(), 2, 1, false)?;
let grid = Grid::new(game.upgrade().engine().gui_handler().clone(), 2, 1, false)?;
let left_base = game.gui_snippet((base.clone() + "left_side.xml").as_str())?;
let left_base = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/abilities/left_side.xml"),
)?;
grid.attach(left_base.clone(), 0, 0, 1, 1)?;
Self::setup_content_switch(&left_base, reference.clone())?;
@ -55,15 +56,14 @@ impl AbilityPage {
// abilities
let ability_mode = PageContent::new(
Content::new(&game, reference.clone(), {
let game_handle = game.clone();
Content::new(&engine, reference.clone(), {
let engine = engine.clone();
let hero = hero.clone();
move || {
let game = game_handle.upgrade();
let mut data = Vec::new();
game.engine().on_scene(|scene| {
engine.on_scene(|scene| {
let hero_object = scene.entity(hero)?;
let inventory = hero_object.get_component::<Inventory>()?;
@ -76,19 +76,22 @@ impl AbilityPage {
}
})?,
{
let ui = game.gui_snippet((base.clone() + "ability_tooltip.xml").as_str())?;
let ui = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/abilities/ability_tooltip.xml"),
)?;
let equip: Arc<Label> = ui.element("equip")?;
equip.set_info_icon(&game.controller_icon(ControllerButton::A)?)?;
equip.set_info_icon(&engine.controller_icon(ControllerButton::A)?)?;
let upgrade: Arc<Label> = ui.element("upgrade")?;
upgrade.set_info_icon(&game.controller_icon(ControllerButton::Y)?)?;
upgrade.set_info_icon(&engine.controller_icon(ControllerButton::Y)?)?;
let salvage: Arc<Label> = ui.element("salvage")?;
salvage.set_info_icon(&game.controller_icon(ControllerButton::X)?)?;
salvage.set_info_icon(&engine.controller_icon(ControllerButton::X)?)?;
let switch_mode: Arc<Label> = ui.element("switch_mode")?;
switch_mode.set_info_icon(&game.controller_icon(ControllerButton::LeftStick)?)?;
switch_mode.set_info_icon(&engine.controller_icon(ControllerButton::LeftStick)?)?;
ui
},
@ -97,15 +100,14 @@ impl AbilityPage {
// addons
let addons_mode = PageContent::new(
Content::new(&game, reference.clone(), {
let game_handle = game.clone();
Content::new(&engine, reference.clone(), {
let engine = engine.clone();
let hero = hero.clone();
move || {
let game = game_handle.upgrade();
let mut data = Vec::new();
game.engine().on_scene(|scene| {
engine.on_scene(|scene| {
let hero_object = scene.entity(hero)?;
let inventory = hero_object.get_component::<Inventory>()?;
@ -118,28 +120,31 @@ impl AbilityPage {
}
})?,
{
let ui = game.gui_snippet((base.clone() + "addon_tooltip.xml").as_str())?;
let ui = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/abilities/addon_tooltip.xml"),
)?;
let equip: Arc<Label> = ui.element("socket")?;
equip.set_info_icon(&game.controller_icon(ControllerButton::A)?)?;
equip.set_info_icon(&engine.controller_icon(ControllerButton::A)?)?;
let salvage: Arc<Label> = ui.element("salvage")?;
salvage.set_info_icon(&game.controller_icon(ControllerButton::X)?)?;
salvage.set_info_icon(&engine.controller_icon(ControllerButton::X)?)?;
let switch_mode: Arc<Label> = ui.element("switch_mode")?;
switch_mode.set_info_icon(&game.controller_icon(ControllerButton::LeftStick)?)?;
switch_mode.set_info_icon(&engine.controller_icon(ControllerButton::LeftStick)?)?;
ui
},
EmptyRightSide,
);
let right_side = AbilityPageRightSide::new(&game, &reference, hero)?;
let right_side = AbilityPageRightSide::new(&engine, &reference, hero)?;
Ok(Self {
close: Arc::downgrade(close),
game_handle: game,
engine: engine.clone(),
hero,
grid,
@ -164,13 +169,13 @@ impl AbilityPage {
}
let mode = &mut self.modes[self.current_mode];
mode.content_mut().update(&self.game_handle, self.hero)?;
mode.content_mut().update(&self.engine, self.hero)?;
self.tooltip.attach(mode.tooltip().clone(), 0, 0, 1, 1)?;
self.content
.attach(mode.content_mut().base().clone(), 0, 0, 1, 1)?;
self.right_side.refresh(&self.game_handle, self.hero)?;
self.right_side.refresh(&self.engine, self.hero)?;
self.grid
.attach(self.right_side.base().clone(), 1, 0, 1, 1)?;
@ -252,13 +257,13 @@ impl Page for AbilityPage {
fn next_tab(&mut self) -> Result<()> {
self.modes[self.current_mode]
.content_mut()
.next_tab(&self.game_handle, self.hero)
.next_tab(&self.engine, self.hero)
}
fn previous_tab(&mut self) -> Result<()> {
self.modes[self.current_mode]
.content_mut()
.previous_tab(&self.game_handle, self.hero)
.previous_tab(&self.engine, self.hero)
}
fn event(&mut self, button: ControllerButton) -> Result<bool> {
@ -271,7 +276,7 @@ impl Page for AbilityPage {
}
ControllerButton::RightStick => {
self.right_side.next_ability(&self.game_handle, self.hero)?;
self.right_side.next_ability(&self.engine, self.hero)?;
true
}

View file

@ -28,7 +28,7 @@ impl CharacterPage {
) -> Result<Self> {
let snippet = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/statistics.xml"),
include_str!("../../resources/character/statistics.xml"),
)?;
let grid: Arc<Grid> = snippet.element("statistic_tab")?;
@ -38,7 +38,7 @@ impl CharacterPage {
let strength: Arc<Button> = snippet.element("strength_field")?;
strength.set_callback({
let update_stats = Self::create_update_stats(hero, game_handle, reference);
let update_stats = Self::create_update_stats(hero, engine, reference);
move || {
update_stats(|attributes| {
@ -49,7 +49,7 @@ impl CharacterPage {
let agility: Arc<Button> = snippet.element("agility_field")?;
agility.set_callback({
let update_stats = Self::create_update_stats(hero, game_handle, reference);
let update_stats = Self::create_update_stats(hero, engine, reference);
move || {
update_stats(|attributes| {
@ -60,7 +60,7 @@ impl CharacterPage {
let intelligence: Arc<Button> = snippet.element("intelligence_field")?;
intelligence.set_callback({
let update_stats = Self::create_update_stats(hero, game_handle, reference);
let update_stats = Self::create_update_stats(hero, engine, reference);
move || {
update_stats(|attributes| {
@ -70,7 +70,7 @@ impl CharacterPage {
});
Ok(Self {
engine,
engine: engine.clone(),
hero,
snippet,
@ -156,7 +156,7 @@ impl CharacterPage {
attributes_label.set_text(format!(
"Attributes ({})",
Self::available_attribute_points(&game, attributes, level)
Self::available_attribute_points(&self.engine, attributes, level)
))?;
strength.set_text(attributes.strength().raw())?;
@ -167,7 +167,11 @@ impl CharacterPage {
})
}
fn available_attribute_points(game: &Game, attributes: &Attributes, level: &Level) -> u32 {
fn available_attribute_points(
engine: &Arc<Engine>,
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();
@ -198,13 +202,13 @@ impl CharacterPage {
let level = multi_mut.get::<Level>()?;
let attributes = multi_mut.get::<Attributes>()?;
if Self::available_attribute_points(&game, attributes, level) > 0 {
if Self::available_attribute_points(&engine, attributes, level) > 0 {
upgrade(attributes);
let statistics = multi_mut.get::<Statistics>()?;
let items = multi_mut.get::<ItemSlotContainer>()?;
statistics.update(attributes, &game.attribute_settings, &*items);
statistics.update(attributes, &engine.attribute_settings, &*items);
upgraded = true;
}

View file

@ -4,14 +4,14 @@ use crate::*;
pub trait ContentWrapper: ContentUpdate + Send + Sync {
fn refresh(&mut self) -> Result<()>;
fn next_tab(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()>;
fn previous_tab(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()>;
fn next_tab(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()>;
fn previous_tab(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()>;
fn base(&self) -> &Arc<GuiSnippet>;
fn is_empty(&self) -> bool;
}
pub trait ContentUpdate {
fn update(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()>;
fn update(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()>;
fn select(&self) -> Result<()>;
}
@ -27,18 +27,25 @@ pub struct Content<T: Send + Sync> {
}
impl<T: Send + Sync> Content<T> {
pub fn new<F>(game: &GameHandle, reference: Weak<CharacterWindow>, on_enable: F) -> Result<Self>
pub fn new<F>(
engine: &Arc<Engine>,
reference: Weak<CharacterWindow>,
on_enable: F,
) -> Result<Self>
where
F: Fn() -> Result<Vec<T>> + Send + Sync + 'static,
{
let base = game.gui_snippet("gui/xml/ingame/character_menu/content.xml")?;
let base = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../resources/content.xml"),
)?;
let left: Arc<Button> = base.element("left")?;
left.set_text("<")?;
left.set_info_icon(&game.controller_icon(ControllerButton::LeftTrigger)?)?;
left.set_info_icon(&engine.controller_icon(ControllerButton::LeftTrigger)?)?;
let right: Arc<Button> = base.element("right")?;
right.set_text(">")?;
right.set_info_icon(&game.controller_icon(ControllerButton::RightTrigger)?)?;
right.set_info_icon(&engine.controller_icon(ControllerButton::RightTrigger)?)?;
Ok(Self {
reference,
@ -68,7 +75,7 @@ impl<T: Send + Sync> Content<T> {
label.set_text(format!("{} / {}", self.page + 1, self.pages))
}
pub fn update_base<F>(&mut self, game_handle: &GameHandle, setup: F) -> Result<()>
pub fn update_base<F>(&mut self, engine: &Arc<Engine>, setup: F) -> Result<()>
where
Self: ContentWrapper,
F: Fn(&Arc<Button>, &T, usize) -> Result<()>,
@ -89,8 +96,10 @@ impl<T: Send + Sync> Content<T> {
match self.data.get(index) {
Some(t) => {
let snippet = game_handle
.gui_snippet("gui/xml/ingame/character_menu/content_button.xml")?;
let snippet = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../resources/content_button.xml"),
)?;
let button: Arc<Button> = snippet.element("button")?;
setup(&button, t, index)?;
@ -130,19 +139,19 @@ where
Ok(())
}
fn next_tab(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
fn next_tab(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()> {
if self.page < (self.pages - 1) {
self.page += 1;
self.update(game_handle, hero)?;
self.update(engine, hero)?;
}
Ok(())
}
fn previous_tab(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
fn previous_tab(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()> {
if self.page > 0 {
self.page -= 1;
self.update(game_handle, hero)?;
self.update(engine, hero)?;
}
Ok(())

View file

@ -16,8 +16,8 @@ use crate::{
use super::jewel_right_side::{LowerJewels, ReferenceItemSource, ReferenceObject};
impl Content<Item> {
fn salvage_item(game: &Game, hero: Entity, item_index: usize) -> Result<()> {
CharacterWindow::salvage_from_inventory(game, hero, |inventory| {
fn salvage_item(engine: &Arc<Engine>, hero: Entity, item_index: usize) -> Result<()> {
CharacterWindow::salvage_from_inventory(engine, hero, |inventory| {
let mut item = inventory.remove_item(item_index);
// unsocket jewels and add them into inventory
@ -35,10 +35,10 @@ impl Content<Item> {
})
}
fn select_to_socket(game: &Game, hero: Entity, item_index: usize) -> Result<bool> {
fn select_to_socket(engine: &Arc<Engine>, hero: Entity, item_index: usize) -> Result<bool> {
let mut has_empty_sockets = true;
game.engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
let entity = scene.entity(hero)?;
let inventory = entity.get_component::<Inventory>()?;
let item = inventory.item_at(item_index).clone();
@ -66,8 +66,8 @@ impl Content<Item> {
Ok(has_empty_sockets)
}
fn equip_item(game: &Game, hero: Entity, item_index: usize) -> Result<()> {
game.engine().on_scene_mut(|scene| {
fn equip_item(engine: &Arc<Engine>, hero: Entity, item_index: usize) -> Result<()> {
engine.on_scene_mut(|scene| {
let entity = scene.entity_mut(hero)?;
let mut multi_mut = entity.multi_mut();
@ -87,20 +87,20 @@ impl Content<Item> {
// update hero stats
let statistics = multi_mut.get::<Statistics>()?;
statistics.update(attributes, &game.attribute_settings, &*hero_items);
statistics.update(attributes, &engine.attribute_settings, &*hero_items);
Ok(())
})
}
fn show_item_tooltip(
game_handle: &GameHandle,
engine: &Arc<Engine>,
hero: Entity,
item_index: usize,
reference: &Weak<CharacterWindow>,
(x, y, w, _h): (i32, i32, u32, u32),
) -> Result<()> {
game_handle.upgrade().engine().on_scene(|scene| {
engine.on_scene(|scene| {
let entity = scene.entity(hero)?;
let inventory = entity.get_component::<Inventory>()?;
@ -110,7 +110,8 @@ impl Content<Item> {
let target_y = y;
let item = inventory.item_at(item_index);
let gui = item.create_tooltip(game_handle, attributes, (target_x, target_y))?;
let gui =
item.create_tooltip(engine.gui_handler(), attributes, (target_x, target_y))?;
gui.enable()?;
let window = reference.upgrade().unwrap();
@ -124,8 +125,11 @@ impl Content<Item> {
let start_x = grid_pos.0 + grid_pos.2 as i32 + spacing;
let start_y = grid_pos.1;
let compare_gui =
equipped.create_tooltip(game_handle, attributes, (start_x, start_y))?;
let compare_gui = equipped.create_tooltip(
engine.gui_handler(),
attributes,
(start_x, start_y),
)?;
compare_gui.enable()?;
gui.perform_double_check(&compare_gui, x, spacing as u32)?;
@ -146,22 +150,20 @@ impl Content<Item> {
}
impl ContentUpdate for Content<Item> {
fn update(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
fn update(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()> {
let reference = self.reference.clone();
self.update_base(game_handle, |button, t, index| {
self.update_base(engine, |button, t, index| {
button.set_icon(&t.icon)?;
button.set_custom_callback({
let game_handle = game_handle.clone();
let reference = reference.clone();
let engine = engine.clone();
move |controller_button| {
Ok(match controller_button {
ControllerButton::X => {
let game = game_handle.upgrade();
Self::salvage_item(&game, hero, index)?;
Self::salvage_item(&engine, hero, index)?;
if let Some(menu) = reference.upgrade() {
let mut tabs = menu.tabs_mut();
@ -174,9 +176,7 @@ impl ContentUpdate for Content<Item> {
}
ControllerButton::Y => {
let game = game_handle.upgrade();
if Self::select_to_socket(&game, hero, index)? {
if Self::select_to_socket(&engine, hero, index)? {
if let Some(menu) = reference.upgrade() {
let mut tabs = menu.tabs_mut();
let inventory = tabs.inventory();
@ -194,13 +194,11 @@ impl ContentUpdate for Content<Item> {
});
button.set_callback({
let game_handle = game_handle.clone();
let reference = reference.clone();
let engine = engine.clone();
move || {
let game = game_handle.upgrade();
Self::equip_item(&game, hero, index)?;
Self::equip_item(&engine, hero, index)?;
if let Some(menu) = reference.upgrade() {
let mut tabs = menu.tabs_mut();
@ -215,14 +213,14 @@ impl ContentUpdate for Content<Item> {
button.set_select_callback({
let weak_button = Arc::downgrade(&button);
let game_handle = game_handle.clone();
let reference = reference.clone();
let engine = engine.clone();
move |selected| {
if selected {
let button_pos = weak_button.upgrade().unwrap().position_extent();
Self::show_item_tooltip(&game_handle, hero, index, &reference, button_pos)?;
Self::show_item_tooltip(&engine, hero, index, &reference, button_pos)?;
} else {
let window = reference.upgrade().unwrap();
@ -245,13 +243,13 @@ impl ContentUpdate for Content<Item> {
impl Content<Jewel> {
fn show_jewel_tooltip(
game_handle: &GameHandle,
engine: &Arc<Engine>,
hero: Entity,
item_index: usize,
reference: &Weak<CharacterWindow>,
(x, y, w, _h): (i32, i32, u32, u32),
) -> Result<()> {
game_handle.upgrade().engine().on_scene(|scene| {
engine.on_scene(|scene| {
let entity = scene.entity(hero)?;
let inventory = entity.get_component::<Inventory>()?;
@ -260,8 +258,8 @@ impl Content<Jewel> {
let jewel = inventory.jewel_at(item_index);
let gui = jewel.create_tooltip(
game_handle,
&game_handle.upgrade().item_settings,
engine.gui_handler(),
&engine.upgrade().item_settings,
(target_x, target_y),
)?;
gui.enable()?;
@ -278,8 +276,8 @@ impl Content<Jewel> {
Ok(())
}
fn select_to_combine(game: &Game, hero: Entity, jewel_index: usize) -> Result<()> {
game.engine().on_scene_mut(|scene| {
fn select_to_combine(engine: &Arc<Engine>, hero: Entity, jewel_index: usize) -> Result<()> {
engine.on_scene_mut(|scene| {
let entity = scene.entity(hero)?;
let inventory = entity.get_component::<Inventory>()?;
let jewel = inventory.jewel_at(jewel_index).clone();
@ -305,8 +303,8 @@ impl Content<Jewel> {
})
}
fn select_to_lower(game: &Game, hero: Entity, jewel_index: usize) -> Result<()> {
game.engine().on_scene_mut(|scene| {
fn select_to_lower(engine: &Arc<Engine>, hero: Entity, jewel_index: usize) -> Result<()> {
engine.on_scene_mut(|scene| {
let entity = scene.entity(hero)?;
let inventory = entity.get_component::<Inventory>()?;
let jewel = inventory.jewel_at(jewel_index).clone();
@ -339,28 +337,22 @@ impl Content<Jewel> {
}
impl ContentUpdate for Content<Jewel> {
fn update(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
fn update(&mut self, engine: &Arc<Engine>, hero: Entity) -> Result<()> {
let reference = self.reference.clone();
self.update_base(game_handle, |button, t, index| {
self.update_base(engine, |button, t, index| {
button.set_icon(&t.icon())?;
button.set_select_callback({
let weak_button = Arc::downgrade(&button);
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move |selected| {
if selected {
let button_pos = weak_button.upgrade().unwrap().position_extent();
Self::show_jewel_tooltip(
&game_handle,
hero,
index,
&reference,
button_pos,
)?;
Self::show_jewel_tooltip(&engine, hero, index, &reference, button_pos)?;
} else {
let window = reference.upgrade().unwrap();
@ -372,13 +364,11 @@ impl ContentUpdate for Content<Jewel> {
});
button.set_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move || {
let game = game_handle.upgrade();
Self::select_to_lower(&game, hero, index)?;
Self::select_to_lower(&engine, hero, index)?;
if let Some(menu) = reference.upgrade() {
let mut tabs = menu.tabs_mut();
@ -392,15 +382,13 @@ impl ContentUpdate for Content<Jewel> {
});
button.set_custom_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move |controller_button| {
Ok(match controller_button {
ControllerButton::Y => {
let game = game_handle.upgrade();
Self::select_to_combine(&game, hero, index)?;
Self::select_to_combine(&engine, hero, index)?;
if let Some(menu) = reference.upgrade() {
let mut tabs = menu.tabs_mut();
@ -427,8 +415,8 @@ impl ContentUpdate for Content<Jewel> {
}
impl ContentUpdate for Content<MapItem> {
fn update(&mut self, game_handle: &GameHandle, _hero: Entity) -> Result<()> {
self.update_base(game_handle, |_button, _t, _index| {
fn update(&mut self, engine: &Arc<Engine>, _hero: Entity) -> Result<()> {
self.update_base(engine, |_button, _t, _index| {
// button.set_icon(&t.icon)?;
Ok(())

View file

@ -23,12 +23,12 @@ pub struct ItemRightSide {
impl ItemRightSide {
pub fn new(
game_handle: &GameHandle,
path: &str,
engine: &Arc<Engine>,
file: &str,
reference: &Weak<CharacterWindow>,
hero: Entity,
) -> Result<Self> {
let snippet = game_handle.gui_snippet(path)?;
let snippet = GuiSnippet::from_str(engine.gui_handler(), file)?;
let icons = InventoryEmptyIcons::new(&snippet)?;
let me = Self {
@ -36,40 +36,40 @@ impl ItemRightSide {
empty_icons: icons,
};
me.setup(game_handle, reference, hero)?;
me.setup(engine, reference, hero)?;
Ok(me)
}
fn setup(
&self,
game_handle: &GameHandle,
engine: &Arc<Engine>,
reference: &Weak<CharacterWindow>,
hero: Entity,
) -> Result<()> {
button_setup!(self, game_handle, reference, hero, helmet, "helmet");
button_setup!(self, game_handle, reference, hero, chest, "chest");
button_setup!(self, game_handle, reference, hero, gloves, "gloves");
button_setup!(self, game_handle, reference, hero, belt, "belt");
button_setup!(self, game_handle, reference, hero, boots, "boots");
button_setup!(self, engine, reference, hero, helmet, "helmet");
button_setup!(self, engine, reference, hero, chest, "chest");
button_setup!(self, engine, reference, hero, gloves, "gloves");
button_setup!(self, engine, reference, hero, belt, "belt");
button_setup!(self, engine, reference, hero, boots, "boots");
#[rustfmt::skip]
button_setup!(self, game_handle, reference, hero, primary_hand, "main hand");
button_setup!(self, engine, reference, hero, primary_hand, "main hand");
#[rustfmt::skip]
button_setup!(self, game_handle, reference, hero, secondary_hand, "off hand");
button_setup!(self, engine, reference, hero, secondary_hand, "off hand");
#[rustfmt::skip]
button_setup!(self, game_handle, reference, hero, amulet, "amulet_0", 0);
button_setup!(self, engine, reference, hero, amulet, "amulet_0", 0);
#[rustfmt::skip]
button_setup!(self, game_handle, reference, hero, amulet, "amulet_1", 1);
button_setup!(self, engine, reference, hero, amulet, "amulet_1", 1);
#[rustfmt::skip]
button_setup!(self, game_handle, reference, hero, ring, "ring_0", 0);
button_setup!(self, engine, reference, hero, ring, "ring_0", 0);
#[rustfmt::skip]
button_setup!(self, game_handle, reference, hero, ring, "ring_1", 1);
button_setup!(self, engine, reference, hero, ring, "ring_1", 1);
#[rustfmt::skip]
button_setup!(self, game_handle, reference, hero, ring, "ring_2", 2);
button_setup!(self, engine, reference, hero, ring, "ring_2", 2);
#[rustfmt::skip]
button_setup!(self, game_handle, reference, hero, ring, "ring_3", 3);
button_setup!(self, engine, reference, hero, ring, "ring_3", 3);
Ok(())
}
@ -99,7 +99,7 @@ impl ItemRightSide {
}
fn create_tooltip(
game_handle: &GameHandle,
engine: &Arc<Engine>,
item: &Item,
attributes: &Attributes,
(x, y, w, _h): (i32, i32, u32, u32),
@ -107,7 +107,7 @@ impl ItemRightSide {
let target_x = x + w as i32;
let target_y = y;
let gui = item.create_tooltip(game_handle, attributes, (target_x, target_y))?;
let gui = item.create_tooltip(engine.gui_handler(), attributes, (target_x, target_y))?;
gui.enable()?;
gui.perform_single_check(x, y)?;
@ -116,10 +116,8 @@ impl ItemRightSide {
}
impl RightSide for ItemRightSide {
fn refresh(&mut self, game_handle: &GameHandle, hero: Entity) -> Result<()> {
let game = game_handle.upgrade();
game.engine().on_scene(|scene| {
fn refresh(&mut self, engine: &Engine, hero: Entity) -> Result<()> {
engine.on_scene(|scene| {
let hero_object = scene.entity(hero)?;
let items = hero_object.get_component::<ItemSlotContainer>()?;
@ -184,18 +182,18 @@ impl InventoryEmptyIcons {
mod macros {
#[macro_export]
macro_rules! button_setup {
($self:ident, $game_handle:ident, $reference:ident, $hero:ident, $item:ident, $button:literal) => {
($self:ident, $engine:ident, $reference:ident, $hero:ident, $item:ident, $button:literal) => {
paste::expr! {
let [<$item _button>]: Arc<Button> = $self.snippet.element($button)?;
[<$item _button>].set_select_callback({
let game_handle = $game_handle.clone();
let engine = $engine.clone();
let reference = $reference.clone();
let weak_button = Arc::downgrade(&[<$item _button>]);
move |selected| {
if selected {
game_handle.upgrade().engine().on_scene(|scene| {
engine.on_scene(|scene| {
let entity = scene.entity($hero)?;
let attributes = entity.get_component::<Attributes>()?;
@ -207,7 +205,7 @@ mod macros {
weak_button.upgrade().unwrap().position_extent();
let gui = Self::create_tooltip(
&game_handle,
&engine,
$item,
attributes,
button_pos,
@ -231,13 +229,13 @@ mod macros {
});
[<$item _button>].set_callback({
let game_handle = $game_handle.clone();
let engine = $engine.clone();
let reference = $reference.clone();
move || {
let mut found_item = false;
game_handle.upgrade().engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
let entity = scene.entity_mut($hero)?;
let mut multi_mut = entity.multi_mut();
@ -257,7 +255,7 @@ mod macros {
statistics.update(
attributes,
&game_handle.upgrade().attribute_settings,
&engine.upgrade().attribute_settings,
&*items
);
@ -285,7 +283,7 @@ mod macros {
});
[<$item _button>].set_custom_callback({
let game_handle = $game_handle.clone();
let engine = $engine.clone();
let reference = $reference.clone();
move |controller_button| {
@ -293,7 +291,7 @@ mod macros {
ControllerButton::Y => {
let mut empty_affixes_found = false;
game_handle.upgrade().engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
let entity = scene.entity_mut($hero)?;
let items = entity.get_component::<ItemSlotContainer>()?;
@ -336,18 +334,18 @@ mod macros {
});
}
};
($self:ident, $game_handle:ident, $reference:ident, $hero:ident, $item:ident, $button:literal, $index:literal) => {
($self:ident, $engine:ident, $reference:ident, $hero:ident, $item:ident, $button:literal, $index:literal) => {
paste::expr! {
let [<$item _button>]: Arc<Button> = $self.snippet.element($button)?;
[<$item _button>].set_select_callback({
let game_handle = $game_handle.clone();
let engine = $engine.clone();
let reference = $reference.clone();
let weak_button = Arc::downgrade(&[<$item _button>]);
move |selected| {
if selected {
game_handle.upgrade().engine().on_scene(|scene| {
engine.on_scene(|scene| {
let entity = scene.entity($hero)?;
let attributes = entity.get_component::<Attributes>()?;
@ -359,7 +357,7 @@ mod macros {
weak_button.upgrade().unwrap().position_extent();
let gui = Self::create_tooltip(
&game_handle,
&engine,
$item,
attributes,
button_pos,
@ -383,13 +381,13 @@ mod macros {
});
[<$item _button>].set_callback({
let game_handle = $game_handle.clone();
let engine = $engine.clone();
let reference = $reference.clone();
move || {
let mut found_item = false;
game_handle.upgrade().engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
let entity = scene.entity_mut($hero)?;
let mut multi_mut = entity.multi_mut();
@ -409,7 +407,7 @@ mod macros {
statistics.update(
attributes,
&game_handle.upgrade().attribute_settings,
&engine.upgrade().attribute_settings,
&*items
);
@ -437,7 +435,7 @@ mod macros {
});
[<$item _button>].set_custom_callback({
let game_handle = $game_handle.clone();
let engine = $engine.clone();
let reference = $reference.clone();
move |controller_button| {
@ -445,7 +443,7 @@ mod macros {
ControllerButton::Y => {
let mut empty_affixes_found = false;
game_handle.upgrade().engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
let entity = scene.entity_mut($hero)?;
let items = entity.get_component::<ItemSlotContainer>()?;

View file

@ -46,17 +46,17 @@ pub struct JewelRightSide {
impl JewelRightSide {
pub fn new(
game_handle: &GameHandle,
path: &str,
engine: &Arc<Engine>,
file: &str,
hero: Entity,
reference: &Weak<CharacterWindow>,
) -> Result<Self> {
let snippet = game_handle.gui_snippet(path)?;
let snippet = GuiSnippet::from_str(engine.gui_handler(), file)?;
let combine: Arc<Label> = snippet.element("combine")?;
combine.set_info_icon(&game_handle.controller_icon(ControllerButton::RightStick)?)?;
combine.set_info_icon(&engine.controller_icon(ControllerButton::RightStick)?)?;
game_handle.upgrade().engine().on_scene_mut(|scene| {
engine.on_scene_mut(|scene| {
scene
.resources
.insert_if_not_exists::<Option<ReferenceObject>>();
@ -66,21 +66,21 @@ impl JewelRightSide {
})?;
let me = Self { snippet };
me.setup_select(game_handle, hero, reference)?;
me.setup_select(engine, hero, reference)?;
Ok(me)
}
fn setup_select(
&self,
game_handle: &GameHandle,
engine: &Arc<Engine>,
hero: Entity,
reference: &Weak<CharacterWindow>,
) -> Result<()> {
let (top, bottom) = self.elements()?;
top.set_select_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let weak_top = Arc::downgrade(&top);
let reference = reference.clone();
@ -94,21 +94,20 @@ impl JewelRightSide {
let (x, y, w, _h) = button.position_extent();
let game = game_handle.upgrade();
let scene = game.engine().scene();
let scene = engine.scene();
let reference_info = scene.resources.get::<Option<ReferenceObject>>();
if let Some(reference_info) = reference_info {
let tooltip = match reference_info {
ReferenceObject::Item { item, .. } => item.create_tooltip(
&game_handle,
engine.gui_handler(),
scene.entity(hero)?.get_component::<Attributes>()?,
(x + w as i32, y),
)?,
ReferenceObject::Jewel { jewel, .. } => jewel.create_tooltip(
&game_handle,
&game_handle.upgrade().item_settings,
engine.gui_handler(),
&engine.upgrade().item_settings,
(x + w as i32, y),
)?,
};
@ -128,7 +127,7 @@ impl JewelRightSide {
for (index, lower) in bottom.iter().enumerate() {
lower.set_select_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let weak_top = Arc::downgrade(&lower);
let reference = reference.clone();
@ -142,15 +141,14 @@ impl JewelRightSide {
let (x, y, w, _h) = button.position_extent();
let game = game_handle.upgrade();
let scene = game.engine().scene();
let scene = engine.scene();
let lower_info = scene.resources.get::<LowerJewels>();
if let Some((lower_jewel, _)) = &lower_info.jewels[index] {
let tooltip = lower_jewel.create_tooltip(
&game_handle,
&game_handle.upgrade().item_settings,
engine.gui_handler(),
&engine.upgrade().item_settings,
(x + w as i32, y),
)?;
@ -168,12 +166,11 @@ impl JewelRightSide {
});
lower.set_callback({
let game_handle = game_handle.clone();
let engine = engine.clone();
let reference = reference.clone();
move || {
let game = game_handle.upgrade();
let scene = game.engine().scene_mut();
let scene = engine.scene_mut();
let lower_info = scene.resources.get_mut::<LowerJewels>();
@ -209,9 +206,8 @@ impl JewelRightSide {
))
}
pub fn clear(game_handle: &GameHandle) {
let game = game_handle.upgrade();
let scene = game.engine().scene_mut();
pub fn clear(engine: &Arc<Engine>) {
let scene = engine.scene_mut();
*scene.resources.get_mut::<Option<ReferenceObject>>() = None;
scene
@ -222,9 +218,8 @@ impl JewelRightSide {
.for_each(|j| *j = None);
}
pub fn combine(game_handle: &GameHandle, hero: Entity) -> Result<bool> {
let game = game_handle.upgrade();
let scene = game.engine().scene_mut();
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 reference_info = resources.get::<Option<ReferenceObject>>();
@ -308,7 +303,7 @@ impl JewelRightSide {
let statistics = multi_mut.get::<Statistics>()?;
let attributes = multi_mut.get::<Attributes>()?;
statistics.update(attributes, &game.attribute_settings, &*item_slots);
statistics.update(attributes, &engine.attribute_settings, &*item_slots);
}
}
}
@ -334,7 +329,7 @@ impl JewelRightSide {
}
upper_jewel.level += 1;
upper_jewel.update_stat(&game.item_settings);
upper_jewel.update_stat(&engine.item_settings);
upper_jewel.icon = Some(game.item_system().jewel_icon(
upper_jewel.rarity,
upper_jewel.level,
@ -360,8 +355,8 @@ impl JewelRightSide {
}
impl RightSide for JewelRightSide {
fn refresh(&mut self, game_handle: &GameHandle, _hero: Entity) -> Result<()> {
game_handle.upgrade().engine().on_scene(|scene| {
fn refresh(&mut self, engine: &Engine, _hero: Entity) -> Result<()> {
engine.on_scene(|scene| {
let (reference, lower) = self.elements()?;
let reference_info = scene.resources.get::<Option<ReferenceObject>>();
@ -390,9 +385,8 @@ impl RightSide for JewelRightSide {
})
}
fn disable(&mut self, game_handle: &GameHandle, _hero: Entity) -> Result<()> {
let game = game_handle.upgrade();
let scene = game.engine().scene_mut();
fn disable(&mut self, engine: &Engine, _hero: Entity) -> Result<()> {
let scene = engine.scene_mut();
*scene.resources.get_mut::<Option<ReferenceObject>>() = None;
scene

View file

@ -9,15 +9,15 @@ pub struct MapRightSide {
}
impl MapRightSide {
pub fn new(game_handle: &GameHandle, path: &str) -> Result<Self> {
let snippet = game_handle.gui_snippet(path)?;
pub fn new(engine: &Arc<Engine>, file: &str) -> Result<Self> {
let snippet = GuiSnippet::from_str(engine.gui_handler(), file)?;
Ok(Self { snippet })
}
}
impl RightSide for MapRightSide {
fn refresh(&mut self, _game_handle: &GameHandle, _hero: Entity) -> Result<()> {
fn refresh(&mut self, _engine: &Engine, _hero: Entity) -> Result<()> {
Ok(())
}

View file

@ -12,7 +12,6 @@ use rpg_components::components::inventory::Inventory;
use super::page_content::PageContent;
use super::traits::*;
use super::{content::Content, CharacterWindow, Page};
use crate::GameHandle;
use item_right_side::ItemRightSide;
use jewel_right_side::JewelRightSide;
use map_right_side::MapRightSide;
@ -20,7 +19,7 @@ use map_right_side::MapRightSide;
pub struct InventoryPage {
close: Weak<Button>,
game_handle: GameHandle,
engine: Arc<Engine>,
hero: Entity,
grid: Arc<Grid>,
@ -35,18 +34,19 @@ pub struct InventoryPage {
impl InventoryPage {
pub fn new(
game: GameHandle,
engine: &Arc<Engine>,
hero: Entity,
reference: Weak<CharacterWindow>,
close: &Arc<Button>,
) -> Result<Self> {
let base = "gui/xml/ingame/character_menu/inventory/".to_string();
let grid = Grid::new(engine.gui_handler().clone(), 2, 1, false)?;
let grid = Grid::new(game.upgrade().engine().gui_handler().clone(), 2, 1, false)?;
let left_base = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/inventory/left_side.xml"),
)?;
let left_base = game.gui_snippet((base.clone() + "left_side.xml").as_str())?;
grid.attach(left_base.clone(), 0, 0, 1, 1)?;
Self::setup_content_switch(&left_base, reference.clone())?;
let tooltip = left_base.element("tooltip")?;
@ -54,15 +54,14 @@ impl InventoryPage {
// items
let item_mode = PageContent::new(
Content::new(&game, reference.clone(), {
let game_handle = game.clone();
Content::new(engine, reference.clone(), {
let engine = engine.clone();
let hero = hero.clone();
move || {
let game = game_handle.upgrade();
let mut data = Vec::new();
game.engine().on_scene(|scene| {
engine.on_scene(|scene| {
let hero_object = scene.entity(hero)?;
let inventory = hero_object.get_component::<Inventory>()?;
@ -75,25 +74,28 @@ impl InventoryPage {
}
})?,
{
let ui = game.gui_snippet((base.clone() + "items/tooltip.xml").as_str())?;
let ui = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/inventory/items/tooltip.xml"),
)?;
let equip: Arc<Label> = ui.element("equip")?;
equip.set_info_icon(&game.controller_icon(ControllerButton::A)?)?;
equip.set_info_icon(&engine.controller_icon(ControllerButton::A)?)?;
let salvage: Arc<Label> = ui.element("salvage")?;
salvage.set_info_icon(&game.controller_icon(ControllerButton::X)?)?;
salvage.set_info_icon(&engine.controller_icon(ControllerButton::X)?)?;
let socket: Arc<Label> = ui.element("socket")?;
socket.set_info_icon(&game.controller_icon(ControllerButton::Y)?)?;
socket.set_info_icon(&engine.controller_icon(ControllerButton::Y)?)?;
let switch_mode: Arc<Label> = ui.element("switch_mode")?;
switch_mode.set_info_icon(&game.controller_icon(ControllerButton::LeftStick)?)?;
switch_mode.set_info_icon(&engine.controller_icon(ControllerButton::LeftStick)?)?;
ui
},
ItemRightSide::new(
&game,
(base.clone() + "items/right_side.xml").as_str(),
engine,
include_str!("../../resources/inventory/items/right_side.xml"),
&reference,
hero,
)?,
@ -101,15 +103,14 @@ impl InventoryPage {
// jewels
let jewel_mode = PageContent::new(
Content::new(&game, reference.clone(), {
let game_handle = game.clone();
Content::new(engine, reference.clone(), {
let engine = engine.clone();
let hero = hero.clone();
move || {
let game = game_handle.upgrade();
let mut data = Vec::new();
game.engine().on_scene(|scene| {
engine.on_scene(|scene| {
let hero_object = scene.entity(hero)?;
let inventory = hero_object.get_component::<Inventory>()?;
@ -122,22 +123,25 @@ impl InventoryPage {
}
})?,
{
let ui = game.gui_snippet((base.clone() + "jewels/tooltip.xml").as_str())?;
let ui = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/inventory/jewels/tooltip.xml"),
)?;
let socket: Arc<Label> = ui.element("socket")?;
socket.set_info_icon(&game.controller_icon(ControllerButton::A)?)?;
socket.set_info_icon(&engine.controller_icon(ControllerButton::A)?)?;
let combine: Arc<Label> = ui.element("combine")?;
combine.set_info_icon(&game.controller_icon(ControllerButton::Y)?)?;
combine.set_info_icon(&engine.controller_icon(ControllerButton::Y)?)?;
let switch_mode: Arc<Label> = ui.element("switch_mode")?;
switch_mode.set_info_icon(&game.controller_icon(ControllerButton::LeftStick)?)?;
switch_mode.set_info_icon(&engine.controller_icon(ControllerButton::LeftStick)?)?;
ui
},
JewelRightSide::new(
&game,
(base.clone() + "jewels/right_side.xml").as_str(),
engine,
include_str!("../../resources/inventory/jewels/right_side.xml"),
hero,
&reference,
)?,
@ -145,15 +149,14 @@ impl InventoryPage {
// maps
let map_mode = PageContent::new(
Content::new(&game, reference.clone(), {
let game_handle = game.clone();
let hero = hero.clone();
Content::new(engine, reference.clone(), {
let engine = engine.clone();
let hero: Entity = hero.clone();
move || {
let game = game_handle.upgrade();
let mut data = Vec::new();
game.engine().on_scene(|scene| {
engine.on_scene(|scene| {
let hero_object = scene.entity(hero)?;
let inventory = hero_object.get_component::<Inventory>()?;
@ -166,26 +169,32 @@ impl InventoryPage {
}
})?,
{
let ui = game.gui_snippet((base.clone() + "maps/tooltip.xml").as_str())?;
let ui = GuiSnippet::from_str(
engine.gui_handler(),
include_str!("../../resources/inventory/maps/tooltip.xml"),
)?;
let select: Arc<Label> = ui.element("select")?;
select.set_info_icon(&game.controller_icon(ControllerButton::A)?)?;
select.set_info_icon(&engine.controller_icon(ControllerButton::A)?)?;
let start: Arc<Label> = ui.element("start")?;
start.set_info_icon(&game.controller_icon(ControllerButton::X)?)?;
start.set_info_icon(&engine.controller_icon(ControllerButton::X)?)?;
let switch_mode: Arc<Label> = ui.element("switch_mode")?;
switch_mode.set_info_icon(&game.controller_icon(ControllerButton::LeftStick)?)?;
switch_mode.set_info_icon(&engine.controller_icon(ControllerButton::LeftStick)?)?;
ui
},
MapRightSide::new(&game, (base.clone() + "maps/right_side.xml").as_str())?,
MapRightSide::new(
engine,
include_str!("../../resources/inventory/maps/right_side.xml"),
)?,
);
Ok(Self {
close: Arc::downgrade(close),
game_handle: game,
engine: engine.clone(),
hero,
grid,
@ -226,9 +235,8 @@ impl InventoryPage {
self.grid
.attach(mode.right_side_mut().base().clone(), 1, 0, 1, 1)?;
mode.content_mut().update(&self.game_handle, self.hero)?;
mode.right_side_mut()
.refresh(&self.game_handle, self.hero)?;
mode.content_mut().update(&self.engine, self.hero)?;
mode.right_side_mut().refresh(&self.engine, self.hero)?;
if select {
mode.content_mut().select()?;
@ -361,7 +369,7 @@ impl Page for InventoryPage {
fn disable(&mut self) -> Result<()> {
self.modes[self.current_mode]
.right_side_mut()
.disable(&self.game_handle, self.hero)
.disable(&self.engine, self.hero)
}
fn select(&self) -> Result<()> {
@ -382,7 +390,7 @@ impl Page for InventoryPage {
{
let mode = &mut self.modes[self.current_mode];
mode.content_mut().next_tab(&self.game_handle, self.hero)?;
mode.content_mut().next_tab(&self.engine, self.hero)?;
mode.content_mut().select()?;
}
@ -393,8 +401,7 @@ impl Page for InventoryPage {
{
let mode = &mut self.modes[self.current_mode];
mode.content_mut()
.previous_tab(&self.game_handle, self.hero)?;
mode.content_mut().previous_tab(&self.engine, self.hero)?;
mode.content_mut().select()?;
}
@ -406,7 +413,7 @@ impl Page for InventoryPage {
ControllerButton::LeftStick => {
self.modes[self.current_mode]
.right_side_mut()
.disable(&self.game_handle, self.hero)?;
.disable(&self.engine, self.hero)?;
self.current_mode = (self.current_mode + 1) % self.modes.len();
@ -416,8 +423,8 @@ impl Page for InventoryPage {
ControllerButton::RightStick => {
// check if jewel page is open
if self.current_mode == 1 {
if JewelRightSide::combine(&self.game_handle, self.hero)? {
JewelRightSide::clear(&self.game_handle);
if JewelRightSide::combine(&self.engine, self.hero)? {
JewelRightSide::clear(&self.engine);
self.update_page(true)?;
}

View file

@ -158,28 +158,9 @@ impl CharacterWindow {
tooltips: Mutex::default(),
tabs: RwLock::new([
Box::new(
CharacterPage::new(&ingame.game, ingame.hero.entity(), ingame.hero.name(), me)
.unwrap(),
),
Box::new(
InventoryPage::new(
ingame.game.clone(),
ingame.hero.entity(),
me.clone(),
&close_button,
)
.unwrap(),
),
Box::new(
AbilityPage::new(
ingame.game.clone(),
ingame.hero.entity(),
me.clone(),
&close_button,
)
.unwrap(),
),
Box::new(CharacterPage::new(&engine, hero, name, me).unwrap()),
Box::new(InventoryPage::new(&engine, hero, me.clone(), &close_button).unwrap()),
Box::new(AbilityPage::new(&engine, hero, me.clone(), &close_button).unwrap()),
]),
tab: AtomicUsize::new(0),
@ -314,39 +295,13 @@ impl TopLevelGui for CharacterWindow {
self.tab().select()?;
let close_button: Arc<Button> = self.menu_gui.element("close")?;
close_button.set_info_icon(&self.game_handle.controller_icon(ControllerButton::B)?)?;
close_button.set_info_icon(&self.engine.controller_icon(ControllerButton::B)?)?;
let left_info: Arc<Icon> = self.menu_gui.element("left_info")?;
match self
.engine
.settings()
.controller_button(&self.engine, ControllerButton::LeftButton)?
{
Some(icon) => {
left_info.set_icon(&icon)?;
left_info.set_text("")?;
}
None => {
left_info.clear_icon()?;
left_info.set_text("")?;
}
};
left_info.set_icon(&self.engine.controller_icon(ControllerButton::LeftButton)?)?;
let right_info: Arc<Icon> = self.menu_gui.element("right_info")?;
match self
.engine
.settings()
.controller_button(&self.engine, ControllerButton::RightButton)?
{
Some(icon) => {
right_info.set_icon(&icon)?;
right_info.set_text("")?;
}
None => {
right_info.clear_icon()?;
right_info.set_text("")?;
}
};
right_info.set_icon(&self.engine.controller_icon(ControllerButton::RightButton)?)?;
Ok(())
}

View file

@ -420,6 +420,13 @@ impl Engine {
self.context().set_active_controller(controller);
}
pub fn controller_icon(&self, button: ControllerButton) -> Result<Arc<Image>> {
Ok(self.settings().controller_icon(self, button)?.unwrap_or(
self.settings()
.controller_button_for(self, button, ControllerType::XBox)?,
))
}
pub fn context(&self) -> &Arc<Context> {
&self.graphical.context
}

View file

@ -189,9 +189,9 @@ impl EngineSettings {
&self.light_key
}
pub fn controller_button(
pub fn controller_icon(
&self,
engine: &Arc<Engine>,
engine: &Engine,
button: ControllerButton,
) -> Result<Option<Arc<Image>>> {
// TODO: don't check it every time we request a button

View file

@ -140,7 +140,7 @@ impl LootStash {
match game
.engine()
.settings()
.controller_button(game.engine(), ControllerButton::DPadUp)?
.controller_icon(game.engine(), ControllerButton::DPadUp)?
{
Some(pic) => {
icon.set_icon(&pic)?;