local talent = CreateFrame("Frame", "InvenSimulatorTalentFrame", UIParent)
talent:Hide()
talent:SetToplevel(true)
talent:SetScript("OnShow", function(self) self:CreateFrame() end)
InvenSimulatorUI.talentFrame = talent

local _G = _G
local max = _G.max
local type = _G.type
local pairs = _G.pairs
local ipairs = _G.ipairs
local unpack = _G.unpack
local tonumber = _G.tonumber
local tinsert = _G.table.insert
local GetTalentTabInfo = _G.GetTalentTabInfo
local GetNumTalents = _G.GetNumTalents
local GetTalentInfo = _G.GetTalentInfo

local LDM = LibStub("LibDropMenu-2.0")
local talentLink = "|cff4e96f7|Htalent:%d:%d|h[%s]|h|r"
local branch, branch1, isLearnable

function talent:CreateFrame()
	self:SetFrameLevel(InvenSimulatorUI:GetFrameLevel() + 5)
	self.levelElements = {}
	self.usablePoints = 0
	self.buttons = {}
	self.talents = {}
	self.tierCount = {}
	self.talentTierColumn = {}
	self.branchs = {}
	self:SetWidth(384)
	self:SetHeight(512)
	self:SetToplevel(true)
	self:EnableMouse(true)
	self:SetClampedToScreen(true)
	self:SetMovable(true)
	self:RegisterForDrag("LeftButton")
	self:SetScript("OnDragStart", self.StartMoving)
	self:SetScript("OnDragStop", function(self)
		self:StopMovingOrSizing()
		InvenSimulatorUI.db.talentPos[1], _, _, InvenSimulatorUI.db.talentPos[2], InvenSimulatorUI.db.talentPos[3] = self:GetPoint()
	end)
	self:SetWidth(340)
	self:SetHeight(426)
	self:SetPoint(unpack(InvenSimulatorUI.db.talentPos))
	self:SetScript("OnShow", function() PlaySound("igCharacterInfoOpen") end)
	self:SetScript("OnHide", function() PlaySound("igCharacterInfoClose") end)
	self.icon = self:CreateTexture(nil, "BACKGROUND")
	self.icon:SetWidth(64)
	self.icon:SetHeight(64)
	self.icon:SetPoint("TOPLEFT", -8, 8)
	self.title = self:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
	self.title:SetHeight(14)
	self.title:SetText(InvenSimulator.addonName.." - 특성 및 문양")
	self.title:SetPoint("TOP", 10, -4)
	local tex
	tex = self:CreateTexture(nil, "ARTWORK")
	tex:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-General-TopLeft")
	tex:SetWidth(256)
	tex:SetHeight(256)
	tex:SetPoint("TOPLEFT", -12, 12)
	tex = self:CreateTexture(nil, "ARTWORK")
	tex:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-General-TopRight")
	tex:SetWidth(128)
	tex:SetHeight(256)
	tex:SetPoint("TOPLEFT", 244, 12)
	tex = self:CreateTexture(nil, "ARTWORK")
	tex:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-General-BottomLeft")
	tex:SetWidth(256)
	tex:SetHeight(256)
	tex:SetPoint("TOPLEFT", -12, -244)
	tex = self:CreateTexture(nil, "ARTWORK")
	tex:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-General-BottomRight")
	tex:SetWidth(128)
	tex:SetHeight(256)
	tex:SetPoint("TOPLEFT", 244, -244)
	self.closeButton = CreateFrame("Button", nil, self, "UIPanelCloseButton")
	self.levelElements[self.closeButton] = 1
	self.closeButton:SetPoint("CENTER", self, "TOPRIGHT", -14, -12)
	self.pointBar = CreateFrame("Frame", nil, self)
	self.levelElements[self.pointBar] = 1
	self.pointBar:SetWidth(331)
	self.pointBar:SetHeight(26)
	self.pointBar:SetPoint("LEFT", 2, 0)
	self.pointBar:SetPoint("RIGHT", -6, 0)
	self.pointBar:SetPoint("BOTTOM", 0, 4)
	tex = self.pointBar:CreateTexture(nil, "BACKGROUND")
	tex:SetTexture("Interface\\Buttons\\UI-Button-Borders2")
	tex:SetTexCoord(0, 0.646484375, 0.2109375, 0.4140625)
	tex:SetAllPoints()
	tex = self.pointBar:CreateTexture(nil, "BORDER")
	tex:SetTexture("Interface\\Buttons\\UI-Button-Borders2")
	tex:SetTexCoord(0, 0.01171875, 0.421875, 0.5625)
	tex:SetWidth(6)
	tex:SetHeight(18)
	tex:SetPoint("LEFT", 4, 0)
	tex:SetPoint("TOP", 0, -5)
	tex:SetPoint("BOTTOM", 0, 5)
	local tex2 = self.pointBar:CreateTexture(nil, "BORDER")
	tex2:SetTexture("Interface\\Buttons\\UI-Button-Borders2")
	tex2:SetTexCoord(0.3046875, 0.31640625, 0.421875, 0.5625)
	tex2:SetWidth(6)
	tex2:SetHeight(18)
	tex2:SetPoint("RIGHT", -4, 0)
	tex2:SetPoint("TOP", 0, -5)
	tex2:SetPoint("BOTTOM", 0, 5)
	local tex3 = self.pointBar:CreateTexture(nil, "BORDER")
	tex3:SetTexture("Interface\\Buttons\\UI-Button-Borders2")
	tex3:SetTexCoord(0.01171875, 0.3046875, 0.421875, 0.5625)
	tex3:SetPoint("TOPLEFT", tex, "TOPRIGHT")
	tex3:SetPoint("BOTTOMRIGHT", tex2, "BOTTOMLEFT")
	self.pointBar.text1 = self.pointBar:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	self.pointBar.text1:SetJustifyH("LEFT")
	self.pointBar.text1:SetPoint("LEFT", 12, 0)
	self.pointBar.text2 = self.pointBar:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
	self.pointBar.text2:SetJustifyH("RIGHT")
	self.pointBar.text2:SetPoint("RIGHT", -12, 0)
	self.tab = {}
	local function tabOnClick(tab)
		PlaySound("igCharacterInfoTab")
		InvenSimulatorTalentFrame.selectedTab = tab:GetID()
		PanelTemplates_UpdateTabs(InvenSimulatorTalentFrame)
		if tab:GetID() > MAX_TALENT_TABS then
			for i = 1, MAX_TALENT_TABS do
				InvenSimulatorTalentFrame.tab[i]:SetText((InvenSimulatorTalentFrame.tab[i]:GetText()):gsub("ffffd200", "ffffffff"))
			end
			InvenSimulatorTalentFrame.scroll:Hide()
			InvenSimulatorTalentFrame.pointBar:Hide()
			if not InvenSimulatorTalentFrame.glyph then
				InvenSimulatorTalentFrame:CreateGlyphFrame()
			end
			InvenSimulatorTalentFrame.glyph:Show()
		else
			InvenSimulatorTalentFrame.scroll:Show()
			InvenSimulatorTalentFrame.pointBar:Show()
			if InvenSimulatorTalentFrame.glyph then
				InvenSimulatorTalentFrame.glyph:Hide()
			end
			talent:SetTalent(tab:GetID())
		end
	end
	for i = 1, MAX_TALENT_TABS + 1 do
		self.tab[i] = CreateFrame("Button", "InvenSimulatorTalentFrameTab"..i, self, "CharacterFrameTabButtonTemplate")
		self.levelElements[self.tab[i]] = 1
		self.tab[i]:SetID(i)
		self.tab[i]:Show()
		self.tab[i]:SetScript("OnClick", tabOnClick)
		if i == 1 then
			self.tab[i]:SetPoint("TOPLEFT", self, "BOTTOMLEFT", 0, 4)
		else
			self.tab[i]:SetPoint("LEFT", self.tab[i - 1], "RIGHT", -15, 0)
		end
		if i > MAX_TALENT_TABS then
			self.tab[i]:SetText("문양")
			PanelTemplates_TabResize(self.tab[i], 0)
		else
			self.tab[i].talentName = GetTalentTabInfo(i)
		end
	end
	PanelTemplates_SetNumTabs(self, MAX_TALENT_TABS + 1)
	self.scroll = CreateFrame("ScrollFrame", "InvenSimulatorTalentFrameScrollFrame", self, "UIPanelScrollFrameTemplate")
	self.levelElements[self.scroll] = 1
	self.scroll:SetWidth(296)
	self.scroll:SetHeight(332)
	self.scroll:SetPoint("TOPRIGHT", -34, -64)
	self.scroll:SetPoint("BOTTOM", self.pointBar, "TOP", 0, 0)
	self.bgTopLeft = self.scroll:CreateTexture(nil, "BORDER")
	self.bgTopLeft:SetWidth(256)
	self.bgTopLeft:SetHeight(256)
	self.bgTopLeft:SetPoint("TOPLEFT")
	self.bgTopLeft:SetPoint("RIGHT", -40, 0)
	self.bgTopLeft:SetPoint("BOTTOM", 0, 76)
	self.bgTopRight = self.scroll:CreateTexture(nil, "BORDER")
	self.bgTopRight:SetWidth(44)
	self.bgTopRight:SetHeight(256)
	self.bgTopRight:SetPoint("TOPRIGHT")
	self.bgTopRight:SetPoint("BOTTOMLEFT", self.bgTopLeft, "BOTTOMRIGHT")
	self.bgTopRight:SetTexCoord(0, 0.6875, 0, 1)
	self.bgBottomLeft = self.scroll:CreateTexture(nil, "BORDER")
	self.bgBottomLeft:SetWidth(256)
	self.bgBottomLeft:SetHeight(75)
	self.bgBottomLeft:SetPoint("BOTTOMLEFT")
	self.bgBottomLeft:SetPoint("TOPRIGHT", self.bgTopLeft, "BOTTOMRIGHT")
	self.bgBottomLeft:SetTexCoord(0, 1, 0, 0.5859375)
	self.bgBottomRight = self.scroll:CreateTexture(nil, "BORDER")
	self.bgBottomRight:SetWidth(44)
	self.bgBottomRight:SetHeight(75)
	self.bgBottomRight:SetPoint("BOTTOMRIGHT")
	self.bgBottomRight:SetPoint("TOPLEFT", self.bgTopLeft, "BOTTOMRIGHT")
	self.bgBottomRight:SetTexCoord(0, 0.6875, 0, 0.5859375)
	tex = self.scroll:CreateTexture(nil, "ARTWORK")
	tex:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ScrollBar")
	tex:SetWidth(31)
	tex:SetHeight(256)
	tex:SetPoint("TOPLEFT", self.scroll, "TOPRIGHT", -2, 5)
	tex:SetTexCoord(0, 0.484375, 0, 1)
	tex = self.scroll:CreateTexture(nil, "ARTWORK")
	tex:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ScrollBar")
	tex:SetWidth(31)
	tex:SetHeight(106)
	tex:SetPoint("BOTTOMLEFT", self.scroll, "BOTTOMRIGHT", -2, -2)
	tex:SetTexCoord(0.515625, 1, 0, 0.4140625)
	self.scrollChild = CreateFrame("Frame", "InvenSimulatorTalentFrameScrollChildFrame", self.scroll)
	self.levelElements[self.scrollChild] = 2
	self.scroll:SetScrollChild(self.scrollChild)
	self.scrollChild:SetWidth(320)
	self.scrollChild:SetHeight(50)
	self.scrollChild:SetPoint("TOPLEFT")
	self.reset = CreateFrame("Button", nil, self.scroll, "UIPanelButtonTemplate")
	self.levelElements[self.reset] = 2
	self.reset:SetWidth(100)
	self.reset:SetHeight(21)
	self.reset:SetText("현재 특성 초기화")
	self.reset:SetPoint("BOTTOMRIGHT", self.scroll, "TOPRIGHT", 27, 21)
	self.reset:SetScript("OnClick", function()
		local tabName = "^"..InvenSimulatorUI.talentTabNames[InvenSimulatorTalentFrame.selectedTab]..";"
		for talent in pairs(InvenSimulatorCharDB.talents) do
			if talent:find(tabName) then
				InvenSimulatorCharDB.talents[talent] = nil
			end
		end
		InvenSimulatorUI:Calculate()
		InvenSimulatorTalentFrame:SetTalent(InvenSimulatorTalentFrame.selectedTab)
	end)
	self.resetAll = CreateFrame("Button", nil, self.scroll, "UIPanelButtonTemplate")
	self.levelElements[self.resetAll] = 2
	self.resetAll:SetWidth(100)
	self.resetAll:SetHeight(21)
	self.resetAll:SetText("모든 특성 초기화")
	self.resetAll:SetPoint("TOP", self.reset, "BOTTOM", 0, 2)
	self.resetAll:SetScript("OnClick", function()
		for talent in pairs(InvenSimulatorCharDB.talents) do
			InvenSimulatorCharDB.talents[talent] = nil
		end
		InvenSimulatorUI:Calculate()
		InvenSimulatorTalentFrame:SetTalent(InvenSimulatorTalentFrame.selectedTab)
	end)
	self.copy = CreateFrame("Button", nil, self.scroll, "UIPanelButtonTemplate")
	self.levelElements[self.copy] = 2
	self.copy:SetWidth(110)
	self.copy:SetHeight(21)
	self.copy:SetText("현재 특성 가져오기")
	self.copy:SetPoint("RIGHT", self.reset, "LEFT", 0, 0)
	self.copy:SetScript("OnClick", function()
		InvenSimulatorUI:CopyTalent()
		InvenSimulatorUI:Calculate()
		InvenSimulatorTalentFrame:SetTalent(InvenSimulatorTalentFrame.selectedTab)
	end)
	tinsert(UISpecialFrames, "InvenSimulatorTalentFrame")
	PlaySound("igCharacterInfoOpen")
	local maxPointSpent, spent = 0, 1
	self.selectedTab = 1
	for i = 1, MAX_TALENT_TABS do
		spent = self:GetSpentPoints(i)
		if maxPointSpent < spent then
			maxPointSpent = spent
			self.selectedTab = i
		end
	end
	PanelTemplates_UpdateTabs(self)
	self:SetTalent(self.selectedTab)
	InvenSimulatorUI:ShowTop(self)
