Quantcast

Added options panel

lure [01-26-12 - 12:21]
Added options panel
Filename
AutoTurnin.lua
AutoTurnin.toc
localization_EN.lua
localization_RU.lua
options.lua
diff --git a/AutoTurnin.lua b/AutoTurnin.lua
index d102313..3395d8d 100644
--- a/AutoTurnin.lua
+++ b/AutoTurnin.lua
@@ -1,69 +1,83 @@
-AutoTurnin = LibStub("AceAddon-3.0"):NewAddon("AutoTurnin", "AceEvent-3.0", "AceConsole-3.0")
+local addonName, ptable = ...
+local L = ptable.L
+AutoTurnIn = LibStub("AceAddon-3.0"):NewAddon("AutoTurnIn", "AceEvent-3.0", "AceConsole-3.0")

 -- quest autocomplete handlers and functions
-function AutoTurnin:OnEnable()
-	if not AutoTurninCharacterDB then
-		AutoTurninCharacterDB = {enabled = true, all = false, loot=false}
+function AutoTurnIn:OnEnable()
+	if not AutoTurnInCharacterDB then
+		AutoTurnInCharacterDB = {enabled = true, all = false, loot = false}
 	end
-	if AutoTurninCharacterDB.enabled then
+	if AutoTurnInCharacterDB.enabled then
 		self:RegisterGossipEvents()
 	end
 end

-function AutoTurnin:RegisterGossipEvents()
+function AutoTurnIn:RegisterGossipEvents()
 	self:RegisterEvent("QUEST_PROGRESS")
 	self:RegisterEvent("QUEST_COMPLETE")
 	self:RegisterEvent("GOSSIP_SHOW")
 	self:RegisterEvent("QUEST_DETAIL")
 end

-function AutoTurnin:OnDisable()
+function AutoTurnIn:OnDisable()
   self:UnregisterAllEvents()
 end

-function AutoTurnin:OnInitialize()
+function AutoTurnIn:OnInitialize()
 	self:RegisterChatCommand("au", "ConsoleComand")
 end

