-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathRepairPanel.js
117 lines (99 loc) · 3.5 KB
/
RepairPanel.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* Created by Jerome Renaux (jerome.renaux@gmail.com) on 31-08-19.
*/
import BigButton from './BigButton'
import Engine from './Engine'
import {BigProgressBar} from './ProgressBar'
import Panel from './Panel'
import Utils from '../shared/Utils'
import itemsData from '../assets/data/items.json'
function RepairPanel(x,y,width,height,title){
Panel.call(this,x,y,width,height,title);
this.texts = [];
this.bigbuttons = [];
this.addInterface();
}
RepairPanel.prototype = Object.create(Panel.prototype);
RepairPanel.prototype.constructor = RepairPanel;
RepairPanel.prototype.addInterface = function(){
this.addText(this.width/2,25,'Building integrity',null,20).setOrigin(0.5);
var barw = this.width-100;
var barx = (this.width-barw)/2;
this.bar = new BigProgressBar(this.x+barx,this.y+50,barw,'gold');
this.bar.moveUp(2);
this.bar.name = 'repair progress bar';
};
RepairPanel.prototype.displayInterface = function(){
this.bar.display();
this.displayTexts();
var slot = this.getNextLongSlot();
var y = this.y + 100;
slot.setUp(this.x+20, y);
var item = 3; // timber
var itemData = itemsData[item];
slot.addIcon(itemData.atlas,itemData.frame);
slot.addText(43,2,itemData.name,null,13);
var player_owned = Engine.player.getItemNb(item);
var txt = slot.addText(152,slot.height-3,player_owned,Utils.colors.white,13);
txt.setOrigin(1,1);
slot.addImage(161, slot.height-10, 'UI', 'smallpack');
var price = Engine.currentBuiling.getPrice(item,'buy');
var priceTxt = price || '--';
var t = slot.addText(152,12,priceTxt,Utils.colors.white,13);
t.setOrigin(1,0.5);
slot.addImage(160, 13, 'UI', 'gold');
slot.moveUp(2);
slot.display();
var panel_ = this;
var btn = new BigButton(this.x+270,y+20,'Give '+itemData.name);
btn.item = item;
btn.callback = function(){
// if(panel_.checkForPanelOnTop()) return;
Engine.repairAction.display();
Engine.repairAction.setUp(this.item,'sell',false); // false = force non-financial
}.bind(btn);
btn.display();
// if(Engine.currentBuiling.isFullyRepaired()) btn.disable();
this.bigbuttons.push(btn);
if(!Engine.currentBuiling.isOwned() && price > 0) {
var btn = new BigButton(this.x + 410, y + 20, 'Sell ' + itemData.name);
btn.item = item;
btn.callback = function(){
// if(panel_.checkForPanelOnTop()) return;
Engine.repairAction.display();
Engine.repairAction.setUp(this.item,'sell',true); // true = force financial
}.bind(btn);
btn.display();
if(Engine.currentBuiling.isFullyRepaired()) btn.disable();
this.bigbuttons.push(btn);
}
this.bigbuttons.forEach(function(btn){
btn.moveUp(2);
});
this.bar.setLevel(Engine.currentBuiling.stats['hp'].getValue(),Engine.currentBuiling.stats['hpmax'].getValue());
};
RepairPanel.prototype.update = function(){
this.hideLongSlots();
this.bigbuttons.forEach(function(btn){
btn.hide();
});
this.displayInterface();
};
RepairPanel.prototype.hideInterface = function(){
this.bar.hide();
this.bigbuttons.forEach(function(b){
b.hide();
});
this.hideTexts();
this.hideLongSlots();
};
RepairPanel.prototype.display = function(){
Panel.prototype.display.call(this);
this.displayInterface();
};
RepairPanel.prototype.hide = function(){
Panel.prototype.hide.call(this);
Engine.repairAction.hide();
this.hideInterface();
};
export default RepairPanel