Files
habitica/website/client/components/inventory/equipment/attributesGrid.vue
T
aszlig 4f2d066d66 client: Fix display of class bonus for other users (#10376)
Whenever one is hovering an item from another user, the bonuses of these
items are shown for the own user. So for example if you're a mage and
view a Royal Magus Robe of another mage, the class bonus is 6.

However if you're a warrior, the class bonus displays as 0 because the
attributes grid is always using the stats for the own user even if
viewing equipment of a different user.

I've fixed this by moving the user object to the properties in
attributesGrid and passing the current user from every other Vue file
that's using attributesGrid.

Not sure whether this is the right approach, as I'm no expert in Vue.js
but some testing with the client now shows the correct values.

Signed-off-by: aszlig <aszlig@nix.build>
2018-05-25 12:38:02 +02:00

173 lines
3.5 KiB
Vue

<template lang="pug">
div.attributes-group
.popover-content-attr(v-for="attr in ATTRIBUTES", :key="attr")
.group-content
span.popover-content-attr-cell.key(:class="{'hasValue': hasSumValue(attr) }") {{ `${$t(attr)}: ` }}
span.popover-content-attr-cell.label.value(:class="{'green': hasSumValue(attr) }") {{ `${stats.sum[attr]}` }}
span.popover-content-attr-cell.label.bold(:class="{'hasValue': hasGearValue(attr) }") {{ $t('gear') }}:
span.popover-content-attr-cell.label(:class="{'hasValue': hasGearValue(attr) }") {{ stats.gear[attr] }}
span.popover-content-attr-cell.label.bold(:class="{'hasValue': hasClassBonus(attr) }") {{ $t('classEquipBonus') }}:
span.popover-content-attr-cell.label(:class="{'hasValue': hasClassBonus(attr) }") {{ `${stats.classBonus[attr]}` }}
</template>
<style lang="scss">
@import '~client/assets/scss/colors.scss';
.attributes-group {
border-radius: 4px;
// unless we have a way to give a popover an id or class, it needs expand the attributes area
margin: -12px -16px;
display:flex;
flex-wrap: wrap;
}
.popover-content-attr {
font-weight: bold;
width: calc(50% - 1px);
background-color: $gray-50;
&:nth-of-type(even) {
margin-left: 1px;
}
&:nth-child(1), &:nth-child(2) {
margin-bottom: 1px;
}
}
.group-content {
display: inline-flex;
flex-wrap: wrap;
padding: 4px 12px;
width: 100%;
}
.popover-content-attr-cell {
width: 70%;
text-align: left;
&:nth-of-type(even) {
text-align: right;
width: 30%;
}
&.key {
color: $white;
font-size: 12px;
font-weight: bold;
line-height: 1.33;
}
&.label {
font-size: 10px;
line-height: 1.2;
color: $gray-300;
}
&.label.bold {
font-weight: bold;
}
&.label.value {
font-size: 12px;
font-weight: bold;
line-height: 1.33;
text-align: right;
white-space: nowrap;
&.green {
color: $green-10;
&:before {
content: '+';
}
}
}
}
.modal-body {
.group-content {
padding: 8px 17px;
}
.popover-content-attr {
background-color: #f4f4f4;
&:nth-of-type(even) {
margin-left: 1px;
width: 50%;
}
}
.popover-content-attr-cell {
&.key {
color: $gray-400;
font-size: 16px;
font-weight: bold;
line-height: 1.25;
&.hasValue {
color: $gray-50;
}
}
&.label {
color: $gray-400;
font-size: 12px;
font-weight: bold;
line-height: 1.33;
&.hasValue {
color: $gray-200;
}
}
&.label.value {
&.green {
color: $green-10;
}
}
}
}
</style>
<script>
import { mapState } from 'client/libs/store';
import statsMixin from 'client/mixins/stats';
export default {
mixins: [statsMixin],
props: {
item: {
type: Object,
},
user: {
type: Object,
},
},
computed: {
...mapState({
ATTRIBUTES: 'constants.ATTRIBUTES',
flatGear: 'content.gear.flat',
}),
},
methods: {
hasSumValue (attr) {
return this.stats.sum[attr] > 0;
},
hasGearValue (attr) {
return this.stats.gear[attr] > 0;
},
hasClassBonus (attr) {
return this.stats.classBonus[attr] > 0;
},
},
};
</script>