redraws frontend UI
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
<template>
|
||||
<main id="app" class="section">
|
||||
<section id="content" class="columns is-desktop">
|
||||
<main id="app" class="container">
|
||||
<Player></Player>
|
||||
<div class="column">
|
||||
<Chest :player="0" v-if="state.initiated"></Chest>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -116,17 +116,14 @@ export const AppStorage = {
|
||||
},
|
||||
updatePlayerWealth (goldValue) {
|
||||
return Api.updateWealth(this.state.player_id, goldValue)
|
||||
.then(done => {
|
||||
if (done.executed) {
|
||||
.then(response => {
|
||||
// Update player wealth
|
||||
var diff = done.response;
|
||||
var diff = response;
|
||||
if (this.debug) console.log('updatePlayerWealth', diff)
|
||||
this.state.player_list[this.state.player_id].cp += diff[0];
|
||||
this.state.player_list[this.state.player_id].sp += diff[1];
|
||||
this.state.player_list[this.state.player_id].gp += diff[2];
|
||||
this.state.player_list[this.state.player_id].pp += diff[3];
|
||||
}
|
||||
return done.executed;
|
||||
});
|
||||
},
|
||||
// Put a claim on an item from group chest.
|
||||
@@ -134,12 +131,8 @@ export const AppStorage = {
|
||||
const playerId = this.state.player_id
|
||||
Api.putClaim(playerId, itemId)
|
||||
.then(done => {
|
||||
if (done.executed) {
|
||||
// Update cliend-side state
|
||||
this.state.player_claims[playerId].push(itemId);
|
||||
} else {
|
||||
if (this.debug) console.log("API responded with 'false'")
|
||||
}
|
||||
// Update cliend-side state
|
||||
this.state.player_claims[playerId].push(itemId);
|
||||
});
|
||||
},
|
||||
// Withdraws a claim.
|
||||
@@ -147,16 +140,12 @@ export const AppStorage = {
|
||||
const playerId = this.state.player_id
|
||||
Api.unClaim(playerId, itemId)
|
||||
.then(done => {
|
||||
if (done.executed) {
|
||||
var idx = this.state.player_claims[playerId].indexOf(itemId);
|
||||
if (idx > -1) {
|
||||
this.state.player_claims[playerId].splice(idx, 1);
|
||||
} else {
|
||||
if (this.debug) console.log("cancel a non-existent request")
|
||||
}
|
||||
} else {
|
||||
if (this.debug) console.log("API responded with 'false'")
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +1,50 @@
|
||||
<template>
|
||||
<div class="container is-paddingless">
|
||||
<div v-if="mainControlsDisplayed"
|
||||
class="columns is-mobile is-vcentered"
|
||||
>
|
||||
<div class="column is-narrow">
|
||||
<span class="icon is-large">
|
||||
<i class="fas fa-2x fa-dragon"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="column has-text-left">
|
||||
<h1 class="title">Coffre de groupe</h1>
|
||||
</div>
|
||||
<div class="column" v-show="canAdd">
|
||||
<div v-show="mainControlsDisplayed" class="buttons is-right">
|
||||
<button v-if="canAdd"
|
||||
class="button is-inverted is-info"
|
||||
@click="is_adding = true"
|
||||
>
|
||||
<span class="icon">
|
||||
<i class="fas fa-box-open"></i>
|
||||
</span>
|
||||
<p>Nouveau loot</p>
|
||||
</button>
|
||||
<button class="button is-inverted is-primary">
|
||||
<span class="icon">
|
||||
<i class="fas fa-coins"></i>
|
||||
</span>
|
||||
<p>Tout vendre</p>
|
||||
<table class="table is-fullwidth is-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ player == 0 ? 'Coffre de groupe' : 'Objets'}}</th>
|
||||
<th v-if="canGrab"></th>
|
||||
<th v-if="canSell">
|
||||
<div class="buttons is-right">
|
||||
<button class="button" :class="is_selling ? 'is-danger' : 'is-warning'"
|
||||
@click="is_selling = !is_selling">
|
||||
<span class="icon"><i class="fas fa-coins"></i></span>
|
||||
<p v-if="!is_selling">Vendre</p>
|
||||
<p v-else>{{ totalSellValue ? totalSellValue : 'Annuler' }}</p>
|
||||
</button>
|
||||
<PercentInput v-show="is_selling"></PercentInput>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Loot v-if="is_adding" @done="is_adding = false"></Loot>
|
||||
<table v-else class="table is-fullwidth is-striped" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Objets de {{ player }}</th>
|
||||
<th v-if="canGrab"></th>
|
||||
<th v-if="canSell">
|
||||
<div class="buttons is-right">
|
||||
<button class="button"
|
||||
:class="is_selling ? 'is-danger' : 'is-warning'"
|
||||
@click="is_selling = !is_selling"
|
||||
>
|
||||
<span class="icon">
|
||||
<i class="fas fa-coins"></i>
|
||||
</span>
|
||||
<p v-if="!is_selling">
|
||||
Vendre</p>
|
||||
<p v-else>
|
||||
{{ totalSellValue ? totalSellValue : 'Annuler' }}</p>
|
||||
</button>
|
||||
<PercentInput v-show="is_selling">
|
||||
</PercentInput>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-if="app_state.initiated">
|
||||
<template v-for="(item, idx) in content">
|
||||
<tr :key="`row-${idx}`">
|
||||
<td>
|
||||
<strong>{{item.name}}</strong>
|
||||
</td>
|
||||
<td v-if="canGrab">
|
||||
<Request :item="item.id"></Request>
|
||||
</td>
|
||||
<td v-if="canSell">
|
||||
<div class="field is-grouped is-pulled-right" v-show="is_selling">
|
||||
<div class="control">
|
||||
<label class="label">
|
||||
<input type="checkbox"
|
||||
id="`item-${idx}`"
|
||||
:value="item.id"
|
||||
v-model="sell_selected">
|
||||
{{item.base_price / 2}} GP
|
||||
</label>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-for="(item, idx) in content">
|
||||
<tr :key="`row-${idx}`">
|
||||
<td>{{item.name}}</td>
|
||||
<td v-if="canGrab">
|
||||
<Request :item="item.id"></Request>
|
||||
</td>
|
||||
<td v-if="canSell">
|
||||
<div class="field is-grouped is-pulled-right" v-show="is_selling">
|
||||
<div class="control">
|
||||
<label class="label">
|
||||
<input type="checkbox"
|
||||
id="`item-${idx}`"
|
||||
:value="item.id"
|
||||
v-model="sell_selected">
|
||||
{{item.base_price / 2}} GP
|
||||
</label>
|
||||
</div>
|
||||
<PercentInput></PercentInput>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<PercentInput></PercentInput>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
<p v-else>Loading...</p>
|
||||
</table>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -154,11 +116,6 @@
|
||||
return (this.app_state.player_id == 0
|
||||
&& this.player == 0);
|
||||
},
|
||||
// The main controls are only displayed on group chest
|
||||
mainControlsDisplayed () {
|
||||
return (this.player == 0
|
||||
&& !this.is_adding);
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<template>
|
||||
<input type="text"
|
||||
class="input"
|
||||
:class="{'is-danger': has_error}"
|
||||
:value="value"
|
||||
@input="checkError"
|
||||
></input>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: ["value"],
|
||||
data () {
|
||||
return { has_error: false};
|
||||
},
|
||||
methods: {
|
||||
checkError (ev) {
|
||||
const newValue = ev.target.value;
|
||||
this.has_error = isNaN(newValue);
|
||||
this.$emit(
|
||||
'input',
|
||||
this.has_error ? 0 : Number(newValue)
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -1,20 +1,18 @@
|
||||
<template>
|
||||
<div class="field has-addons">
|
||||
<div v-show="is_opened" class="control has-icons-left">
|
||||
<input class="input is-small" type="number" size="3" min=-50 max=50 step=5>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-percent"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button class="button is-small is-outlined"
|
||||
@click="is_opened = !is_opened"
|
||||
>
|
||||
<small v-if="!is_opened">Mod.</small>
|
||||
<span v-else class="icon"><i class="fas fa-times-circle"></i></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field has-addons">
|
||||
<div v-show="is_opened" class="control has-icons-left">
|
||||
<input class="input is-small" type="number" size="3" min=-50 max=50 step=5>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-percent"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button class="button is-small is-outlined" @click="is_opened = !is_opened">
|
||||
<small v-if="!is_opened">Mod.</small>
|
||||
<span v-else class="icon"><i class="fas fa-times-circle"></i></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
@@ -1,51 +1,45 @@
|
||||
<template>
|
||||
<div class="column is-one-third-desktop">
|
||||
<div id="sidebar" class="card">
|
||||
<header id="sidebar-heading" class="card-header">
|
||||
<p class="card-header-title">
|
||||
{{ app_state.initiated ? player.name : "..." }}</p>
|
||||
<div class="dropdown is-right"
|
||||
:class="{ 'is-active': show_dropdown }">
|
||||
<div class="dropdown-trigger" ref="dropdown_btn">
|
||||
<a id="change_player" class="card-header-icon"
|
||||
@click="show_dropdown = !show_dropdown"
|
||||
aria-haspopup="true" aria-controls="dropdown-menu">
|
||||
<span class="icon is-small">
|
||||
<i class="fas fa-exchange-alt"></i>
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="dropdown-menu" id="dropdown-menu" role="menu"
|
||||
v-closable="{ exclude: ['dropdown_btn'], handler: 'closeDropdown', visible: show_dropdown }">
|
||||
<div class="dropdown-content" v-if="app_state.initiated">
|
||||
<a v-for="(p,i) in app_state.player_list" :key="i"
|
||||
@click="setActivePlayer(i)"
|
||||
href="#" class="dropdown-item">
|
||||
{{ p.name }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="card-content">
|
||||
<Wealth :wealth="wealth" :debt="player.debt"></Wealth>
|
||||
<div class="box is-shadowless" v-show="!playerIsGroup">
|
||||
<div class="columns is-vcentered" @click="switchPlayerChestVisibility">
|
||||
<div class="column is-one-fifth">
|
||||
<span class="icon is-large">
|
||||
<i class="fas fa-2x fa-box"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="column if-four-fifth has-text-left">
|
||||
<p class="is-size-3">Coffre</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="">
|
||||
<nav class="navbar is-info">
|
||||
<div class="navbar-brand">
|
||||
<p class="navbar-item is-size-4" @click="show_wealth = !show_wealth">{{ app_state.initiated ? player.name : "..." }}</p>
|
||||
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
</a>
|
||||
</div>
|
||||
<div id="menu" class="navbar-menu">
|
||||
<div class="navbar-start">
|
||||
<template v-if="playerIsGroup">
|
||||
<a class="navbar-item">Nouveau loot</a>
|
||||
</template>
|
||||
<template v-else>
|
||||
<a class="navbar-item" @click="switchPlayerChestVisibility">
|
||||
{{ app_state.show_player_chest ? 'Coffre de groupe' : 'Mon coffre' }}</a>
|
||||
<a class="navbar-item">Marchand</a>
|
||||
</template>
|
||||
</div>
|
||||
<div class="navbar-end">
|
||||
<div class="navbar-item has-dropdown is-hoverable">
|
||||
<a class="navbar-link">Autres</a>
|
||||
<div class="navbar-dropdown is-right">
|
||||
<a class="navbar-item">History of Loot</a>
|
||||
<hr class="navbar-divider">
|
||||
<div class="navbar-item heading">Changer</div>
|
||||
<a v-for="(p,i) in app_state.player_list" :key="i"
|
||||
@click="setActivePlayer(i)"
|
||||
href="#" class="navbar-item">
|
||||
{{ p.name }}</a>
|
||||
</div>
|
||||
</div>
|
||||
<Chest :player="app_state.player_id"
|
||||
v-show="app_state.show_player_chest">
|
||||
</Chest>
|
||||
<a href="#" class="button is-link is-fullwidth is-hidden" disabled>Historique</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<section class="has-background-light" v-if="show_wealth">
|
||||
<Wealth :wealth="wealth" :debt="player.debt"></Wealth>
|
||||
</section>
|
||||
<Chest :player="shownChest"></Chest>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -75,9 +69,7 @@
|
||||
data () {
|
||||
return {
|
||||
app_state: AppStorage.state,
|
||||
show_dropdown: false,
|
||||
edit_wealth: false,
|
||||
handleOutsideClick: null,
|
||||
show_wealth: true,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -100,6 +92,11 @@
|
||||
// Check if the active player is the special 'Group' player
|
||||
playerIsGroup () {
|
||||
return this.app_state.player_id == 0;
|
||||
},
|
||||
shownChest () {
|
||||
return this.app_state.show_player_chest
|
||||
? this.app_state.player_id
|
||||
: 0;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -120,43 +117,6 @@
|
||||
this.show_dropdown = false
|
||||
}
|
||||
},
|
||||
directives: {
|
||||
'closable': {
|
||||
bind: function(el, binding, vnode) {
|
||||
handleOutsideClick = (e) => {
|
||||
e.stopPropagation();
|
||||
const { exclude, handler } = binding.value;
|
||||
let excludedElClicked = false;
|
||||
exclude.forEach(refName => {
|
||||
if (!excludedElClicked) {
|
||||
const elt = vnode.context.$refs[refName];
|
||||
excludedElClicked = elt.contains(e.target);
|
||||
}
|
||||
});
|
||||
|
||||
if (!excludedElClicked) {
|
||||
console.log('outsideCloseDropdown');
|
||||
vnode.context[handler]()
|
||||
}
|
||||
};
|
||||
},
|
||||
// Bind custom handler only when dropdown is visible
|
||||
update: function(el, binding, vnode, _) {
|
||||
const { visible } = binding.value;
|
||||
if (visible) {
|
||||
document.addEventListener('click', handleOutsideClick);
|
||||
document.addEventListener('touchstart', handleOutsideClick);
|
||||
} else {
|
||||
document.removeEventListener('click', handleOutsideClick);
|
||||
document.removeEventListener('touchstart', handleOutsideClick);
|
||||
}
|
||||
},
|
||||
unbind: function() { console.log("unbind");
|
||||
document.removeEventListener('click', handleOutsideClick);
|
||||
document.removeEventListener('touchstart', handleOutsideClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,57 +1,53 @@
|
||||
<template>
|
||||
<div class="box is-shadowless">
|
||||
<nav class="columns is-mobile is-multiline is-vcentered">
|
||||
<div class="column">
|
||||
<section class="level is-mobile">
|
||||
<div class="level-left">
|
||||
<div class="level-item">
|
||||
<span class="icon is-large"
|
||||
@click="edit = !edit">
|
||||
<i class="fas fa-2x fa-piggy-bank"></i>
|
||||
</span>
|
||||
<p v-if="debt" class="has-text-danger">-{{ debt }}gp </p>
|
||||
</div>
|
||||
<div class="column has-text-info">
|
||||
<p class="heading">PP</p>
|
||||
<p class="is-size-4">{{ wealth[3] }}</p>
|
||||
</div>
|
||||
<div class="column has-text-warning">
|
||||
<p class="heading">PO</p>
|
||||
<p class="is-size-4">{{ wealth[2] }}</p>
|
||||
</div>
|
||||
<div class="column has-text-grey">
|
||||
<p class="heading">PA</p>
|
||||
<p class="is-size-4">{{ wealth[1] }}</p>
|
||||
</div>
|
||||
<div class="column has-text-grey">
|
||||
<p class="heading">PC</p>
|
||||
<p class="is-size-4">{{ wealth[0] }}</p>
|
||||
</div>
|
||||
</nav>
|
||||
<div v-if="edit"> <!-- or v-show ? -->
|
||||
<nav class="columns is-mobile">
|
||||
<div class="column">
|
||||
<NumberInput v-model="edit_value"></NumberInput>
|
||||
</div>
|
||||
<div class="column is-2">
|
||||
<button class="button is-outlined is-fullwidth is-danger"
|
||||
@click="updateWealth('minus')">
|
||||
<span class="icon"><i class="fas fa-2x fa-minus"></i></span>
|
||||
</div>
|
||||
<template v-if="edit">
|
||||
<div class="level-item">
|
||||
<input type="number" step="0.01" v-model="edit_value"></input>
|
||||
</div>
|
||||
<div class="level-item">
|
||||
<button class="button is-danger" @click="updateWealth()">
|
||||
Modifier
|
||||
</button>
|
||||
</div>
|
||||
<div class="column is-2">
|
||||
<button class="button is-outlined is-primary is-fullwidth"
|
||||
@click="updateWealth('plus')">
|
||||
<span class="icon"><i class="fas fa-2x fa-plus"></i></span>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="level-item ">
|
||||
<p class="is-size-4">{{ wealth[3] }}</p>
|
||||
<p class="heading">PP</p>
|
||||
</div>
|
||||
<div class="level-item ">
|
||||
<p class="is-size-4">{{ wealth[2] }}</p>
|
||||
<p class="heading">PO</p>
|
||||
</div>
|
||||
<div class="level-item ">
|
||||
<p class="is-size-4">{{ wealth[1] }}</p>
|
||||
<p class="heading">PA</p>
|
||||
</div>
|
||||
<div class="level-item ">
|
||||
<p class="is-size-4">{{ wealth[0] }}</p>
|
||||
<p class="heading">PC</p>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-right" v-if="debt">
|
||||
<div class="level-item">
|
||||
<p class="heading is-size-4 has-text-danger">Dette: {{ debt }}gp </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { AppStorage } from '../AppStorage.js'
|
||||
import NumberInput from './NumberInput.vue'
|
||||
export default {
|
||||
components: { NumberInput },
|
||||
props: ["wealth", "debt"],
|
||||
data () {
|
||||
return {
|
||||
@@ -60,28 +56,9 @@
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
updateWealth (op) {
|
||||
var goldValue;
|
||||
switch (op) {
|
||||
case 'plus':
|
||||
goldValue = this.edit_value;
|
||||
break;
|
||||
case 'minus':
|
||||
goldValue = -this.edit_value;
|
||||
break;
|
||||
default:
|
||||
console.log("Error, bad operator !", op);
|
||||
return;
|
||||
}
|
||||
AppStorage.updatePlayerWealth(goldValue)
|
||||
.then(done => {
|
||||
if (done) {
|
||||
this.$emit('updated');
|
||||
this.resetValues();
|
||||
} else {
|
||||
console.log('correct errors');
|
||||
}
|
||||
});
|
||||
updateWealth () {
|
||||
AppStorage.updatePlayerWealth(this.edit_value)
|
||||
.then(_ => this.resetValues());
|
||||
},
|
||||
resetValues () {
|
||||
this.edit = false;
|
||||
|
||||
Reference in New Issue
Block a user