MoveIt.GUI.Profile = {} function MoveIt.GUI.Profile:Create(container) self.groupChooseProfile = AceGUI:Create("InlineGroup") self.groupChooseProfile:SetRelativeWidth(0.5) self.groupChooseProfile:SetLayout("Flow") self.groupChooseProfile:SetTitle("Choose Profile") self.labelCurrentProfile = AceGUI:Create("Label") self.labelCurrentProfile:SetRelativeWidth(0.25) self.labelCurrentProfile:SetText("Profile: ") self.groupChooseProfile:AddChild(self.labelCurrentProfile) self.dropdownProfileSelect = AceGUI:Create("Dropdown") self.dropdownProfileSelect:SetRelativeWidth(0.5) self.dropdownProfileSelect:SetCallback("OnValueChanged", function(_, _, value) self.buttonSwitchProfile:SetDisabled(value == MoveIt.db:GetCurrentProfile() or value == nil) end) self.groupChooseProfile:AddChild(self.dropdownProfileSelect) self.buttonSwitchProfile = AceGUI:Create("Button") self.buttonSwitchProfile:SetRelativeWidth(0.25) self.buttonSwitchProfile:SetText("Activate") self.buttonSwitchProfile:SetDisabled(true) self.buttonSwitchProfile:SetCallback("OnClick", function() self:OnSwitchProfile() end) self.groupChooseProfile:AddChild(self.buttonSwitchProfile) container:AddChild(self.groupChooseProfile) self.groupCreateProfile = AceGUI:Create("InlineGroup") self.groupCreateProfile:SetRelativeWidth(0.5) self.groupCreateProfile:SetLayout("Flow") self.groupCreateProfile:SetTitle("Create New Profile") self.labelCreateProfile = AceGUI:Create("Label") self.labelCreateProfile:SetRelativeWidth(0.25) self.labelCreateProfile:SetText("Profile name: ") self.groupCreateProfile:AddChild(self.labelCreateProfile) self.editboxCreateProfile = AceGUI:Create("EditBox") self.editboxCreateProfile:SetRelativeWidth(0.5) self.editboxCreateProfile:SetCallback("OnEnterPressed", function(_, _, value) self:OnNewProfileNameEntered(value) end) self.groupCreateProfile:AddChild(self.editboxCreateProfile) self.buttonCreateProfile = AceGUI:Create("Button") self.buttonCreateProfile:SetRelativeWidth(0.25) self.buttonCreateProfile:SetText("Create") self.buttonCreateProfile:SetDisabled(true) self.buttonCreateProfile:SetCallback("OnClick", function() self:OnCreateProfile() end) self.groupCreateProfile:AddChild(self.buttonCreateProfile) container:AddChild(self.groupCreateProfile) --MoveIt.GUI:CreateDivider(container) self.groupCopyProfile = AceGUI:Create("InlineGroup") self.groupCopyProfile:SetRelativeWidth(0.6) self.groupCopyProfile:SetLayout("Flow") self.groupCopyProfile:SetTitle("Copy Profile") self.dropdownCopySource = AceGUI:Create("Dropdown") self.dropdownCopySource:SetRelativeWidth(0.35) self.dropdownCopySource:SetLabel("Copy from:") self.dropdownCopySource:SetCallback("OnValueChanged", function() self:OnCopySelectionChanged() end) self.groupCopyProfile:AddChild(self.dropdownCopySource) self.dropdownCopyDestination = AceGUI:Create("Dropdown") self.dropdownCopyDestination:SetRelativeWidth(0.35) self.dropdownCopyDestination:SetLabel("Copy to:") self.dropdownCopyDestination:SetCallback("OnValueChanged", function() self:OnCopySelectionChanged() end) self.groupCopyProfile:AddChild(self.dropdownCopyDestination) self.buttonCopyProfile = AceGUI:Create("Button") self.buttonCopyProfile:SetRelativeWidth(0.3) self.buttonCopyProfile:SetText("Copy Settings") self.buttonCopyProfile:SetCallback("OnClick", function() self:OnCopyProfile() end) self.buttonCopyProfile:SetDisabled(true) self.groupCopyProfile:AddChild(self.buttonCopyProfile) container:AddChild(self.groupCopyProfile) self.groupDeleteProfile = AceGUI:Create("InlineGroup") self.groupDeleteProfile:SetRelativeWidth(0.4) self.groupDeleteProfile:SetLayout("Flow") self.groupDeleteProfile:SetTitle("Delete Profile") self.dropdownDeleteProfile = AceGUI:Create("Dropdown") self.dropdownDeleteProfile:SetRelativeWidth(0.6) self.dropdownDeleteProfile:SetLabel("Delete profile:") self.dropdownDeleteProfile:SetCallback("OnValueChanged", function(_, _, value) self.buttonDeleteProfile:SetDisabled(value == nil) end) self.groupDeleteProfile:AddChild(self.dropdownDeleteProfile) self.buttonDeleteProfile = AceGUI:Create("Button") self.buttonDeleteProfile:SetRelativeWidth(0.4) self.buttonDeleteProfile:SetText("Delete") self.buttonDeleteProfile:SetDisabled(true) self.buttonDeleteProfile:SetCallback("OnClick", function() self:OnDeleteProfile() end) self.groupDeleteProfile:AddChild(self.buttonDeleteProfile) container:AddChild(self.groupDeleteProfile) MoveIt.GUI:CreateDivider(container) self.labelActiveProfile = AceGUI:Create("Label") self.labelActiveProfile:SetRelativeWidth(1) self.labelActiveProfile:SetText("Active Profile: " .. MoveIt.Utils.ColouredText(MoveIt.db:GetCurrentProfile(), "ffff00") .. " - Switching profile or modifying/deleting the active profile will reload the UI") container:AddChild(self.labelActiveProfile) self:UpdateProfileLists() end function MoveIt.GUI.Profile:OnSwitchProfile() local profileName = self.dropdownProfileSelect:GetValue() MoveIt.db:SetProfile(profileName) ReloadUI() end function MoveIt.GUI.Profile:OnNewProfileNameEntered(value) if value ~= "" and MoveIt.db.profiles[value] == nil then self.buttonCreateProfile:SetDisabled(false) return end self.buttonCreateProfile:SetDisabled(true) end function MoveIt.GUI.Profile:OnCreateProfile() local profileName = self.editboxCreateProfile:GetText() MoveIt.db.profiles[profileName] = {} MoveIt.GUI:StatusMessage("Profile '" .. profileName .. "' created") self.editboxCreateProfile:SetText("") self.buttonCreateProfile:SetDisabled(true) self:UpdateProfileLists() end function MoveIt.GUI.Profile:UpdateProfileLists() local profileList = self:GetProfileList() local userProfileList, userProfileCount = self:GetProfileList(true) self.dropdownProfileSelect:SetList(profileList) self.dropdownProfileSelect:SetValue(MoveIt.db:GetCurrentProfile(), false) if userProfileCount == 0 then self.dropdownProfileSelect:SetDisabled(true) self.dropdownCopySource:SetDisabled(true) self.dropdownCopyDestination:SetDisabled(true) self.dropdownDeleteProfile:SetDisabled(true) else self.dropdownProfileSelect:SetDisabled(false) self.dropdownCopySource:SetDisabled(false) self.dropdownCopyDestination:SetDisabled(false) self.dropdownDeleteProfile:SetDisabled(false) self.dropdownCopySource:SetList(profileList) self.dropdownCopyDestination:SetList(profileList) self.dropdownDeleteProfile:SetList(userProfileList) self.dropdownCopySource:SetValue("") self.dropdownCopyDestination:SetValue("") self.dropdownDeleteProfile:SetValue("") end end function MoveIt.GUI.Profile:OnCopySelectionChanged() local copySource = self.dropdownCopySource:GetValue() local copyDestination = self.dropdownCopyDestination:GetValue() self.buttonCopyProfile:SetDisabled(copySource == copyDestination or copySource == nil or copyDestination == nil) end function MoveIt.GUI.Profile:OnCopyProfile() local copySource = self.dropdownCopySource:GetValue() local copyDestination = self.dropdownCopyDestination:GetValue() MoveIt.db.profiles[copyDestination] = MoveIt.db.profiles[copySource] if copyDestination == MoveIt.db:GetCurrentProfile() then ReloadUI() end MoveIt.GUI:StatusMessage("Profile copied") self.buttonCopyProfile:SetDisabled(true) end function MoveIt.GUI.Profile:GetProfileList(excludeDefault) local profileList = {} local count = 0 for k, _ in pairs(MoveIt.db.profiles) do if not (excludeDefault and k == "Default") then profileList[k] = k count = count + 1 end end return profileList, count end function MoveIt.GUI.Profile:OnDeleteProfile() local deleteProfile = self.dropdownDeleteProfile:GetValue() MoveIt.db.profiles[deleteProfile] = nil if deleteProfile == MoveIt.db:GetCurrentProfile() then MoveIt.db:SetProfile("Default") ReloadUI() end self:UpdateProfileLists() self.dropdownDeleteProfile:SetValue("") self.buttonDeleteProfile:SetDisabled(true) MoveIt.GUI:StatusMessage("Profile '" .. deleteProfile .. "' deleted") end