Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/templating/SetupHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ trait SetupHelper:
(Pref.Animation.SLOW, trans.slow.txt())
)

def translatedZenChoices(using Lang) =
List(
(Pref.Zen.NO, trans.no.txt()),
(Pref.Zen.YES, trans.yes.txt()),
(Pref.Zen.GAME_AUTO, trans.preferences.inGameOnly.txt())
)

def translatedBoardCoordinateChoices(using Lang) =
List(
(Pref.Coords.NONE, trans.no.txt()),
Expand Down
10 changes: 5 additions & 5 deletions app/views/account/bits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ object bits:

def setting(name: Frag, body: Frag) = st.section(h2(name), body)

def radios[A](field: play.api.data.Field, options: Iterable[(A, String)], prefix: String = "ir") =
def radios[A](field: play.api.data.Field, options: Iterable[(A, String)]) =
st.group(cls := "radio")(
options.map { (key, value) =>
val id = s"$prefix${field.id}_$key"
val id = s"ir${field.id}_$key"
val checked = field.value has key.toString
div(
input(
Expand All @@ -49,12 +49,12 @@ object bits:
}.toList
)

def bitCheckboxes(field: play.api.data.Field, options: Iterable[(Int, String)], prefix: String = "ir") =
def bitCheckboxes(field: play.api.data.Field, options: Iterable[(Int, String)]) =
st.group(cls := "radio")(
/// Will hold the value being calculated with the various checkboxes when sending
div(
input(
st.id := s"$prefix${field.id}_hidden",
st.id := s"ir${field.id}_hidden",
true option st.checked,
tpe := "hidden",
st.value := "",
Expand All @@ -63,7 +63,7 @@ object bits:
st.style := "display: none;"
) :: options
.map: (key, value) =>
val id = s"$prefix${field.id}_$key"
val id = s"ir${field.id}_$key"
val intVal = ~field.value.flatMap(_.toIntOption)
val checked = (intVal & key) == key
div(
Expand Down
2 changes: 1 addition & 1 deletion app/views/account/pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object pref:
),
setting(
zenMode(),
radios(form("display.zen"), booleanChoices)
radios(form("display.zen"), translatedZenChoices)
),
setting(
displayBoardResizeHandle(),
Expand Down
5 changes: 3 additions & 2 deletions app/views/base/layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,14 @@ object layout:
baseClass -> true,
"dark-board" -> (pref.bg == lila.pref.Pref.Bg.DARKBOARD),
"piece-letter" -> pref.pieceNotationIsLetter,
"zen" -> pref.isZen,
"blind-mode" -> ctx.blind,
"kid" -> ctx.kid,
"mobile" -> lila.common.HTTPRequest.isMobileBrowser(ctx.req),
"playing fixed-scroll" -> playing,
"no-rating" -> !pref.showRatings,
"zen" -> (pref.isZen || (playing && pref.isZenAuto)),
"zenable" -> zenable,
"no-rating" -> !pref.showRatings
"zen-auto" -> (zenable && pref.isZenAuto)
)
},
dataDev,
Expand Down
3 changes: 2 additions & 1 deletion app/views/round/player.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ object player:

bits.layout(
variant = pov.game.variant,
title = s"${trans.play.txt()} ${if ctx.pref.isZen then "ZEN" else playerText(pov.opponent)}",
title = s"${trans.play
.txt()} ${if ctx.pref.isZen || ctx.pref.isZenAuto then "ZEN" else playerText(pov.opponent)}",
moreJs = frag(
roundNvuiTag,
jsModuleInit(
Expand Down
1 change: 1 addition & 0 deletions modules/i18n/src/main/I18nKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,7 @@ object I18nKeys:
val `explainShowPlayerRatings` = I18nKey("preferences:explainShowPlayerRatings")
val `displayBoardResizeHandle` = I18nKey("preferences:displayBoardResizeHandle")
val `onlyOnInitialPosition` = I18nKey("preferences:onlyOnInitialPosition")
val `inGameOnly` = I18nKey("preferences:inGameOnly")
val `blindfoldChess` = I18nKey("preferences:blindfoldChess")
val `chessClock` = I18nKey("preferences:chessClock")
val `tenthsOfSeconds` = I18nKey("preferences:tenthsOfSeconds")
Expand Down
17 changes: 14 additions & 3 deletions modules/pref/src/main/Pref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ case class Pref(
SoundSet.allByKey get value map { s =>
copy(soundSet = s.key)
}
case "zen" => copy(zen = if value == "1" then 1 else 0).some
case "zen" => copy(zen = ~value.toIntOption.filter(Zen.choices.map(_._1).contains)).some
case "voice" => copy(voice = if value == "1" then 1.some else 0.some).some
case "keyboardMove" => copy(keyboardMove = if value == "1" then 1 else 0).some
case _ => none
Expand All @@ -115,7 +115,8 @@ case class Pref(

def pieceNotationIsLetter = pieceNotation == PieceNotation.LETTER

def isZen = zen == Zen.YES
def isZen = zen == Zen.YES
def isZenAuto = zen == Zen.GAME_AUTO

val showRatings = ratings == Ratings.YES

Expand Down Expand Up @@ -436,7 +437,17 @@ object Pref:
val changedAt = instantOf(2021, 12, 28, 8, 0)
val showPrompt = changedAt.isAfter(nowInstant minusMonths 6)

object Zen extends BooleanPref
object Zen:
val NO = 0
val YES = 1
val GAME_AUTO = 2

val choices = Seq(
NO -> "No",
YES -> "Yes",
GAME_AUTO -> "In-game only"
)

object Ratings extends BooleanPref

val darkByDefaultSince = instantOf(2021, 11, 7, 8, 0)
Expand Down
4 changes: 2 additions & 2 deletions modules/pref/src/main/PrefForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object PrefForm:
"coords" -> checkedNumber(Pref.Coords.choices),
"replay" -> checkedNumber(Pref.Replay.choices),
"pieceNotation" -> optional(booleanNumber),
"zen" -> optional(booleanNumber),
"zen" -> optional(checkedNumber(Pref.Zen.choices)),
"resizeHandle" -> optional(checkedNumber(Pref.ResizeHandle.choices)),
"blindfold" -> checkedNumber(Pref.Blindfold.choices)
)(DisplayData.apply)(unapply),
Expand Down Expand Up @@ -245,7 +245,7 @@ object PrefForm:

val zen = Form(
single(
"zen" -> text.verifying(Set("0", "1") contains _)
"zen" -> text.verifying(Set("0", "1", "2") contains _)
)
)

Expand Down
1 change: 1 addition & 0 deletions translation/source/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<string name="explainShowPlayerRatings">This allows hiding all ratings from the website, to help focus on the chess. Games can still be rated, this is only about what you get to see.</string>
<string name="displayBoardResizeHandle">Show board resize handle</string>
<string name="onlyOnInitialPosition">Only on initial position</string>
<string name="inGameOnly">In-game only</string>
<string name="blindfoldChess">Blindfold chess (invisible pieces)</string>
<string name="chessClock">Chess clock</string>
<string name="tenthsOfSeconds">Tenths of seconds</string>
Expand Down
4 changes: 3 additions & 1 deletion ui/puzzle/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ export default function (opts: PuzzleOpts, redraw: Redraw): Controller {
lichess.pubsub.on('zen', () => {
const zen = $('body').toggleClass('zen').hasClass('zen');
window.dispatchEvent(new Event('resize'));
xhr.setZen(zen);
if (!$('body').hasClass('zen-auto')) {
xhr.setZen(zen);
}
});
$('body').addClass('playing'); // for zen
$('#zentog').on('click', () => lichess.pubsub.emit('zen'));
Expand Down
10 changes: 9 additions & 1 deletion ui/round/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ export default class RoundController {
lichess.pubsub.on('zen', () => {
const zen = $('body').toggleClass('zen').hasClass('zen');
window.dispatchEvent(new Event('resize'));
xhr.setZen(zen);
if (!$('body').hasClass('zen-auto')) {
xhr.setZen(zen);
}
});

if (!this.opts.noab && this.isPlaying()) ab.init(this);
Expand Down Expand Up @@ -566,6 +568,12 @@ export default class RoundController {
)
this.opts.chat?.instance?.then(c => c.post('Good game, well played'));
}

if ($('body').hasClass('zen-auto') && $('body').hasClass('zen')) {
$('body').toggleClass('zen');
window.dispatchEvent(new Event('resize'));
}

if (d.crazyhouse) crazyEndHook();
this.clearJust();
this.setTitle();
Expand Down
4 changes: 3 additions & 1 deletion ui/storm/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export default class StormCtrl implements PuzCtrl {
lichess.pubsub.on('zen', () => {
const zen = $('body').toggleClass('zen').hasClass('zen');
window.dispatchEvent(new Event('resize'));
xhr.setZen(zen);
if (!$('body').hasClass('zen-auto')) {
xhr.setZen(zen);
}
});
$('#zentog').on('click', this.toggleZen);
lichess.sound.move();
Expand Down