Quantcast

Some enchant checking or character frame

Repooc [09-16-13 - 19:05]
Some enchant checking or character frame
Filename
ElvUI_SLE/media/textures/Warning-Small.tga
ElvUI_SLE/modules/characterframe/characterframe.lua
ElvUI_SLE/modules/characterframe/itemlevel.lua
ElvUI_SLE/modules/characterframe/itemmods.lua
ElvUI_SLE/modules/characterframe/load_characterframe.xml
diff --git a/ElvUI_SLE/media/textures/Warning-Small.tga b/ElvUI_SLE/media/textures/Warning-Small.tga
new file mode 100644
index 0000000..feb4e38
Binary files /dev/null and b/ElvUI_SLE/media/textures/Warning-Small.tga differ
diff --git a/ElvUI_SLE/modules/characterframe/characterframe.lua b/ElvUI_SLE/modules/characterframe/characterframe.lua
index c0c1e8b..eb1c2cd 100755
--- a/ElvUI_SLE/modules/characterframe/characterframe.lua
+++ b/ElvUI_SLE/modules/characterframe/characterframe.lua
@@ -4,12 +4,14 @@ local CFO = E:NewModule('CharacterFrameOptions', 'AceHook-3.0', 'AceEvent-3.0');
 function CFO:ToggleCFO()
 	self:UpdateItemDurability()
 	self:UpdateItemLevel()
+	self:UpdateItemMods()
 end

 function CFO:Initialize()
 	if not E.private.sle.characterframeoptions.enable then return; end
 	self:LoadDurability()
 	self:LoadItemLevel()
+	self:LoadItemMods()
 end

 E:RegisterModule(CFO:GetName())
