Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 57 additions & 48 deletions src/Components/popup.luau
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,64 @@ export type popup = {
}
local popup = {} :: popup

local function getColors(valueType: string, theme): {BackgroundColor: Color3, TextColor: Color3, ShadowColor: Color3, ButtonGlowColor: Color3}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theme should be typed, using RedonUI.theme.theme as the type

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I'll fix that

if valueType == "primary" then
return {
BackgroundColor = theme.colors.sky,
TextColor = theme.colors.crust,
ShadowColor = theme.colors.sky,
ButtonGlowColor = theme.colors.sky,
}
elseif valueType == "danger" then
return {
BackgroundColor = theme.colors.red,
TextColor = theme.colors.crust,
ShadowColor = theme.colors.red,
ButtonGlowColor = theme.colors.red,
}
else
return {
BackgroundColor = theme.colors.crust,
TextColor = theme.colors.text,
ShadowColor = theme.colors.crust,
ButtonGlowColor = theme.colors.maroon,
}
end
end

local function cleanupPopups(self)
for _, popupInstance in { self.currentPopup, self.currentCustomPopup } do
if popupInstance then
if popupInstance:IsA("Instance") then
popupInstance:Destroy()
else
popupInstance.Parent = nil
end
end
end
self.currentPopup = nil
self.currentCustomPopup = nil
end

function popup.addPopup(self, scope, props)
if self.currentContainer == nil then
return
end
if self.currentPopup ~= nil then
self.currentPopup:Destroy()
self.currentPopup = nil
end
if self.currentCustomPopup ~= nil then
self.currentCustomPopup.Parent = nil
self.currentCustomPopup = nil
end

cleanupPopups(self)

local currentContainer = scope.peek(self.currentContainer)
local currentTheme = RedonUI.theme.theme:now()
local newPopup
local keybinds = {}

for _, action in ipairs(props.actions) do
if action.keybind ~= nil then
keybinds[action.keybind] = action.callback
end
end
self.keybinds = keybinds

newPopup = self.parentScope:base {
AutomaticSize = Enum.AutomaticSize.XY,
BackgroundColor3 = currentTheme.colors.base,
Expand Down Expand Up @@ -130,46 +166,26 @@ function popup.addPopup(self, scope, props)
SortOrder = Enum.SortOrder.LayoutOrder,
},

--selene: allow(shadowing)
self.parentScope:ForValues(props.actions, function(_, newScope: types.Scope, value: action)
local BackgroundColor = if value.type == "primary"
then currentTheme.colors.sky
elseif value.type == "danger" then currentTheme.colors.red
else currentTheme.colors.crust
local TextColor = if value.type == "standard"
then currentTheme.colors.text
else currentTheme.colors.crust
local ShadowColor = if value.type == "primary"
then currentTheme.colors.sky
elseif value.type == "danger" then currentTheme.colors.red
else currentTheme.colors.crust
local ButtonGlowColor = if value.type == "primary"
then if currentTheme.colors.white == Color3.new(1, 1, 1)
then currentTheme.colors.text
else currentTheme.colors.base
else currentTheme.colors.maroon
local colors = getColors(value.type, currentTheme)

return newScope:textButton {
Size = UDim2.fromOffset(175, 35),
Text = value.text,
TextScaled = true,
MaxTextSize = 25,
TextColor3 = TextColor,
BackgroundColor3 = BackgroundColor,
ButtonGlowColor3 = ButtonGlowColor,
ShadowColor3 = ShadowColor,
ButtonGlow = if value.type == "standard" then false else true,
TextColor3 = colors.TextColor,
BackgroundColor3 = colors.BackgroundColor,
ButtonGlowColor3 = colors.ButtonGlowColor,
ShadowColor3 = colors.ShadowColor,
ButtonGlow = value.type ~= "standard",
Shadow = true,
Border = 2,
CornerRadius = UDim.new(0, 10),
[Fusion.OnEvent "Activated"] = function()
local mt = getmetatable(scope :: any)
if typeof(mt) == "table" and mt._FUSION_POISONED then
return
end
Comment on lines -165 to -168
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this get deleted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to the other comment.

value.callback(newPopup)
end :: unknown,
LayoutOrder = value.key,

Reactive = true,
ZIndex = 5002,
}
Expand All @@ -178,6 +194,7 @@ function popup.addPopup(self, scope, props)
},
},
}

self.enabled:set(true)
newPopup.Parent = currentContainer
self.currentPopup = newPopup
Expand All @@ -187,14 +204,9 @@ function popup.customPopup(self, scope, child)
if self.currentContainer == nil then
return
end
if self.currentPopup ~= nil then
self.currentPopup:Destroy()
self.currentPopup = nil
end
if self.currentCustomPopup ~= nil then
self.currentCustomPopup.Parent = nil
self.currentCustomPopup = nil
end

cleanupPopups(self)

local currentContainer = scope.peek(self.currentContainer)
self.currentCustomPopup = child
self.enabled:set(true)
Expand All @@ -210,6 +222,7 @@ function popup.container(self, scope)
self.parentScope = scope
local currentTheme = RedonUI.theme.theme:now()
self.enabled = scope:Value(false)

local container = scope:base {
Size = UDim2.fromScale(2, 2),
AnchorPoint = Vector2.new(0.5, 0.5),
Expand All @@ -231,11 +244,7 @@ function popup.container(self, scope)
ZIndex = 5001,

[Fusion.OnEvent "InputBegan"] = function(input)
if self.currentPopup ~= nil and self.keybinds[input.KeyCode] ~= nil then
local mt = getmetatable(scope :: any)
if typeof(mt) == "table" and mt._FUSION_POISONED then
return
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this get deleted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops probably overlooked this on accident as well for the other one too

if input.UserInputType == Enum.UserInputType.Keyboard and self.currentPopup ~= nil and self.keybinds[input.KeyCode] then
self.keybinds[input.KeyCode](self.currentPopup)
end
end :: unknown,
Expand Down