Benutzer-Werkzeuge

Webseiten-Werkzeuge


utilscripts:cutscenecreatingtools2

Erklärung hier.

function InitCutsceneCreatingTools()
    CutsceneCreatingTools = {
                                EscapeOrig      = GameCallback_Escape,        --Esc
                                CinematicMode      = false,
                                Music            = Music.GetVolumeAdjustment(),
                                MusicUpdateOrig  = LocalMusic_UpdateMusic,
                                MusicEnd            = 0,
                                MusicSet            = LocalMusic.SetBriefing,
                                MusicTimes      = 5,
                                MusicJob            = 0,
                                ToggleMenu      = GUIAction_ToggleMenu,      --F1 - F5
                                QuickSave         = QuickSave,            --F6
                                QuickLoad         = QuickLoad,            --F7
                                ToggleClock   = KeyBindings_ToggleClock,   --F8
                                ToggleSound   = assert(KeyBindings_ToggleSound), --F12
                                TogglePause   = KeyBindings_TogglePause,   --Break
                                SelectTroops        = GroupSelection_SelectTroops,
                                ZoomStart         = 4000,
                                AngleStart      = 30,
                                CinemaText1   = "@color:0,255,0 Pfeiltasten\t\tPositions-Einstellung @cr F1 + F2\t\tZoom-Einstellung @cr Entf + Einfg\t\tRotations-Einstellung @cr F3 + F4\t\tZoom-Rotations-Einstellung @cr Pause\t\tAusgabe @cr F5 - F8\t\tDauer einstellen @cr Aktuelle Dauer:\t\t",
                                CinemaText2   = "@color:0,255,0 1\t\tPositionsspeicherung @cr 2\t\tL\195\182schen der letzten Positionsspeicherung @cr 3\t\tAusgabe der letzten Speicherung @cr F12\t\tStarten des Fluges @cr Aktuelle Dauer:\t\t",
                                CurrentCinemaText   = 1,
                                SiteDuration        = 0,
                                FlightSafe      = {},
                                Flying        = false,
                                CurrentFlight      = 0,
                            }
    function GameCallback_Escape()
        CutsceneCreatingTools.EscapeOrig()
        CutsceneCreatingTools:ToggleCinematicMode()
    end
 
    function CutsceneCreatingTools:ToggleCinematicMode()
        if IsBriefingActive() or cutsceneIsActive or self.Flying then
            return
        end
        self.CinematicMode = not self.CinematicMode
 
        local flag = self.CinematicMode and 1 or 0
 
        Logic.SetGlobalInvulnerability(flag)
        Interface_SetCinematicMode(flag)
        XGUIEng.ShowWidget( "Cinematic_Headline", flag )
        XGUIEng.ShowWidget( "Cinematic_Text", flag )
        Display.SetFarClipPlaneMinAndMax(0, flag * 14000)
 
        GUI.SetFeedbackSoundOutputState( flag == 1 and 0 or 1 )
 
        if self.CinematicMode then
            Camera.SetControlMode(0)
            Music.SetVolumeAdjustment( self.Music * 0.5 )
            Sound.PlayFeedbackSound( 0, 0 )
            self.MusicEnd = 0
            LocalMusic_UpdateMusic = function() end
            self.MusicJob = StartSimpleJob( "CutsceneCreatingTools_Update" )
            Music.Stop()
            Counter.SetLimit( "CutsceneCreatingText", 50 )
        else
            Music.SetVolumeAdjustment( self.Music )
            LocalMusic_UpdateMusic = self.MusicUpdateOrig
            EndJob(self.MusicJob)
            LocalMusic.SongLength = Logic.GetTime() + 1
            self.MusicTimes = 5
            Counter.CutsceneCreatingText = nil
            self.FlightSafe = {}
        end
 
        CutsceneCreatingTools:ChangeButtons()
    end
 
    function CutsceneCreatingTools_Update()
        CutsceneCreatingTools:UpdateMusic()
        CutsceneCreatingTools:UpdateText()
    end
 
    function CutsceneCreatingTools:UpdateMusic()
        assert(type(self.MusicSet) == "table")
        if self.MusicEnd > Logic.GetTime() then return end
        LocalMusic.SongLength = Logic.GetTime() + 300
 
        local set = self.MusicSet
        if table.getn(set) == 0 then
            assert(type(set.summer) == "table" and type(set.rain) == "table" and type(set.snow) == "table")
            local weatherState = Logic.GetWeatherState()
            if weatherState == 1 then
                set = set.summer
            elseif weatherState == 2 then
                set = set.rain
            else
                set = set.snow
            end
        end
 
        assert(table.getn(set) > 0)
 
        local random = math.random(table.getn(set))
        local song = set[random]
        if self.MusicTimes == 0 then
            self.MusicEnd = Logic.GetTime() + song[2]
        else
            self.MusicTimes = self.MusicTimes - 1
        end
        Sound.StartMusic( "Music" .. string.char(92) .. song[1], song[2] )
    end
 
    function CutsceneCreatingTools:UpdateText()
        if self.Flying then return end
        if Counter.Tick( "CutsceneCreatingText" ) then
            Counter.SetLimit( "CutsceneCreatingText", 50 )
            self.CurrentCinemaText = self.CurrentCinemaText + 1
            if not self["CinemaText" .. self.CurrentCinemaText] then
                self.CurrentCinemaText = 1
            end
 
            PrintBriefingText( self["CinemaText" .. self.CurrentCinemaText] .. ( table.getn(self.FlightSafe) == 0 and "noch nicht m\195\182glich" or self.SiteDuration ) )
        end
    end
 
    function CutsceneCreatingTools:ChangeButtons()
        --F1 and F2 for zoom, F3 and F4 for rotation, F5 and F6 for angle
        if self.CinematicMode then
            PrintBriefingHeadline( "@color:255,250,200 Steuerung" )
            GUIAction_ToggleMenu = function( _menu, _flag )
                                        if _menu == gvGUI_WidgetID.MainMenuWindow then
                                            CutsceneCreatingTools:MainMenuWindowButton()
                                        elseif _menu == gvGUI_WidgetID.DiplomacyWindow then
                                            CutsceneCreatingTools:DiplomacyWindowButton()
                                        elseif _menu == gvGUI_WidgetID.TradeWindow then
                                            CutsceneCreatingTools:TributeWindowButton()
                                        elseif _menu == gvGUI_WidgetID.QuestWindow then
                                            CutsceneCreatingTools:QuestWindowButton()
                                        elseif _menu == gvGUI_WidgetID.StatisticsWindow then
                                            CutsceneCreatingTools:StatisticsWindowButton()
                                        end
                                    end
            QuickSave = function() CutsceneCreatingTools:QuickSaveButton() end
            KeyBindings_TogglePause = function() CutsceneCreatingTools:PrintCutsceneTable() end
            QuickLoad = function() CutsceneCreatingTools:QuickLoadButton() end
            KeyBindings_ToggleClock = function() CutsceneCreatingTools:ToggleClockButton() end
            KeyBindings_ToggleSound = function() CutsceneCreatingTools:ToggleSoundButton() end
            GroupSelection_SelectTroops = function(_number) CutsceneCreatingTools:TroopSelectionButtons(_number) end
            Camera.StopCameraFlight()
            Camera.ZoomSetDistance( self.ZoomStart )
            Camera.ZoomSetAngle( self.AngleStart )
            Camera.ScrollSetLookAt( Camera.ScrollGetLookAt() )
 
            PrintBriefingText(self.CinemaText1 .. "noch nicht m\195\182glich")
            self.CurrentCinemaText = 1
 
        else
            GUIAction_ToggleMenu = self.ToggleMenu
            QuickSave = self.QuickSave
            QuickLoad = self.QuickLoad
            KeyBindings_ToggleClock = self.ToggleClock
            self.ZoomStart = 4000
            self.AngleStart = 30
            KeyBindings_TogglePause = self.TogglePause
            KeyBindings_ToggleSound = self.ToggleSound
            GroupSelection_SelectTroops = self.SelectTroops
            self.SiteDuration = 0
        end
    end
 
    function CutsceneCreatingTools:MainMenuWindowButton()
        if self.Flying then return end
        self.ZoomStart = self.ZoomStart + 10
        Camera.StopCameraFlight()
        Camera.ZoomSetDistance( self.ZoomStart )
        Camera.ScrollSetLookAt( Camera.ScrollGetLookAt() )
    end
 
    function CutsceneCreatingTools:DiplomacyWindowButton()
        if self.Flying then return end
        self.ZoomStart = self.ZoomStart - 10
        Camera.StopCameraFlight()
        Camera.ZoomSetDistance( self.ZoomStart )
        Camera.ScrollSetLookAt( Camera.ScrollGetLookAt() )
    end
 
    function CutsceneCreatingTools:TributeWindowButton()
        if self.Flying then return end
        self.AngleStart = self.AngleStart + 1
        Camera.StopCameraFlight()
        Camera.ZoomSetAngle( self.AngleStart )
        Camera.ScrollSetLookAt( Camera.ScrollGetLookAt() )
    end
 
    function CutsceneCreatingTools:QuestWindowButton()
        if self.Flying then return end
        self.AngleStart = self.AngleStart - 1
        Camera.StopCameraFlight()
        Camera.ZoomSetAngle( self.AngleStart )
        Camera.ScrollSetLookAt( Camera.ScrollGetLookAt() )  
    end
 
    function CutsceneCreatingTools:StatisticsWindowButton()
        if self.Flying then return end
        if table.getn(self.FlightSafe) == 0 then return end
        self.SiteDuration = self.SiteDuration + 1
        PrintBriefingText(self["CinemaText" .. self.CurrentCinemaText] .. self.SiteDuration)
    end
 
    function CutsceneCreatingTools:QuickSaveButton()
        if self.Flying then return end
        if table.getn(self.FlightSafe) == 0 then return end
        if self.SiteDuration == 0 then return end
        self.SiteDuration = self.SiteDuration - 1
        if self.SiteDuration < 0 then self.SiteDuration = 0 end
        PrintBriefingText(self["CinemaText" .. self.CurrentCinemaText] .. self.SiteDuration)
    end
 
    function CutsceneCreatingTools:QuickLoadButton()
        if self.Flying or table.getn(self.FlightSafe) == 0 then return end
        self.SiteDuration = self.SiteDuration + 0.1
        PrintBriefingText(self["CinemaText" .. self.CurrentCinemaText] .. self.SiteDuration)
    end
 
    function CutsceneCreatingTools:ToggleClockButton()
        if self.Flying or table.getn(self.FlightSafe) == 0 or self.SiteDuration == 0 then return end
        self.SiteDuration = self.SiteDuration - 0.1
        if self.SiteDuration < 0.1 then
            self.SiteDuration = 0
        end
        PrintBriefingText(self["CinemaText" .. self.CurrentCinemaText] .. self.SiteDuration)
    end
 
 
    function CutsceneCreatingTools:PrintCutsceneTable()
        if self.Flying then return end
        local s = "\n{\n\tzoom = " .. self.ZoomStart .. ",\n\trotation = " .. Camera.RotGetAngle() .. ",\n\tangle = " .. self.AngleStart .. ",\n\tposition = { "
        local x,y = Camera.ScrollGetLookAt()
		local z
		do
			local entity = Logic.CreateEntity(Entities.XD_ScriptEntity, x, y, 0, 1)
			local _
			_, _, z = Logic.EntityGetPos(entity)
			Logic.DestroyEntity(entity)
		end
        s = s .. "X = " .. x .. ", Y = " .. y .. ", Z = " .. z .. " },\n\tduration = " .. self.SiteDuration .. ",\n}"
        assert(false, s)
    end
 
    function CutsceneCreatingTools:TroopSelectionButtons(_number)
        if self.Flying then return end
        if _number == 1 then
            self:SavePositionAndDuration()
        elseif _number == 2 then
            self:DeleteLastSafe()
        elseif _number == 3 then
            self:PrintLastSafe()
        end
    end
 
    function CutsceneCreatingTools:SavePositionAndDuration()
        local x, y = Camera.ScrollGetLookAt()
		local z
		do
			local entity = Logic.CreateEntity(Entities.XD_ScriptEntity, x, y, 0, 1)
			local _
			_, _, z = Logic.EntityGetPos(entity)
			Logic.DestroyEntity(entity)
		end
        local entry = {
                          position = { X = x, Y = y, Z = z },
                          duration = self.SiteDuration,
                          zoom = self.ZoomStart,
                          angle = self.AngleStart,
                          rotation = Camera.RotGetAngle(),
                      }
 
        table.insert( self.FlightSafe, entry )
        PrintBriefingText( self["CinemaText" .. self.CurrentCinemaText] .. self.SiteDuration )
    end
 
    function CutsceneCreatingTools:DeleteLastSafe()
        if table.getn( self.FlightSafe ) > 0 then
            table.remove( self.FlightSafe, table.getn(self.FlightSafe) )
            if table.getn( self.FlightSafe ) == 0 then
                PrintBriefingText( self["CinemaText" .. self.CurrentCinemaText] .. "noch nicht m\195\182glich" )
                self.SiteDuration = 0
            end
        end
    end
 
    function CutsceneCreatingTools:PrintLastSafe()
        local safe = self.FlightSafe[ table.getn(self.FlightSafe) ]
        local s = "\n{\n\tzoom = " .. safe.zoom .. ",\n\trotation = " .. safe.rotation .. ",\n\tangle = " .. safe.angle .. ",\n" ..
            "\tposition = { X = " .. safe.position.X .. ", Y = " ..safe.position.Y .. ", Z = " .. safe.position.Z .. " },\n\tduration = " .. safe.duration .. ",\n}"
 
        assert(false, s)
    end
 
 
    function CutsceneCreatingTools:ToggleSoundButton()
        if self.Flying then return end
        if table.getn( self.FlightSafe) > 1 then
            self.Flying = true
            self.CurrentFlight = 2
            Camera.SetControlMode(1)
            Counter.SetLimit( "CutsceneFlightControl", -1 )
            local start = self.FlightSafe[1]
            Camera.StopCameraFlight()
            Camera.ZoomSetDistance( start.zoom )
            Camera.RotSetAngle( start.rotation )
            Camera.ZoomSetAngle( start.angle )
            Camera.ScrollSetLookAt( start.position.X, start.position.Y )
            local job = StartSimpleHiResJob( "CutsceneCreatingTools_ControlFlights" )
            if CutsceneCreatingTools_ControlFlights() then
                EndJob(job)
            end
        end
    end
 
    function CutsceneCreatingTools_ControlFlights()
        return CutsceneCreatingTools:ControlFlights()
    end
 
    function CutsceneCreatingTools:ControlFlights()
        if Counter.Tick( "CutsceneFlightControl" ) then
            PrintBriefingHeadline( "@color:255,250,200 Testflug" )
            PrintBriefingText( "@color:0,255,0 Flug " .. (self.CurrentFlight - 1) .. " von " .. (table.getn(self.FlightSafe) - 1) )
            local currFlight = self.FlightSafe[self.CurrentFlight]
            if not currFlight then
                self:FlightsDone()
                return true
            else
                assert(type(currFlight) == "table")
            end
 
            local duration = currFlight.duration
            if duration > 0 then
                Camera.InitCameraFlight()
                Camera.ZoomSetDistanceFlight( currFlight.zoom, duration )
                Camera.RotFlight( currFlight.rotation, duration )
                Camera.ZoomSetAngleFlight( currFlight.angle, duration )
                Camera.FlyToLookAt( currFlight.position.X, currFlight.position.Y, duration )
 
                Counter.SetLimit( "CutsceneFlightControl", math.floor(duration * 10) )
 
                self.CurrentFlight = self.CurrentFlight + 1
            else
                Camera.StopCameraFlight()
                Camera.ZoomSetDistance( currFlight.zoom )
                Camera.RotSetAngle( currFlight.rotation )
                Camera.ZoomSetAngle( currFlight.angle )
                Camera.ScrollSetLookAt( currFlight.position.X, currFlight.position.Y )
 
                self.CurrentFlight = self.CurrentFlight + 1
 
                Counter.SetLimit( "CutsceneFlightControl", 0 )
 
                return self:ControlFlights()
            end
 
        end
    end
 
    function CutsceneCreatingTools:FlightsDone()
        PrintBriefingHeadline( "@color:255,250,200 Steuerung" )
        PrintBriefingText( "@color:0,255,0 Testfl\195\188ge beendet, gehe zu normalem Cutscene-Erstellungs-Modus" )
        self.Flying = false
        Counter.CutsceneFlightControl = nil
 
        Camera.SetControlMode(0)
    end
 
end
utilscripts/cutscenecreatingtools2.txt · Zuletzt geändert: 2021/09/18 19:15 von 127.0.0.1