';
// left menu 1 (high-res: left, low-res: bottom)
- buf += '
';
+ buf += '
';
buf += '
'+Tools.escapeHTML(name)+' wants to battle!
'; - buf += ''+Tools.escapeFormat(challenge.format)+'
'; - if (challenge.format === 'randombattle') { - buf += 'random team
'; - buf += ''; - } else { - buf += '
idk man
'; - buf += ''; - } + var buf = ''; $challenge.html(buf); } else { var $challenge = $pmWindow.find('.challenge'); if ($challenge.length) { if ($challenge.find('button[name=acceptChallenge]').length) { - $challenge.html('
The challenge was cancelled.
'); + $challenge.html(''); } else { - this.dismissChallenge(); + $challenge.remove(); } } } @@ -220,10 +221,9 @@ var userid = toId(name); var $challenge = this.openChallenge(name); - var buf = 'Waiting for '+Tools.escapeHTML(name)+'...
'; + var buf = ''; $challenge.html(buf); } @@ -237,9 +237,16 @@ } return $challenge; }, - updateSearch: function() { + updateFormats: function() { if (window.BattleFormats) { this.$('.mainmenu button.big').html('Look for a battle').removeClass('disabled'); + var self = this; + this.$('button[name=format]').each(function(i, el) { + var val = el.value; + var $teamButton = $(el).closest('form').find('button[name=team]'); + $(el).replaceWith(self.renderFormats(val)); + $teamButton.replaceWith(self.renderTeams(val)); + }); } else { this.$('.mainmenu button.big').html('Connecting...').addClass('disabled'); } @@ -260,15 +267,22 @@ return; } $challenge = this.openChallenge(name); - var buf = 'Challenge '+Tools.escapeHTML(name)+'?
'; - buf += 'Random Battle
'; - buf += 'random team
'; - buf += ''; + var buf = ''; $challenge.html(buf); }, acceptChallenge: function(i, target) { - var userid = $(target).closest('.pm-window').data('userid'); + var $pmWindow = $(target).closest('.pm-window'); + var userid = $pmWindow.data('userid'); + + var teamIndex = $pmWindow.find('button[name=team]').val(); + var team = null; + if (app.user.teams[teamIndex]) team = app.user.teams[teamIndex].team; + $(target).closest('.challenge').remove(); + if (team) app.send('/saveteam '+$.toJSON(team)); app.send('/accept '+userid); }, rejectChallenge: function(i, target) { @@ -277,16 +291,22 @@ app.send('/reject '+userid); }, makeChallenge: function(i, target) { - var userid = $(target).closest('.pm-window').data('userid'); - var name = $(target).closest('.pm-window').data('name'); + var $pmWindow = $(target).closest('.pm-window'); + var userid = $pmWindow.data('userid'); + var name = $pmWindow.data('name'); + var format = $pmWindow.find('button[name=format]').val(); - var buf = '
Challenging '+Tools.escapeHTML(name)+'...
'; - buf += 'Random Battle
'; - buf += 'random team
'; - buf += ''; + var teamIndex = $pmWindow.find('button[name=team]').val(); + var team = null; + if (app.user.teams[teamIndex]) team = app.user.teams[teamIndex].team; + + var buf = ''; $(target).closest('.challenge').html(buf); - app.send('/challenge '+userid+', randombattle'); + if (team) app.send('/saveteam '+$.toJSON(team)); + app.send('/challenge '+userid+', '+format); }, cancelChallenge: function(i, target) { var userid = $(target).closest('.pm-window').data('userid'); @@ -296,13 +316,163 @@ dismissChallenge: function(i, target) { $(target).closest('.challenge').remove(); }, + format: function(format, button) { + app.addPopup('format', FormatPopup, {format: format, sourceEl: button}); + }, + team: function(team, button) { + var format = $(button).closest('form').find('button[name=format]').val(); + app.addPopup('team', TeamPopup, {team: team, format: format, sourceEl: button}); + }, + + // format/team selection + + curFormat: '', + renderFormats: function(formatid, noChoice) { + if (!window.BattleFormats) { + return ''; + } + if (_.isEmpty(BattleFormats)) { + return '' + } + if (!noChoice) { + this.curFormat = formatid; + if (!this.curFormat) { + if (BattleFormats['randombattle']) { + this.curFormat = 'randombattle'; + } else for (var i in BattleFormats) { + this.curFormat = i; + break; + } + } + formatid = this.curFormat; + } + return ''; + }, + curTeamFormat: '', + curTeamIndex: -1, + renderTeams: function(formatid) { + if (!app.user.teams || !window.BattleFormats) { + return ''; + } + if (!formatid) formatid = this.curFormat; + if (!window.BattleFormats[formatid]) { + return ''; + } + if (window.BattleFormats[formatid].team) { + return ''; + } + var teams = app.user.teams; + if (!teams.length) { + return '' + } + var teamIndex = 0; + if (this.curTeamIndex >= 0) { + teamIndex = this.curTeamIndex; + } + if (this.curTeamFormat !== formatid) { + for (var i=0; i'+Tools.escapeHTML(curSection)+'
- '+bufs[0]+'
- '+bufs[1]+'
- '+bufs[0]+'
'+Tools.escapeFormat(teamFormat)+' teams
Other teams
- '+buf+'
'; + for (var i=0; i