-
Notifications
You must be signed in to change notification settings - Fork 1
/
TileInfoView.js
79 lines (63 loc) · 2.67 KB
/
TileInfoView.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
var TileBriefView = {
// fonts list
fontBrief: [
{font: "40px myKaiti", fill: "white", boundsAlignH: "top", boundsAlignV: "middle"},
{font: "30px myKaiti", fill: "orange", boundsAlignH: "top", boundsAlignV: "middle"}
],
createNew: function(index) {
console.assert(index || index === 0);
var view = MainGame.game.add.sprite(0, 0, "tile_hover_backpanel");
var tile = MainGame.board.at(index);
var labelText = '';
var textPosition;
if (tile.hasBuilding()) {
labelText = tile.getBuilding().playerLabel;
textPosition = view.height/4;
// If the building is under construction
if (tile.getBuilding().startingTurn > MainGame.global.turn) {
view.underConst = MainGame.game.make.text(0, 0, 'Under Construction', this.fontBrief[1]);
view.underConst.x = view.width/2 - view.underConst.width/2
view.underConst.y = view.height/2;
view.addChild(view.underConst);
} else {
// Do some setup before we go
TileBriefView.setUpOccupancyDisplay(view, tile.getBuilding().people, tile.getBuilding().maxPeople);
}
} else {
labelText = tile.terrainLabel;
textPosition = view.height/2;
}
view.label = MainGame.game.make.text(view.width/2, textPosition, labelText, this.fontBrief[0]);
view.label.anchor.set(0.5);
view.addChild(view.label);
// Class vars
view.index = index;
// Class func
view.updatePos = function() { return TileBriefView.updatePos(view) };
return view;
},
updatePos: function(view) {
/*global MainGame*/
var board = MainGame.board;
var tile = board.at(view.index);
view.x = board.x + tile.x*board.currentScale;
view.y = board.y + (tile.y + tile.height*7)*board.currentScale;
view.scale.set(board.currentScale);
},
setUpOccupancyDisplay: function(view, occupantCount, maxSize) {
var occupancyDisplay = MainGame.game.make.sprite(0, view.height/2);
var occupantWidth = MainGame.game.make.sprite(0, 0, 'worker_icon').width;
for (var i = 0; i < maxSize; i++) {
occupant = MainGame.game.make.sprite(0, 0, 'worker_icon');
occupant.x = occupant.width*0.5*i;
// Tint it to show occupancy
if (i < occupantCount) {
occupant.tint = 0x00ff00;
}
occupancyDisplay.addChild(occupant);
}
// Center the bar
occupancyDisplay.x = -occupantWidth/4 + (view.width/2) - ((occupantWidth*maxSize*0.5)/2);
view.addChild(occupancyDisplay);
},
};