File size: 4,000 Bytes
b6a38d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
-- Movie-playing dialog
--
-- To use: OpenSubtitledMovieDlg( { filename = "movie", fade_in = 1000, subtitles = subs_table, ... })
--
-- Optional in the place on the ellipsis:
--   text_style = [string], default is UISubtitles
--
-- Subtitle format:
--   subs_table = {
--	    { start_time =  4000, duration = 11000, text = T{"Almighty-sounding text number one"} },
--	    { start_time = 16000, duration = 5000 , text = T{"Even more inspiring text number two"} },
--     ...
--   }
--
-- Default movie subtitles in MovieSubtitles[language][movie] or MovieSubtitles.English[movie]

if FirstLoad then
	MovieSubtitles = { English = {} }
end

function GetMovieSubtitles(movie)
	local  lang1 = MovieSubtitles[GetVoiceLanguage() or ""]
	local  lang2 = MovieSubtitles.English
	return lang1 and lang1[movie] or lang2 and lang2[movie]
end

DefineClass.XFullscreenMovieDlg = {
	__parents = { "XDialog" }, 
	
	skippable = true,
	sound_type = "Voiceover",
	fade_in = false,
	fadeout_music = false,
	
	open_time = false,
	movie_path = false, 
	subtitles = false, 
	text_style = false,
}

function XFullscreenMovieDlg:Init(parent, context)
	--assert(type(context) == "table")
	self.skippable = context.skippable or true
	self.sound_type = context.sound_type or "Voiceover"
	self.fade_in = context.fade_in
	
	self.movie_path = context.movie_path
	self.subtitles = context.subtitles
	self.fadeout_music = context.fadeout_music
	self.text_style = context.text_style
end

function XFullscreenMovieDlg:Open(...)
	XDialog.Open(self, ...)
	
	self.open_time = RealTime()
	if self.text_style then 
		self.idSubtitles:SetTextStyle(self.text_style)
	end

	if GetUIStyleGamepad(nil, self) then
		self.idSkipHint:SetText(T(576896503712, "<ButtonB> Skip"))
	else
		self.idSkipHint:SetText(T(696052205292, "<style SkipHint>Escape: Skip</style>")) -- no icon for Esc button
	end
	
	assert(self.movie_path)
	local sound_type = self.sound_type
	self.idVideoPlayer.FileName = self.movie_path
	self.idVideoPlayer.Sound = self.movie_path
	self.idVideoPlayer.SoundType = sound_type
	self.idVideoPlayer.Desaturate = const.MovieCorrectionDesaturation
	self.idVideoPlayer.Gamma = const.MovieCorrectionGamma
	self.idVideoPlayer.OnEnd = function()
		self:Close()
	end
	self:PlayMovie()
end

function XFullscreenMovieDlg:StopMovie()
	DeleteThread("FadePlayback")
	self.idSubtitles:SetText("")
	self.idVideoPlayer:Stop()
	if Music and self.fadeout_music then
		Music:SetVolume(1000, 300)
	end
end

function XFullscreenMovieDlg:PlayMovie()
	if self.fadeout_music and Music then
		Music:SetVolume(0, 300)
	end
	self:CreateThread("FadePlayback", function()
		if self.fade_in then
			Sleep(self.fade_in)
		end

		self.idVideoPlayer:Play();
		if self.subtitles then --and GetAccountStorageOptionValue("Subtitles") then
			local time_start = now() 
			for i = 1,#self.subtitles do
				local sub  = self.subtitles[i]
				local wait = time_start + sub.start_time - now()
				Sleep(wait)
				self.idSubtitles:SetText(sub.text)
				Sleep(sub.duration)
				self.idSubtitles:SetText("")
			end
		end
	end)
end

function XFullscreenMovieDlg:OnShortcut(shortcut, source, ...)
	if RealTime() - self.open_time < 250 then return "break" end
	if RealTime() - terminal.activate_time < 250 then return "break" end
	
	if self.skippable then
		if not self.idSkipHint:GetVisible() then
			self.idSkipHint:SetVisible(true)
		elseif shortcut == "Escape" or shortcut == "ButtonB" then
			self:Close()
		end
		return "break"
	end
end

function XFullscreenMovieDlg:Close()
	self:StopMovie()
	g_FullscreenMovieDlg = false
	
	XDialog.Close(self)
end

MapVar("g_FullscreenMovieDlg", false)
function OpenSubtitledMovieDlg(content)
	if not content then 
		content = {
			movie_path = "Movies/Haemimont", 
			skippable = true,
			fade_in = 250,
			subtitles = MovieSubtitles.English,
			fadeout_music = false,
	} end
	
	if not g_FullscreenMovieDlg then 
		g_FullscreenMovieDlg = OpenDialog("XFullscreenMovieDlg", terminal.desktop, content);
	end
	return g_FullscreenMovieDlg
end