uiCombo: Custom Value Possible? (Workaround) #631
-
uiCombo: Custom Value Possible?
As usual, any thoughts appreciated.
uiCombo selections for Filter Type
|
Beta Was this translation helpful? Give feedback.
Answered by
unityconstruct
Apr 16, 2024
Replies: 1 comment
-
CtrlrCombo Integration WorkaroundProvides custom value assignments in a CtrlrCombo object Summary
Getting value from a selection-- Fetch selected text
local text = L(panel:getModulator("layer_filt_type_L1_15371"):getComponent():getComponentText())
-- Fetch data from text ( [###] ) using helper function
local value = GetStringBetween(text,"[","]")
-------------------------------------------------------------------------
---Get string between two specified chars/strings
---@param text string
---@param startChar string
---@param endChar string
---@return number|nil
function GetStringBetween(text,startChar,endChar)
startChar = startChar or "["
endChar = endChar or "["
if ( text == nil) then return nil end
local first = string.find(text,startChar,1,true)
local last = string.find(text,endChar,1,true)
if ( first ~= nil) and ( last ~= nil) then
local value = string.sub(text,first+1,last-1)
if ( value ~= nil) then
return tonumber(value)
end
end
return nil
end Set modulator by data
---lookup table/enum
---@enum LayerFilterType
LayerFilterType = {
[127] = 0,
[0] = 1,
[1] = 2,
[2] = 3,
[132] = 4,
[133] = 5,
[134] = 6,
[136] = 7,
[137] = 8,
[8] = 9,
[9] = 10,
[16] = 11,
[17] = 12,
[18] = 13,
[32] = 14,
[33] = 15,
[34] = 16,
[146] = 17,
}
--- translate a value to a ComboList index
-- given value of 137
local value = 137
-- perform lookup and reassign `value`
value = LayerFilterType[value]
-- assign value to modulator
mod:setModulatorValue(tonumber(value),false,false,false) OnChangeHandler function--@param mod CtrlrModulator
---@param value number: modulator value
---@param source number: where did change get called from
function OnChangeHandler(mod, value, source)
local modName = L(mod:getName())
-- parse modname to detect call from specific modulator so ONE function can handle many mods
if (found ~= string.find(modName, "layer_filt_type_L1_15371", 1, true)) then -- true = plain text search
-- Fetch selected text
local text = L(panel:getModulator("layer_filt_type_L1_15371"):getComponent():getComponentText())
-- Fetch data from text ( [###] ) using helper function
local value = GetStringBetween(text,"[","]")
end
end Permutations of CallsL(panel:getModulator("layer_filt_type_L1_15371"):getComponent():getComponentText())
L(layer_filt_type_L1_15371:getComponent():getComponentText())
mod = panel:getModulator("layer_filt_type_L1_15371")
L(mod:getComponent():getComponentText())
comp = panel:getModulator("layer_filt_type_L1_15371"):getComponent()
comp = panel:getComponent("layer_filt_type_L1_15371")
L(comp:getComponentText()) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
unityconstruct
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CtrlrCombo Integration Workaround
Provides custom value assignments in a CtrlrCombo object
Summary
Getting value from a selection