Added options menu, options for equippable only and debug mode
Salvatore Lopiparo [07-15-16 - 02:23]
Added options menu, options for equippable only and debug mode
diff --git a/CanIMogIt.toc b/CanIMogIt.toc
index b18591b..87040b3 100644
--- a/CanIMogIt.toc
+++ b/CanIMogIt.toc
@@ -6,3 +6,5 @@
## X-Category: Transmogrify
## X-Website: http://mods.curse.com/addons/wow/can-i-mog-it
code.lua
+options.lua
+##SavedVariables: CanIMogItOptions
diff --git a/code.lua b/code.lua
index 937e7e2..4745358 100644
--- a/code.lua
+++ b/code.lua
@@ -4,11 +4,6 @@ CanIMogIt = {}
local dressUpModel = CreateFrame('DressUpModel')
-local DEBUG = false
-
-if DEBUG then
- print("CanIMogIt is in Debug mode.")
-end
-----------------------------
-- Maps --
@@ -143,6 +138,13 @@ CanIMogIt.cachedTooltipText = nil;
-----------------------------
+function CanIMogIt:IsEquippable(itemLink)
+ -- Returns whether the item is equippable or not (exluding bags)
+ local slotName = select(9, GetItemInfo(itemLink))
+ return slotName ~= "" and slotName ~= "INVTYPE_BAG"
+end
+
+
function CanIMogIt:GetSource(itemLink)
local itemID, _, _, slotName = GetItemInfoInstant(itemLink)
local slot = inventorySlotsMap[slotName]
@@ -251,6 +253,12 @@ function CanIMogIt:GetTooltipText(itemLink)
-- Gets the text to display on the tooltip
local text = ""
+ if CanIMogItOptions["showEquippableOnly"] and
+ not CanIMogIt:IsEquippable(itemLink) then
+ -- Don't bother if it's not equipable.
+ return
+ end
+
if CanIMogIt:IsTransmogable(itemLink) then
if CanIMogIt:PlayerKnowsTransmogFromItem(itemLink) then
-- Set text to KNOWN
@@ -288,7 +296,7 @@ local function addToTooltip(tooltip, itemLink)
CanIMogIt.cachedTooltipText = nil
return
end
- if DEBUG then
+ if CanIMogItOptions["debug"] then
printDebug(CanIMogIt.tooltip, itemLink)
end
diff --git a/options.lua b/options.lua
new file mode 100644
index 0000000..49dffad
--- /dev/null
+++ b/options.lua
@@ -0,0 +1,103 @@
+-- Options for CanIMogIt
+--
+-- Thanks to Stanzilla and Semlar and their addon AdvancedInterfaceOptions, which I used as reference.
+
+local _G = _G
+
+CanIMogIt_OptionsVersion = "1.1"
+
+CanIMogItOptions_Defaults = {
+ ["options"] = {
+ ["version"] = CanIMogIt_OptionsVersion,
+ ["debug"] = false,
+ ["showEquippableOnly"] = true,
+ },
+}
+
+
+CanIMogItOptions_DisplayData = {
+ ["debug"] = {
+ ["displayName"] = "Debug",
+ ["description"] = "Enables a detailed display for debug purposes. Use this when sending bug reports.",
+ },
+ ["showEquippableOnly"] = {
+ ["displayName"] = "Show On Equippable Items Only",
+ ["description"] = "When selected, only items that can be equipped will display the Can I Mog It? tooltip."
+ },
+}
+
+
+CanIMogIt.frame = CreateFrame("Frame", "CanIMogItOptionsFrame", UIParent);
+CanIMogIt.frame.name = "Can I Mog It?";
+InterfaceOptions_AddCategory(CanIMogIt.frame);
+CanIMogIt.frame:RegisterEvent("ADDON_LOADED")
+
+CanIMogIt.frame:SetScript("OnEvent", function(self, event, addonName)
+ if event == "ADDON_LOADED" and addonName == "CanIMogIt" then
+ CanIMogIt.frame.Loaded()
+ end
+end)
+
+
+local function checkboxOnClick(self)
+ local checked = self:GetChecked()
+ PlaySound(checked and "igMainMenuOptionCheckBoxOn" or "igMainMenuOptionCheckBoxOff")
+ self:SetValue(checked)
+end
+
+
+local function newCheckbox(parent, variableName)
+ -- Creates a new checkbox in the parent frame for the given variable name
+ local displayData = CanIMogItOptions_DisplayData[variableName]
+ local checkbox = CreateFrame("CheckButton", "CanIMogItCheckbox" .. variableName,
+ parent, "InterfaceOptionsCheckButtonTemplate")
+
+ -- checkbox.value = CanIMogItOptions[variableName]
+
+ checkbox.GetValue = function (self)
+ return CanIMogItOptions[variableName]
+ end
+ checkbox.SetValue = function (self, value) CanIMogItOptions[variableName] = value end
+
+ checkbox:SetScript("OnClick", checkboxOnClick)
+ checkbox:SetChecked(checkbox:GetValue())
+
+ checkbox.label = _G[checkbox:GetName() .. "Text"]
+ checkbox.label:SetText(displayData["displayName"])
+
+ checkbox.tooltipText = displayData["displayName"]
+ checkbox.tooltipRequirement = displayData["description"]
+ return checkbox
+end
+
+
+local function createOptionsMenu()
+ -- define the checkboxes
+ local debug = newCheckbox(CanIMogIt.frame, "debug")
+ local showEquippableOnly = newCheckbox(CanIMogIt.frame, "showEquippableOnly")
+
+ -- position the checkboxes
+ debug:SetPoint("TOPLEFT", 16, -16)
+ showEquippableOnly:SetPoint("TOPLEFT", debug, "BOTTOMLEFT")
+end
+
+
+function CanIMogIt.frame.Loaded()
+ -- Set the Options from defaults.
+ if (not CanIMogItOptions) then
+ CanIMogItOptions = CanIMogItOptions_Defaults.options
+ print("CanIMogItOptions not found, loading defaults!")
+ end
+ -- Set missing options from the defaults if the version is out of date.
+ if (CanIMogItOptions["version"] < CanIMogIt_OptionsVersion) then
+ CanIMogItOptions_temp = CanIMogItOptions_Defaults.options;
+ for k,v in pairs(CanIMogItOptions) do
+ if (CanIMogItOptions_Defaults.options[k]) then
+ CanIMogItOptions_temp[k] = v;
+ end
+ end
+ CanIMogItOptions_temp["version"] = CanIMogIt_OptionsVersion;
+ CanIMogItOptions = CanIMogItOptions_temp;
+ end
+ createOptionsMenu()
+end