local mConversationInstances = {} local mDialogInstances = {} local mActionChoiceInstances = {} local mChoices = nil local mHighlightedIdx = nil local mDialogTimerThread = nil local mbDialogTimerRunning = false local mbDialogTimerRanOut = false local mbPause = false; local mbPreventInput = false; local mDisplayDelay = 0; local mDisplayDelayFull = 0; local mbJoystickOn = Platform_IsJoystickCentric() local mCurrentSubtitle = nil local kChoiceText = "Choice Display Text" local kChoiceID = "Choice ID" local kTextScale = "Text Scale" local kTextString = "Text String" local kTextColor = "Text Color" Callback_OnChoiceSelected = Callback(); Callback_OnChoiceInit = Callback(); require("mode_reticle.lua") mode_DialogChoice = { name = "mode_DialogChoice", parent = mode_Main, category = "interaction", scene = "ui_dialog.scene", inputMap = "ui_dialog.imap" } mode_DialogActionChoice = { name = "mode_dialogActionChoice", parent = mode_Main, category = "interaction", inputMap = "reticle.imap" } mode_DialogNoMovement = { name = "mode_DialogNoMovement", category = "movement", parent = mode_Main } ------------------------------------------------------------------------------- -- Checks for both indexed and named values local function tableIsEmpty( t ) if table.getn(t) > 0 then return false end for k,v in pairs(t) do return false end return true end -- -- local function TableCopy( source, dest, bDeep ) for index, value in pairs( source ) do if ( bDeep and IsTable( source[index] ) ) then dest[index] = {}; TableCopy( dest[index], source[index] ); else dest[index] = source[index]; end end end local function TableGetFirst( t ) for i, v in pairs( t ) do return v end return nil end ------------------------------------------------------------------------------- -- Dialog Timer ------------------------------------------------------------------------------- local function getChoiceProgressPercent( timedChoices, timerController ) if timedChoices and table.getn( timedChoices ) > 0 then return 1 - (timedChoices[1]["Remaining"] - mDisplayDelayFull) / (timedChoices[1]["Total"] - mDisplayDelayFull) elseif timerController and ControllerIsPlaying( timerController ) then return (ControllerGetTime( timerController ) - mDisplayDelayFull) / (ControllerGetLength( timerController ) - mDisplayDelayFull) end -- print( "got nothing" ) return 1 end local function updateDialogTimer( instance ) -- get the timed choices or playback controller being used as a timer local timedChoices local timerController = DlgGetCurPlaybackController( instance ) -- Print( "Started dlg timer" ) -- play the show chore ChorePlay( "ui_dialog_timerOpen.chore" ) -- start up the timer chore local ctl = ChorePlay( "ui_dialog_timer.chore" ) ControllerPause( ctl ) mbDialogTimerRunning = true while mbDialogTimerRunning do if ( mbPause ) then ControllerPause( timerController ); elseif( not mbPause ) then if( ControllerIsPaused( timerController ) ) then ControllerPlay( timerController ); end end -- poll timed choices every frame, otherwise we don't get progress updates timedChoices = DlgGetChoices( instance, true ) local pct = getChoiceProgressPercent( timedChoices, timerController ) -- Suppress the dialog UI close if we got far enough for this to look -- like it faded out if pct > .97 then mbDialogTimerRanOut = true end -- if we're done with progressing through, exit if pct >= 1 then break end -- set the timer UI % ControllerSetTimePercent( ctl, pct ) Yield() end -- Print( "Closing dlg timer" ) -- close timer and clean up ControllerKill(ctl) ChorePlayAndWait( "ui_dialog_timerClose.chore" ) mbDialogTimerRunning = false mDialogTimerThread = nil end local function startDialogTimer( instance ) -- Print( "Trying to start dlg timer" ) -- get the timed choices or playback controller being used as a timer local timedChoices = DlgGetChoices( instance, true ) local timerController = DlgGetCurPlaybackController( instance ) -- if there's no timed choices or timer controller, no need to show the timer if not ( ( timedChoices and table.getn( timedChoices ) > 0 ) or (timerController and not Logic.bDelayChoices) ) then return end -- start the update thread, if there's not one running if not mDialogTimerThread then mDialogTimerThread = ThreadStart( updateDialogTimer, instance ) end end -- leaving this as a separate function in case we need to do more timer closing stuff later local function closeDialogTimer() mbDialogTimerRunning = false end ------------------------------------------------------------------------------- local function subtitlesOnTopOkay() return LocalizationGetEnabled("spanish") or Platform_IsIOS() end local function openDialogUI() -- Note: This function shouldn't get run unless there are choices, -- but it's possible for them to go away before the open chore is finished. -- This is fine: another function will queue up a mode end, which will be -- run after this finishes. We just have to handle it correctly here. if not subtitlesOnTopOkay() then -- Suppress subtitles from ambient chores while the dialog choice is up AgentSetProperty("logic_module_subtitles", "Subtitles - Hidden", true) end -- Make sure this is set to whatever we open the UI with mbJoystickOn = Logic.bUsingJoystick if Logic.bUsingJoystick or Platform_IsIOS() then ChorePlayAndWait("ui_dialog_openGamepad.chore") else ChorePlayAndWait("ui_dialog_openMouse.chore") end mbDialogTimerRanOut = false local choice = TableGetFirst( mChoices ) if choice then startDialogTimer( choice.instance ) else print("Warning: Dialog choices went away real fast! Maybe there's a choice node with nothing after it.") end end local function closeDialogUI() closeDialogTimer() if not mbDialogTimerRanOut then if Logic.bUsingJoystick or Platform_IsIOS() then ChorePlayAndWait("ui_dialog_closeGamepad.chore") else ChorePlayAndWait("ui_dialog_closeMouse.chore") end end AgentSetProperty("logic_module_subtitles", "Subtitles - Hidden", false) while mDialogTimerThread do Yield() end end local function getPane( idx, bGamepad ) if bGamepad == nil then bGamepad = Logic.bUsingJoystick end if bGamepad then return AgentFind("ui_dialog_Item"..idx.."Gamepad") else return AgentFind("ui_dialog_Item"..idx) end end local function enterChoiceMode(instance, choices) if mActionChoiceInstances[instance] then mChoices = choices for i, choice in ipairs(choices) do choice.instance = instance end Mode_Push(mode_DialogActionChoice) else Mode_Push(mode_DialogChoice) end end local function endChoiceMode() Mode_End(mode_DialogChoice) Mode_End(mode_DialogActionChoice) Mode_End(mode_DialogNoMovement) end ------------------------------------------------------------------------------- -- Internal callbacks local function onNodeBegin(nodeID,dlgName,instanceID) --function onNodeBegin(dlgName, nodeID, instanceID, executionCount) -- Hack! if Reticle_IsReticleInstance( instanceID ) then return end --[[ Nowadays, a reticle presentation dialog choice is perfectly valid! if DlgGetObjUserPropsValue( dlgName, nodeID, "Reticle presentation" ) then mDialogReticleInstance = instanceID end --]] -- Track reticle presentation flag local reticlePresentation = DlgGetObjUserPropsValue( dlgName, nodeID, "Reticle presentation" ) if reticlePresentation == true then mActionChoiceInstances[instanceID] = true elseif reticlePresentation == false then mActionChoiceInstances[instanceID] = nil end -- If it's equal to neither true nor false, it's nil, and it's because the current node -- doesn't have this prop. Leave the flag alone. -- Track choice display delay. -- For anything other than Choices nodes, this will be false. local displayDelay = DlgGetObjUserPropsValue( dlgName, nodeID, "Delay choice display" ) if displayDelay then mDisplayDelay = displayDelay mDisplayDelayFull = displayDelay end -- If a node began within the dialog instance that our conversation is running on... -- AND if that node is a cutscene, then we're probably not in a conversation anymore.... right? if( mDialogInstances[instanceID] ) then -- Only do this check for EXCHANGE nodes. local evalNode = DlgEvaluateToNode(dlgName, nodeID, "exchange", false) if evalNode and nodeID == evalNode["Node ID"] then if ( not DlgGetObjUserPropsValue( dlgName, nodeID, "Dialog node - Ambient Line" ) ) then endChoiceMode() end end -- Also get rid of dialog choice mode if we simply don't have any choices. local nchoices = table.getn(DlgGetChoices(instanceID)) if nchoices <= 0 then endChoiceMode() end end end -- If a choice has no visible children, we kill the dialog to prevent a soft lock. -- Such occurences are really content bugs, but handling it here will minimize the damage. function onChoiceNodeEnd( nodeID, dlgName, instance, nodePlayCount ) local choices = DlgGetChoices(instance) if choices == nil or table.getn(choices) == 0 then DlgStop(instance) end end local function onChoice(instance) if not DlgIsRunning(instance) then return end -- Hack! if Reticle_IsReticleInstance( instance ) then Reticle_HandleReticleInstance( instance ) return end local choices = DlgGetChoices(instance) if table.getn(choices) <= 0 then return end -- If there's only one choice left, and it's an "exit" choice, -- pick it without bothering to display the choice interface. if table.getn(choices) == 1 then local choice = choices[1] if DlgGetObjUserPropsValue( choice["Dlog"], choice["Choice Object ID"], "Exit Choice" ) then Logic["Dialog exhausted"] = true DlgSelectChoice(instance, choice[kChoiceID]) return end end Logic["Dialog exhausted"] = false mDialogInstances[instance] = instance -- Logic["Dialog: leave"] = false if not Mode_IsOnStack(mode_DialogNoMovement) then mConversationInstances[instance] = instance Mode_Push(mode_DialogNoMovement) end enterChoiceMode(instance, choices) end local function onEnd(instance) if mDialogInstances[instance] then mDialogInstances[instance] = nil local count = 0 for k,v in pairs(mDialogInstances) do count = count+1 end if count == 0 then endChoiceMode() end end mConversationInstances[instance] = nil mActionChoiceInstances[instance] = nil if tableIsEmpty(mConversationInstances) then Mode_End(mode_DialogNoMovement) end end ------------------------------------------------------------------------------- local function unhighlight() if Logic.bUsingJoystick and not Platform_IsIOS() then return end if mHighlightedIdx then local idx = mHighlightedIdx mHighlightedIdx = nil if Platform_IsIOS() then if idx == 1 or idx == 4 then ShaderOverrideAllTextures("ui_dialog_facebutton"..idx, "ui_dialog_iOS_button1.d3dtx") else ShaderOverrideAllTextures("ui_dialog_facebutton"..idx, "ui_dialog_iOS_button2.d3dtx") end --ChorePlay("ui_dialog_itemRollOff.chore", nil, "default", AgentGetName(getPane(idx, true))) else ChorePlay("ui_dialog_itemRollOff.chore", nil, "default", AgentGetName(getPane(idx, false))) end end end local function highlight( idx, bForce ) local bIOS = Platform_IsIOS() if Logic.bUsingJoystick and not bIOS then return end if not idx then return end local minChoice = nil local maxChoice = nil for i=1,4 do if mChoices[i] then if not minChoice then minChoice = i end maxChoice = i end end if idx < minChoice then idx = minChoice elseif idx > maxChoice then idx = maxChoice end if mHighlightedIdx then if mHighlightedIdx == idx then if not bForce then return end else unhighlight() end end local changed = (mHighlightedIdx ~= idx) mHighlightedIdx = idx if bIOS then --ChorePlay("ui_dialog_itemRollOn.chore", nil, "default", AgentGetName(getPane(idx, true))) if idx == 1 or idx == 4 then ShaderOverrideAllTextures("ui_dialog_facebutton"..idx, "ui_dialog_iOS_button1roll.d3dtx") else ShaderOverrideAllTextures("ui_dialog_facebutton"..idx, "ui_dialog_iOS_button2roll.d3dtx") end --ChorePlay("ui_dialog_itemRollOn.chore", nil, "default", AgentGetName(getPane(idx, true))) if changed and idx then SoundPlay("ui_click_1.wav") end else ChorePlay("ui_dialog_itemRollOn.chore", nil, "default", AgentGetName(getPane(idx, false))) end end local mstr = "" function ShowStringCallback() AgentSetProperty("ui_helptext_text", "Text String", mstr) SceneHide("ui_helptext.scene", false) AgentHide("ui_helptext_text", false) end function ShowString(str) mstr = str SceneAdd("ui_helptext.scene", "ShowStringCallback") end local function highlightUnderCursor() -- Used in iOS only. Highlights the choice under the cursor position, or unhighlights if nothing is. local agent = CursorGetAgent() local idx = nil for i=1, 4 do if mChoices[i] and agent == AgentFind("ui_dialog_Item"..i.."Gamepad") then idx = i end end if idx then highlight(idx) else unhighlight() end end local mbSelectingChoice = false -- are we currently processing a selection? local function selectChoice( idx ) if ( mbPreventInput ) then return; end Callback_OnChoiceSelected:Run( idx ); mbDialogTimerRanOut = false -- don't process this selection if we're already in the process of selecting something if mbSelectingChoice then return end -- if we're on gamepad, and there's no idx specified, we clicked the A button if Logic.bUsingJoystick and not idx and not Platform_IsIOS() then idx = 1 end idx = idx or mHighlightedIdx Callback_OnChoiceInit:Run( mChoices[idx] ); if idx and mChoices[idx] then mbSelectingChoice = true local choice = mChoices[idx] local bSilent = DlgGetObjUserPropsValue( choice["Dlog"], choice["Choice Object ID"], "Silent Choice" ) local cont = DlgGetCurPlaybackController( choice["instance"] ) -- Only let the current subtitle block if it's from the same dialog as the choice local blockingSubtitle = nil local subtitleInstance = SubtitleGetDlgInstanceID(mCurrentSubtitle) if subtitleInstance == choice["instance"] then blockingSubtitle = mCurrentSubtitle end -- Wait for anything that's deliberately blocking dialog choices to finish blocking them. -- The following things can deliberately block dialog choices: -- * The logic key "bDelayChoices", which we can turn on and off arbitrarily -- * A subtitled line from the same dialog as the choice is in progress -- * If the choice is flagged as "silent", an exchange in progress on the same dialog instance if blockingSubtitle or (bSilent and ControllerIsPlaying(cont)) or Logic.bDelayChoices then Cutscene_Start(choice["instance"]) ControllerPlay( cont ); while (mCurrentSubtitle and (mCurrentSubtitle == blockingSubtitle)) or (bSilent and ControllerIsPlaying(cont)) or Logic.bDelayChoices do Yield() end end DlgSelectChoice(choice["instance"], mChoices[idx][kChoiceID]) if not Cutscene_IsActive() then Cutscene_Start(choice["instance"]) end if AgentExists("ui_dialog.scene") then ChorePlay("ui_dialog_itemSelect.chore", 200, "default", AgentGetName(getPane(idx))) end endChoiceMode() mbSelectingChoice = false end end -- put the exit choice on B/Circle local function reorderExitChoice() local slot = 2 for i=1,4 do local choice = mChoices[i] if choice and i ~= slot and DlgGetObjUserPropsValue( choice["Dlog"], choice["Choice Object ID"], "Exit Choice" ) then local swap = mChoices[slot] mChoices[slot] = mChoices[i] mChoices[i] = swap break end end end -- put the silent choice on X/Square local function reorderSilentChoice() local slot = 3 for i=1,4 do local choice = mChoices[i] if choice and i ~= slot and DlgGetObjUserPropsValue( choice["Dlog"], choice["Choice Object ID"], "Silent Choice" ) then local swap = mChoices[slot] mChoices[slot] = mChoices[i] mChoices[i] = swap break end end end -- Exchanges the UI positions of two dialog choices, given their current positions. (Passing in the position of an empty slot is fine.) local function swapChoices( pos1, pos2 ) local swap = mChoices[pos1] mChoices[pos1] = mChoices[pos2] mChoices[pos2] = swap end -- reorder dialog choices after getting them (gamepad only) local function orderChoices( bForceUsingJoystick ) local numChoices = table.getn( mChoices ) -- On iOS, use the bottom row if you don't need both rows. if Platform_IsIOS() then if numChoices < 3 then mChoices[3] = mChoices[1] mChoices[4] = mChoices[2] mChoices[1] = nil mChoices[2] = nil end return end if not bForceUsingJoystick and not Logic.bUsingJoystick then return end -- if there are only 2 choices, put them on the East and West face buttons -- there will already be one on East, so just move South to West if numChoices == 2 then if mChoices[1] then mChoices[3] = mChoices[1] mChoices[1] = nil end -- if the choice doesn't have a preferred spot set, then randomize the pair. -- TODO: Make dialog choices actually respect "Preferred Button Assignment" (it only works for Reticle at the moment) if DlgGetObjUserPropsValue( mChoices[3]["Dlog"], mChoices[3]["Choice Object ID"], "Preferred Button Assignment" ) == 0 then -- 50% change to randomly swap the choices: Print("Rolling for random...") --DlgGetObjUserPropsValue( DlgGetCurrentDialog( instance ), choice["Choice Object ID"], "Preferred Button Assignment" ) if (math.floor(math.random() * 10)) % 2 == 1 then swapChoices(2, 3) end else end -- If there are more than 2 choices, randomize the choices elseif table.getn( mChoices ) > 2 then local copy = {} TableCopy( mChoices, copy ) local numElements = numChoices mChoices = {} while ( numElements > 0 ) do -- Remove a random element from the copy and insert it at the end of the new table table.insert( mChoices, table.remove( copy, RandomInt( 1, numElements ) ) ) numElements = numElements - 1 end end -- Respect "Preferred Button Assignment" for i=1,4 do if mChoices[i] then mChoices[i].preferredButton = DlgGetObjUserPropsValue( mChoices[i]["Dlog"], mChoices[i]["Choice Object ID"], "Preferred Button Assignment" ) end end -- Check for conflicts for i=1,3 do if mChoices[i] and mChoices[i].preferredButton ~= 0 then for j=i+1,4 do if mChoices[j] and mChoices[j].preferredButton == mChoices[i].preferredButton then print("WARNING: Two dialog choices have the same preferred button assignment! One will be ignored.") mChoices[j].preferredButton = 0 end end end end -- Now that there are no conflicts, we can just swap everything into place for i=1, 4 do while mChoices[i] and mChoices[i].preferredButton ~= 0 and mChoices[i].preferredButton ~= i do swapChoices(i, mChoices[i].preferredButton) end end reorderExitChoice() reorderSilentChoice() end local function displayChoices( bForceUsingJoystick ) mChoices = {} for k,instance in pairs( mDialogInstances ) do local choices = DlgGetChoices(instance) for i, choice in ipairs(choices) do choice.instance = instance table.insert(mChoices, choice) end end if table.getn(mChoices) == 0 then endChoiceMode() return end Tooltip_Clear() -- QA is imatient! Must clear tooltips immediately! AgentSetProperty( "ui_tooltip_noun", "Text String", "" ) AgentSetProperty( "ui_tooltip_verb", "Text String", "" ) orderChoices( bForceUsingJoystick ) for i=1,4 do if mChoices[i] then local choicetxt = mChoices[i][kChoiceText]; if ( not choicetxt ) then choicetxt = mChoices[ i ][ "First Line" ]; end -- special case: if this is a silent choice, use the silence text from text.dlog if DlgGetObjUserPropsValue( mChoices[i]["Dlog"], mChoices[i]["Choice Object ID"], "Silent Choice" ) then choicetxt = Dialog_GetText( "text_silence", nil, "text.dlog" ) -- special case: if this is an exit choice, use the silence text from text.dlog elseif DlgGetObjUserPropsValue( mChoices[i]["Dlog"], mChoices[i]["Choice Object ID"], "Exit Choice" ) then choicetxt = Dialog_GetText( "text_exit", nil, "text.dlog" ) end -- no text found anywhere if ( not choicetxt or choicetxt == "" ) then choicetxt = " "; if IsToolBuild() then Print( "No display text found!", 0 ) end end AgentSetProperty(getPane(i, false), kTextString, choicetxt) AgentSetProperty(getPane(i, true), kTextString, choicetxt) AgentSetProperty("ui_dialog_facebutton"..i, "Render Constant Alpha Multiply", 1) --AgentHide(pane, false) else AgentSetProperty(getPane(i, false), kTextString, "") AgentSetProperty(getPane(i, true), kTextString, "") AgentSetProperty("ui_dialog_facebutton"..i, "Render Constant Alpha Multiply", 0) end end -- (now handled in mode's OnActivate function) -- openDialogUI() end local function changeInput(bUsingJoystick) if Platform_IsIOS() then return end -- Prevent repeated callbacks by checking current state if mbJoystickOn == bUsingJoystick then return end mbJoystickOn = bUsingJoystick displayChoices(bUsingJoystick) if bUsingJoystick then if( ReticleUI_IsEnabled() ) then ThreadStart( function() ChorePlayAndWait("ui_reticle_hideMouse.chore" ) ChorePlayAndWait("ui_reticle_showNav.chore") end ); end ChorePlayAndWait("ui_dialog_mousetogamepad.chore") else if( ReticleUI_IsEnabled() ) then ThreadStart( function() ChorePlayAndWait("ui_reticle_hideNav.chore") ChorePlayAndWait("ui_reticle_showMouse.chore") end ); end ChorePlayAndWait("ui_dialog_gamepadtomouse.chore") end -- force re-highlight = true highlight(mHighlightedIdx, true) end ------------------------------------------------------------------------------- -- The dialog interface mode function mode_DialogChoice:OnStart() -- If desired, Wait a little while before activating the mode if mDisplayDelay > 0 then if Platform_IsIOS() then -- Maybe do this on all platforms? AgentHide("dialogParent", true, true) -- The open chore will unhide stuff end -- We don't want to just sleep, because that will ignore time scale (I think). local accum = 0 while accum < mDisplayDelay do Yield() accum = accum + (GetFrameTime()*SceneGetTimeScale(SceneGetBottomScene())) end mDisplayDelay = 0 end if not Platform_IsIOS() then ShaderOverrideAllTextures("ui_dialog_facebutton1", "ui_dialog_facebutton_A.d3dtx") ShaderOverrideAllTextures("ui_dialog_facebutton2", "ui_dialog_facebutton_B.d3dtx") ShaderOverrideAllTextures("ui_dialog_facebutton3", "ui_dialog_facebutton_X.d3dtx") ShaderOverrideAllTextures("ui_dialog_facebutton4", "ui_dialog_facebutton_Y.d3dtx") end Callback_OnUsingJoystick:Add(changeInput) displayChoices() -- getn returns 0 if the first element is missing -- element at index 1 will be missing after rearranging the buttons for gamepad -- Instead, use tableIsEmpty on mChoices if tableIsEmpty( mChoices ) then Mode_End(mode_DialogChoice) return end --Callback_DialogOnNodeBegin:Add( onNodeBegin ); if not Platform_IsIOS() then mHighlightedIdx = 1 end end function mode_DialogChoice:OnEnd() -- Print( "mode_DialogChoice:OnEnd" ) Callback_OnUsingJoystick:Remove(changeInput) --mDialogInstances = {} --Callback_DialogOnNodeBegin:Remove( onNodeBegin ); end function mode_DialogChoice:OnActivate() if subtitlesOnTopOkay() then AgentSetProperty("logic_module_subtitles", "Subtitles - Align to Bottom", false) end --Print( "mode_DialogChoice:OnActivate" ) SceneHide(self.scene, false) AgentFind( "logic_reticle" ).mProps[ "Reticle Display Mode" ] = "Navigation"; openDialogUI() -- force re-highlight = true if Platform_IsIOS() then --highlightUnderCursor() mHighlightedIdx = nil --[[ for k=1,4 do --if k ~= mHighlightedIdx then ChorePlay("ui_dialog_itemRollOff.chore", nil, "default", AgentGetName(getPane(k, true))) --end end --]] else highlight( mHighlightedIdx, true ) end end function mode_DialogChoice:OnDeactivate() if subtitlesOnTopOkay() and mCurrentSubtitle then ThreadStart(function() local s = mCurrentSubtitle while s == mCurrentSubtitle do Yield() end AgentSetProperty("logic_module_subtitles", "Subtitles - Align to Bottom", true) end) else AgentSetProperty("logic_module_subtitles", "Subtitles - Align to Bottom", true) end --Print( "mode_DialogChoice:OnDeactivate" ) closeDialogUI() SceneHide(self.scene, true) AgentFind( "logic_reticle" ).mProps[ "Reticle Display Mode" ] = "Select"; -- Print( "mode_DialogChoice done deactivating" ) end function mode_DialogChoice:OnScrollUp( evt ) if ( mbPreventInput ) then return; end if Logic.bUsingJoystick then return end local x = mHighlightedIdx - 1 highlight(x) end function mode_DialogChoice:OnScrollDown( evt ) if ( mbPreventInput ) then return; end if Logic.bUsingJoystick then return end local x = mHighlightedIdx + 1 highlight(x) end function mode_DialogChoice:OnMouseDown( evt ) if ( mbPreventInput ) then return; end if not Platform_IsIOS() then selectChoice() end end function mode_DialogChoice:OnMouseUp( evt ) if ( mbPreventInput ) then return; end if Platform_IsIOS() then selectChoice() end end -- -- function mode_DialogChoice:OnUp( evt ) if ( mbPreventInput ) then return; end if Logic.bUsingJoystick then return end local x = mHighlightedIdx - 1 highlight(x) end -- -- function mode_DialogChoice:OnDown( evt ) if ( mbPreventInput ) then return; end if Logic.bUsingJoystick then return end local x = mHighlightedIdx + 1 highlight(x) end -- -- function mode_DialogChoice:OnEnter( evt ) if ( mbPreventInput ) then return; end selectChoice() end function mode_DialogChoice:OnMouseMove( evt ) -- This is only relevant on iOS. if Platform_IsIOS() then highlightUnderCursor() end end function mode_DialogChoice:OnChoice( evt ) if ( mbPreventInput ) then return; end local which = evt.code - 48 -- ascii '0' if mChoices[which] then selectChoice(which) end end function mode_DialogChoice:OnChoice1( event ) selectChoice(1) end function mode_DialogChoice:OnChoice2( event ) selectChoice(2) end function mode_DialogChoice:OnChoice3( event ) selectChoice(3) end function mode_DialogChoice:OnChoice4( event ) selectChoice(4) end ------------------------------------------------------------------------------- function mode_DialogActionChoice:OnActivate() --[[ Reticle_ShowReticle() -- hide the useicon agents -- We don't do this in the scene's initial state because the agents don't -- get their mesh properties until they are first visible in the scene. -- This avoids Lua errors when trying to initially set the useicon textures. for i = 1, 4 do AgentHide("ui_useIcon" .. i, true) end Reticle_UpdateActionIcons(nil, mChoices) --]] end function mode_DialogActionChoice:OnDeactivate() -- Reticle_ClearActionIcons() -- Reticle_HideReticle() end function mode_DialogActionChoice:DoAction() local idx = Reticle_GetSelectionIndex() DlgSelectChoice(mChoices[idx]["instance"], mChoices[idx][kChoiceID]) endChoiceMode() end function mode_DialogActionChoice:OnMouseUp( event ) end mode_DialogActionChoice.OMouseDown = mode_Reticle.OnMouseDown mode_DialogActionChoice.OnScrollUp = mode_Reticle.OnScrollUp mode_DialogActionChoice.OnScrollDown = mode_Reticle.OnScrollDown mode_DialogActionChoice.OnMouseDown = mode_Reticle.OnMouseDown mode_DialogActionChoice.OnChoice = mode_Reticle.OnChoice mode_DialogActionChoice.OnChoice1 = mode_Reticle.OnChoice1 mode_DialogActionChoice.OnChoice2 = mode_Reticle.OnChoice2 mode_DialogActionChoice.OnChoice3 = mode_Reticle.OnChoice3 mode_DialogActionChoice.OnChoice4 = mode_Reticle.OnChoice4 mode_DialogActionChoice.OnDUp = mode_Reticle.OnDUp mode_DialogActionChoice.OnDDown = mode_Reticle.OnDDown mode_DialogActionChoice.OnDLeft = mode_Reticle.OnDLeft mode_DialogActionChoice.OnDRight = mode_Reticle.OnDRight mode_DialogActionChoice.OnMouseMove = mode_Reticle.OnMouseMove mode_DialogActionChoice.OnRightStick = mode_Reticle.OnRightStick ------------------------------------------------------------------------------- Callback_SubtitleOnCreate:Add( function(id) mCurrentSubtitle = id end ) Callback_SubtitleOnDestroy:Add( function(id) if id == mCurrentSubtitle then mCurrentSubtitle = nil end end ) ------------------------------------------------------------------------------- -- Initialization local function OnLogicReady() AgentSetProperty( "logic_module_subtitles", "Subtitles - Align to Bottom", true ) -- in case we do a scene load while in dialog choice mode end local function init() Callback_DialogOnNodeBegin:Add( onNodeBegin ); Callback_DialogOnChoices:Add( onChoice ) Callback_DialogOnEnd:Add( onEnd ) Callback_LogicReady:Add( OnLogicReady ) --DlgSetCallbackNodeEnd("onChoiceNodeEnd", "choices") end function PauseDialogTimer( bPause ) mbPause = bPause; end function DialogPreventInput( bPreventInput ) mbPreventInput = bPreventInput; end init()