-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathMaterialsPanel.js
60 lines (53 loc) · 1.78 KB
/
MaterialsPanel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Created by Jerome Renaux (jerome.renaux@gmail.com) on 11-02-18.
*/
function MaterialsPanel(x,y,width,height,title){
Panel.call(this,x,y,width,height,title);
this.slotCounter = 0;
this.slots = [];
this.texts = [];
}
MaterialsPanel.prototype = Object.create(Panel.prototype);
MaterialsPanel.prototype.constructor = MaterialsPanel;
MaterialsPanel.prototype.getNextSlot = function(){
if(this.slotCounter >= this.slots.length){
this.slots.push(new LongSlot(100));
}
return this.slots[this.slotCounter++];
};
MaterialsPanel.prototype.displayMaterials = function(){
var materials = Engine.buildingsData[Engine.currentBuiling.buildingType].recipe;
if(!materials) return;
var keys = Object.keys(materials);
for(var i = 0; i < keys.length; i++) {
var item = keys[i];
var nb = materials[item];
var slot = this.getNextSlot();
var x = (this.width-slot.totalwidth)/2;
slot.setUp(this.x+x, this.y + 20 + (i++ * 50));
var itemData = Engine.itemsData[item];
slot.addIcon(itemData.atlas,itemData.frame);
slot.addText(43,2,itemData.name,null,13);
var owned = Engine.currentBuiling.getItemNb(item);
slot.addText(43,17,owned+'/'+nb,(owned >= nb ? Utils.colors.green : Utils.colors.red),13);
slot.display();
}
};
MaterialsPanel.prototype.hideInterface = function(){
this.slots.forEach(function(s){
s.hide();
});
this.slotsCounter = 0;
};
MaterialsPanel.prototype.update = function(){
this.hideInterface();
this.displayMaterials();
};
MaterialsPanel.prototype.display = function(){
Panel.prototype.display.call(this);
this.displayMaterials();
};
MaterialsPanel.prototype.hide = function(){
Panel.prototype.hide.call(this);
this.hideInterface();
};