-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathRecipesPanel.js
77 lines (58 loc) · 2.39 KB
/
RecipesPanel.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Created by Jerome Renaux (jerome.renaux@gmail.com) on 24-03-19.
*/
import Client from './Client'
import Engine from './Engine'
import ItemSlot from './ItemSlot'
import ShopInventoryPanel from './ShopInventoryPanel'
import UI from './UI'
import Utils from '../shared/Utils'
import TutorialManager from './TutorialManager'
import itemsData from '../assets/data/items.json'
function RecipesPanel(x,y,width,height,title,invisible){
ShopInventoryPanel.call(this,x,y,width,height,title,invisible);
}
RecipesPanel.prototype = Object.create(ShopInventoryPanel.prototype);
RecipesPanel.prototype.constructor = RecipesPanel;
RecipesPanel.prototype.getNextSlot = function(x,y){
if(this.slotsCounter >= this.slots.length){
this.slots.push(new RecipeSlot(x,y,360,80));
}
return this.slots[this.slotsCounter++];
};
// -------------------------------------
function RecipeSlot(x,y,width,height){
ItemSlot.call(this,x,y,width,height);
this.addIngredients();
this.content.forEach(function(c){
c.setScrollFactor(0);
c.setDepth(1);
});
}
RecipeSlot.prototype = Object.create(ItemSlot.prototype);
RecipeSlot.prototype.constructor = RecipeSlot;
RecipeSlot.prototype.addIngredients = function(){
this.ingredients = UI.scene.add.text(this.x + this.width - 10, this.y + this.height - 25, '0/4', { font: '16px '+Utils.fonts.fancy, fill: '#ffffff', stroke: '#000000', strokeThickness: 3 });
this.ingredients.setOrigin(1,0);
this.content.push(this.ingredients);
};
RecipeSlot.prototype.setUp = function(action,item,nb){
ItemSlot.prototype.setUp.call(this,action,item,nb);
var status = Engine.player.needsToCraft(item);
var itemData = itemsData[item];
if(itemData.ability && !Engine.player.hasAbility(itemData.ability)){
this.ingredients.setText('Ability needed');
this.ingredients.setFill(Utils.colors.red);
}else {
this.ingredients.setText(status[0]+'/'+status[1]);
this.ingredients.setFill(status[0] == status[1] ? Utils.colors.green : Utils.colors.red);
}
this.price.setText(Engine.currentBuiling.getPrice(item,'sell'));
this.zone.off('pointerup');
this.zone.on('pointerup',function(){
if(this.checkForPanelOnTop()) return;
Engine.currentMenu.panels['combi'].setUp(item);
if(Client.tutorial) TutorialManager.triggerHook('recipe:'+item);
}.bind(this));
};
export default RecipesPanel