Skip to content

Commit

Permalink
Merchants info is now enabled in guild storage
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatApo committed Nov 7, 2021
1 parent d8623ba commit 4c32075
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
4 changes: 3 additions & 1 deletion PROGRESS.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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
Expand Down
73 changes: 73 additions & 0 deletions source/core/source/guild.storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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 <div class="icon_rubies">
// 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+(?:<|&lt;)div class=\\(?:"|&quot;)icon_rubies\\(?:"|&quot;)(?:>|&gt;)/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(){
Expand Down

0 comments on commit 4c32075

Please sign in to comment.