Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return function(plugin,pluginBase,dock,requestClose,EasyLSpageCalback)
- ---------------
- --//Pre-Run\\--
- ---------------
- local pageConnections = {}
- -------------------
- --//Static Defs\\--
- -------------------
- local resource = pluginBase:WaitForChild("PluginCode"):WaitForChild("Core"):WaitForChild("Resource")
- local OOP = resource:WaitForChild("OOP")
- local ELSOOP = OOP:WaitForChild("ELSPage")
- local patternGroupObject = require(ELSOOP:WaitForChild("PatternGroupObject"))
- local traditionalButton = require(OOP:WaitForChild("TraditionalButton"))
- local nodeTreeObject = require(OOP:WaitForChild("NodeTree"))(plugin,pluginBase,dock)
- local traditionalDropdown = require(OOP:WaitForChild("TraditionalDropdown"))
- local traditionalSelector = require(OOP:WaitForChild("TraditionalSelector"))(plugin,pluginBase,dock)
- local pluginSettings = require(resource:WaitForChild("LocalSettings"))
- --local defaultPatternData = require(resource:WaitForChild("DefaultPatternData"))
- -- @depricated
- local ezlsEnum = require(resource:WaitForChild("Enumerators"))
- local primaryDCASHelper = require(resource:WaitForChild("PrimaryDockContextActionHelper"))
- local page = dock:WaitForChild("UIContainer"):WaitForChild("EasyLS"):WaitForChild("MainContainer"):WaitForChild("ELSPage")
- local mainPanelContainer = page:WaitForChild("MainPanelContainer")
- local lightGroups = mainPanelContainer:WaitForChild("Groups")
- local groupsEditor = mainPanelContainer:WaitForChild("GroupsEditor")
- local optionsFrame = mainPanelContainer:WaitForChild("Options")
- local addGroupContainer = lightGroups:WaitForChild("AddLightGroup"):WaitForChild("AddLightContainer")
- local addGroupButton = addGroupContainer:WaitForChild("AddButton")
- local leftPanelContainer = page:WaitForChild("LeftPanelContainer")
- local leftPanelBackground = leftPanelContainer:WaitForChild("LeftPanelBackground")
- local leftPanelBorder = leftPanelContainer:WaitForChild("LeftPanelBorder")
- local leftPanelContent = leftPanelBackground:WaitForChild("Content")
- local leftPanelEditorContainer = leftPanelContent:WaitForChild("Editor")
- local leftPanelGroupsContainer = leftPanelContent:WaitForChild("Groups")
- local pageSelectorButtons = leftPanelBackground:WaitForChild("PageSelector"):WaitForChild("Pages")
- local editorPageButton = pageSelectorButtons:WaitForChild("Editor")
- local groupsPageButton = pageSelectorButtons:WaitForChild("Groups")
- local optionsPageButton = pageSelectorButtons:WaitForChild("Options")
- local leftPanelEditorContainerMainFrame = leftPanelEditorContainer:WaitForChild("Main")
- local patternSelectDropdown = leftPanelEditorContainerMainFrame:WaitForChild("PatternSelect")
- local pausePlay = leftPanelEditorContainer:WaitForChild("MiniButtons"):WaitForChild("PausePlay")
- local pauseButton = pausePlay:WaitForChild("Pause")
- local playButton = pausePlay:WaitForChild("Play")
- local colorSelectorContainer = leftPanelEditorContainerMainFrame:WaitForChild("ColorSelector"):WaitForChild("MainContainer")
- local colorSelectorTitle = colorSelectorContainer:WaitForChild("TextContainer"):WaitForChild("TextLabel")
- local colorSelectorLeftArrow = colorSelectorContainer:WaitForChild("LeftArrowContainer"):WaitForChild("Button")
- local colorSelectorRightArrow = colorSelectorContainer:WaitForChild("RightArrowContainer"):WaitForChild("Button")
- local dataEditMenuBackground = leftPanelGroupsContainer:WaitForChild("Background")
- local dataEditMenuTitle = dataEditMenuBackground:WaitForChild("Title")
- local dataEditMenuIndexValue = dataEditMenuBackground:WaitForChild("Index"):WaitForChild("Value")
- local dataEditMenuDoneButton = dataEditMenuBackground:WaitForChild("LowerButtons"):WaitForChild("Done")
- local dataEditMenuRemoveButton = dataEditMenuBackground:WaitForChild("LowerButtons"):WaitForChild("Remove")
- local leftPanelColumnEditorContainer = leftPanelEditorContainer:WaitForChild("LightEditor")
- local halogenOptions = leftPanelColumnEditorContainer:WaitForChild("LightEditor"):WaitForChild("LightColumnEditor"):WaitForChild("HalogenOptions")
- local templates = pluginBase:WaitForChild("Storage"):WaitForChild("Templates")
- local dataSerializerRef = { --used to access verious properties of PatternObjects and PatternGroupObjects with the same keys
- name = {pg="name",p="patternName"},
- index = {pg="playbackPriority",p="patternIndex"},
- }
- --------------------
- --//Dynamic Defs\\--
- --------------------
- local patternGroups = {} --all pattern groups
- local patternDepthMap = {} --maps patterns in linear order to patterns in depth in pattern groups: {patternGroupIndex=patGroupIndex,patternindex=patIndex}
- local loadedPattern = nil --data object for loaded pattern
- local queuedPattern = nil --data object for queued pattern
- local addGroupButtonObject = nil
- local playButtonObject = nil
- local pauseButtonObject = nil
- local patternSelectDropdownObject = nil
- local patternNodeTree = nil
- local colorSelectorObject = nil
- local windows = {
- {
- button = editorPageButton,
- containers = {leftPanelEditorContainer,lightGroups},
- },
- {
- button = groupsPageButton,
- containers = {leftPanelGroupsContainer,groupsEditor},
- },
- --[[{
- button = optionsPageButton,
- containers = {optionsFrame},
- },]]
- }
- local currentWindow = 0
- local isOpen = false --page is currently open
- local playing = true --paused or playing
- local dataEditMenuOpen = {false} --false when closed, true when open with second and [third] param set to pattern group and pattern if applicable
- local dataEditMenuConnections = {}
- local dataEditMenuDoneButtonObject = nil
- local dataEditMenuRemoveButtonObject = nil
- local columnEditorContent = nil --light that is currently being edited by the column editor
- local columnEditorDoneButtonObject = nil
- local columnLightEditorBulbTypeDropdownObject = nil
- local columnLightEditorFadeInDropdownObject = nil
- local columnLightEditorFadeOutDropdownObject = nil
- local columnEditorConnections = {}
- local currentConfig = {}
- -------------------
- --//Preset Defs\\--
- -------------------
- local miscDirectory = { -- a directory of misc functions to be called from parent EasyLS module
- colorRemovedFromPallete = function(colorIndex) --makes indexes of colors match up after a color is removed
- for _,patternGroupData in ipairs(patternGroups) do
- for _,patternData in ipairs(patternGroupData.patternObjects) do
- for _,lightGroupData in ipairs(patternData.lightGroups) do
- for _,columnData in ipairs(lightGroupData.lightColumns) do
- if columnData._type == ezlsEnum.ClassType.LightColumnObject then
- for _,lightData in ipairs(columnData.lightData) do
- if lightData[1] > colorIndex then
- lightData[1]-=1
- elseif lightData[1] == colorIndex then
- lightData[1] = -1
- end
- end
- end
- end
- end
- end
- end
- end,
- getKeybindOptions = function()
- local allOptions = {}
- --//Index functions for each specific pattern and pattern group
- local function indexPG(pg)
- table.insert(allOptions,
- {
- object=pg,
- getRawName = function() -- used by compiler
- return "PG_"..pg.name
- end,
- getName = function() --<font size=''> </font>
- return "<b>"..pg.name.."</b> <font size='10'><font transparency='.5'>(Group)</font></font>"
- end,
- actions={
- {name="Cycle",bindType=ezlsEnum.KeybindActionType.ToggleAction}, --defines keybind restriction data
- {name="Off",bindType=ezlsEnum.KeybindActionType.ToggleAction},
- }, --The first action provided will be auto selected when this category is selected. is it the default action
- }
- )
- end
- local function indexP(p)
- table.insert(allOptions,
- {
- object=p,
- getRawName = function() -- used by compiler
- return "P_"..p.patternName
- end,
- getName = function()
- return p.patternName.." <font size='10'><font transparency='.5'>(Pattern)</font></font>"
- end,
- actions={
- {name="Toggle",bindType=ezlsEnum.KeybindActionType.ToggleAction}, --defines keybind restriction data
- {name="On",bindType=ezlsEnum.KeybindActionType.ToggleAction},
- {name="Off",bindType=ezlsEnum.KeybindActionType.ToggleAction},
- {name="Activate",bindType=ezlsEnum.KeybindActionType.ActivateAction},
- }, --The first action provided will be auto selected when this category is selected. is it the default action
- }
- )
- end
- for _,pg in ipairs(patternGroups) do
- indexPG(pg)
- for _,p in ipairs(pg.patternObjects) do
- indexP(p)
- end
- end
- --//Custom Functions
- table.insert(allOptions,
- {
- object="All ELS",
- getRawName = function() -- used by compiler
- return "All ELS"
- end,
- getName = function()
- return "All ELS"
- end,
- actions={
- {name="Off",bindType=ezlsEnum.KeybindActionType.ToggleAction},
- },
- }
- )
- for _,option in ipairs(allOptions) do
- setmetatable(option,{
- __tostring = function(t)
- return t.getName()
- end,
- __eq = function(self,t) --overwrite EQ here so when dropdown object compares these tables, it will be based off object not name
- return typeof(t)=="table" and self.object==t.object
- end,
- })
- for _,actionTable in ipairs(option.actions) do --//Make sure all option actions tostring metamethod point to their name field. tostring is called on that data in dropdown object
- setmetatable(actionTable,{
- __tostring = function(t)
- return t.name
- end,
- __eq = function(self,t)
- return typeof(t)=="table" and self.name==t.name
- end,
- })
- end
- end
- warn("GETTING OPTIONS")
- return allOptions
- end,
- }
- local fadeOptions = {"Linear","Quad","Exponential"}
- -----------------
- --//Fucntions\\--
- -----------------
- local function c(con) --short statement to index a connection to the page, so i dont have to write this out every time
- table.insert(pageConnections,con)
- end
- local function accessPatternObjectFromMapIndex(i)
- local patternDepthResult = patternDepthMap[i]
- if patternDepthResult then
- return patternGroups[patternDepthResult.patternGroupIndex].patternObjects[patternDepthResult.patternIndex]
- else
- return nil
- end
- end
- local function playPatterns()
- if not playing then
- playButton.Visible = false
- playButtonObject:SetState(false)
- pauseButton.Visible = true
- if loadedPattern then
- for _,v in ipairs(loadedPattern.lightGroups) do
- v:PlayPattern()
- end
- end
- playing = true
- pauseButtonObject:SetState(true)
- end
- end
- local function pausePatterns()
- if playing then
- pauseButton.Visible = false
- playButton.Visible = true
- pauseButtonObject:SetState(false)
- if loadedPattern then
- for _,v in ipairs(loadedPattern.lightGroups) do
- v:PausePattern()
- end
- end
- playing = false
- playButtonObject:SetState(true)
- end
- end
- local function unloadPattern(patternObject)
- if patternObject then
- patternObject:UnloadFromEditor()
- loadedPattern = nil
- end
- end
- local function loadPattern(patternObject)
- if isOpen then --load the pattern
- playPatterns() --whenever we switch patterns, start with it playing
- unloadPattern(loadedPattern) --unload existing pattern
- --//load new pattern
- if patternObject then
- patternObject:LoadToEditor()
- end
- loadedPattern = patternObject --def as loaded pattern
- else --queue pattern to be loaded when menu is opened
- if patternObject ~= queuedPattern then
- queuedPattern = patternObject
- end
- end
- end
- local function resumeData()
- for _,v in pairs(patternGroups) do
- v:Resume()
- end
- loadPattern(queuedPattern)
- queuedPattern = nil
- end
- local function pauseData()
- for _,v in pairs(patternGroups) do
- v:Yield()
- end
- queuedPattern = loadedPattern
- unloadPattern(loadedPattern)
- end
- local function syncPatterns() --called whenever a pattern is added, removed, or its index is changed
- local absolutePatternToGroupAndPattern = {}
- local absolutePatternToName = {}
- for patternGroupIndex,patternGroupObject in pairs(patternGroups) do
- for patternIndex,patternObject in pairs(patternGroupObject.patternObjects) do
- table.insert(absolutePatternToGroupAndPattern,{patternGroupIndex=patternGroupIndex,patternIndex=patternIndex})
- table.insert(absolutePatternToName,patternObject)
- end
- end
- patternDepthMap = absolutePatternToGroupAndPattern --update depth map.
- local reselectedPatternIndex = patternSelectDropdownObject:UpdateOptions(absolutePatternToName,true)
- reselectedPatternIndex = reselectedPatternIndex or 1 --if nothing was able to be reselected, queue the default pattern
- if isOpen then
- unloadPattern(loadedPattern)
- loadPattern(accessPatternObjectFromMapIndex(reselectedPatternIndex))
- else
- queuedPattern = accessPatternObjectFromMapIndex(reselectedPatternIndex)
- end
- end
- local function canAddNewPattern(nodeMap)
- return patternGroups[nodeMap[1]]:CanMakeNewPattern()
- end
- local function newPattern(nodeMap)
- local patternGroup = patternGroups[nodeMap[1]]
- patternGroup:RawNewPattern(#patternGroup.patternObjects+1)
- end
- local function rawRemovePatternGroup(index)
- patternGroups[index]:Cleanup()
- table.remove(patternGroups,index)
- for i=index,#patternGroups do
- patternGroups[i]:SyncOrder(i)
- end
- syncPatterns()
- end
- local function removePatternGroup(index)
- rawRemovePatternGroup(index)
- end
- local function rawNewPatternGroup(priority,name)
- local group = patternGroupObject.new(priority,name)
- table.insert(patternGroups,group)
- group:Initialize()
- if isOpen then
- group:Resume()
- end
- return group
- end
- local function canAddPatternGroup()
- return #patternGroups < pluginSettings.elsSettings.maxPatternGroups
- end
- local function newPatternGroup(priority,name)
- --//fill priority at lowest if not given
- if type(priority)~="number" then
- local highestNum = 0
- for _,patternGroup in pairs(patternGroups) do
- local p = patternGroup.playbackPriority
- highestNum = p>highestNum and p or highestNum
- end
- priority = highestNum+1
- end
- --//make light group if allowed
- if canAddPatternGroup() then
- local group = rawNewPatternGroup(priority,name)
- return group
- else
- warn("Max pattern groups reached")
- end
- end
- local function clearData()
- for i=1,#patternGroups do
- rawRemovePatternGroup(1)
- end
- loadedPattern = nil
- end
- local function rawUpdatePatternGroupIndex(patternGroupIndex,newIndex)
- --//make raw data change
- local d = patternGroups[patternGroupIndex]
- table.remove(patternGroups,patternGroupIndex)
- table.insert(patternGroups,newIndex,d)
- --//sync objects to reflect change
- for i = math.min(patternGroupIndex,newIndex),math.max(patternGroupIndex,newIndex) do
- patternGroups[i]:SyncOrder(i)
- end
- --//sync second table that lists data in terms of patterns instead of pattern groups
- patternNodeTree:MoveNode({},patternGroupIndex,newIndex)
- syncPatterns()
- --//return new value
- return newIndex
- end
- local function updatePatternGroupIndex(patternGroupIndex,newIndex) --returns new pattern group index
- local result = patternGroupIndex --nothing changed, so just spit out the old value
- local newIndex = tonumber(newIndex)
- if newIndex then
- newIndex = math.clamp(newIndex,1,#patternGroups)--verify newindex is within range, if not clamp to range
- if patternGroupIndex~=newIndex then --verify newindex is given and a number
- result = rawUpdatePatternGroupIndex(patternGroupIndex,newIndex) --carry out update and spit out new index
- end
- end
- return result
- end
- local function resetDataEditMenuData()
- for _,c in ipairs(dataEditMenuConnections) do
- c:Disconnect()
- end
- table.clear(dataEditMenuConnections)
- dataEditMenuDoneButtonObject:SetState(false)
- dataEditMenuRemoveButtonObject:SetState(false)
- end
- local function closeDataEditMenu()
- dataEditMenuBackground.Visible = false
- resetDataEditMenuData()
- end
- local function openDataEditMenu(patternGroupIndex,patternIndex)
- --//when provided with 1 param, assumes pattern group. if given 2, assumes pattern
- local dataObject = patternGroups[patternGroupIndex]
- local dataType = "pg" --pg for group, p for pattern
- if patternIndex then
- dataObject = dataObject.patternObjects[patternIndex]
- dataType = "p"
- end
- --//open menu, load data, init connections
- dataEditMenuBackground.Visible = true
- dataEditMenuTitle.Text = dataObject[dataSerializerRef.name[dataType]]
- dataEditMenuIndexValue.Text = dataObject[dataSerializerRef.index[dataType]] --init value to show existing index
- table.insert(dataEditMenuConnections,dataEditMenuIndexValue.FocusLost:Connect(function()
- local text = dataEditMenuIndexValue.Text
- --//determine new index
- local result = patternIndex and patternGroups[patternGroupIndex]:MovePattern(patternIndex,text) or updatePatternGroupIndex(patternGroupIndex,text)
- --//update ui to reflect result
- dataEditMenuIndexValue.Text = result
- --//make sure this function is aware of change
- resetDataEditMenuData()
- openDataEditMenu(patternIndex and patternGroupIndex or result, patternIndex and result or nil)
- end))
- dataEditMenuDoneButtonObject:SetState(true)
- dataEditMenuRemoveButtonObject.callback = function()
- if patternIndex then --treat as pattern object
- patternGroups[patternGroupIndex]:RemovePattern(patternIndex)
- else --treat as pattern group object
- removePatternGroup(patternGroupIndex)
- end
- closeDataEditMenu()
- end
- dataEditMenuRemoveButtonObject:SetState(true)
- end
- local function dispatchNodeMapUpcall(f,...)
- patternNodeTree[f](patternNodeTree,...)--calling an oop function with . and passing self as param 1 to fake oop principles
- end
- local function editNodeCallback(nodeLocation)
- openDataEditMenu(nodeLocation[1],nodeLocation[2])
- end
- local function nodeNameChangedCallback(nodeLocation,oldName,newName) --terrible practice. shld just have both object inheret from a baseclass with a name property
- local node = #nodeLocation==1 and patternGroups[nodeLocation[1]] or patternGroups[nodeLocation[1]]["patternObjects"][nodeLocation[2]]
- return node:ChangeName(newName)
- end
- ---
- ---below is column editor stuff
- ---
- local function closeColumnEditor() --closes column editor
- columnLightEditorBulbTypeDropdownObject.callback = nil
- columnLightEditorFadeInDropdownObject.callback = nil
- columnLightEditorFadeOutDropdownObject.callback = nil
- for _,v in columnEditorConnections do
- v:Disconnect()
- end
- table.clear(columnEditorConnections)
- leftPanelColumnEditorContainer.Visible = false
- columnEditorContent = nil
- end
- local function openColumnEditor(columnDataRef) --display this data in light column
- if columnDataRef==columnEditorContent then
- closeColumnEditor()
- return
- elseif columnEditorContent then
- closeColumnEditor()
- end
- leftPanelColumnEditorContainer.Visible = false
- columnEditorContent = columnDataRef
- if columnDataRef._type==ezlsEnum.ClassType.LightColumnObject then --if this is a light column. Make another case for rotators
- leftPanelColumnEditorContainer.LightEditor.LightColumnEditor.Visible = true
- leftPanelColumnEditorContainer.LightEditor.RotatorColumnEditor.Visible = false
- leftPanelColumnEditorContainer.LightEditor.LightColumnEditor.Title.Text = #columnDataRef.columnName>0 and columnDataRef.columnName or "Unnamed Light"
- --Initialize UI
- if columnDataRef.fadeData then
- columnLightEditorBulbTypeDropdownObject:UpdateSelection(2) --select halogen
- halogenOptions.Visible = true
- columnLightEditorFadeInDropdownObject:UpdateSelection(table.find(fadeOptions,columnDataRef.fadeData.FadeInMethod))
- columnLightEditorFadeOutDropdownObject:UpdateSelection(table.find(fadeOptions,columnDataRef.fadeData.FadeOutMethod))
- halogenOptions.FadeInTime.Field.Input.Text = columnDataRef.fadeData.FadeInTime
- halogenOptions.FadeOutTime.Field.Input.Text = columnDataRef.fadeData.FadeOutTime
- else
- columnLightEditorBulbTypeDropdownObject:UpdateSelection(1) --select LED
- halogenOptions.Visible = false
- end
- --Connect UI to backend data
- columnLightEditorBulbTypeDropdownObject.callback = function(i)
- if i==1 then --LED
- halogenOptions.Visible = false
- columnDataRef.fadeData = nil
- elseif i==2 then --halogen
- halogenOptions.Visible = true
- columnDataRef.fadeData = {
- FadeInMethod="Quad",
- FadeInTime=.1,
- FadeOutMethod="Linear",
- FadeOutTime=.3,
- }
- halogenOptions.FadeInTime.Field.Input.Text = columnDataRef.fadeData.FadeInTime
- halogenOptions.FadeOutTime.Field.Input.Text = columnDataRef.fadeData.FadeOutTime
- columnLightEditorFadeInDropdownObject:UpdateSelection(table.find(fadeOptions,columnDataRef.fadeData.FadeInMethod))
- columnLightEditorFadeOutDropdownObject:UpdateSelection(table.find(fadeOptions,columnDataRef.fadeData.FadeOutMethod))
- end
- end
- columnLightEditorFadeInDropdownObject.callback = function(i)
- columnDataRef.fadeData.FadeInMethod = fadeOptions[i]
- end
- table.insert(columnEditorConnections,halogenOptions.FadeInTime.Field.Input.FocusLost:Connect(function()
- local text = halogenOptions.FadeInTime.Field.Input.Text
- if tonumber(text) then
- columnDataRef.fadeData.FadeInTime = tonumber(text)
- else
- halogenOptions.FadeInTime.Field.Input.Text = columnDataRef.fadeData.FadeInTime --revert
- end
- end))
- columnLightEditorFadeOutDropdownObject.callback = function(i)
- columnDataRef.fadeData.FadeOutMethod = fadeOptions[i]
- end
- table.insert(columnEditorConnections,halogenOptions.FadeOutTime.Field.Input.FocusLost:Connect(function()
- local text = halogenOptions.FadeOutTime.Field.Input.Text
- if tonumber(text) then
- columnDataRef.fadeData.FadeOutTime = tonumber(text)
- else
- halogenOptions.FadeOutTime.Field.Input.Text = columnDataRef.fadeData.FadeOutTime --revert
- end
- end))
- end
- leftPanelColumnEditorContainer.Visible = true
- end
- local function updateColumnEditorProperty(columnRef,property,new) --update menu name if its changed while menu is open
- if columnRef==columnEditorContent then
- leftPanelColumnEditorContainer.LightEditor.LightColumnEditor.Title.Text = #new>0 and new or "Unnamed Light"
- end
- end
- local function columnDeleted(columnRef) --column data is reference, check if its currently open. if so, close menu
- if not columnEditorContent then return end
- if columnRef==columnEditorContent._super then --cast to superclass bc columnRef comes in from the superclass
- closeColumnEditor()
- end
- end
- ---
- ---
- ---
- local function upCall(f,...)
- if f == "isOpen" then
- return isOpen
- elseif f == "isPlaying" then
- return playing
- elseif f == "syncPatterns" then
- syncPatterns()
- elseif f == "openDataEditMenu" then
- openDataEditMenu(...)
- elseif f == "nodeMap" then
- dispatchNodeMapUpcall(...)
- elseif f == "getCurrentColorIndex" then
- return colorSelectorObject.selected
- elseif f == "OpenColumnEditor" then
- openColumnEditor(...)
- elseif f == "UpdateColumnEditorProperty" then
- updateColumnEditorProperty(...)
- elseif f == "ColumnDeleted" then
- columnDeleted(...)
- end
- end
- local function toWindow(i)
- if i~=currentWindow then
- local currentWindowData = windows[currentWindow]
- local newWindowData = windows[i]
- if currentWindowData then
- for _,v in pairs(currentWindowData.containers) do
- v.Visible = false
- end
- coroutine.resume(coroutine.create(function() --wrap in thread and catch errors that may rise if plugin is destroyed while unloading (idk why this happens but its out of my control)
- currentWindowData.button:FindFirstChild("Selected").BackgroundColor3 = Color3.new(1,1,1)
- currentWindowData.button:FindFirstChild("Selected"):TweenSize(UDim2.new(0,0,0,1),Enum.EasingDirection.In,Enum.EasingStyle.Quad,.1,true,function()
- currentWindowData.button:FindFirstChild("Selected").Visible = false
- end)
- end))
- end
- if newWindowData then
- for _,v in pairs(newWindowData.containers) do
- v.Visible = true
- end
- coroutine.resume(coroutine.create(function()
- newWindowData.button:FindFirstChild("Selected").Visible = true
- newWindowData.button:FindFirstChild("Selected").BackgroundColor3 = Color3.new(1,1,1)
- newWindowData.button:FindFirstChild("Selected"):TweenSize(UDim2.new(.8,0,0,1),Enum.EasingDirection.In,Enum.EasingStyle.Quad,.1,true)
- end))
- end
- currentWindow = i
- end
- end
- local function newLightGroup() --helper fucntion to cast new LG call down to active pattern object
- loadedPattern:AddGroup("",true) --construct "default" data in this group to avoid undefined behavior
- end
- local function colorSelectionChanged(newColorIndex)
- local colorData = currentConfig.colorPallete[newColorIndex]
- if not colorData then return end --if there is no color data at all somehow
- colorSelectorTitle.Text = colorData[1]
- colorSelectorContainer.BackgroundColor3 = colorData[2]
- end
- local function initialize(tabWindow,tabIndex)
- --//initialize objects
- patternGroupObject = patternGroupObject(plugin,pluginBase,dock,requestClose,EasyLSpageCalback,upCall,pluginSettings.stressTestMode)
- --//init buttons
- addGroupButtonObject = traditionalButton.new(plugin,addGroupButton,{},pluginSettings.normalMouseID,pluginSettings.buttonHoverID,{{addGroupButton,{ImageTransparency=0}}})
- addGroupButtonObject.callback = newLightGroup
- playButtonObject = traditionalButton.new(plugin,playButton,{},pluginSettings.normalMouseID,pluginSettings.buttonHoverID,{})
- playButtonObject.callback = playPatterns
- pauseButtonObject = traditionalButton.new(plugin,pauseButton,{},pluginSettings.normalMouseID,pluginSettings.buttonHoverID,{})
- pauseButtonObject.callback = pausePatterns
- dataEditMenuDoneButtonObject = traditionalButton.new(plugin,dataEditMenuDoneButton,{TextColor3=Color3.new(1,1,1),BackgroundColor3=dataEditMenuDoneButton.TextColor3},pluginSettings.normalMouseID,pluginSettings.buttonHoverID,{})
- dataEditMenuDoneButtonObject.callback = closeDataEditMenu
- dataEditMenuRemoveButtonObject = traditionalButton.new(plugin,dataEditMenuRemoveButton,{TextColor3=Color3.new(1,1,1),BackgroundColor3=dataEditMenuRemoveButton.TextColor3},pluginSettings.normalMouseID,pluginSettings.buttonHoverID,{})
- --//create pattern selector dropdown
- patternSelectDropdownObject = traditionalDropdown.new(plugin,dock,patternSelectDropdown,pluginSettings.normalMouseID,pluginSettings.buttonHoverID)
- patternSelectDropdownObject.callback = function(i)
- loadPattern(accessPatternObjectFromMapIndex(i))
- end
- --//column editor stuff
- columnLightEditorBulbTypeDropdownObject = traditionalDropdown.new(plugin,dock,leftPanelColumnEditorContainer.LightEditor.LightColumnEditor.BulbType.BulbTypeDropdown,pluginSettings.normalMouseID,pluginSettings.buttonHoverID)
- columnLightEditorBulbTypeDropdownObject:UpdateOptions({"LED","Halogen"})
- columnLightEditorFadeInDropdownObject = traditionalDropdown.new(plugin,dock,halogenOptions.FadeInMethod.DropdownContainer,pluginSettings.normalMouseID,pluginSettings.buttonHoverID)
- columnLightEditorFadeInDropdownObject:UpdateOptions(fadeOptions)
- columnLightEditorFadeOutDropdownObject = traditionalDropdown.new(plugin,dock,halogenOptions.FadeOutMethod.DropdownContainer,pluginSettings.normalMouseID,pluginSettings.buttonHoverID)
- columnLightEditorFadeOutDropdownObject:UpdateOptions(fadeOptions)
- columnEditorDoneButtonObject = traditionalButton.new(plugin,leftPanelColumnEditorContainer.Done,{TextColor3=Color3.new(1,1,1),BackgroundColor3=leftPanelColumnEditorContainer.Done.TextColor3},pluginSettings.normalMouseID,pluginSettings.buttonHoverID,{})
- columnEditorDoneButtonObject.callback = closeColumnEditor
- --//create color selector
- colorSelectorObject = traditionalSelector.new(colorSelectionChanged,colorSelectorLeftArrow,colorSelectorRightArrow)
- --//create pattern node tree for pattern edit menu
- patternNodeTree = nodeTreeObject.new(groupsEditor,
- {
- {
- defaultNodeName = "Car Name",
- nodeNameChangedCallback = nil,
- nodeButtons = {
- },
- addSubnodeFunctions = {
- canAdd = canAddPatternGroup,
- addCallback = newPatternGroup,
- },
- },
- {
- defaultNodeName = "New Pattern Group",
- nodeNameChangedCallback = nodeNameChangedCallback,
- nodeButtons = {
- {4370186570,editNodeCallback}
- },
- addSubnodeFunctions = {
- canAdd = canAddNewPattern,
- addCallback = newPattern,
- },
- },
- {
- defaultNodeName = "New Pattern",
- nodeNameChangedCallback = nodeNameChangedCallback,
- nodeButtons = {
- {4370186570,editNodeCallback}
- },
- addSubnodeFunctions = nil
- }
- }
- )
- --//Init keybind group
- EasyLSpageCalback.keybindAPI.registerBindGroup("ELS",function() --function should return whether or not to display this bind group when keybinds page is opened
- return EasyLSpageCalback.getTabState(tabIndex)
- end)
- end
- local function loadData(carObject,pageData) --recieves data once when a car is loaded into the editor, fills editor with cars data
- clearData() --clear all existing data to load from a blank slate when a new car is selected
- if not pageData then warn("No page data") pageData = {} end
- patternNodeTree:RenameNode({},"ELS Controller")
- for patternGroupIndex,patternGroupData in pageData do
- local pg = rawNewPatternGroup(patternGroupIndex,patternGroupData[1])
- for patternIndex,patternData in patternGroupData[2] do
- local p = pg:RawNewPattern(patternIndex,patternData[1])
- for lightGroupIndex,lightGroupData in patternData[2] do
- local lg = p:AddGroup(lightGroupData[1])
- lg:RawUpdateTempo(lightGroupData[2])
- lg:RawUpdateSteps(lightGroupData[3])
- for columnIndex,columnData in lightGroupData[5] do
- if columnData[1]=="LightColumnObject" then
- local lc = lg:RawCreateLightColumn(columnData[2][1],columnData[2][3])
- --coloring lights depends on colorpallete of config file, so it is done below in linkData
- elseif columnData[1]=="SpacerObject" then
- elseif columnData[1]=="RotatorObject" then
- else
- warn("Unrecognized column type "..tostring(columnData[1]))
- end
- end
- end
- end
- end
- end
- local function linkData(carObject,pageData)
- for patternGroupIndex,patternGroupData in pageData do
- local pg = patternGroups[patternGroupIndex]
- for patternIndex,patternData in patternGroupData[2] do
- local p = pg.patternObjects[patternIndex]
- for lightGroupIndex,lightGroupData in patternData[2] do
- local lg = p.lightGroups[lightGroupIndex]
- for columnIndex,columnData in lightGroupData[5] do
- if columnData[1]=="LightColumnObject" then
- local lc = lg.lightColumns[columnIndex]
- for rowIndex,rowColorIndex in columnData[2][2] do
- if rowColorIndex==0 then continue end --row is uncolored
- lc:HighlightLight(rowIndex,rowColorIndex)
- end
- elseif columnData[1]=="SpacerObject" then
- elseif columnData[1]=="RotatorObject" then
- else
- warn("Unrecognized column type "..tostring(columnData[1]))
- end
- end
- end
- end
- end
- if isOpen then
- resumeData()
- end
- toWindow(1)
- end
- local function validateAllLightNames()
- for _, patternGroup in ipairs(patternGroups) do
- for _, pattern in ipairs(patternGroup.patternObjects) do
- for _, lightGroup in ipairs(pattern.lightGroups) do
- for _, lightColumn in ipairs(lightGroup.lightColumns) do
- if lightColumn._type == ezlsEnum.ClassType.LightColumnObject then
- lightColumn:ValidateLightName()
- end
- end
- end
- end
- end
- end
- local function onOpen()
- --//Define page opening
- local instanceID = newproxy()
- isOpen = instanceID
- --//button connections
- for windowIndex,windowData in pairs(windows) do
- table.insert(pageConnections,windowData.button.MouseButton1Click:Connect(function()
- toWindow(windowIndex)
- end))
- table.insert(pageConnections,windowData.button.MouseEnter:Connect(function()
- plugin:GetMouse().Icon = pluginSettings.buttonHoverID
- if currentWindow ~= windowIndex then --dont highlight a tab thats selected
- windowData.button:FindFirstChild("Selected").BackgroundColor3 = Color3.new(.3,.3,.3)
- windowData.button:FindFirstChild("Selected").Visible = true
- windowData.button:FindFirstChild("Selected"):TweenSize(UDim2.new(.8,0,0,1),Enum.EasingDirection.In,Enum.EasingStyle.Quad,.1,true)
- end
- end))
- table.insert(pageConnections,windowData.button.MouseLeave:Connect(function()
- plugin:GetMouse().Icon = pluginSettings.normalMouseID
- if currentWindow ~= windowIndex then --dont unhighlight a tab thats selected
- windowData.button:FindFirstChild("Selected").BackgroundColor3 = Color3.new(.3,.3,.3)
- windowData.button:FindFirstChild("Selected"):TweenSize(UDim2.new(0,0,0,1),Enum.EasingDirection.In,Enum.EasingStyle.Quad,.1,true,function(completed)
- windowData.button:FindFirstChild("Selected").Visible = false
- end)
- end
- end))
- end
- --//resume objects
- addGroupButtonObject:SetState(true)
- patternSelectDropdownObject:SetState(true)
- pauseButtonObject:SetState(true)
- playButtonObject:SetState(true)
- patternNodeTree:SetState(true)
- colorSelectorObject:SetState(true)
- columnLightEditorBulbTypeDropdownObject:SetState(true)
- columnLightEditorFadeInDropdownObject:SetState(true)
- columnLightEditorFadeOutDropdownObject:SetState(true)
- columnEditorDoneButtonObject:SetState(true)
- --//update color selector
- currentConfig = EasyLSpageCalback.getConfig()
- colorSelectorObject:SetOptions(currentConfig.colorPallete)
- --//resume data objects
- resumeData()
- --//bind done button for column editor
- table.insert(pageConnections,leftPanelColumnEditorContainer.Done.MouseButton1Click:Connect(closeColumnEditor))
- --//keybinds
- primaryDCASHelper.DCAS:BindAction("Color_Forward",function()
- colorSelectorObject:CycleForwards()
- end,Enum.KeyCode.E,Enum.UserInputState.Begin)
- primaryDCASHelper.DCAS:BindAction("Color_Backward",function()
- colorSelectorObject:CycleBackwards()
- end,Enum.KeyCode.Q,Enum.UserInputState.Begin)
- --//validate light names
- validateAllLightNames()
- --//tween menu border
- task.defer(function()
- while isOpen == instanceID do
- for i = 1,255,.25 do
- leftPanelBorder.BackgroundColor3 = Color3.fromHSV(i/255,1,1)
- task.wait()
- end
- end
- end)
- end
- local function onClose()
- --//Close page instance
- isOpen = false
- for _,connection in pairs(pageConnections) do
- connection:Disconnect()
- end
- table.clear(pageConnections)
- --//pause objects
- addGroupButtonObject:SetState(false)
- patternSelectDropdownObject:SetState(false)
- pauseButtonObject:SetState(false)
- playButtonObject:SetState(false)
- patternNodeTree:SetState(false)
- colorSelectorObject:SetState(false)
- columnLightEditorBulbTypeDropdownObject:SetState(false)
- columnLightEditorFadeInDropdownObject:SetState(false)
- columnLightEditorFadeOutDropdownObject:SetState(false)
- columnEditorDoneButtonObject:SetState(false)
- --//remove binds
- primaryDCASHelper.DCAS:UnbindAction("Color_Forward")
- primaryDCASHelper.DCAS:UnbindAction("Color_Backward")
- --//close column editor
- closeColumnEditor()
- --//pause data objects
- pauseData()
- end
- local function getCompilerData()
- local data = {}
- for i,v in ipairs(patternGroups) do
- data[i] = v:PullData()
- end
- return data
- end
- ------------
- --//Core\\--
- ------------
- local page = {}
- page.initialize = initialize
- page.loadData = loadData
- page.linkData = linkData
- page.onOpen = onOpen
- page.onClose = onClose
- page.getCompilerData = getCompilerData
- page.miscDirectory = miscDirectory
- return page
- end
Advertisement
Add Comment
Please, Sign In to add comment