function SandboxUI(config){ var self = this; self.id = config.id; self.slideshow = config.slideshow; // 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", onclick: function(){ if(slideshow.objects.tournament.isAutoPlaying){ publish("tournament/autoplay/stop"); }else{ publish("tournament/autoplay/start"); } } }); listen(self, "tournament/autoplay/stop",function(){ playButton.setText("label_play"); }); listen(self, "tournament/autoplay/start",function(){ playButton.setText("label_stop"); }); 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=0 && diff<0; i--){ // do NOT adjust anchor. var conf = Tournament.INITIAL_AGENTS[i]; if(conf.strategy==peepID) continue; if(conf.count==0) continue; // DON'T DO IT IF IT'S ZERO conf.count--; // REMOVE diff++; // yay } } // If positive, add one starting from TOP, skipping anchor. if(diff>0){ for(var i=0; i0; i++){ // do NOT adjust anchor. var conf = Tournament.INITIAL_AGENTS[i]; if(conf.strategy==peepID) continue; conf.count++; // ADD diff--; // yay } } // NOW adjust UI for(var i=0; i