From 4c320758156ce2242ec0a1cfd56907780aa1d3eb Mon Sep 17 00:00:00 2001 From: Grammatopoulos Apostolos Date: Sun, 7 Nov 2021 20:38:48 +0000 Subject: [PATCH] Merchants info is now enabled in guild storage --- PROGRESS.md | 4 +- source/core/source/guild.storage.js | 73 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/PROGRESS.md b/PROGRESS.md index 83ab6324..f80fedde 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -1,7 +1,7 @@ ## Progress on Version 4.3.5 [Alpha] ![version type](https://img.shields.io/badge/version-alpha-yellow.svg?style=flat-square) -![improvements](https://img.shields.io/badge/improvements-11-green.svg?style=flat-square) +![improvements](https://img.shields.io/badge/improvements-12-green.svg?style=flat-square) ![bug fixes](https://img.shields.io/badge/bug%20fixes-17-red.svg?style=flat-square) ![translations](https://img.shields.io/badge/translations-5-blue.svg?style=flat-square) @@ -17,6 +17,8 @@ - [x] Attack by id not by name (issue #241) - **Training** - [x] Added some clarification at the footnotes (#248) +- **Guild** + - [x] Guild storage: merchant shop info is enabled (shows total gold of storage items) (#290) - **Settings** - [x] Reduce exported settings size - [ ] Added settings export to player's notes functionality diff --git a/source/core/source/guild.storage.js b/source/core/source/guild.storage.js index 0e600e9f..e0207e51 100644 --- a/source/core/source/guild.storage.js +++ b/source/core/source/guild.storage.js @@ -10,6 +10,10 @@ var gca_guild_storage = { (gca_options.bool("global","item_shadow") && this.itemShadow.inject()); + // Fade non affordable items + (gca_options.bool("merchants","show_shop_info") && + this.containerItemsInfo.prepare()); + // Double click to sell/buy items (gca_options.bool("merchants","double_click_actions") && this.doubleClickActions.init()); @@ -40,6 +44,75 @@ var gca_guild_storage = { } }, + // Show information about shop's items + containerItemsInfo : { + prepare : function() { + // Exit if no inventory + if(!document.getElementById("shop")) return; + + // Create UI + this.infoBox = document.createElement("div"); + this.infoBox.className = "gca-shop-info"; + + this.infoRubies = document.createElement("span"); + this.infoBox.appendChild(this.infoRubies); + this.infoBox.appendChild(document.createTextNode(" ")); + this.infoBox.appendChild(gca_tools.create.rubiesIcon()); + + var space = document.createElement("span"); + space.style.display = 'inline-block'; + space.style.width = '8px'; + this.infoBox.appendChild(space); + + this.infoGold = document.createElement("span"); + this.infoBox.appendChild(this.infoGold); + this.infoBox.appendChild(document.createTextNode(" ")); + this.infoBox.appendChild(gca_tools.create.goldIcon()); + + document.getElementById("shop").parentNode.insertBefore(this.infoBox, document.getElementById("shop").nextSibling); + + // Show info + this.refresh(); + + // On item move + gca_tools.event.request.onAjaxResponse((data) => { + if ( + data.hasOwnProperty("data") && data.data && + data.data.hasOwnProperty("to") && data.data.to && + data.data.to.hasOwnProperty("data") && data.data.to.data && + data.elem.length === 1 + ) { + this.refresh(data.elem[0]); + } + }) + }, + + refresh : function(item = {dataset:{amount:0,itemId:0,priceGold:0,tooltip:''}}) { + // Get items + var items = document.getElementById('shop').getElementsByClassName('ui-draggable'); + // Count gold + let rubies = 0; + let gold = 0; + + //23
+ // For each item + for (var i = items.length - 1; i >= 0; i--) { + let itm = (item.dataset.itemId == items[i].dataset.itemId) ? item : items[i]; + let g = itm.dataset.amount * itm.dataset.priceGold; + let r = itm.dataset.tooltip.replace(/\./g, ''); + r = r.match(/(\d+)\s+(?:<|<)div class=\\(?:"|")icon_rubies\\(?:"|")(?:>|>)/i); + r = (r) ? parseInt(r[1], 10) : 0; + + if (!isNaN(g)) gold += g; + if (!isNaN(r)) rubies += r; + } + + // Display + this.infoRubies.textContent = gca_tools.strings.insertDots(rubies); + this.infoGold.textContent = gca_tools.strings.insertDots(gold); + } + }, + // Double click sell/buy doubleClickActions : { init : function(){