Fixed offhand weapons, when nothing was in the mainhand

This commit is contained in:
Sam 2021-03-23 22:04:21 -04:00 committed by jshipsey
parent b53e1653f6
commit c594f67d47
3 changed files with 69 additions and 32 deletions

View File

@ -78,8 +78,20 @@ impl State {
let inventory = inventories.get(client.entity());
let stats = client.state().ecs().read_storage::<common::comp::Stats>();
let stat = stats.get(client.entity());
let should_be_present = if let (Some(inventory), Some(stat)) = (inventory, stat) {
inventory.equipped(EquipSlot::Mainhand).map_or(false, |i| {
let hands = |equip_slot| match inventory.and_then(|i| i.equipped(equip_slot).map(|i| i.kind())) {
Some(ItemKind::Tool(tool)) => Some(tool.hands),
_ => None,
};
let equip_slot = match (hands(EquipSlot::Mainhand), hands(EquipSlot::Offhand)) {
(Some(_), _) => Some(EquipSlot::Mainhand),
(_, Some(_)) => Some(EquipSlot::Offhand),
_ => None,
};
let should_be_present = if let (Some(inventory), Some(stat), Some(equip_slot)) = (inventory, stat, equip_slot) {
inventory.equipped(equip_slot).map_or(false, |i| {
i.item_config_expect()
.abilities
.abilities
@ -126,8 +138,9 @@ impl State {
let (equip_slot, skill_index) = match (active_tool_hands, second_tool_hands) {
(Some(Hands::Two), _) => (Some(EquipSlot::Mainhand), 1),
(_, Some(Hands::One)) => (Some(EquipSlot::Offhand), 0),
(Some(_), Some(Hands::One)) => (Some(EquipSlot::Offhand), 0),
(Some(Hands::One), _) => (Some(EquipSlot::Mainhand), 1),
(None, Some(_)) => (Some(EquipSlot::Offhand), 1),
(_, _) => (None, 0),
};

View File

@ -563,8 +563,9 @@ impl<'a> Widget for Skillbar<'a> {
let equip_slot = match (active_tool_hands, second_tool_hands) {
(Some(Hands::Two), _) => Some(EquipSlot::Mainhand),
(_, Some(Hands::One)) => Some(EquipSlot::Offhand),
(Some(_), Some(Hands::One)) => Some(EquipSlot::Offhand),
(Some(Hands::One), _) => Some(EquipSlot::Mainhand),
(None, Some(_)) => Some(EquipSlot::Offhand),
(_, _) => None,
};
@ -661,27 +662,32 @@ impl<'a> Widget for Skillbar<'a> {
.w_h(40.0, 40.0)
.right_from(state.ids.slot5, slot_offset)
.set(state.ids.m1_slot_bg, ui);
Button::image(
match self
.inventory
.equipped(EquipSlot::Mainhand)
.map(|i| i.kind())
{
Some(ItemKind::Tool(Tool { kind, .. })) => match kind {
ToolKind::Sword => self.imgs.twohsword_m1,
ToolKind::Dagger => self.imgs.onehdagger_m1,
ToolKind::Shield => self.imgs.onehshield_m1,
ToolKind::Hammer => self.imgs.twohhammer_m1,
ToolKind::Axe => self.imgs.twohaxe_m1,
ToolKind::Bow => self.imgs.bow_m1,
ToolKind::Sceptre => self.imgs.skill_sceptre_lifesteal,
ToolKind::Staff => self.imgs.fireball,
ToolKind::Debug => self.imgs.flyingrod_m1,
_ => self.imgs.nothing,
},
_ => self.imgs.nothing,
},
) // Insert Icon here
let active_tool = get_item_and_tool(self.inventory, EquipSlot::Mainhand);
let second_tool = get_item_and_tool(self.inventory, EquipSlot::Offhand);
let tool = match (
active_tool.map(|(_, x)| x.hands),
second_tool.map(|(_, x)| x.hands),
) {
(Some(_), _) => active_tool,
(_, Some(_)) => second_tool,
(_, _) => None,
};
Button::image(match tool.map(|(_, t)| t.kind) {
Some(ToolKind::Sword) => self.imgs.twohsword_m1,
Some(ToolKind::Dagger) => self.imgs.onehdagger_m1,
Some(ToolKind::Shield) => self.imgs.onehshield_m1,
Some(ToolKind::Hammer) => self.imgs.twohhammer_m1,
Some(ToolKind::Axe) => self.imgs.twohaxe_m1,
Some(ToolKind::Bow) => self.imgs.bow_m1,
Some(ToolKind::Sceptre) => self.imgs.skill_sceptre_lifesteal,
Some(ToolKind::Staff) => self.imgs.fireball,
Some(ToolKind::Debug) => self.imgs.flyingrod_m1,
_ => self.imgs.nothing,
}) // Insert Icon here
.w_h(36.0, 36.0)
.middle_of(state.ids.m1_slot_bg)
.set(state.ids.m1_content, ui);
@ -709,8 +715,9 @@ impl<'a> Widget for Skillbar<'a> {
second_tool.map(|(_, x)| x.hands),
) {
(Some(Hands::Two), _) => active_tool,
(_, Some(Hands::One)) => second_tool,
(Some(_), Some(Hands::One)) => second_tool,
(Some(Hands::One), _) => active_tool,
(None, Some(_)) => second_tool,
(_, _) => None,
};

View File

@ -144,14 +144,30 @@ impl<'a> SlotKey<HotbarSource<'a>, HotbarImageSource<'a>> for HotbarSlot {
.map(|item| HotbarImage::Item(item.into()))
.map(|i| (i, None)),
hotbar::SlotContents::Ability3 => {
let tool = match inventory
.equipped(EquipSlot::Mainhand)
.map(|i| (i, i.kind()))
{
Some((item, ItemKind::Tool(tool))) => Some((item, tool)),
let hands = |equip_slot| match inventory.equipped(equip_slot).map(|i| i.kind()) {
Some(ItemKind::Tool(tool)) => Some(tool.hands),
_ => None,
};
let active_tool_hands = hands(EquipSlot::Mainhand);
let second_tool_hands = hands(EquipSlot::Offhand);
let equip_slot = match (active_tool_hands, second_tool_hands) {
(Some(_), _) => Some(EquipSlot::Mainhand),
(None, Some(_)) => Some(EquipSlot::Offhand),
(_, _) => None,
};
let tool = equip_slot.and_then(|es|
match inventory
.equipped(es)
.map(|i| (i, i.kind()))
{
Some((item, ItemKind::Tool(tool))) => Some((item, tool)),
_ => None,
}
);
tool.and_then(|(item, tool)| {
hotbar_image(tool.kind).map(|i| {
(
@ -184,8 +200,9 @@ impl<'a> SlotKey<HotbarSource<'a>, HotbarImageSource<'a>> for HotbarSlot {
let (equip_slot, skill_index) = match (active_tool_hands, second_tool_hands) {
(Some(Hands::Two), _) => (Some(EquipSlot::Mainhand), 1),
(_, Some(Hands::One)) => (Some(EquipSlot::Offhand), 0),
(Some(_), Some(Hands::One)) => (Some(EquipSlot::Offhand), 0),
(Some(Hands::One), _) => (Some(EquipSlot::Mainhand), 1),
(None, Some(_)) => (Some(EquipSlot::Offhand), 1),
(_, _) => (None, 0),
};