end

function talent:SetTalent(id)
	for p in pairs(self.talents) do
		self.talents[p] = nil
	end
	for p in pairs(self.talentTierColumn) do
		for v in pairs(self.talentTierColumn[p]) do
			self.talentTierColumn[p][v] = nil
		end
	end
	self.reset:SetText(InvenSimulatorUI.talentTabNames[id].." 특성 초기화")
	self.numTalents = GetNumTalents(id)
	local tabName, tabIcon, _, background = GetTalentTabInfo(id)
	local spentPoint, name, icon, tier, column, rank, maxRank, isExceptional, meetsPrereq, button, ptier, pcolumn
	SetPortraitToTexture(self.icon, tabIcon)
	self.bgTopLeft:SetTexture("Interface\\TalentFrame\\"..background.."-TopLeft")
	self.bgTopRight:SetTexture("Interface\\TalentFrame\\"..background.."-TopRight")
	self.bgBottomLeft:SetTexture("Interface\\TalentFrame\\"..background.."-BottomLeft")
	self.bgBottomRight:SetTexture("Interface\\TalentFrame\\"..background.."-BottomRight")
	for i = 1, MAX_TALENT_TABS do
		spentPoint = self:GetSpentPoints(i)
		self.totalPoint = (i == 1 and 0 or self.totalPoint) + spentPoint
		self.spentPoint = i == id and spentPoint or self.spentPoint
		self.tab[i]:SetText(self.tab[i].talentName.."|cffffffff "..spentPoint)
		PanelTemplates_TabResize(self.tab[i], 0)
	end
	self.numBranch, self.maxTier = 0, 0
	for i = 1, self.numTalents do
		self:CreateButton(i)
		name, icon, tier, column, _, maxRank, isExceptional, meetsPrereq = GetTalentInfo(id, i)
		ptier, pcolumn = GetTalentPrereqs(id, i)
		self.maxTier = max(self.maxTier, tier)
		rank = InvenSimulatorCharDB.talents[InvenSimulatorUI.talentTabNames[id]..";"..name] or 0
		self.buttons[i].name = name
		self.buttons[i].rank = rank
		self.buttons[i].maxRank = maxRank
		self.buttons[i].tier = tier
		self.buttons[i].talentID = tonumber(GetTalentLink(id, i):match("talent:(%d+)"))
		self.buttons[i].icon:SetTexture(icon)
		self.buttons[i]:ClearAllPoints()
		self.buttons[i]:SetPoint("TOPLEFT", (column - 1) * 63 + 35, (1 - tier) * 63 - 20)
		self.buttons[i]:Show()
		self.talents[name] = i
		self.talentTierColumn[tier] = self.talentTierColumn[tier] or {}
		self.talentTierColumn[tier][column] = name
		if self.buttons[i].req then
			for p in pairs(self.buttons[i].req) do
				self.buttons[i].req[p] = nil
			end
		end
		if self.buttons[i].lines then
			for p in pairs(self.buttons[i].lines) do
				self.buttons[i].lines[p] = nil
			end
		end
		if self.buttons[i].arrow then
			self.buttons[i].arrow:Hide()
		end
		if ptier and self.talentTierColumn[ptier] and pcolumn and self.talentTierColumn[ptier][pcolumn] then
			self.buttons[i].lines = self.buttons[i].lines or {}
			self.buttons[i].dep = self.talents[self.talentTierColumn[ptier][pcolumn]]
			self.buttons[self.talents[self.talentTierColumn[ptier][pcolumn]]].req = self.buttons[self.talents[self.talentTierColumn[ptier][pcolumn]]].req or {}
			self.buttons[self.talents[self.talentTierColumn[ptier][pcolumn]]].req[i] = true
			self:CreateBranch(tier, column, ptier, pcolumn)
		else
			self.buttons[i].dep = nil
		end
	end
	for i = self.numTalents + 1, #self.buttons do
		self.buttons[i]:Hide()
	end
	for i = self.numBranch + 1, #self.branchs do
		self.branchs[i]:Hide()
	end
	self:UpdateTalent()