-function AutoTurnin:ConsoleComand(arg)
-	if (#arg == 0) then
-		self:Print(AutoTurnin.L["usage1"])
-		self:Print(AutoTurnin.L["usage2"])
-		self:Print(AutoTurnin.L["usage3"])
+local p1 = {
+	[true]=L["enabled"],
+	[false]=L["disabled"]
+}
+local p2 = {
+	[true]=L["all"],
+	[false]=L["list"]
+}
+
+
+function AutoTurnIn:ConsoleComand(arg)
+	if (#arg == 0) then
+		InterfaceOptionsFrame_OpenToCategory(AutoTurnInOptionsPanel)
 	elseif arg == "on" then
-		if (not AutoTurninCharacterDB.enabled) then
-			AutoTurninCharacterDB.enabled = true
+		if (not AutoTurnInCharacterDB.enabled) then
+			AutoTurnInCharacterDB.enabled = true
 			self:RegisterGossipEvents()
 		end
-		self:Print(AutoTurnin.L["enabled"])
+		self:Print(L["enabled"])
 	elseif arg == "off"  then
-		if AutoTurninCharacterDB.enabled then
-			AutoTurninCharacterDB.enabled = false
+		if AutoTurnInCharacterDB.enabled then
+			AutoTurnInCharacterDB.enabled = false
 			self:UnregisterAllEvents()
 		end
-		self:Print(AutoTurnin.L["disabled"])
+		self:Print(L["disabled"])
 	elseif arg == "all" then
-		AutoTurninCharacterDB.all = true
-		self:Print(AutoTurnin.L["all"])
+		AutoTurnInCharacterDB.all = true
+		self:Print(L["all"])
 	elseif arg == "list" then
-		AutoTurninCharacterDB.all = false
-		self:Print(AutoTurnin.L["list"])
+		AutoTurnInCharacterDB.all = false
+		self:Print(L["list"])
 	elseif arg == "loot" then
-		AutoTurninCharacterDB.lootMostExpensive = not AutoTurninCharacterDB.lootMostExpensive
-		self:Print(AutoTurnin.L["loot"..tostring(AutoTurninCharacterDB.lootMostExpensive)])
+		AutoTurnInCharacterDB.lootMostExpensive = not AutoTurnInCharacterDB.lootMostExpensive
+		self:Print(L["loot"..tostring(AutoTurnInCharacterDB.lootMostExpensive)])
+	elseif arg == "help" then
+		self:Print(L["usage1"] .. " | " .. p1[AutoTurnInCharacterDB.enabled])
+		self:Print(L["usage2"] .. " | " .. p2[AutoTurnInCharacterDB.all])
+		self:Print(L["usage3"] .. " | " .. L["loot"..tostring(AutoTurnInCharacterDB.lootMostExpensive)])
 	end
 end


 -- (gaq[i+3]) equals "1" if quest is complete, "nil" otherwise
-function AutoTurnin:GOSSIP_SHOW()
+function AutoTurnIn:GOSSIP_SHOW()
 	if (GetGossipActiveQuests()) then
 		local gaq = {GetGossipActiveQuests()}

 		for i=1, #gaq, 4 do
 			if (gaq[i+3]) then
-				local quest = AutoTurnin.quests[gaq[i]]
-				if AutoTurninCharacterDB.all or quest then
+				local quest = L.quests[gaq[i]]
+				if AutoTurnInCharacterDB.all or quest then
 					if quest and quest.amount then
 						local has = 0
 						if quest.currency then
@@ -87,7 +101,7 @@ function AutoTurnin:GOSSIP_SHOW()
 	if (GetGossipAvailableQuests()) then
 		gaq={GetGossipAvailableQuests()}
 		for i=1, #gaq, 5 do
-			if AutoTurninCharacterDB.all or AutoTurnin.quests[gaq[i]] then
+			if AutoTurnInCharacterDB.all or L.quests[gaq[i]] then
 				SelectGossipAvailableQuest(math.floor(i/5)+1)
 				return
 			end
@@ -95,25 +109,25 @@ function AutoTurnin:GOSSIP_SHOW()
 	end
 end

-function AutoTurnin:QUEST_DETAIL()
-	if AutoTurninCharacterDB.all or AutoTurnin.quests[GetTitleText()] then
+function AutoTurnIn:QUEST_DETAIL()
+	if AutoTurnInCharacterDB.all or L.quests[GetTitleText()] then
 		QuestInfoDescriptionText:SetAlphaGradient(0, math.huge)
 		QuestInfoDescriptionText:SetAlpha(1)
 		AcceptQuest()
 	end
 end

-function AutoTurnin:QUEST_PROGRESS()
-    if (AutoTurninCharacterDB.all or AutoTurnin.quests[GetTitleText()]) and IsQuestCompletable() then
+function AutoTurnIn:QUEST_PROGRESS()
+    if (AutoTurnInCharacterDB.all or L.quests[GetTitleText()]) and IsQuestCompletable() then
 		CompleteQuest()
     end
 end

-function AutoTurnin:QUEST_COMPLETE()
-    if AutoTurninCharacterDB.all or AutoTurnin.quests[GetTitleText()] then
+function AutoTurnIn:QUEST_COMPLETE()
+    if AutoTurnInCharacterDB.all or L.quests[GetTitleText()] then
 		local index, money = 0, 0;
 		if GetNumQuestChoices() > 0 then
-			if AutoTurninCharacterDB.lootMostExpensive then
+			if AutoTurnInCharacterDB.lootMostExpensive then
 				for i=1, GetNumQuestChoices() do
 					local m = select(11, GetItemInfo(GetQuestItemLink("choice", i)))
 					if m > money then
diff --git a/AutoTurnin.toc b/AutoTurnin.toc
index 9575f92..f8cb0dc 100644
--- a/AutoTurnin.toc
+++ b/AutoTurnin.toc
@@ -1,8 +1,9 @@
-## Interface: 40300
+## Interface: 40300
 ## Title: AutoTurnin
 ## Version: 1.0
 ## Author: Lur
-## Notes: Auto accepting and autocomplete daily quests (may be reworked to auto every quest)
+## Notes: Auto accepting and autocomplete daily quests
+## Notes-ruRU: Автоматический приниматель и сдаватель квестов.
 ## OptionalDeps: Ace3
 ## SavedVariables: AutoTurninDB
 ## SavedVariablesPerCharacter: AutoTurninCharacterDB
@@ -11,6 +12,7 @@
 ## X-Embeds: Ace3

 embeds.xml
-AutoTurnin.lua
 localization_RU.lua
 localization_EN.lua
+options.lua
+AutoTurnIn.lua
diff --git a/localization_EN.lua b/localization_EN.lua
index fb01bd4..0b5525a 100644
--- a/localization_EN.lua
+++ b/localization_EN.lua
@@ -1,6 +1,7 @@
+local addonName, privateTable = ...
 if (GetLocale() == "enUS") or (GetLocale() == "enGB") then
-AutoTurnin.L = setmetatable({
-	["usage1"]="usage: 'on'/'off' to enable or disable addon",
+privateTable.L = setmetatable({
+	["usage1"]="'on'/'off' to enable or disable addon",
 	["usage2"]="'all'/'list' to handle any quest or just specified in a list",
 	["usage3"]="'loot' do not complete quests with a list of rewards or complete it and choose most expensive one of rewards",
 	["all"]="ready to handle every quest",
@@ -9,7 +10,7 @@ AutoTurnin.L = setmetatable({
 	["lootfalse"]="quest with item rewards will not be finished by addon"},
 	{__index = function(table, index) return index end})

-AutoTurnin.quests = {
+privateTable.L.quests = {
 -- AV Repetive Quests

 -- Alliance AV Quests
diff --git a/localization_RU.lua b/localization_RU.lua
index 96cf9f7..fdc5caa 100644
--- a/localization_RU.lua
+++ b/localization_RU.lua
@@ -1,8 +1,9 @@
+local addonName, privateTable = ...
 if (GetLocale() == "ruRU")  then
-AutoTurnin.L = setmetatable({
-	["usage1"]="использование: 'on'/'off' включает или отключает аддон",
-	["usage2"]="'all'/'list' определяет, будут ли приниматься и сдаваться все задания, или только внесенные в список",
-	["usage3"]="'loot' переключает между двумя состояниями: не завершать задания, где есть список наград либо завершать и выбирать самую дорогую",
+privateTable.L = setmetatable({
+	["usage1"]="'on'/'off' включает или отключает аддон",
+	["usage2"]="'all'/'list' принимать и сдавать все задания или только внесенные в список",
+	["usage3"]="'loot' не завершать задания, где есть список наград либо завершать и выбирать самую дорогую",
 	["enabled"]="включен",
 	["disabled"]="отключен",
 	["all"]="готов принять и сдать любое задание",
@@ -11,7 +12,7 @@ AutoTurnin.L = setmetatable({
 	["lootfalse"]="аддон не будет пытаться завершить заданиия с выбором наград"},
 	{__index = function(table, index) return index end})

-AutoTurnin.quests = {
+privateTable.L.quests = {
 -- AV Repetive Quests
 ["Припасы Железного рудника"]="",
 ["Припасы из рудника Ледяного Зуба"]="",
diff --git a/options.lua b/options.lua
new file mode 100644
index 0000000..6fb6f89
--- /dev/null
+++ b/options.lua
@@ -0,0 +1,98 @@
+local addonName, ptable = ...
+local L = ptable.L
+
+--[[
+	Thanks to LoseControl author for ideas and direction
+	http://forums.wowace.com/showthread.php?t=15763
+	http://www.wowwiki.com/UI_Object_UIDropDownMenu
+]]--
+local O = addonName .. "OptionsPanel"
+local OptionsPanel = CreateFrame("Frame", O)
+OptionsPanel.name=addonName
+-- Title
+local title = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
+title:SetText(addonName)
+-- Description
+local subText = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
+local notes = GetAddOnMetadata(addonName, "Notes-" .. GetLocale())
+if not notes then
+	notes = GetAddOnMetadata(addonName, "Notes")
+end
+subText:SetText(notes)
+
+-- Enable CheckBox
+local Enable = CreateFrame("CheckButton", O.."Enable", OptionsPanel, "OptionsCheckButtonTemplate")
+_G[O.."EnableText"]:SetText(L["enabled"])
+Enable:SetScript("OnClick", function(self) AutoTurnInCharacterDB.enabled = self:GetChecked() end)
+
+-- Quest types to handle
+
+local QuestType = CreateFrame("Frame", O.."QuestTypes", OptionsPanel, "UIDropDownMenuTemplate")
+UIDropDownMenu_Initialize(QuestType, function (self, level)
+    local info
+    for k, v in pairs({["all"] = L["all"],["list"] = L["list"]}) do
+        info = UIDropDownMenu_CreateInfo()
+        info.text = v
+        info.value = k
+        info.func = function(self)
+						UIDropDownMenu_SetSelectedID(QuestType, self:GetID())
+						AutoTurnInCharacterDB.all = (self:GetID() == 2)
+					end
+        UIDropDownMenu_AddButton(info, level)
+    end
+end)
+UIDropDownMenu_SetWidth(QuestType,400 );
+UIDropDownMenu_JustifyText(QuestType, "LEFT")
+
+-- Loot type
+local LootType = CreateFrame("Frame", O.."LootTypes", OptionsPanel, "UIDropDownMenuTemplate")
+UIDropDownMenu_Initialize(LootType, function (self, level)
+    local info
+    for k, v in pairs({["loottrue"] = L["loottrue"],["lootfalse"] = L["lootfalse"]}) do
+        info = UIDropDownMenu_CreateInfo()
+        info.text = v
+        info.value = k
+        info.func = function(self)
+						UIDropDownMenu_SetSelectedID(LootType, self:GetID())
+						AutoTurnInCharacterDB.lootMostExpensive = (self:GetID() == 2)
+					end
+        UIDropDownMenu_AddButton(info, level)
+    end
+end)
+UIDropDownMenu_SetWidth(LootType,400 );
+UIDropDownMenu_JustifyText(LootType, "LEFT")
+
+-- Control placement
+title:SetPoint("TOPLEFT", 16, -16)
+subText:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
+Enable:SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -16)
+QuestType:SetPoint("TOPLEFT", Enable, "BOTTOMLEFT", -15, -16)
+LootType:SetPoint("TOPLEFT", QuestType, "BOTTOMLEFT", 0, -16)
+
+OptionsPanel.refresh = function()
+	Enable:SetChecked(AutoTurnInCharacterDB.enabled)
+
+	if AutoTurnInCharacterDB.all then
+		UIDropDownMenu_SetSelectedID(QuestType, 2)
+		UIDropDownMenu_SetText(QuestType, L["all"])
+	else
+		UIDropDownMenu_SetSelectedID(QuestType, 1)
+		UIDropDownMenu_SetText(QuestType, L["list"])
+	end
+
+	if AutoTurnInCharacterDB.lootMostExpensive then
+		UIDropDownMenu_SetSelectedID(LootType, 2)
+		UIDropDownMenu_SetText(LootType, L["loottrue"])
+	else
+		UIDropDownMenu_SetSelectedID(LootType, 1)
+		UIDropDownMenu_SetText(LootType, L["lootfalse"])
+	end
+end
+
+OptionsPanel.default = function()
+
+	AutoTurnInCharacterDB.enabled = true
+	AutoTurnInCharacterDB.all = false
+	AutoTurnInCharacterDB.lootMostExpensive = false
+end
+InterfaceOptions_AddCategory(OptionsPanel)
\ No newline at end of file