--[[#tag push NAME]]

if not luad then
	local luad = dofile "patcher/skin/luad.lua"
	luad.setRootPath "patcher/skin"
end

local unused = "unused\024\0\0\0\0\0"
local luad = assert(luad)
local malut = luad.require( "malut", "malut.lua" )

local UI = luad.require( "UI", "ui.lua" )
local malut = luad.require( "malut", "malut.lua" )
local config = luad.require( "config", "config.lua" )

local print = print
local io = io

local Figure = UI.Figure
local Button = UI.Button
local HProgressBar = UI.HProgressBar
local VProgressBar = UI.VProgressBar
local HRoundProgressBar = UI.HRoundProgressBar
local Text = UI.Text
local TextButton = UI.TextButton
local CheckBox = UI.CheckBox
local Slider = UI.Slider
local ComboBox = UI.ComboBox
local InputBox = UI.InputBox
local SpinBox = UI.SpinBox
local Browser = UI.Browser
local Window = UI.Window

local AnimationButton = UI.AnimationButton
local function TEXT(...) return ... end
local function FILEPATH (path)
	return LuaSkin.makeFullPath(path)
end
local defaultFont = config.defaultFont or "宋体"

--
-- load position data
--

local positionData = UI.convertPosition(luad "image/position.txt", "patcher/skin/image/")

--
-- main window
--

local mainWindow = Window
{
	name = "main",
	title = TEXT"蜀山缥缈录",
	width = positionData["main"].width,
	height = positionData["main"].height,
}

function mainWindow:onInit ()
	Window.onInit(self)

	local serverlist = LuaSkin.loadOption(FILEPATH"patcher/config/serverlist.cfg")
	if serverlist and serverlist.webUrl then
		self:findItemByName("browser"):setUrl(serverlist.webUrl)
	end
end

function mainWindow:onClose ()
	LuaSkin.closeAllWindow()
end

do
	local item = Text (mainWindow)
	{
		name = "serverversion",
		font = defaultFont,
		size = 13,
		color = 0xff0f0e0c,
		align = "left",
		valign = "center",
		bMultiLine = false,
		text = "",
	} :addToGroup(nil)
end

do
	local item = Text (mainWindow)
	{
		name = "localversion",
		font = defaultFont, size = 13, color = 0xff0f0e0c, align="left",
	} :addToGroup(nil)
end

do
	local item = Text (mainWindow)
	{
		name = "status",
		font = defaultFont, size = 13, color = 0xff0f0e0c, align="left",
	} :addToGroup(nil)
end

do
	local item = Button (mainWindow) { name = "minimum", } :addToGroup(nil)

	function item:onClick ()
		self.m_window.m_cwindow:minimize()
	end
end

do
	local item = Button (mainWindow) { name = "close", } :addToGroup(nil)

	function item:onClick ()
		LuaSkin.closeAllWindow()
	end
end

do
	local item = Button (mainWindow) { name = "updatelocal", } :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/button.wav")
		LuaSkin.confirmStopUpdateForFullCheckOrLocalUpdate(function ()
			LuaSkin.asyncLocalUpdate(function () end)
		end)
	end
end

do
	local item = Button (mainWindow) { name = "fullcheck", } :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/button.wav")
		LuaSkin.confirmStopUpdateForFullCheckOrLocalUpdate(function ()
			LuaSkin.asyncFullCheck(function () end)
		end)
	end
end

do
	local item = Button (mainWindow) { name = "register", } :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/button.wav")
		LuaSkinApi.openWebUrl("http://passport.wanmei.com/register/phone.jsp")
	end
end

do
	local item = Button (mainWindow) { name = "updatesetting", } :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/button.wav")
		LuaSkin.showWindow("updatesetting", true)
	end
end

do
	local item = Button (mainWindow) { name = "videosetting", } :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/button.wav")
		LuaSkin.showWindow("videosetting", true)
	end
end

do
	local item = AnimationButton (mainWindow) { name = "homepage", } :addToGroup(nil)

	function item:onHover ()
	end
	function item:onPress ()
	end
	function item:onClick ()
		self.m_window:showAnimation("Patcher/skin/image/animation_once.png", 0, 0)
		LuaSkinApi.playSound("patcher/skin/sounds/button.wav")
		LuaSkinApi.openWebUrl("http://shushan.wanmei.com/")
	end
	function item:onDisHover ()
	end
end

do
	local item = HRoundProgressBar (mainWindow) { name = "totalprogress", } :addToGroup(nil)
end

do
	local item = HRoundProgressBar (mainWindow) { name = "fileprogress", } :addToGroup(nil)
end

do
	local item = Button (mainWindow) { name = "play", } :addToGroup(nil)

	function item:onClick ()
		LuaSkin.hideAllWindow()

		self:setAction("startClient", function (dtime)
			LuaSkinApi.playSound("patcher/skin/sounds/button.wav", true)	--太长了点
			LuaSkin.startClient()
			return "end"
		end)
	end

	function item:onHitTest (x, y)
		local w, h = self.m_curWidth, self.m_curHeight
		local cenX = self.m_curX + w/2
		local cenY = self.m_curY + h/2
		local rx = (x-cenX)/w
		local ry = (y-cenY)/h
		return rx*rx + ry*ry < 1
	end

	while false do
		local gfx = Figure (mainWindow)
		{
			bAnimation = true,
			imageFile = "Patcher/skin/image/main_play_gfx.png",
			x = 0, y = 0,
		} :addToGroup(item)

		function gfx:onInit ()
			Figure.onInit(self)
			self:moveTo(item.m_x - 25, item.m_y - 25)
			self:show(false)
		end

		function item:onHover ()
	--~ 		self:transformTo(0, 0, 1.2, 1.2, 0.3)
			if gfx.m_curImage == unused then return end

			gfx:show(true)
			self:setAction(gfx, function (dtime)
				local bMore, bNewFrame = gfx.m_curImage.pic:increaseTime(dtime)
				if bNewFrame then
					self.m_window:setDirty()
				end
			end)
		end
		function item:onDisHover ()
	--~ 		self:transformTo(0, 0, 1, 1, 0.3)
			if gfx.m_curImage == unused then return end

			self:setAction(gfx, function (dtime)
				local bMore, bNewFrame = gfx.m_curImage.pic:decreaseTime(dtime)
				if bNewFrame then
					self.m_window:setDirty()
				end
				if not bMore then
					self:setAction(gfx, nil)
					gfx:show(false)
				end
			end)
		end

	end
end

do
	local item = Browser (mainWindow) {name = "browser"} :addToGroup(nil)

	function item:onInit ()
		Browser.onInit(self)
		-- set default url
		--self:setUrl "http://10.68.52.10/swordsman/update/info"
	end
end

local updatesettingWindow = Window
{
	name = "updatesetting",
	title = TEXT"更新设置",
	width = positionData["updatesetting"].width,
	height = positionData["updatesetting"].height,
}

updatesettingWindow.m_serverList = unused

function updatesettingWindow:onInit ()
	Window.onInit(self)
end

function updatesettingWindow:onShowWindow (flag)
	Window.onShowWindow(self, flag)

	if flag ~= 1 then
		return
	end

	if self.m_serverList == unused then		-- first pop
		local serverList = LuaSkin.loadOption(FILEPATH"patcher/config/serverlist.cfg") or {}
		local serverListObj = self:findItemByName "serverlist"
		for i=1, #serverList do
			serverListObj:addLine(serverList[i].name)
		end
		self.m_serverList = serverList
	end

	self:loadOption()
end

function updatesettingWindow:loadOption ()
	local serverList = self.m_serverList

	local option = LuaSkin.loadOption(FILEPATH"patcher/config/update.cfg")
	if option then
		-- server
		local serverid = option.serverid
		local server = LuaSkin.getServerById(serverid)
		if server then
			local serverName = server.name
			local serverListObj = self:findItemByName "serverlist"
			serverListObj:setSelectedLine(serverName)
		end

		-- auto select last server
		self:findItemByName("autoselectserver"):check(option.bAutoSelectServer)
		-- use p2sp
		self:findItemByName("usep2sp"):check(option.bUseP2sp ~= false)
		-- max thread
		self:findItemByName("maxthreadinput"):setValue(option.maxThread or 5)
		-- max speed
		self:findItemByName("hasmaxspeed"):check(option.hasMaxSpeed)
		self:findItemByName("maxspeedinput"):setValue(option.maxSpeed or 200)
	else		-- default value
		-- auto select last server
		self:findItemByName("autoselectserver"):check(true)
		self:findItemByName("usep2sp"):check(true)
		-- max thread
		self:findItemByName("maxthreadinput"):setValue(5)
		-- max speed
		self:findItemByName("hasmaxspeed"):check(false)
		self:findItemByName("maxspeedinput"):setValue(200)
	end

	self:findItemByName("maxspeedinput"):enable(self:findItemByName("hasmaxspeed"):isChecked())
end

function updatesettingWindow:saveOption ()
	local option = {}

	-- server
	local server
	local serverList = self.m_serverList

	local serverListObj = self:findItemByName "serverlist"
	local index, serverName = serverListObj:getSelectedLine()
	if index then
		server = self.m_serverList[index]
		if server then
			option.serverid = server.id
		end
	end

	if not server then
		return
	end

	-- auto select last server
	option.bAutoSelectServer = self:findItemByName("autoselectserver"):isChecked()
	-- use p2sp
	option.bUseP2sp = self:findItemByName("usep2sp"):isChecked()
	-- max thread
	option.maxThread = self:findItemByName("maxthreadinput"):getValue()
	-- max speed
	option.hasMaxSpeed = self:findItemByName("hasmaxspeed"):isChecked()
	option.maxSpeed = self:findItemByName("maxspeedinput"):getValue()

	-- save
	LuaSkin.saveOption(option, FILEPATH"patcher/config/update.cfg")

	LuaSkin.checkUpdateConfig()
end

function updatesettingWindow:onOK ()
	LuaSkinApi.playSound("patcher/skin/sounds/confirm.wav")
	self:saveOption()
	LuaSkinApi.updateFunc("MessageBoxOK", "")
	self.m_cwindow:show(false)
end

function updatesettingWindow:onCancel ()
	LuaSkinApi.playSound("patcher/skin/sounds/cancel.wav")
	LuaSkinApi.updateFunc("MessageBoxCancel", "")
	self.m_cwindow:show(false)
end

do
	local item = Text (updatesettingWindow)
	{
		name = "title",
		font = defaultFont, size = 15, color = 0xff010101,
		text = TEXT"更新设置",
	} :addToGroup(nil)
end

do
	local item = Text (updatesettingWindow)
	{
		name = "servertext",
		font = defaultFont, size = 13, color = 0xff010101,
		text = TEXT"请选择更新服务器", align = "left",
	} :addToGroup(nil)
end

do
	local item = CheckBox (updatesettingWindow)
	{
		name = "autoselectserver",
		textStyle = { text = TEXT"自动选择最近登陆的服务器", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/check.wav")
	end

	item:show(false)	--强制为true
end

do
	local item = CheckBox (updatesettingWindow)
	{
		name = "usep2sp",
		textStyle = { text = TEXT"使用P2SP", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/check.wav")
	end

	item:show(false)	--服务器这边无人维护 所以把p2sp隐藏掉
end

do
	local item = Text (updatesettingWindow)
	{
		name = "maxthreadtext",
		font = defaultFont, size = 13, color = 0xff010101, align="left",
		text = TEXT"最大下载线程数",
	} :addToGroup(nil)
end

do
	local item = SpinBox (updatesettingWindow)
	{
		name = "maxthreadinput",
		textStyle = { text = "1", font = defaultFont, size = 13},
		maxLength = 2,
		min = 1, max = 10,
	} :addToGroup(nil)
end

do
	local item = Text (updatesettingWindow)
	{
		name = "maxthreadremark",
		font = defaultFont, size = 13, color = 0xff010101, align="left",
		text = TEXT"(1～10)",
	} :addToGroup(nil)
end

do
	local item = CheckBox (updatesettingWindow)
	{
		name = "hasmaxspeed",
		textStyle = { text = TEXT"最大下载速度", font = defaultFont, size = 13},
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onInit ()
		CheckBox.onInit(self)
	end

	function item:onClick ()
		updatesettingWindow:findItemByName("maxspeedinput"):enable(self:isChecked())
		LuaSkinApi.playSound("patcher/skin/sounds/check.wav")
	end
end

do
	local item = SpinBox (updatesettingWindow)
	{
		name = "maxspeedinput",
		textStyle = { text = "1", font = defaultFont, size = 13},
		maxLength = 6,
		min = 10, step = 10,
	} :addToGroup(nil)
end

do
	local item = Text (updatesettingWindow)
	{
		name = "maxspeedremark",
		font = defaultFont, size = 13, color = 0xff010101, align="left",
		text = TEXT"kB/s",
	} :addToGroup(nil)
end

do
	local item = TextButton (updatesettingWindow)
	{
		name = "ok",
		textStyle = { text = TEXT"确定", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		updatesettingWindow:onOK()
	end
end

do
	local item = TextButton (updatesettingWindow)
	{
		name = "cancel",
		textStyle = { text = TEXT"取消", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		updatesettingWindow:onCancel()
	end
end

do
	local item = ComboBox (updatesettingWindow)
	{
		name = "serverlist",
		textStyle = { text = TEXT"选择服务器", font = defaultFont, size = 13, },
		colors = {default=0xfffefefe, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
		listStyle =
		{
			textStyle = { font = defaultFont, size = 13 },
			lineHeight = 20,
			colors = { default=0xfffefefe, hover=0xff000000, select=0xfffefefe, hoverBg=0xcc8888ff, selectBg=0xccff8888 },
		},
	} :addToGroup(nil)

	function item:onExpand ()
		LuaSkinApi.playSound("patcher/skin/sounds/selectserver.wav")
	end
end


--
-- videosetting window
--

local videosettingWindow = Window
{
	name = "videosetting",
	title = TEXT"系统设置",
	width = positionData["videosetting"].width,
	height = positionData["videosetting"].height,
}

function videosettingWindow:onInit ()
	Window.onInit(self)

	LuaSkinApi.updateFunc("CalcDisplayMode", "")
	local resolutionList = LuaSkin.loadOption(FILEPATH"patcher/config/resolution.cfg")
	if not resolutionList then
		self.m_resolutionList = {}
	else
		self.m_resolutionList = resolutionList
	end
	local resolutionListObj = self:findItemByName "resolutionlist"
	for i=1, #resolutionList do
		resolutionListObj:addLine(resolutionList[i])
	end
	local renderlevelListObj = self:findItemByName("renderlevellist")
	do
		renderlevelListObj:addLine(TEXT"不改变")
		renderlevelListObj:addLine(TEXT"低画质")
		renderlevelListObj:addLine(TEXT"中画质")
		renderlevelListObj:addLine(TEXT"高画质")
	end

	self:findItemByName("systeminfo"):setText(LuaSkinApi.getSystemInfo())
	self.m_bHasShader = LuaSkinApi.isShaderAvailable()
end

function videosettingWindow:onShowWindow (flag)
	Window.onShowWindow(self, flag)

	if flag == 1 then
		LuaSkinApi.updateFunc("LoadVideoSetting", "")
		self:loadOption()
	end
end

function videosettingWindow:loadOption ()
	local resolutionList = self.m_resolutionList

	local option = LuaSkin.loadOption(FILEPATH"patcher/config/video.cfg")
	if option then
		local bShader = not option.bNoShader

		-- resolution
		local w, h = option.RenderWid, option.RenderHei
		if w and h then
			self:findItemByName("resolutionlist"):setSelectedLine(("%dx%d"):format(w, h))
		end

		-- other setting
		self:findItemByName("windowmode"):check(not option.FullScreen)

		-- other setting
		self:findItemByName("compatiblemode"):check(not not option.CompatibleMode)

		-- other setting
		self:findItemByName("minimalmode"):check(not not option.MinimalMode)
	end

	-- renderlevel
	self:findItemByName("renderlevellist"):setSelectedLine(1)
end

function videosettingWindow:saveOption ()
	local option = {}
	-- resolution
	local resolutionListObj = self:findItemByName "resolutionlist"
	local _, resolution = resolutionListObj:getSelectedLine()
	if resolution then
		local resolutionList = self.m_resolutionList
		for i=1, #resolutionList do
			if resolutionList[i] == resolution then
				local w, h = resolution:match "(%d+)x(%d+)"
				if w and h then
					option.RenderWid = w
					option.RenderHei = h
				end
			end
		end
	end

	-- renderlevel
	local iRenderconfigPlus, _ = self:findItemByName("renderlevellist"):getSelectedLine()
	if iRenderconfigPlus and iRenderconfigPlus > 1 then
		option.ChangeRenderLevel = iRenderconfigPlus - 1
	end	--否则不改变

	-- other setting
	option.FullScreen = not self:findItemByName("windowmode"):isChecked()
	option.CompatibleMode = self:findItemByName("compatiblemode"):isChecked()
	option.MinimalMode = self:findItemByName("minimalmode"):isChecked()

	-- save
	LuaSkin.saveOption(option, FILEPATH"patcher/config/video.cfg")
	LuaSkinApi.updateFunc("SaveVideoSetting", "")
end

function videosettingWindow:onOK ()
	LuaSkinApi.playSound("patcher/skin/sounds/confirm.wav")
	self.m_cwindow:show(false)
	self:saveOption()
end

function videosettingWindow:onCancel ()
	LuaSkinApi.playSound("patcher/skin/sounds/cancel.wav")
	self.m_cwindow:show(false)
end


do
	local item = ComboBox (videosettingWindow)
	{
		name = "resolutionlist",
		textStyle = { text = TEXT"自定义尺寸", font = defaultFont, size = 13, },
		colors = {default=0xfffefefe, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
		listStyle =
		{
			textStyle = { font = defaultFont, size = 13 },
			lineHeight = 20,
			colors = { default=0xfffefefe, hover=0xff000000, select=0xff000000, hoverBg=0xcc8888ff, selectBg=0xccff8888 },
		},
	} :addToGroup(nil)

	function item:onExpand (flag)
		LuaSkinApi.playSound("patcher/skin/sounds/selectresolution.wav")
	end
end

do
	local item = Text (videosettingWindow)
	{
		name = "title", text = TEXT"系统设置",
		font = defaultFont, size = 15, color = 0xff010101,
	} :addToGroup(nil)
end

do
	local item = Text (videosettingWindow)
	{
		name = "systeminfo", text = "sys\ntem\ninfo",
		font = defaultFont, size = 13, color = 0xff010101,
		bMultiLine = true, align = "left",
	} :addToGroup(nil)
end

do
	local item = TextButton (videosettingWindow)
	{
		name = "ok",
		textStyle = { text = TEXT"确定", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		self.m_window:onOK()
	end
end

do
	local item = TextButton (videosettingWindow)
	{
		name = "cancel",
		textStyle = { text = TEXT"取消", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		self.m_window:onCancel()
	end
end

do
	local item = CheckBox (videosettingWindow)
	{
		name = "windowmode",
		textStyle = { text = TEXT"窗口模式", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/check.wav")
	end
end

do
	local item = CheckBox (videosettingWindow)
	{
		name = "compatiblemode",
		textStyle = { text = TEXT"XP兼容模式(会降低游戏效率)", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/check.wav")
	end
end

do
	local item = CheckBox (videosettingWindow)
	{
		name = "minimalmode",
		textStyle = { text = TEXT"精简模式(会极大降低画面效果)", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/check.wav")
	end
end

do
	local item = Text (videosettingWindow)
	{
		name = "resolutiontext", text = TEXT"屏幕分辨率",
		font = defaultFont, size = 13, color = 0xff010101,
	} :addToGroup(nil)
end

do
	local item = Text (videosettingWindow)
	{
		name = "renderleveltext", text = TEXT"调整渲染设置",
		font = defaultFont, size = 13, color = 0xff010101,
	} :addToGroup(nil)

	item:show(false)
end

do
	local item = ComboBox (videosettingWindow)
	{
		name = "renderlevellist",
		textStyle = { text = TEXT"不改变", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
		listStyle =
		{
			textStyle = { font = defaultFont, size = 13 },
			lineHeight = 20,
			colors = { default=0xff010101, hover=0xff000000, select=0xff000000, hoverBg=0xcc8888ff, selectBg=0xccff8888 },
		},
	} :addToGroup(nil)

	function item:onExpand (flag)
		LuaSkinApi.playSound("patcher/skin/sounds/selectresolution.wav")
	end

	item:show(false)
end


--
-- choose window
--

local chooseWindow = Window
{
	name = "choose",
	title = TEXT"请选择",
	width = positionData["choose"].width,
	height = positionData["choose"].height,
}

chooseWindow.m_callback = unused

function chooseWindow:setCallback (callback)
	if callback then
		chooseWindow.m_callback = callback
	else
		chooseWindow.m_callback = unused
	end
end

function chooseWindow:onOK ()
	if self.m_callback ~= unused then
		self.m_callback()
		self.m_callback = unused
	end

	self.m_cwindow:show(false)
	LuaSkinApi.playSound("patcher/skin/sounds/confirm.wav")
	LuaSkinApi.updateFunc("MessageBoxOK", "")
end

function chooseWindow:onCancel ()
	chooseWindow.m_callback = unused

	self.m_cwindow:show(false)
	LuaSkinApi.playSound("patcher/skin/sounds/cancel.wav")
	LuaSkinApi.updateFunc("MessageBoxCancel", "")
end

do
	local item = Text (chooseWindow)
	{
		name = "title",
		font = defaultFont, size = 13, color = 0xff010101,
	} :addToGroup(nil)
end

do
	local item = Text (chooseWindow)
	{
		name = "content",
		font = defaultFont, size = 13, color = 0xff010101,
		align = "left", valign = "top", bMultiLine = true,
	} :addToGroup(nil)
end

do
	local item = TextButton (chooseWindow)
	{
		name = "ok",
		textStyle = { text = TEXT"确定", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		self.m_window:onOK()
	end
end

do
	local item = TextButton (chooseWindow)
	{
		name = "cancel",
		textStyle = { text = TEXT"取消", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		self.m_window:onCancel()
	end
end


--
-- choosefullcheck window
--

local choosefullcheckWindow = Window
{
	name = "choosefullcheck",
	title = TEXT"请选择",
	width = positionData["choosefullcheck"].width,
	height = positionData["choosefullcheck"].height,
}

function choosefullcheckWindow:onOK ()
	self.m_cwindow:show(false)
	LuaSkinApi.playSound("patcher/skin/sounds/confirm.wav")
	LuaSkinApi.updateFunc("MessageBoxOK", "")
end

function choosefullcheckWindow:onCancel ()
	self.m_cwindow:show(false)
	LuaSkinApi.playSound("patcher/skin/sounds/cancel.wav")
	LuaSkinApi.updateFunc("MessageBoxCancel", "")
end

do
	local item = Text (choosefullcheckWindow)
	{
		name = "title",
		font = defaultFont, size = 13, color = 0xff010101,
	} :addToGroup(nil)
end

do
	local item = Text (choosefullcheckWindow)
	{
		name = "content",
		font = defaultFont, size = 13, color = 0xff010101,
		valign = "top", bMultiLine = true,
	} :addToGroup(nil)
end

do
	local item = CheckBox (choosefullcheckWindow)
	{
		name = "fastcheck",
		textStyle = { text = TEXT"仅验证关键文件", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/check.wav")
	end

	item:show(false)	--强制为true
end

do
	local item = CheckBox (choosefullcheckWindow)
	{
		name = "updatefilelist",
		textStyle = { text = TEXT"更新文件列表", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		LuaSkinApi.playSound("patcher/skin/sounds/check.wav")
	end

	item:show(false)	--强制为true
end

do
	local item = TextButton (choosefullcheckWindow)
	{
		name = "ok",
		textStyle = { text = TEXT"确定", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		self.m_window:onOK()
	end
end

do
	local item = TextButton (choosefullcheckWindow)
	{
		name = "cancel",
		textStyle = { text = TEXT"取消", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		self.m_window:onCancel()
	end
end

--
-- messagebox window
--

local messageboxWindow = Window
{
	name = "messagebox",
	title = TEXT"请选择",
	width = positionData["messagebox"].width,
	height = positionData["messagebox"].height,
}

function messageboxWindow:onOK ()
	self.m_cwindow:show(false)
	LuaSkinApi.playSound("patcher/skin/sounds/confirm.wav")
	LuaSkinApi.updateFunc("MessageBoxCancel", "")
end

function messageboxWindow:onCancel ()
	self:onOK()
end

do
	local item = Text (messageboxWindow)
	{
		name = "title",
		font = defaultFont, size = 15, color = 0xff010101,
	} :addToGroup(nil)
end

do
	local item = Text (messageboxWindow)
	{
		name = "content",
		font = defaultFont, size = 13, color = 0xff010101, align = "left",
		valign = "top", bMultiLine = true,
	} :addToGroup(nil)
end

do
	local item = TextButton (messageboxWindow)
	{
		name = "ok",
		textStyle = { text = TEXT"确定", font = defaultFont, size = 13, },
		colors = {default=0xff010101, hover=0xff62460b, press=0xffee6666, disable=0xff444444},
	} :addToGroup(nil)

	function item:onClick ()
		self.m_window:onOK()
	end
end

local windowArray =
{
	mainWindow,
	updatesettingWindow,
	videosettingWindow,
	chooseWindow,
	choosefullcheckWindow,
	messageboxWindow,
}

local windowList = {}

for i = 1, #windowArray do
	local win = windowArray[i]
	windowList[win.m_name] = win
end

UI.applyPositionDataToWindowList(windowList, positionData)
--~ malut.printTable(windowList.updatesetting:getItemGroup()[3], 2)

return windowList
