From 7f292e2a7b7f63e81be290afb41ea7f622c2a773 Mon Sep 17 00:00:00 2001 From: mikx Date: Thu, 18 Jan 2018 09:34:24 -0500 Subject: [PATCH] (beta) Full AceGui3.0 usage --- Event/ENCOUNTER_LOOT_RECEIVED.lua | 11 +- Event/PLAYER_MONEY.lua | 59 ++++---- Frame/MainFrame.lua | 226 +++++++++--------------------- Function/Alert.lua | 1 - Function/Load_Functions.xml | 1 - Locale/frFR.lua | 5 +- Locale/usEN.lua | 5 +- MxW.toc | 5 +- init.lua | 85 ++++++----- 9 files changed, 161 insertions(+), 237 deletions(-) diff --git a/Event/ENCOUNTER_LOOT_RECEIVED.lua b/Event/ENCOUNTER_LOOT_RECEIVED.lua index 834b3e6..dfd4e01 100644 --- a/Event/ENCOUNTER_LOOT_RECEIVED.lua +++ b/Event/ENCOUNTER_LOOT_RECEIVED.lua @@ -11,10 +11,11 @@ local ENCOUNTER_LOOT_RECEIVED_Frame = CreateFrame("Frame") ENCOUNTER_LOOT_RECEIVED_Frame:RegisterEvent("ENCOUNTER_LOOT_RECEIVED") ENCOUNTER_LOOT_RECEIVED_Frame:SetScript("OnEvent", function(self, event, ...) - local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = ... - name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(arg2) - value = MX.TSM:GetItemValue(arg2, "DBMarket"); - if (value ~= nil and value >= Farmer_Logic_MinAlert and quality >= 1) then - MX:SendAlert(arg2,value); + local encounterID, itemID, itemLink, quantity, playerName, className, arg7, arg8, arg9 = ... + name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) + value = MX.TSM:GetItemValue(itemID, "DBMarket"); + local pn = UnitName("player"); + if (value ~= nil and value >= Farmer_Logic_MinAlert and quality >= 1 and playerName == pn) then + MX:SendAlert(itemID,value); end end) diff --git a/Event/PLAYER_MONEY.lua b/Event/PLAYER_MONEY.lua index 682248b..78c0558 100644 --- a/Event/PLAYER_MONEY.lua +++ b/Event/PLAYER_MONEY.lua @@ -10,35 +10,32 @@ local L = LibStub("AceLocale-3.0"):GetLocale("MxW"); local PLAYER_MONEY_Frame = CreateFrame("Frame") PLAYER_MONEY_Frame:RegisterEvent("PLAYER_MONEY") PLAYER_MONEY_Frame:SetScript("OnEvent", function(self, event, ...) - local tmpMoney = GetMoney() - if self.CurrentMoney then - self.DiffMoney = tmpMoney - self.CurrentMoney - else - self.DiffMoney = 0 - end - self.CurrentMoney = tmpMoney - if self.DiffMoney > 0 then - -- Money Gain - -- Reset daily counter if this is a new day - local weekday, month, day, year = CalendarGetDate(); - -- Reset Global Daily Counter - if (Farmer_Logic_Day ~= day) then - Farmer_Money_DayGlobal = 0; - MX:UpdateText() - Farmer_Logic_Day = day; - end - -- Reset Player Daily Counter - if (Farmer_Logic_PlayerDay ~= day) then - Farmer_Money_DayPlayer = 0; - MX:UpdateText() - Farmer_Logic_PlayerDay = day; - end - -- Write to SavedVariables - Farmer_Money_DayPlayer = Farmer_Money_DayPlayer + self.DiffMoney; - Farmer_Money_MonthPlayer = Farmer_Money_MonthPlayer + self.DiffMoney; - Farmer_Money_MonthGlobal = Farmer_Money_MonthGlobal + self.DiffMoney; - Farmer_Money_DayGlobal = Farmer_Money_DayGlobal + self.DiffMoney; - elseif self.DiffMoney < 0 then - -- Money Lost - end + + local DiffGold = 0 + local NewGold = GetMoney() -- Get the player gold after the event + DiffGold = NewGold - CurrentGold -- Get the gold difference + + if (DiffGold > 0) then -- Gold gain + + local weekday, month, day, year = CalendarGetDate(); + -- Reset Global Daily Counter + if (Farmer_Logic_Day ~= day) then + Farmer_Money_DayGlobal = 0; + MX:UpdateMainUI() + Farmer_Logic_Day = day; + end + + -- Write to SavedVariables + Farmer_Money_MonthGlobal = Farmer_Money_MonthGlobal + DiffGold; + Farmer_Money_DayGlobal = Farmer_Money_DayGlobal + DiffGold; + + MX:UpdateMainUI() + + elseif (DiffGold <= 0) then -- Gold lost + + end + + CurrentGold = GetMoney() + DiffGold = 0 + end) diff --git a/Frame/MainFrame.lua b/Frame/MainFrame.lua index 0a9f26d..b690a2f 100644 --- a/Frame/MainFrame.lua +++ b/Frame/MainFrame.lua @@ -8,183 +8,97 @@ local MX = LibStub("AceAddon-3.0"):GetAddon("MxW"); local L = LibStub("AceLocale-3.0"):GetLocale("MxW"); local AceGUI = LibStub("AceGUI-3.0") - local GUI_LOOTCOLLECTED, GUI_SCROLLCONTAINER local lootCollectedLastEntry = nil --- - --- main frame -local f = CreateFrame("Frame","FarmerMainFrame", UIParent) - local mxwVersion = GetAddOnMetadata("MxW", "Version") -local mainFrameWidth = 350; - -- make it draggable with the mouse -f:SetMovable(true) -f:EnableMouse(true) -f:SetScript("OnMouseDown", function(self, button) - if button == "LeftButton" and not self.isMoving then - self:StartMoving(); - self.isMoving = true; - end -end) -f:SetScript("OnMouseUp", function(self, button) - if button == "LeftButton" and self.isMoving then - self:StopMovingOrSizing(); - self.isMoving = false; - end -end) -f:SetScript("OnHide", function(self) - if ( self.isMoving ) then - self:StopMovingOrSizing(); - self.isMoving = false; - end -end) +local backdrop = { + bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], + edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], + edgeSize = 2, + insets = { left = 1, right = 1, top = 1, bottom = 1 } + } -f:SetFrameStrata("BACKGROUND") --Set its strata -f:SetHeight(100) --Give it height -f:SetWidth(mainFrameWidth) --and width +local labTodayGold = AceGUI:Create("Label") +local labMonthGold = AceGUI:Create("Label") -f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", --Set the background and border textures - edgeFile = "Interface/Tooltips/UI-Tooltip-Border", - tile = true, tileSize = 16, edgeSize = 10, - insets = { left = 4, right = 4, top = 4, bottom = 4 } -}) -f:SetBackdropColor(0, 0, 0) --Set the background colour to black -f:SetPoint("CENTER") --Put it in the centre of the parent frame (UIParent) +function MX:ShowMainUI() + local MAIN_UI = AceGUI:Create("Window") + MAIN_UI:SetHeight(100) + MAIN_UI:SetTitle("MxW " .. self.db.profile.version) + MAIN_UI:SetStatusTable(self.db.profile.mainUI) + MAIN_UI:SetLayout("List") + MAIN_UI:SetWidth(300) + MAIN_UI:EnableResize(false) -f.txtLogo = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text -f.txtLogo:SetFont("Fonts\\FRIZQT__.TTF", 14) --Set the font and size -f.txtLogo:SetTextColor(1, 1, 1) --Set the text colour -f.txtLogo:SetPoint("TOP", 0, -5) --Put it in the centre of the frame -f.txtLogo:SetText("MxW") --Change the displayed text + labTodayGold:SetFont("Fonts\\FRIZQT__.TTF", 10) + labTodayGold:SetColor(1, 1, 1) + labTodayGold:SetFullWidth(true) + MAIN_UI:AddChild(labTodayGold) -f.txtVersion = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text -f.txtVersion:SetFont("Fonts\\FRIZQT__.TTF", 9) --Set the font and size -f.txtVersion:SetTextColor(1, 1, 1) --Set the text colour -f.txtVersion:SetPoint("TOP", -(mainFrameWidth/2) + (#mxwVersion*3.0), -5) --Put it in the centre of the frame -f.txtVersion:SetText(mxwVersion) --Change the displayed text + labMonthGold:SetFont("Fonts\\FRIZQT__.TTF", 10) + labMonthGold:SetColor(1, 1, 1) + labMonthGold:SetFullWidth(true) + MAIN_UI:AddChild(labMonthGold) - local button = CreateFrame("Button", nil, f) - button:SetPoint("TOP", f, "TOP", (mainFrameWidth/2) - #L["MainForm_Label_Close"]*6.0, -5) - button:SetWidth(#L["MainForm_Label_Close"]*10.5) - button:SetHeight(17) + local labSpace = AceGUI:Create("Label") + labSpace:SetFont("Fonts\\FRIZQT__.TTF", 10) + labSpace:SetColor(1, 1, 1) + labSpace:SetFullWidth(true) + labSpace:SetText(" ") + MAIN_UI:AddChild(labSpace) - button:SetText(L["MainForm_Label_Close"]) - button:SetNormalFontObject("GameFontNormal") + local BUTTON_LOOTLIST = AceGUI:Create("Button") + BUTTON_LOOTLIST:SetAutoWidth(true) + BUTTON_LOOTLIST:SetText(L["MainForm_Button_LootList"]) + BUTTON_LOOTLIST:SetPoint("RIGHT", 5, 15) + BUTTON_LOOTLIST:SetCallback("OnClick", + function() + MX:ShowListUI() + end + ) + MAIN_UI:AddChild(BUTTON_LOOTLIST) +end - local ntex = button:CreateTexture() - ntex:SetTexture("Interface/Buttons/UI-Panel-Button-Up") - ntex:SetTexCoord(0, 0.625, 0, 0.6875) - ntex:SetAllPoints() - button:SetNormalTexture(ntex) +function MX:ShowListUI() + local LOOTLIST_UI = AceGUI:Create("Window") + LOOTLIST_UI:SetHeight(100) + LOOTLIST_UI:SetTitle(L["MainForm_Button_LootList"]) + LOOTLIST_UI:SetStatusTable(self.db.profile.lootlistUI) + LOOTLIST_UI:SetLayout("List") + LOOTLIST_UI:SetWidth(300) - local htex = button:CreateTexture() - htex:SetTexture("Interface/Buttons/UI-Panel-Button-Highlight") - htex:SetTexCoord(0, 0.625, 0, 0.6875) - htex:SetAllPoints() - button:SetHighlightTexture(htex) + GUI_SCROLLCONTAINER = AceGUI:Create("SimpleGroup") + GUI_SCROLLCONTAINER:SetFullWidth(true) + GUI_SCROLLCONTAINER:SetHeight(150) + GUI_SCROLLCONTAINER:SetLayout("Fill") + GUI_SCROLLCONTAINER.frame:SetBackdrop(backdrop) + GUI_SCROLLCONTAINER.frame:SetBackdropColor(0, 0, 0) + GUI_SCROLLCONTAINER.frame:SetBackdropBorderColor(0.4, 0.4, 0.4) - local ptex = button:CreateTexture() - ptex:SetTexture("Interface/Buttons/UI-Panel-Button-Down") - ptex:SetTexCoord(0, 0.625, 0, 0.6875) - ptex:SetAllPoints() - button:SetPushedTexture(ptex) - - button:SetScript("OnClick", function(self, arg1) - f:Hide(); - end) - -f.txtLabTM = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text -f.txtLabTM:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size -f.txtLabTM:SetTextColor(1, 1, 1) --Set the text colour -f.txtLabTM:SetPoint("TOP", 0, -20) --Put it in the centre of the frame -f.txtLabTM:SetText(format("%s / %s",L["MainForm_Label_Money_Lab_Today"],L["MainForm_Label_Money_Lab_Month"])) --Change the displayed text - -f.txtPlayer = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text -f.txtPlayer:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size -f.txtPlayer:SetTextColor(1, 1, 1) --Set the text colour -f.txtPlayer:SetPoint("TOPLEFT", 10, -32) --Put it in the centre of the frame -f.txtPlayer:SetText(L["MainForm_Label_Money_Player"]) --Change the displayed text - -f.txtGlobal = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text -f.txtGlobal:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size -f.txtGlobal:SetTextColor(1, 1, 1) --Set the text colour -f.txtGlobal:SetPoint("TOPLEFT", 10, -42) --Put it in the centre of the frame -f.txtGlobal:SetText(L["MainForm_Label_Money_Global"]) --Change the displayed text - -f.txtLootLabel = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text -f.txtLootLabel:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size -f.txtLootLabel:SetTextColor(1, 1, 1) --Set the text colour -f.txtLootLabel:SetPoint("TOP", 0, -56) --Put it in the centre of the frame -f.txtLootLabel:SetText(L["MainForm_Label_Loot"]) --Put it in the centre of the frame - -f.txtLootLinkQty = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text -f.txtLootLinkQty:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size -f.txtLootLinkQty:SetTextColor(1, 1, 1) --Set the text colour -f.txtLootLinkQty:SetPoint("TOP", 0, -66) - -f.txtLast = f:CreateFontString(nil, "ARTWORK") --Create a FontString to display text -f.txtLast:SetFont("Fonts\\FRIZQT__.TTF", 10) --Set the font and size -f.txtLast:SetTextColor(1, 1, 1) --Set the text colour -f.txtLast:SetPoint("TOPLEFT", 10, -62) --Put it in the centre of the frame - -local MAIN_UI = AceGUI:Create("Window") -MAIN_UI:Hide() -MAIN_UI:SetHeight(200) -MAIN_UI:SetTitle("MxW") -MAIN_UI:SetLayout("Flow") -MAIN_UI:SetWidth(300) -MAIN_UI:EnableResize(true) - -GUI_SCROLLCONTAINER = AceGUI:Create("SimpleGroup") -GUI_SCROLLCONTAINER:SetFullWidth(true) -GUI_SCROLLCONTAINER:SetHeight(150) -GUI_SCROLLCONTAINER:SetLayout("Fill") -GUI_SCROLLCONTAINER.frame:SetBackdrop(backdrop) -GUI_SCROLLCONTAINER.frame:SetBackdropColor(0, 0, 0) -GUI_SCROLLCONTAINER.frame:SetBackdropBorderColor(0.4, 0.4, 0.4) - -GUI_LOOTCOLLECTED = AceGUI:Create("ScrollFrame") -GUI_LOOTCOLLECTED:SetLayout("Flow") -GUI_SCROLLCONTAINER:AddChild(GUI_LOOTCOLLECTED) -MAIN_UI:AddChild(GUI_SCROLLCONTAINER) + GUI_LOOTCOLLECTED = AceGUI:Create("ScrollFrame") + GUI_LOOTCOLLECTED:SetLayout("Flow") + LOOTLIST_UI:AddChild(GUI_SCROLLCONTAINER) + GUI_SCROLLCONTAINER:AddChild(GUI_LOOTCOLLECTED) +end local MainFrame_Event_ADDON_LOADED = CreateFrame("Frame") MainFrame_Event_ADDON_LOADED:RegisterEvent("ADDON_LOADED") MainFrame_Event_ADDON_LOADED:SetScript("OnEvent", function(self, event, ...) - MX:UpdateText() + end) -local MainFrame_Event_PLAYER_MONEY = CreateFrame("Frame") -MainFrame_Event_PLAYER_MONEY:RegisterEvent("PLAYER_MONEY") -MainFrame_Event_PLAYER_MONEY:SetScript("OnEvent", function(self, event, ...) - MX:UpdateText() +local MainFrame_Event_PLAYER_ENTERING_WORLD = CreateFrame("Frame") +MainFrame_Event_PLAYER_ENTERING_WORLD :RegisterEvent("PLAYER_ENTERING_WORLD") +MainFrame_Event_PLAYER_ENTERING_WORLD :SetScript("OnEvent", function(self, event, ...) + -- Init gold variable + CurrentGold = GetMoney() + MX:UpdateMainUI() end) -local MainFrame_Event_ENCOUNTER_LOOT_RECEIVED = CreateFrame("Frame") -MainFrame_Event_ENCOUNTER_LOOT_RECEIVED:RegisterEvent("ENCOUNTER_LOOT_RECEIVED") -MainFrame_Event_ENCOUNTER_LOOT_RECEIVED:SetScript("OnEvent", function(self, event, ...) - local arg1, iid, ilink, iqty, arg5, arg6, arg7, arg8, arg9 = ... - --name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(iid); - value = MX.TSM:GetItemValue(iid, "DBMarket"); - if (value ~= nil and value >= Farmer_Logic_MinAlert and quality >= 0) then - --f.txtLast:SetText(format("%s %s (%s) (%s %s)",L["MainForm_Label_Money_Last"],link,MX:FormatMoney(value),L["MainForm_Label_Money_Min"],MX:FormatMoney(Farmer_Logic_MinAlert))); - local fv = MX:FormatMoneyShort(value); - local tfv = MX:FormatMoneyShort(value*iqty); - if (iqty > 1) then - f.txtLootLinkQty:SetText(format("%sx %s (%s) (T. %s)", iqty, ilink, fv, tfv)); - MX:addItem2LootCollectedList(format("%sx %s (%s) (T. %s)", iqty, ilink, fv, tfv),texture) - elseif (iqty == 1) then - f.txtLootLinkQty:SetText(format("%sx %s (%s)", iqty, ilink, fv)); - MX:addItem2LootCollectedList(format("%sx %s (%s)", iqty, ilink, fv),texture) - end - end -end) - -function MX:UpdateText() - f.txtPlayer:SetText(format("%s %s / %s",L["MainForm_Label_Money_Player"], MX:FormatMoney(Farmer_Money_DayPlayer), MX:FormatMoney(Farmer_Money_MonthPlayer))) --Change the displayed text - f.txtGlobal:SetText(format("%s %s / %s",L["MainForm_Label_Money_Global"], MX:FormatMoney(Farmer_Money_DayGlobal), MX:FormatMoney(Farmer_Money_MonthGlobal))) --Change the displayed text +function MX:UpdateMainUI() + labTodayGold:SetText(format("%s (%s)", MX:FormatMoney(Farmer_Money_DayGlobal),L["MainForm_Label_Money_Lab_Today"])) + labMonthGold:SetText(format("%s (%s)", MX:FormatMoney(Farmer_Money_MonthGlobal),L["MainForm_Label_Money_Lab_Month"])) end function MX:ShowMain() diff --git a/Function/Alert.lua b/Function/Alert.lua index f457fc7..a1cbf8b 100644 --- a/Function/Alert.lua +++ b/Function/Alert.lua @@ -6,7 +6,6 @@ local MX = LibStub("AceAddon-3.0"):GetAddon("MxW"); local L = LibStub("AceLocale-3.0"):GetLocale("MxW"); -print("Alert.lua has been loaded."); -- Alert Cooking -- Based on [[ AchievementAlertFrame ]] from Blizzard diff --git a/Function/Load_Functions.xml b/Function/Load_Functions.xml index d41a6c7..a1cafe8 100644 --- a/Function/Load_Functions.xml +++ b/Function/Load_Functions.xml @@ -3,6 +3,5 @@