Remove gamepad layout settings

This commit is contained in:
LoveEevee 2019-04-06 00:10:15 +03:00
parent 59fc718a08
commit 8565a3cbba
4 changed files with 54 additions and 70 deletions

View File

@ -31,24 +31,11 @@ class Keyboard{
} }
this.keyboardEvents = 0 this.keyboardEvents = 0
var layout = settings.getItem("gamepadLayout")
var gameBtn = {} var gameBtn = {}
if(layout === "b"){
gameBtn[this.kbd["don_l"]] = ["d", "r", "ls"]
gameBtn[this.kbd["don_r"]] = ["a", "x", "rs"]
gameBtn[this.kbd["ka_l"]] = ["u", "l", "lb", "lt"]
gameBtn[this.kbd["ka_r"]] = ["b", "y", "rb", "rt"]
}else if(layout === "c"){
gameBtn[this.kbd["don_l"]] = ["d", "l", "ls"]
gameBtn[this.kbd["don_r"]] = ["a", "b", "rs"]
gameBtn[this.kbd["ka_l"]] = ["u", "r", "lb", "lt"]
gameBtn[this.kbd["ka_r"]] = ["x", "y", "rb", "rt"]
}else{
gameBtn[this.kbd["don_l"]] = ["u", "d", "l", "r", "ls"] gameBtn[this.kbd["don_l"]] = ["u", "d", "l", "r", "ls"]
gameBtn[this.kbd["don_r"]] = ["a", "b", "x", "y", "rs"] gameBtn[this.kbd["don_r"]] = ["a", "b", "x", "y", "rs"]
gameBtn[this.kbd["ka_l"]] = ["lb", "lt"] gameBtn[this.kbd["ka_l"]] = ["lb", "lt"]
gameBtn[this.kbd["ka_r"]] = ["rb", "rt"] gameBtn[this.kbd["ka_r"]] = ["rb", "rt"]
}
this.gamepad = new Gamepad(gameBtn) this.gamepad = new Gamepad(gameBtn)
this.gamepadInterval = setInterval(this.gamepadKeys.bind(this), 1000 / 60 / 2) this.gamepadInterval = setInterval(this.gamepadKeys.bind(this), 1000 / 60 / 2)

View File

