----------------------------------------
-- 拡張管理
----------------------------------------
usr = {}
----------------------------------------
	e:include('system/extend/user/map.lua')			-- map
	e:include('system/extend/user/grph.lua')		-- アマカノグラフ
--	e:include('system/extend/user/tips.lua')		-- tips
--	e:include('system/extend/user/mw_save.lua')		-- mwsave
--	e:include('system/extend/user/langselect.lua')	-- 多言語設定
--	e:include('system/extend/user/sm.lua')			-- sm / float
--	e:include('system/extend/user/titlechar.lua')	-- キャラ選択
--	e:include('system/extend/user/sysvo.lua')		-- sysvo
	e:include('system/extend/staff/staff.lua')		-- staffroll
	e:include('system/langselect.lua')
----------------------------------------
local namesize = 10		-- 名前入力できる文字数
----------------------------------------
-- UIアニメーション
----------------------------------------
function uiopenanime(name)
	local tm = init.ui_fade
	local dialog = function(id)
		local tm = yesno_fadetime()
		local y  = mulpos(-50)
		systween2{ id=(id..".dl"), y=(y..",0"), time=(tm)}
		systween2{ id=(id),      alpha="0,255", time=(tm)}
		flip()
	end
	local sw = {

	----------------------------------------
	-- dialog
	dialog  = function() dialog(init.dlgbaseid) end,
	gameend = function() dialog(init.dlgwin_id) end,

	----------------------------------------
	-- pico設定
	mwconf = function()
		local v  = getBtnInfo("bg")
		local x  = -v.w
		systween2{ id="500.mn", x=(x..",0"), time=(tm)}
		estag("init")
		estag{"uitrans", tm}
		estag()
	end,
--[[
	----------------------------------------
	-- backlog
	blog = function()
		tag{"lyprop", id="500.z", visible="0"}
		estag("init")
		estag{"uitrans", { rule="rule_backlogon", fade="250" } }
		estag{"lyprop", id="500.z", visible="1"}
		estag{"uitrans"}
		estag()
	end,

	----------------------------------------
	-- save / load
	save = function()
		local s = flg.saveanime
		if not s then
			flg.saveanime = true
			local t1 = 150
			local t2 = 150
			local v  = getBtnInfo('logo')
			local y  = (-v.h)..","..(v.y)
			e:tag{"lyprop", id=(v.idx), visible="0"}
			e:tag{"lyprop", id="500.z", visible="0"}
			estag("init")
			estag{"systween", { id="500.2", time=(t2 + tm), delay=(t1), alpha="0,255"}}
			estag{"uitrans", { rule="rule_saveon", fade=(t1 + t2) }}
			estag{"systween", { id=(v.idx), y=(y), time=(tm)}}
			estag{"lyprop", id="500.z", visible="1"}
			estag{"lyprop", id=(v.idx), visible="1"}
			estag{"uitrans", tm}
			estag()
		else
			uitrans()
		end
	end,

	----------------------------------------
	-- favo
	favo = function()
		local t1 = 150
		local t2 = 150
		local v  = getBtnInfo('logo')
		local y  = (-v.h)..","..(v.y)
		e:tag{"lyprop", id=(v.idx), visible="0"}
		e:tag{"lyprop", id="500.z", visible="0"}
		estag("init")
		estag{"systween", { id="500.2", time=(t2 + tm), delay=(t1), alpha="0,255"}}
		estag{"uitrans", { rule="rule_favoon", fade=(t1 + t2) }}
		estag{"systween", { id=(v.idx), y=(y), time=(tm)}}
		estag{"lyprop", id="500.z", visible="1"}
		estag{"lyprop", id=(v.idx), visible="1"}
		estag{"uitrans", tm}
		estag()
	end,

	----------------------------------------
	-- config
	conf = function()
		e:tag{"lyprop", id="500.z", visible="0"}
		estag("init")
		estag{"uitrans", { rule="rule_confon", fade=(tm) }}
		estag{"lyprop", id="500.z", visible="1"}
		estag{"uitrans", tm}
		estag()
	end,

	----------------------------------------
	-- extra
	extra = function()
		local t2 = tm * 2
		local i1 = "500.z"				-- body
		local i2 = getBtnID("bg02")		-- black
		local i3 = "500.sy.1"			-- up
		local i4 = "500.sy.2"			-- dw
		local v1 = getBtnInfo("bg03")	-- up info
		local v2 = getBtnInfo("bg04")	-- dw info
		e:tag{"lyprop", id=(i1), visible="0"}
		e:tag{"lyprop", id=(i2), visible="0"}
		e:tag{"lyprop", id=(i3), top=(-v1.h)}
		e:tag{"lyprop", id=(i4), top=( v2.h)}
		estag("init")
		estag{"uitrans", { rule="rule_extraon", fade=(t2) }}
		estag{"lyprop", id=(i2), visible="1"}
		estag{"systween", { id=(i3), y=(-v1.h..",0"), time=(t2)}}
		estag{"systween", { id=(i4), y=( v1.h..",0"), time=(t2)}}
		estag{"uitrans", t2}
		estag{"lyprop", id=(i1), visible="1"}
		estag{"uitrans", tm}
		estag()
	end,
]]
	}
	if sw[name] then sw[name]()
	else uitrans() end
