All pastes #1522624 Raw Edit

FinalFighter

public lua v1 · immutable
#1522624 ·published 2009-08-09 04:17 UTC
rendered paste body
-- Japanese gui.text Example: gui.text(Japanese)-- ported to Lua by FinalFighter-- 字幕設定ファイルを読み込んでタイムラインに重ねるスクリプト-- jimaku.txtのフォーマットは下記の繰り返し-- 1行目:表示開始フレーム 表示間隔(フレーム) フォントサイズ R G B-- 2行目:表示したいテキスト-- 必須値は以下である-- 表示開始フレーム,表示したいテキストrequire "gd"--全体的に微透過するgui.transparency(1)--str    文字列--font_size フォントの大きさ(プロポーショナルフォント推奨)--color_r   文字色(R)--color_g   文字色(G)--color_b   文字色(B)function gui_text_ja(str,font_size,color_r,color_g,color_b)	--設定する文字	--str	--文字の長さ	strlen = string.len(str)	--フォント名	font_name = "MSPgothic"	--フォントサイズ	if(font_size == nil) then font_size=10 end	--いったん文字書き込んで幅とかを認識する	--im:stringFT(色, "フォント",フォントサイズ,回転角度, X座標, Y座標, "表示文字列",extra)	if(im == nil) then  im = gd.createTrueColor(1, 1) end	llX, llY, lrX, lrY, urX, urY, ulX, ulY = im:stringFTEx(0, font_name, font_size, 0, 0, font_size, str, {} )	--フォントサイズから幅を計算	--フォントサイズ*フォントサイズに合わせた係数*文字の長さ	if(lrX ~= nil and  llX ~= nil  and  llY ~= nil)then		width = lrX - llX		height = llY		--画像作成		im = gd.createTrueColor(width, height)		--文字書き込むX座標を計算		strx = (256 - width)/2		--文字書き込むY座標を計算		stry = 224 - height/2		--文字色の定義		if(color_r == nil) then color_r=255 end		if(color_g == nil) then color_g=0 end		if(color_b == nil) then color_b=0 end		strcolor = im:colorAllocate(color_r, color_g, color_b)		--文字を画像に書き込み		im:stringFTEx(strcolor, font_name, font_size, 0, 0, font_size, str, {} )		--出力		gui.gdoverlay(strx,stry, im:gdStr())	endend--テキストをクリアするfunction gui_text_ja_clear()	gui_text_ja("",0,0,0,0,0)end--メインルーチン--ファイル読み込みfp = io.open("jimaku.txt")--フレームカウント取得framecount = tonumber(movie.framecount())while (true) do	--1行読み込み	line = fp:read("*l")	--データがなかったら抜ける	if(line == nil)then		do break end	end	--lineを分割する	jimaku_table = {}	i=0	for w in string.gmatch(line, "%w+") do		jimaku_table[i] = w		i=i+1	end	--Luaはcontineができないので代わりのフラグ	continue_flag = false	--値設定	--表示開始フレーム(必須)	if(jimaku_table[0] ~= nil)then		display_frame = tonumber(jimaku_table[0])	else		continue_flag = true	end	--表示終了フレーム	if(jimaku_table[0] ~= nil and jimaku_table[1] ~= nil)then		display_end_frame = tonumber(jimaku_table[0]) + tonumber(jimaku_table[1])	else		display_end_frame = tonumber(jimaku_table[0]) + 300	end	--フォントサイズ	if(jimaku_table[2] ~= nil)then		font_size = tonumber(jimaku_table[2])	else		font_size = 10	end	--R(赤)	if(jimaku_table[3] ~= nil)then		R = tonumber(jimaku_table[3])	else		R = 255	end	--G(緑)	if(jimaku_table[4] ~= nil)then		G = tonumber(jimaku_table[4])	else		G = 0	end	--B(緑)	if(jimaku_table[5] ~= nil)then		B = tonumber(jimaku_table[5])	else		B = 0	end	--テキスト読み込み	line = fp:read("*l")		--データがなかったら抜ける	if(line == nil)then		do break end	end	--表示テキスト	text = line	--表示開始	if(continue_flag == false)then		--表示開始フレームまで飛ばす		while(framecount < display_frame) do			framecount = tonumber(movie.framecount())			FCEU.frameadvance()		end		--表示フレームと一致した場合はテキストを表示		if(framecount == display_frame)then			gui_text_ja(text,font_size,R,G,B)						--表示終了フレームまで飛ばす			while(framecount < display_end_frame)do				framecount = tonumber(movie.framecount())				FCEU.frameadvance()			end		end		--テキストクリア		gui_text_ja_clear()	end		--次の字幕へendwhile (true) do	FCEU.frameadvance()end