end

function talent:UpdateTalent()
	self.usablePoints = 71 - self.totalPoint
	self.tab[self.selectedTab]:SetText(self.tab[self.selectedTab].talentName.."|cffffd200 "..self.spentPoint)
	self.pointBar.text1:SetFormattedText("%s 특성 포인트 함계:|cffffffff %d|r", self.tab[self.selectedTab].talentName, self.spentPoint)
	self.pointBar.text2:SetFormattedText("사용하지 않은 특성 포인트:|cffffffff %d|r", self.usablePoints)
	local count = 0
	for i = 1, self.maxTier do
		self.tierCount[i] = 0
	end
	for i = 1, self.numTalents do
		self.tierCount[self.buttons[i].tier] = self.tierCount[self.buttons[i].tier] + self.buttons[i].rank
		count = count + self.buttons[i].rank
		if self.usablePoints == 0 and self.buttons[i].rank == 0 then
			isLearnable = 0
		elseif self.buttons[i].rank == self.buttons[i].maxRank then
			isLearnable = 2
		elseif ((self.buttons[i].tier - 1) * 5) <= count then
			isLearnable = 1
		else
			isLearnable = 0
		end
		if self.buttons[i].dep and self.buttons[self.buttons[i].dep].rank < self.buttons[self.buttons[i].dep].maxRank then
			isLearnable = 0
		end
		if isLearnable == 1 then
			self.buttons[i].icon:SetDesaturated(nil)
			self.buttons[i].slot:SetVertexColor(0.1, 1, 0.1)
			self.buttons[i].rankText:SetTextColor(0, 1, 0)
		elseif isLearnable == 2 then
			self.buttons[i].icon:SetDesaturated(nil)
			self.buttons[i].slot:SetVertexColor(1, 0.82, 0)
			self.buttons[i].rankText:SetTextColor(1, 0.82, 0)
		else
			self.buttons[i].icon:SetDesaturated(true)
			self.buttons[i].slot:SetVertexColor(0.5, 0.5, 0.5)
			self.buttons[i].rankText:SetTextColor(1, 1, 1)
		end
		if self.buttons[i].rank == 0 and self.usablePoints == 0 then
			self.buttons[i].rankBorder:Hide()
		else
			self.buttons[i].rankBorder:Show()
		end
		self.buttons[i].rankText:SetFormattedText("%d/%d", self.buttons[i].rank, self.buttons[i].maxRank)
		if self.buttons[i].arrow and self.buttons[i].arrow:IsShown() then
			if self.usablePoints > 0 and isLearnable == 0 then
				branch = -1
			elseif self.buttons[i].rank == 0 and self.usablePoints == 0 then
				branch = -1
			elseif self.buttons[self.buttons[i].dep].rank == self.buttons[self.buttons[i].dep].maxRank then
				branch = 1
			else
				branch = -1
			end
			self.buttons[i].arrow:SetTexCoord(unpack(TALENT_ARROW_TEXTURECOORDS[self.buttons[i].arrow.coord][branch]))
			for _, texture in pairs(self.buttons[i].lines) do
				texture:SetTexCoord(unpack(TALENT_BRANCH_TEXTURECOORDS[texture.coord][branch]))
			end
		end
	end
end

local function createBranch(coord)
	InvenSimulatorTalentFrame.numBranch = InvenSimulatorTalentFrame.numBranch + 1
	if not InvenSimulatorTalentFrame.branchs[InvenSimulatorTalentFrame.numBranch] then
		InvenSimulatorTalentFrame.branchs[InvenSimulatorTalentFrame.numBranch] = InvenSimulatorTalentFrameScrollChildFrame:CreateTexture(nil, "BACKGROUND", "TalentBranchTemplate")
	end
	InvenSimulatorTalentFrame.branchs[InvenSimulatorTalentFrame.numBranch].coord = coord
	InvenSimulatorTalentFrame.branchs[InvenSimulatorTalentFrame.numBranch]:ClearAllPoints()
	InvenSimulatorTalentFrame.branchs[InvenSimulatorTalentFrame.numBranch]:Show()
	return InvenSimulatorTalentFrame.branchs[InvenSimulatorTalentFrame.numBranch]
end

local function createArrow(button, coord)
	button.arrow = button.arrow or button:CreateTexture(nil, "OVERLAY", "TalentArrowTemplate")
	button.arrow.coord = coord
	button.arrow:ClearAllPoints()
	if coord == "top" then
		button.arrow:SetPoint("CENTER", button, "TOP", 0, 2)
	elseif coord == "right" then
		button.arrow:SetPoint("CENTER", button, "RIGHT", 2, 0)
	else
		button.arrow:SetPoint("CENTER", button, "LEFT", -2, 0)
	end
	button.arrow:SetTexCoord(unpack(TALENT_ARROW_TEXTURECOORDS[coord][-1]))
	button.arrow:Show()
end

function talent:CreateBranch(t, c, pt, pc)
	if t == pt and c > pc then
		createArrow(self.buttons[self.talents[self.talentTierColumn[t][c]]], "left")
		branch = createBranch("right")
		branch:SetPoint("RIGHT", self.buttons[self.talents[self.talentTierColumn[t][c]]], "LEFT")
		branch:SetPoint("LEFT", self.buttons[self.talents[self.talentTierColumn[pt][pc]]], "RIGHT")
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch)
	elseif t == pt and c < pc then
		createArrow(self.buttons[self.talents[self.talentTierColumn[t][c]]], "right")
		branch = createBranch("left")
		branch:SetPoint("LEFT", self.buttons[self.talents[self.talentTierColumn[t][c]]], "RIGHT")
		branch:SetPoint("RIGHT", self.buttons[self.talents[self.talentTierColumn[pt][pc]]], "LEFT")
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch)
	elseif c == pc and t > pt then
		createArrow(self.buttons[self.talents[self.talentTierColumn[t][c]]], "top")
		branch = createBranch("down")
		branch:SetPoint("BOTTOM", self.buttons[self.talents[self.talentTierColumn[t][c]]], "TOP")
		branch:SetPoint("TOP", self.buttons[self.talents[self.talentTierColumn[pt][pc]]], "BOTTOM")
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch)
	elseif t > pt and c < pc then
		createArrow(self.buttons[self.talents[self.talentTierColumn[t][c]]], "top")
		branch = createBranch("topleft")
		branch:SetPoint("TOPLEFT", (c - 1) * 63 + 37.5, (1 - pt) * 63 - 22.5)
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch)
		branch1 = createBranch("right")
		branch1:SetPoint("RIGHT", self.buttons[self.talents[self.talentTierColumn[pt][pc]]], "LEFT")
		branch1:SetPoint("LEFT", branch, "RIGHT", -2, 0)
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch1)
		branch1 = createBranch("down")
		branch1:SetPoint("BOTTOM", self.buttons[self.talents[self.talentTierColumn[t][c]]], "TOP")
		branch1:SetPoint("TOP", branch, "BOTTOM", 0, 2)
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch1)
	elseif t > pt and c > pc then
		createArrow(self.buttons[self.talents[self.talentTierColumn[t][c]]], "top")
		branch = createBranch("topright")
		branch:SetPoint("TOPLEFT", (c - 1) * 63 + 37.5, (1 - pt) * 63 - 22.5)
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch)
		branch1 = createBranch("right")
		branch1:SetPoint("LEFT", self.buttons[self.talents[self.talentTierColumn[pt][pc]]], "RIGHT")
		branch1:SetPoint("RIGHT", branch, "LEFT", 2, 0)
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch1)
		branch1 = createBranch("down")
		branch1:SetPoint("BOTTOM", self.buttons[self.talents[self.talentTierColumn[t][c]]], "TOP")
		branch1:SetPoint("TOP", branch, "BOTTOM", 0, 2)
		tinsert(self.buttons[self.talents[self.talentTierColumn[t][c]]].lines, branch1)
	end
end

local function talentButtonOnEnter(self)
	GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
	GameTooltip:SetHyperlink(talentLink:format(self.talentID, self.rank - 1, self.name))
	GameTooltip:Show()
end

local function talentButtonOnClick(self, button)
	if button == "LeftButton" then
		if IsShiftKeyDown() then
			ChatFrame1EditBox:Show()
			ChatFrame1EditBox:Insert(("|cff4e96f7|Htalent:%d:%d|h[%s]|h|r"):format(self.talentID, self.rank - 1, self.name))
		elseif self.rank < self.maxRank and InvenSimulatorTalentFrame.usablePoints > 0 then
			InvenSimulatorTalentFrame:LearnTalent(self, 1)
		end
	elseif self.rank > 0 then
		InvenSimulatorTalentFrame:LearnTalent(self, -1)
	end
	talentButtonOnEnter(self)
end

local function talentButtonRankBorderOnEnter(self)
	self:GetParent():LockHighlight()
	talentButtonOnEnter(self:GetParent())
end

local function talentButtonRankBorderOnLeave(self)
	self:GetParent():UnlockHighlight()
	GameTooltip:Hide()
end

local function talentButtonRankBorderOnClick(self, button)
	talentButtonOnClick(self:GetParent(), button)
end

function talent:CreateButton(id)
	if self.buttons[id] then return end
	self.buttons[id] = CreateFrame("Button", nil, self.scrollChild)
	self.levelElements[self.buttons[id]] = 3
	self.buttons[id]:SetID(id)
	self.buttons[id]:SetWidth(37)
	self.buttons[id]:SetHeight(37)
	self.buttons[id]:SetScript("OnClick", talentButtonOnClick)
	self.buttons[id]:SetScript("OnEnter", talentButtonOnEnter)
	self.buttons[id]:SetScript("OnLeave", GameTooltip_Hide)
	self.buttons[id]:RegisterForClicks("LeftButtonUp", "RightButtonUp")
	self.buttons[id]:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
	self.buttons[id].icon = self.buttons[id]:CreateTexture(nil, "BORDER")
	self.buttons[id].icon:SetPoint("TOPLEFT", 1, -1)
	self.buttons[id].icon:SetPoint("BOTTOMRIGHT", -1, 1)
	self.buttons[id].icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
	self.buttons[id].slot = self.buttons[id]:CreateTexture(nil, "BACKGROUND")
	self.buttons[id].slot:SetTexture("Interface\\Buttons\\UI-EmptySlot-White")
	self.buttons[id].slot:SetWidth(64)
	self.buttons[id].slot:SetHeight(64)
	self.buttons[id].slot:SetPoint("CENTER")
	self.buttons[id].rankBorder = CreateFrame("Button", nil, self.buttons[id])
	self.buttons[id].rankBorder:SetWidth(42)
	self.buttons[id].rankBorder:SetHeight(32)
	self.buttons[id].rankBorder:SetPoint("CENTER", self.buttons[id], "BOTTOMRIGHT")
	self.buttons[id].rankBorder:RegisterForClicks("LeftButtonUp", "RightButtonUp")
	self.buttons[id].rankBorder:SetScript("OnClick", talentButtonRankBorderOnClick)
	self.buttons[id].rankBorder:SetScript("OnEnter", talentButtonRankBorderOnEnter)
	self.buttons[id].rankBorder:SetScript("OnLeave", talentButtonRankBorderOnLeave)
	self.buttons[id].rankBorder.left = self.buttons[id].rankBorder:CreateTexture(nil, "OVERLAY")
	self.buttons[id].rankBorder.left:SetTexture("Interface\\TalentFrame\\TalentFrame-RankBorder")
	self.buttons[id].rankBorder.left:SetTexCoord(0, 0.5, 0, 1)
	self.buttons[id].rankBorder.left:SetWidth(16)
	self.buttons[id].rankBorder.left:SetHeight(32)
	self.buttons[id].rankBorder.left:SetPoint("LEFT")
	self.buttons[id].rankBorder.right = self.buttons[id].rankBorder:CreateTexture(nil, "OVERLAY")
	self.buttons[id].rankBorder.right:SetTexture("Interface\\TalentFrame\\TalentFrame-RankBorder")
	self.buttons[id].rankBorder.right:SetTexCoord(0.5, 1, 0, 1)
	self.buttons[id].rankBorder.right:SetWidth(16)
	self.buttons[id].rankBorder.right:SetHeight(32)
	self.buttons[id].rankBorder.right:SetPoint("RIGHT")
	self.buttons[id].rankBorder.middle = self.buttons[id].rankBorder:CreateTexture(nil, "OVERLAY")
	self.buttons[id].rankBorder.middle:SetTexture("Interface\\TalentFrame\\TalentFrame-RankBorder")
	self.buttons[id].rankBorder.middle:SetTexCoord(0.4, 0.6, 0, 1)
	self.buttons[id].rankBorder.middle:SetPoint("TOPLEFT", self.buttons[id].rankBorder.left, "TOPRIGHT")
	self.buttons[id].rankBorder.middle:SetPoint("BOTTOMRIGHT", self.buttons[id].rankBorder.right, "BOTTOMLEFT")
	self.buttons[id].rankText = self.buttons[id].rankBorder:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
	self.buttons[id].rankText:SetPoint("CENTER", 0, 1)
end

function talent:LearnTalent(button, add)
	if add > 0 then
		if button.dep and self.buttons[button.dep].rank < self.buttons[button.dep].maxRank then
			return
		elseif self.spentPoint < (button.tier * 5 - 5) then
			return
		end
	elseif add < 0 then
		if button.req then
			for id in pairs(button.req) do
				if self.buttons[id].rank > 0 then
					return
				end
			end
		end
		if button.tier < self.maxTier then
			local count = add
			for i = 1, self.maxTier do
				if i > button.tier and self.tierCount[i] > 0 and ((i - 1) * 5) > count then
					return
				end
				count = count + self.tierCount[i]
			end
		end
	end
	button.rank = button.rank + add
	self.spentPoint = self.spentPoint + add
	self.totalPoint = self.totalPoint + add
	self:UpdateTalent()
	InvenSimulatorCharDB.talents[InvenSimulatorUI.talentTabNames[self.selectedTab]..";"..button.name] = (InvenSimulatorCharDB.talents[InvenSimulatorUI.talentTabNames[self.selectedTab]..";"..button.name] or 0) + add
	InvenSimulatorCharDB.talents[InvenSimulatorUI.talentTabNames[self.selectedTab]..";"..button.name] = InvenSimulatorCharDB.talents[InvenSimulatorUI.talentTabNames[self.selectedTab]..";"..button.name] > 0 and InvenSimulatorCharDB.talents[InvenSimulatorUI.talentTabNames[self.selectedTab]..";"..button.name] or nil
	InvenSimulatorUI:Calculate()
end

function talent:GetSpentPoints(id)
	if InvenSimulatorUI.talentTabNames[id] then
		local count = 0
		for p, v in pairs(InvenSimulatorCharDB.talents) do
			if p:find("^"..InvenSimulatorUI.talentTabNames[id]..";") then
				count = count + v
			end
		end
		return count
	else
		return 0
	end
end

function talent:GetTalentTabName(id)
	return GetTalentTabInfo(id) or ""
end

local majorGlyphList = InvenSimulatorUI.database.majorGlyphList[InvenSimulatorUI.class]
local minorGlyphList = InvenSimulatorUI.database.minorGlyphList[InvenSimulatorUI.class]
local majorGlyphMenu, minorGlyphMenu

