Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ===================================================================
  2. #
  3. #   Script: Component_GameSceneBehavior
  4. #
  5. #   $$COPYRIGHT$$
  6. #
  7. # ===================================================================
  8. class Component_GameSceneBehavior extends gs.Component_LayoutSceneBehavior
  9.  #   @objectCodecBlackList = ["objectManager"]
  10.     ###*
  11.     * Defines the behavior of visual novel game scene.
  12.     *
  13.     * @module vn
  14.     * @class Component_GameSceneBehavior
  15.     * @extends gs.Component_LayoutSceneBehavior
  16.     * @memberof vn
  17.     ###
  18.     constructor: ->
  19.         super()
  20.        
  21.         @onAutoCommonEventStart = =>
  22.             @object.removeComponent(@object.interpreter)
  23.             @object.interpreter.stop()
  24.         @onAutoCommonEventFinish = =>
  25.             if !@object.components.contains(@object.interpreter)
  26.                 @object.addComponent(@object.interpreter)
  27.             @object.interpreter.resume()
  28.            
  29.         @resourceContext = null
  30.         @objectDomain = ""
  31.        
  32.     ###*
  33.     * Initializes the scene.
  34.     *
  35.     * @method initialize
  36.     ###
  37.     initialize: ->
  38.         if SceneManager.previousScenes.length == 0
  39.             gs.GlobalEventManager.clearExcept(@object.commonEventContainer.subObjects)
  40.            
  41.         @resourceContext = ResourceManager.createContext()
  42.         ResourceManager.context = @resourceContext
  43.        
  44.         Graphics.freeze()
  45.         saveGame = GameManager.loadedSaveGame
  46.         sceneUid = null
  47.        
  48.         if saveGame
  49.             sceneUid = saveGame.sceneUid
  50.             @object.sceneData = saveGame.data
  51.         else
  52.             sceneUid = $PARAMS.preview?.scene.uid || @object.sceneData.uid || RecordManager.system.startInfo.scene.uid
  53.        
  54.         @object.sceneDocument = DataManager.getDocument(sceneUid)
  55.        
  56.         if @object.sceneDocument and @object.sceneDocument.items.type == "vn.scene"
  57.             @object.chapter = DataManager.getDocument(@object.sceneDocument.items.chapterUid)
  58.             @object.currentCharacter = { "name": "" } #RecordManager.characters[0]
  59.    
  60.             if not GameManager.initialized
  61.                 GameManager.initialize()
  62.    
  63.             LanguageManager.loadBundles()
  64.         else
  65.             sprite = new gs.Sprite()
  66.             sprite.bitmap = new gs.Bitmap(Graphics.width, 50)
  67.             sprite.bitmap.drawText(0, 0, Graphics.width, 50, "No Start Scene selected", 1, 0)
  68.             sprite.srcRect = new gs.Rect(0, 0, Graphics.width, 50)
  69.             sprite.y = (Graphics.height - 50) / 2
  70.             sprite.z = 10000
  71.    
  72.         @setupScreen()
  73.        
  74.     ###*
  75.     * Disposes the scene.
  76.     *
  77.     * @method dispose
  78.     ###
  79.     dispose: ->
  80.         ResourceManager.context = @resourceContext
  81.         @object.removeObject(@object.commonEventContainer)
  82.         @show(no)
  83.  
  84.         for event in GameManager.commonEvents
  85.             if event
  86.                 event.events.offByOwner("start", @object)
  87.                 event.events.offByOwner("finish", @object)
  88.            
  89.         if @object.video
  90.             @object.video.dispose()
  91.             @object.video.onEnded()
  92.        
  93.         super()
  94.    
  95.     changePictureDomain: (domain) ->
  96.         @object.pictureContainer.behavior.changeDomain(domain)
  97.         @object.pictures = @object.pictureContainer.subObjects
  98.     changeTextDomain: (domain) ->
  99.         @object.textContainer.behavior.changeDomain(domain)
  100.         @object.texts = @object.textContainer.subObjects
  101.     changeVideoDomain: (domain) ->
  102.         @object.videoContainer.behavior.changeDomain(domain)
  103.         @object.videos = @object.videoContainer.subObjects
  104.     changeHotspotDomain: (domain) ->
  105.         @object.hotspotContainer.behavior.changeDomain(domain)
  106.         @object.hotspots = @object.hotspotContainer.subObjects
  107.     changeMessageAreaDomain: (domain) ->
  108.         @object.messageAreaContainer.behavior.changeDomain(domain)
  109.         @object.messageAreas = @object.messageAreaContainer.subObjects
  110.            
  111.     ###*
  112.     * Shows/Hides the current scene. A hidden scene is no longer shown and executed
  113.     * but all objects and data is still there and be shown again anytime.
  114.     *
  115.     * @method show
  116.     * @param {boolean} visible - Indicates if the scene should be shown or hidden.
  117.     ###          
  118.     show: (visible) ->
  119.         if visible
  120.             @object.viewport = GameManager.sceneViewport
  121.            
  122.         window.$dataFields = @dataFields
  123.         @object.visible = visible
  124.        
  125.         @object.layout?.update()
  126.        
  127.         @object.pictureContainer.behavior.setVisible(visible)
  128.         @object.hotspotContainer.behavior.setVisible(visible)
  129.         @object.textContainer.behavior.setVisible(visible)
  130.         @object.videoContainer.behavior.setVisible(visible)
  131.         @object.messageAreaContainer.behavior.setVisible(visible)
  132.         @object.viewportContainer.behavior.setVisible(visible)
  133.         @object.characterContainer.behavior.setVisible(visible)
  134.         @object.backgroundContainer.behavior.setVisible(visible)
  135.  
  136.         @viewport?.visible = visible
  137.         @object.choiceWindow?.visible = visible
  138.         @object.inputNumberBox?.visible = visible
  139.         @object.inputTextBox?.visible = visible
  140.         @object.inputTextBox?.update()
  141.         @object.inputNumberBox?.update()
  142.         @object.choiceWindow?.update()
  143.        
  144.         #if visible and @object.commonEventContainer.subObjects.length == 0
  145.         @setupCommonEvents()
  146.    
  147.      
  148.     ###*
  149.     * Sets up common event handling.
  150.     *
  151.     * @method setupCommonEvents
  152.     ###  
  153.     setupCommonEvents: ->
  154.         commonEvents = @object.sceneData?.commonEvents
  155.        
  156.         if commonEvents
  157.             for event, i in commonEvents
  158.                 if event and @object.commonEventContainer.subObjects.indexOf(event) == -1
  159.                     @object.commonEventContainer.setObject(event, i)
  160.                     event.behavior.setupEventHandlers()
  161.                
  162.                     if event.interpreter?.isRunning
  163.                         event.events.emit("start", event)
  164.         else
  165.             for event, i in GameManager.commonEvents
  166.                 if event and (event.record.startCondition == 1 or event.record.parallel) and @object.commonEventContainer.subObjects.indexOf(event) == -1
  167.                     @object.commonEventContainer.setObject(event, i)
  168.                    
  169.                     event.events.offByOwner("start", @object)
  170.                     event.events.offByOwner("finish", @object)
  171.                    
  172.                     if not event.record.parallel
  173.                         event.events.on "start", gs.CallBack("onAutoCommonEventStart", this), null, @object
  174.                         event.events.on "finish", gs.CallBack("onAutoCommonEventFinish", this), null, @object
  175.  
  176.                     if event.interpreter?.isRunning
  177.                         event.events.emit("start", event)
  178.          
  179.         return null
  180.        
  181.     ###*
  182.     * Sets up main interpreter.
  183.     *
  184.     * @method setupInterpreter
  185.     * @protected
  186.     ###      
  187.     setupInterpreter: ->
  188.         @object.commands = @object.sceneDocument.items.commands
  189.        
  190.         if @object.sceneData.interpreter
  191.             @object.removeComponent(@object.interpreter)
  192.             @object.interpreter = @object.sceneData.interpreter
  193.             @object.addComponent(@object.interpreter)
  194.             #Object.mixin(@object.interpreter, @object.sceneData.interpreter, gs.Component_CommandInterpreter.objectCodecBlackList)
  195.             @object.interpreter.context.set(@object.sceneDocument.uid, @object)
  196.             @object.interpreter.object = @object
  197.         else
  198.             @object.interpreter.setup()
  199.             @object.interpreter.context.set(@object.sceneDocument.uid, @object)
  200.             @object.interpreter.start()
  201.            
  202.      
  203.     ###*
  204.     * Sets up characters and restores them from loaded save game if necessary.
  205.     *
  206.     * @method setupCharacters
  207.     * @protected
  208.     ###      
  209.     setupCharacters: ->
  210.         if @object.sceneData.characters?
  211.             for c, i in @object.sceneData.characters
  212.                 @object.characterContainer.setObject(c, i)
  213.        
  214.         @object.currentCharacter = @object.sceneData.currentCharacter || { name: "" }#RecordManager.characters[0]
  215.        
  216.    
  217.     ###*
  218.     * Sets up viewports and restores them from loaded save game if necessary.
  219.     *
  220.     * @method setupViewports
  221.     * @protected
  222.     ###    
  223.     setupViewports: ->
  224.         viewports = @object.sceneData?.viewports ? []
  225.         for viewport, i in viewports
  226.             if viewport
  227.                 @object.viewportContainer.setObject(viewport, i)
  228.     ###*
  229.     * Sets up backgrounds and restores them from loaded save game if necessary.
  230.     *
  231.     * @method setupBackgrounds
  232.     * @protected
  233.     ###  
  234.     setupBackgrounds: ->
  235.         backgrounds = @object.sceneData?.backgrounds ? []
  236.         for b, i in backgrounds
  237.             @object.backgroundContainer.setObject(b, i)
  238.            
  239.     ###*
  240.     * Sets up pictures and restores them from loaded save game if necessary.
  241.     *
  242.     * @method setupPictures
  243.     * @protected
  244.     ###  
  245.     setupPictures: ->
  246.         pictures = @object.sceneData?.pictures ? {}
  247.         for domain of pictures
  248.             @object.pictureContainer.behavior.changeDomain(domain)
  249.             if pictures[domain] then for picture, i in pictures[domain]
  250.                 @object.pictureContainer.setObject(picture, i)
  251.                 if picture?.image
  252.                     path = "Graphics/Pictures/#{picture.image}"
  253.                     @resourceContext.add(path, ResourceManager.resourcesByPath[path])
  254.        
  255.     ###*
  256.     * Sets up texts and restores them from loaded save game if necessary.
  257.     *
  258.     * @method setupTexts
  259.     * @protected
  260.     ###  
  261.     setupTexts: ->
  262.         texts = @object.sceneData?.texts ? {}
  263.         for domain of texts
  264.             @object.textContainer.behavior.changeDomain(domain)
  265.             if texts[domain] then for text, i in texts[domain]
  266.                 @object.textContainer.setObject(text, i)
  267.            
  268.     ###*
  269.     * Sets up videos and restores them from loaded save game if necessary.
  270.     *
  271.     * @method setupVideos
  272.     * @protected
  273.     ###
  274.     setupVideos: ->
  275.         videos = @object.sceneData?.videos ? {}
  276.         for domain of videos
  277.             @object.videoContainer.behavior.changeDomain(domain)
  278.             if videos[domain] then for video, i in videos[domain]
  279.                 if video
  280.                     path = "Movies/#{video.video}"
  281.                     @resourceContext.add(path, ResourceManager.resourcesByPath[path])
  282.                     video.visible = yes
  283.                     video.update()
  284.                    
  285.                 @object.videoContainer.setObject(video, i)
  286.      
  287.     ###*
  288.     * Sets up hotspots and restores them from loaded save game if necessary.
  289.     *
  290.     * @method setupHotspots
  291.     * @protected
  292.     ###        
  293.     setupHotspots: ->
  294.         hotspots = @object.sceneData?.hotspots ? {}
  295.         for domain of hotspots
  296.             @object.hotspotContainer.behavior.changeDomain(domain)
  297.             if hotspots[domain] then for hotspot, i in hotspots[domain]
  298.                 @object.hotspotContainer.setObject(hotspot, i)
  299.      
  300.     ###*
  301.     * Sets up layout.
  302.     *
  303.     * @method setupLayout
  304.     * @protected
  305.     ###      
  306.     setupLayout: ->
  307.         @dataFields = ui.UIManager.dataSources[ui.UiFactory.layouts.gameLayout.dataSource || "default"]()
  308.         @dataFields.scene = @object
  309.         window.$dataFields = @dataFields
  310.         advVisible = @object.messageMode == vn.MessageMode.ADV
  311.        
  312.         @object.layout = ui.UiFactory.createFromDescriptor(ui.UiFactory.layouts.gameLayout, @object)
  313.         @object.layout.visible = advVisible
  314.         $gameMessage_message.visible = advVisible
  315.         @object.layout.ui.prepare()
  316.        
  317.         @object.choices = @object.sceneData?.choices || @object.choices
  318.         if @object.choices?.length > 0
  319.             @showChoices(gs.CallBack("onChoiceAccept", @object.interpreter, { pointer: @object.interpreter.pointer, params: @params }))
  320.    
  321.         if @object.interpreter.waitingFor.inputNumber
  322.             @showInputNumber(GameManager.tempFields.digits, gs.CallBack("onInputNumberFinish", @object.interpreter, @object.interpreter))
  323.            
  324.         if @object.interpreter.waitingFor.inputText
  325.             @showInputText(GameManager.tempFields.letters, gs.CallBack("onInputTextFinish", @object.interpreter, @object.interpreter))
  326.      
  327.     ###*
  328.     * Sets up the main viewport / screen viewport.
  329.     *
  330.     * @method setupMainViewport
  331.     * @protected
  332.     ###
  333.     setupMainViewport: ->
  334.         if !@object.sceneData.viewport
  335.             GameManager.sceneViewport.removeComponent(GameManager.sceneViewport.visual)
  336.             GameManager.sceneViewport.dispose()
  337.             GameManager.sceneViewport = new gs.Object_Viewport(GameManager.sceneViewport.visual.viewport)
  338.             @viewport = GameManager.sceneViewport.visual.viewport
  339.             @object.viewport = GameManager.sceneViewport
  340.         else
  341.             GameManager.sceneViewport.dispose()
  342.             GameManager.sceneViewport = @object.sceneData.viewport
  343.             @object.viewport = @object.sceneData.viewport
  344.             @viewport = @object.viewport.visual.viewport
  345.             @viewport.viewport = Graphics.viewport
  346.            
  347.     ###*
  348.     * Sets up screen.
  349.     *
  350.     * @method setupScreen
  351.     * @protected
  352.     ###
  353.     setupScreen: ->
  354.         if @object.sceneData.screen
  355.             @object.viewport.restore(@object.sceneData.screen)
  356.            
  357.     ###*
  358.     * Restores main interpreter from loaded save game.
  359.     *
  360.     * @method restoreInterpreter
  361.     * @protected
  362.     ###      
  363.     restoreInterpreter: ->
  364.         if @object.sceneData.interpreter
  365.             @object.interpreter.restore()
  366.    
  367.     ###*
  368.     * Restores message from loaded save game.
  369.     *
  370.     * @method restoreMessages
  371.     * @protected
  372.     ###
  373.     restoreMessages: ->
  374.         if @object.sceneData?.messageAreas
  375.             for domain of @object.sceneData.messageAreas
  376.                 @object.messageAreaContainer.behavior.changeDomain(domain)
  377.                 messageAreas = @object.sceneData.messageAreas
  378.                 if messageAreas[domain] then for area, i in messageAreas[domain]
  379.                     if area
  380.                         messageArea = new gs.Object_MessageArea()
  381.                         messageLayout = ui.UIManager.createControlFromDescriptor(type: "ui.CustomGameMessage", id: "customGameMessage_"+i, params: { id: "customGameMessage_"+i }, messageArea)
  382.                         message = gs.ObjectManager.current.objectById("customGameMessage_"+i+"_message")
  383.                         area.message.textRenderer.disposeEventHandlers();
  384.                         message.textRenderer.dispose()
  385.                         Object.mixin(message, area.message)
  386.                         for c in message.components
  387.                             c.object = message
  388.                         #message.restore(f.message)
  389.                        
  390.                         messageLayout.dstRect.x = area.layout.dstRect.x
  391.                         messageLayout.dstRect.y = area.layout.dstRect.y
  392.                         messageLayout.dstRect.width = area.layout.dstRect.width
  393.                         messageLayout.dstRect.height = area.layout.dstRect.height
  394.                         messageLayout.needsUpdate = yes
  395.                         message.textRenderer.setupEventHandlers()
  396.                         messageLayout.update()
  397.                        
  398.                         #message.message.restoreMessages(f.messages)
  399.                         #message.textRenderer.restore(f.textRenderer)
  400.                         #message.visible = yes
  401.                         messageArea.message = message
  402.                         messageArea.layout = messageLayout
  403.                         messageArea.addObject(messageLayout)
  404.                         @object.messageAreaContainer.setObject(messageArea, i)
  405.                        
  406.  
  407.                    
  408.          
  409.    
  410.    
  411.     ###*
  412.     * Restores audio-playback from loaded save game.
  413.     *
  414.     * @method restoreAudioPlayback
  415.     * @protected
  416.     ###        
  417.     restoreAudioPlayback: ->
  418.         if @object.sceneData.audio
  419.             AudioManager.audioBuffers.push(b) for b in @object.sceneData.audio.audioBuffers
  420.             AudioManager.audioBuffersByLayer = @object.sceneData.audio.audioBuffersByLayer
  421.             AudioManager.audioLayers = @object.sceneData.audio.audioLayers
  422.             AudioManager.soundReferences = @object.sceneData.audio.soundReferences
  423.            
  424.      
  425.     ###*
  426.     * Restores the scene objects from the current loaded save-game. If no save-game is
  427.     * present in GameManager.loadedSaveGame, nothing will happen.
  428.     *
  429.     * @method restoreScene
  430.     * @protected
  431.     ###
  432.     restoreScene: ->
  433.         saveGame = GameManager.loadedSaveGame
  434.         if saveGame
  435.             context = new gs.ObjectCodecContext([Graphics.viewport, @object, this], saveGame.encodedObjectStore, null)
  436.             saveGame.data = gs.ObjectCodec.decode(saveGame.data, context)
  437.             for c in saveGame.data.characterNames
  438.                 if c then RecordManager.characters[c.index]?.name = c.name
  439.             GameManager.restore(saveGame)
  440.             gs.ObjectCodec.onRestore(saveGame.data, context)
  441.             @resourceContext.fromDataBundle(saveGame.data.resourceContext, ResourceManager.resourcesByPath)
  442.  
  443.             @object.sceneData = saveGame.data
  444.             Graphics.frameCount = saveGame.data.frameCount
  445.        
  446.     ###*
  447.     * Prepares all data for the scene and loads the necessary graphic and audio resources.
  448.     *
  449.     * @method prepareData
  450.     * @abstract
  451.     ###
  452.     prepareData: ->
  453.         #RecordManager.translate()
  454.        
  455.         GameManager.scene = @object
  456.  
  457.         gs.ObjectManager.current = @objectManager
  458.        
  459.         @object.sceneData.uid = @object.sceneDocument.uid
  460.        
  461.         if !ResourceLoader.loadEventCommandsData(@object.sceneDocument.items.commands)
  462.             ResourceLoader.loadEventCommandsGraphics(@object.sceneDocument.items.commands)
  463.             GameManager.backlog = @object.sceneData.backlog || GameManager.sceneData.backlog || []
  464.            
  465.             ResourceLoader.loadSystemSounds()
  466.             ResourceLoader.loadSystemGraphics()
  467.             ResourceLoader.loadUiTypesGraphics(ui.UiFactory.customTypes)
  468.             ResourceLoader.loadUiLayoutGraphics(ui.UiFactory.layouts.gameLayout)
  469.            
  470.             if @dataFields?
  471.                 ResourceLoader.loadUiDataFieldsGraphics(@dataFields)
  472.                
  473.             $tempFields.choiceTimer = @object.choiceTimer
  474.            
  475.             GameManager.variableStore.setup({ id: @object.sceneDocument.uid})
  476.            
  477.     ###*
  478.     * Prepares all visual game object for the scene.
  479.     *
  480.     * @method prepareVisual
  481.     ###
  482.     prepareVisual: ->
  483.         if @object.layout then return
  484.        
  485.         if GameManager.tempFields.isExitingGame
  486.             GameManager.tempFields.isExitingGame = no
  487.             gs.GameNotifier.postResetSceneChange(@object.sceneDocument.items.name)
  488.         else
  489.             gs.GameNotifier.postSceneChange(@object.sceneDocument.items.name)
  490.        
  491.         @restoreScene()
  492.         @object.messageMode = @object.sceneData.messageMode ? vn.MessageMode.ADV
  493.         @setupMainViewport()
  494.         @setupViewports()
  495.         @setupCharacters()
  496.         @setupBackgrounds()
  497.         @setupPictures()
  498.         @setupTexts()
  499.         @setupVideos()
  500.         @setupHotspots()
  501.         @setupInterpreter()
  502.         @setupLayout()
  503.         @setupCommonEvents()
  504.        
  505.         @restoreMessageBox()
  506.         @restoreInterpreter()
  507.         @restoreMessages()
  508.         @restoreAudioPlayback()
  509.        
  510.         @show(true)
  511.        
  512.         @object.sceneData = {}
  513.         GameManager.sceneData = {}
  514.        
  515.         Graphics.update()
  516.         @transition({ duration: 0 })
  517.        
  518.        
  519.     ###*
  520.     * Adds a new character to the scene.
  521.     *
  522.     * @method addCharacter
  523.     * @param {vn.Object_Character} character - The character to add.
  524.     * @param {boolean} noAnimation - Indicates if the character should be added immediately witout any appear-animation.
  525.     * @param {Object} animationData - Contains the appear-animation data -> { animation, easing, duration }.
  526.     ###
  527.     addCharacter: (character, noAnimation, animationData) ->
  528.         unless noAnimation
  529.             character.motionBlur.set(animationData.motionBlur)
  530.            
  531.             if animationData.duration > 0
  532.                 character.animator.appear(character.dstRect.x, character.dstRect.y, animationData.animation, animationData.easing, animationData.duration) unless noAnimation
  533.        
  534.         character.viewport = @viewport
  535.         character.visible = yes
  536.    
  537.         @object.characterContainer.addObject(character)
  538.        
  539.     ###*
  540.     * Removes a character from the scene.
  541.     *
  542.     * @method removeCharacter
  543.     * @param {vn.Object_Character} character - The character to remove.
  544.     * @param {Object} animationData - Contains the disappear-animation data -> { animation, easing, duration }.
  545.     ###
  546.     removeCharacter: (character, animationData) ->
  547.         character?.animator.disappear(animationData.animation, animationData.easing, animationData.duration, (sender) -> sender.dispose())
  548.    
  549.     ###*
  550.     * Resumes the current scene if it has been paused.
  551.     *
  552.     * @method resumeScene
  553.     ###
  554.     resumeScene: ->
  555.         @object.pictureContainer.active = yes
  556.         @object.characterContainer.active = yes
  557.         @object.backgroundContainer.active = yes
  558.         @object.textContainer.active = yes
  559.         @object.hotspotContainer.active = yes
  560.         @object.videoContainer.active = yes
  561.        
  562.         message = gs.ObjectManager.current.objectById("gameMessage_message")
  563.         message.active = yes
  564.  
  565.     ###*
  566.     * Pauses the current scene. A paused scene will not continue, messages, pictures, etc. will
  567.     * stop until the scene resumes.
  568.     *
  569.     * @method pauseScene
  570.     ###
  571.     pauseScene: ->
  572.         @object.pictureContainer.active = no
  573.         @object.characterContainer.active = no
  574.         @object.backgroundContainer.active = no
  575.         @object.textContainer.active = no
  576.         @object.hotspotContainer.active = no
  577.         @object.videoContainer.active = no
  578.        
  579.         message = gs.ObjectManager.current.objectById("gameMessage_message")
  580.         message.active = no
  581.      
  582.     ###*
  583.     * Changes the visibility of the entire game UI like the message boxes, etc. to allows
  584.     * the player to see the entire scene. Useful for CGs, etc.
  585.     *
  586.     * @param {boolean} visible - If <b>true</b>, the game UI will be visible. Otherwise it will be hidden.
  587.     * @method changeUIVisibility
  588.     ###  
  589.     changeUIVisibility: (visible) ->
  590.         @uiVisible = visible
  591.         @object.layout.visible = visible
  592.        
  593.     ###*
  594.     * Shows input-text box to let the user enter a text.
  595.     *
  596.     * @param {number} letters - The max. number of letters the user can enter.
  597.     * @param {gs.Callback} callback - A callback function called if the input-text box has been accepted by the user.
  598.     * @method showInputText
  599.     ###
  600.     showInputText: (letters, callback) ->
  601.         @object.inputTextBox?.dispose()
  602.         @object.inputTextBox = ui.UiFactory.createControlFromDescriptor(ui.UiFactory.customTypes["ui.InputTextBox"], @object.layout)
  603.         @object.inputTextBox.ui.prepare()
  604.         @object.inputTextBox.events.on("accept", callback)
  605.        
  606.     ###*
  607.     * Shows input-number box to let the user enter a number.
  608.     *
  609.     * @param {number} digits - The max. number of digits the user can enter.
  610.     * @param {gs.Callback} callback - A callback function called if the input-number box has been accepted by the user.
  611.     * @method showInputNumber
  612.     ###
  613.     showInputNumber: (digits, callback) ->
  614.         @object.inputNumberBox?.dispose()
  615.         @object.inputNumberBox = ui.UiFactory.createControlFromDescriptor(ui.UiFactory.customTypes["ui.InputNumberBox"], @object.layout)
  616.         @object.inputNumberBox.ui.prepare()
  617.         @object.inputNumberBox.events.on("accept", callback)    
  618.    
  619.     ###*
  620.     * Shows choices to let the user pick a choice.
  621.     *
  622.     * @param {Object[]} choices - An array of choices
  623.     * @param {gs.Callback} callback - A callback function called if a choice has been picked by the user.
  624.     * @method showChoices
  625.     ###    
  626.     showChoices: (callback) ->
  627.         useFreeLayout = @object.choices.where((x) -> x.dstRect?).length > 0
  628.                
  629.         @object.choiceWindow?.dispose()
  630.        
  631.         if useFreeLayout
  632.             @object.choiceWindow = ui.UiFactory.createControlFromDescriptor(ui.UiFactory.customTypes["ui.FreeChoiceBox"], @object.layout)
  633.         else
  634.             @object.choiceWindow = ui.UiFactory.createControlFromDescriptor(ui.UiFactory.customTypes["ui.ChoiceBox"], @object.layout)
  635.        
  636.         @object.choiceWindow.events.on("selectionAccept", callback)
  637.         @object.choiceWindow.ui.prepare()
  638.        
  639.     ###*
  640.     * Changes the background of the scene.
  641.     *
  642.     * @method changeBackground
  643.     * @param {Object} background - The background graphic object -> { name }
  644.     * @param {boolean} noAnimation - Indicates if the background should be changed immediately witout any change-animation.
  645.     * @param {Object} animation - The appear/disappear animation to use.
  646.     * @param {Object} easing - The easing of the change animation.
  647.     * @param {number} duration - The duration of the change in frames.
  648.     * @param {number} ox - The x-origin of the background.
  649.     * @param {number} oy - The y-origin of the background.
  650.     * @param {number} layer - The background-layer to change.
  651.     * @param {boolean} loopHorizontal - Indicates if the background should be looped horizontally.
  652.     * @param {boolean} loopVertical - Indicates if the background should be looped vertically.
  653.     ###  
  654.     changeBackground: (background, noAnimation, animation, easing, duration, ox, oy, layer, loopHorizontal, loopVertical) ->
  655.         if background?
  656.             otherObject = @object.backgrounds[layer]
  657.             object = new vn.Object_Background()
  658.             object.image = background.name
  659.             object.origin.x = ox
  660.             object.origin.y = oy
  661.             object.viewport = @viewport
  662.             object.visual.looping.vertical = no
  663.             object.visual.looping.horizontal = no
  664.             object.update()
  665.            
  666.             @object.backgroundContainer.setObject(object, layer)
  667.                
  668.             duration = duration ? 30
  669.            
  670.             otherObject?.zIndex = layer
  671.             otherObject?.animator.otherObject?.dispose()
  672.            
  673.             if duration == 0
  674.                 otherObject?.dispose()
  675.                 object.visual.looping.vertical = loopVertical
  676.                 object.visual.looping.horizontal = loopHorizontal
  677.             else
  678.                 if noAnimation
  679.                     object.visual.looping.vertical = loopVertical
  680.                     object.visual.looping.horizontal = loopHorizontal
  681.                 else
  682.                     object.animator.otherObject = otherObject
  683.                     object.animator.appear(0, 0, animation, easing, duration, (sender) =>
  684.                         sender.update()
  685.                         sender.animator.otherObject?.dispose()
  686.                         sender.animator.otherObject = null
  687.                         sender.visual.looping.vertical = loopVertical
  688.                         sender.visual.looping.horizontal = loopHorizontal
  689.                     )
  690.         else
  691.             @object.backgrounds[layer]?.animator.hide duration, easing,  =>
  692.                @object.backgrounds[layer].dispose()
  693.                @object.backgrounds[layer] = null
  694.    
  695.    
  696.     ###*
  697.     * Skips all viewport animations except the main viewport animation.
  698.     *
  699.     * @method skipViewports
  700.     * @protected
  701.     ###
  702.     skipViewports: ->
  703.         viewports = @object.viewportContainer.subObjects
  704.         for viewport in viewports
  705.             if viewport
  706.                 for component in viewport.components
  707.                     component.skip?()
  708.         return null
  709.        
  710.     ###*
  711.     * Skips all picture animations.
  712.     *
  713.     * @method skipPictures
  714.     * @protected
  715.     ###  
  716.     skipPictures: ->
  717.         for picture in @object.pictures
  718.             if picture
  719.                 for component in picture.components
  720.                     component.skip?()
  721.         return null
  722.        
  723.     ###*
  724.     * Skips all text animations.
  725.     *
  726.     * @method skipTexts
  727.     * @protected
  728.     ###
  729.     skipTexts: ->
  730.        for text in @object.texts
  731.             if text
  732.                 for component in text.components
  733.                     component.skip?()
  734.         return null
  735.        
  736.     ###*
  737.     * Skips all video animations but not the video-playback itself.
  738.     *
  739.     * @method skipVideos
  740.     * @protected
  741.     ###
  742.     skipVideos: ->
  743.         for video in @object.videos
  744.             if video
  745.                 for component in video.components
  746.                     component.skip?()
  747.         return null
  748.        
  749.     ###*
  750.     * Skips all background animations.
  751.     *
  752.     * @method skipBackgrounds
  753.     * @protected
  754.     ###
  755.     skipBackgrounds: ->
  756.         for background in @object.backgrounds
  757.             if background
  758.                 for component in background.components
  759.                     component.skip?()
  760.         return null
  761.        
  762.     ###*
  763.     * Skips all character animations
  764.     *
  765.     * @method skipCharacters
  766.     * @protected
  767.     ###
  768.     skipCharacters: ->
  769.         for character in @object.characters
  770.             if character
  771.                 for component in character.components
  772.                     component.skip?()
  773.         return null
  774.      
  775.     ###*
  776.     * Skips the main viewport animation.
  777.     *
  778.     * @method skipMainViewport
  779.     * @protected
  780.     ###    
  781.     skipMainViewport: ->
  782.         for component in @object.viewport.components
  783.             component.skip?()
  784.         return null
  785.        
  786.     ###*
  787.     * Skips all animations of all message boxes defined in MESSAGE_BOX_IDS ui constant.
  788.     *
  789.     * @method skipMessageBoxes
  790.     * @protected
  791.     ###
  792.     skipMessageBoxes: ->
  793.         for messageBoxId in gs.UIConstants.MESSAGE_BOX_IDS || ["messageBox", "nvlMessageBox"]
  794.             messageBox = gs.ObjectManager.current.objectById(messageBoxId)
  795.             if messageBox.components
  796.                 for component in messageBox.components
  797.                     component.skip?()
  798.         return null
  799.      
  800.     ###*
  801.     * Skips all animations of all message areas.
  802.     *
  803.     * @method skipMessageAreas
  804.     * @protected
  805.     ###    
  806.     skipMessageAreas: ->
  807.         for messageArea in @object.messageAreas
  808.             if messageArea?.message
  809.                 for component in messageArea.message.components
  810.                     component.skip?()
  811.                
  812.         msg = gs.ObjectManager.current.objectById("gameMessage_message")    
  813.         if msg
  814.             for component in msg.components
  815.                 component.skip?()
  816.         msg = gs.ObjectManager.current.objectById("nvlGameMessage_message")    
  817.         if msg
  818.             for component in msg.components
  819.                 component.skip?()
  820.                    
  821.         return null
  822.        
  823.     ###*
  824.     * Skips the scene interpreter timer.
  825.     *
  826.     * @method skipInterpreter
  827.     * @protected
  828.     ###
  829.     skipInterpreter: ->
  830.         if @object.interpreter.waitCounter > GameManager.tempSettings.skipTime
  831.             @object.interpreter.waitCounter = GameManager.tempSettings.skipTime
  832.             if @object.interpreter.waitCounter == 0
  833.                 @object.interpreter.isWaiting = no
  834.    
  835.     ###*
  836.     * Skips the interpreter timer of all common events.
  837.     *
  838.     * @method skipCommonEvents
  839.     * @protected
  840.     ###  
  841.     skipCommonEvents: ->
  842.         events = @object.commonEventContainer.subObjects
  843.         for event in events
  844.             if event?.interpreter and event.interpreter.waitCounter > GameManager.tempSettings.skipTime
  845.                 event.interpreter.waitCounter = GameManager.tempSettings.skipTime
  846.                 if event.interpreter.waitCounter == 0
  847.                     event.interpreter.isWaiting = no
  848.                    
  849.     ###*
  850.     * Skips the scene's content.
  851.     *
  852.     * @method skipContent
  853.     * @protected
  854.     ###    
  855.     skipContent: ->
  856.         @skipPictures()
  857.         @skipTexts()
  858.         @skipVideos()
  859.         @skipBackgrounds()
  860.         @skipCharacters()
  861.         @skipMainViewport()
  862.         @skipViewports()
  863.         @skipMessageBoxes()
  864.         @skipMessageAreas()
  865.         @skipInterpreter()
  866.         @skipCommonEvents()
  867.    
  868.    
  869.     ###*
  870.     * Checks for the shortcut to hide/show the game UI. By default, this is the space-key. You
  871.     * can override this method to change the shortcut.
  872.     *
  873.     * @method updateUIVisibilityShortcut
  874.     * @protected
  875.     ###
  876.     updateUIVisibilityShortcut: ->
  877.         if !@uiVisible and (Input.trigger(Input.C) or Input.Mouse.buttonDown)
  878.             @changeUIVisibility(!@uiVisible)
  879.         if Input.trigger(Input.KEY_SPACE)
  880.             @changeUIVisibility(!@uiVisible)
  881.    
  882.     ###*
  883.     * Checks for the shortcut to exit the game. By default, this is the escape-key. You
  884.     * can override this method to change the shortcut.
  885.     *
  886.     * @method updateQuitShortcut
  887.     * @protected
  888.     ###        
  889.     updateQuitShortcut: ->
  890.         if Input.trigger(Input.KEY_ESCAPE)
  891.             gs.Application.exit()
  892.    
  893.    
  894.     ###*
  895.     * Checks for the shortcut to open the settings menu. By default, this is the s-key. You
  896.     * can override this method to change the shortcut.
  897.     *
  898.     * @method updateSettingsShortcut
  899.     * @protected
  900.     ###          
  901.     updateSettingsShortcut: ->
  902.         if GameManager.tempSettings.menuAccess and Input.trigger(Input.X)
  903.             SceneManager.switchTo(new gs.Object_Layout("settingsMenuLayout"), true)
  904.      
  905.     ###*
  906.     * Checks for the shortcut to open the settings menu. By default, this is the control-key. You
  907.     * can override this method to change the shortcut.
  908.     *
  909.     * @method updateSkipShortcut
  910.     * @protected
  911.     ###        
  912.     updateSkipShortcut: ->
  913.         if @object.settings.allowSkip
  914.             if Input.keys[Input.KEY_CONTROL] == 1
  915.                 GameManager.tempSettings.skip = yes
  916.             else if Input.keys[Input.KEY_CONTROL] == 2
  917.                 GameManager.tempSettings.skip = no
  918.                
  919.     ###*
  920.     * Checks for default keyboard shortcuts e.g space-key to hide the UI, etc.
  921.     *
  922.     * @method updateShortcuts
  923.     * @protected
  924.     ###
  925.     updateShortcuts: ->
  926.         @updateSettingsShortcut()
  927.         @updateQuitShortcut()
  928.         @updateUIVisibilityShortcut()
  929.         @updateSkipShortcut()
  930.  
  931.     ###*
  932.     * Updates the full screen video played via Play Movie command.
  933.     *
  934.     * @method updateVideo
  935.     ###  
  936.     updateVideo: ->
  937.         if @object.video?
  938.             @object.video.update()
  939.             if @object.settings.allowVideoSkip and (Input.trigger(Input.C) or Input.Mouse.buttons[Input.Mouse.LEFT] == 2)
  940.                 @object.video.stop()
  941.             Input.clear()
  942.      
  943.     ###*
  944.     * Updates skipping if enabled.
  945.     *
  946.     * @method updateSkipping
  947.     ###        
  948.     updateSkipping: ->
  949.         if !@object.settings.allowSkip
  950.             @object.tempSettings.skip = no
  951.            
  952.         if GameManager.tempSettings.skip
  953.             @skipContent()
  954.            
  955.     ###*
  956.     * Updates the scene's content.
  957.     *
  958.     * @method updateContent
  959.     ###      
  960.     updateContent: ->
  961.         #if !@object.interpreter.isRunning and !Graphics.frozen
  962.         #    @setupInterpreter()
  963.         GameManager.scene = @object
  964.         Graphics.viewport.update()
  965.         @object.viewport.update()
  966.    
  967.         @updateSkipping()
  968.         @updateVideo()
  969.         @updateShortcuts()
  970.  
  971.         super()
  972.        
  973. vn.Component_GameSceneBehavior = Component_GameSceneBehavior
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement