_G = GLOBAL
--[[
if _G.IsDLCEnabled and _G.IsDLCEnabled(_G.CAPY_DLC) then
	LoadPOFile("DS_sw.po", "chs")
else
	LoadPOFile("DS_rog.po", "chs")
end]]

--[[if _G.IsDLCEnabled and _G.IsDLCEnabled(_G.REIGN_OF_GIANTS) and not _G.IsDLCEnabled(_G.CAPY_DLC) then
	LoadPOFile("DS_dlc1.po", "chs")
elseif _G.IsDLCEnabled and _G.IsDLCEnabled(_G.CAPY_DLC) then
	LoadPOFile("DS_dlc2.po", "chs")
else
	LoadPOFile("DS_dlc1.po", "chs")
end]]
local function Enable_chs()
	if _G.IsDLCEnabled ~= nil and _G.IsDLCEnabled(_G.CAPY_DLC) ~= nil then
		
		if _G.IsDLCEnabled then
		
			if _G.IsDLCEnabled(_G.CAPY_DLC) then
				LoadPOFile("DS_sw.po", "chs")
			else 
				LoadPOFile("DS_rog.po", "chs")
			end
			
		else
			LoadPOFile("DS.po", "chs")
		end
		
	end
end

	
--设置是否强制启用汉化
local Fopen = GetModConfigData("Fopen")
if not Fopen then
	if _G.LanguageTranslator and _G.LanguageTranslator.defaultlang and _G.LanguageTranslator.languages then
		if _G.LanguageTranslator.defaultlang == "lmu" then
			print("[Chinsee] 加载汉化。")
			Enable_chs()
		end
	else
		print("[Chinsee] 未安装编码补丁！如需强行启用汉化，请将mod“强行启用”设置为“是”。")
		print("[Chinsee] 如需强行启用汉化，请将mod“强行启用”设置为“是”。")
	end
else
	print("[Chinsee] 强制加载汉化。")
	Enable_chs()
end

--local nochange = GetModConfigData("colour")
local colour = GetModConfigData("colour")
--if not nochange then
	--字体颜色
	local colourtable = 
	{
		nochange = {255,255,255},
		qing = {0, 255, 255},
		bai = {255, 255, 255},
		hei= {0, 0, 0},
		hong= {255, 0, 0},
		cheng= {255, 165, 0},
		huang= {255, 255, 0},
		lv= {0, 255, 0},
		lan= {0, 0, 255},
		zi= {255, 0, 255},
	}

	--字体灰度
	local huidu = GetModConfigData("huidu")

	local function RGB(tab)
		return { tab[1] / 255 * huidu, tab[2] / 255 * huidu, tab[3] / 255 * huidu, 1 }
	end

	--text***
	local Text = _G.require "widgets/text"
	local old_Text_SetColour = Text.SetColour
	function Text:SetColour(r,g,b,a)
	
		if colour == "nochange" then
			old_Text_SetColour(self, r,g,b,a)
		else
			local textcolour = RGB(colourtable[colour])
			self.inst.TextWidget:SetColour(textcolour[1], textcolour[2], textcolour[3], textcolour[4])
		end
		
	end
	function Text:SetString(str)
		self.string = str
		self.inst.TextWidget:SetString(str or "")
		
		if colour ~= "nochange" then
			local textcolour = RGB(colourtable[colour])
			self.inst.TextWidget:SetColour(textcolour[1], textcolour[2], textcolour[3], textcolour[4])
		end
		
	end
	function Text:SetAlpha(a)
		if colour == "nochange" then
			self.inst.TextWidget:SetColour(1, 1, 1, a)
		else
			local textcolour = RGB(colourtable[colour])
			self.inst.TextWidget:SetColour(textcolour[1], textcolour[2], textcolour[3], a)
		end
	end
--end

--[[
--hover
local HoverText = _G.require "widgets/hoverer"
local old_hover_update = HoverText.OnUpdate
function HoverText:OnUpdate()
	  
	old_hover_update(self)
	
	local textcolour = RGB(colourtable[colour])
	self.text:SetColour(textcolour[1], textcolour[2], textcolour[3], textcolour[4])
   
end

--itemtile
local ItemTile = _G.require "widgets/itemtile"
local old_itemtile_update = ItemTile.UpdateTooltip
function ItemTile:UpdateTooltip()
	
	old_itemtile_update(self)
	
	local textcolour = RGB(colourtable[colour])
	self:SetTooltipColour(textcolour[1], textcolour[2], textcolour[3], textcolour[4])
	
end

--inventorybar
local Inv = _G.require "widgets/inventorybar"
local old_Inv_SetTooltipColour = Inv.SetTooltipColour
function Inv:SetTooltipColour(r,g,b,a)
	old_Inv_SetTooltipColour(self, r,g,b,a)
	local textcolour = RGB(colourtable[colour])
	self.actionstringtitle:SetColour(textcolour[1], textcolour[2], textcolour[3], textcolour[4])
end

--widget
local Widget = _G.require "widgets/widget"
local old_Widget_SetTooltipColour = Widget.SetTooltipColour
function Widget:SetTooltipColour(r,g,b,a)
	old_Widget_SetTooltipColour(self, r,g,b,a)
	local textcolour = RGB(colourtable[colour])
    self.tooltipcolour = textcolour
end

--talker***
AddPrefabPostInitAny(function(inst)
	if inst.components.talker then
		local textcolour = RGB(colourtable[colour])
		inst.components.talker.colour = textcolour
	end
end)]]

--[[
--chatqueue
local ChatQueue = _G.require "widgets/chatqueue"
local old_chatqueue_update = ChatQueue.OnUpdate
function ChatQueue:OnUpdate()
	
	old_chatqueue_update(self)
	
	local textcolour = RGB(colourtable[colour])
	self.messages[i]:SetColour(textcolour[1], textcolour[2], textcolour[3], textcolour[4])
	self.users[i]:SetColour(textcolour[1], textcolour[2], textcolour[3], textcolour[4])
	
end]]











