120 lines
2.8 KiB
HTML
120 lines
2.8 KiB
HTML
{include "layout.html"}
|
|
|
|
{block "content"}
|
|
<div class="town shop">
|
|
<div class="title"><h3>{town.Name} Maps</h3></div>
|
|
{error_message}
|
|
<section>
|
|
<p>Buying maps will put the town in your Travel To box, and it won't cost you as many TP to get there.</p>
|
|
<p>Click a town name to purchase its map.</p>
|
|
</section>
|
|
|
|
<section>
|
|
<table class="shop">
|
|
{for map in maplist}
|
|
<tr>
|
|
<td>
|
|
{if map.Owned == false}
|
|
{if user.Gold >= map.Cost}
|
|
<a class="buy-item" data-item="{map.Name} Map" data-cost="{map.Cost}" href="/town/maps/buy/{map.ID}">{map.Name}</a>
|
|
{else}
|
|
<span class="light">{map.Name}</span>
|
|
{/if}
|
|
{else}
|
|
{map.Name}
|
|
{/if}
|
|
</td>
|
|
<td>
|
|
{if map.Owned == false}
|
|
{if user.Gold >= map.Cost}
|
|
{map.Cost}G
|
|
{else}
|
|
{map.Cost}G <span class="light">(can't afford)</span>
|
|
{/if}
|
|
{else}
|
|
<span>{map.X}, {map.Y}</span><br>
|
|
<span>TP Cost: {map.TP}</span>
|
|
{/if}
|
|
</td>
|
|
</tr>
|
|
{/for}
|
|
</table>
|
|
</section>
|
|
|
|
<section>
|
|
<p>If you've changed your mind, you may also return back to <a href="/town">town</a>.</p>
|
|
</section>
|
|
|
|
<div id="shop-modal" class="modal">
|
|
<div class="content">
|
|
<p id="msg">Are you sure you want to buy this item?</p>
|
|
<div class="buttons">
|
|
<button id="confirm" class="btn btn-primary">Buy Now</button>
|
|
<button id="cancel" class="btn">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{/block}
|
|
|
|
{block "scripts"}
|
|
<script>
|
|
class ShopModal {
|
|
constructor() {
|
|
this.modal = document.querySelector("#shop-modal")
|
|
this.message = this.modal.querySelector("#msg")
|
|
this.confirmBtn = this.modal.querySelector("#confirm")
|
|
this.cancelBtn = this.modal.querySelector("#cancel")
|
|
this.currentUrl = null
|
|
|
|
this.init()
|
|
}
|
|
|
|
init() {
|
|
document.querySelectorAll('.buy-item').forEach(link => {
|
|
link.addEventListener('click', (e) => {
|
|
e.preventDefault()
|
|
this.show(link.href, link.dataset.item, link.dataset.cost)
|
|
})
|
|
})
|
|
|
|
this.confirmBtn.addEventListener('click', () => this.confirm())
|
|
this.cancelBtn.addEventListener('click', () => this.hide())
|
|
|
|
this.modal.addEventListener('click', (e) => {
|
|
if (e.target === this.modal) this.hide()
|
|
})
|
|
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape' && this.modal.style.display === 'block') {
|
|
this.hide()
|
|
}
|
|
})
|
|
}
|
|
|
|
show(url, itemName, itemCost) {
|
|
this.currentUrl = url
|
|
this.message.textContent = `Are you sure you want to buy ${itemName} for ${itemCost}G?`
|
|
this.modal.style.display = 'block'
|
|
this.confirmBtn.focus()
|
|
}
|
|
|
|
hide() {
|
|
this.modal.style.display = 'none'
|
|
this.currentUrl = null
|
|
}
|
|
|
|
confirm() {
|
|
if (this.currentUrl) {
|
|
window.location.href = this.currentUrl
|
|
}
|
|
this.hide()
|
|
}
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
new ShopModal()
|
|
})
|
|
</script>
|
|
{/block}
|