Quantcast

Merge branch 'master' of git.curseforge.net:wow/autoturnin/mainline

Alex Shubert [10-14-14 - 19:25]
Merge branch 'master' of git.curseforge.net:wow/autoturnin/mainline
Filename
AutoTurnIn.lua
AutoTurnIn.toc
QuestLevel.lua
loc/localization_DE.lua
loc/localization_EN.lua
loc/localization_FR.lua
loc/localization_RU.lua
ui/main_options.lua
diff --git a/AutoTurnIn.lua b/AutoTurnIn.lua
index 9c3b920..5bea4ea 100644
--- a/AutoTurnIn.lua
+++ b/AutoTurnIn.lua
@@ -9,9 +9,12 @@ local addonName, ptable = ...
 local L = ptable.L
 local C = ptable.CONST
 local TOCVersion = GetAddOnMetadata(addonName, "Version")
+local Q_ALL, Q_DAILY, Q_EXCEPTDAILY = 1, 2, 3
+

 AutoTurnIn = LibStub("AceAddon-3.0"):NewAddon("AutoTurnIn", "AceEvent-3.0", "AceConsole-3.0")
-AutoTurnIn.defaults = {enabled = true, all = false, trivial = false, lootreward = 1, tournament = 2,
+AutoTurnIn.defaults = {enabled = true, all = 2, trivial = false, completeonly = false,
+                       lootreward = 1, tournament = 2,
 					   darkmoonteleport=true, todarkmoon=true, togglekey=4, darkmoonautostart=true, showrewardtext=true,
 					   version=TOCVersion, autoequip = false, debug=false,
 					   questlevel=true, watchlevel=true, questshare=false,
@@ -57,7 +60,7 @@ end
 -- quest autocomplete handlers and functions
 function AutoTurnIn:OnEnable()
 	if (not AutoTurnInCharacterDB) or (not AutoTurnInCharacterDB.version or (AutoTurnInCharacterDB.version < TOCVersion)) then
-		AutoTurnInCharacterDB = nil
+        AutoTurnInCharacterDB = nil
 		self:Print(L["reset"])
 	end

@@ -107,6 +110,7 @@ function AutoTurnIn:RegisterGossipEvents()
 	self:RegisterEvent("QUEST_PROGRESS")
 	self:RegisterEvent("QUEST_COMPLETE")
 	self:RegisterEvent("QUEST_LOG_UPDATE")
+	self:RegisterEvent("QUEST_ACCEPTED")
 end

 function AutoTurnIn:QUEST_LOG_UPDATE()
@@ -121,18 +125,30 @@ function AutoTurnIn:QUEST_LOG_UPDATE()
 	end
 end

--- returns true if quest offered by gossip is daily
-function AutoTurnIn:AllOrCachedDaily(questname)
-	return AutoTurnInCharacterDB.all or (not not self.questCache[questname])
+-- Available check requires cache
+-- Active check query API function Returns true if quest matches options
+function AutoTurnIn:isAppropriate(questname, byCache)
+    local daily
+    if byCache then
+        daily = (not not self.questCache[questname])
+    else
+        daily = (QuestIsDaily() or QuestIsWeekly())
+    end
+    return self:_isAppropriate(daily)
 end

-function AutoTurnIn:AllOrDaily(questname)
-	return AutoTurnInCharacterDB.all or (QuestIsDaily() or QuestIsWeekly())
+-- 'private' function
+function AutoTurnIn:_isAppropriate(daily)
+    if daily then
+        return (AutoTurnInCharacterDB.all ~= Q_EXCEPTDAILY)
+    else
+        return (AutoTurnInCharacterDB.all ~= Q_DAILY)
+    end
 end

 -- caches offered by gossip quest as daily
-function AutoTurnIn:CacheAsDaily(gossipQuest)
-	self.questCache[gossipQuest] = true
+function AutoTurnIn:CacheAsDaily(questname)
+	self.questCache[questname] = true
 end

 function AutoTurnIn:IsIgnoredQuest(quest)
@@ -149,8 +165,6 @@ function AutoTurnIn:IsIgnoredQuest(quest)
 	return false
 end

-local p1 = {[true]=L["enabled"], [false]=L["disabled"]}
-local p2 = {[true]=L["all"], [false]=L["list"]}
 function AutoTurnIn:ConsoleComand(arg)
 	arg = strlower(arg)
 	if (#arg == 0) then
@@ -193,32 +207,34 @@ function AutoTurnIn:QUEST_GREETING()

 	for index=1, GetNumActiveQuests() do
 		local quest, isComplete = GetActiveTitle(index)
-		if isComplete and (self:AllOrCachedDaily(quest)) then
+		if isComplete and (self:isAppropriate(quest, true)) then
 			SelectActiveQuest(index)
 		end
 	end

-	for index=1, GetNumAvailableQuests() do
-		local isTrivial, isDaily, isRepeatable = GetAvailableQuestInfo(index)
-		local triviaAndAllowedOrNotTrivia = (not isTrivial) or AutoTurnInCharacterDB.trivial
-		local title = GetAvailableTitle(index)
-		local quest = L.quests[title]
-		local notBlackListed = not (quest and (quest.donotaccept or AutoTurnIn:IsIgnoredQuest(title)))
-
-		if isDaily then
-			self:CacheAsDaily(GetAvailableTitle(index))
-		end
-
-		if (triviaAndAllowedOrNotTrivia and notBlackListed and (AutoTurnInCharacterDB.all or isDaily)) then
-			if quest and quest.amount then
-				if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
-					SelectAvailableQuest(index)
-				end
-			else
-				SelectAvailableQuest(index)
-			end
-		end
-	end
+    if not AutoTurnInCharacterDB.completeonly then
+        for index=1, GetNumAvailableQuests() do
+            local isTrivial, isDaily, isRepeatable = GetAvailableQuestInfo(index)
+            local triviaAndAllowedOrNotTrivia = (not isTrivial) or AutoTurnInCharacterDB.trivial
+            local title = GetAvailableTitle(index)
+            local quest = L.quests[title]
+            local notBlackListed = not (quest and (quest.donotaccept or AutoTurnIn:IsIgnoredQuest(title)))
+
+            if isDaily then
+                self:CacheAsDaily(GetAvailableTitle(index))
+            end
+
+            if (triviaAndAllowedOrNotTrivia and notBlackListed and self:_isAppropriate(isDaily)) then
+                if quest and quest.amount then
+                    if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
+                        SelectAvailableQuest(index)
+                    end
+                else
+                    SelectAvailableQuest(index)
+                end
+            end
+        end
+    end
 end

 -- (gaq[i+3]) equals "1" if quest is complete, "nil" otherwise
@@ -231,7 +247,7 @@ function AutoTurnIn:VarArgForActiveQuests(...)
 		local isComplete = select(i+3, ...) -- complete status
 		if ( isComplete ) then
 			local questname = select(i, ...)
-			if self:AllOrCachedDaily(questname) then
+			if self:isAppropriate(questname, true) then
 				local quest = L.quests[questname]
 				if quest and quest.amount then
 					if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
@@ -260,7 +276,7 @@ function AutoTurnIn:VarArgForAvailableQuests(...)
 		local notBlackListed = not (quest and (quest.donotaccept or AutoTurnIn:IsIgnoredQuest(title)))

 		-- Quest is appropriate if: (it is trivial and trivial are accepted) and (any quest accepted or (it is daily quest that is not in ignore list))
-		if (triviaAndAllowedOrNotTrivia and notBlackListed and (AutoTurnInCharacterDB.all or isDaily )) then
+		if (triviaAndAllowedOrNotTrivia and notBlackListed and self:_isAppropriate(isDaily)) then
 			if quest and quest.amount then
 				if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
 					SelectGossipAvailableQuest(math.floor(i/MOP_INDEX_CONST)+1)
@@ -304,7 +320,9 @@ function AutoTurnIn:GOSSIP_SHOW()
 	local questCount = GetNumGossipActiveQuests() > 0

 	self:VarArgForActiveQuests(GetGossipActiveQuests())
-	self:VarArgForAvailableQuests(GetGossipAvailableQuests())
+    if not AutoTurnInCharacterDB.completeonly then
+	    self:VarArgForAvailableQuests(GetGossipAvailableQuests())
+    end

 	if self:isDarkmoonAndAllowed(questCount) then
 		local options = {GetGossipOptions()}
@@ -330,8 +348,8 @@ function AutoTurnIn:QUEST_DETAIL()
 	if (QuestIsDaily() or QuestIsWeekly()) then
 		self:CacheAsDaily(GetTitleText())
 	end
-
-	if self:AllowedToHandle() and self:AllOrDaily() then
+
+	if self:AllowedToHandle() and self:isAppropriate() and (not AutoTurnInCharacterDB.completeonly)then
 		QuestInfoDescriptionText:SetAlphaGradient(0, -1)
 		QuestInfoDescriptionText:SetAlpha(1)
 		AcceptQuest()
@@ -346,8 +364,8 @@ function AutoTurnIn:QUEST_ACCEPTED(event, index)
 end

 function AutoTurnIn:QUEST_PROGRESS()
-    if  self:AllowedToHandle() and IsQuestCompletable() and self:AllOrDaily() then
-		CompleteQuest()
+    if  self:AllowedToHandle() and IsQuestCompletable() and self:isAppropriate() then
+        CompleteQuest()
     end
 end

@@ -456,7 +474,7 @@ function AutoTurnIn:TurnInQuest(rewardIndex)
 		elseif (GetNumQuestChoices() == 0) then
 			self:Print("Debug: turning quest in, no choice required")
 		end
-	else
+    else
 		GetQuestReward(rewardIndex)
 	end
 end
@@ -506,7 +524,7 @@ function AutoTurnIn:Need()
 			self:Print(L["stopitemfound"]:format(_G[equipSlot]))
 			return true
 		end
-		local itemCandidate = {index=i, points=0, type="", stat="NOTCHOSEN", secondary={}}
+		local itemCandidate = {index=i, points=0, type="", stat="", secondary={}} --DEBUG structure

 		-- TYPE: item is suitable if there are no type specified at all or item type is chosen
 		local OkByType = false
@@ -520,23 +538,30 @@ function AutoTurnIn:Need()
 		itemCandidate.type=subclass .. ((not not OkByType) and "=>OK" or "=>FAIL")

 		--STAT+SECONDARY: Same here: if no stat specified or item stat is chosen then item is wanted
-		local OkByStat = not next(AutoTurnInCharacterDB.stat) 					-- true if table is empty
+		local OkByStat = not next(AutoTurnInCharacterDB.stat) 			-- true if table is empty
 		local OkBySecondary = not next(AutoTurnInCharacterDB.secondary) -- true if table is empty
 		if (not (OkByStat and OkBySecondaryStat)) then
 			wipe(self.stattable)
 			GetItemStats(link, self.stattable)
+            local count = 0
 			for stat, value in pairs(self.stattable) do
+                count = count + 1
 				if ( AutoTurnInCharacterDB.stat[stat] ) then
 					OkByStat = true
-					itemCandidate.stat=_G[stat].."=>OK"
+					itemCandidate.stat = _G[stat].. "=>OK"
 				end
 				if ( AutoTurnInCharacterDB.secondary[stat] ) then
 					OkBySecondary = true
 					itemCandidate.points =  itemCandidate.points + 1
 					tinsert(itemCandidate.secondary, _G[stat])
 				end
-			end
-		end
+            end
+            if (count == 1) then -- Common quality items have only 1 attribute. This 'if' makes them suitable loot candidates.
+                OkByStat, OkBySecondary = true, true
+            end
+        else
+            itemCandidate.stat = "NO_STAT_SETTINGS"
+        end

 		-- User may not choose any options hence any item became 'ok'. That situation is undoubtly incorrect.
 		local SettingsExists = (class == C.WEAPONLABEL and next(AutoTurnInCharacterDB.weapon) or next(AutoTurnInCharacterDB.armor))
@@ -588,7 +613,7 @@ function AutoTurnIn:QUEST_COMPLETE()

 	--/script faction = (GameTooltip:NumLines() > 2 and not UnitIsPlayer(select(2,GameTooltip:GetUnit()))) and
     -- getglobal("GameTooltipTextLeft"..GameTooltip:NumLines()):GetText() DEFAULT_CHAT_FRAME:AddMessage(faction or "NIL")
-    if self:AllOrDaily() then
+    if self:isAppropriate() then
 		local questname = GetTitleText()
 		local quest = L.quests[questname]

@@ -624,4 +649,4 @@ end
 hooksecurefunc(QuestFrame, "Hide", function() AutoTurnIn.allowed = nil end)
 -- if (GetItemCount(45724, false) > 0) then
 	-- UseItemByName(45724)
--- end
\ No newline at end of file
+-- end
diff --git a/AutoTurnIn.toc b/AutoTurnIn.toc
index 77cbcb7..03dc778 100644
--- a/AutoTurnIn.toc
+++ b/AutoTurnIn.toc
@@ -1,6 +1,6 @@
 ## Interface: 50400
 ## Title: AutoTurnIn
-## Version: 4.3
+## Version: 4.4
 ## Author: Alex Shubert
 ## Notes: Quest handling automation
 ## Notes-ruRU: Автоматически обработка заданий
diff --git a/QuestLevel.lua b/QuestLevel.lua
index 989dce1..2ee4653 100644
--- a/QuestLevel.lua
+++ b/QuestLevel.lua
@@ -46,7 +46,7 @@ function AutoTurnIn:ShowQuestLevelInWatchFrame()
 	end

 	for i = 1, #WATCHFRAME_LINKBUTTONS do
-		button = WATCHFRAME_LINKBUTTONS[i]
+		local button = WATCHFRAME_LINKBUTTONS[i]

 		if( button.type == "QUEST" ) then
 			local questIndex = GetQuestIndexForWatch(button.index)
@@ -55,7 +55,7 @@ function AutoTurnIn:ShowQuestLevelInWatchFrame()
 				if textLine.text:GetText() and (not string.find("", "^%[.*%].*")) then
 					local title, level, _, _, _, _, _, isDaily = GetQuestLogTitle(questIndex)
 					local questTypeIndex = GetQuestLogQuestType(questIndex)
-					tagString = AutoTurnIn.QuestTypesIndex[questTypeIndex]
+					local tagString = AutoTurnIn.QuestTypesIndex[questTypeIndex]
 					if (not tagString) then
 						--AutoTurnIn:Print("Please, inform addon author unknown QT for: " ..title)
 						tagString = ""
diff --git a/loc/localization_DE.lua b/loc/localization_DE.lua
index 2593465..ffbe384 100644
--- a/loc/localization_DE.lua
+++ b/loc/localization_DE.lua
@@ -15,16 +15,18 @@ privateTable.L = setmetatable({

 	["questTypeLabel"] = "quests",
 	["questTypeAll"] = "alle",
-	["TrivialQuests"]="'graue' Quests annehmen",
-	["questTypeList"] = "Tägliche Quests",
+    ["questTypeList"] = "Tägliche",
+    ["questTypeExceptDaily"] = "außer Tägliche",
+    ["TrivialQuests"]="'graue' Quests annehmen",
 	["ShareQuestsLabel"] = "teilen die Quest",
+    ["CompleteOnly"] = "zurückliefern bloß",

 	["lootTypeLabel"]="Jobs mit Belohnungen",
 	["lootTypeFalse"]="nicht abgeben",
 	["lootTypeGreed"]="Teuerste Belohnung wählen",
 	["lootTypeNeed"]="Wähle Belohnung nach Parametern",

-	["tournamentLabel"]="Turnier",
+	["tournamentLabel"]="Das Argentumturnier",
 	["tournamentWrit"]="Verfügung des Champions", -- 46114
 	["tournamentPurse"]="Geldbeutel des Champions",  -- 45724

@@ -157,7 +159,6 @@ privateTable.L.quests = {
 ["Spaß für die Kleinen"] = {item=393, amount=15, currency=true},
 --MoP
 ["Saat der Angst"]={item="Schreckensambersplitter", amount=5, currency=false},
-["Auffüllen der Speisekammer"]={item="Bündel mit Zutaten", amount=1, currency=false},
 ["Ein Gericht für Jogu"]={item="Gebratene Karotten", amount=5, currency=false},

 ["Garnelenklößchen"]={item="Garnelenklößchen", amount=5, currency=false},
diff --git a/loc/localization_EN.lua b/loc/localization_EN.lua
index 15cefe3..54a0ab9 100644
--- a/loc/localization_EN.lua
+++ b/loc/localization_EN.lua
@@ -6,6 +6,7 @@ local replaceTable = {
 		["esES"]=true,
 		["esMX"]=true,
 		["zhTW"]=true,
+		["ptBR"]=true,
 		["zhCN"]=true }

 if (replaceTable[GetLocale()])  then
@@ -19,18 +20,20 @@ privateTable.L = setmetatable({
 	["dontloottrue"]="do not complete quests with rewards",
 	["resetbutton"]="reset",

-	["questTypeLabel"] = "Quests to handle",
+	["questTypeLabel"] = "quests to handle",
 	["questTypeAll"] = "all",
-	["TrivialQuests"]="Accept 'grey' quests",
-	["questTypeList"] = "daily",
-	["ShareQuestsLabel"] = "Quest auto sharing",
+    ["questTypeList"] = "daily",
+    ["questTypeExceptDaily"] = "except daily",
+    ["TrivialQuests"]="Accept 'grey' quests",
+	["ShareQuestsLabel"] = "quest auto sharing",
+    ["CompleteOnly"] = "turn in only",

-	["lootTypeLabel"]="Quests with rewards",
+	["lootTypeLabel"]="quests with rewards",
 	["lootTypeFalse"]="don't turn in",
 	["lootTypeGreed"]="loot most expensive reward",
 	["lootTypeNeed"]="loot by parameters",

-	["tournamentLabel"]="Tournament",
+	["tournamentLabel"]="Argent Tournament",
 	["tournamentWrit"]="Champion's Writ", -- 46114
 	["tournamentPurse"]="Champion's Purse",  -- 45724

@@ -39,11 +42,11 @@ privateTable.L = setmetatable({
 	["DarkmoonFaireTeleport"]="Teleportologist Fozlebub",
 	["DarkmoonAutoLabel"]="Darkmoon: start the game!",

-	["rewardtext"]="Print quest competition text",
-	["questlevel"]="Show quest level",
-	["watchlevel"]="Show watched quest level",
-	["autoequip"]="Equip received reward",
-	["togglekey"]="Enable/disable key",
+	["rewardtext"]="print quest competition text",
+	["questlevel"]="show quest level",
+	["watchlevel"]="show watched quest level",
+	["autoequip"]="equip received reward",
+	["togglekey"]="enable/disable key",

 	['Jewelry']="Jewelry",
 	["rewardlootoptions"]="Reward loot rules",
@@ -146,7 +149,6 @@ privateTable.L.quests = {
 ["Fun for the Little Ones"] = {item=393, amount=15, currency=true},
 --MoP
 ["Seeds of Fear"]={item="Dread Amber Shards", amount=5, currency=false},
-["Replenishing the Pantry"]={item="Bundle of Groceries", amount=1, currency=false},
 ["A Dish for Jogu"]={item="Sauteed Carrots", amount=5, currency=false},

 ["A Dish for Ella"]={item="Shrimp Dumplings", amount=5, currency=false},
diff --git a/loc/localization_FR.lua b/loc/localization_FR.lua
index edd6c26..a3858b8 100644
--- a/loc/localization_FR.lua
+++ b/loc/localization_FR.lua
@@ -13,16 +13,18 @@ privateTable.L = setmetatable({

     ["questTypeLabel"] = "Quêtes à prendre en compte",
     ["questTypeAll"] =  "Toutes",
+    ["questTypeList"] = "journalières",
+    ["questTypeExceptDaily"] = "excepté journalières",
     ["TrivialQuests"]= "Accepter les quêtes 'grise'",
-    ["questTypeList"] = "Quêtes journalières",
 	["ShareQuestsLabel"] = "partager la quête",
+    ["CompleteOnly"] = "turn in only",

     ["lootTypeLabel"]="Quêtes à récompense d'objet",
     ["lootTypeFalse"]="Ne pas rendre",
     ["lootTypeGreed"]="Vhoisir la récompense la plus chère",
     ["lootTypeNeed"]="choisir la récompense selon les paramètres",

-    ["tournamentLabel"]="Tournoi d'argent",
+    ["tournamentLabel"]="Le tournoi d'Argent",
     ["tournamentWrit"]="Commission de champion", -- 46114
     ["tournamentPurse"]="Bourse de champion",  -- 45724

@@ -152,7 +154,6 @@ privateTable.L.quests = {
 ["Les petits s'amusent aussi"] = {item=393, amount=15, currency=true},
 --MoP
 ["Les graines de la peur"]={item="Eclats d’ambre d’effroi", amount=5, currency=false},
-["Remplir le garde-manger"]={item="Panier de vivres", amount=1, currency=false},
 ["Un plat pour Jogu"]={item="Carottes sautées", amount=5, currency=false},

 ["Un plat pour Ella"]={item="Raviolis aux crevettes", amount=5, currency=false},
diff --git a/loc/localization_RU.lua b/loc/localization_RU.lua
index 82392f5..ea838e0 100644
--- a/loc/localization_RU.lua
+++ b/loc/localization_RU.lua
@@ -15,9 +15,11 @@ privateTable.L = setmetatable({

 	["questTypeLabel"] = "задания",
 	["questTypeAll"] = "все",
-	["TrivialQuests"]="брать 'серые' квесты",
-	["questTypeList"] = "ежедневные",
+    ["questTypeList"] = "ежедневные",
+    ["questTypeExceptDaily"] = "кроме ежедневных",
+    ["TrivialQuests"]="брать 'серые' квесты",
 	["ShareQuestsLabel"] = "Предлагать задание группе",
+    ["CompleteOnly"] = "только завершать",

 	["lootTypeLabel"]="задания с наградами",
 	["lootTypeFalse"]="не сдавать",
diff --git a/ui/main_options.lua b/ui/main_options.lua
index 53a9b91..5119f37 100644
--- a/ui/main_options.lua
+++ b/ui/main_options.lua
@@ -4,206 +4,114 @@ local O = addonName .. "OptionsPanel"
 AutoTurnIn.OptionsPanel = CreateFrame("Frame", O)
 AutoTurnIn.OptionsPanel.name=addonName
 local OptionsPanel = AutoTurnIn.OptionsPanel
-
+-- switch flag. 'false' signals that reset must be made. 'true' allows redraw the screen keeping values
 local MakeACopy=true

 -- Title
 local title = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
 title:SetText(addonName .." ".. AutoTurnIn.defaults.version)
+
 -- Description
 local notes = GetAddOnMetadata(addonName, "Notes-" .. GetLocale()) or GetAddOnMetadata(addonName, "Notes")
 local subText = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
 subText:SetText(notes)
+
 -- Reset button
 local ResetButton = CreateFrame("Button", nil, OptionsPanel, "OptionsButtonTemplate")
 ResetButton:SetText(L["resetbutton"])
 ResetButton:SetScript("OnClick", function()
 	ptable.TempConfig = CopyTable(AutoTurnIn.defaults)
-
 	MakeACopy=false;
 	AutoTurnIn.RewardPanel.refresh();
 	AutoTurnIn.OptionsPanel.refresh();
 end)

-local function CreateCheckbox(name, marginx, marginy)
-	local nm = O..name
-	local cb = CreateFrame("CheckButton", nm,  OptionsPanel, "OptionsCheckButtonTemplate")
-	_G[nm.."Text"]:SetText(L[name])
-	cb:SetPoint("TOPLEFT", OptionsPanel, "BOTTOMLEFT", marginx, marginy)
-
-	cb:SetScript("OnClick", function(self)
-		ptable.TempConfig[name] = self:GetChecked() == 1
-	end)
-	return cb
+local function newCheckbox(name, caption, config)
+    local cb = CreateFrame("CheckButton", "$parent"..name, OptionsPanel, "OptionsCheckButtonTemplate")
+    _G[cb:GetName().."Text"]:SetText(caption and caption or name)
+    cb:SetScript("OnClick", function(self)
+        ptable.TempConfig[config] = self:GetChecked() == 1
+    end)
+    return cb
 end

--- 'Enable' CheckBox
-local Enable = CreateCheckbox("enabled", 0, -14)
-
--- Quest types to handle
-local QuestLabel = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
-QuestLabel:SetText(L["questTypeLabel"])
-local QuestConst = {L["questTypeAll"], L["questTypeList"]}
-local QuestDropDown = CreateFrame("Frame", O.."QuestDropDown", OptionsPanel, "UIDropDownMenuTemplate")
-UIDropDownMenu_Initialize(QuestDropDown, function (self, level)
-    for k, v in ipairs(QuestConst) do
-        local info = UIDropDownMenu_CreateInfo()
-        info.text, info.value = v, k
-        info.func = function(self)
-						UIDropDownMenu_SetSelectedID(QuestDropDown, self:GetID())
-						ptable.TempConfig.all = (self:GetID() == 1)
-					end
-        UIDropDownMenu_AddButton(info, level)
-    end
-end)
-UIDropDownMenu_SetWidth(QuestDropDown, 200);
-UIDropDownMenu_JustifyText(QuestDropDown, "LEFT")
-
--- DarkmoonTeleport
-local TrivialQuests = CreateFrame("CheckButton", O.."TrivialQuests", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[TrivialQuests:GetName().."Text"]:SetText(L["TrivialQuests"])
-TrivialQuests:SetScript("OnClick", function(self)
-	ptable.TempConfig.trivial = self:GetChecked() == 1
-end)
-
--- Tournament loot type
-local TournamentDropDownLabel = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
-TournamentDropDownLabel:SetText(L["tournamentLabel"])
-local TournamentConst = {L["tournamentWrit"], L["tournamentPurse"]};
-local TournamentDropDown = CreateFrame("Frame", O.."TournamentDropDown", OptionsPanel, "UIDropDownMenuTemplate")
-function TournamentDropDown:initialize ()
-    for k, v in ipairs(TournamentConst) do
-        local info = UIDropDownMenu_CreateInfo()
-        info.text, info.value = v, k
-        info.func = function(self)
-						UIDropDownMenu_SetSelectedID(TournamentDropDown, self:GetID())
-						ptable.TempConfig.tournament = self:GetID()
-					end
-        UIDropDownMenu_AddButton(info, level)
-    end
+local function newDropDown(caption, name, values, config)
+    local label = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
+    label:SetText(caption)
+
+    local dropDown = CreateFrame("Frame", O..name, OptionsPanel, "UIDropDownMenuTemplate")
+    UIDropDownMenu_Initialize(dropDown, function (self, level)
+        for k, v in ipairs(values) do
+            local info = UIDropDownMenu_CreateInfo()
+            info.text, info.value = v, k
+            info.func = function(self)
+                UIDropDownMenu_SetSelectedID(dropDown, self:GetID())
+                ptable.TempConfig[config] = self:GetID()
+            end
+            UIDropDownMenu_AddButton(info, level)
+        end
+    end)
+    UIDropDownMenu_SetWidth(dropDown, 200);
+    UIDropDownMenu_JustifyText(dropDown, "LEFT")
+    label:SetPoint("BOTTOMLEFT", dropDown, "TOPLEFT", 18, 0)
+    return dropDown
 end
-UIDropDownMenu_SetWidth(TournamentDropDown, 200);
-UIDropDownMenu_JustifyText(TournamentDropDown, "LEFT")
-
--- How to loot
-local LootLabel = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
-LootLabel:SetText(L["lootTypeLabel"])
-local LootConst = {L["lootTypeFalse"], L["lootTypeGreed"], L["lootTypeNeed"]}
-local LootDropDown = CreateFrame("Frame", O.."LootDropDown", OptionsPanel, "UIDropDownMenuTemplate")
-UIDropDownMenu_Initialize(LootDropDown, function (self, level)
-    for k, v in ipairs(LootConst) do
-        local info = UIDropDownMenu_CreateInfo()
-		info.text, info.value = v, k
-        info.func = function(self)
-						UIDropDownMenu_SetSelectedID(LootDropDown, self:GetID())
-						ptable.TempConfig.lootreward = self:GetID()
-					end
-        UIDropDownMenu_AddButton(info, level)
-    end
-end)
-UIDropDownMenu_SetWidth(LootDropDown, 200);
-UIDropDownMenu_JustifyText(LootDropDown, "LEFT")
-
--- Teleport to Darkmoon Faire
-local ToDarkMoon= CreateFrame("CheckButton", O.."ToDarkMoon", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[O.."ToDarkMoonText"]:SetText(L["ToDarkmoonLabel"])
-ToDarkMoon:SetScript("OnClick", function(self)
-	ptable.TempConfig.todarkmoon = self:GetChecked() == 1
-end)

+-- 'Enable' CheckBox
+local Enable = newCheckbox("enabled", L["enabled"], "enabled")
+-- trivial, so called grayed quests
+local TrivialQuests = newCheckbox("TrivialQuests", L["TrivialQuests"], "trivial")
+-- Only hand in the quest
+local CompleteOnly = newCheckbox("CompleteOnly", L["CompleteOnly"], "completeonly")
 -- DarkmoonTeleport
-local DarkMoonCannon = CreateFrame("CheckButton", O.."DarkMoonCannon", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[O.."DarkMoonCannonText"]:SetText(L["DarkmoonTeleLabel"])
-DarkMoonCannon:SetScript("OnClick", function(self)
-	ptable.TempConfig.darkmoonteleport = self:GetChecked() == 1
-end)
-
+local ToDarkMoon = newCheckbox("ToDarkMoon", L["ToDarkmoonLabel"], "todarkmoon")
+-- Darkmoon Teleport to cannon
+local DarkMoonCannon = newCheckbox("DarkMoonCannon", L["DarkmoonTeleLabel"], "darkmoonteleport")
 -- Darkmoon games
-local DarkMoonAutoStart = CreateFrame("CheckButton", O.."DarkMoonAutoStart", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[DarkMoonAutoStart:GetName().."Text"]:SetText(L["DarkmoonAutoLabel"])
-DarkMoonAutoStart:SetScript("OnClick", function(self)
-	ptable.TempConfig.darkmoonautostart = self:GetChecked() == 1
-end)
-
+local DarkMoonAutoStart = newCheckbox("DarkMoonAutoStart", L["DarkmoonAutoLabel"], "darkmoonautostart")
 -- 'Show Reward Text' CheckBox
-local ShowRewardText = CreateFrame("CheckButton", O.."Reward", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[ShowRewardText:GetName().."Text"]:SetText(L["rewardtext"])
-ShowRewardText:SetScript("OnClick", function(self)
-	ptable.TempConfig.showrewardtext = self:GetChecked() == 1
-end)
-
--- 'Equip Reward Text' CheckBox
-local EquipReward = CreateFrame("CheckButton", O.."Equip", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[EquipReward:GetName().."Text"]:SetText(L["autoequip"])
-EquipReward:SetScript("OnClick", function(self)
-	ptable.TempConfig.autoequip = self:GetChecked() == 1
-end)
-
--- 'Equip Reward Text' CheckBox
-local Debug = CreateFrame("CheckButton", O.."Debug", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[Debug:GetName().."Text"]:SetText(L["debug"])
-Debug:SetScript("OnClick", function(self)
-	ptable.TempConfig.debug = self:GetChecked() == 1
-end)
-
-local ShareQuests = CreateFrame("CheckButton", O.."ShareQuests", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[ShareQuests:GetName().."Text"]:SetText(L["ShareQuestsLabel"])
-ShareQuests:SetScript("OnClick", function(self)
-	ptable.TempConfig.questshare = self:GetChecked() == 1
-end)
+local ShowRewardText = newCheckbox("Reward", L["rewardtext"], "showrewardtext")
+-- 'Equip Reward' CheckBox
+local EquipReward = newCheckbox("Equip", L["autoequip"], "autoequip")
+-- reward loot explanation
+local Debug = newCheckbox("Debug", L["debug"], "debug")
+-- share quest (!!! alpha)
+local ShareQuests = newCheckbox("ShareQuests", L["ShareQuestsLabel"], "questshare")
+-- 'Show QuestLevel' CheckBox
+local ShowQuestLevel = newCheckbox("QuestLevel", L["questlevel"], "questlevel")
+-- 'Show Watch Quest Level' CheckBox
+local ShowWatchLevel = newCheckbox("WatchLevel", L["watchlevel"], "watchlevel")

 -- Auto toggle key
-local ToggleKeyLabel = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
-ToggleKeyLabel:SetText(L["togglekey"])
 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())
-						ptable.TempConfig.togglekey = self:GetID()
-					end
-        UIDropDownMenu_AddButton(info, level)
-    end
-end)
-UIDropDownMenu_SetWidth(ToggleKeyDropDown, 200);
-UIDropDownMenu_JustifyText(ToggleKeyDropDown, "LEFT")
-
--- 'Show QuestLevel' CheckBox
-local ShowQuestLevel = CreateFrame("CheckButton", O.."QuestLevel", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[ShowQuestLevel:GetName().."Text"]:SetText(L["questlevel"])
-ShowQuestLevel:SetScript("OnClick", function(self)
-	ptable.TempConfig.questlevel = self:GetChecked() == 1
-end)
+local ToggleKeyDropDown = newDropDown(L["togglekey"], "ToggleKeyDropDown", ToggleKeyConst, "togglekey")
+-- Quest types to handle
+local QuestConst = {L["questTypeAll"], L["questTypeList"], L["questTypeExceptDaily"]}
+local QuestDropDown = newDropDown(L["questTypeLabel"], "QuestDropDown", QuestConst, "all")   -- self:GetID() == 1
+-- Tournament loot type
+local TournamentConst = {L["tournamentWrit"], L["tournamentPurse"]}
+local TournamentDropDown = newDropDown(L["tournamentLabel"], "TournamentDropDown", TournamentConst, "tournament")
+-- How to loot
+local LootConst = {L["lootTypeFalse"], L["lootTypeGreed"], L["lootTypeNeed"]}
+local LootDropDown = newDropDown(L["lootTypeLabel"], "LootDropDown", LootConst, "lootreward")

--- 'Show Watch Quest Level' CheckBox
-local ShowWatchLevel = CreateFrame("CheckButton", O.."WatchLevel", OptionsPanel, "OptionsCheckButtonTemplate")
-_G[ShowWatchLevel:GetName().."Text"]:SetText(L["watchlevel"])
-ShowWatchLevel:SetScript("OnClick", function(self)
-	ptable.TempConfig.watchlevel = self:GetChecked() == 1
-end)

 -- Control placement
 title:SetPoint("TOPLEFT", 16, -16)
 subText:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
 ResetButton:SetPoint("TOPRIGHT", OptionsPanel, "TOPRIGHT", -10, -10)
 Enable:SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -14)
-QuestLabel:SetPoint("BOTTOMLEFT", QuestDropDown, "TOPLEFT", 18, 0)
 QuestDropDown:SetPoint("TOPLEFT", Enable, "BOTTOMLEFT", -15, -22)
 TrivialQuests:SetPoint("TOPLEFT", QuestDropDown, "TOPRIGHT", 30, 0)
-LootLabel:SetPoint("BOTTOMLEFT", LootDropDown, "TOPLEFT", 18, 0)
+CompleteOnly:SetPoint("TOPLEFT", TrivialQuests, "BOTTOMLEFT", 0, -10)
 LootDropDown:SetPoint("TOPLEFT", QuestDropDown, "BOTTOMLEFT", 0, -22)
-TournamentDropDownLabel:SetPoint("BOTTOMLEFT", TournamentDropDown, "TOPLEFT", 18, 0)
-TournamentDropDown:SetPoint("TOPLEFT", LootDropDown, "TOPRIGHT", 17, 0)
+TournamentDropDown:SetPoint("TOPLEFT", ToggleKeyDropDown, "TOPRIGHT", 17, 0)
 EquipReward:SetPoint("TOPLEFT", LootDropDown, "BOTTOMLEFT", 16, -10)
 ShowRewardText:SetPoint("TOPLEFT", EquipReward, "BOTTOMLEFT", 0, -10)
 ToDarkMoon:SetPoint("TOPLEFT", ShowRewardText, "BOTTOMLEFT", 0, -10)
 DarkMoonCannon:SetPoint("TOPLEFT", ToDarkMoon, "BOTTOMLEFT", 0, -10)
 DarkMoonAutoStart:SetPoint("TOPLEFT", DarkMoonCannon, "BOTTOMLEFT", 0, -10)
 Debug:SetPoint("TOPLEFT", ResetButton, "BOTTOMLEFT", 0, -10)
-ToggleKeyLabel:SetPoint("BOTTOMLEFT", ToggleKeyDropDown, "TOPLEFT", 18, 0)
 ToggleKeyDropDown:SetPoint("TOPLEFT", DarkMoonAutoStart, "BOTTOMLEFT", -15, -22)
 ShowQuestLevel:SetPoint("TOPLEFT", ToggleKeyDropDown, "BOTTOMLEFT", 16, -10)
 ShowWatchLevel:SetPoint("TOPLEFT", ShowQuestLevel, "BOTTOMLEFT", 0, -10)
@@ -216,14 +124,14 @@ OptionsPanel.refresh = function()

 	Enable:SetChecked(ptable.TempConfig.enabled)

-	UIDropDownMenu_SetSelectedID(QuestDropDown, ptable.TempConfig.all and 1 or 2)
-	UIDropDownMenu_SetText(QuestDropDown, ptable.TempConfig.all and L["questTypeAll"] or L["questTypeList"]  )
+	UIDropDownMenu_SetSelectedID(QuestDropDown, ptable.TempConfig.all)
+	UIDropDownMenu_SetText(QuestDropDown, QuestConst[ptable.TempConfig.all])

 	UIDropDownMenu_SetSelectedID(LootDropDown, ptable.TempConfig.lootreward)
 	UIDropDownMenu_SetText(LootDropDown, LootConst[ptable.TempConfig.lootreward])

 	UIDropDownMenu_SetSelectedID(TournamentDropDown, ptable.TempConfig.tournament)
-	UIDropDownMenu_SetText(TournamentDropDown,TournamentConst[ptable.TempConfig.tournament])
+	UIDropDownMenu_SetText(TournamentDropDown, TournamentConst[ptable.TempConfig.tournament])
 	ToDarkMoon:SetChecked(ptable.TempConfig.todarkmoon)
 	DarkMoonCannon:SetChecked(ptable.TempConfig.darkmoonteleport)
 	DarkMoonAutoStart:SetChecked(ptable.TempConfig.darkmoonautostart)
@@ -231,12 +139,13 @@ OptionsPanel.refresh = function()
 	EquipReward:SetChecked(ptable.TempConfig.autoequip)
 	Debug:SetChecked(ptable.TempConfig.debug)
 	TrivialQuests:SetChecked(ptable.TempConfig.trivial)
+    CompleteOnly:SetChecked(ptable.TempConfig.completeonly)
 	ShowQuestLevel:SetChecked(ptable.TempConfig.questlevel)
 	ShowWatchLevel:SetChecked(ptable.TempConfig.watchlevel)
 	ShareQuests:SetChecked(ptable.TempConfig.questshare)

 	UIDropDownMenu_SetSelectedID(ToggleKeyDropDown, ptable.TempConfig.togglekey)
-	UIDropDownMenu_SetText(ToggleKeyDropDown,  ToggleKeyConst[ptable.TempConfig.togglekey])
+	UIDropDownMenu_SetText(ToggleKeyDropDown, ToggleKeyConst[ptable.TempConfig.togglekey])
 	MakeACopy = true
 end