\ No newline at end of file
diff --git a/ElvUI_SLE/modules/characterframe/itemlevel.lua b/ElvUI_SLE/modules/characterframe/itemlevel.lua
index d00ec72..124cc55 100755
--- a/ElvUI_SLE/modules/characterframe/itemlevel.lua
+++ b/ElvUI_SLE/modules/characterframe/itemlevel.lua
@@ -19,14 +19,12 @@ local WOW_Heirlooms = {

 function CFO:UpdateItemLevel()
 	local frame = _G["CharacterFrame"]
-
-	if not frame:IsShown() then
-		return
-	end
+	if not frame:IsShown() then return end

 	for i = 1, #ilvlSlots do
 		frame = _G[("Character%s"):format(ilvlSlots[i])]
 		frame.ItemLevel:SetText()
+
 		local avgItemLevel, avgEquipItemLevel = GetAverageItemLevel()
 		local actualItemLevel, itemLink
 		itemLink = GetInventoryItemLink("player",GetInventorySlotInfo(ilvlSlots[i]))
diff --git a/ElvUI_SLE/modules/characterframe/itemmods.lua b/ElvUI_SLE/modules/characterframe/itemmods.lua
new file mode 100644
index 0000000..4193a6f
--- /dev/null
+++ b/ElvUI_SLE/modules/characterframe/itemmods.lua
@@ -0,0 +1,160 @@
+local E, L, V, P, G, _ = unpack(ElvUI);
+local CFO = E:GetModule('CharacterFrameOptions')
+local LSM = LibStub("LibSharedMedia-3.0")
+
+local enchantSlot = {
+	"HeadSlot","NeckSlot","ShoulderSlot","BackSlot","ChestSlot","WristSlot",
+	"MainHandSlot","SecondaryHandSlot","HandsSlot","WaistSlot",
+	"LegsSlot","FeetSlot","Finger0Slot","Finger1Slot","Trinket0Slot","Trinket1Slot"
+}
+
+local isEnchantable = {
+	"ShoulderSlot",
+	"BackSlot",
+	"ChestSlot",
+	"WristSlot",
+	"HandsSlot",
+	"MainHandSlot",
+	"SecondaryHandSlot",
+	"LegsSlot",
+	"FeetSlot"
+}
+local frameDB = {
+	CharacterHeadSlot, CharacterNeckSlot, CharacterShoulderSlot, CharacterBackSlot, CharacterChestSlot, CharacterWristSlot,
+	CharacterMainHandSlot, CharacterSecondaryHandSlot, CharacterHandsSlot, CharacterWaistSlot,
+	CharacterLegsSlot, CharacterFeetSlot, CharacterFinger0Slot, CharacterFinger1Slot, CharacterTrinket0Slot, CharacterTrinket1Slot
+}
+local PlayerProfession = {}
+
+function CFO:UpdateItemMods()
+	local frame = _G["CharacterFrame"]
+	if not frame:IsShown() then return end
+
+	for k, myslot in pairs(enchantSlot) do
+		--frame = _G[("Character%s"):format(enchantSlot[i])]
+		frame = frameDB[k]
+		frame.ItemEnchant:SetText()
+
+		local canEnchant, isEnchanted
+		--slot = GetInventorySlotInfo(enchantSlot[i])
+
+		--if itemLink then
+			if myslot == "Finger0Slot" or myslot == "Finger1Slot" then
+				local profNames = self:fetchProfs()
+				for k, v in pairs(profNames) do
+					if v == "Enchanting" then
+						canEnchant = true
+						isEnchanted = self:fetchChant(myslot)
+					end
+				end
+			elseif myslot == "RangedSlot" then
+				local subClass = self:fetchSubclass(myslot)
+				if subClass == "Bows" or subClass == "Guns" or subClass == "Crossbows" then
+					canEnchant = true
+					isEnchanted = self:fetchChant(myslot)
+				end
+			elseif myslot == "WristSlot" or myslot == "HandsSlot" then
+				canEnchant = true
+				isEnchanted = self:fetchChant(myslot)
+			else
+				for k ,v in pairs(isEnchantable) do
+					if v == myslot then
+						canEnchant = true
+						isEnchanted = self:fetchChant(myslot)
+					end
+				end
+			end
+
+			isEnchanted = tonumber(isEnchanted)
+			if canEnchant == true then
+				if isEnchanted == 0 then
+					--self.ItemEnchant:SetFormattedText("|cffff0000%s|r|cffff0000%s|r", "E", "G")
+					frame.ItemEnchant:SetFormattedText("|cffff0000%s|r", "Not Enchanted")
+				elseif isEnchanted > 0 then
+					--self.ItemEnchant:SetFormattedText("|cff00ff00%i|r|cffff0000%s|r", "E", "G")
+					frame.ItemEnchant:SetFormattedText("|cff00ff00%s|r", "Enchanted")
+				end
+			elseif canEnchant == false then
+					frame.ItemEnchant:SetFormattedText("|cff00ff00%s|r", "Cant Enchant")
+			elseif canEnchant == nil then
+				frame.ItemEnchant:SetFormattedText("")
+			end
+
+			if not E.db.sle.characterframeoptions.itemdurability.enable then
+			frame.ItemEnchant:Hide()
+			else
+			frame.ItemEnchant:Show()
+			end
+		--end
+	end
+end
+function CFO:fetchChant(slotName)
+	local inventoryID = GetInventorySlotInfo(slotName)
+	local myLink = GetInventoryItemLink("player", inventoryID)
+	local parsedItemDataTable = {}
+	local foundStart, foundEnd, parsedItemData = string.find(myLink, "^|c%x+|H(.+)|h%[.*%]")
+	for v in string.gmatch(parsedItemData, "[^:]+") do
+		tinsert(parsedItemDataTable, v)
+	end
+
+	return parsedItemDataTable[3]
+end
+
+function CFO:fetchProfs()
+	local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions()
+	local profs = {prof1, prof2, archaeology, fishing, cooking, firstAid}
+	local profNames = {}
+
+	for k, v in pairs(profs) do
+		local name, texture, rank, maxRank, numSpells, spelloffset, skillLine, rankModifier = GetProfessionInfo(v)
+		tinsert(profNames, name)
+	end
+
+	return profNames
+end
+function CFO:fetchSubclass(slotName)
+	local slotId, texture, checkRelic = GetInventorySlotInfo(slotName)
+	local itemId = GetInventoryItemID("player", slotId)
+	if itemId then
+		local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemId)
+		return(subclass)
+	end
+end
+function CFO:UpdateItemModsFont()
+	local frame
+	for i = 1, #enchantSlot do
+		frame = _G[("Character%s"):format(enchantSlot[i])]
+		frame.ItemEnchant:FontTemplate(LSM:Fetch("font", E.db.sle.characterframeoptions.itemdurability.font), E.db.sle.characterframeoptions.itemdurability.fontSize, E.db.sle.characterframeoptions.itemdurability.fontOutline)
+	end
+end
+
+function CFO:LoadItemMods()
+	_G["CharacterFrame"]:HookScript("OnShow", function(self)
+		CFO:UpdateItemMods()
+	end)
+
+	self:RegisterEvent("PLAYER_EQUIPMENT_CHANGED", "UpdateItemMods")
+
+	local frame
+	for i = 1, #enchantSlot do
+		frame = _G[("Character%s"):format(enchantSlot[i])]
+		frame.ItemEnchant = frame:CreateFontString(nil, "OVERLAY")
+
+		if frame == CharacterHeadSlot or frame == CharacterNeckSlot or frame == CharacterShoulderSlot or frame == CharacterBackSlot or frame == CharacterChestSlot or frame == CharacterWristSlot or frame == CharacterShirtSlot or frame == CharacterTabardSlot then
+			frame.ItemEnchant:SetPoint("LEFT", frame, "RIGHT", 2, 7)
+		elseif frame == CharacterHandsSlot or frame == CharacterWaistSlot or frame == CharacterLegsSlot or frame == CharacterFeetSlot or frame == CharacterFinger0Slot or frame == CharacterFinger1Slot or frame == CharacterTrinket0Slot or frame == CharacterTrinket1Slot then
+			frame.ItemEnchant:SetPoint("RIGHT", frame, "LEFT", -2, 7)
+		elseif frame == CharacterMainHandSlot or frame == CharacterSecondaryHandSlot or frame == CharacterRangedSlot then
+			frame.ItemEnchant:SetPoint("TOP", frame, "BOTTOM", 0, -3)
+		end
+		frame.ItemEnchant:FontTemplate(LSM:Fetch("font", E.db.sle.characterframeoptions.itemdurability.font), E.db.sle.characterframeoptions.itemdurability.fontSize, E.db.sle.characterframeoptions.itemdurability.fontOutline)
+
+		--frame.EnchantWarning = CreateFrame('Button', nil, frame)
+		--frame.EnchantWarning:Size(12)
+		--frame.EnchantWarning.Texture = frame.EnchantWarning:CreateTexture(nil, 'OVERLAY')
+		--frame.EnchantWarning.Texture:SetInside()
+		--frame.EnchantWarning.Texture:SetTexture('Interface\\AddOns\\ElvUI_SLE\\Media\\Textures\\Warning-Small.tga')
+		--frame.EnchantWarning:Point("LEFT", frame.ItemEnchant, "RIGHT", 3, 0)
+		--frame.EnchantWarning:Hide()
+	end
+end
\ No newline at end of file
diff --git a/ElvUI_SLE/modules/characterframe/load_characterframe.xml b/ElvUI_SLE/modules/characterframe/load_characterframe.xml
index 1df4e7c..b7cc29a 100755
--- a/ElvUI_SLE/modules/characterframe/load_characterframe.xml
+++ b/ElvUI_SLE/modules/characterframe/load_characterframe.xml
@@ -2,5 +2,6 @@
 	<Script file='characterframe.lua'/>
 	<Script file='durability.lua'/>
 	<Script file='itemlevel.lua'/>
+	<Script file='itemmods.lua'/>
 	<Script file='options.lua'/>
 </Ui>
\ No newline at end of file