Commit c4777d89 authored by Jyrki's avatar Jyrki 🐾

the buy button is now disabled if we don't have enough moneys

parent 82103ce2
......@@ -214,6 +214,8 @@ $(document).ready -> updateCounters()
setPriceLabels = (type) ->
selectorBuy = "span#market-price-#{type}-buy"
selectorSell = "span#market-price-#{type}-sell"
selectorValue = "span[name=market-#{type}-val]"
selectorBuyButton = "button[name=market-buy][data-type=#{type}]"
switch type
when "wheat"
......@@ -229,8 +231,17 @@ setPriceLabels = (type) ->
buyPrice = window.gameVars.prices.buy.cattleGrid
sellPrice = window.gameVars.prices.sell.cattleGrid
$(selectorBuy).html Number($("span[name=market-#{type}-val]").html()) * buyPrice
$(selectorSell).html Number($("span[name=market-#{type}-val]").html()) * sellPrice
buyPrice *= Number($(selectorValue).html())
sellPrice *= Number($(selectorValue).html())
# check if we can even buy this shizzle
if buyPrice > window.gameVars.gold
$(selectorBuyButton).attr "disabled", "disabled"
else
$(selectorBuyButton).removeAttr "disabled"
$(selectorBuy).html buyPrice
$(selectorSell).html sellPrice
return true
......
......@@ -119,7 +119,7 @@
<div class="row">
<div class="col-md-6">
<p class="market-price text-center text-success">...for <span id="market-price-wheat-buy">{n}</span> gold.</p>
<button class="btn btn-market btn-block btn-success">Buy <span name="market-wheat-val">{n}</span> Wheat</button>
<button class="btn btn-market btn-block btn-success" name="market-buy" data-type="wheat">Buy <span name="market-wheat-val">{n}</span> Wheat</button>
</div>
<div class="col-md-6">
<p class="market-price text-center text-danger">...for <span id="market-price-wheat-sell">{n}</span> gold.</p>
......@@ -138,7 +138,7 @@
<div class="row">
<div class="col-md-6">
<p class="market-price text-center text-success">...for <span id="market-price-livestock-buy">{n}</span> gold.</p>
<button class="btn btn-market btn-block btn-success">Buy <span name="market-livestock-val">{n}</span> Livestock</button>
<button class="btn btn-market btn-block btn-success" name="market-buy" data-type="livestock">Buy <span name="market-livestock-val">{n}</span> Livestock</button>
</div>
<div class="col-md-6">
<p class="market-price text-center text-danger">...for <span id="market-price-livestock-sell">{n}</span> gold.</p>
......@@ -157,7 +157,7 @@
<div class="row">
<div class="col-md-6">
<p class="market-price text-center text-success">...for <span id="market-price-fields-buy">{n}</span> gold.</p>
<button class="btn btn-market btn-block btn-success">Buy <span name="market-fields-val">{n}</span> Fields</button>
<button class="btn btn-market btn-block btn-success" name="market-buy" data-type="fields">Buy <span name="market-fields-val">{n}</span> Fields</button>
</div>
<div class="col-md-6">
<p class="market-price text-center text-danger">...for <span id="market-price-fields-sell">{n}</span> gold.</p>
......@@ -176,7 +176,7 @@
<div class="row">
<div class="col-md-6">
<p class="market-price text-center text-success">...for <span id="market-price-cattle-buy">{n}</span> gold.</p>
<button class="btn btn-market btn-block btn-success">Buy <span name="market-cattle-val">{n}</span> Cattle Grids</button>
<button class="btn btn-market btn-block btn-success" name="market-buy" data-type="cattle">Buy <span name="market-cattle-val">{n}</span> Cattle Grids</button>
</div>
<div class="col-md-6">
<p class="market-price text-center text-danger">...for <span id="market-price-cattle-sell">{n}</span> gold.</p>
......
......@@ -232,9 +232,11 @@
});
setPriceLabels = function(type) {
var buyPrice, selectorBuy, selectorSell, sellPrice;
var buyPrice, selectorBuy, selectorBuyButton, selectorSell, selectorValue, sellPrice;
selectorBuy = "span#market-price-" + type + "-buy";
selectorSell = "span#market-price-" + type + "-sell";
selectorValue = "span[name=market-" + type + "-val]";
selectorBuyButton = "button[name=market-buy][data-type=" + type + "]";
switch (type) {
case "wheat":
buyPrice = window.gameVars.prices.buy.wheat;
......@@ -252,8 +254,15 @@
buyPrice = window.gameVars.prices.buy.cattleGrid;
sellPrice = window.gameVars.prices.sell.cattleGrid;
}
$(selectorBuy).html(Number($("span[name=market-" + type + "-val]").html()) * buyPrice);
$(selectorSell).html(Number($("span[name=market-" + type + "-val]").html()) * sellPrice);
buyPrice *= Number($(selectorValue).html());
sellPrice *= Number($(selectorValue).html());
if (buyPrice > window.gameVars.gold) {
$(selectorBuyButton).attr("disabled", "disabled");
} else {
$(selectorBuyButton).removeAttr("disabled");
}
$(selectorBuy).html(buyPrice);
$(selectorSell).html(sellPrice);
return true;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment