tabs, pages, controls
parent
14bf47f11a
commit
e8c18fdbe9
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
@ -0,0 +1,53 @@
|
|||||||
|
// a url (naming it a, because it will be reused to store callbacks)
|
||||||
|
// e timeout error placeholder to avoid using var, not to be used
|
||||||
|
// xhr placeholder to avoid using var, not to be used
|
||||||
|
function pegasus(a, e, xhr) {
|
||||||
|
xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
// Set URL
|
||||||
|
xhr.open('GET', a);
|
||||||
|
|
||||||
|
// Don't need a to store URL anymore
|
||||||
|
// Reuse it to store callbacks
|
||||||
|
a = [];
|
||||||
|
|
||||||
|
pegasus.timeout && (xhr.timeout = pegasus.timeout);
|
||||||
|
|
||||||
|
xhr.ontimeout = function (event) {
|
||||||
|
e = event
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.onreadystatechange = xhr.then = function(onSuccess, onError, cb, data) {
|
||||||
|
// Test if onSuccess is a function
|
||||||
|
// Means that the user called xhr.then
|
||||||
|
if (onSuccess && onSuccess.call) {
|
||||||
|
a = [,onSuccess, onError];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test if there's a timeout error
|
||||||
|
e && a[2] && a[2](e, xhr)
|
||||||
|
|
||||||
|
// Test if request is complete
|
||||||
|
if (xhr.readyState == 4) {
|
||||||
|
// index will be:
|
||||||
|
// 0 if undefined
|
||||||
|
// 1 if status is between 200 and 399
|
||||||
|
// 2 if status is over
|
||||||
|
cb = a[0|xhr.status / 200];
|
||||||
|
if (cb) {
|
||||||
|
/*try {
|
||||||
|
data = JSON.parse(xhr.responseText) // NICKY FIX -- don't be helpful
|
||||||
|
} catch (e) {*/
|
||||||
|
data = null;
|
||||||
|
//}
|
||||||
|
cb(data, xhr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send the GET request
|
||||||
|
xhr.send();
|
||||||
|
|
||||||
|
// Return request
|
||||||
|
return xhr;
|
||||||
|
}
|
@ -1,2 +0,0 @@
|
|||||||
//0.3.5
|
|
||||||
function pegasus(a,b,c){return c=new XMLHttpRequest,c.open("GET",a),a=[],pegasus.timeout&&(c.timeout=pegasus.timeout),c.ontimeout=function(a){b=a},c.onreadystatechange=c.then=function(d,e,f,g){if(d&&d.call&&(a=[,d,e]),b&&a[2]&&a[2](b,c),4==c.readyState&&(f=a[0|c.status/200])){try{g=JSON.parse(c.responseText)}catch(a){g=null}f(g,c)}},c.send(),c}
|
|
@ -0,0 +1,108 @@
|
|||||||
|
function SandboxUI(config){
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
self.id = config.id;
|
||||||
|
|
||||||
|
// Create DOM
|
||||||
|
self.dom = document.createElement("div");
|
||||||
|
self.dom.className = "object";
|
||||||
|
var dom = self.dom;
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// BUTTONS for playing //////////////////
|
||||||
|
/////////////////////////////////////////
|
||||||
|
|
||||||
|
var playButton = new Button({x:130, y:135, text_id:"label_play", message:"tournament/autoplay"});
|
||||||
|
dom.appendChild(playButton.dom);
|
||||||
|
var stepButton = new Button({x:130, y:135+70, text_id:"label_step", message:"tournament/step"});
|
||||||
|
dom.appendChild(stepButton.dom);
|
||||||
|
var resetButton = new Button({x:130, y:135+70*2, text_id:"label_reset", message:"tournament/reset"});
|
||||||
|
dom.appendChild(resetButton.dom);
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// Create TABS & PAGES //////////////////
|
||||||
|
/////////////////////////////////////////
|
||||||
|
|
||||||
|
// Tabs
|
||||||
|
var tabs = document.createElement("div");
|
||||||
|
tabs.id = "sandbox_tabs";
|
||||||
|
dom.appendChild(tabs);
|
||||||
|
|
||||||
|
// Tab Hitboxes
|
||||||
|
var _makeHitbox = function(label, x, width, pageIndex){
|
||||||
|
|
||||||
|
label = label.toUpperCase();
|
||||||
|
|
||||||
|
var hitbox = document.createElement("div");
|
||||||
|
hitbox.className = "hitbox";
|
||||||
|
hitbox.style.left = x+"px";
|
||||||
|
hitbox.style.width = width+"px";
|
||||||
|
hitbox.innerHTML = label;
|
||||||
|
tabs.appendChild(hitbox);
|
||||||
|
|
||||||
|
(function(pageIndex){
|
||||||
|
hitbox.onclick = function(){
|
||||||
|
_goToPage(pageIndex);
|
||||||
|
};
|
||||||
|
})(pageIndex);
|
||||||
|
|
||||||
|
};
|
||||||
|
_makeHitbox(Words.get("label_population"), 30, 100, 0);
|
||||||
|
_makeHitbox(Words.get("label_payoffs"), 220, 100, 1);
|
||||||
|
_makeHitbox(Words.get("label_rules"), 366, 100, 2);
|
||||||
|
|
||||||
|
// Pages
|
||||||
|
var pages = [];
|
||||||
|
var _makePage = function(){
|
||||||
|
var page = document.createElement("div");
|
||||||
|
page.className = "sandbox_page";
|
||||||
|
tabs.appendChild(page);
|
||||||
|
pages.push(page);
|
||||||
|
};
|
||||||
|
for(var i=0; i<3; i++) _makePage(); // make three pages
|
||||||
|
|
||||||
|
// Go To Page
|
||||||
|
var _goToPage = function(showIndex){
|
||||||
|
|
||||||
|
// Background
|
||||||
|
tabs.style.backgroundPosition = (-showIndex*500)+"px 0px";
|
||||||
|
|
||||||
|
// Show page
|
||||||
|
for(var i=0; i<pages.length; i++) pages[i].style.display = "none";
|
||||||
|
pages[showIndex].style.display = "block";
|
||||||
|
|
||||||
|
};
|
||||||
|
_goToPage(0);
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// PAGE 0: POPULATION ///////////////////
|
||||||
|
/////////////////////////////////////////
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// PAGE 1: PAYOFFS //////////////////////
|
||||||
|
/////////////////////////////////////////
|
||||||
|
|
||||||
|
var page = pages[1];
|
||||||
|
|
||||||
|
var label = _makeLabel("sandbox_payoffs", 0, 0, 433);
|
||||||
|
page.appendChild(label);
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// PAGE 2: RULES ////////////////////////
|
||||||
|
/////////////////////////////////////////
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// Add & Remove Object //////////////////
|
||||||
|
/////////////////////////////////////////
|
||||||
|
|
||||||
|
// Add...
|
||||||
|
self.add = function(INSTANT){
|
||||||
|
return _add(self);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Remove...
|
||||||
|
self.remove = function(INSTANT){
|
||||||
|
return _remove(self);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
SLIDES.push({
|
|
||||||
|
|
||||||
id: "sim",
|
|
||||||
add:[
|
|
||||||
|
|
||||||
// The tournament simulation
|
|
||||||
{id:"tournament", type:"Tournament", x:0, y:20},
|
|
||||||
|
|
||||||
// All the words!
|
|
||||||
{
|
|
||||||
id:"textbox", type:"TextBox",
|
|
||||||
boxes:[
|
|
||||||
{ x:500, y:0, width:460, height:50, text_id:"sandbox_1" },
|
|
||||||
{ x:500, y:370, width:460, height:200, text_id:"sandbox_2" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// Buttons
|
|
||||||
{
|
|
||||||
id:"_b1", type:"Button", x:500, y:150, width:140,
|
|
||||||
text_id: "label_play_tournament",
|
|
||||||
message: "tournament/play"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:"_b2", type:"Button", x:500, y:220, width:140,
|
|
||||||
text_id: "label_eliminate_bottom_5",
|
|
||||||
message: "tournament/eliminate",
|
|
||||||
active:false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:"_b3", type:"Button", x:500, y:290, width:140,
|
|
||||||
text_id: "label_reproduce_top_5",
|
|
||||||
message: "tournament/reproduce",
|
|
||||||
active:false
|
|
||||||
}
|
|
||||||
|
|
||||||
]
|
|
||||||
|
|
||||||
});
|
|
@ -0,0 +1,14 @@
|
|||||||
|
SLIDES.push({
|
||||||
|
|
||||||
|
id: "sim",
|
||||||
|
add:[
|
||||||
|
|
||||||
|
// The tournament simulation
|
||||||
|
{id:"tournament", type:"Tournament", x:-20, y:-20},
|
||||||
|
|
||||||
|
// Screw it, just ALL of the Sandbox UI
|
||||||
|
{id:"sandbox", type:"SandboxUI"}
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue