Skip to content

Commit

Permalink
Its terrible but assetswidgets is now ported to roact
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarber committed May 25, 2018
1 parent 6670353 commit 00e98e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Models/Core/MainModule/UI/Components/AssetsWidget.lua
Expand Up @@ -13,7 +13,7 @@ local AssetsWidget = Roact.Component:extend("AssetsWidget")
function AssetsWidget:init(props)
self.state = {
Plugin = props.Plugin,
CurrentCategory = "NPC",
CurrentCategory = nil,
Assets = {
NPC = {
-- Frog
Expand All @@ -37,17 +37,21 @@ end
function AssetsWidget:render()
local items = {}
local propsType = "Model"
if self.state.CurrentCategory == "Tools" then
propsType = "Tool"
end
for _, v in pairs(self.state.Assets[self.state.CurrentCategory]) do
table.insert(items, c(AssetItem, {
ID = v,
Plugin = self.Plugin,
Type = propsType,
}))
-- Only add try to add asset items if a category is chosen
if self.state.CurrentCategory then
for _, v in pairs(self.state.Assets[self.state.CurrentCategory]) do
table.insert(items, c(AssetItem, {
ID = v,
Plugin = self.Plugin,
Type = propsType,
}))
end
end
return c("Frame", {
Expand All @@ -66,7 +70,11 @@ function AssetsWidget:render()
"Utilities",
"Tools",
},
CurrentItem = self.state.CurrentCategory,
ChangeFn = function(item)
self:setState({
CurrentCategory = item,
})
end
})
}),
AssetList = c("ScrollingFrame", {
Expand Down
9 changes: 9 additions & 0 deletions src/Models/Core/MainModule/UI/Components/Dropdown.lua
Expand Up @@ -14,6 +14,7 @@ function Dropdown:init(props)
self.state = {
Open = props.Open or false,
Items = props.Items or {},
ChangeFn = props.ChangeFn,
CurrentItem = nil,
}
end
Expand All @@ -26,8 +27,13 @@ function Dropdown:render()
BorderSizePixel = 0,
Text = item,
Size = UDim2.new(1, 0, 0, 20),
ZIndex = 5,
[Roact.Event.MouseButton1Click] = function(_)
if self.state.ChangeFn ~= nil then
self.state.ChangeFn(item)
end
self:setState({
CurrentItem = item,
Open = false,
Expand All @@ -39,6 +45,7 @@ function Dropdown:render()
return c("TextButton", {
Size = UDim2.new(0, 200, 0, 30),
Text = "",
ZIndex = 5,
[Roact.Event.MouseButton1Click] = function(_)
self:setState({
Expand All @@ -64,6 +71,7 @@ function Dropdown:render()
Font = Enum.Font.SourceSans,
TextSize = 18,
TextScaled = true,
ZIndex = 6,
}, {
c("UITextSizeConstraint", {
MaxTextSize = 18,
Expand All @@ -73,6 +81,7 @@ function Dropdown:render()
Visible = self.state.Open,
Size = UDim2.new(1, 0, 0, 100),
Position = UDim2.new(0, 0, 1, 0),
ZIndex = 5,
}, {
c("UIListLayout"),
unpack(items),
Expand Down

0 comments on commit 00e98e8

Please sign in to comment.