forked from plainblack/Lacuna-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildingEntertainment.js
123 lines (110 loc) · 5.27 KB
/
buildingEntertainment.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
118
119
120
121
122
123
YAHOO.namespace("lacuna.buildings");
if (typeof YAHOO.lacuna.buildings.Entertainment == "undefined" || !YAHOO.lacuna.buildings.Entertainment) {
(function(){
var Util = YAHOO.util,
Dom = Util.Dom,
Event = Util.Event,
Lacuna = YAHOO.lacuna,
Game = Lacuna.Game,
Lib = Lacuna.Library;
var Entertainment = function(result){
Entertainment.superclass.constructor.call(this, result);
this.service = Game.Services.Buildings.Entertainment;
this.lotteryAllVotedMessage = "You have voted as many times as you could today. Please check back tomorrow for your next chance!";
};
YAHOO.lang.extend(Entertainment, Lacuna.buildings.Building, {
getChildTabs : function() {
return [this._getLotteryTab(),this._getDuckTab()];
},
_getLotteryTab : function() {
var tab = new YAHOO.widget.Tab({ label: "Lottery", content: ['<p id="entertainmentLotteryMessage">Welcome to the Lacuna Lottery! Get entered in the Expanse\'s daily lottery for a chance to win 10 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" />! Each link clicked below gives you one extra chance to win. Links will be removed after voting and return tomorrow.</p><div><ul id="entertainmentLotteryList"></ul></div>'].join('')});
tab.subscribe("activeChange", this.LotteryView, this, true);
return tab;
},
_getDuckTab : function() {
var tab = new YAHOO.widget.Tab({ label: "Duck", content: [
'<div id="entertainmentTotalQuacks"></div>',
'<div><button type="button" id="entertainmentQuack">Quack</button></div>',
'<hr />',
'<div><pre id="entertainmentDuckMessage"></pre></div>'
].join('')});
Event.on("entertainmentQuack", "click", this.Quack, this, true);
this.subscribe("onLoad", this.SetQuacks, this, true);
return tab;
},
LotteryView : function(e) {
if(e.newValue) {
Lacuna.Pulser.Show();
this.service.get_lottery_voting_options({session_id:Game.GetSession(),building_id:this.building.id}, {
success : function(o){
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
this.LotteryPopulate(o.result.options);
},
scope:this
});
}
},
LotteryPopulate : function(options) {
var details = Dom.get("entertainmentLotteryList");
if(details) {
var li = document.createElement("li");
Event.purgeElement(details);
details.innerHTML = "";
Dom.setStyle(details.parentNode,"height","");
Dom.setStyle(details.parentNode,"overflow-y","");
if(options.length == 0) {
li.innerHTML = this.lotteryAllVotedMessage;
details.appendChild(li);
}
else {
for(var i=0; i<options.length; i++) {
var vote = options[i],
nLi = li.cloneNode(false);
nLi.innerHTML = ['<a href="',vote.url,'" target="_blank">',vote.name,'</a>'].join('');
Event.on(nLi, "click", this.LotteryVoted, this);
details.appendChild(nLi);
}
//wait for tab to display first
setTimeout(function() {
var Ht = Game.GetSize().h - 200;
if(Ht > 300) { Ht = 300; }
Dom.setStyle(details.parentNode,"height",Ht + "px");
Dom.setStyle(details.parentNode,"overflow-y","auto");
},10);
}
}
},
LotteryVoted : function(e, oSelf) {
var li = Event.getTarget(e);
if(li) {
Event.removeListener(li, "click");
var ul = li.parentNode;
ul.removeChild(li);
if(ul.children && ul.children.length == 0) {
ul.innerHTML = ['<li>',this.lotteryAllVotedMessage,'</li>'].join('');
}
}
},
SetQuacks : function() {
Dom.get("entertainmentTotalQuacks").innerHTML = ['There have been a total of ', this.result.ducks_quacked || 0, ' ducks quacked.'].join('');
},
Quack : function() {
Lacuna.Pulser.Show();
this.service.duck_quack({session_id:Game.GetSession(),building_id:this.building.id}, {
success : function(o){
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
this.result.ducks_quacked++;
this.SetQuacks();
Dom.get("entertainmentDuckMessage").innerHTML = o.result;
},
scope:this
});
}
});
Lacuna.buildings.Entertainment = Entertainment;
})();
YAHOO.register("Entertainment", YAHOO.lacuna.buildings.Entertainment, {version: "1", build: "0"});
}
// vim: noet:ts=4:sw=4