@ -23,12 +23,6 @@ class Settings{
ka_r: ["k"] ka_r: ["k"]
}, },
touch: false touch: false
},
gamepadLayout: {
type: "select",
options: ["a", "b", "c"],
default: "a",
gamepad: true
} }
} }
@ -82,25 +76,18 @@ class SettingsView{
loader.changePage("settings", false) loader.changePage("settings", false)
assets.sounds["bgm_settings"].playLoop(0.1, false, 0, 1.392, 26.992) assets.sounds["bgm_settings"].playLoop(0.1, false, 0, 1.392, 26.992)
this.endButton = document.getElementById("tutorial-end-button")
if(touchEnabled){ if(touchEnabled){
document.getElementById("tutorial-outer").classList.add("touch-enabled") document.getElementById("tutorial-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
}
}
}
this.mode = "settings" this.mode = "settings"
var tutorialTitle = document.getElementById("tutorial-title") var tutorialTitle = document.getElementById("tutorial-title")
tutorialTitle.innerText = strings.gameSettings tutorialTitle.innerText = strings.gameSettings
tutorialTitle.setAttribute("alt", strings.gameSettings) tutorialTitle.setAttribute("alt", strings.gameSettings)
this.defaultButton = document.getElementById("settings-default")
this.defaultButton.innerText = strings.settings.default
this.defaultButton.setAttribute("alt", strings.settings.default)
this.endButton = document.getElementById("tutorial-end-button")
this.endButton.innerText = strings.settings.ok this.endButton.innerText = strings.settings.ok
this.endButton.setAttribute("alt", strings.settings.ok) this.endButton.setAttribute("alt", strings.settings.ok)
this.resolution = settings.getItem("resolution") this.resolution = settings.getItem("resolution")
@ -112,8 +99,7 @@ class SettingsView{
var current = settings.items[i] var current = settings.items[i]
if( if(
!touchEnabled && current.touch === true || !touchEnabled && current.touch === true ||
touchEnabled && current.touch === false || touchEnabled && current.touch === false
!gamepadEnabled && current.gamepad === true
){ ){
continue continue
} }
@ -145,17 +131,23 @@ class SettingsView{
valueDiv: valueDiv valueDiv: valueDiv
}) })
} }
this.items.push({
id: "default",
settingBox: this.defaultButton
})
this.items.push({ this.items.push({
id: "back", id: "back",
settingBox: this.endButton settingBox: this.endButton
}) })
this.setKbd() this.setKbd()
pageEvents.add(this.defaultButton, ["mousedown", "touchstart"], this.defaultSettings.bind(this))
pageEvents.add(this.endButton, ["mousedown", "touchstart"], this.onEnd.bind(this)) pageEvents.add(this.endButton, ["mousedown", "touchstart"], this.onEnd.bind(this))
pageEvents.keyAdd(this, "all", "down", this.keyEvent.bind(this)) pageEvents.keyAdd(this, "all", "down", this.keyEvent.bind(this))
this.gamepad = new Gamepad({ this.gamepad = new Gamepad({
"confirm": ["b", "ls", "rs"], "confirm": ["b", "ls", "rs"],
"previous": ["u", "l", "lb", "lt", "lsu", "lsl"], "up": ["u", "lsu"],
"previous": ["l", "lb", "lt", "lsl"],
"next": ["d", "r", "rb", "rt", "lsd", "lsr"], "next": ["d", "r", "rb", "rt", "lsd", "lsr"],
"back": ["start", "a"] "back": ["start", "a"]
}, this.keyPressed.bind(this)) }, this.keyPressed.bind(this))
@ -166,7 +158,8 @@ class SettingsView{
var kbdSettings = settings.getItem("keyboardSettings") var kbdSettings = settings.getItem("keyboardSettings")
this.kbd = { this.kbd = {
"confirm": ["enter", " ", kbdSettings.don_l[0], kbdSettings.don_r[0]], "confirm": ["enter", " ", kbdSettings.don_l[0], kbdSettings.don_r[0]],
"previous": ["arrowleft", "arrowup", kbdSettings.ka_l[0]], "up": ["arrowup"],
"previous": ["arrowleft", kbdSettings.ka_l[0]],
"next": ["arrowright", "arrowdown", kbdSettings.ka_r[0]], "next": ["arrowright", "arrowdown", kbdSettings.ka_r[0]],
"back": ["backspace", "escape"] "back": ["backspace", "escape"]
} }
@ -258,12 +251,16 @@ class SettingsView{
if(name === "confirm"){ if(name === "confirm"){
if(selected.id === "back"){ if(selected.id === "back"){
this.onEnd() this.onEnd()
}else if(selected.id === "default"){
this.defaultSettings()
}else{ }else{
this.setValue(selected.id) this.setValue(selected.id)
} }
}else if(name === "previous" || name === "next"){ }else if(name === "up" || name === "previous" || name === "next"){
selected.settingBox.classList.remove("selected") selected.settingBox.classList.remove("selected")
do{
this.selected = this.mod(this.items.length, this.selected + (name === "next" ? 1 : -1)) this.selected = this.mod(this.items.length, this.selected + (name === "next" ? 1 : -1))
}while(this.items[this.selected].id === "default" && name !== "previous")
this.items[this.selected].settingBox.classList.add("selected") this.items[this.selected].settingBox.classList.add("selected")
assets.sounds["se_ka"].play() assets.sounds["se_ka"].play()
}else if(name === "back"){ }else if(name === "back"){
@ -303,6 +300,27 @@ class SettingsView{
selected.valueDiv.classList.remove("selected") selected.valueDiv.classList.remove("selected")
this.getValue(selected.id, selected.valueDiv) this.getValue(selected.id, selected.valueDiv)
} }
defaultSettings(event){
if(event && event.type === "touchstart"){
event.preventDefault()
}
var selectedIndex = this.items.findIndex(item => item.id === "default")
if(this.selected !== selectedIndex){
this.items[this.selected].settingBox.classList.remove("selected")
this.selected = selectedIndex
this.items[this.selected].settingBox.classList.add("selected")
}
for(var i in settings.items){
settings.setItem(i, null)
}
for(var i in this.items){
var item = this.items[i]
if(item.valueDiv){
this.getValue(item.id, item.valueDiv)
}
}
assets.sounds["se_don"].play()
}
onEnd(event){ onEnd(event){
var touched = false var touched = false
if(event){ if(event){
@ -329,6 +347,7 @@ class SettingsView{
for(var i in this.items){ for(var i in this.items){
pageEvents.remove(this.items[i].settingBox, ["mousedown", "touchstart"]) pageEvents.remove(this.items[i].settingBox, ["mousedown", "touchstart"])
} }
delete this.defaultButton
delete this.endButton delete this.endButton
delete this.items delete this.items
if(this.resolution !== settings.getItem("resolution")){ if(this.resolution !== settings.getItem("resolution")){

View File

@ -117,14 +117,9 @@
don_r: "面(右)", don_r: "面(右)",
ka_r: "ふち(右)" ka_r: "ふち(右)"
}, },
gamepadLayout: {
name: "そうさタイプ設定",
a: "タイプA",
b: "タイプB",
c: "タイプC"
},
on: "オン", on: "オン",
off: "オフ", off: "オフ",
default: "既定値にリセット",
ok: "OK" ok: "OK"
} }
this.browserSupport = { this.browserSupport = {
@ -253,14 +248,9 @@ function StringsEn(){
don_r: "Right Surface", don_r: "Right Surface",
ka_r: "Right Rim" ka_r: "Right Rim"
}, },
gamepadLayout: {
name: "Gamepad Layout",
a: "Type A",
b: "Type B",
c: "Type C"
},
on: "On", on: "On",
off: "Off", off: "Off",
default: "Reset to Defaults",
ok: "OK" ok: "OK"
} }
this.browserSupport = { this.browserSupport = {
@ -389,14 +379,9 @@ function StringsCn(){
don_r: "Right Surface", don_r: "Right Surface",
ka_r: "Right Rim" ka_r: "Right Rim"
}, },
gamepadLayout: {
name: "操作类型设定",
a: "类型A",
b: "类型B",
c: "类型C"
},
on: "开", on: "开",
off: "关", off: "关",
default: "重置为默认值",
ok: "确定" ok: "确定"
} }
this.browserSupport = { this.browserSupport = {
@ -525,14 +510,9 @@ function StringsTw(){
don_r: "Right Surface", don_r: "Right Surface",
ka_r: "Right Rim" ka_r: "Right Rim"
}, },
gamepadLayout: {
name: "操作類型設定",
a: "類型A",
b: "類型B",
c: "類型C"
},
on: "開", on: "開",
off: "關", off: "關",
default: "重置為默認值",
ok: "確定" ok: "確定"
} }
this.browserSupport = { this.browserSupport = {
@ -661,14 +641,9 @@ function StringsKo(){
don_r: "Right Surface", don_r: "Right Surface",
ka_r: "Right Rim" ka_r: "Right Rim"
}, },
gamepadLayout: {
name: "조작 타입 설정",
a: "타입 A",
b: "타입 B",
c: "타입 C"
},
on: "온", on: "온",
off: "오프", off: "오프",
default: "기본값으로 재설정",
ok: "확인" ok: "확인"
} }
this.browserSupport = { this.browserSupport = {

View File

@ -2,6 +2,9 @@
<div id="tutorial"> <div id="tutorial">
<div id="tutorial-title" class="stroke-sub"></div> <div id="tutorial-title" class="stroke-sub"></div>
<div id="tutorial-content"></div> <div id="tutorial-content"></div>
<div id="about-link-btns">
<div id="settings-default" class="taibtn stroke-sub"></div>
</div>
<div id="tutorial-end-button" class="taibtn stroke-sub"></div> <div id="tutorial-end-button" class="taibtn stroke-sub"></div>
</div> </div>
</div> </div>