Move from tekKonfig to externals for scrollbar

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ 2016-09-11 04:12:42 -06:00
parent cc1c0f9fc9
commit d6f700ba55
6 changed files with 65 additions and 73 deletions

View File

@ -47,9 +47,10 @@ function ns.OnLoad()
end end
local scrollbar = LibStub("tekKonfig-Scroll").new(GVS, 0, SCROLLSTEP) local scrollbar = ns.NewScrollBar(GVS, 0, SCROLLSTEP)
local offset = 0 local offset = 0
local function Refresh() function scrollbar:Refresh()
local offset = scrollbar:GetValue()
local n = GetMerchantNumItems() local n = GetMerchantNumItems()
local row, n_searchmatch = 1, 0 local row, n_searchmatch = 1, 0
for i=1,n do for i=1,n do
@ -67,32 +68,28 @@ function ns.OnLoad()
rows[i]:Hide() rows[i]:Hide()
end end
end end
GVS.CURRENCY_DISPLAY_UPDATE = Refresh GVS.CURRENCY_DISPLAY_UPDATE = scrollbar.Refresh
GVS.BAG_UPDATE = Refresh GVS.BAG_UPDATE = scrollbar.Refresh
GVS.MERCHANT_UPDATE = Refresh GVS.MERCHANT_UPDATE = scrollbar.Refresh
ns.MakeSearchField(GVS, Refresh) ns.MakeSearchField(GVS, scrollbar.Refresh)
local f = scrollbar:GetScript("OnValueChanged")
scrollbar:SetScript("OnValueChanged", function(self, value, ...)
offset = math.floor(value)
Refresh()
return f(self, value, ...)
end)
local offset = 0 local offset = 0
GVS:EnableMouseWheel(true) GVS:EnableMouseWheel(true)
GVS:SetScript("OnMouseWheel", function(self, value) GVS:SetScript("OnMouseWheel", function(self, value)
scrollbar:SetValue(scrollbar:GetValue() - value * SCROLLSTEP) if value > 0 then
scrollbar:Decrement()
else
scrollbar:Increment()
end
end) end)
GVS:SetScript("OnShow", function(self, noreset) GVS:SetScript("OnShow", function(self, noreset)
local max = math.max(0, GetMerchantNumItems() - NUMROWS) local max = math.max(0, GetMerchantNumItems() - NUMROWS)
scrollbar:SetMinMaxValues(0, max) scrollbar:SetMinMaxValues(0, max)
scrollbar:SetValue(noreset and math.min(scrollbar:GetValue(), max) or 0) scrollbar:SetValue(noreset and math.min(scrollbar:GetValue(), max) or 0)
Refresh() scrollbar.Refresh()
GVS:RegisterEvent("BAG_UPDATE") GVS:RegisterEvent("BAG_UPDATE")
GVS:RegisterEvent("MERCHANT_UPDATE") GVS:RegisterEvent("MERCHANT_UPDATE")

View File

@ -14,10 +14,10 @@ externals\events.lua
externals\itemid.lua externals\itemid.lua
externals\size_to_fit.lua externals\size_to_fit.lua
externals\tooltip_scanner.lua externals\tooltip_scanner.lua
externals\ui-scrollbar.lua
externals\ui-textinput.lua externals\ui-textinput.lua
tekFunks\gsc.lua tekFunks\gsc.lua
tekKonfig\tekKonfig.xml
LibItemSearch-1.0.lua LibItemSearch-1.0.lua
frames\AltCurrency.lua frames\AltCurrency.lua

View File

@ -2,4 +2,5 @@ events.lua
itemid.lua itemid.lua
size_to_fit.lua size_to_fit.lua
tooltip_scanner.lua tooltip_scanner.lua
ui-scrollbar.lua
ui-textinput.lua ui-textinput.lua

View File

@ -1,8 +1,8 @@
local lib, oldminor = LibStub:NewLibrary("tekKonfig-Scroll", 2) local myname, ns = ...
if not lib then return end
lib.bg = {
local BACKDROP = {
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tile = true,
tileSize = 16, tileSize = 16,
@ -10,18 +10,50 @@ lib.bg = {
insets = { left = 0, right = 0, top = 5, bottom = 5 } 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 -- Creates a scrollbar
-- Parent is required, offset and step are optional -- 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) local f = CreateFrame("Slider", nil, parent)
f:SetWidth(16) f:SetWidth(16)
f:SetPoint("TOPRIGHT", 0 - (offset or 0), -16 - (offset or 0)) f:SetPoint("TOP", 0, -16 - (offset or 0))
f:SetPoint("BOTTOMRIGHT", 0 - (offset or 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) local up = CreateFrame("Button", nil, f)
up:SetPoint("BOTTOM", f, "TOP") up:SetPoint("BOTTOM", f, "TOP")
up:SetWidth(16) up:SetHeight(16) up:SetSize(16, 16)
up:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up") up:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up")
up:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Down") up:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Down")
up:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Disabled") 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():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetHighlightTexture():SetBlendMode("ADD") up:GetHighlightTexture():SetBlendMode("ADD")
up:SetScript("OnClick", function(self) up:SetScript("OnClick", OnClickUp)
local parent = self:GetParent() up:SetScript("PostClick", Sound)
parent:SetValue(parent:GetValue() - (step or parent:GetHeight()/2))
PlaySound("UChatScrollButton")
end)
local down = CreateFrame("Button", nil, f) local down = CreateFrame("Button", nil, f)
down:SetPoint("TOP", f, "BOTTOM") down:SetPoint("TOP", f, "BOTTOM")
down:SetWidth(16) down:SetHeight(16) down:SetSize(16, 16)
down:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up") down:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up")
down:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Down") down:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Down")
down:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Disabled") 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():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetHighlightTexture():SetBlendMode("ADD") down:GetHighlightTexture():SetBlendMode("ADD")
down:SetScript("OnClick", function(self) down:SetScript("OnClick", OnClickDown)
local parent = self:GetParent() down:SetScript("PostClick", Sound)
parent:SetValue(parent:GetValue() + (step or parent:GetHeight()/2))
PlaySound("UChatScrollButton")
end)
f:SetThumbTexture("Interface\\Buttons\\UI-ScrollBar-Knob") f:SetThumbTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
local thumb = f:GetThumbTexture() local thumb = f:GetThumbTexture()
thumb:SetWidth(16) thumb:SetHeight(24) thumb:SetSize(16, 24)
thumb:SetTexCoord(1/4, 3/4, 1/8, 7/8) thumb:SetTexCoord(1/4, 3/4, 1/8, 7/8)
f:SetScript("OnValueChanged", function(self, value) f:SetScript("OnValueChanged", function(self, value)
local min, max = self:GetMinMaxValues() local min, max = self:GetMinMaxValues()
if value == min then up:Disable() else up:Enable() end if value == min then up:Disable() else up:Enable() end
if value == max then down:Disable() else down:Enable() end if value == max then down:Disable() else down:Enable() end
if self.Refresh then self:Refresh() end
end) end)
local border = CreateFrame("Frame", nil, f) local border = CreateFrame("Frame", nil, f)
border:SetPoint("TOPLEFT", up, -5, 5) border:SetPoint("TOPLEFT", up, -5, 5)
border:SetPoint("BOTTOMRIGHT", down, 5, -3) border:SetPoint("BOTTOMRIGHT", down, 5, -3)
border:SetBackdrop(lib.bg) border:SetBackdrop(BACKDROP)
border:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b, 0.5) 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 return f, up, down, border
end end

View File

@ -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

View File

@ -1,5 +0,0 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="LibStub.lua"/>
<Script file="tekKonfigScroll.lua"/>
<Script file="tekKonfigAboutPanel.lua"/>
</Ui>