Quantcast

key toggle, first approach

Alex Shubert [03-21-12 - 20:27]
key toggle, first approach
Filename
AutoTurnIn.lua
AutoTurnIn.toc
options.lua
diff --git a/AutoTurnIn.lua b/AutoTurnIn.lua
index 74d5121..47b87c7 100644
--- a/AutoTurnIn.lua
+++ b/AutoTurnIn.lua
@@ -1,25 +1,20 @@
 local addonName, ptable = ...
 local L = ptable.L
-local AutoTurnInCharacterDB, AutoTurnInDB
 AutoTurnIn = LibStub("AceAddon-3.0"):NewAddon("AutoTurnIn", "AceEvent-3.0", "AceConsole-3.0")

-AutoTurnIn.defaults = {enabled = true, all = false, dontloot = true, tournament = 2, darkmoonteleport=true}
+AutoTurnIn.defaults = {enabled = true, all = false, dontloot = true, tournament = 2, darkmoonteleport=true, togglekey=1}

 -- quest autocomplete handlers and functions
 function AutoTurnIn:OnEnable()
-	AutoTurnInDB = _G.AutoTurnInDB
-	AutoTurnInCharacterDB = _G.AutoTurnInCharacterDB
 	local vers = GetAddOnMetadata(addonName, "Version")

 	if (not AutoTurnInDB) or (not AutoTurnInDB.version or (AutoTurnInDB.version < vers)) then
 		AutoTurnInCharacterDB = nil
 		_G.AutoTurnInDB = {version = vers}
-		AutoTurnInDB = _G.AutoTurnInDB
 		self:Print(L["reset"])
 	end
 	if not AutoTurnInCharacterDB then
-		_G.AutoTurnInCharacterDB = CopyTable(AutoTurnIn.defaults)
-		AutoTurnInCharacterDB = _G.AutoTurnInCharacterDB
+		_G.AutoTurnInCharacterDB = CopyTable(AutoTurnIn.defaults)
 	end
 	if AutoTurnInCharacterDB.enabled then
 		self:RegisterGossipEvents()
diff --git a/AutoTurnIn.toc b/AutoTurnIn.toc
index 1aa0707..1cfd0e8 100644
--- a/AutoTurnIn.toc
+++ b/AutoTurnIn.toc
@@ -1,6 +1,6 @@
 ## Interface: 40300
 ## Title: AutoTurnIn
-## Version: 2.1
+## Version: 2.2
 ## Author: Lur
 ## Notes: Auto accept and complete daily or any quests
 ## Notes-ruRU: Автоматически принимает и сдает ежедневные либо все задания
diff --git a/options.lua b/options.lua
index f33d9a5..437cd4c 100644
--- a/options.lua
+++ b/options.lua
@@ -19,11 +19,6 @@ local Enable = CreateFrame("CheckButton", O.."Enable", OptionsPanel, "OptionsChe
 _G[O.."EnableText"]:SetText(L["enabled"])
 Enable:SetScript("OnClick", function(self)
 	TempConfig.enabled = self:GetChecked() == 1
-	if (TempConfig.enabled) then
-		AutoTurnIn:RegisterGossipEvents()
-	else
-		AutoTurnIn:UnregisterAllEvents()
-	end
 end)

 -- Quest types to handle
@@ -95,13 +90,33 @@ DarkMoonCannon:SetScript("OnClick", function(self)
 	TempConfig.darkmoonteleport = self:GetChecked() == 1
 end)

--- 'Enable' CheckBox
+-- 'Show Reward Text' CheckBox
 local ShowRewardText = CreateFrame("CheckButton", O.."Reward", OptionsPanel, "OptionsCheckButtonTemplate")
 _G[ShowRewardText:GetName().."Text"]:SetText(L["rewardtext"])
 ShowRewardText:SetScript("OnClick", function(self)
 	TempConfig.showrewardtext = self:GetChecked() == 1
 end)

+-- Auto toggle key
+local ToggleKeyLabel = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
+ToggleKeyLabel:SetText("Toggle AutoTurnIn key")
+local ToggleKeyConst = {NONE_KEY,ALT_KEY,CTRL_KEY,SHIFT_KEY}
+local ToggleKeyDropDown = CreateFrame("Frame", O.."ToggleKeyDropDown", OptionsPanel, "UIDropDownMenuTemplate")
+UIDropDownMenu_Initialize(ToggleKeyDropDown, function (self, level)
+    for k, v in ipairs(ToggleKeyConst) do
+        local info = UIDropDownMenu_CreateInfo()
+		info.text, info.value = v, k
+        info.func = function(self)
+						UIDropDownMenu_SetSelectedID(ToggleKeyDropDown, self:GetID())
+						TempConfig.togglekey = self:GetID()
+					end
+        UIDropDownMenu_AddButton(info, level)
+    end
+end)
+UIDropDownMenu_SetWidth(ToggleKeyDropDown, 200);
+UIDropDownMenu_JustifyText(ToggleKeyDropDown, "LEFT")
+
+
 -- Control placement
 title:SetPoint("TOPLEFT", 16, -16)
 subText:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
@@ -115,6 +130,9 @@ TournamentDropDown:SetPoint("TOPLEFT", LootDropDown, "TOPRIGHT", 17, 0)
 DarkMoonCannon:SetPoint("TOPLEFT", LootDropDown, "BOTTOMLEFT", 16, -16)
 ShowRewardText:SetPoint("TOPLEFT", DarkMoonCannon, "BOTTOMLEFT", 0, -16)

+ToggleKeyLabel:SetPoint("BOTTOMLEFT", ToggleKeyDropDown, "TOPLEFT", 18, 0)
+ToggleKeyDropDown:SetPoint("TOPLEFT", ShowRewardText, "BOTTOMLEFT", -15, -30)
+
 OptionsPanel.refresh = function()
 	TempConfig = CopyTable(AutoTurnInCharacterDB)

@@ -133,6 +151,10 @@ OptionsPanel.refresh = function()
 	end
 	DarkMoonCannon:SetChecked(TempConfig.darkmoonteleport)
 	ShowRewardText:SetChecked(TempConfig.showrewardtext)
+
+	UIDropDownMenu_SetSelectedID(ToggleKeyDropDown, TempConfig.togglekey)
+	UIDropDownMenu_SetText(ToggleKeyDropDown,  ToggleKeyConst[TempConfig.togglekey])
+
 end

 OptionsPanel.default = function()
@@ -140,6 +162,13 @@ OptionsPanel.default = function()
 end

 OptionsPanel.okay = function()
+	if (AutoTurnInCharacterDB.enabled ~= TempConfig.enabled) then
+		if TempConfig.enabled then
+			AutoTurnIn:RegisterGossipEvents()
+		else
+			AutoTurnIn:UnregisterAllEvents()
+		end
+	end
 	AutoTurnInCharacterDB = CopyTable(TempConfig)
 end