end
----------------------------------------
function uicloseanime(name)
	local tm = init.ui_fade
	local dialog = function(id, nm)
		local tm = yesno_fadetime()
		local y  = mulpos(50)
		systween2{ id=(id..".dl"), y=("0,"..y), time=(tm)}
		e:tag{"lyprop", id=(id), visible="0"}
		estag("init")
		estag{"uitrans", tm}
		estag{ nm }
		estag()
	end
	local sw = {

	----------------------------------------
	-- dialog
	dialog  = function() dialog(init.dlgbaseid, "dialog_return") end,
	gameend = function() dialog(init.dlgwin_id, "yesno_exclickexit") end,

	----------------------------------------
	-- backlog
	blog = function()
		estag("init")
		estag{"blog_reset"}
		estag{"uitrans"}
		estag()
	end,

	----------------------------------------
	-- save / load
	save = function()
		estag("init")
		estag{"save_reset"}
		if not getTitle() then estag{"uitrans"} end
		estag()
	end,

	----------------------------------------
	-- config
	conf = function()
		estag("init")
		estag{"conf_savecheck"}		-- セーブ確認
		estag{"conf_reset"}			-- 消去
		if not getTitle() then estag{"uitrans"} end
		estag()
	end,

	----------------------------------------
	-- pico設定
	mwconf = function()
		local v  = getBtnInfo("bg")
		local x  = -v.w
		e:tag{"lyprop", id="500", visible="0"}
		systween2{ id="500.mn", x=("0,"..x), time=(tm)}
		uitrans(tm)
	end,
	}
	if sw[name] then sw[name]()
	else uitrans() end
end
----------------------------------------
-- 時限選択肢拡張
----------------------------------------
--[[
function user_selecttimed_open(time, wait)
	local id = select_timed_getid()
	local a  = scr.select.anime
	local y  = a.y or 0
	systween{ id=(id), alpha="0,255", time=(time), ease="none"}
	systween{ id=(id), y=((y-80)..","..y), time=(time)}
end
----------------------------------------
function user_selecttimed_close(time, wait)
	local id = select_timed_getid()
	local a  = scr.select.anime
	local y  = a.y or 0
	systween{ id=(id), alpha="255,0", time=(time), ease="none"}
	systween{ id=(id), y=(y..","..(y+80)), time=(time)}
end
]]
----------------------------------------
--
----------------------------------------
-- 作品別初期化ルーチン / 起動時及びconfig reset時に呼ばれる
function user_conf()

--	conf.patch = 0		-- 裸パッチ初期値
	conf.imo = 0		-- imo初期値
	conf.heye = 0		-- 
	conf.hjump = 0		-- 
	conf.hcount = 0		-- 

