var base_url = 'https://act-webstatic.mihoyo.com/event_bh3_com/avg-anti-entropy' base_url = resPath var now_galgame_tag = '_2017_anti_entropy_now_galgame' var now_scene_tag = '_2017_anti_entropy_now_scene' var now_action_tag = '_2017_anti_entropy_now_action' var now_galgame = 1 var sceneList = [] var characterData = [] var now_scene = -1 //存放当前场景,存档 var now_action = -1 var historyChoiceList = [] //用于记录当前场景的历史选择 var uiImageList = new Array() var showInSceneList = new Array() var date_url = '' var xml_files_all_in_this = new Array() var tl_base_url = base_url + '/' var tl_css_lang = 'zh' uiImageList.push( 'auto.png', 'auto_1.png', 'cancel.png', 'close.png', 'continue.png', 'dialog.png', 'dialogBig.png', 'Label-L.png', 'Label-M.png', 'Label-R.png', 'left.png', 'load.png', 'log.png', 'quickload.png', 'quicksave.png', 'remark.png', 'right.png', 'save.png', 'skip.png', 'skip_1.png', 'submit.png', 'thanks.png' ) function tryAudio(pauseOrPlay, indexOrInner, countNumber) { var audio if (indexOrInner == 0) audio = $('#indexbgm')[0] else audio = $('#bgm')[0] //选择控件 if (pauseOrPlay == 0) { audio.pause() if (!isNaN(audio.duration)) audio.currentTime = 0 if (indexOrInner == 0) indexAudioPlayingflag = false else innerAudioPlayingflag = false return //暂停,立即执行 } if (countNumber != 0) { if (indexOrInner == 0 && indexAudioPlayingflag == false) return if (indexOrInner == 1 && innerAudioPlayingflag == false) return } else { if (indexOrInner == 0) indexAudioPlayingflag = true else innerAudioPlayingflag = true } audio.load() if (!isNaN(audio.duration)) audio.currentTime = 0 $(audio).one('canplay', function () { this.play().catch(function () { setTimeout(function () { tryAudio(1, indexOrInner, countNumber + 1) }, 100) }) }) } //------------------------------------------------------ $(function () { loadExistXmlFile('date_url', function () { date_url = xml_files_all_in_this['date_url'].getElementsByTagName('log')[0].getAttribute('lastDate') }) preLoadUiImages('ui', uiImageList) $('#all').on('selectstart', function () { return false }) history.pushState(null, null, document.URL) window.addEventListener('popstate', function () { history.pushState(null, null, document.URL) }) check_size() tryAudio(1, 0, 0) }) window.onresize = function () { check_size() if (wrk_check_size()) window.scrollTo(0, 1) //隐藏浏览器工具栏 } window.addEventListener( 'orientationchange', function () { window.scrollTo(0, 1) //隐藏浏览器工具栏 }, false ) //------------------------------------------------------ //主框体单击响应事件------------------------------------ var listenScene //监听场景动向 var listenAction //监听行动列动向 var listenLoading //监听读档动向 var str_index_in_Autotype //打字机动画用 function setListens(s, a, k) { listenScene = s listenAction = a listenLoading = k } $('.galgame-content').click(function () { if (listenScene != null && listenAction != null) { if (listenLoading != 1) nextAction(listenScene, listenAction) //进行下一步 else Action(listenScene, listenAction, listenLoading) //调回状态 } else if (listenScene == null && listenAction == null && listenLoading != null) { if (listenLoading >= 0) { if (autoSpeed == 'typing') dialogAutoplay('stop') //自动播放的打字,优先关闭自动播放 else str_index_in_autotype = listenLoading //打字机状态调整 } else if (listenLoading == -1) dialogAutoplay('stop') //处理自动播放变化 else if (listenLoading == -2) $('.dialog-overflow').stop(true, true) //立即结束滚屏动画 } }) var textSpeed = 75 //全局变量相关:打字机效果 $.fn.autotype_text = function (gotoScene, gotoAction) { var str var timer_key var $pThis = $(this) $('.dialog-overflow').scrollTop(0) //开始打字前校正滚动条位置 if (autoSpeed != 'skip') { str = $pThis.html() if (str.indexOf('<') >= 0) { return } //注入了html文档的情形 if (isdialogAutoplay()) dialogAutoplayAutoStop('autotype') $pThis.html('') str_index_in_autotype = 0 setListens(null, null, str.length) timer_key = setInterval(function () { str_index_in_autotype++ $pThis.html(str.substring(0, str_index_in_autotype)) //当前显示的文本长度 if ($('.dialog-overflow')[0].scrollHeight > $('.dialog-overflow').height()) { //超出内容一次性显示完毕 $pThis.html(str) str_index_in_autotype = str.length } if (isdialogAutoplay()) { //打字动画中自动播放开启 $pThis.html(str) str_index_in_autotype = str.length } if (str_index_in_autotype >= str.length) { clearInterval(timer_key) //结束setInterval的定时循环 if (isdialogAutoplay()) { if (autoSpeed == 'auto') { dialogAutoplay('countinue') } } else if (autoSpeed == 'typing') { dialogAutoplay('countinue') } else { setListens(gotoScene, gotoAction) } } }, textSpeed) } } //全局变量相关:自动播放 var dialogAutoplayFlag = -1 //控制自动播放 var timer_Autoplay //每次单击调用的是同一个timer var autoSpeed = 'stop' //skip和autoplay的速度变量 $('.dialog-btn-autoplay').click(function (e) { e.stopPropagation() if (listenScene == null && listenAction == null && listenLoading != null) { if (listenLoading >= 0) { $('.dialog-btn-autoplay').addClass('dialog-btn-autoplay-on') dialogAutoplayAutoStop('autotype') return } } if (autoSpeed == 'stop') dialogAutoplay('countinue') else dialogAutoplay('auto') }) $('.dialog-btn-skip').click(function (e) { e.stopPropagation() if (listenScene == null && listenAction == null && listenLoading != null) { if (listenLoading >= 0) str_index_in_autotype = listenLoading //打字机状态调整 } dialogAutoplay('skip') }) function dialogAutoplay(keySpeed) { var tempTimeout if (keySpeed == null || keySpeed == 'auto' || keySpeed == 'countinue') { //按下auto if (autoSpeed == 'skip' && isdialogAutoplay()) { //在skip时按下auto dialogAutoplayAutoStop() } autoSpeed = 'auto' $('.dialog-btn-autoplay').addClass('dialog-btn-autoplay-on') } else if (keySpeed == 'skip') { //按下skip if (autoSpeed == 'auto' && isdialogAutoplay()) { //在auto时按下skip dialogAutoplayAutoStop() } autoSpeed = 'skip' $('.dialog-btn-skip').addClass('dialog-btn-skip-on') } else { dialogAutoplayAutoStop() return } changedialogAutoplayFlag() if (isdialogAutoplay()) { setListens(null, null, -1) //主操作响应事件改变 if (keySpeed == 'countinue') { tempTimeout = baseTime() } else { tempTimeout = getdialogAutoplaySpeed() } if (tempTimeout > 0) { timer_Autoplay = setTimeout(function () { if (autoSpeed == 'auto') { $('.dialog-btn-autoplay').addClass('dialog-btn-autoplay-on') nextAction(now_scene, now_action) } else if (autoSpeed == 'skip') { $('.dialog-btn-skip').addClass('dialog-btn-skip-on') nextAction(now_scene, now_action, 1) } dialogAutoplayAutoStop(1) if (autoSpeed != 'stop' && autoSpeed != 'typing') { dialogAutoplay(autoSpeed) } }, tempTimeout) } else { dialogAutoplayAutoStop() } } else { dialogAutoplayAutoStop() } } function getdialogAutoplaySpeed() { if (autoSpeed == 'auto') { var overflowTime if ($('p')[0]) { var textWhole = getText($('p')) } else { var textWhole = $('.dialog-text').html() } var textTime = parseInt((baseTime() * textWhole.length) / 10) if (textTime < baseTime()) textTime = baseTime() if (checkTextScrollLastMove > 0) { overflowTime = parseInt(checkTextScrollLastMove) } else { if (!checkTextScroll()) overflowTime = textTime else overflowTime = parseInt( ((baseTime() * $('.dialog-overflow').height()) / parseInt($('.dialog-text').css('line-height'))) * 2.5 ) } if (textTime <= overflowTime) { return textTime } else { return overflowTime } } else if (autoSpeed == 'skip') return baseTime() / 10 else return -1 } function isdialogAutoplay() { if (dialogAutoplayFlag > 0) return true else return false } function changedialogAutoplayFlag() { dialogAutoplayFlag *= -1 } function dialogAutoplayAutoStop(keyFlag) { dialogAutoplayFlag = -1 if (keyFlag == null) { autoSpeed = 'stop' clearTimeout(timer_Autoplay) $('.dialog-btn-autoplay').removeClass('dialog-btn-autoplay-on') $('.dialog-btn-skip').removeClass('dialog-btn-skip-on') setListens(now_scene, now_action) timer_Autoplay = null } else if (keyFlag == 'autotype') { autoSpeed = 'typing' clearTimeout(timer_Autoplay) timer_Autoplay = null } } //------------------------------------------------------ //CG展示 var cgPageIndex = 0 var cgPageLength = 0 var cgListTemp = null function cgPage(page, flag) { var i var j startLoad() if (!page) { page = cgPageIndex } var xmlDoc = loadExistXmlFile('cg_list', function () { cgListTemp = xml_files_all_in_this['cg_list'].getElementsByTagName('cg') cgPageLength = cgListTemp.length cgPage(page, flag) }) if (!xmlDoc) { return } if (cgPageIndex == 0) { $('.pagenum#pagenum-1').addClass('pagenum-gray') } if ((cgPageIndex + 1) * 4 >= cgPageLength) { $('.pagenum#pagenum-2').addClass('pagenum-gray') } var cgListSort = new Array() for (i = 0; cgListTemp[i] != null; i++) { j = cgListTemp[i].getAttribute('id') cgListSort[Number(j)] = cgListTemp[i] } for (i = page * 4; i < (page + 1) * 4; i++) { $('#cg-' + (i - page * 4)).hide() } //preload var cgImageList = new Array() j = 0 for (i in cgListSort) { if (j >= page * 4 && j < (page + 1) * 4) { $('#cg-' + (j - page * 4)).unbind() cgImageList.push(getText(cgListSort[i])) } else if (j >= (page + 1) * 4) { break } j++ } preLoadUiImages('cg', cgImageList) //检测预加载图片是否加载完毕 if (preLoadImagesCheck() > 0) { //如果已经预载过 //加载 j = 0 for (i in cgListSort) { if (j >= page * 4 && j < (page + 1) * 4) { $('#cg-' + (j - page * 4)).css( 'background-image', "url('" + base_url + '/resources/cg/' + getText(cgListSort[i]) + "')" ) $('#cg-' + (j - page * 4)).click({ str: getText(cgListSort[i]) }, function (e) { showCgOrigin(e.data.str) }) $('#cg-' + (j - page * 4)).show() } else if (j >= (page + 1) * 4) { break } j++ } if (flag == null) $('.cg-wrapper').fadeIn() cgListSort = null LoadFinish() return } var countIndexTimer = 0 var preLoadImagesTimer = setInterval(function () { var i var j if (preLoadImagesCheck() > 0 || countIndexTimer > 1000) { //图片预载完毕,或者超时 clearTimeout(preLoadImagesTimer) //加载 j = 0 for (i in cgListSort) { if (j >= page * 4 && j < (page + 1) * 4) { $('#cg-' + (j - page * 4)).css( 'background-image', "url('" + base_url + '/resources/cg/' + getText(cgListSort[i]) + "')" ) $('#cg-' + (j - page * 4)).click({ str: getText(cgListSort[i]) }, function (e) { showCgOrigin(e.data.str) }) $('#cg-' + (j - page * 4)).show() } else if (j >= (page + 1) * 4) { break } j++ } if (flag == null) $('.cg-wrapper').fadeIn() cgListSort = null LoadFinish() return } countIndexTimer++ }, 100) } $('.pagenum#pagenum-1').click(function () { if (cgPageIndex > 0) { if ((cgPageIndex + 1) * 4 >= cgPageLength) { $('.pagenum#pagenum-2').removeClass('pagenum-gray') } cgPageIndex-- showCGFrame(cgPageIndex) if (cgPageIndex == 0) { $('.pagenum#pagenum-1').addClass('pagenum-gray') } } }) $('.pagenum#pagenum-2').click(function () { if ((cgPageIndex + 1) * 4 < cgPageLength) { if (cgPageIndex == 0) { $('.pagenum#pagenum-1').removeClass('pagenum-gray') } cgPageIndex++ showCGFrame(cgPageIndex) if ((cgPageIndex + 1) * 4 >= cgPageLength) { $('.pagenum#pagenum-2').addClass('pagenum-gray') } } }) function showCGFrame(page) { $('.cg-frame').hide() cgPage(page, 1) $('.cg-frame').show() } //------------------------------------------------------ function generate_all_characterData(name) { var j var xmlDoc xmlDoc = loadExistXmlFile(name, function () { generate_all_characterData(name) }) if (!xmlDoc) return if (characterData.length) { //此时xml已经载入过 var imageList = xmlDoc.getElementsByTagName('image') preLoadImagesBegin(imageList) return } xmlDoc = loadExistXmlFile('characterData', function () { generate_all_characterData(name) }) if (!xmlDoc) return //此时characterData还是空的,从下面开始读入 var characterList = xmlDoc.getElementsByTagName('character') for (j = 0; j < characterList.length; j++) { var newCharacter = {} newCharacter['name'] = characterList[j].getAttribute('name') newCharacter['color'] = characterList[j].getAttribute('color') newCharacter['src'] = characterList[j].getAttribute('src') newCharacter['id'] = characterList[j].getAttribute('id') if (!characterData[newCharacter['id']]) { characterData[newCharacter['id']] = newCharacter } else if (characterData[newCharacter['id']]['name'] != newCharacter['name']) { console.log( 'id-' + newCharacter['id'] + ', Name Contradiction: ' + newCharacter['name'] + ' vs ' + characterData[newCharacter['id']]['name'] + '; in line ' + j ) } else if (characterData[newCharacter['id']]['color'] != newCharacter['color']) { console.log( 'id-' + newCharacter['id'] + ', Color Contradiction: ' + newCharacter['color'] + ' vs ' + characterData[newCharacter['id']]['color'] + '; in line ' + j ) } else if (characterData[newCharacter['id']]['src'] != newCharacter['src']) { console.log( 'id-' + newCharacter['id'] + ', SRC Contradiction: ' + newCharacter['src'] + ' vs ' + characterData[newCharacter['id']]['src'] + '; in line ' + j ) } } //此时xml已经载入过 xmlDoc = loadExistXmlFile(name) var imageList = xmlDoc.getElementsByTagName('image') preLoadImagesBegin(imageList) } function galgame(name) { var i var j var thisSceneTemp var uselessTexts var number_name = Number(name.replace(/[^0-9]/gi, '')) now_galgame = number_name now_scene = -1 now_action = -1 ClearCharas() ClearDialog() startLoad() var xmlDoc = loadExistXmlFile(name, function () { galgame(name) }) if (!xmlDoc) return //--让scene的id在sceneList中有意义 var sceneList0 = [] sceneList0 = xmlDoc.getElementsByTagName('scene') sceneList = new Array() for (i = 0; sceneList0[i] != null; i++) { thisSceneTemp = sceneList0[i] uselessTexts = new Array() for (j = 0; thisSceneTemp.childNodes[j] != null; j++) { if (thisSceneTemp.childNodes[j].nodeName == '#text') { uselessTexts.push(thisSceneTemp.childNodes[j]) } } for (j = 0; uselessTexts[j] != null; j++) { thisSceneTemp.removeChild(uselessTexts[j]) } //在此处清除所有#text j = thisSceneTemp.getAttribute('id') sceneList[Number(j)] = thisSceneTemp sceneList0[i] = null uselessTexts = null thisSceneTemp = null } sceneList0 = null //-- generate_all_characterData(name) } function startLoad() { $('#loading').show() } function LoadFinish() { $('#loading').hide() } function baseTime() { return 1000 } var checkTextScrollLastMove = 0 function checkTextScroll() { var scrollTop0 = $('.dialog-overflow')[0].scrollTop var scrollHeight0 = $('.dialog-overflow')[0].scrollHeight var showHeight = $('.dialog-overflow').height() var lineHeight = parseInt($('.dialog-text').css('line-height')) var scrollTop1 = scrollTop0 + showHeight if (scrollTop0 + showHeight <= scrollHeight0 - lineHeight) { if (scrollTop1 + showHeight > scrollHeight0) { scrollTop1 = scrollHeight0 - showHeight } return { scrollTop: scrollTop1, textLenth: (baseTime() / 5) * ((scrollTop1 - scrollTop0) / lineHeight) } } else if (scrollTop0 + showHeight < scrollHeight0 - lineHeight / 5) { return { scrollTop: scrollTop1, textLenth: baseTime() / 20 } //误差累积的情形 } else { return null //到底了 } } var lastEventNode = 0 function Action(gotoScene, gotoAction, skipKey, loadKey2) { //console.log("action: " + gotoScene + ', ' + gotoAction + ', ' +skipKey + ', ' + loadKey2 + '; autoSpeed:' + autoSpeed) ; var thisScene var thisEvent //首先判断文本滚动的情况,优先显示完毕当前文本 checkTextScrollLastMove = 0 if (!skipKey && autoSpeed != 'skip' && gotoScene == now_scene) { //如果不是读档的情形 var checkTextScroll_answer = checkTextScroll() if (checkTextScroll_answer != null) { checkTextScrollLastMove = checkTextScroll_answer.textLenth * 5 * 2.5 $('.dialog-overflow').animate( { scrollTop: checkTextScroll_answer.scrollTop }, { duration: checkTextScroll_answer.textLenth, start: function () { if (autoSpeed == 'auto' || autoSpeed == 'typing') dialogAutoplayAutoStop('autotype') }, step: function () { if (autoSpeed == 'stop') { setListens(null, null, -2) //单击事件变成快速完成动画 } else if (autoSpeed == 'skip') { $('.dialog-overflow').stop(true, true) } }, done: function () { if (autoSpeed == 'skip') { dialogAutoplay('skip') } else if (autoSpeed == 'auto') { dialogAutoplayAutoStop(1) dialogAutoplay('auto') } else if (autoSpeed == 'typing') { dialogAutoplayAutoStop(1) dialogAutoplay('auto') } else { setListens(gotoScene, lastEventNode) //console.log("set: " + lastEventNode); } } } ) return } } if (autoSpeed == 'stop') setListens(gotoScene, gotoAction) //普通状态 //-- remark_btn_hide() $('.choice_list').hide() $('.choice_list').html('') thisScene = sceneList[gotoScene] if (gotoAction < 2) { historyChoiceList = new Array() //清空选择标记 } thisEvent = thisScene.childNodes[gotoAction] if (gotoScene != now_scene) { ClearCharas() ClearDialog() if (thisScene.getAttribute('background')) { if (thisScene.getAttribute('background') == 'black' || thisScene.getAttribute('background') == 'white') { $('.background').css('background', thisScene.getAttribute('background')) } else { var size = '100%' if (thisScene.getAttribute('size')) { size = thisScene.getAttribute('size') } $('.background') .removeAttr('background') .css( 'background', "url('" + base_url + '/resources/background/' + thisScene.getAttribute('background') + "') no-repeat" ) //附加属性 white去除 否则会一瞬间跳白 .css('background-size', size + ' ' + size) .css('background-position', 'center') } } else { $('.background').css('background', 'black') } } now_scene = gotoScene now_action = gotoAction if (!thisEvent) { if (!skipKey || !loadKey2) { nextAction(gotoScene, gotoAction, skipKey) } return } processAction(thisEvent, gotoScene, gotoAction, skipKey, loadKey2) } function processAction(act, gotoScene, gotoAction, skipKey, loadKey2) { //console.log('⬆ ' + act.nodeName); if ($.inArray(act.nodeName, ['text', 'speak', 'choices']) >= 0) { $('#all').show() } switch (act.nodeName) { case 'cg': if (skipKey) { if (loadKey2) return //读档时跳过CG } dialogAutoplay('stop') //强制终止自动播放 lastEventNode = gotoAction $('#all').hide() var fadeInTimeCG = 300 var fadeOutTimeCG = 300 if (act.getAttribute('fadeIn') != null) { fadeInTimeCG = Number(act.getAttribute('fadeIn')) } if (act.getAttribute('fadeOut') != null) { fadeOutTimeCG = Number(act.getAttribute('fadeOut')) } if (act.getAttribute('bg') != null) { $('.cgBackground') .css('background', "url('" + base_url + '/resources/background/' + act.getAttribute('bg') + "') no-repeat") .css('background-size', 'auto 100%') .css('background-position', 'center') .fadeIn(fadeInTimeCG) } else { $('.cgBackground').hide() } $('.cg') .unbind() .css('background', "url('" + base_url + '/resources/cg/' + act.getAttribute('src') + "') no-repeat") .css('background-size', 'auto 100%') .css('background-position', 'center') .fadeIn(fadeInTimeCG) .click({ gs: gotoScene, ga: gotoAction }, function (e) { if (fadeOutTimeCG != 0) $('.cgBackground').fadeOut(fadeOutTimeCG) $('.cg').unbind() if (fadeOutTimeCG != 0) $('.cg').fadeOut(fadeOutTimeCG, function () { nextAction(e.data.gs, e.data.ga) }) else nextAction(e.data.gs, e.data.ga) }) break case 'blink': lastEventNode = gotoAction $('#all').hide() if (skipKey || autoSpeed == 'skip') { //快速播放或读档时跳过 return } var time = 0.5 var color = 'white' var repeat = 10 if (act.getAttribute('time')) { time = act.getAttribute('time') } if (act.getAttribute('color')) { color = act.getAttribute('color') } if (act.getAttribute('repeat')) { repeat = act.getAttribute('repeat') } $('.screen') .css('background-color', color) .css('animation', 'screenblink ' + time + 'ms linear 0s infinite forwards') .css('-moz-animation', 'screenblink ' + time + 'ms linear 0s infinite forwards') .css('-webkit-animation', 'screenblink ' + time + 'ms linear 0s infinite forwards') .css('-o-animation', 'screenblink ' + time + 'ms linear 0s infinite forwards') .show() setTimeout(function () { $('.screen').hide() if (autoSpeed != 'stop') return else nextAction(gotoScene, gotoAction) }, time * repeat) break case 'shake': lastEventNode = gotoAction if (skipKey || autoSpeed == 'skip') { //快速播放或读档时跳过 return } var time = Number(act.getAttribute('time')) var id = act.getAttribute('position') == 'all' ? 'all' : 'character-' + act.getAttribute('position') var className = act.getAttribute('type') || 'shake' $('#' + id).addClass(className) setTimeout(function () { $('#' + id).removeClass(className) if (autoSpeed == 'skip') return else if (autoSpeed == 'auto' && time >= baseTime() - 10) return else nextAction(gotoScene, gotoAction) }, time) break case 'text': lastEventNode = gotoAction ClearDialog() //清除临时加载的格式 $('.dialog-chara').hide() post_achievement_in_event(act) var tempAttribute = act.getAttribute('article') var thisTextTemp = null if (tempAttribute != null) { if ( tempAttribute == '1' || tempAttribute.indexOf('true') >= 0 || tempAttribute.indexOf('True') >= 0 || tempAttribute.indexOf('TRUE') >= 0 ) { $('.dialog').addClass('dialog_article') $('.dialog-overflow').addClass('dialog-overflow_article') thisTextTemp = act.innerHTML } else { $('.dialog').removeClass('dialog_article') $('.dialog-overflow').removeClass('dialog-overflow_article').removeClass('dialog-overflow_article_center') } } else { $('.dialog').removeClass('dialog_article') $('.dialog-overflow').removeClass('dialog-overflow_article').removeClass('dialog-overflow_article_center') } if (thisTextTemp == null) thisTextTemp = getText(act) tempAttribute = act.getAttribute('remark') if (tempAttribute != null) { if ( tempAttribute == '1' || tempAttribute.indexOf('next') >= 0 || tempAttribute.indexOf('Next') >= 0 || tempAttribute.indexOf('NEXT') >= 0 ) { remark_btn_show() } } RefreshDialog(thisTextTemp, gotoScene, gotoAction, skipKey, null) break case 'speak': lastEventNode = gotoAction ClearDialog() //清除临时加载的格式 post_achievement_in_event(act) $('.dialog').removeClass('dialog_article') $('.dialog-overflow').removeClass('dialog-overflow_article').removeClass('dialog-overflow_article_center') $('.dialog-chara').show() var chara = act.getAttribute('chara') var textColour = characterData[chara]['color'] $('.dialog-chara-text').html(characterData[chara]['name']) $('.dialog-chara-text').css('color', textColour) var tempAttribute = act.getAttribute('remark') if (tempAttribute != null) { if ( tempAttribute == '1' || tempAttribute.indexOf('next') >= 0 || tempAttribute.indexOf('Next') >= 0 || tempAttribute.indexOf('NEXT') >= 0 ) { remark_btn_show() } } RefreshDialog(getText(act), gotoScene, gotoAction, skipKey, textColour) break case 'choices': lastEventNode = gotoAction if (skipKey) { if (loadKey2) return //读档过程中,跳过 } dialogAutoplay('stop') //强制终止自动播放 var choiceList = act.childNodes var choices = [] for (var i = 0; i < choiceList.length; i++) { if (choiceList[i].nodeName != '#text') { if (choiceList[i].getAttribute('exit') != 'no') { if (choiceList[i].getAttribute('goto') == null) { choices.push({ text: getText(choiceList[i]), continueScene: gotoScene, continueAction: gotoAction }) //选择肢无影响 } else { choices.push({ text: getText(choiceList[i]), goto: choiceList[i].getAttribute('goto'), change: choiceList[i].getAttribute('change') }) } } } } ShowDialog(2, choices) break case 'show': lastEventNode = gotoAction var position = act.getAttribute('position') if (!position) { position = 'center' } var opacityTemp = act.getAttribute('opacity') if (!opacityTemp) { opacityTemp = 1 } opacityTemp = Number(opacityTemp) var chara = act.getAttribute('chara') if (chara) { if (characterData[chara]) { var url = "url('" + base_url + '/resources/chara/' + characterData[chara]['src'] + "') 50% 50% /auto 100% no-repeat" var positionLeft = [] positionLeft['mostleft'] = '-50' positionLeft['left'] = '-25' positionLeft['center'] = '0' positionLeft['back'] = '0' positionLeft['right'] = '25' positionLeft['mostright'] = '50' var pDivTemp = $('.character-' + position).children() if (pDivTemp.length) { if (!act.getAttribute('time') || skipKey) { pDivTemp .addClass('character-pic') .css('margin-left', positionLeft[position] + '%') .css('opacity', opacityTemp) .css('background', url) } else { var transTime = Math.abs(Number(act.getAttribute('time'))) var pDivTemp2 = $('
') pDivTemp2 .addClass('character-pic') .css('margin-left', positionLeft[position] + '%') .css('opacity', opacityTemp) .css('background', url) .css('display', 'none') $('.character-' + position).append(pDivTemp2) pDivTemp.fadeOut(transTime, function () { $(this).remove() }) pDivTemp2.fadeIn(transTime) } } else { var pDivTemp2 = $('') pDivTemp2 .addClass('character-pic') .css('margin-left', positionLeft[position] + '%') .css('opacity', opacityTemp) .css('background', url) $('.character-' + position).html(pDivTemp2) } } } if (!skipKey || !loadKey2) { nextAction(gotoScene, gotoAction, skipKey) } break case 'hide': lastEventNode = gotoAction $('.character-' + act.getAttribute('position')).html('') if (!skipKey || !loadKey2) { nextAction(gotoScene, gotoAction, skipKey) } break case 'end': lastEventNode = gotoAction dialogAutoplay('stop') //强制终止自动播放 post_achievement_in_event(act) if (act.getAttribute('last')) { endGame(-1) } else endGame(1) break case 'goto': lastEventNode = 0 gotoA(act.getAttribute('goto'), act.getAttribute('change'), skipKey) break case 'sound': lastEventNode = gotoAction if (skipKey || autoSpeed == 'skip') { //读档或快进跳过历史音效 return } var sound = $('#sound')[0] $('#sound').attr('src', base_url + '/resources/sound/' + act.getAttribute('src')) if (!isNaN(sound.duration)) sound.currentTime = 0 sound.play() nextAction(gotoScene, gotoAction) break case 'bgm': lastEventNode = gotoAction var bgm = $('#bgm')[0] if (act.getAttribute('status') == 'start') { $('#bgm').attr('src', base_url + '/resources/sound/' + act.getAttribute('src')) if (!isNaN(bgm.duration)) bgm.currentTime = 0 bgm.play() } else if (act.getAttribute('status') == 'continue') { if (bgm.paused) { $('#bgm').attr('src', base_url + '/resources/sound/' + act.getAttribute('src')) if (!isNaN(bgm.duration)) bgm.currentTime = 0 bgm.play() } } else { bgm.pause() if (!isNaN(bgm.duration)) bgm.currentTime = 0 } if (!skipKey || !loadKey2) { nextAction(gotoScene, gotoAction, skipKey) } break default: if (!skipKey || !loadKey2) { nextAction(gotoScene, gotoAction, skipKey) } } } var thanksWordsFlag = false function thanksWords() { thanksWordsFlag = true // pv("gameEnd_Newest"); // if (GetQueryString("from") == "wx") { // pv("gameEnd_Newest_WX"); // } else if (GetQueryString("from") == "bh3") { // pv("gameEnd_Newest_BH3"); // } else if (GetQueryString("from") == "ipz") { // pv("gameEnd_Newest_IPZ"); // } else if (GetQueryString("from") == "cd") { // pv("gameEnd_Newest_CD"); // } $('#confirm_1') .html(``) .css('background', "url('" + base_url + "/resources/ui/thanks.png') no-repeat") .css('background-size', 'auto 100%') .css('background-position', 'center') $('.submit-center').click(function () { $('.submit-center').unbind() CloseConfirmDialog() endGame() }) $('#confirm').fadeIn() } function nextChapterBox() { $('#confirm_1') .html(``) .css('background', "url('" + base_url + '/resources/catalog/' + date_url + "nextChapter.png') no-repeat") .css('background-size', 'auto 100%') .css('background-position', 'center') $('#confirm').fadeIn() } function gotoA(sceneKey, change, skipKey) { var changeColour = '#ffffff' var changeTime = 1000 if (change != null) { changeColour = change if (change.indexOf('none') >= 0 || change.indexOf('None') >= 0 || change.indexOf('NONE') >= 0 || change == '0') { changeColour = null } } if (changeColour) dialogAutoplay('stop') //强制终止自动播放 $('.white').removeClass().addClass('white').hide() //容错 $('.background').css('transition-duration', '0ms').css('transform', 'scale(1,1)').css('transform-origin', 'center') if (changeColour) { setListens() //单击暂时无响应 $('.white') .css('background', changeColour) .fadeIn(changeTime, function () { Action(sceneKey, 0) $('.white').fadeOut(changeTime) }) } else { if (skipKey) nextAction(sceneKey, -1, skipKey) else nextAction(sceneKey, -1) } } var actionTimer function nextAction(nowScene, nowAction, nowKey) { systemAutoSave() //自动保存 if (!isdialogAutoplay()) { setListens() //单击暂时无响应 } if (actionTimer) { clearTimeout(actionTimer) actionTimer = null } actionTimer = setTimeout(function () { Action(Number(nowScene), Number(nowAction) + 1, nowKey) }, 1) } function RefreshDialog(dialog_text, gotoScene, gotoAction, typeLoad, textColour) { $('.dialog-text').html(dialog_text) $('div.article-pic').css('background-image', function (n, v) { return "url('" + base_url + '/resources/background/' + $('div.article-pic')[n].getAttribute('picsrc') + "')" }) if (checkTextScroll() == null) { $('.dialog-overflow_article').addClass('dialog-overflow_article_center') //居中 } else { $('.dialog-overflow_article').removeClass('dialog-overflow_article_center') //取消居中 } if (textColour != null) $('.dialog-text').css('color', textColour) else $('.dialog-text').css('color', '#ffffff') if (typeLoad == 1) { } else { $('.dialog-text').autotype_text(gotoScene, gotoAction) } } function ShowDialog(mode, content) { var choiceHtml if (mode == 1) { $('.dialog1').show() } else if (mode == 2) { $('.choice_list').append('' + catalogListSort[i].getAttribute('quotationOne') + '
' ) if (!catalogListSort[i].getAttribute('partThree')) { if (!catalogListSort[i].getAttribute('partTwo')) { $('#catalog-content-' + (j - page * 2)).addClass('catalog-content-1A') $('#catalog-label_1-' + (j - page * 2)).addClass('catalog-label_1_on') $('#catalog-go-' + (j - page * 2)) .unbind() .click( { str: catalogListSort[i].getAttribute('id'), sce: catalogListSort[i].getAttribute('partOne') }, function (ee) { startGame(ee.data.str, { S: ee.data.sce, A: 0 }) } ) } else { $('#catalog-content-' + (j - page * 2)).addClass('catalog-content-2Ab') $('#catalog-label_1-' + (j - page * 2)) .addClass('catalog-label_1_on') .click( { pic: catalogListSort[i].getAttribute('picOne'), quo: catalogListSort[i].getAttribute('quotationOne'), str: catalogListSort[i].getAttribute('id'), sc1: catalogListSort[i].getAttribute('partOne'), sc2: catalogListSort[i].getAttribute('partTwo'), sc3: catalogListSort[i].getAttribute('partThree'), pos: j - page * 2 }, function (e) { $('.catalog-wrapper-new').css( 'background-image', "url('" + base_url + '/resources/background/' + e.data.pic + ".jpg')" ) $('#article-frame-' + e.data.pos).html( '' + e.data.quo + '
' ) $('#catalog-content-' + e.data.pos) .removeClass('catalog-content-2Ba') .addClass('catalog-content-2Ab') $('#catalog-label_1-' + e.data.pos) .removeClass('catalog-label_1_off') .addClass('catalog-label_1_on') $('#catalog-go-' + e.data.pos) .unbind() .click({ str: e.data.str, sce: e.data.sc1 }, function (ee) { startGame(ee.data.str, { S: ee.data.sce, A: 0 }) }) } ) $('#catalog-label_2-' + (j - page * 2)) .addClass('catalog-label_2_off') .click( { pic: catalogListSort[i].getAttribute('picTwo'), quo: catalogListSort[i].getAttribute('quotationTwo'), str: catalogListSort[i].getAttribute('id'), sc1: catalogListSort[i].getAttribute('partOne'), sc2: catalogListSort[i].getAttribute('partTwo'), sc3: catalogListSort[i].getAttribute('partThree'), pos: j - page * 2 }, function (e) { $('.catalog-wrapper-new').css( 'background-image', "url('" + base_url + '/resources/background/' + e.data.pic + ".jpg')" ) $('#article-frame-' + e.data.pos).html( '' + e.data.quo + '
' ) $('#catalog-content-' + e.data.pos) .removeClass('catalog-content-2Ab') .addClass('catalog-content-2Ba') $('#catalog-label_2-' + e.data.pos) .removeClass('catalog-label_2_off') .addClass('catalog-label_2_on') $('#catalog-go-' + e.data.pos) .unbind() .click({ str: e.data.str, sce: e.data.sc2 }, function (ee) { startGame(ee.data.str, { S: ee.data.sce, A: 0 }) }) } ) $('#catalog-go-' + (j - page * 2)) .unbind() .click( { str: catalogListSort[i].getAttribute('id'), sce: catalogListSort[i].getAttribute('partOne') }, function (ee) { startGame(ee.data.str, { S: ee.data.sce, A: 0 }) } ) } } else { $('#catalog-content-' + (j - page * 2)).addClass('catalog-content-3Abc') $('#catalog-label_1-' + (j - page * 2)) .addClass('catalog-label_1_on') .click( { pic: catalogListSort[i].getAttribute('picOne'), quo: catalogListSort[i].getAttribute('quotationOne'), str: catalogListSort[i].getAttribute('id'), sc1: catalogListSort[i].getAttribute('partOne'), sc2: catalogListSort[i].getAttribute('partTwo'), sc3: catalogListSort[i].getAttribute('partThree'), pos: j - page * 2 }, function (e) { $('.catalog-wrapper-new').css( 'background-image', "url('" + base_url + '/resources/background/' + e.data.pic + ".jpg')" ) $('#article-frame-' + e.data.pos).html('' + e.data.quo + '
') $('#catalog-content-' + e.data.pos) .removeClass('catalog-content-3Bac') .removeClass('catalog-content-3Cab') .addClass('catalog-content-3Abc') $('#catalog-label_1-' + e.data.pos) .removeClass('catalog-label_1_off') .addClass('catalog-label_1_on') $('#catalog-go-' + e.data.pos) .unbind() .click({ str: e.data.str, sce: e.data.sc1 }, function (ee) { startGame(ee.data.str, { S: ee.data.sce, A: 0 }) }) } ) $('#catalog-label_2-' + (j - page * 2)) .addClass('catalog-label_2_off') .click( { pic: catalogListSort[i].getAttribute('picTwo'), quo: catalogListSort[i].getAttribute('quotationTwo'), str: catalogListSort[i].getAttribute('id'), sc1: catalogListSort[i].getAttribute('partOne'), sc2: catalogListSort[i].getAttribute('partTwo'), sc3: catalogListSort[i].getAttribute('partThree'), pos: j - page * 2 }, function (e) { $('.catalog-wrapper-new').css( 'background-image', "url('" + base_url + '/resources/background/' + e.data.pic + ".jpg')" ) $('#article-frame-' + e.data.pos).html('' + e.data.quo + '
') $('#catalog-content-' + e.data.pos) .removeClass('catalog-content-3Abc') .removeClass('catalog-content-3Cab') .addClass('catalog-content-3Bac') $('#catalog-label_2-' + e.data.pos) .removeClass('catalog-label_2_off') .addClass('catalog-label_2_on') $('#catalog-go-' + e.data.pos) .unbind() .click({ str: e.data.str, sce: e.data.sc2 }, function (ee) { startGame(ee.data.str, { S: ee.data.sce, A: 0 }) }) } ) $('#catalog-label_3-' + (j - page * 2)) .addClass('catalog-label_3_off') .click( { pic: catalogListSort[i].getAttribute('picThree'), quo: catalogListSort[i].getAttribute('quotationThree'), str: catalogListSort[i].getAttribute('id'), sc1: catalogListSort[i].getAttribute('partOne'), sc2: catalogListSort[i].getAttribute('partTwo'), sc3: catalogListSort[i].getAttribute('partThree'), pos: j - page * 2 }, function (e) { $('.catalog-wrapper-new').css( 'background-image', "url('" + base_url + '/resources/background/' + e.data.pic + ".jpg')" ) $('#article-frame-' + e.data.pos).html('' + e.data.quo + '
') $('#catalog-content-' + e.data.pos) .removeClass('catalog-content-3Abc') .removeClass('catalog-content-3Bac') .addClass('catalog-content-3Cab') $('#catalog-label_3-' + e.data.pos) .removeClass('catalog-label_3_off') .addClass('catalog-label_3_on') $('#catalog-go-' + e.data.pos) .unbind() .click({ str: e.data.str, sce: e.data.sc3 }, function (ee) { startGame(ee.data.str, { S: ee.data.sce, A: 0 }) }) } ) $('#catalog-go-' + (j - page * 2)) .unbind() .click( { str: catalogListSort[i].getAttribute('id'), sce: catalogListSort[i].getAttribute('partOne') }, function (ee) { startGame(ee.data.str, { S: ee.data.sce, A: 0 }) } ) } $('#catalog-content-' + (j - page * 2)).show() } else if (j >= (page + 1) * 2) { break } j++ } if (flag == null) $('.catalog-wrapper-new').fadeIn() catalogListSort = null LoadFinish() } $('.pagenum#pagenum-7').click(function () { if (catalogPageIndex > 0) { if ((catalogPageIndex + 1) * 2 >= catalogListLength) { $('.pagenum#pagenum-8').removeClass('pagenum-gray') } catalogPageIndex-- showCatalogFrame(catalogPageIndex) if (catalogPageIndex == 2) { $('.pagenum#pagenum-7').addClass('pagenum-gray') } } }) //向前 $('.pagenum#pagenum-8').click(function () { if ((catalogPageIndex + 1) * 2 < catalogListLength) { if (catalogPageIndex == 0) { $('.pagenum#pagenum-7').removeClass('pagenum-gray') } catalogPageIndex++ showCatalogFrame(catalogPageIndex) if ((catalogPageIndex + 1) * 2 >= catalogListLength) { $('.pagenum#pagenum-8').addClass('pagenum-gray') } } }) //向后 function showCatalogFrame(page) { //new catalogPageNew(page) } //------------------------------------------------------- function setCookie(name, value) { // var Days = 30; // var exp = new Date(); // exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); // document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); localStorage.setItem(name, value) } ///删除cookie function delCookie(name) { // var exp = new Date(); // exp.setTime(exp.getTime() - 1); // var cval = getCookie(name); // if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); localStorage.removeItem(name) } //读取cookie function getCookie(name) { // var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); // if (arr != null) return unescape(arr[2]); // return null; return localStorage.getItem(name) } function GetQueryString(_name) { var reg = new RegExp('(^|&)' + _name + '=([^&]*)(&|$)') var r = window.location.search.substr(1).match(reg) if (r != null) return unescape(r[2]) return null } //历史纪录相关------------------------------------------------------ $('.dialog-btn-history').click(function (e) { e.stopPropagation() showHistory() }) $('.home_btn').click(function () { if ($('.home_btn').hasClass('home_btn_history')) { hideHistory() } else if ($('.home_btn').hasClass('home_btn_remark')) { hideremark() } else { dialogAutoplay('stop') systemAutoSave() ToggleWindow('backToMenu') } }) $('.history').hide() var remarkFlag_History = false function showHistory() { var thisScene = sceneList[now_scene] var thisEvent var pHtml, pHtml2 var choiceList var historyTextBox var choiceKey dialogAutoplay('stop') $('.dialog').hide() $('.dialog-btn').hide() $('.choice').hide() $('.history').show() if ($('.remark_btn').css('opacity') == '1') { remark_btn_hide() remarkFlag_History = true } setListens() $('.home_btn').addClass('home_btn_history') historyTextBox = $('div#historyTextBox.history-text') historyTextBox.html('') for (var i = 0; i <= now_action; i++) { thisEvent = thisScene.childNodes[i] if (thisEvent != null) { pHtml = null pHtml2 = null if (thisEvent.nodeName == 'text') { var tempAttribute = thisEvent.getAttribute('article') pHtml = $('') if (tempAttribute == null) { pHtml.html(getText(thisEvent)) } else if ( tempAttribute == '1' || tempAttribute.indexOf('true') >= 0 || tempAttribute.indexOf('True') >= 0 || tempAttribute.indexOf('TRUE') >= 0 ) { pHtml = $('') pHtml.html(thisEvent.innerHTML) } else { pHtml.html(getText(thisEvent)) } pHtml.addClass('history-text') historyTextBox.append(pHtml) } else if (thisEvent.nodeName == 'speak') { pHtml = $('') pHtml.html(characterData[thisEvent.getAttribute('chara')]['name'] + ':').addClass('history-text') historyTextBox.append(pHtml) pHtml = $('') pHtml.html(getText(thisEvent)).addClass('history-text') historyTextBox.append(pHtml) } else if (thisEvent.nodeName == 'choices') { choiceList = thisEvent.childNodes pHtml = $('