Skip to content

Commit

Permalink
Address "Convert" doing nothing with UI Editor tool in use #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Quenty committed Jul 14, 2018
1 parent 8968404 commit 1583007
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 90 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.sublime-workspace
*.rbxl

archive/*.*
Binary file added buildPlugin.rbxl
Binary file not shown.
96 changes: 56 additions & 40 deletions src/UI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ local HttpService = game:GetService("HttpService")
local function TrimString(str, pattern)
pattern = pattern or "%s";
-- %S is whitespaces
-- When we find the first non space character defined by ^%s
-- we yank out anything in between that and the end of the string
-- Everything else is replaced with %1 which is essentially nothing
-- When we find the first non space character defined by ^%s
-- we yank out anything in between that and the end of the string
-- Everything else is replaced with %1 which is essentially nothing

-- Credit Sorcus, Modified by Quenty
return (str:gsub("^"..pattern.."*(.-)"..pattern.."*$", "%1"))
end
end

local UIBase = {}
UIBase.ClassName = "UIBase"
Expand Down Expand Up @@ -101,6 +101,18 @@ function Checkbox.new(Gui)
end)
self:UpdateRender()

self.Maid:GiveTask(self.Gui.InputBegan:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
self.Gui.BackgroundTransparency = 0
end
end))

self.Maid:GiveTask(self.Gui.InputEnded:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
self.Gui.BackgroundTransparency = 1
end
end))

return self
end

Expand Down Expand Up @@ -181,7 +193,7 @@ end
function DropDownButton:UpdateRender()
local Desired = Color3.new(1, 1, 1)
if self.IsSelected.Value then
Desired = Color3.new(90/255, 142/255, 243/255)
Desired = Color3.new(90/255, 142/255, 243/255)
end

if self.MouseOver then
Expand Down Expand Up @@ -258,9 +270,7 @@ function DropDownFilter.new(Gui)
self.AutoselectTop = Signal.new()

self.Maid.VisibleChanged = self.VisibleChanged:connect(function(IsVisible, DoNotAnimate)
if IsVisible then
--self.Gui:CaptureFocus()
else
if not IsVisible then
self.Gui:ReleaseFocus(false)
end
end)
Expand Down Expand Up @@ -416,7 +426,7 @@ function DropDownPane.new(Gui)


self.Maid.AutoselectTop = self.FilterBox.AutoselectTop:connect(function()
if self.Buttons[1] then
if self.Buttons[1] then
self.Selected.Value = self.Buttons[1]
self:Hide()
end
Expand Down Expand Up @@ -444,7 +454,7 @@ function DropDownPane:UpdateRender()
if self:IsVisible() then
self.Gui.Size = UDim2.new(self.Gui.Size.X, UDim.new(0, math.min(self.MaxHeight, YHeight + 80)))
else
self.Gui.Size = UDim2.new(self.Gui.Size.X, UDim.new(0, self.Gui.Parent.Size.Y.Offset))
self.Gui.Size = UDim2.new(self.Gui.Size.X, UDim.new(1, 0))
end
self.Container.Size = UDim2.new(self.Gui.Size.X, UDim.new(0, YHeight))
end
Expand All @@ -458,7 +468,7 @@ function DropDownPane:GetButtonFromData(Data)

local Gui = self.Template:Clone()
Gui.Visible = false
Gui.Name = tostring(Data.ClassName) .. "Button"
Gui.Name = tostring(Data.ClassName) .. "Button"
Gui.Parent = self.Template.Parent

local Button = DropDownButton.new(Gui)
Expand Down Expand Up @@ -547,35 +557,35 @@ function CheckboxPane:AddCheckbox(Data)

local CheckboxMaid = MakeMaid()

local Checkbox = Checkbox.new(Gui)
local checkbox = Checkbox.new(Gui)
:WithData(Data)
:WithRenderData({
Name = Data.Name;
})
CheckboxMaid.Checkbox = Checkbox
CheckboxMaid:GiveTask(checkbox)

CheckboxMaid.Changed = Checkbox.Checked.Changed:connect(function()
CheckboxMaid:GiveTask(checkbox.Checked.Changed:connect(function()
self.SettingsChanged:fire()
end)
end))

if Data.DefaultValue then
Checkbox.Checked.Value = Data.DefaultValue
checkbox.Checked.Value = Data.DefaultValue
end

Checkbox:Show()
checkbox:Show()

self.Maid[Checkbox] = CheckboxMaid
table.insert(self.Checkboxes, Checkbox)
self.Maid[checkbox] = CheckboxMaid
table.insert(self.Checkboxes, checkbox)

self:UpdateRender()

return Checkbox
return checkbox
end

function CheckboxPane:GetSettings()
local Settings = {}
for _, Checkbox in pairs(self.Checkboxes) do
Settings[Checkbox.Data.SerializeName] = Checkbox.Checked.Value
for _, checkbox in pairs(self.Checkboxes) do
Settings[checkbox.Data.SerializeName] = checkbox.Checked.Value
end
return Settings
end
Expand All @@ -597,9 +607,9 @@ Pane.ClassName = "Pane"
function Pane.new(Gui, Selection)
local self = setmetatable(UIBase.new(Gui), Pane)

self.Done = Signal.new()
-- self.Done = Signal.new()
self.ConversionStarting = Signal.new()

self.ConversionEnding = Signal.new()

self.Selection = Selection or error("No selection")
self.Content = self.Gui.Content
Expand Down Expand Up @@ -637,10 +647,10 @@ function Pane.new(Gui, Selection)
self:UpdateRender()
end)

self.Maid.ScreenGui = self.Gui.Parent
self.Maid.CloseButtonClick = self.Gui.Header.CloseButton.MouseButton1Click:connect(function()
self.Done:fire()
end)
-- self.Maid.ScreenGui = self.Gui.Parent
-- self.Maid.CloseButtonClick = self.Gui.Header.CloseButton.MouseButton1Click:connect(function()
-- self.Done:fire()
-- end)


self.Maid.RetryButton = self.RetryButton.MouseButton1Click:connect(function()
Expand All @@ -649,14 +659,9 @@ function Pane.new(Gui, Selection)
self:UpdateRender()
end)

self.Maid.SelectionChanged = self.Selection.SelectionChanged:connect(function()
self.Maid:GiveTask(self.DropDown.Pane.Selected.Changed:connect(function()
self:UpdateRender()
end)

self.Maid.SelectedClassChanged = self.DropDown.Pane.Selected.Changed:connect(function()
self:UpdateRender()
end)

end))

self.Maid.ConvertButtonClick = self.ConvertButton.MouseButton1Click:connect(function()
self:UpdateRender()
Expand All @@ -673,6 +678,16 @@ function Pane.new(Gui, Selection)
self.DropDown:SetVisible(IsVisible)

self:UpdateRender()

if IsVisible then
self.Maid.SelectionChangedEvent = self.Selection.SelectionChanged:connect(function()
if self:IsVisible() then
self:UpdateRender()
end
end)
else
self.Maid.SelectionChangedEvent = nil
end
end)

self.Maid.FilterChanged = self.DropDown.Pane.FilterBox.CurrentText.Changed:connect(function(CurrentText)
Expand Down Expand Up @@ -703,10 +718,10 @@ function Pane:UpdateRender()
self.WarningPane.Visible = true
self.Content.Visible = false

if not self.WasNoHttp then
self.WasNoHttp = true
self:SelectHttpService()
end
-- if not self.WasNoHttp then
-- self.WasNoHttp = true
-- self:SelectHttpService()
-- end

IsAvailable = false
else
Expand Down Expand Up @@ -785,9 +800,10 @@ function Pane:DoConversion()
end

self.Selection:Set(NewSelection)
self.ConversionEnding:fire()
else
print("[Converter] - No selection or class name")
end
end

return Pane
return Pane
117 changes: 68 additions & 49 deletions src/init.server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ local HttpService = game:GetService("HttpService")
local IS_DEBUG_MODE = script:IsDescendantOf(game)
if IS_DEBUG_MODE then
warn("Starting plugin in debug mode")
while not Players.LocalPlayer do
wait(0.05)
end
end

local MakeMaid = require(script:WaitForChild("Maid")).MakeMaid

local Converter = require(script:WaitForChild("Converter"))
local UI = require(script:WaitForChild("UI"))
local Signal = require(script:WaitForChild("Signal"))

local ScreenGui = script.Parent:WaitForChild("ScreenGui")
ScreenGui.Enabled = false
local MainMaid = MakeMaid()

local Selection do
if not IS_DEBUG_MODE then
Expand Down Expand Up @@ -87,76 +89,93 @@ if IS_DEBUG_MODE then
plugin = FakeMetatable.new(plugin)
end

local IsActive = false
local Converter = Converter.new(IS_DEBUG_MODE)
local converter = Converter.new(IS_DEBUG_MODE)
:WithPluginForCache(plugin)

local function Deactivate(Button)
-- Deactivates the plugin
MainMaid.ActiveMaid = nil
IsActive = false
end

local function Activate(Button)
local screenGui
do
-- Activates the plugin
if IS_DEBUG_MODE then
screenGui = Instance.new("ScreenGui")
screenGui.Name = "Converter"
screenGui.Parent = Players.LocalPlayer.PlayerGui
screenGui.Enabled = false
else
local info = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
false,
false,
250,
320,
200,
240
)
screenGui = plugin:CreateDockWidgetPluginGui("Quenty_Class_Converter", info)
screenGui.Title = "Quenty's Class Converter Plugin"
end

local Maid = MakeMaid()
IsActive = true
local function initializeGui()
local main = ScreenGui.Main:Clone()
main.Parent = screenGui

local NewScreenGui = ScreenGui:Clone()
NewScreenGui.Enabled = true
NewScreenGui.Parent = IS_DEBUG_MODE and game.Players.LocalPlayer.PlayerGui or game.CoreGui
local ui = UI.new(main, Selection)
:WithConverter(converter)

local MainUI = UI.new(NewScreenGui.Main, Selection)
:WithConverter(Converter)
Maid.MainUI = MainUI
screenGui:GetPropertyChangedSignal("Enabled"):Connect(function()
ui:SetVisible(screenGui.Enabled)
if not screenGui.Enabled then
ui.DropDown:SetVisible(false)
end
end)
ui:SetVisible(screenGui.Enabled)

Maid.Done = MainUI.Done:connect(function()
Deactivate(Button)
end)
if not IS_DEBUG_MODE then
local ChangeHistoryService = game:GetService("ChangeHistoryService")
ui.ConversionStarting:connect(function()
ChangeHistoryService:SetWaypoint("Conversion_" .. HttpService:GenerateGUID(true))
end)
ui.ConversionEnding:connect(function()
ChangeHistoryService:SetWaypoint("Conversion_" .. HttpService:GenerateGUID(true))
end)

if Button then
Button:SetActive(true)
end

Maid.Cleanup = function()
if Button then
Button:SetActive(false)
screenGui.WindowFocusReleased:Connect(function()
ui.DropDown:SetVisible(false)
end)
end

IsActive = false
end

MainUI:Show()

if not IS_DEBUG_MODE then
local ChangeHistoryService = game:GetService("ChangeHistoryService")
MainUI.ConversionStarting:connect(function()
ChangeHistoryService:SetWaypoint("Conversion_" .. HttpService:GenerateGUID(true))
if screenGui.Enabled then
initializeGui()
return
else
-- Wait to load GUI
local connection
connection = screenGui:GetPropertyChangedSignal("Enabled"):Connect(function()
connection:disconnect()
initializeGui()
end)
end

MainMaid.ActiveMaid = Maid
end



if not IS_DEBUG_MODE then
local Toolbar = plugin:CreateToolbar("Object")
local toolbar = plugin:CreateToolbar("Object")

local Button = Toolbar:CreateButton(
"Class Converter",
local button = toolbar:CreateButton(
"Class converter",
"Converts classes from one item to another",
"rbxassetid://906772526"
)

Button.Click:connect(function()
if not IsActive then
Activate(Button)
else
Deactivate(Button)
end
screenGui:GetPropertyChangedSignal("Enabled"):Connect(function()
button:SetActive(screenGui.Enabled)
end)
button:SetActive(screenGui.Enabled)

button.Click:connect(function()
screenGui.Enabled = not screenGui.Enabled
end)
else
Activate()
screenGui.Enabled = true
end

0 comments on commit 1583007

Please sign in to comment.