diff --git a/libs/actions.js b/libs/actions.js index 1a8597dd..544dc945 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -823,6 +823,13 @@ actions.prototype._selectChoices = function (length, keycode, callback) { if (keycode == 13 || keycode == 32 || keycode == 67) { callback.apply(this, [this.HSIZE, topIndex + core.status.event.selection]); } + //左右方向键调整 音量 行走速度 + if(core.status.event.id == "switchs" && (core.status.event.selection == 2 || core.status.event.selection == 3)) + { + if (keycode == 37) callback.apply(this, [this.HSIZE - 2, topIndex + core.status.event.selection]); + if (keycode == 39) callback.apply(this, [this.HSIZE + 2, topIndex + core.status.event.selection]); + } + if (keycode >= 49 && keycode <= 57) { var index = keycode - 49; if (index < length) { @@ -1910,11 +1917,11 @@ actions.prototype._keyUpSL = function (keycode) { ////// 系统设置界面时的点击操作 ////// actions.prototype._clickSwitchs = function (x, y) { - if (x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) return; var choices = core.status.event.ui.choices; var topIndex = this.HSIZE - parseInt((choices.length - 1) / 2) + (core.status.event.ui.offset || 0); - if (y >= topIndex && y < topIndex + choices.length) { - var selection = y - topIndex; + var selection = y - topIndex; + if ((x < this.CHOICES_LEFT || x > this.CHOICES_RIGHT) && (x != this.HSIZE-2 && selection != 2) && (x != this.HSIZE+2 && selection != 2) && (x != this.HSIZE-2 && selection != 3) && (x != this.HSIZE+2 && selection != 3)) return; + if (selection >= 0 && selection < choices.length) { core.status.event.selection = selection; switch (selection) { case 0: @@ -1922,18 +1929,24 @@ actions.prototype._clickSwitchs = function (x, y) { case 1: return this._clickSwitchs_sound(); case 2: - return this._clickSwitchs_moveSpeed(); + if (x == this.HSIZE-2) { return this._clickSwitchs_userVolume(-0.1); } + else if (x == this.HSIZE+2) { return this._clickSwitchs_userVolume(0.1); } + return; case 3: - return this._clickSwitchs_displayEnemyDamage(); + if (x == this.HSIZE-2) { return this._clickSwitchs_moveSpeed(-10); } + else if (x == this.HSIZE+2) { return this._clickSwitchs_moveSpeed(10); } + return; case 4: - return this._clickSwitchs_displayCritical(); + return this._clickSwitchs_displayEnemyDamage(); case 5: - return this._clickSwitchs_displayExtraDamage(); + return this._clickSwitchs_displayCritical(); case 6: - return this._clickSwitchs_localForage(); + return this._clickSwitchs_displayExtraDamage(); case 7: - return this._clickSwitchs_clickMove(); + return this._clickSwitchs_localForage(); case 8: + return this._clickSwitchs_clickMove(); + case 9: core.status.event.selection = 0; core.ui.drawSettings(); break; @@ -1952,16 +1965,25 @@ actions.prototype._clickSwitchs_sound = function () { core.ui.drawSwitchs(); } -actions.prototype._clickSwitchs_moveSpeed = function () { - core.myprompt("请输入行走速度(每走一步的时间,单位毫秒,默认100)", core.values.moveSpeed, function (value) { - value = parseInt(value) || core.values.moveSpeed; - value = core.clamp(value, 10, 500); - core.values.moveSpeed = value; - core.setLocalStorage("moveSpeed", value); - core.ui.drawSwitchs(); - }); +actions.prototype._clickSwitchs_userVolume = function (delta) { + //浮点运算精度 JS弱类型 + var value= parseFloat(Math.sqrt(core.musicStatus.userVolume).toFixed(1)); + core.musicStatus.userVolume = parseFloat(Math.pow(core.clamp(parseFloat(value + delta), 0, 1), 2).toFixed(2)); + //audioContext 音效 不受designVolume 影响 + if(core.musicStatus.gainNode != null) core.musicStatus.gainNode.gain.value = core.musicStatus.userVolume; + if (core.musicStatus.playingBgm) core.material.bgms[core.musicStatus.playingBgm].volume = core.musicStatus.userVolume * core.musicStatus.designVolume; + core.setLocalStorage('userVolume', core.musicStatus.userVolume); + core.ui.drawSwitchs(); } +actions.prototype._clickSwitchs_moveSpeed = function (delta) { + var value = core.clamp(parseInt(core.values.moveSpeed + delta), 50, 200); + core.values.moveSpeed = parseInt(value); + core.setLocalStorage("moveSpeed", core.values.moveSpeed); + core.ui.drawSwitchs(); +} + + actions.prototype._clickSwitchs_displayEnemyDamage = function () { core.flags.displayEnemyDamage = !core.flags.displayEnemyDamage; core.updateDamage(); diff --git a/libs/control.js b/libs/control.js index 523a0622..b978711d 100644 --- a/libs/control.js +++ b/libs/control.js @@ -2251,7 +2251,7 @@ control.prototype._playBgm_play = function (bgm, startTime) { // 缓存BGM core.loader.loadBgm(bgm); // 播放当前BGM - core.material.bgms[bgm].volume = core.musicStatus.volume; + core.material.bgms[bgm].volume = core.musicStatus.userVolume * core.musicStatus.designVolume; core.material.bgms[bgm].currentTime = startTime || 0; core.material.bgms[bgm].play(); core.musicStatus.playingBgm = bgm; @@ -2324,7 +2324,7 @@ control.prototype.playSound = function (sound) { core.musicStatus.playingSounds[id] = source; } else { - core.material.sounds[sound].volume = core.musicStatus.volume; + core.material.sounds[sound].volume = core.musicStatus.userVolume; core.material.sounds[sound].play(); } } diff --git a/libs/core.js b/libs/core.js index 0268bb5a..d9c8f933 100644 --- a/libs/core.js +++ b/libs/core.js @@ -61,7 +61,8 @@ function core() { 'lastBgm': null, // 上次播放的bgm 'gainNode': null, 'playingSounds': {}, // 正在播放的SE - 'volume': 1.0, // 音量 + 'userVolume': 1.0, // 用户音量 + 'designVolume': 1.0, //设计音量 'cachedBgms': [], // 缓存BGM内容 'cachedBgmCount': 4, // 缓存的bgm数量 } @@ -302,6 +303,8 @@ core.prototype._init_platform = function () { } core.musicStatus.bgmStatus = core.getLocalStorage('bgmStatus', true); core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true); + //新增 userVolume 默认值1.0 + core.musicStatus.userVolume = core.getLocalStorage('userVolume', 1.0); ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"].forEach(function (t) { if (navigator.userAgent.indexOf(t) >= 0) { if (t == 'iPhone' || t == 'iPad' || t == 'iPod') core.platform.isIOS = true; diff --git a/libs/events.js b/libs/events.js index 54defd83..8fbbc4e9 100644 --- a/libs/events.js +++ b/libs/events.js @@ -2540,16 +2540,16 @@ events.prototype.showGif = function (name, x, y) { ////// 淡入淡出音乐 ////// events.prototype.setVolume = function (value, time, callback) { var set = function (value) { - core.musicStatus.volume = value; + core.musicStatus.designVolume = value; if (core.musicStatus.playingBgm) - core.material.bgms[core.musicStatus.playingBgm].volume = value; + core.material.bgms[core.musicStatus.playingBgm].volume = core.musicStatus.userVolume * core.musicStatus.designVolume; } if (!time || time < 100) { set(value); if (callback) callback(); return; } - var currVolume = core.musicStatus.volume; + var currVolume = core.musicStatus.designVolume; time /= Math.max(core.status.replay.speed, 1); var per_time = 10, step = 0, steps = parseInt(time / per_time); if (steps <= 0) steps = 1; diff --git a/libs/ui.js b/libs/ui.js index a1b88121..3a17f00d 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1496,7 +1496,10 @@ ui.prototype.drawSwitchs = function() { var choices = [ "背景音乐: "+(core.musicStatus.bgmStatus ? "[ON]" : "[OFF]"), "背景音效: "+(core.musicStatus.soundStatus ? "[ON]" : "[OFF]"), - "行走速度: "+parseInt(core.values.moveSpeed), + //显示为 0~10 十挡 + " < "+"音量:"+parseInt(parseFloat(Math.sqrt(core.musicStatus.userVolume).toFixed(1)) * 10)+" > ", + //数值越大耗时越长 + " < "+"步时:" + parseInt(core.values.moveSpeed) +" > ", "怪物显伤: "+(core.flags.displayEnemyDamage ? "[ON]" : "[OFF]"), "临界显伤: "+(core.flags.displayCritical ? "[ON]" : "[OFF]"), "领域显伤: "+(core.flags.displayExtraDamage ? "[ON]" : "[OFF]"),