diff --git a/core.lua b/core.lua index 922d18b..5bf6bec 100644 --- a/core.lua +++ b/core.lua @@ -70,7 +70,7 @@ XIVBar.LSM = LibStub('LibSharedMedia-3.0'); _G[AddOnName] = Engine; function XIVBar:OnInitialize() - + self.db = LibStub("AceDB-3.0"):New("XIVBarDB", self.defaults) self.LSM:Register(self.LSM.MediaType.FONT, L['Homizio Bold'], self.constants.mediaPath.."homizio_bold.ttf") local options = { @@ -96,6 +96,7 @@ function XIVBar:OnInitialize() } -- modules } } + for name, module in self:IterateModules() do if module['GetConfig'] ~= nil then options.args.modules.args[name] = module:GetConfig() @@ -106,7 +107,7 @@ function XIVBar:OnInitialize() end end - self.db = LibStub("AceDB-3.0"):New("XIVBarDB", self.defaults, "Default") + self.db:RegisterDefaults(self.defaults) P = self.db.profile LibStub("AceConfig-3.0"):RegisterOptionsTable(AddOnName, options) @@ -127,6 +128,7 @@ end function XIVBar:OnEnable() self.frames = {} self:CreateMainBar() + self:Refresh() end function XIVBar:ToggleConfig() @@ -176,7 +178,6 @@ end function XIVBar:CreateMainBar() self:RegisterFrame('bar', CreateFrame("FRAME", "XIV_Databar", UIParent)) self:RegisterFrame('bgTexture', self.frames.bar:CreateTexture(nil, "BACKGROUND")) - self:Refresh() end function XIVBar:GetHeight() @@ -184,18 +185,17 @@ function XIVBar:GetHeight() end function XIVBar:Refresh() - local mainBar = self.frames.bar - local bgTexture = self.frames.bgTexture + if self.frames.bar == nil then return; end + --error(debugstack()) local barColor = P.color.barColor + self.frames.bar:ClearAllPoints() + self.frames.bar:SetPoint(self.db.profile.general.barPosition) + self.frames.bar:SetPoint("LEFT") + self.frames.bar:SetPoint("RIGHT") + self.frames.bar:SetHeight(self:GetHeight()) - mainBar:ClearAllPoints() - mainBar:SetPoint(P.general.barPosition) - mainBar:SetPoint("LEFT") - mainBar:SetPoint("RIGHT") - mainBar:SetHeight(self:GetHeight()) - - bgTexture:SetAllPoints() - bgTexture:SetColorTexture(barColor.r, barColor.g, barColor.b, barColor.a) + self.frames.bgTexture:SetAllPoints() + self.frames.bgTexture:SetColorTexture(barColor.r, barColor.g, barColor.b, barColor.a) for name, module in self:IterateModules() do if module['Refresh'] == nil then return; end @@ -220,8 +220,8 @@ function XIVBar:GetGeneralOptions() order = 1, values = {TOP = L['Top'], BOTTOM = L['Bottom']}, style = "dropdown", - get = function() return P.general.barPosition; end, - set = function(info, value) P.general.barPosition = value; self:Refresh(); end, + get = function() return self.db.profile.general.barPosition; end, + set = function(info, value) self.db.profile.general.barPosition = value; self:Refresh(); end, }, barColor = { name = L['Bar Color'], diff --git a/modules/micromenu.lua b/modules/micromenu.lua index 4872399..16d5cf9 100644 --- a/modules/micromenu.lua +++ b/modules/micromenu.lua @@ -11,7 +11,6 @@ function MenuModule:GetName() end function MenuModule:OnInitialize() - P = xb.db.profile self.mediaFolder = xb.constants.mediaPath..'microbar\\' self.icons = {} self.frames = {} @@ -20,6 +19,7 @@ function MenuModule:OnInitialize() end function MenuModule:OnEnable() + P = xb.db.profile self.microMenuFrame = CreateFrame("FRAME", nil, xb:GetFrame('bar')) xb:RegisterFrame('microMenuFrame', self.microMenuFrame) @@ -28,6 +28,7 @@ function MenuModule:OnEnable() self:CreateIcons() self:Refresh() self:UpdateGuildText() + self:UpdateFriendText() end function MenuModule:OnDisable() @@ -57,6 +58,7 @@ function MenuModule:Refresh() self.microMenuFrame:SetSize(totalWidth, xb:GetHeight()) for name, frame in pairs(self.text) do + frame:SetFont(xb.LSM:Fetch(xb.LSM.MediaType.FONT, P.text.font), P.text.smallFontSize) frame:SetPoint('CENTER', self.frames[name], self.textPosition) self.bgTexture[name]:SetColorTexture(P.color.barColor.r, P.color.barColor.g, P.color.barColor.b, P.color.barColor.a) self.bgTexture[name]:SetPoint('CENTER', frame) @@ -64,25 +66,25 @@ function MenuModule:Refresh() end function MenuModule:CreateFrames() - self.frames.menu = CreateFrame("BUTTON", nil, xb:GetFrame('microMenuFrame')) - - self.frames.socialParent = CreateFrame("FRAME", nil, self.frames.menu) - self.frames.chat = CreateFrame("BUTTON", nil, self.frames.socialParent) - self.frames.guild = CreateFrame("BUTTON", nil, self.frames.chat) - self.frames.social = CreateFrame("BUTTON", nil, self.frames.guild) - - self.frames.microbar = CreateFrame("FRAME", nil, self.frames.social) - self.frames.char = CreateFrame("BUTTON", nil, self.frames.microbar) - self.frames.spell = CreateFrame("BUTTON", nil, self.frames.char) - self.frames.talent = CreateFrame("BUTTON", nil, self.frames.spell) - self.frames.ach = CreateFrame("BUTTON", nil, self.frames.talent) - self.frames.quest = CreateFrame("BUTTON", nil, self.frames.ach) - self.frames.lfg = CreateFrame("BUTTON", nil, self.frames.quest) - self.frames.journal = CreateFrame("BUTTON", nil, self.frames.lfg) - self.frames.pvp = CreateFrame("BUTTON", nil, self.frames.journal) - self.frames.pet = CreateFrame("BUTTON", nil, self.frames.pvp) - self.frames.shop = CreateFrame("BUTTON", nil, self.frames.pet) - self.frames.help = CreateFrame("BUTTON", nil, self.frames.shop) + self.frames.menu = self.frames.menu or CreateFrame("BUTTON", nil, xb:GetFrame('microMenuFrame')) + + self.frames.socialParent = self.frames.socialParent or CreateFrame("FRAME", nil, self.frames.menu) + self.frames.chat = self.frames.chat or CreateFrame("BUTTON", nil, self.frames.socialParent) + self.frames.guild = self.frames.guild or CreateFrame("BUTTON", nil, self.frames.chat) + self.frames.social = self.frames.social or CreateFrame("BUTTON", nil, self.frames.guild) + + self.frames.microbar = self.frames.microbar or CreateFrame("FRAME", nil, self.frames.social) + self.frames.char = self.frames.char or CreateFrame("BUTTON", nil, self.frames.microbar) + self.frames.spell = self.frames.spell or CreateFrame("BUTTON", nil, self.frames.char) + self.frames.talent = self.frames.talent or CreateFrame("BUTTON", nil, self.frames.spell) + self.frames.ach = self.frames.ach or CreateFrame("BUTTON", nil, self.frames.talent) + self.frames.quest = self.frames.quest or CreateFrame("BUTTON", nil, self.frames.ach) + self.frames.lfg = self.frames.lfg or CreateFrame("BUTTON", nil, self.frames.quest) + self.frames.journal = self.frames.journal or CreateFrame("BUTTON", nil, self.frames.lfg) + self.frames.pvp = self.frames.pvp or CreateFrame("BUTTON", nil, self.frames.journal) + self.frames.pet = self.frames.pet or CreateFrame("BUTTON", nil, self.frames.pvp) + self.frames.shop = self.frames.shop or CreateFrame("BUTTON", nil, self.frames.pet) + self.frames.help = self.frames.help or CreateFrame("BUTTON", nil, self.frames.shop) self.text.guild = self.frames.guild:CreateFontString(nil, 'OVERLAY') self.bgTexture.guild = self.frames.guild:CreateTexture(nil, "OVERLAY") @@ -128,8 +130,10 @@ function MenuModule:RegisterFrameEvents() self.frames.menu:SetScript('OnClick', self:MainMenuClick()) self.frames.chat:SetScript('OnClick', self:ChatClick()) + self.frames.guild:SetScript('OnClick', self:GuildClick()) self:RegisterEvent('GUILD_ROSTER_UPDATE', 'UpdateGuildText') + self.frames.social:SetScript('OnClick', self:SocialClick()) self:RegisterEvent('BN_FRIEND_ACCOUNT_ONLINE', 'UpdateFriendText') self:RegisterEvent('BN_FRIEND_ACCOUNT_OFFLINE', 'UpdateFriendText') @@ -142,6 +146,7 @@ function MenuModule:UpdateGuildText() if IsInGuild() then local _, onlineMembers = GetNumGuildMembers() self.text.guild:SetText(onlineMembers) + self.bgTexture.guild:SetPoint('CENTER', self.text.guild) else self.text.guild:Hide() self.bgTexture.guild:Hide() @@ -153,14 +158,7 @@ function MenuModule:UpdateFriendText() local _, friendsOnline = GetNumFriends() local totalFriends = bnOnlineMembers + friendsOnline self.text.social:SetText(totalFriends) - - if IsInGuild() then - local _, onlineMembers = GetNumGuildMembers() - self.text.guild:SetText(onlineMembers) - else - self.text.guild:Hide() - self.bgTexture.guild:Hide() - end + self.bgTexture.social:SetPoint('CENTER', self.text.social) end function MenuModule:DefaultHover(name) @@ -207,27 +205,28 @@ end function MenuModule:GuildClick() return function(self, button, down) - if InCombatLockdown() then return end - --[[if button == "LeftButton" then + if InCombatLockdown() then return; end + if button == "LeftButton" then + ToggleGuildFrame() if ( IsInGuild() ) then - ToggleGuildFrame() GuildFrameTab2:Click() - else - ToggleGuildFinder() end - end]]-- - ToggleGuildFrame() + end end end function MenuModule:SocialClick() return function(self, button, down) + if InCombatLockdown() then return; end + if button == "LeftButton" then + ToggleFriendsFrame() + end end end function MenuModule:CharacterClick() return function(self, button, down) - if InCombatLockdown() then return end + if InCombatLockdown() then return; end if button == "LeftButton" then ToggleCharacter("PaperDollFrame") end diff --git a/modules/test.lua b/modules/test.lua index 3bd7bbf..ae72e82 100644 --- a/modules/test.lua +++ b/modules/test.lua @@ -11,10 +11,10 @@ function TestModule:GetName() end function TestModule:OnInitialize() - P = xb.db.profile end function TestModule:OnEnable() + P = xb.db.profile xb:RegisterFrame('testModuleFrame', CreateFrame("FRAME", nil, xb:GetFrame('bar'))) self:Refresh() end