From d6f700ba5561f8cf39ec04be2871f45a2a734786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tekkub=20=CA=95=20=C2=B4=E1=B4=A5=60=20=CA=94?= Date: Sun, 11 Sep 2016 04:12:42 -0600 Subject: [PATCH] Move from tekKonfig to externals for scrollbar --- GnomishVendorShrinker.lua | 29 ++++---- GnomishVendorShrinker.toc | 2 +- externals.txt | 1 + .../ui-scrollbar.lua | 71 +++++++++++++------ tekKonfig/LibStub.lua | 30 -------- tekKonfig/tekKonfig.xml | 5 -- 6 files changed, 65 insertions(+), 73 deletions(-) rename tekKonfig/tekKonfigScroll.lua => externals/ui-scrollbar.lua (66%) delete mode 100644 tekKonfig/LibStub.lua delete mode 100644 tekKonfig/tekKonfig.xml diff --git a/GnomishVendorShrinker.lua b/GnomishVendorShrinker.lua index 63ab768..f578a8f 100644 --- a/GnomishVendorShrinker.lua +++ b/GnomishVendorShrinker.lua @@ -47,9 +47,10 @@ function ns.OnLoad() end - local scrollbar = LibStub("tekKonfig-Scroll").new(GVS, 0, SCROLLSTEP) + local scrollbar = ns.NewScrollBar(GVS, 0, SCROLLSTEP) local offset = 0 - local function Refresh() + function scrollbar:Refresh() + local offset = scrollbar:GetValue() local n = GetMerchantNumItems() local row, n_searchmatch = 1, 0 for i=1,n do @@ -67,32 +68,28 @@ function ns.OnLoad() rows[i]:Hide() end end - GVS.CURRENCY_DISPLAY_UPDATE = Refresh - GVS.BAG_UPDATE = Refresh - GVS.MERCHANT_UPDATE = Refresh + GVS.CURRENCY_DISPLAY_UPDATE = scrollbar.Refresh + GVS.BAG_UPDATE = scrollbar.Refresh + GVS.MERCHANT_UPDATE = scrollbar.Refresh - ns.MakeSearchField(GVS, Refresh) - - - local f = scrollbar:GetScript("OnValueChanged") - scrollbar:SetScript("OnValueChanged", function(self, value, ...) - offset = math.floor(value) - Refresh() - return f(self, value, ...) - end) + ns.MakeSearchField(GVS, scrollbar.Refresh) local offset = 0 GVS:EnableMouseWheel(true) GVS:SetScript("OnMouseWheel", function(self, value) - scrollbar:SetValue(scrollbar:GetValue() - value * SCROLLSTEP) + if value > 0 then + scrollbar:Decrement() + else + scrollbar:Increment() + end end) GVS:SetScript("OnShow", function(self, noreset) local max = math.max(0, GetMerchantNumItems() - NUMROWS) scrollbar:SetMinMaxValues(0, max) scrollbar:SetValue(noreset and math.min(scrollbar:GetValue(), max) or 0) - Refresh() + scrollbar.Refresh() GVS:RegisterEvent("BAG_UPDATE") GVS:RegisterEvent("MERCHANT_UPDATE") diff --git a/GnomishVendorShrinker.toc b/GnomishVendorShrinker.toc index 1053a13..e2cc74e 100644 --- a/GnomishVendorShrinker.toc +++ b/GnomishVendorShrinker.toc @@ -14,10 +14,10 @@ externals\events.lua externals\itemid.lua externals\size_to_fit.lua externals\tooltip_scanner.lua +externals\ui-scrollbar.lua externals\ui-textinput.lua tekFunks\gsc.lua -tekKonfig\tekKonfig.xml LibItemSearch-1.0.lua frames\AltCurrency.lua diff --git a/externals.txt b/externals.txt index 845b384..50929f8 100644 --- a/externals.txt +++ b/externals.txt @@ -2,4 +2,5 @@ events.lua itemid.lua size_to_fit.lua tooltip_scanner.lua +ui-scrollbar.lua ui-textinput.lua diff --git a/tekKonfig/tekKonfigScroll.lua b/externals/ui-scrollbar.lua similarity index 66% rename from tekKonfig/tekKonfigScroll.lua rename to externals/ui-scrollbar.lua index ff69b13..a10bd3f 100644 --- a/tekKonfig/tekKonfigScroll.lua +++ b/externals/ui-scrollbar.lua @@ -1,8 +1,8 @@ -local lib, oldminor = LibStub:NewLibrary("tekKonfig-Scroll", 2) -if not lib then return end +local myname, ns = ... -lib.bg = { + +local BACKDROP = { edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, @@ -10,18 +10,50 @@ lib.bg = { insets = { left = 0, right = 0, top = 5, bottom = 5 } } + +local function Decrement(self) + self:SetValue(self:GetValue() - self:GetValueStep()) +end + + +local function Increment(self) + self:SetValue(self:GetValue() + self:GetValueStep()) +end + + +local function OnClickUp(self) + self:GetParent():Decrement() +end + + +local function OnClickDown(self) + self:GetParent():Increment() +end + + +local function Sound() + PlaySound("UChatScrollButton") +end + + -- Creates a scrollbar -- Parent is required, offset and step are optional -function lib.new(parent, offset, step) +function ns.NewScrollBar(parent, offset, step) local f = CreateFrame("Slider", nil, parent) f:SetWidth(16) - f:SetPoint("TOPRIGHT", 0 - (offset or 0), -16 - (offset or 0)) - f:SetPoint("BOTTOMRIGHT", 0 - (offset or 0), 16 + (offset or 0)) + f:SetPoint("TOP", 0, -16 - (offset or 0)) + f:SetPoint("BOTTOM", 0, 16 + (offset or 0)) + f:SetPoint("RIGHT", 0 - (offset or 0), 0) + + f:SetValueStep(step or 1) + + f.Decrement = Decrement + f.Increment = Increment local up = CreateFrame("Button", nil, f) up:SetPoint("BOTTOM", f, "TOP") - up:SetWidth(16) up:SetHeight(16) + up:SetSize(16, 16) up:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up") up:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Down") up:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Disabled") @@ -33,15 +65,12 @@ function lib.new(parent, offset, step) up:GetHighlightTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4) up:GetHighlightTexture():SetBlendMode("ADD") - up:SetScript("OnClick", function(self) - local parent = self:GetParent() - parent:SetValue(parent:GetValue() - (step or parent:GetHeight()/2)) - PlaySound("UChatScrollButton") - end) + up:SetScript("OnClick", OnClickUp) + up:SetScript("PostClick", Sound) local down = CreateFrame("Button", nil, f) down:SetPoint("TOP", f, "BOTTOM") - down:SetWidth(16) down:SetHeight(16) + down:SetSize(16, 16) down:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up") down:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Down") down:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Disabled") @@ -53,28 +82,28 @@ function lib.new(parent, offset, step) down:GetHighlightTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4) down:GetHighlightTexture():SetBlendMode("ADD") - down:SetScript("OnClick", function(self) - local parent = self:GetParent() - parent:SetValue(parent:GetValue() + (step or parent:GetHeight()/2)) - PlaySound("UChatScrollButton") - end) + down:SetScript("OnClick", OnClickDown) + down:SetScript("PostClick", Sound) f:SetThumbTexture("Interface\\Buttons\\UI-ScrollBar-Knob") local thumb = f:GetThumbTexture() - thumb:SetWidth(16) thumb:SetHeight(24) + thumb:SetSize(16, 24) thumb:SetTexCoord(1/4, 3/4, 1/8, 7/8) f:SetScript("OnValueChanged", function(self, value) local min, max = self:GetMinMaxValues() if value == min then up:Disable() else up:Enable() end if value == max then down:Disable() else down:Enable() end + if self.Refresh then self:Refresh() end end) local border = CreateFrame("Frame", nil, f) border:SetPoint("TOPLEFT", up, -5, 5) border:SetPoint("BOTTOMRIGHT", down, 5, -3) - border:SetBackdrop(lib.bg) - border:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b, 0.5) + border:SetBackdrop(BACKDROP) + local r,g = TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g + local b,a = TOOLTIP_DEFAULT_COLOR.b, 0.5 + border:SetBackdropBorderColor(r,g,b,a) return f, up, down, border end diff --git a/tekKonfig/LibStub.lua b/tekKonfig/LibStub.lua deleted file mode 100644 index 725982d..0000000 --- a/tekKonfig/LibStub.lua +++ /dev/null @@ -1,30 +0,0 @@ --- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info --- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke -local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS! -local LibStub = _G[LIBSTUB_MAJOR] - -if not LibStub or LibStub.minor < LIBSTUB_MINOR then - LibStub = LibStub or {libs = {}, minors = {} } - _G[LIBSTUB_MAJOR] = LibStub - LibStub.minor = LIBSTUB_MINOR - - function LibStub:NewLibrary(major, minor) - assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)") - minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.") - - local oldminor = self.minors[major] - if oldminor and oldminor >= minor then return nil end - self.minors[major], self.libs[major] = minor, self.libs[major] or {} - return self.libs[major], oldminor - end - - function LibStub:GetLibrary(major, silent) - if not self.libs[major] and not silent then - error(("Cannot find a library instance of %q."):format(tostring(major)), 2) - end - return self.libs[major], self.minors[major] - end - - function LibStub:IterateLibraries() return pairs(self.libs) end - setmetatable(LibStub, { __call = LibStub.GetLibrary }) -end diff --git a/tekKonfig/tekKonfig.xml b/tekKonfig/tekKonfig.xml deleted file mode 100644 index f9489b9..0000000 --- a/tekKonfig/tekKonfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - -