Skip to content

Instantly share code, notes, and snippets.

@Corgan
Created September 5, 2014 17:00
Show Gist options
  • Save Corgan/0a8874054e3252806412 to your computer and use it in GitHub Desktop.
Save Corgan/0a8874054e3252806412 to your computer and use it in GitHub Desktop.
dojo.extend(com.nuclearunicorn.game.ui.BuildingBtnModern, {
afterRender: function() {
dojo.addClass(this.domNode, "modern");
this.renderLinks();
dojo.connect(this.domNode, "onmouseover", this, dojo.hitch( this, function(){ this.game.selectedBuilding = this.getBuilding(); }));
dojo.connect(this.domNode, "onmouseout", this, dojo.hitch( this, function(){ this.game.selectedBuilding = null; }));
/*this.game.attachTooltip(this.domNode, dojo.partial( function(btn){
}, this));*/
this.attachTooltip(this.domNode, dojo.partial( function(btn){
var tooltip = dojo.create("div", { style: {
width: "280px",
minHeight:"150px"
}}, null);
dojo.create("div", {
innerHTML: this.getName(),
style: {
textAlign: "center",
width: "100%",
borderBottom: "1px solid gray",
paddingBottom: "4px"
}}, tooltip);
//----------- description -------
dojo.create("div", {
innerHTML: this.description,
style: {
textAlign: "center",
width: "100%",
borderBottom: "1px solid gray",
paddingBottom: "4px",
fontSize: "15px",
color: "gray"
}}, tooltip);
//--------------- prices ----------------
var prices = this.getPrices();
if (prices.length){
for( var i = 0; i < prices.length; i++){
var price = prices[i];
var priceItemNode = dojo.create("div", {
style : {
overflow: "hidden"
}
}, tooltip);
var res = this.game.resPool.get(price.name);
var hasRes = (res.value >= prices[i].val);
var nameSpan = dojo.create("span", { innerHTML: res.title || res.name, style: { float: "left"} }, priceItemNode );
var priceSpan = dojo.create("span", {
innerHTML: (function() {
if(hasRes) {
return this.game.getDisplayValueExt(price.val);
} else {
var text = this.game.getDisplayValueExt(res.value) + " / " + this.game.getDisplayValueExt(price.val);
if(res.perTickUI > 0) {
var left = price.val - res.value;
var ticksLeft = left / res.perTickUI;
var time = this.game.toDisplaySeconds(ticksLeft / this.game.rate)
text += " <small>" + time + "</small>";
}
return text;
}}).call(this),
className: hasRes ? "" : "noRes",
style: {
float: "right"
}
}, priceItemNode );
}
}
//---------- effects-------------
dojo.create("div", {
innerHTML: "Effects:",
style: {
textAlign: "center",
width: "100%",
borderBottom: "1px solid gray",
paddingBottom: "4px",
marginBottom: "8px"
}}, tooltip);
//-----------------------------------------
var bld = this.getBuilding();
for (effectName in bld.effects){
var nameSpan = dojo.create("div", { innerHTML: effectName + ": " + this.game.getDisplayValueExt(bld.effects[effectName]),
style: {
float: "left",
fontSize: "14px",
color: "gray",
clear: "both"
}}, tooltip );
}
dojo.create("div", { style: { minHeight:"20px"} }, tooltip);
//-------------- flavor stuff -------------
dojo.create("div", {
innerHTML: bld.flavour || "flavor text",
className: "flavor",
style: {
position: "absolute",
bottom: "2px",
right: "4px",
fontSize: "12px",
fontStyle: "italic"
}}, tooltip);
return tooltip.outerHTML;
}, this));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment