--[[
作者：小开心
请不要擅自修改或删除
请尊重版权
@

说明：
想患 懒癌强迫症
]]

local Widget = require "widgets/widget" 
local TEMPLATES = require "widgets/templates"
local name = "nagisa"
-- 640 360
local width , height = TheSim:GetScreenSize()
local pw = width / 1134
local ph = height / 638

local Custwidget = Class(Widget, function(self, owner)
	Widget._ctor(self, "Custwidget") 

    self.owner = owner or GetPlayer()
    self.width , self.height = TheSim:GetScreenSize() 
--[[
    local image_name = "self_inspect_"..self.owner.prefab..".tex"
    local atlas_name = "images/avatars/self_inspect_"..self.owner.prefab..".xml"
    if softresolvefilepath(atlas_name) == nil then
        atlas_name = "images/hud.xml"
    end
    self.ad = self:AddChild(TEMPLATES.IconButton(atlas_name, image_name, "news", false, false, function() self:Enable() end, {size = 30}, "self_inspect_mod.tex"))
    self.ad.icon:SetScale(.7)
    self.ad.icon:SetPosition(-4, 6)
    self.ad:SetScale(.5)
    self.ad:SetPosition(30 * pw , 20 * ph , 0)
]]

	self.mod = self:AddChild(TEMPLATES.Button("定制 mod", function() self:Enable() end)) --, nil, nil, .5  Vector3(0 , pw * 1.5 , 0)
	self.mod:ForceImageSize(120, 50)
	self.mod:SetScale(.7)
	self.mod:SetHoverText("定制你的专属 mod ", { font = NEWFONT_OUTLINE, size = 30, offset_x = 30, offset_y = 45, colour = {1,1,1,1}, bg = nil })
	self.mod:SetPosition(50 * pw , 20 * ph , 0)

    TheInput:AddKeyDownHandler(KEY_F10,function()
    	if self.owner.hide then
			self.owner.hide = nil
			self:Show()
		end
 	end)

	self:StartUpdating()
end)

function Custwidget:Enable( )
	if self.news == nil then
		self.news = self:AddChild(require(name.."/widgets/news")(self.owner, self))
		self.news:SetPosition(.4 * width, height / 2 , 0)
	elseif self.news ~= nil then
		self.news:Kill()
		self.news = nil
	end
end

function Custwidget:_Hide( )
	if self.owner.hide then
		if self.news ~= nil then
			self.news:Kill()
			self.news = nil
		end
		self:Hide()
	end
end

local function updatewindow( self , width , height)

	pw = (width - 640) / (1134 - 640)
	ph = height / 638
	self.width = width 
	self.height = height

	self.ad:SetPosition(30 * pw , 20 * ph , 0)
end
	
function Custwidget:OnUpdate(dt)

	local width , height = TheSim:GetScreenSize()
	if self.width ~= width then
		updatewindow( self , width , height)
	end
end

return Custwidget