end
----------------------------------------
--[[
-- 裸パッチ確認
function user_hadaka()
	exhadaka = true
	if isFile("patch.ini") then
		exhadaka = nil
	end
end
----------------------------------------
user_hadaka()
]]
----------------------------------------
--
----------------------------------------
--[[
-- extra cg / 強制開放
function extra_cgopen()
	local set_table = {
		ev_gue_01 = true,
	}
	local ev_table = {
		ev_gue_01a = true,
	}

	-- set登録
	for set, v in pairs(set_table) do
		if not gscr.evset[set] then
			gscr.evset[set] = true
		end
	end

	-- ev登録
	for k, v in pairs(ev_table) do
		if not gscr.ev[k] then
			gscr.ev[k] = true
		end
	end
end
]]
----------------------------------------
-- user tag
----------------------------------------
tags.user = function(e, p)
	local md = p.mode
	local sw = {
		-- start時のmanual
		start = function()
		 	user_gamestart()
		end,

		--exskip強制停止
		exskipstop = function()
			if flg.exskip then
				flg.exskipstop = true
				exskip_stop()
			end
		end,

		-- tips
		tips = function()
			if tips then tips.settips(p) end
		end,

		-- 拡張処理
		map  = function() user_mapinit(p) end,			-- map.lua
		grph = function() user_grphinit(p) end,			-- grph.lua
--		shop = function() netshop_check(p) end,			-- shop.lua / 課金画面呼び出し
		heroname = function() user_heroname(p) end,		-- 名前入力
		namecheck = function() user_namecheck(p) end,	-- 名前確認
		hcount=function() user_hcount(p) end,			-- 射精カウントダウン
	}
	if sw[md] then sw[md]() end
	return 1
end
----------------------------------------
function user_gamestart()
	flg.ui = {}
	csvbtn3("user", "500", lang.ui_start)
	estag("init")
	estag{"uitrans", 1000}
	estag{"eqwait"}
	estag("stop")
end
----------------------------------------
function user_gameclick()
	ResetStack()
	se_ok()
	delbtn("user")		-- 削除
	uitrans(1000)
	flg.ui = nil
	init_adv_btn()		-- adv btn
	autoskip_init()		-- autoskip
end
----------------------------------------
--
----------------------------------------
tags["demo"] = function(e, p)
	local cf = p.auto or 1
	conf.mspeed = p.mspeed or conf.mspeed
	conf.aspeed = p.aspeed or conf.aspeed
	conf.auto   = p.auto or 1
	conf.tabletui = p.tablet or 0
	conf.mw_aread = p.aread  or 0
	adv_auto()
	return 1
end
----------------------------------------
-- 名前入力
----------------------------------------
function user_heroname(p)
	local tb = { ln="name_last", fn="name_first" }
	local md = p.name
	local v  = getLangHelp("dlgmes")
	local tx = v[tb[md]]
	local nm = getHeroName(md, true)

	tag_dialog({ title=(tx), message=(nm), textfield="t.tx", textfieldsize=(namesize) }, "user_heroname_save", md)
end
----------------------------------------
function user_heroname_save(md)
	local nm = e:var("t.tx")
	if nm == "" then nm = getHeroName(md, true) end

	setHeroName(md, nm)
end
----------------------------------------
-- 名前確認
function user_namecheck(p)
	local tx = p.text
	local df = getHeroName(tx, true)
	local nm = getHeroName(tx)
	local r  = df == nm and 1 or 0
	message("通知", "初期名：", df, "設定名：", nm)
	set_eval("f.s="..r)
end
----------------------------------------
-- config voice
----------------------------------------
function user_confvoice(e, p)
	if p.p ~= p.old then
		local v  = getBtnInfo(p.name)
		local ch = v.def
		sesys_vochar(ch, "sysvo")
	elseif not p.p then
		local v  = getBtnInfo(p.name)
		local ch = v.def:gsub("svo_", "")
		sesys_vochar(ch, "sysvo")
	end
end
----------------------------------------
