Adding magic localization table, deDE locale strings from decimad
[WoW-TourGuide.git] / TourGuide.lua
blobf554dacf7c74f8a4e0d9ca9f77e47f2208355cb7
2 local OptionHouse = LibStub("OptionHouse-1.1")
5 local myfaction = UnitFactionGroup("player")
6 local L = TOURGUIDE_LOCALE
7 TOURGUIDE_LOCALE = nil
9 TourGuide = DongleStub("Dongle-1.0"):New("TourGuide")
10 if tekDebug then TourGuide:EnableDebug(10, tekDebug:GetFrame("TourGuide")) end
11 TourGuide.guides = {}
12 TourGuide.guidelist = {}
13 TourGuide.nextzones = {}
14 TourGuide.Locale = L
17 TourGuide.icons = setmetatable({
18 ACCEPT = "Interface\\GossipFrame\\AvailableQuestIcon",
19 COMPLETE = "Interface\\Icons\\Ability_DualWield",
20 TURNIN = "Interface\\GossipFrame\\ActiveQuestIcon",
21 KILL = "Interface\\Icons\\Ability_Creature_Cursed_02",
22 RUN = "Interface\\Icons\\Ability_Tracking",
23 MAP = "Interface\\Icons\\Ability_Spy",
24 FLY = "Interface\\Icons\\Ability_Druid_FlightForm",
25 TRAIN = "Interface\\GossipFrame\\trainerGossipIcon",
26 SETHEARTH = "Interface\\AddOns\\TourGuide\\resting.tga",
27 HEARTH = "Interface\\Icons\\INV_Misc_Rune_01",
28 NOTE = "Interface\\Icons\\INV_Misc_Note_01",
29 GRIND = "Interface\\Icons\\INV_Stone_GrindingStone_05",
30 USE = "Interface\\Icons\\INV_Misc_Bag_08",
31 BUY = "Interface\\Icons\\INV_Misc_Coin_01",
32 BOAT = "Interface\\Icons\\Spell_Frost_SummonWaterElemental",
33 GETFLIGHTPOINT = "Interface\\Icons\\Ability_Hunter_EagleEye",
34 }, {__index = function() return "Interface\\Icons\\INV_Misc_QuestionMark" end})
37 function TourGuide:Initialize()
38 self.db = self:InitializeDB("TourGuideAlphaDB", {
39 char = {
40 turnedin = {},
41 cachedturnins = {},
44 self.turnedin = self.db.char.turnedin
45 self.cachedturnins = self.db.char.cachedturnins
47 self.db.char.currentguide = self.db.char.currentguide or self.guidelist[1]
48 self:LoadGuide(self.db.char.currentguide)
49 self:PositionStatusFrame()
50 end
53 function TourGuide:Enable()
54 local _, title = GetAddOnInfo("TourGuide")
55 local author, version = GetAddOnMetadata("TourGuide", "Author"), GetAddOnMetadata("TourGuide", "Version")
56 local oh = OptionHouse:RegisterAddOn("Tour Guide", title, author, version)
57 oh:RegisterCategory("Guides", TourGuide, "CreateGuidesPanel")
58 oh:RegisterCategory("Objectives", TourGuide, "CreateObjectivePanel")
60 for _,event in pairs(self.TrackEvents) do self:RegisterEvent(event) end
61 self:RegisterEvent("QUEST_COMPLETE", "UpdateStatusFrame")
62 self:RegisterEvent("QUEST_DETAIL", "UpdateStatusFrame")
63 self.TrackEvents = nil
64 self:UpdateStatusFrame()
65 end
68 function TourGuide:RegisterGuide(name, nextzone, faction, sequencefunc)
69 if faction ~= myfaction then return end
70 self.guides[name] = sequencefunc
71 self.nextzones[name] = nextzone
72 table.insert(self.guidelist, name)
73 end
76 function TourGuide:LoadNextGuide()
77 local name = self.nextzones[self.db.char.currentguide]
78 if not name then return end
80 for i,quest in ipairs(self.quests) do self.turnedin[quest] = nil end -- Clean out old completed objectives, to avoid conflicts
82 self:LoadGuide(name)
83 self:UpdateGuidesPanel()
84 return true
85 end
88 function TourGuide:GetQuestLogIndexByName(name)
89 name = name or self.quests[self.current]
90 name = name:gsub(L.PART_GSUB, "")
91 for i=1,GetNumQuestLogEntries() do
92 if GetQuestLogTitle(i) == name then return i end
93 end
94 end
96 function TourGuide:GetQuestDetails(name)
97 if not name then return end
99 local i = self:GetQuestLogIndexByName(name)
100 local complete = i and select(7, GetQuestLogTitle(i)) == 1
101 return i, complete
105 function TourGuide:FindBagSlot(itemid)
106 for bag=0,4 do
107 for slot=1,GetContainerNumSlots(bag) do
108 local item = GetContainerItemLink(bag, slot)
109 if item and string.find(item, "item:"..itemid) then return bag, slot end
115 function TourGuide:GetObjectiveInfo(i)
116 i = i or self.current
117 if not self.actions[i] then return end
119 return self.actions[i], self.quests[i]:gsub("@.*@", ""), self.quests[i] -- Action, display name, full name
123 function TourGuide:GetObjectiveStatus(i)
124 i = i or self.current
125 if not self.actions[i] then return end
127 return self.turnedin[self.quests[i]], self:GetQuestDetails(self.quests[i]) -- turnedin, logi, complete
131 function TourGuide:SetTurnedIn(i, value, noupdate)
132 if not i then
133 i = self.current
134 value = true
137 if value then value = true else value = nil end -- Cleanup to minimize savedvar data
139 self.turnedin[self.quests[i]] = value
140 self:DebugF(1, "Set turned in %q = %s", self.quests[i], tostring(value))
141 if not noupdate then self:UpdateStatusFrame()
142 else self.updatedelay = true end
146 function TourGuide:CompleteQuest(name, noupdate)
147 if not self.current then
148 self:DebugF(1, "Cannot complete %q, no guide loaded", name)
149 return
152 local i = self.current
153 local action, quest
154 repeat
155 action, quest = self:GetObjectiveInfo(i)
156 if action == "TURNIN" and not self:GetObjectiveStatus(i) and name == quest:gsub(L.PART_GSUB, "") then
157 self:DebugF(1, "Saving quest turnin %q", quest)
158 return self:SetTurnedIn(i, true, noupdate)
160 i = i + 1
161 until not action
162 self:DebugF(1, "Quest %q not found!", name)