local mCutsceneInstance = nil local mCutsceneNodeChoreName = nil -- used for debugging in tool buiilds, so we can get the na e of both cutscenes playing at once. local mCutsceneNode = nil local mbCutsceneEndingMaybe = false local mbSuppressWarning = false; local mbInCutscene = false local mbFramed = false local bIOS = Platform_IsIOS() local mbSuppressingReticle = false local function frame() if bIOS and not mbFramed and not ReticleUI_InCombatMode() then mbFramed = DlgGetObjUserPropsValue(DlgGetCurrentDialog(mCutsceneInstance), mCutsceneNode, "Force border on") if not mbFramed then local cameraMoveable = Main_VirtualStickControlsCamera() local controller = DlgGetCurPlaybackController(mCutsceneInstance) mbFramed = (not cameraMoveable) and controller and ControllerIsPlaying(controller) and (ControllerGetLength(controller) - ControllerGetTime(controller)) > 4 end if mbFramed then SceneHide("ui_cutsceneFrame.scene", false) ChorePlay("ui_cutsceneFrame_show.chore") end end if not bIOS then DisableReticle( DlgGetObjUserPropsValue(DlgGetCurrentDialog(mCutsceneInstance), mCutsceneNode, "Force reticle off") ) end end local function unframe() if bIOS and mbFramed then mbFramed = false ChorePlay("ui_cutsceneFrame_hide.chore") end DisableReticle(false) end function Cutscene_IsFramed() return mbFramed end function Cutscene_OnCameraChange() if bIOS and Mode_IsActive(mode_Cutscene_Interaction) then frame() end end function Cutscene_InitFrame() -- In theory, the scene should be fully loaded at this point, -- but doing SceneHide immediately doesn't always work. -- I suspect residue from chores still in progress when the -- scene load occurs. RenderDelay(1) Yield() SceneHide("ui_cutsceneframe.scene", true) SceneAddOnCameraChangeCallback(SceneGetBottomScene(), "Cutscene_OnCameraChange") end if bIOS then SceneAdd("ui_cutsceneFrame.scene", "Cutscene_InitFrame") end --[[ mode_Cutscene = { name = "mode_Cutscene" } function mode_Cutscene:OnEnd() mCutsceneInstance = nil mCutsceneNode = nil end --]] -- Actually we're going to use a couple of submodes of mode_main. mode_Cutscene_Movement = { name = "mode_Cutscene_Movement", category = "movement", parent = mode_Main } mode_Cutscene_Interaction = { name = "mode_Cutscene_Interaction", category = "interaction", parent = mode_Main } function mode_Cutscene_Interaction:OnActivate() frame() end function mode_Cutscene_Interaction:OnEnd() unframe() end local function nodeIsType(nodeID, dlg, nodeType) local found = DlgEvaluateToNode(dlg, nodeID, nodeType, false) if found then return found["Node ID"] == nodeID else return false end end ------------------------------------------------------------------------------- -- Internal callbacks function cutscene_OnDialogChoices(instance) -- If we're in the cutscene mode and we got dialog choices, we probably don't want them anymore. -- Therefore, let's kill that dialog instance. if ( Mode_IsActive(mode_Cutscene) ) then DlgStop( instance ); end end function Cutscene_SuppressWarning( bSuppress ) mbSuppressWarning = bSuppress; end ------------------------------------------------------------------------------- function Cutscene_IsActive() return Mode_IsOnStack(mode_Cutscene_Movement) or Mode_IsOnStack(mode_Cutscene_Interaction) end function Cutscene_Start( instance, node, dlgName ) AgentFind( "Lee" ).mProps[ "Look At - Enabled" ] = false; if mCutsceneInstance ~= instance then if ( not mbSuppressWarning ) then if mCutsceneInstance ~= nil then print("***** Attempt to play two cutscenes at once") if IsToolBuild() then if nodeIsType(node, dlgName, "exchange") then local newChoreName = DlgExchangeGetChore(dlgName,node) Print("*** Starting exchange: " .. newChoreName ); Print("*** Exchange already playing: " .. mCutsceneNodeChoreName ); end end end assert(mCutsceneInstance == nil, "Attempt to play two cutscenes at once") else DlgStop( mCutsceneInstance ); end if mbInCutscene then mCutsceneInstance = instance return end ThreadQueue_Enter("cutscene") if mCutsceneInstance == nil or mbCutsceneEndingMaybe then mCutsceneNode = node mbCutsceneEndingMaybe = false end mCutsceneInstance = instance -- in tool builds, save the name of the cutscene we're playing so we can use it for debug output later if something else -- tries to play at the same time. if IsToolBuild() then if nodeIsType(node, dlgName, "exchange") then mCutsceneNodeChoreName = DlgExchangeGetChore(dlgName,node) end end --Mode_Push(mode_Cutscene) mbInCutscene = true Mode_Push(mode_Cutscene_Movement) Mode_Push(mode_Cutscene_Interaction) DialogManager_setQueueing(true) ThreadQueue_Leave("cutscene") else mCutsceneNode = node mbCutsceneEndingMaybe = false end end function Cutscene_End() --Mode_Pop(mode_Cutscene) ThreadQueue_Enter("cutscene") mbInCutscene = false Mode_Pop(mode_Cutscene_Interaction) Mode_Pop(mode_Cutscene_Movement) local choices = DlgGetChoices(mCutsceneInstance) if not (choices and choices[1]) then DialogManager_setQueueing(false) end mCutsceneInstance = nil mCutsceneNodeChoreName = "" mCutsceneNode = nil mbCutsceneEndingMaybe = false ThreadQueue_Leave("cutscene") end local function onNodeBegin( nodeID, dlgName, dialogInstanceID, nodePlayCount ) -- Only pay attention to exchange, chore, and wait nodes if not (nodeIsType(nodeID, dlgName, "exchange") or nodeIsType(nodeID, dlgName, "chore") or nodeIsType(nodeID, dlgName, "wait")) then return end local isCutscene = not DlgGetObjUserPropsValue( dlgName, nodeID, "Dialog node - Ambient line" ) and not DlgGetObjUserPropsValue( dlgName, nodeID, "Dialog Node - Player Controlled Playback" ) if isCutscene then Cutscene_Start(dialogInstanceID, nodeID, dlgName) Yield() frame() elseif mCutsceneInstance == dialogInstanceID and mbCutsceneEndingMaybe then Cutscene_End() end end local function onNodeEnd( nodeID, dlgName, dialogInstanceID, nodePlayCount ) if mCutsceneInstance == dialogInstanceID and mCutsceneNode == nodeID then mbCutsceneEndingMaybe = true end end local function onDialogEnd( id ) if id == mCutsceneInstance then Cutscene_End() DialogManager_setQueueing(false) end end Callback_DialogOnNodeBegin:Add( onNodeBegin ) Callback_DialogOnNodeEnd:Add( onNodeEnd ) Callback_DialogOnEnd:Add( onDialogEnd ) ------------------------------------------------------------------------------- -- Special "cutscene" mode for use in the tool menu -- I'm keeping this separate so that you'll never be kicked out of tool cutscene -- mode by a dialog callback or whatever. local mode_ToolCutscene = { name = "mode_ToolCutscene" } function mode_ToolCutscene:OnActivate() CursorHide(false) AgentFind( "Lee" ).mProps[ "Look At - Enabled" ] = false; end function ToggleCutsceneMode() if Mode_IsOnStack(mode_ToolCutscene) then Mode_Pop(mode_ToolCutscene) else Mode_Push(mode_ToolCutscene) end end if IsToolBuild() then InputMapperActivate("devcutscene.imap") end