mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-03-21 17:50:29 -05:00
Reimplement "ignore nicknames" without CSS
Honestly, the CSS solution was really cool. It was just incompatible with the new system. It also had enough other flaws (like, bad accessibility) that I don't feel _too_ bad about ripping it out. The new version is less code, anyway, although it does have the flaw of needing to replay the battle if you turn nicknames on or off. Fortunately, that should be a rare enough occurrence not to be a big deal.
This commit is contained in:
parent
32a16d3879
commit
bec475e602
|
|
@ -1378,43 +1378,12 @@
|
|||
this.battle.ignoreNicks = !!e.currentTarget.checked;
|
||||
Tools.prefs('ignorenicks', this.battle.ignoreNicks);
|
||||
this.battle.add('Nicknames ' + (this.battle.ignoreNicks ? '' : 'no longer ') + 'ignored.');
|
||||
this.toggleNicknames(this.battle.mySide);
|
||||
this.toggleNicknames(this.battle.yourSide);
|
||||
|
||||
var $log = $('.battle-log .inner');
|
||||
var $message = $('.battle .message');
|
||||
if (this.battle.ignoreNicks) {
|
||||
$log.addClass('hidenicks');
|
||||
$message.addClass('hidenicks');
|
||||
} else {
|
||||
$log.removeClass('hidenicks');
|
||||
$message.removeClass('hidenicks');
|
||||
}
|
||||
this.battle.resetToCurrentTurn();
|
||||
},
|
||||
toggleIgnoreOpponent: function (e) {
|
||||
this.battle.ignoreOpponent = !!e.currentTarget.checked;
|
||||
this.battle.add('Opponent ' + (this.battle.ignoreOpponent ? '' : 'no longer ') + 'ignored.');
|
||||
var $log = $('.battle-log .inner');
|
||||
var $message = $('.battle .message');
|
||||
var $messages = $log.find('.chatmessage-' + this.battle.yourSide.id);
|
||||
if (!$messages.length) return;
|
||||
if (this.battle.ignoreOpponent) {
|
||||
$messages.hide();
|
||||
$log.addClass('hidenicks');
|
||||
$message.addClass('hidenicks');
|
||||
} else {
|
||||
$messages.show();
|
||||
$log.removeClass('hidenicks');
|
||||
$message.removeClass('hidenicks');
|
||||
}
|
||||
},
|
||||
toggleNicknames: function (side) {
|
||||
for (var i = 0; i < side.active.length; i++) {
|
||||
if (!side.active[i]) continue;
|
||||
side.active[i].statbarElem.html(side.getStatbarHTML(side.active[i], true));
|
||||
side.updateStatbar(side.active[i], true, true);
|
||||
}
|
||||
side.updateSidebar();
|
||||
this.battle.resetToCurrentTurn();
|
||||
},
|
||||
toggleRightPanelBattles: function (e) {
|
||||
Tools.prefs('rightpanelbattles', !!e.currentTarget.checked);
|
||||
|
|
|
|||
|
|
@ -163,6 +163,17 @@ class BattleScene {
|
|||
$frame.addClass('battle');
|
||||
this.$frame = $frame;
|
||||
this.log = new BattleLog($logFrame[0] as HTMLDivElement, this);
|
||||
this.log.battleParser!.pokemonName = (pokemonId: string) => {
|
||||
if (!pokemonId) return '';
|
||||
if (battle.ignoreNicks || battle.ignoreOpponent) {
|
||||
const pokemon = battle.getPokemon(pokemonId);
|
||||
if (pokemon) return pokemon.species;
|
||||
}
|
||||
if (!pokemonId.startsWith('p1') && !pokemonId.startsWith('p2')) return '???pokemon:' + pokemonId + '???';
|
||||
if (pokemonId.charAt(3) === ':') return pokemonId.slice(4).trim();
|
||||
else if (pokemonId.charAt(2) === ':') return pokemonId.slice(3).trim();
|
||||
return '???pokemon:' + pokemonId + '???';
|
||||
};
|
||||
|
||||
let numericId = 0;
|
||||
if (battle.id) {
|
||||
|
|
@ -234,12 +245,6 @@ class BattleScene {
|
|||
this.$battle.append(this.$delay);
|
||||
this.$battle.append(this.$hiddenMessage);
|
||||
|
||||
if (this.battle.ignoreNicks) {
|
||||
this.log.setHideNicks(true);
|
||||
this.$messagebar.addClass('hidenicks');
|
||||
this.$hiddenMessage.addClass('hidenicks');
|
||||
}
|
||||
|
||||
if (!this.animating) {
|
||||
this.$battle.append('<div class="seeking"><strong>seeking...</strong></div>');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,9 +60,6 @@ class BattleLog {
|
|||
destroy() {
|
||||
this.elem.onscroll = null;
|
||||
}
|
||||
setHideNicks(hideNicks: boolean) {
|
||||
this.elem.className = this.className + (hideNicks ? ' hidenicks' : '');
|
||||
}
|
||||
add(args: Args, kwArgs?: KWArgs, preempt?: boolean) {
|
||||
if (kwArgs && kwArgs.silent) return;
|
||||
let divClass = 'chat';
|
||||
|
|
|
|||
|
|
@ -43,38 +43,29 @@ class BattleTextParser {
|
|||
return input.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
|
||||
}
|
||||
|
||||
pokemonName = (pokemon: string) => {
|
||||
if (!pokemon) return '';
|
||||
if (!pokemon.startsWith('p1') && !pokemon.startsWith('p2')) return '???pokemon:' + pokemon + '???';
|
||||
if (pokemon.charAt(3) === ':') return pokemon.slice(4).trim();
|
||||
else if (pokemon.charAt(2) === ':') return pokemon.slice(3).trim();
|
||||
return '???pokemon:' + pokemon + '???';
|
||||
};
|
||||
|
||||
pokemon(pokemon: string) {
|
||||
if (!pokemon) return '';
|
||||
let side;
|
||||
if (pokemon.startsWith('p1')) side = 0;
|
||||
else if (pokemon.startsWith('p2')) side = 1;
|
||||
else return '???pokemon:' + pokemon + '???';
|
||||
if (pokemon.charAt(3) === ':') pokemon = pokemon.slice(4).trim();
|
||||
else if (pokemon.charAt(2) === ':') pokemon = pokemon.slice(3).trim();
|
||||
else return '???pokemon:' + pokemon + '???';
|
||||
const name = this.pokemonName(pokemon);
|
||||
let template = BattleText.default[side === this.perspective ? 'pokemon' : 'opposingPokemon'];
|
||||
return template.replace('[NICKNAME]', pokemon);
|
||||
}
|
||||
|
||||
pokemonName(pokemon: string) {
|
||||
if (!pokemon) return '';
|
||||
if (!pokemon.startsWith('p1') && !pokemon.startsWith('p2')) return '???pokemon:' + pokemon + '???';
|
||||
if (pokemon.charAt(3) === ':') pokemon = pokemon.slice(4).trim();
|
||||
else if (pokemon.charAt(2) === ':') pokemon = pokemon.slice(3).trim();
|
||||
else return '???pokemon:' + pokemon + '???';
|
||||
return pokemon;
|
||||
return template.replace('[NICKNAME]', name);
|
||||
}
|
||||
|
||||
pokemonFull(pokemon: string, details: string) {
|
||||
if (pokemon.startsWith('p1')) {}
|
||||
else if (pokemon.startsWith('p2')) {}
|
||||
else return '???pokemon:' + pokemon + '???';
|
||||
let nickname;
|
||||
if (pokemon.charAt(3) === ':') nickname = pokemon.slice(4).trim();
|
||||
else if (pokemon.charAt(2) === ':') nickname = pokemon.slice(3).trim();
|
||||
else return '???pokemon:' + pokemon + '???';
|
||||
const nickname = this.pokemonName(pokemon);
|
||||
|
||||
let species = details.split(',')[0];
|
||||
const species = details.split(',')[0];
|
||||
if (nickname === species) return [pokemon.slice(0, 2), `**${species}**`];
|
||||
return [pokemon.slice(0, 2), `${nickname} (**${species}**)`];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1033,15 +1033,13 @@ class Battle {
|
|||
this.scene.log.add(args, kwArgs, preempt);
|
||||
}
|
||||
|
||||
switchSides(replay?: boolean) {
|
||||
resetToCurrentTurn() {
|
||||
if (this.ended) {
|
||||
this.setSidesSwitched(!this.sidesSwitched);
|
||||
this.reset(true);
|
||||
this.fastForwardTo(-1);
|
||||
} else {
|
||||
let turn = this.turn;
|
||||
let paused = this.paused;
|
||||
this.setSidesSwitched(!this.sidesSwitched);
|
||||
this.reset(true);
|
||||
this.paused = paused;
|
||||
if (turn) this.fastForwardTo(turn);
|
||||
|
|
@ -1052,6 +1050,10 @@ class Battle {
|
|||
}
|
||||
}
|
||||
}
|
||||
switchSides() {
|
||||
this.setSidesSwitched(!this.sidesSwitched);
|
||||
this.resetToCurrentTurn();
|
||||
}
|
||||
setSidesSwitched(sidesSwitched: boolean) {
|
||||
this.sidesSwitched = sidesSwitched;
|
||||
if (this.sidesSwitched) {
|
||||
|
|
|
|||
|
|
@ -952,12 +952,3 @@ button.subtle {
|
|||
button.subtle:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.hidenicks span.battle-nickname,
|
||||
.hidenicks span.battle-nickname-foe {
|
||||
font-size: 0;
|
||||
}
|
||||
.hidenicks span.battle-nickname::before,
|
||||
.hidenicks span.battle-nickname-foe::before{
|
||||
content: attr(title);
|
||||
font-size: 9pt;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user