Update shaders.lua
This commit is contained in:
parent
6b85d7094a
commit
ebabc7bf8e
@ -17,6 +17,14 @@ local groups = {}
|
|||||||
|
|
||||||
local widgetsToGroups = {}
|
local widgetsToGroups = {}
|
||||||
local allSettings = {}
|
local allSettings = {}
|
||||||
|
local shaderConfig
|
||||||
|
|
||||||
|
function displayed()
|
||||||
|
shaderConfig = root.getConfiguration("postProcessGroups")
|
||||||
|
end
|
||||||
|
function dismissed()
|
||||||
|
shaderConfig = nil
|
||||||
|
end
|
||||||
|
|
||||||
local function addGroupToList(data)
|
local function addGroupToList(data)
|
||||||
local name = widget.addListItem(GROUP_LIST_WIDGET)
|
local name = widget.addListItem(GROUP_LIST_WIDGET)
|
||||||
@ -67,7 +75,7 @@ local function addOptionGroup(data, i, added)
|
|||||||
added[#added + 1] = name
|
added[#added + 1] = name
|
||||||
local label = {
|
local label = {
|
||||||
type = "label",
|
type = "label",
|
||||||
value = data.name,
|
value = data.label,
|
||||||
wrapWidth = 120,
|
wrapWidth = 120,
|
||||||
fontSize = 8,
|
fontSize = 8,
|
||||||
hAnchor = "mid",
|
hAnchor = "mid",
|
||||||
@ -77,6 +85,16 @@ local function addOptionGroup(data, i, added)
|
|||||||
widget.addChild(fmt("%s.%s", BINDS_WIDGET, name), label, "text")
|
widget.addChild(fmt("%s.%s", BINDS_WIDGET, name), label, "text")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function digitRegex(n)
|
||||||
|
local i = 0
|
||||||
|
while n ~= math.floor(n) do
|
||||||
|
n = n * 10
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
return fmt("%%.%df",i) -- create format string %.nf, where n = %d (i with no decimal points)
|
||||||
|
end
|
||||||
|
local optionPrefix = "option_"
|
||||||
|
local optionOffset = #optionPrefix+1
|
||||||
local function addOption(data, i, added)
|
local function addOption(data, i, added)
|
||||||
local y = (i - 1) * -14
|
local y = (i - 1) * -14
|
||||||
local bg = {
|
local bg = {
|
||||||
@ -84,12 +102,12 @@ local function addOption(data, i, added)
|
|||||||
file = PATH .. "optionname.png",
|
file = PATH .. "optionname.png",
|
||||||
position = {-12, y}
|
position = {-12, y}
|
||||||
}
|
}
|
||||||
local name = "label_" .. i
|
local name = "label_" .. data.name
|
||||||
widget.addChild(OPTIONS_WIDGET, bg, name)
|
widget.addChild(OPTIONS_WIDGET, bg, name)
|
||||||
added[#added + 1] = name
|
added[#added + 1] = name
|
||||||
local label = {
|
local label = {
|
||||||
type = "label",
|
type = "label",
|
||||||
value = data.name,
|
value = data.label,
|
||||||
wrapWidth = 120,
|
wrapWidth = 120,
|
||||||
fontSize = 8,
|
fontSize = 8,
|
||||||
hAnchor = "mid",
|
hAnchor = "mid",
|
||||||
@ -97,7 +115,115 @@ local function addOption(data, i, added)
|
|||||||
position = {62, 6}
|
position = {62, 6}
|
||||||
}
|
}
|
||||||
widget.addChild(fmt("%s.%s", OPTIONS_WIDGET, name), label, "text")
|
widget.addChild(fmt("%s.%s", OPTIONS_WIDGET, name), label, "text")
|
||||||
|
local value = data.default or 0
|
||||||
|
if not shaderConfig[activeGroup] then
|
||||||
|
shaderConfig[activeGroup] = {parameters={}}
|
||||||
|
end
|
||||||
|
if not shaderConfig[activeGroup].parameters then
|
||||||
|
shaderConfig[activeGroup].parameters = {}
|
||||||
|
end
|
||||||
|
if shaderConfig[activeGroup].parameters[data.name] ~= nil then
|
||||||
|
value = shaderConfig[activeGroup].parameters[data.name]
|
||||||
|
end
|
||||||
|
|
||||||
-- todo: finish this
|
-- todo: finish this
|
||||||
|
if data.type == "slider" then
|
||||||
|
local range = data.range or {0,1}
|
||||||
|
local delta = data.delta or 0.01
|
||||||
|
-- for some reason ranges require ints so
|
||||||
|
local r = {range[1]/delta, range[2]/delta, 1}
|
||||||
|
|
||||||
|
local slider = {
|
||||||
|
type = "slider",
|
||||||
|
callback = "sliderOptionModified",
|
||||||
|
position = {110, y + 2},
|
||||||
|
gridImage = "/interface/optionsmenu/smallselection.png",
|
||||||
|
range = r
|
||||||
|
}
|
||||||
|
name = optionPrefix..data.name
|
||||||
|
added[#added + 1] = name
|
||||||
|
widget.addChild(OPTIONS_WIDGET, slider, name)
|
||||||
|
|
||||||
|
widget.setSliderValue(fmt("%s.%s",OPTIONS_WIDGET,name), value/delta)
|
||||||
|
local valLabel = {
|
||||||
|
type = "label",
|
||||||
|
value = fmt(digitRegex(delta),value),
|
||||||
|
position = {186, y + 2}
|
||||||
|
}
|
||||||
|
added[#added + 1] = name.."_value"
|
||||||
|
widget.addChild(OPTIONS_WIDGET, valLabel, name.."_value")
|
||||||
|
elseif data.type == "select" then
|
||||||
|
local n = #data.values
|
||||||
|
local width = math.floor(118/n)
|
||||||
|
local by = y
|
||||||
|
local buttons = {}
|
||||||
|
for i=0,n-1 do
|
||||||
|
local img = fmt("%sselect.png?crop=0;0;%.0f;13",PATH,width)
|
||||||
|
local button = {
|
||||||
|
type = "button",
|
||||||
|
callback="selectOptionPressed",
|
||||||
|
caption = data.values[i+1],
|
||||||
|
base = img,
|
||||||
|
hover = img.."?brightness=-25",
|
||||||
|
baseImageChecked = img.."?multiply=00ff00",
|
||||||
|
hoverImageChecked = img.."?multiply=00ff00?brightness=-25",
|
||||||
|
position = {110+width*i, by},
|
||||||
|
pressedOffset = {0, 0},
|
||||||
|
checkable = true,
|
||||||
|
checked = (value == i)
|
||||||
|
}
|
||||||
|
name = "select_"..data.name.."_"..i
|
||||||
|
added[#added + 1] = name
|
||||||
|
widget.addChild(OPTIONS_WIDGET, button, name)
|
||||||
|
table.insert(buttons,{widget=fmt("%s.%s",OPTIONS_WIDGET,name),index=i})
|
||||||
|
end
|
||||||
|
for k,v in next, buttons do
|
||||||
|
widget.setData(v.widget,{option=data,index=v.index,buttons=buttons})
|
||||||
|
end
|
||||||
|
--[[local bge = {
|
||||||
|
type = "image",
|
||||||
|
file = PATH.."selectend.png",
|
||||||
|
position = {110+width*3, by}
|
||||||
|
}
|
||||||
|
name = "bgend_"..data.name
|
||||||
|
added[#added + 1] = name
|
||||||
|
widget.addChild(OPTIONS_WIDGET, bge, name)]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function sliderOptionModified(option, odata)
|
||||||
|
local oname = string.sub(option, optionOffset)
|
||||||
|
local parameter = groups[activeGroup].parameters[oname]
|
||||||
|
local value = widget.getSliderValue(fmt("%s.%s",OPTIONS_WIDGET,option))*parameter.delta
|
||||||
|
|
||||||
|
widget.setText(fmt("%s.%s",OPTIONS_WIDGET,option.."_value"), fmt(digitRegex(parameter.delta),value))
|
||||||
|
|
||||||
|
for k,v in next, parameter.effects do
|
||||||
|
renderer.setEffectParameter(v, oname, value)
|
||||||
|
end
|
||||||
|
shaderConfig[activeGroup].parameters[oname] = value
|
||||||
|
root.setConfiguration("postProcessGroups",shaderConfig)
|
||||||
|
end
|
||||||
|
|
||||||
|
function selectOptionPressed(button,bdata)
|
||||||
|
sb.logInfo(sb.print(bdata))
|
||||||
|
|
||||||
|
for k,v in next, bdata.buttons do
|
||||||
|
if v.index ~= bdata.index then
|
||||||
|
widget.setChecked(v.widget, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
value = bdata.index
|
||||||
|
|
||||||
|
local oname = bdata.option.name
|
||||||
|
local parameter = groups[activeGroup].parameters[oname]
|
||||||
|
|
||||||
|
for k,v in next, parameter.effects do
|
||||||
|
renderer.setEffectParameter(v, oname, value)
|
||||||
|
end
|
||||||
|
shaderConfig[activeGroup].parameters[oname] = value
|
||||||
|
root.setConfiguration("postProcessGroups",shaderConfig)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addEnabled(groupname, i, added)
|
local function addEnabled(groupname, i, added)
|
||||||
@ -139,6 +265,7 @@ end
|
|||||||
|
|
||||||
function toggleGroupEnabled(checkbox, cdata)
|
function toggleGroupEnabled(checkbox, cdata)
|
||||||
renderer.setPostProcessGroupEnabled(activeGroup, widget.getChecked(fmt("%s.%s",OPTIONS_WIDGET,checkbox)), true)
|
renderer.setPostProcessGroupEnabled(activeGroup, widget.getChecked(fmt("%s.%s",OPTIONS_WIDGET,checkbox)), true)
|
||||||
|
shaderConfig = root.getConfiguration("postProcessGroups")
|
||||||
end
|
end
|
||||||
|
|
||||||
function selectGroup()
|
function selectGroup()
|
||||||
@ -163,7 +290,21 @@ function selectGroup()
|
|||||||
local added = {}
|
local added = {}
|
||||||
local index = 0
|
local index = 0
|
||||||
addEnabled(group.groupId,index,added)
|
addEnabled(group.groupId,index,added)
|
||||||
|
if group.categories then
|
||||||
|
|
||||||
|
elseif group.parameters then
|
||||||
|
local sortedParams = {}
|
||||||
|
for k,v in next, group.parameters do
|
||||||
|
v.name = k
|
||||||
|
sortedParams[#sortedParams+1] = v
|
||||||
|
end
|
||||||
|
table.sort(sortedParams, alphabeticalNameSortLesser)
|
||||||
|
|
||||||
|
for k,v in next, sortedParams do
|
||||||
|
index = index + 1
|
||||||
|
addOption(v, index, added)
|
||||||
|
end
|
||||||
|
end
|
||||||
--[[
|
--[[
|
||||||
local categories = group.categories or {}
|
local categories = group.categories or {}
|
||||||
if not categories.unsorted then
|
if not categories.unsorted then
|
||||||
@ -198,7 +339,8 @@ function selectGroup()
|
|||||||
addOption(category.sortedOptions[iB], index, added)
|
addOption(category.sortedOptions[iB], index, added)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end]]
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
widget.setData(OPTIONS_WIDGET, added)
|
widget.setData(OPTIONS_WIDGET, added)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user