2019-04-05 04:40:11 +08:00
|
|
|
class Settings{
|
|
|
|
constructor(){
|
|
|
|
var ios = /iPhone|iPad/.test(navigator.userAgent)
|
|
|
|
var phone = /Android|iPhone|iPad/.test(navigator.userAgent)
|
|
|
|
|
|
|
|
this.items = {
|
2019-04-06 18:19:10 +08:00
|
|
|
language: {
|
|
|
|
type: "language",
|
|
|
|
options: ["ja", "en", "cn", "tw", "ko"],
|
|
|
|
default: this.getLang()
|
|
|
|
},
|
2019-04-05 04:40:11 +08:00
|
|
|
resolution: {
|
|
|
|
type: "select",
|
|
|
|
options: ["high", "medium", "low", "lowest"],
|
|
|
|
default: phone ? "medium" : "high"
|
|
|
|
},
|
|
|
|
touchAnimation: {
|
|
|
|
type: "toggle",
|
|
|
|
default: !ios,
|
|
|
|
touch: true
|
2019-04-06 03:53:51 +08:00
|
|
|
},
|
|
|
|
keyboardSettings: {
|
|
|
|
type: "keyboard",
|
|
|
|
default: {
|
|
|
|
ka_l: ["d"],
|
|
|
|
don_l: ["f"],
|
|
|
|
don_r: ["j"],
|
|
|
|
ka_r: ["k"]
|
|
|
|
},
|
|
|
|
touch: false
|
2019-04-17 02:06:41 +08:00
|
|
|
},
|
|
|
|
gamepadLayout: {
|
|
|
|
type: "gamepad",
|
|
|
|
options: ["a", "b", "c"],
|
|
|
|
default: "a",
|
|
|
|
gamepad: true
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.storage = {}
|
|
|
|
try{
|
|
|
|
var storage = JSON.parse(localStorage.getItem("settings") || "{}")
|
|
|
|
for(var i in this.items){
|
|
|
|
var current = this.items[i]
|
2019-04-06 18:19:10 +08:00
|
|
|
if(current.type === "language"){
|
|
|
|
this.storage[i] = localStorage.getItem("lang")
|
|
|
|
if(current.options.indexOf(this.storage[i]) === -1){
|
|
|
|
this.storage[i] = null
|
|
|
|
}
|
|
|
|
}else if(i in storage){
|
2019-04-17 02:06:41 +08:00
|
|
|
if((current.type === "select" || current.type === "gamepad") && current.options.indexOf(storage[i]) === -1){
|
2019-04-05 04:40:11 +08:00
|
|
|
this.storage[i] = null
|
2019-04-06 03:53:51 +08:00
|
|
|
}else if(current.type === "keyboard"){
|
|
|
|
var obj = {}
|
|
|
|
for(var j in current.default){
|
2019-04-06 18:19:10 +08:00
|
|
|
if(storage[i] && storage[i][j] && storage[i][j][0]){
|
2019-04-06 03:53:51 +08:00
|
|
|
obj[j] = storage[i][j]
|
|
|
|
}else{
|
|
|
|
obj = null
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.storage[i] = obj
|
2019-04-05 04:40:11 +08:00
|
|
|
}else{
|
|
|
|
this.storage[i] = storage[i]
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
this.storage[i] = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch(e){
|
|
|
|
for(var i in this.items){
|
|
|
|
this.storage[i] = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getItem(name){
|
|
|
|
var value = this.storage[name]
|
|
|
|
return value === null ? this.items[name].default : value
|
|
|
|
}
|
|
|
|
setItem(name, value){
|
|
|
|
this.storage[name] = value
|
|
|
|
try{
|
2019-04-06 18:19:10 +08:00
|
|
|
if(name === "language"){
|
|
|
|
if(value){
|
|
|
|
localStorage.setItem("lang", value)
|
|
|
|
}else{
|
|
|
|
localStorage.removeItem("lang")
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
var language = this.storage.language
|
|
|
|
delete this.storage.language
|
|
|
|
localStorage.setItem("settings", JSON.stringify(this.storage))
|
|
|
|
this.storage.language = language
|
|
|
|
}
|
2019-04-05 04:40:11 +08:00
|
|
|
}catch(e){}
|
|
|
|
}
|
2019-04-06 18:19:10 +08:00
|
|
|
getLang(){
|
|
|
|
if("languages" in navigator){
|
|
|
|
var userLang = navigator.languages.slice()
|
|
|
|
userLang.unshift(navigator.language)
|
|
|
|
for(var i in userLang){
|
|
|
|
for(var j in allStrings){
|
|
|
|
if(allStrings[j].regex.test(userLang[i])){
|
|
|
|
return j
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "ja"
|
|
|
|
}
|
|
|
|
setLang(lang, noEvent){
|
|
|
|
strings = lang
|
|
|
|
var boldFonts = strings.font === "Microsoft YaHei, sans-serif"
|
|
|
|
loader.screen.style.fontFamily = strings.font
|
|
|
|
loader.screen.style.fontWeight = boldFonts ? "bold" : ""
|
|
|
|
loader.screen.classList[boldFonts ? "add" : "remove"]("bold-fonts")
|
|
|
|
if(!noEvent){
|
|
|
|
pageEvents.send("language-change", lang.id)
|
|
|
|
}
|
|
|
|
}
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsView{
|
2019-04-17 02:06:41 +08:00
|
|
|
constructor(touchEnabled, tutorial, songId){
|
2019-04-05 04:40:11 +08:00
|
|
|
this.touchEnabled = touchEnabled
|
2019-04-07 03:14:44 +08:00
|
|
|
this.tutorial = tutorial
|
2019-04-17 02:06:41 +08:00
|
|
|
this.songId = songId
|
|
|
|
|
|
|
|
loader.changePage("settings", tutorial)
|
|
|
|
assets.sounds["bgm_settings"].playLoop(0.1, false, 0, 1.392, 26.992)
|
|
|
|
this.defaultButton = document.getElementById("settings-default")
|
2019-04-05 04:40:11 +08:00
|
|
|
if(touchEnabled){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.getElement("view-outer").classList.add("touch-enabled")
|
|
|
|
}
|
|
|
|
var gamepadEnabled = false
|
|
|
|
if("getGamepads" in navigator){
|
|
|
|
var gamepads = navigator.getGamepads()
|
|
|
|
for(var i = 0; i < gamepads.length; i++){
|
|
|
|
if(gamepads[i]){
|
|
|
|
gamepadEnabled = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
2019-04-06 03:53:51 +08:00
|
|
|
this.mode = "settings"
|
2019-04-05 04:40:11 +08:00
|
|
|
|
2019-04-17 02:06:41 +08:00
|
|
|
this.keyboard = new Keyboard({
|
|
|
|
"confirm": ["enter", "space", "don_l", "don_r"],
|
|
|
|
"up": ["up"],
|
|
|
|
"previous": ["left", "ka_l"],
|
|
|
|
"next": ["right", "down", "ka_r"],
|
|
|
|
"back": ["esc"],
|
|
|
|
"other": ["wildcard"]
|
|
|
|
}, this.keyPressed.bind(this))
|
|
|
|
this.gamepad = new Gamepad({
|
|
|
|
"confirm": ["b", "ls", "rs"],
|
|
|
|
"up": ["u", "lsu"],
|
|
|
|
"previous": ["l", "lb", "lt", "lsl"],
|
|
|
|
"next": ["d", "r", "rb", "rt", "lsd", "lsr"],
|
|
|
|
"back": ["start", "a"]
|
|
|
|
}, this.keyPressed.bind(this))
|
|
|
|
|
|
|
|
this.viewTitle = this.getElement("view-title")
|
|
|
|
this.endButton = this.getElement("view-end-button")
|
2019-04-05 04:40:11 +08:00
|
|
|
this.resolution = settings.getItem("resolution")
|
|
|
|
|
2019-04-17 02:06:41 +08:00
|
|
|
var content = this.getElement("view-content")
|
2019-04-05 04:40:11 +08:00
|
|
|
this.items = []
|
2019-05-03 10:59:31 +08:00
|
|
|
this.selected = 0
|
2019-04-05 04:40:11 +08:00
|
|
|
for(let i in settings.items){
|
2019-04-06 03:53:51 +08:00
|
|
|
var current = settings.items[i]
|
|
|
|
if(
|
|
|
|
!touchEnabled && current.touch === true ||
|
2019-04-07 03:14:44 +08:00
|
|
|
touchEnabled && current.touch === false ||
|
2019-05-03 10:59:31 +08:00
|
|
|
!gamepadEnabled && current.gamepad === true
|
2019-04-06 03:53:51 +08:00
|
|
|
){
|
2019-04-05 04:40:11 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
var settingBox = document.createElement("div")
|
|
|
|
settingBox.classList.add("setting-box")
|
|
|
|
var nameDiv = document.createElement("div")
|
|
|
|
nameDiv.classList.add("setting-name", "stroke-sub")
|
|
|
|
var name = strings.settings[i].name
|
|
|
|
nameDiv.innerText = name
|
|
|
|
nameDiv.setAttribute("alt", name)
|
|
|
|
settingBox.appendChild(nameDiv)
|
|
|
|
var valueDiv = document.createElement("div")
|
|
|
|
valueDiv.classList.add("setting-value")
|
2019-04-06 03:53:51 +08:00
|
|
|
this.getValue(i, valueDiv)
|
2019-04-05 04:40:11 +08:00
|
|
|
settingBox.appendChild(valueDiv)
|
|
|
|
content.appendChild(settingBox)
|
|
|
|
if(this.items.length === this.selected){
|
|
|
|
settingBox.classList.add("selected")
|
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
this.addTouch(settingBox, event => this.setValue(i))
|
2019-04-05 04:40:11 +08:00
|
|
|
this.items.push({
|
|
|
|
id: i,
|
|
|
|
settingBox: settingBox,
|
2019-04-06 18:19:10 +08:00
|
|
|
nameDiv: nameDiv,
|
2019-04-05 04:40:11 +08:00
|
|
|
valueDiv: valueDiv
|
|
|
|
})
|
|
|
|
}
|
2019-05-03 10:59:31 +08:00
|
|
|
this.items.push({
|
|
|
|
id: "default",
|
|
|
|
settingBox: this.defaultButton
|
|
|
|
})
|
|
|
|
this.addTouch(this.defaultButton, this.defaultSettings.bind(this))
|
2019-04-05 04:40:11 +08:00
|
|
|
this.items.push({
|
|
|
|
id: "back",
|
|
|
|
settingBox: this.endButton
|
|
|
|
})
|
2019-04-17 02:06:41 +08:00
|
|
|
this.addTouch(this.endButton, this.onEnd.bind(this))
|
2019-04-05 04:40:11 +08:00
|
|
|
|
2019-04-17 02:06:41 +08:00
|
|
|
this.gamepadSettings = document.getElementById("settings-gamepad")
|
|
|
|
this.addTouch(this.gamepadSettings, event => {
|
|
|
|
if(event.target === event.currentTarget){
|
|
|
|
this.gamepadBack()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.gamepadTitle = this.gamepadSettings.getElementsByClassName("view-title")[0]
|
|
|
|
this.gamepadEndButton = this.gamepadSettings.getElementsByClassName("view-end-button")[0]
|
|
|
|
this.addTouch(this.gamepadEndButton, event => this.gamepadBack(true))
|
2019-04-17 03:48:21 +08:00
|
|
|
this.gamepadBox = this.gamepadSettings.getElementsByClassName("setting-box")[0]
|
|
|
|
this.addTouch(this.gamepadBox, event => this.gamepadSet(1))
|
2019-04-17 02:06:41 +08:00
|
|
|
this.gamepadButtons = document.getElementById("gamepad-buttons")
|
|
|
|
this.gamepadValue = document.getElementById("gamepad-value")
|
|
|
|
|
|
|
|
this.setStrings()
|
|
|
|
|
|
|
|
pageEvents.send("settings")
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
getElement(name){
|
|
|
|
return loader.screen.getElementsByClassName(name)[0]
|
|
|
|
}
|
|
|
|
addTouch(element, callback){
|
|
|
|
pageEvents.add(element, ["mousedown", "touchstart"], event => {
|
|
|
|
if(event.type === "touchstart"){
|
|
|
|
event.preventDefault()
|
|
|
|
this.touched = true
|
|
|
|
}else if(event.which !== 1){
|
|
|
|
return
|
|
|
|
}else{
|
|
|
|
this.touched = false
|
|
|
|
}
|
|
|
|
callback(event)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
removeTouch(element){
|
|
|
|
pageEvents.remove(element, ["mousedown", "touchstart"])
|
2019-04-06 03:53:51 +08:00
|
|
|
}
|
|
|
|
getValue(name, valueDiv){
|
2019-04-05 04:40:11 +08:00
|
|
|
var current = settings.items[name]
|
|
|
|
var value = settings.getItem(name)
|
2019-04-06 18:19:10 +08:00
|
|
|
if(current.type === "language"){
|
|
|
|
value = allStrings[value].name + " (" + value + ")"
|
2019-04-17 02:06:41 +08:00
|
|
|
}else if(current.type === "select" || current.type === "gamepad"){
|
2019-04-05 04:40:11 +08:00
|
|
|
value = strings.settings[name][value]
|
|
|
|
}else if(current.type === "toggle"){
|
|
|
|
value = value ? strings.settings.on : strings.settings.off
|
2019-04-06 03:53:51 +08:00
|
|
|
}else if(current.type === "keyboard"){
|
|
|
|
valueDiv.innerHTML = ""
|
|
|
|
for(var i in value){
|
2019-04-17 02:06:41 +08:00
|
|
|
var keyDiv = document.createElement("div")
|
|
|
|
keyDiv.style.color = i === "ka_l" || i === "ka_r" ? "#009aa5" : "#ef2c10"
|
|
|
|
var key = value[i][0]
|
|
|
|
for(var j in this.keyboard.substitute){
|
|
|
|
if(this.keyboard.substitute[j] === key){
|
|
|
|
key = j
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keyDiv.innerText = key.toUpperCase()
|
|
|
|
valueDiv.appendChild(keyDiv)
|
2019-04-06 03:53:51 +08:00
|
|
|
}
|
|
|
|
return
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
2019-04-06 03:53:51 +08:00
|
|
|
valueDiv.innerText = value
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
|
|
|
setValue(name){
|
|
|
|
var current = settings.items[name]
|
|
|
|
var value = settings.getItem(name)
|
2019-04-06 03:53:51 +08:00
|
|
|
var selectedIndex = this.items.findIndex(item => item.id === name)
|
|
|
|
var selected = this.items[selectedIndex]
|
|
|
|
if(this.mode !== "settings"){
|
|
|
|
if(this.selected === selectedIndex){
|
|
|
|
this.keyboardBack(selected)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(this.selected !== selectedIndex){
|
|
|
|
this.items[this.selected].settingBox.classList.remove("selected")
|
|
|
|
this.selected = selectedIndex
|
|
|
|
selected.settingBox.classList.add("selected")
|
|
|
|
}
|
2019-04-06 18:19:10 +08:00
|
|
|
if(current.type === "language" || current.type === "select"){
|
2019-04-05 04:40:11 +08:00
|
|
|
value = current.options[this.mod(current.options.length, current.options.indexOf(value) + 1)]
|
|
|
|
}else if(current.type === "toggle"){
|
|
|
|
value = !value
|
2019-04-06 03:53:51 +08:00
|
|
|
}else if(current.type === "keyboard"){
|
|
|
|
this.mode = "keyboard"
|
|
|
|
selected.settingBox.style.animation = "none"
|
|
|
|
selected.valueDiv.classList.add("selected")
|
|
|
|
this.keyboardKeys = {}
|
|
|
|
this.keyboardSet()
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
return
|
2019-04-17 02:06:41 +08:00
|
|
|
}else if(current.type === "gamepad"){
|
|
|
|
this.mode = "gamepad"
|
|
|
|
this.gamepadSelected = current.options.indexOf(value)
|
|
|
|
this.gamepadSet()
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
return
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
|
|
|
settings.setItem(name, value)
|
2019-04-06 03:53:51 +08:00
|
|
|
this.getValue(name, this.items[this.selected].valueDiv)
|
2019-04-05 17:36:14 +08:00
|
|
|
assets.sounds["se_ka"].play()
|
2019-04-06 18:19:10 +08:00
|
|
|
if(current.type === "language"){
|
|
|
|
this.setLang(allStrings[value])
|
|
|
|
}
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
keyPressed(pressed, name, event){
|
2019-04-05 04:40:11 +08:00
|
|
|
if(!pressed){
|
|
|
|
return
|
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
this.touched = false
|
2019-04-05 04:40:11 +08:00
|
|
|
var selected = this.items[this.selected]
|
2019-04-06 03:53:51 +08:00
|
|
|
if(this.mode === "settings"){
|
|
|
|
if(name === "confirm"){
|
|
|
|
if(selected.id === "back"){
|
|
|
|
this.onEnd()
|
2019-04-06 05:10:15 +08:00
|
|
|
}else if(selected.id === "default"){
|
|
|
|
this.defaultSettings()
|
2019-04-06 03:53:51 +08:00
|
|
|
}else{
|
|
|
|
this.setValue(selected.id)
|
|
|
|
}
|
2019-04-06 05:10:15 +08:00
|
|
|
}else if(name === "up" || name === "previous" || name === "next"){
|
2019-04-06 03:53:51 +08:00
|
|
|
selected.settingBox.classList.remove("selected")
|
2019-04-06 05:10:15 +08:00
|
|
|
do{
|
|
|
|
this.selected = this.mod(this.items.length, this.selected + (name === "next" ? 1 : -1))
|
|
|
|
}while(this.items[this.selected].id === "default" && name !== "previous")
|
2019-04-07 03:14:44 +08:00
|
|
|
selected = this.items[this.selected]
|
|
|
|
selected.settingBox.classList.add("selected")
|
|
|
|
selected.settingBox.scrollIntoView()
|
2019-04-06 03:53:51 +08:00
|
|
|
assets.sounds["se_ka"].play()
|
|
|
|
}else if(name === "back"){
|
2019-04-05 04:40:11 +08:00
|
|
|
this.onEnd()
|
2019-04-06 03:53:51 +08:00
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
}else if(this.mode === "gamepad"){
|
|
|
|
if(name === "confirm"){
|
|
|
|
this.gamepadBack(true)
|
|
|
|
}else if(name === "up" || name === "previous" || name === "next"){
|
|
|
|
this.gamepadSet(name === "next" ? 1 : -1)
|
|
|
|
}else if(name === "back"){
|
|
|
|
this.gamepadBack()
|
|
|
|
}
|
2019-04-06 03:53:51 +08:00
|
|
|
}else if(this.mode === "keyboard"){
|
|
|
|
if(name === "back"){
|
|
|
|
this.keyboardBack(selected)
|
2019-04-17 02:06:41 +08:00
|
|
|
assets.sounds["se_cancel"].play()
|
|
|
|
}else{
|
|
|
|
event.preventDefault()
|
|
|
|
var currentKey = event.key.toLowerCase()
|
|
|
|
for(var i in this.keyboardKeys){
|
|
|
|
if(this.keyboardKeys[i][0] === currentKey || !currentKey){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var current = this.keyboardCurrent
|
|
|
|
assets.sounds[current === "ka_l" || current === "ka_r" ? "se_ka" : "se_don"].play()
|
|
|
|
this.keyboardKeys[current] = [currentKey]
|
|
|
|
this.keyboardSet()
|
2019-04-06 03:53:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keyboardSet(){
|
|
|
|
var selected = this.items[this.selected]
|
|
|
|
var current = settings.items[selected.id]
|
|
|
|
selected.valueDiv.innerHTML = ""
|
|
|
|
for(var i in current.default){
|
2019-04-17 02:06:41 +08:00
|
|
|
var keyDiv = document.createElement("div")
|
|
|
|
keyDiv.style.color = i === "ka_l" || i === "ka_r" ? "#009aa5" : "#ef2c10"
|
2019-04-06 03:53:51 +08:00
|
|
|
if(this.keyboardKeys[i]){
|
2019-04-17 02:06:41 +08:00
|
|
|
var key = this.keyboardKeys[i][0]
|
|
|
|
for(var j in this.keyboard.substitute){
|
|
|
|
if(this.keyboard.substitute[j] === key){
|
|
|
|
key = j
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keyDiv.innerText = key.toUpperCase()
|
|
|
|
selected.valueDiv.appendChild(keyDiv)
|
2019-04-05 04:40:11 +08:00
|
|
|
}else{
|
2019-04-17 02:06:41 +08:00
|
|
|
keyDiv.innerText = "[" + strings.settings[selected.id][i] + "]"
|
|
|
|
selected.valueDiv.appendChild(keyDiv)
|
2019-04-06 03:53:51 +08:00
|
|
|
this.keyboardCurrent = i
|
|
|
|
return
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
|
|
|
}
|
2019-04-06 03:53:51 +08:00
|
|
|
settings.setItem(selected.id, this.keyboardKeys)
|
|
|
|
this.keyboardBack(selected)
|
2019-04-17 02:06:41 +08:00
|
|
|
this.keyboard.update()
|
2019-04-06 03:53:51 +08:00
|
|
|
pageEvents.setKbd()
|
|
|
|
}
|
|
|
|
keyboardBack(selected){
|
|
|
|
this.mode = "settings"
|
|
|
|
selected.settingBox.style.animation = ""
|
|
|
|
selected.valueDiv.classList.remove("selected")
|
|
|
|
this.getValue(selected.id, selected.valueDiv)
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
gamepadSet(diff){
|
|
|
|
if(this.mode !== "gamepad"){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var selected = this.items[this.selected]
|
|
|
|
var current = settings.items[selected.id]
|
|
|
|
if(diff){
|
|
|
|
this.gamepadSelected = this.mod(current.options.length, this.gamepadSelected + diff)
|
|
|
|
assets.sounds["se_ka"].play()
|
|
|
|
}
|
|
|
|
var opt = current.options[this.gamepadSelected]
|
2019-04-17 03:48:21 +08:00
|
|
|
var value = strings.settings[selected.id][opt]
|
|
|
|
this.gamepadValue.innerText = value
|
|
|
|
this.gamepadValue.setAttribute("alt", value)
|
2019-04-17 02:06:41 +08:00
|
|
|
this.gamepadButtons.style.backgroundPosition = "0 " + (-318 - 132 * this.gamepadSelected) + "px"
|
|
|
|
this.gamepadSettings.style.display = "block"
|
|
|
|
}
|
2019-04-17 04:29:26 +08:00
|
|
|
gamepadBack(confirm){
|
2019-04-17 02:06:41 +08:00
|
|
|
if(this.mode !== "gamepad"){
|
|
|
|
return
|
|
|
|
}
|
2019-04-17 04:29:26 +08:00
|
|
|
var selected = this.items[this.selected]
|
|
|
|
var current = settings.items[selected.id]
|
|
|
|
settings.setItem(selected.id, current.options[this.gamepadSelected])
|
|
|
|
this.getValue(selected.id, selected.valueDiv)
|
|
|
|
assets.sounds[confirm ? "se_don" : "se_cancel"].play()
|
2019-04-17 02:06:41 +08:00
|
|
|
this.gamepadSettings.style.display = ""
|
|
|
|
this.mode = "settings"
|
|
|
|
}
|
|
|
|
defaultSettings(){
|
2019-04-06 18:19:10 +08:00
|
|
|
if(this.mode === "keyboard"){
|
|
|
|
this.keyboardBack(this.items[this.selected])
|
2019-04-06 05:10:15 +08:00
|
|
|
}
|
|
|
|
for(var i in settings.items){
|
|
|
|
settings.setItem(i, null)
|
|
|
|
}
|
2019-04-06 18:19:10 +08:00
|
|
|
this.setLang(allStrings[settings.getItem("language")])
|
2019-04-17 02:06:41 +08:00
|
|
|
this.keyboard.update()
|
|
|
|
pageEvents.setKbd()
|
2019-04-06 05:10:15 +08:00
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
onEnd(){
|
2019-04-05 04:40:11 +08:00
|
|
|
this.clean()
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
setTimeout(() => {
|
2019-04-17 02:06:41 +08:00
|
|
|
if(this.tutorial && !this.touched){
|
|
|
|
new Tutorial(false, this.songId)
|
|
|
|
}else{
|
2019-04-17 04:29:26 +08:00
|
|
|
try{
|
|
|
|
localStorage.setItem("tutorial", "true")
|
|
|
|
}catch(e){}
|
2019-04-17 02:06:41 +08:00
|
|
|
new SongSelect(this.tutorial ? false : "settings", false, this.touched, this.songId)
|
|
|
|
}
|
2019-04-05 04:40:11 +08:00
|
|
|
}, 500)
|
|
|
|
}
|
2019-04-06 18:19:10 +08:00
|
|
|
setLang(lang){
|
|
|
|
settings.setLang(lang)
|
|
|
|
if(failedTests.length !== 0){
|
|
|
|
showUnsupported(strings)
|
|
|
|
}
|
|
|
|
for(var i in this.items){
|
|
|
|
var item = this.items[i]
|
|
|
|
if(item.valueDiv){
|
|
|
|
var name = strings.settings[item.id].name
|
|
|
|
item.nameDiv.innerText = name
|
|
|
|
item.nameDiv.setAttribute("alt", name)
|
|
|
|
this.getValue(item.id, item.valueDiv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setStrings()
|
|
|
|
}
|
|
|
|
setStrings(){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.viewTitle.innerText = strings.gameSettings
|
|
|
|
this.viewTitle.setAttribute("alt", strings.gameSettings)
|
|
|
|
this.endButton.innerText = strings.settings.ok
|
|
|
|
this.endButton.setAttribute("alt", strings.settings.ok)
|
|
|
|
this.gamepadTitle.innerText = strings.settings.gamepadLayout.name
|
|
|
|
this.gamepadTitle.setAttribute("alt", strings.settings.gamepadLayout.name)
|
|
|
|
this.gamepadEndButton.innerText = strings.settings.ok
|
|
|
|
this.gamepadEndButton.setAttribute("alt", strings.settings.ok)
|
2019-05-03 10:59:31 +08:00
|
|
|
this.defaultButton.innerText = strings.settings.default
|
|
|
|
this.defaultButton.setAttribute("alt", strings.settings.default)
|
2019-04-06 18:19:10 +08:00
|
|
|
}
|
2019-04-05 04:40:11 +08:00
|
|
|
mod(length, index){
|
|
|
|
return ((index % length) + length) % length
|
|
|
|
}
|
|
|
|
clean(){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.keyboard.clean()
|
2019-04-05 04:40:11 +08:00
|
|
|
this.gamepad.clean()
|
2019-04-05 17:36:14 +08:00
|
|
|
assets.sounds["bgm_settings"].stop()
|
2019-04-05 04:40:11 +08:00
|
|
|
for(var i in this.items){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.removeTouch(this.items[i].settingBox)
|
2019-04-05 04:40:11 +08:00
|
|
|
}
|
2019-04-07 03:14:44 +08:00
|
|
|
if(this.defaultButton){
|
|
|
|
delete this.defaultButton
|
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
this.removeTouch(this.gamepadSettings)
|
|
|
|
this.removeTouch(this.gamepadEndButton)
|
2019-04-17 03:48:21 +08:00
|
|
|
this.removeTouch(this.gamepadBox)
|
2019-04-06 18:19:10 +08:00
|
|
|
delete this.tutorialTitle
|
2019-04-05 04:40:11 +08:00
|
|
|
delete this.endButton
|
|
|
|
delete this.items
|
2019-04-17 02:06:41 +08:00
|
|
|
delete this.gamepadSettings
|
|
|
|
delete this.gamepadTitle
|
|
|
|
delete this.gamepadEndButton
|
2019-04-17 03:48:21 +08:00
|
|
|
delete this.gamepadBox
|
2019-04-17 02:06:41 +08:00
|
|
|
delete this.gamepadButtons
|
|
|
|
delete this.gamepadValue
|
2019-04-05 04:40:11 +08:00
|
|
|
if(this.resolution !== settings.getItem("resolution")){
|
|
|
|
for(var i in assets.image){
|
2019-04-05 05:21:08 +08:00
|
|
|
if(i === "touch_drum" || i.startsWith("bg_song_") || i.startsWith("bg_stage_") || i.startsWith("bg_don_")){
|
2019-04-05 04:40:11 +08:00
|
|
|
URL.revokeObjectURL(assets.image[i].src)
|
|
|
|
delete assets.image[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|