function talent:CreateGlyphFrame()
	self.glyph = CreateFrame("Frame", "InvenSimulatorGlyphFrame", self)
	self.levelElements[self.glyph] = 1
	self.glyph:Hide()
	self.glyph:SetPoint("TOPLEFT", self, "TOPLEFT", 4, -23)
	self.glyph:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -6, 6)
	self.glyph:SetScript("OnShow", function(self)
		SetPortraitToTexture(self:GetParent().icon, "Interface\\Icons\\INV_Glyph_Major"..select(2, UnitClass("player")))
	end)
	self.glyph.bgCoords = { { 0, 0.12890625, 0.87109375, 1 }, { 0.130859375, 0.259765625, 0.87109375, 1 }, { 0.392578125, 0.521484375, 0.87109375, 1 }, { 0.5234375, 0.65234375, 0.87109375, 1 }, { 0.26171875, 0.390625, 0.87109375, 1 }, { 0.654296875, 0.783203125, 0.87109375, 1 } }
	self.glyph.icons = InvenSimulatorUI.database.glyphIcons
	self.glyph.spellToItem = InvenSimulatorUI.database.glyphSpellToItem
	self.glyph.itemToSpell = InvenSimulatorUI.database.glyphItemToSpell
	self.glyph.bg = self.glyph:CreateTexture(nil, "BACKGROUND")
	self.glyph.bg:SetAllPoints()
	self.glyph.bg:SetTexture("Interface\\Spellbook\\UI-GlyphFrame")
	self.glyph.bg:SetTexCoord(0.0364, 0.68, 0.0745, 0.8445)
	self.glyph.buttons = {}
	local function buttonOnEnter(self)
		self.highlight:Show()
		GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
		if self.link then
			if InvenSimulatorGlyphFrame.spellToItem[self.link] then
				GameTooltip:SetHyperlink("item:"..InvenSimulatorGlyphFrame.spellToItem[self.link])
			else
				GameTooltip:SetHyperlink("spell:"..self.link)
			end
		else
			GameTooltip:AddLine(self.isMajor and "주 문양" or "보조 문양")
		end
		GameTooltip:Show()
	end
	local function buttonOnLeave(self)
		self.highlight:Hide()
		GameTooltip:Hide()
	end
	local function buttonOnClick(self)
		if IsShiftKeyDown() then
			LDM:CloseMenu(1)
			ChatFrame1EditBox:Show()
			ChatFrame1EditBox:Insert(select(2, GetItemInfo(InvenSimulatorGlyphFrame.spellToItem[self.link])) or "")
		elseif self.isMajor then
			if LDM:IsOpen("ItemItemCompare2MajorGlyph") then
				LDM:CloseMenu(1)
			else
				for p, menu in pairs(majorGlyphMenu.args) do
					menu.arg1 = self:GetID()
					if p ~= "none" and InvenSimulatorUI:HasGlyphs(menu.arg2) then
						menu.hidden = true
					else
						menu.hidden = nil
					end
				end
				LDM:OpenMenu("ItemItemCompare2MajorGlyph", "TOPLEFT", self, "CENTER")
			end
		else
			if LDM:IsOpen("ItemItemCompare2MinorGlyph") then
				LDM:CloseMenu(1)
			else
				for p, menu in pairs(minorGlyphMenu.args) do
					menu.arg1 = self:GetID()
					if p ~= "none" and InvenSimulatorUI:HasGlyphs(menu.arg2) then
						menu.hidden = true
					else
						menu.hidden = nil
					end
				end
				LDM:OpenMenu("ItemItemCompare2MinorGlyph", "TOPLEFT", self, "CENTER")
			end
		end
	end
	for i = 1, 6 do
		self.glyph.buttons[i] = CreateFrame("Button", "InvenSimulatorGlyphFrameGlyph"..i, self.glyph)
		self.levelElements[self.glyph.buttons[i]] = 2
		self.glyph.buttons[i]:RegisterForClicks("LeftButtonUp", "RightButtonUp")
		self.glyph.buttons[i]:SetID(i)
		self.glyph.buttons[i].setting = self.glyph.buttons[i]:CreateTexture(nil, "BACKGROUND")
		self.glyph.buttons[i].setting:SetTexture("Interface\\Spellbook\\UI-GlyphFrame")
		self.glyph.buttons[i].setting:SetPoint("CENTER")
		self.glyph.buttons[i].highlight = self.glyph.buttons[i]:CreateTexture(nil, "BORDER")
		self.glyph.buttons[i].highlight:SetTexture("Interface\\Spellbook\\UI-GlyphFrame")
		self.glyph.buttons[i].highlight:SetPoint("CENTER")
		self.glyph.buttons[i].highlight:SetBlendMode("ADD")
		self.glyph.buttons[i].highlight:SetVertexColor(1, 1, 1, 0.25)
		self.glyph.buttons[i].highlight:Hide()
		self.glyph.buttons[i].background = self.glyph.buttons[i]:CreateTexture(nil, "BORDER")
		self.glyph.buttons[i].background:SetTexture("Interface\\Spellbook\\UI-GlyphFrame")
		self.glyph.buttons[i].background:SetTexCoord(0.78125, 0.91015625, 0.69921875, 0.828125)
		self.glyph.buttons[i].background:SetPoint("CENTER")
		self.glyph.buttons[i].glyph = self.glyph.buttons[i]:CreateTexture(nil, "ARTWORK")
		self.glyph.buttons[i].glyph:SetWidth(53)
		self.glyph.buttons[i].glyph:SetHeight(53)
		self.glyph.buttons[i].glyph:SetPoint("CENTER")
		self.glyph.buttons[i].glyph:Hide()
		self.glyph.buttons[i].ring = self.glyph.buttons[i]:CreateTexture(nil, "OVERLAY")
		self.glyph.buttons[i].ring:SetTexture("Interface\\Spellbook\\UI-GlyphFrame")
		self.glyph.buttons[i].shine = self.glyph.buttons[i]:CreateTexture(nil, "OVERLAY")
		self.glyph.buttons[i].shine:SetTexture("Interface\\Spellbook\\UI-GlyphFrame")
		self.glyph.buttons[i].shine:SetWidth(16)
		self.glyph.buttons[i].shine:SetHeight(16)
		self.glyph.buttons[i].shine:SetPoint("CENTER", -9, 12)
		self.glyph.buttons[i]:SetScript("OnClick", buttonOnClick)
		self.glyph.buttons[i]:SetScript("OnEnter", buttonOnEnter)
		self.glyph.buttons[i]:SetScript("OnLeave", buttonOnLeave)
		if i == 1 or i == 4 or i == 6 then
			self.glyph.buttons[i].isMajor = true
			self.glyph.buttons[i]:SetWidth(90)
			self.glyph.buttons[i]:SetHeight(90)
			self.glyph.buttons[i].setting:SetWidth(108)
			self.glyph.buttons[i].setting:SetHeight(108)
			self.glyph.buttons[i].setting:SetTexCoord(0.740234375, 0.953125, 0.484375, 0.697265625)
			self.glyph.buttons[i].highlight:SetWidth(108)
			self.glyph.buttons[i].highlight:SetHeight(108)
			self.glyph.buttons[i].highlight:SetTexCoord(0.740234375, 0.953125, 0.484375, 0.697265625)
			self.glyph.buttons[i].background:SetWidth(70)
			self.glyph.buttons[i].background:SetHeight(70)
			self.glyph.buttons[i].glyph:SetVertexColor(1, 0.25, 0)
			self.glyph.buttons[i].ring:SetWidth(82)
			self.glyph.buttons[i].ring:SetHeight(82)
			self.glyph.buttons[i].ring:SetPoint("CENTER", 0, -1)
			self.glyph.buttons[i].ring:SetTexCoord(0.767578125, 0.92578125, 0.32421875, 0.482421875)
			self.glyph.buttons[i].shine:SetTexCoord(0.9609375, 1, 0.9609375, 1)
		else
			self.glyph.buttons[i]:SetWidth(72)
			self.glyph.buttons[i]:SetHeight(72)
			self.glyph.buttons[i].setting:SetWidth(86)
			self.glyph.buttons[i].setting:SetHeight(86)
			self.glyph.buttons[i].setting:SetTexCoord(0.765625, 0.927734375, 0.15625, 0.31640625)
			self.glyph.buttons[i].highlight:SetWidth(86)
			self.glyph.buttons[i].highlight:SetHeight(86)
			self.glyph.buttons[i].highlight:SetTexCoord(0.765625, 0.927734375, 0.15625, 0.31640625)
			self.glyph.buttons[i].background:SetWidth(64)
			self.glyph.buttons[i].background:SetHeight(64)
			self.glyph.buttons[i].glyph:SetVertexColor(0, 0.25, 1)
			self.glyph.buttons[i].ring:SetWidth(62)
			self.glyph.buttons[i].ring:SetHeight(62)
			self.glyph.buttons[i].ring:SetPoint("CENTER", 0, 1)
			self.glyph.buttons[i].ring:SetTexCoord(0.787109375, 0.908203125, 0.033203125, 0.154296875)
			self.glyph.buttons[i].shine:SetTexCoord(0.9609375, 1, 0.921875, 0.9609375)
		end
		self:SetGlyph(i, InvenSimulatorUI.db.glyphs[i])
	end
	self.glyph.buttons[1]:SetPoint("TOP", -6, -36)
	self.glyph.buttons[2]:SetPoint("BOTTOM", -6, 36)
	self.glyph.buttons[3]:SetPoint("TOPLEFT", 18, -105)
	self.glyph.buttons[4]:SetPoint("BOTTOMRIGHT", -20, 90)
	self.glyph.buttons[5]:SetPoint("TOPRIGHT", -28, -105)
	self.glyph.buttons[6]:SetPoint("BOTTOMLEFT", 8, 90)
	self.glyph.clearMinor = CreateFrame("Button", "InvenSimulatorGlyphFrameClearMinor", self.glyph, "UIPanelButtonTemplate")
	self.levelElements[self.glyph.clearMinor] = 2
	self.glyph.clearMinor:SetText("보조 문양 제거")
	self.glyph.clearMinor:SetWidth(110)
	self.glyph.clearMinor:SetHeight(20)
	self.glyph.clearMinor:SetPoint("BOTTOMLEFT", 0, 2)
	self.glyph.clearMinor:SetScript("OnClick", function()
		for i = 1, 6 do
			if not InvenSimulatorGlyphFrame.buttons[i].isMajor then
				InvenSimulatorTalentFrame:SetGlyph(i, nil, true)
			end
		end
		InvenSimulatorUI:Calculate()
	end)
	self.glyph.clearMajor = CreateFrame("Button", "InvenSimulatorGlyphFrameClearMajor", self.glyph, "UIPanelButtonTemplate")
	self.levelElements[self.glyph.clearMajor] = 2
	self.glyph.clearMajor:SetText("주 문양 제거")
	self.glyph.clearMajor:SetWidth(110)
	self.glyph.clearMajor:SetHeight(20)
	self.glyph.clearMajor:SetPoint("BOTTOM", self.glyph.clearMinor, "TOP", 0, 0)
	self.glyph.clearMajor:SetScript("OnClick", function()
		for i = 1, 6 do
			if InvenSimulatorGlyphFrame.buttons[i].isMajor then
				InvenSimulatorTalentFrame:SetGlyph(i, nil, true)
			end
		end
		InvenSimulatorUI:Calculate()
	end)
	self.glyph.copyAll = CreateFrame("Button", "InvenSimulatorGlyphFrameClearAll", self.glyph, "UIPanelButtonTemplate")
	self.levelElements[self.glyph.copyAll] = 2
	self.glyph.copyAll:SetText("현재 문양 가져오기")
	self.glyph.copyAll:SetWidth(110)
	self.glyph.copyAll:SetHeight(20)
	self.glyph.copyAll:SetPoint("BOTTOMRIGHT", 0, 2)
	self.glyph.copyAll:SetScript("OnClick", function()
		InvenSimulatorUI:CopyGlyphs()
	end)
	self.glyph.clearAll = CreateFrame("Button", "InvenSimulatorGlyphFrameClearAll", self.glyph, "UIPanelButtonTemplate")
	self.levelElements[self.glyph.clearAll] = 2
	self.glyph.clearAll:SetText("모든 문양 제거")
	self.glyph.clearAll:SetWidth(110)
	self.glyph.clearAll:SetHeight(20)
	self.glyph.clearAll:SetPoint("BOTTOM", self.glyph.copyAll, "TOP", 0, 0)
	self.glyph.clearAll:SetScript("OnClick", function()
		for i = 1, 6 do
			InvenSimulatorTalentFrame:SetGlyph(i, nil, true)
		end
		InvenSimulatorUI:Calculate()
	end)
	local function setGlyph(slot, id)
		InvenSimulatorTalentFrame:SetGlyph(slot, id)
		LDM:CloseMenu(1)
	end
	majorGlyphMenu = { type = "group", name = "주 문양", args = {} }
	for i, id in ipairs(majorGlyphList) do
		if self.glyph.itemToSpell[id] then
			majorGlyphMenu.args[i] = {
				type = "execute",
				order = i,
				name = GetSpellInfo(self.glyph.itemToSpell[id]),
				icon = GetItemIcon(id),
				link = "item:"..id,
				arg2 = self.glyph.itemToSpell[id],
				func = setGlyph,
			}
		end
	end
	majorGlyphMenu.args.none = { type = "execute", order = 100, name = "문양 제거", desc = "현재 문양을 제거합니다.", func = setGlyph }
	LDM:RegisterMenu("ItemItemCompare2MajorGlyph", majorGlyphMenu)
	minorGlyphMenu = { type = "group", name = "보조 문양", args = {} }
	for i, id in ipairs(minorGlyphList) do
		if self.glyph.itemToSpell[id] then
			minorGlyphMenu.args[i] = {
				type = "execute",
				order = i,
				name = GetSpellInfo(self.glyph.itemToSpell[id]),
				icon = GetItemIcon(id),
				link = "item:"..id,
				arg2 = self.glyph.itemToSpell[id],
				func = setGlyph,
			}
		end
	end
	minorGlyphMenu.args.none = { type = "execute", order = 100, name = "문양 제거", desc = "현재 문양을 제거합니다.", func = setGlyph }
	LDM:RegisterMenu("ItemItemCompare2MinorGlyph", minorGlyphMenu)
end

function talent:SetGlyph(id, glyphID, skipCalculate)
	InvenSimulatorUI.db.glyphs[id] = glyphID
	if self.glyph then
		self.glyph.buttons[id].link = glyphID
		if glyphID == nil then
			self.glyph.buttons[id].background:SetTexCoord(0.78125, 0.91015625, 0.69921875, 0.828125)
			self.glyph.buttons[id].glyph:Hide()
		else
			self.glyph.buttons[id].background:SetTexCoord(unpack(self.glyph.bgCoords[id]))
			self.glyph.buttons[id].glyph:SetTexture("Interface\\Spellbook\\UI-Glyph-Rune"..(self.glyph.icons[glyphID] or 1))
			self.glyph.buttons[id].glyph:Show()
		end
	end
	if not skipCalculate then
		InvenSimulatorUI:Calculate()
	end
end


