Added Selling + Big Inventory Tooltips

This commit is contained in:
MasterGordon 2018-04-02 13:00:53 +02:00
parent 64e23f0887
commit 662e791c76
5 changed files with 53 additions and 33 deletions

View File

@ -87,7 +87,7 @@ body {
.itemBig { .itemBig {
width: 72; width: 72;
height: 72; height: 72;
background-image: url(../images/inventorybg.png); /*background-image: url(../images/inventorybg.png);*/
} }
#showmore { #showmore {

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

View File

@ -212,6 +212,44 @@ function prepairRender() {
$('#buildselect').hide() $('#buildselect').hide()
$('#inventoryBig').hide() $('#inventoryBig').hide()
buildEvents() buildEvents()
//Build Sell/Select Items Menu
for (var i = 0; i < items.length; i++) {
$('#itemsScroll').append('<canvas class="itemBig" id="itemBig_' + i + '"></canvas>')
$('#itemBig_' + i)[0].width = 72
$('#itemBig_' + i)[0].height = 72
}
$('canvas').hover(
function() {
//ENTER
var id = $(this).attr("id");
if (id.startsWith("itemBig_")) {
id = parseInt(id.substr(8))
if (id < itemId.length) {
hoverTooltip = true
$('#tooltip').text(lang.items[itemId[id]] + " (" + formatCount(items[itemId[id]].value) + " " + lang.items[0] + ")")
$('#tooltip').show()
tooltip = true
}
}
},
function() {
//LEAVE
hoverTooltip = false
}
);
$('canvas').click(
function() {
//ENTER
var id = $(this).attr("id");
if (id.startsWith("itemBig_")) {
id = parseInt(id.substr(8))
if (id < itemId.length) {
if(inventory.take(itemId[id],1)){
money += items[itemId[id]].value
}
}
}
})
$('#clickToSell').text(lang.clickToSell) $('#clickToSell').text(lang.clickToSell)
} }

View File

@ -227,6 +227,9 @@ function setTooltip() {
tooltip = false tooltip = false
} }
var itemId = []
var itemCount = []
function buildEvents() { function buildEvents() {
$('img').click(function() { $('img').click(function() {
var id = $(this).attr("id"); var id = $(this).attr("id");
@ -371,8 +374,6 @@ function closeUi() {
} }
} }
var itemId = []
var itemCount = []
function drawInventory(inventory, title) { function drawInventory(inventory, title) {
if (!(inventory instanceof Inventory)) if (!(inventory instanceof Inventory))
@ -425,6 +426,9 @@ function drawInventory(inventory, title) {
} }
} }
var itembg = new Image
itembg.src = "images/inventorybg.png"
function drawBigInventory(inventory) { function drawBigInventory(inventory) {
if (!(inventory instanceof Inventory)) if (!(inventory instanceof Inventory))
return false; return false;
@ -441,25 +445,17 @@ function drawBigInventory(inventory) {
itemCount[index]++ itemCount[index]++
} }
} }
for(var i=0;i<items.length;i++){
//inventoryCtx.clearRect(0, 0, innerWidth, innerHeight) $('#itemBig_' + i)[0].getContext("2d").clearRect(0, 0, 72, 72)
//inventoryCtx.font = "20px Electrolize" }
//inventoryCtx.fillStyle = "#a3a3a3"
//inventoryCtx.fillRect(0, 0, 25 * 48, 24);
//inventoryCtx.fillStyle = "black"
//inventoryCtx.fillText(lang.inventory + " - " + title, 2, 18)
//inventoryCtx.fillStyle = "black"
//inventoryCtx.textAlign = "start"
var currentIndex = 0 var currentIndex = 0
$('#itemsScroll').empty()
while (currentIndex != itemId.length) { while (currentIndex != itemId.length) {
$('#itemsScroll').append('<canvas class="itemBig" style="width: 72; height: 72" id="itemBig_' + itemId[currentIndex] + '"></canvas>') var itemCtx = $('#itemBig_' + currentIndex)[0].getContext("2d")
$('#itemBig_' + itemId[currentIndex])[0].width = 72;
$('#itemBig_' + itemId[currentIndex])[0].height = 72
var itemCtx = $('#itemBig_' + itemId[currentIndex])[0].getContext("2d")
var img = new Image var img = new Image
img.src = "images/items/" + items[itemId[currentIndex]].name + ".png" img.src = "images/items/" + items[itemId[currentIndex]].name + ".png"
itemCtx.clearRect(0, 0, innerWidth, innerHeight)
itemCtx.font = "16px Electrolize" itemCtx.font = "16px Electrolize"
itemCtx.drawImage(itembg, 0, 0, 72, 72)
itemCtx.drawImage(img, 12, 12, 48, 48) itemCtx.drawImage(img, 12, 12, 48, 48)
var formattedCount = formatCount(itemCount[currentIndex]) var formattedCount = formatCount(itemCount[currentIndex])
@ -470,19 +466,5 @@ function drawBigInventory(inventory) {
itemCtx.fillText("x" + formattedCount, 4, 67) itemCtx.fillText("x" + formattedCount, 4, 67)
currentIndex++ currentIndex++
$('#itemBig_' + itemId[currentIndex]).hover(
function() {
//ENTER
console.log("TRIGGER")
hoverTooltip = true
$('#tooltip').text(lang.items[itemId[currentIndex]] + "(" + formatCount(items[itemId[currentIndex]].value) + " " + lang.items[0] + ")")
$('#tooltip').show()
tooltip = true
},
function() {
//LEAVE
hoverTooltip = false
}
);
} }
} }

View File

@ -18,7 +18,7 @@
} }
}, },
"items": ["Dollars", "Log", "Planks"], "items": ["Dollars", "Log", "Planks"],
"more": "Sell Items", "more": "Show Inventory / Sell Items",
"inventory": "Inventory", "inventory": "Inventory",
"player": "Player", "player": "Player",
"infotooltips": ["Build", "Move", "Rotate", "Delete!", "", "Upgrade", "Information", "", "Go To Space!!"], "infotooltips": ["Build", "Move", "Rotate", "Delete!", "", "Upgrade", "Information", "", "Go To Space!!"],