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
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")

View File

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

View File

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

View File

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

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>