forked from plainblack/Lacuna-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildingArchaeology.js
425 lines (381 loc) · 12.4 KB
/
buildingArchaeology.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
YAHOO.namespace("lacuna.buildings");
if (typeof YAHOO.lacuna.buildings.Archaeology == "undefined" || !YAHOO.lacuna.buildings.Archaeology) {
(function(){
var Lang = YAHOO.lang,
Util = YAHOO.util,
DDM = Util.DragDropMgr,
Dom = Util.Dom,
Event = Util.Event,
Sel = Util.Selector,
Lacuna = YAHOO.lacuna,
Game = Lacuna.Game,
Lib = Lacuna.Library;
var DDList = function(id, sGroup, config) {
DDList.superclass.constructor.call(this, id, sGroup, config);
var el = this.getDragEl();
Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent
this.goingUp = false;
this.lastY = 0;
};
YAHOO.extend(DDList, YAHOO.util.DDProxy, {
startDrag: function(x, y) {
// make the proxy look like the source element
var dragEl = this.getDragEl();
var clickEl = this.getEl();
Dom.setStyle(clickEl, "visibility", "hidden");
dragEl.innerHTML = clickEl.innerHTML;
Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));
Dom.setStyle(dragEl, "backgroundColor", Dom.getStyle(clickEl, "backgroundColor"));
Dom.setStyle(dragEl, "border", "2px solid gray");
Dom.setStyle(dragEl, "zIndex", Dom.getStyle("buildingDetails_c", "zIndex")*1+1);
},
endDrag: function(e) {
var srcEl = this.getEl();
var proxy = this.getDragEl();
// Show the proxy element and animate it to the src element's location
Dom.setStyle(proxy, "visibility", "");
var a = new YAHOO.util.Motion(
proxy, {
points: {
to: Dom.getXY(srcEl)
}
},
0.2,
YAHOO.util.Easing.easeOut
);
var proxyid = proxy.id;
var thisid = this.id;
// Hide the proxy and show the source element when finished with the animation
a.onComplete.subscribe(function() {
Dom.setStyle(proxyid, "visibility", "hidden");
Dom.setStyle(thisid, "visibility", "");
});
a.animate();
},
onDragDrop: function(e, id) {
if (id == "archaeologyGlyphDetails" || id == "archaeologyGlyphCombine") {
// The position of the cursor at the time of the drop (YAHOO.util.Point)
var pt = DDM.interactionInfo.point;
// The region occupied by the source element at the time of the drop
var region = DDM.interactionInfo.sourceRegion;
// Check to see if we are over the source element's location. We will
// append to the bottom of the list once we are sure it was a drop in
// the negative space (the area of the list without any list items)
if (!region.intersect(pt)) {
var destEl = Dom.get(id);
var destDD = DDM.getDDById(id);
destEl.appendChild(this.getEl());
destDD.isEmpty = false;
DDM.refreshCache();
}
}
},
onDrag: function(e) {
// Keep track of the direction of the drag for use during onDragOver
var y = Event.getPageY(e);
if (y < this.lastY) {
this.goingUp = true;
} else if (y > this.lastY) {
this.goingUp = false;
}
this.lastY = y;
},
onDragOver: function(e, id) {
var srcEl = this.getEl();
var destEl = Dom.get(id);
// We are only concerned with list items, we ignore the dragover
// notifications for the list.
if (destEl.nodeName.toLowerCase() == "li") {
var orig_p = srcEl.parentNode;
var p = destEl.parentNode;
if (this.goingUp) {
p.insertBefore(srcEl, destEl); // insert above
} else {
p.insertBefore(srcEl, destEl.nextSibling); // insert below
}
DDM.refreshCache();
}
}
});
var Archaeology = function(result){
Archaeology.superclass.constructor.call(this, result);
this.service = Game.Services.Buildings.Archaeology;
};
Lang.extend(Archaeology, Lacuna.buildings.Building, {
getChildTabs : function() {
return [this._getSearchTab(), this._getViewTab()];
},
_getSearchTab : function() {
var tab = new YAHOO.widget.Tab({ label: "Search", content: [
'<div id="archaeologySearchContainer">',
' <ul id="archaeologySearchForm">',
' <li>Search Ore:<select id="archaeologyOre"></select></li>',
' <li><button type="button" id="archaeologySearch">Search</button></li>',
' </ul>',
' <ul id="archaeologySearchNone" style="display: none">',
' <li>Not enough ore available to search.</li>',
' </ul>',
'</div>',
'<div id="archaeologyWorkingContainer">',
' <ul>',
' <li>Time left on current search: <span id="archaeologySearchTime"></span></li>',
' <li>You may subsidize the search for 2 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" />.</li>',
' <li><button type="button" id="archaeologySearchSubsidize">Subsidize</button></li>',
' </ul>',
'</div>'
].join('')});
tab.subscribe("activeChange", function(e) {
if(e.newValue) {
this.checkIfWorking();
}
}, this, true);
this.searchTab = tab;
Event.on("archaeologySearch", "click", this.searchForGlyph, this, true);
Event.on("archaeologySearchSubsidize", "click", this.Subsidize, this, true);
return tab;
},
_getViewTab : function() {
var tab = new YAHOO.widget.Tab({ label: "View Glyphs", content: [
'<div class="clearafter">',
' <div class="archaeologySlots">',
' <label>Available Glyphs</label>',
' <ul id="archaeologyGlyphDetails" class="archaeologyGlyphInfo">',
' </ul>',
' </div>',
' <div class="archaeologySlots">',
' <label>Combine Glyphs</label>',
' <ul id="archaeologyGlyphCombine" class="archaeologyGlyphInfo">',
' </ul>',
' <div><button type="button" id="archaeologyCombine">Combine</button></div>',
' </div>',
'</div>'
].join('')});
tab.subscribe("activeChange", function(e) {
if(e.newValue) {
this.getGlyphs();
}
}, this, true);
Event.onAvailable("archaeologyCombine", function(e){
Event.on("archaeologyCombine", "click", this.assembleGlyph, this, true);
}, this, true);
this.viewTab = tab;
return tab;
},
populateSearch : function() {
var sel = Dom.get("archaeologyOre");
if(sel && this.ore){
sel.options.length = 0;
var opt = document.createElement("option");
for(var oKey in this.ore) {
if(this.ore.hasOwnProperty(oKey)) {
var nOpt = opt.cloneNode(false);
nOpt.value = oKey;
nOpt.innerHTML = [oKey, ' (', this.ore[oKey], ')'].join('');
sel.appendChild(nOpt);
}
}
if (sel.options.length > 0) {
Dom.setStyle("archaeologySearchForm", "display", "");
Dom.setStyle("archaeologySearchNone", "display", "none");
}
else {
Dom.setStyle("archaeologySearchForm", "display", "none");
Dom.setStyle("archaeologySearchNone", "display", "");
}
}
},
populateActiveSearch : function(seconds_remaining) {
this.addQueue(seconds_remaining, this.searchQueue, "archaeologySearchTime");
},
searchQueue : function(remaining, el){
if(remaining <= 0) {
var span = Dom.get(el),
p = span.parentNode;
p.removeChild(span);
p.innerHTML = "Search Complete";
}
else {
Dom.get(el).innerHTML = Lib.formatTime(Math.round(remaining));
}
},
populateView : function() {
var glyphs = this.glyphs,
details = Dom.get("archaeologyGlyphDetails");
if(details) {
if(!this.glyphList) {
this.glyphList = new Util.DDTarget("archaeologyGlyphDetails");
this.glyphList.isGlyphContainer = true;
}
else {
var gl = Sel.query("li", "archaeologyGlyphDetails");
for(var gli=0, glLen=gl.length; gli<glLen; gli++) {
var glio = gl[gli];
glio.DD.unreg();
glio.parentNode.removeChild(glio);
glio = null;
}
}
if(!this.glyphCombine) {
this.glyphCombine = new Util.DDTarget("archaeologyGlyphCombine");
this.glyphCombine.isGlyphContainer = true;
}
else {
var gc = Sel.query("li", "archaeologyGlyphCombine");
for(var gci=0, gcLen=gc.length; gci<gcLen; gci++) {
var gcio = gc[gci];
gcio.DD.unreg();
gcio.parentNode.removeChild(gcio);
gcio = null;
}
}
var li = document.createElement("li");
for(var i=0; i<glyphs.length; i++) {
var obj = glyphs[i],
nLi = li.cloneNode(false);
nLi.Glyph = obj;
Dom.addClass(nLi,"archaeologyGlyph");
nLi.innerHTML = [
'<div class="archaeologyGlyphContainer">',
' <div class="archaeologyGlyphHeader">',obj.type,'</div>',
' <img src="',Lib.AssetUrl,'glyphs/',obj.type,'.png" alt="',obj.type,'" title="',obj.type,'" style="width:119px;height:150px;" />', //"width:158px;height:200px;"
'</div>'
].join('');
nLi = details.appendChild(nLi);
nLi.DD = new DDList(nLi);
}
}
},
checkIfWorking : function() {
if(this.work && this.work.seconds_remaining) {
Dom.setStyle("archaeologySearchContainer", "display", "none");
Dom.setStyle("archaeologyWorkingContainer", "display", "");
this.populateActiveSearch(this.work.seconds_remaining);
}
else {
Dom.setStyle("archaeologySearchContainer", "display", "");
Dom.setStyle("archaeologyWorkingContainer", "display", "none");
this.getOres();
}
},
getOres : function() {
if(!this.ore) {
Lacuna.Pulser.Show();
this.service.get_ores_available_for_processing({session_id:Game.GetSession(),building_id:this.building.id}, {
success : function(o){
YAHOO.log(o, "info", "Archaeology.getOres.success");
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
this.ore = o.result.ore;
this.populateSearch();
},
failure : function(o){
YAHOO.log(o, "error", "Archaeology.getOres.failure");
Lacuna.Pulser.Hide();
this.rpcFailure(o);
},
timeout:Game.Timeout,
scope:this
});
}
},
getGlyphs : function() {
if(!this.glyphs) {
Lacuna.Pulser.Show();
this.service.get_glyphs({session_id:Game.GetSession(),building_id:this.building.id}, {
success : function(o){
YAHOO.log(o, "info", "Archaeology.getGlyphs.success");
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
this.glyphs = o.result.glyphs;
this.populateView();
},
failure : function(o){
YAHOO.log(o, "error", "Archaeology.getGlyphs.failure");
Lacuna.Pulser.Hide();
this.rpcFailure(o);
},
timeout:Game.Timeout,
scope:this
});
}
},
assembleGlyph : function() {
Lacuna.Pulser.Show();
var glyphs = Sel.query("li", "archaeologyGlyphCombine"),
glyphIds = [];
for(var g=0, len=glyphs.length; g<len; g++) {
glyphIds.push(glyphs[g].Glyph.id);
}
this.service.assemble_glyphs({session_id:Game.GetSession(),building_id:this.building.id, ids:glyphIds}, {
success : function(o){
YAHOO.log(o, "info", "Archaeology.assembleGlyph.success");
alert("You have found a " + o.result.item_name + "!");
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
delete this.glyphs;
this.getGlyphs();
},
failure : function(o){
YAHOO.log(o, "error", "Archaeology.assembleGlyph.failure");
Lacuna.Pulser.Hide();
this.rpcFailure(o);
},
timeout:Game.Timeout,
scope:this
});
},
searchForGlyph : function() {
Lacuna.Pulser.Show();
var sel = Dom.get("archaeologyOre"),
opts = sel.options,
selInd = sel.selectedIndex,
type = opts.length > 0 && selInd >= 0 && opts[selInd].value;
if(type) {
this.service.search_for_glyph({session_id:Game.GetSession(),building_id:this.building.id,ore_type:type}, {
success : function(o){
YAHOO.log(o, "info", "Archaeology.searchForGlyph.success");
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
//this.work = o.result.building.work;
//this.updateBuildingTile(o.result.building);
this.checkIfWorking();
},
failure : function(o){
YAHOO.log(o, "error", "Archaeology.searchForGlyph.failure");
Lacuna.Pulser.Hide();
this.rpcFailure(o);
},
timeout:Game.Timeout,
scope:this
});
}
},
Subsidize : function() {
Lacuna.Pulser.Show();
this.service.subsidize_search({
session_id:Game.GetSession(),
building_id:this.building.id
}, {
success : function(o){
Lacuna.Pulser.Hide();
this.rpcSuccess(o);
delete this.work;
delete this.ore;
this.updateBuildingTile(o.result.building);
this.resetQueue();
Dom.get("archaeologySearchTime").innerHTML = "";
this.checkIfWorking();
},
failure : function(o){
Lacuna.Pulser.Hide();
this.rpcFailure(o);
},
timeout:Game.Timeout,
scope:this
});
}
});
Lacuna.buildings.Archaeology = Archaeology;
})();
YAHOO.register("archaeology", YAHOO.lacuna.buildings.Archaeology, {version: "1", build: "0"});
}