Hydrax_Animatez

d

Dec 11th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.95 KB | None | 0 0
  1. local coreGui = game:GetService("CoreGui")
  2.  
  3. local camera = workspace.CurrentCamera
  4. local drawingUI = Instance.new("ScreenGui")
  5. drawingUI.Name = "Drawing | Xeno"
  6. drawingUI.IgnoreGuiInset = true
  7. drawingUI.DisplayOrder = 0x7fffffff
  8. drawingUI.Parent = coreGui
  9.  
  10. local drawingIndex = 0
  11. local drawingFontsEnum = {
  12. [0] = Font.fromEnum(Enum.Font.Roboto),
  13. [1] = Font.fromEnum(Enum.Font.Legacy),
  14. [2] = Font.fromEnum(Enum.Font.SourceSans),
  15. [3] = Font.fromEnum(Enum.Font.RobotoMono)
  16. }
  17.  
  18. local function getFontFromIndex(fontIndex)
  19. return drawingFontsEnum[fontIndex]
  20. end
  21.  
  22. local function convertTransparency(transparency)
  23. return math.clamp(1 - transparency, 0, 1)
  24. end
  25.  
  26. local baseDrawingObj = setmetatable({
  27. Visible = true,
  28. ZIndex = 0,
  29. Transparency = 1,
  30. Color = Color3.new(),
  31. Remove = function(self)
  32. setmetatable(self, nil)
  33. end,
  34. Destroy = function(self)
  35. setmetatable(self, nil)
  36. end,
  37. SetProperty = function(self, index, value)
  38. if self[index] ~= nil then
  39. self[index] = value
  40. else
  41. warn("Attempted to set invalid property: " .. tostring(index))
  42. end
  43. end,
  44. GetProperty = function(self, index)
  45. if self[index] ~= nil then
  46. return self[index]
  47. else
  48. warn("Attempted to get invalid property: " .. tostring(index))
  49. return nil
  50. end
  51. end,
  52. SetParent = function(self, parent)
  53. self.Parent = parent
  54. end
  55. }, {
  56. __add = function(t1, t2)
  57. local result = {}
  58. for index, value in pairs(t1) do
  59. result[index] = value
  60. end
  61. for index, value in pairs(t2) do
  62. result[index] = value
  63. end
  64. return result
  65. end
  66. })
  67.  
  68. local DrawingLib = {}
  69. DrawingLib.Fonts = {
  70. ["UI"] = 0,
  71. ["System"] = 1,
  72. ["Plex"] = 2,
  73. ["Monospace"] = 3
  74. }
  75.  
  76. function DrawingLib.new(drawingType)
  77. drawingIndex += 1
  78. if drawingType == "Line" then
  79. return DrawingLib.createLine()
  80. elseif drawingType == "Text" then
  81. return DrawingLib.createText()
  82. elseif drawingType == "Circle" then
  83. return DrawingLib.createCircle()
  84. elseif drawingType == "Square" then
  85. return DrawingLib.createSquare()
  86. elseif drawingType == "Image" then
  87. return DrawingLib.createImage()
  88. elseif drawingType == "Quad" then
  89. return DrawingLib.createQuad()
  90. elseif drawingType == "Triangle" then
  91. return DrawingLib.createTriangle()
  92. elseif drawingType == "Frame" then
  93. return DrawingLib.createFrame()
  94. elseif drawingType == "ScreenGui" then
  95. return DrawingLib.createScreenGui()
  96. elseif drawingType == "TextButton" then
  97. return DrawingLib.createTextButton()
  98. elseif drawingType == "TextLabel" then
  99. return DrawingLib.createTextLabel()
  100. elseif drawingType == "TextBox" then
  101. return DrawingLib.createTextBox()
  102. else
  103. error("Invalid drawing type: " .. tostring(drawingType))
  104. end
  105. end
  106.  
  107. function DrawingLib.createLine()
  108. local lineObj = ({
  109. From = Vector2.zero,
  110. To = Vector2.zero,
  111. Thickness = 1
  112. } + baseDrawingObj)
  113.  
  114. local lineFrame = Instance.new("Frame")
  115. lineFrame.Name = drawingIndex
  116. lineFrame.AnchorPoint = Vector2.new(0.5, 0.5)
  117. lineFrame.BorderSizePixel = 0
  118.  
  119. lineFrame.Parent = drawingUI
  120. return setmetatable({Parent = drawingUI}, {
  121. __newindex = function(_, index, value)
  122. if lineObj[index] == nil then
  123. warn("Invalid property: " .. tostring(index))
  124. return
  125. end
  126.  
  127. if index == "From" or index == "To" then
  128. local direction = (index == "From" and lineObj.To or value) - (index == "From" and value or lineObj.From)
  129. local center = (lineObj.To + lineObj.From) / 2
  130. local distance = direction.Magnitude
  131. local theta = math.deg(math.atan2(direction.Y, direction.X))
  132.  
  133. lineFrame.Position = UDim2.fromOffset(center.X, center.Y)
  134. lineFrame.Rotation = theta
  135. lineFrame.Size = UDim2.fromOffset(distance, lineObj.Thickness)
  136. elseif index == "Thickness" then
  137. lineFrame.Size = UDim2.fromOffset((lineObj.To - lineObj.From).Magnitude, value)
  138. elseif index == "Visible" then
  139. lineFrame.Visible = value
  140. elseif index == "ZIndex" then
  141. lineFrame.ZIndex = value
  142. elseif index == "Transparency" then
  143. lineFrame.BackgroundTransparency = convertTransparency(value)
  144. elseif index == "Color" then
  145. lineFrame.BackgroundColor3 = value
  146. elseif index == "Parent" then
  147. lineFrame.Parent = value
  148. end
  149. lineObj[index] = value
  150. end,
  151. __index = function(self, index)
  152. if index == "Remove" or index == "Destroy" then
  153. return function()
  154. lineFrame:Destroy()
  155. lineObj:Remove()
  156. end
  157. end
  158. return lineObj[index]
  159. end,
  160. __tostring = function() return "Drawing" end
  161. })
  162. end
  163.  
  164. function DrawingLib.createText()
  165. local textObj = ({
  166. Text = "",
  167. Font = DrawingLib.Fonts.UI,
  168. Size = 0,
  169. Position = Vector2.zero,
  170. Center = false,
  171. Outline = false,
  172. OutlineColor = Color3.new()
  173. } + baseDrawingObj)
  174.  
  175. local textLabel, uiStroke = Instance.new("TextLabel"), Instance.new("UIStroke")
  176. textLabel.Name = drawingIndex
  177. textLabel.AnchorPoint = Vector2.new(0.5, 0.5)
  178. textLabel.BorderSizePixel = 0
  179. textLabel.BackgroundTransparency = 1
  180.  
  181. local function updateTextPosition()
  182. local textBounds = textLabel.TextBounds
  183. local offset = textBounds / 2
  184. textLabel.Size = UDim2.fromOffset(textBounds.X, textBounds.Y)
  185. textLabel.Position = UDim2.fromOffset(textObj.Position.X + (not textObj.Center and offset.X or 0), textObj.Position.Y + offset.Y)
  186. end
  187.  
  188. textLabel:GetPropertyChangedSignal("TextBounds"):Connect(updateTextPosition)
  189.  
  190. uiStroke.Thickness = 1
  191. uiStroke.Enabled = textObj.Outline
  192. uiStroke.Color = textObj.Color
  193.  
  194. textLabel.Parent, uiStroke.Parent = drawingUI, textLabel
  195.  
  196. return setmetatable({Parent = drawingUI}, {
  197. __newindex = function(_, index, value)
  198. if textObj[index] == nil then
  199. warn("Invalid property: " .. tostring(index))
  200. return
  201. end
  202.  
  203. if index == "Text" then
  204. textLabel.Text = value
  205. elseif index == "Font" then
  206. textLabel.FontFace = getFontFromIndex(math.clamp(value, 0, 3))
  207. elseif index == "Size" then
  208. textLabel.TextSize = value
  209. elseif index == "Position" then
  210. updateTextPosition()
  211. elseif index == "Center" then
  212. textLabel.Position = UDim2.fromOffset((value and camera.ViewportSize / 2 or textObj.Position).X, textObj.Position.Y)
  213. elseif index == "Outline" then
  214. uiStroke.Enabled = value
  215. elseif index == "OutlineColor" then
  216. uiStroke.Color = value
  217. elseif index == "Visible" then
  218. textLabel.Visible = value
  219. elseif index == "ZIndex" then
  220. textLabel.ZIndex = value
  221. elseif index == "Transparency" then
  222. local transparency = convertTransparency(value)
  223. textLabel.TextTransparency = transparency
  224. uiStroke.Transparency = transparency
  225. elseif index == "Color" then
  226. textLabel.TextColor3 = value
  227. elseif index == "Parent" then
  228. textLabel.Parent = value
  229. end
  230. textObj[index] = value
  231. end,
  232. __index = function(self, index)
  233. if index == "Remove" or index == "Destroy" then
  234. return function()
  235. textLabel:Destroy()
  236. textObj:Remove()
  237. end
  238. elseif index == "TextBounds" then
  239. return textLabel.TextBounds
  240. end
  241. return textObj[index]
  242. end,
  243. __tostring = function() return "Drawing" end
  244. })
  245. end
  246.  
  247. function DrawingLib.createCircle()
  248. local circleObj = ({
  249. Radius = 150,
  250. Position = Vector2.zero,
  251. Thickness = 0.7,
  252. Filled = false
  253. } + baseDrawingObj)
  254.  
  255. local circleFrame, uiCorner, uiStroke = Instance.new("Frame"), Instance.new("UICorner"), Instance.new("UIStroke")
  256. circleFrame.Name = drawingIndex
  257. circleFrame.AnchorPoint = Vector2.new(0.5, 0.5)
  258. circleFrame.BorderSizePixel = 0
  259.  
  260. uiCorner.CornerRadius = UDim.new(1, 0)
  261. circleFrame.Size = UDim2.fromOffset(circleObj.Radius, circleObj.Radius)
  262. uiStroke.Thickness = circleObj.Thickness
  263. uiStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
  264.  
  265. circleFrame.Parent, uiCorner.Parent, uiStroke.Parent = drawingUI, circleFrame, circleFrame
  266.  
  267. return setmetatable({Parent = drawingUI}, {
  268. __newindex = function(_, index, value)
  269. if circleObj[index] == nil then
  270. warn("Invalid property: " .. tostring(index))
  271. return
  272. end
  273.  
  274. if index == "Radius" then
  275. local radius = value * 2
  276. circleFrame.Size = UDim2.fromOffset(radius, radius)
  277. elseif index == "Position" then
  278. circleFrame.Position = UDim2.fromOffset(value.X, value.Y)
  279. elseif index == "Thickness" then
  280. uiStroke.Thickness = math.clamp(value, 0.6, 0x7fffffff)
  281. elseif index == "Filled" then
  282. circleFrame.BackgroundTransparency = value and convertTransparency(circleObj.Transparency) or 1
  283. uiStroke.Enabled = not value
  284. elseif index == "Visible" then
  285. circleFrame.Visible = value
  286. elseif index == "ZIndex" then
  287. circleFrame.ZIndex = value
  288. elseif index == "Transparency" then
  289. local transparency = convertTransparency(value)
  290. circleFrame.BackgroundTransparency = circleObj.Filled and transparency or 1
  291. uiStroke.Transparency = transparency
  292. elseif index == "Color" then
  293. circleFrame.BackgroundColor3 = value
  294. uiStroke.Color = value
  295. elseif index == "Parent" then
  296. circleFrame.Parent = value
  297. end
  298. circleObj[index] = value
  299. end,
  300. __index = function(self, index)
  301. if index == "Remove" or index == "Destroy" then
  302. return function()
  303. circleFrame:Destroy()
  304. circleObj:Remove()
  305. end
  306. end
  307. return circleObj[index]
  308. end,
  309. __tostring = function() return "Drawing" end
  310. })
  311. end
  312.  
  313. function DrawingLib.createSquare()
  314. local squareObj = ({
  315. Size = Vector2.zero,
  316. Position = Vector2.zero,
  317. Thickness = 0.7,
  318. Filled = false
  319. } + baseDrawingObj)
  320.  
  321. local squareFrame, uiStroke = Instance.new("Frame"), Instance.new("UIStroke")
  322. squareFrame.Name = drawingIndex
  323. squareFrame.BorderSizePixel = 0
  324.  
  325. squareFrame.Parent, uiStroke.Parent = drawingUI, squareFrame
  326.  
  327. return setmetatable({Parent = drawingUI}, {
  328. __newindex = function(_, index, value)
  329. if squareObj[index] == nil then
  330. warn("Invalid property: " .. tostring(index))
  331. return
  332. end
  333.  
  334. if index == "Size" then
  335. squareFrame.Size = UDim2.fromOffset(value.X, value.Y)
  336. elseif index == "Position" then
  337. squareFrame.Position = UDim2.fromOffset(value.X, value.Y)
  338. elseif index == "Thickness" then
  339. uiStroke.Thickness = math.clamp(value, 0.6, 0x7fffffff)
  340. elseif index == "Filled" then
  341. squareFrame.BackgroundTransparency = value and convertTransparency(squareObj.Transparency) or 1
  342. uiStroke.Enabled = not value
  343. elseif index == "Visible" then
  344. squareFrame.Visible = value
  345. elseif index == "ZIndex" then
  346. squareFrame.ZIndex = value
  347. elseif index == "Transparency" then
  348. local transparency = convertTransparency(value)
  349. squareFrame.BackgroundTransparency = squareObj.Filled and transparency or 1
  350. uiStroke.Transparency = transparency
  351. elseif index == "Color" then
  352. squareFrame.BackgroundColor3 = value
  353. uiStroke.Color = value
  354. elseif index == "Parent" then
  355. squareFrame.Parent = value
  356. end
  357. squareObj[index] = value
  358. end,
  359. __index = function(self, index)
  360. if index == "Remove" or index == "Destroy" then
  361. return function()
  362. squareFrame:Destroy()
  363. squareObj:Remove()
  364. end
  365. end
  366. return squareObj[index]
  367. end,
  368. __tostring = function() return "Drawing" end
  369. })
  370. end
  371.  
  372. function DrawingLib.createImage()
  373. local imageObj = ({
  374. Data = "",
  375. DataURL = "rbxassetid://0",
  376. Size = Vector2.zero,
  377. Position = Vector2.zero
  378. } + baseDrawingObj)
  379.  
  380. local imageFrame = Instance.new("ImageLabel")
  381. imageFrame.Name = drawingIndex
  382. imageFrame.BorderSizePixel = 0
  383. imageFrame.ScaleType = Enum.ScaleType.Stretch
  384. imageFrame.BackgroundTransparency = 1
  385.  
  386. imageFrame.Parent = drawingUI
  387.  
  388. return setmetatable({Parent = drawingUI}, {
  389. __newindex = function(_, index, value)
  390. if imageObj[index] == nil then
  391. warn("Invalid property: " .. tostring(index))
  392. return
  393. end
  394.  
  395. if index == "Data" then
  396. elseif index == "DataURL" then
  397. imageFrame.Image = value
  398. elseif index == "Size" then
  399. imageFrame.Size = UDim2.fromOffset(value.X, value.Y)
  400. elseif index == "Position" then
  401. imageFrame.Position = UDim2.fromOffset(value.X, value.Y)
  402. elseif index == "Visible" then
  403. imageFrame.Visible = value
  404. elseif index == "ZIndex" then
  405. imageFrame.ZIndex = value
  406. elseif index == "Transparency" then
  407. imageFrame.ImageTransparency = convertTransparency(value)
  408. elseif index == "Color" then
  409. imageFrame.ImageColor3 = value
  410. elseif index == "Parent" then
  411. imageFrame.Parent = value
  412. end
  413. imageObj[index] = value
  414. end,
  415. __index = function(self, index)
  416. if index == "Remove" or index == "Destroy" then
  417. return function()
  418. imageFrame:Destroy()
  419. imageObj:Remove()
  420. end
  421. elseif index == "Data" then
  422. return nil
  423. end
  424. return imageObj[index]
  425. end,
  426. __tostring = function() return "Drawing" end
  427. })
  428. end
  429.  
  430. function DrawingLib.createQuad()
  431. local quadObj = ({
  432. PointA = Vector2.zero,
  433. PointB = Vector2.zero,
  434. PointC = Vector2.zero,
  435. PointD = Vector2.zero,
  436. Thickness = 1,
  437. Filled = false
  438. } + baseDrawingObj)
  439.  
  440. local _linePoints = {
  441. A = DrawingLib.createLine(),
  442. B = DrawingLib.createLine(),
  443. C = DrawingLib.createLine(),
  444. D = DrawingLib.createLine()
  445. }
  446.  
  447. local fillFrame = Instance.new("Frame")
  448. fillFrame.Name = drawingIndex .. "_Fill"
  449. fillFrame.BorderSizePixel = 0
  450. fillFrame.BackgroundTransparency = quadObj.Transparency
  451. fillFrame.BackgroundColor3 = quadObj.Color
  452. fillFrame.ZIndex = quadObj.ZIndex
  453. fillFrame.Visible = quadObj.Visible and quadObj.Filled
  454.  
  455. fillFrame.Parent = drawingUI
  456.  
  457. return setmetatable({Parent = drawingUI}, {
  458. __newindex = function(_, index, value)
  459. if quadObj[index] == nil then
  460. warn("Invalid property: " .. tostring(index))
  461. return
  462. end
  463.  
  464. if index == "PointA" then
  465. _linePoints.A.From = value
  466. _linePoints.B.To = value
  467. elseif index == "PointB" then
  468. _linePoints.B.From = value
  469. _linePoints.C.To = value
  470. elseif index == "PointC" then
  471. _linePoints.C.From = value
  472. _linePoints.D.To = value
  473. elseif index == "PointD" then
  474. _linePoints.D.From = value
  475. _linePoints.A.To = value
  476. elseif index == "Thickness" or index == "Visible" or index == "Color" or index == "ZIndex" then
  477. for _, linePoint in pairs(_linePoints) do
  478. linePoint[index] = value
  479. end
  480. if index == "Visible" then
  481. fillFrame.Visible = value and quadObj.Filled
  482. elseif index == "Color" then
  483. fillFrame.BackgroundColor3 = value
  484. elseif index == "ZIndex" then
  485. fillFrame.ZIndex = value
  486. end
  487. elseif index == "Filled" then
  488. for _, linePoint in pairs(_linePoints) do
  489. linePoint.Transparency = value and 1 or quadObj.Transparency
  490. end
  491. fillFrame.Visible = value
  492. elseif index == "Parent" then
  493. fillFrame.Parent = value
  494. end
  495. quadObj[index] = value
  496. end,
  497. __index = function(self, index)
  498. if index == "Remove" or index == "Destroy" then
  499. return function()
  500. for _, linePoint in pairs(_linePoints) do
  501. linePoint:Remove()
  502. end
  503. fillFrame:Destroy()
  504. quadObj:Remove()
  505. end
  506. end
  507. return quadObj[index]
  508. end,
  509. __tostring = function() return "Drawing" end
  510. })
  511. end
  512.  
  513. function DrawingLib.createTriangle()
  514. local triangleObj = ({
  515. PointA = Vector2.zero,
  516. PointB = Vector2.zero,
  517. PointC = Vector2.zero,
  518. Thickness = 1,
  519. Filled = false
  520. } + baseDrawingObj)
  521.  
  522. local _linePoints = {
  523. A = DrawingLib.createLine(),
  524. B = DrawingLib.createLine(),
  525. C = DrawingLib.createLine()
  526. }
  527.  
  528. local fillFrame = Instance.new("Frame")
  529. fillFrame.Name = drawingIndex .. "_Fill"
  530. fillFrame.BorderSizePixel = 0
  531. fillFrame.BackgroundTransparency = triangleObj.Transparency
  532. fillFrame.BackgroundColor3 = triangleObj.Color
  533. fillFrame.ZIndex = triangleObj.ZIndex
  534. fillFrame.Visible = triangleObj.Visible and triangleObj.Filled
  535.  
  536. fillFrame.Parent = drawingUI
  537.  
  538. return setmetatable({Parent = drawingUI}, {
  539. __newindex = function(_, index, value)
  540. if triangleObj[index] == nil then
  541. warn("Invalid property: " .. tostring(index))
  542. return
  543. end
  544.  
  545. if index == "PointA" then
  546. _linePoints.A.From = value
  547. _linePoints.B.To = value
  548. elseif index == "PointB" then
  549. _linePoints.B.From = value
  550. _linePoints.C.To = value
  551. elseif index == "PointC" then
  552. _linePoints.C.From = value
  553. _linePoints.A.To = value
  554. elseif index == "Thickness" or index == "Visible" or index == "Color" or index == "ZIndex" then
  555. for _, linePoint in pairs(_linePoints) do
  556. linePoint[index] = value
  557. end
  558. if index == "Visible" then
  559. fillFrame.Visible = value and triangleObj.Filled
  560. elseif index == "Color" then
  561. fillFrame.BackgroundColor3 = value
  562. elseif index == "ZIndex" then
  563. fillFrame.ZIndex = value
  564. end
  565. elseif index == "Filled" then
  566. for _, linePoint in pairs(_linePoints) do
  567. linePoint.Transparency = value and 1 or triangleObj.Transparency
  568. end
  569. fillFrame.Visible = value
  570. elseif index == "Parent" then
  571. fillFrame.Parent = value
  572. end
  573. triangleObj[index] = value
  574. end,
  575. __index = function(self, index)
  576. if index == "Remove" or index == "Destroy" then
  577. return function()
  578. for _, linePoint in pairs(_linePoints) do
  579. linePoint:Remove()
  580. end
  581. fillFrame:Destroy()
  582. triangleObj:Remove()
  583. end
  584. end
  585. return triangleObj[index]
  586. end,
  587. __tostring = function() return "Drawing" end
  588. })
  589. end
  590.  
  591. function DrawingLib.createFrame()
  592. local frameObj = ({
  593. Size = UDim2.new(0, 100, 0, 100),
  594. Position = UDim2.new(0, 0, 0, 0),
  595. Color = Color3.new(1, 1, 1),
  596. Transparency = 0,
  597. Visible = true,
  598. ZIndex = 1
  599. } + baseDrawingObj)
  600.  
  601. local frame = Instance.new("Frame")
  602. frame.Name = drawingIndex
  603. frame.Size = frameObj.Size
  604. frame.Position = frameObj.Position
  605. frame.BackgroundColor3 = frameObj.Color
  606. frame.BackgroundTransparency = convertTransparency(frameObj.Transparency)
  607. frame.Visible = frameObj.Visible
  608. frame.ZIndex = frameObj.ZIndex
  609. frame.BorderSizePixel = 0
  610.  
  611. frame.Parent = drawingUI
  612.  
  613. return setmetatable({Parent = drawingUI}, {
  614. __newindex = function(_, index, value)
  615. if frameObj[index] == nil then
  616. warn("Invalid property: " .. tostring(index))
  617. return
  618. end
  619.  
  620. if index == "Size" then
  621. frame.Size = value
  622. elseif index == "Position" then
  623. frame.Position = value
  624. elseif index == "Color" then
  625. frame.BackgroundColor3 = value
  626. elseif index == "Transparency" then
  627. frame.BackgroundTransparency = convertTransparency(value)
  628. elseif index == "Visible" then
  629. frame.Visible = value
  630. elseif index == "ZIndex" then
  631. frame.ZIndex = value
  632. elseif index == "Parent" then
  633. frame.Parent = value
  634. end
  635. frameObj[index] = value
  636. end,
  637. __index = function(self, index)
  638. if index == "Remove" or index == "Destroy" then
  639. return function()
  640. frame:Destroy()
  641. frameObj:Remove()
  642. end
  643. end
  644. return frameObj[index]
  645. end,
  646. __tostring = function() return "Drawing" end
  647. })
  648. end
  649.  
  650. function DrawingLib.createScreenGui()
  651. local screenGuiObj = ({
  652. IgnoreGuiInset = true,
  653. DisplayOrder = 0,
  654. ResetOnSpawn = true,
  655. ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
  656. Enabled = true
  657. } + baseDrawingObj)
  658.  
  659. local screenGui = Instance.new("ScreenGui")
  660. screenGui.Name = drawingIndex
  661. screenGui.IgnoreGuiInset = screenGuiObj.IgnoreGuiInset
  662. screenGui.DisplayOrder = screenGuiObj.DisplayOrder
  663. screenGui.ResetOnSpawn = screenGuiObj.ResetOnSpawn
  664. screenGui.ZIndexBehavior = screenGuiObj.ZIndexBehavior
  665. screenGui.Enabled = screenGuiObj.Enabled
  666.  
  667. screenGui.Parent = coreGui
  668.  
  669. return setmetatable({Parent = coreGui}, {
  670. __newindex = function(_, index, value)
  671. if screenGuiObj[index] == nil then
  672. warn("Invalid property: " .. tostring(index))
  673. return
  674. end
  675.  
  676. if index == "IgnoreGuiInset" then
  677. screenGui.IgnoreGuiInset = value
  678. elseif index == "DisplayOrder" then
  679. screenGui.DisplayOrder = value
  680. elseif index == "ResetOnSpawn" then
  681. screenGui.ResetOnSpawn = value
  682. elseif index == "ZIndexBehavior" then
  683. screenGui.ZIndexBehavior = value
  684. elseif index == "Enabled" then
  685. screenGui.Enabled = value
  686. elseif index == "Parent" then
  687. screenGui.Parent = value
  688. end
  689. screenGuiObj[index] = value
  690. end,
  691. __index = function(self, index)
  692. if index == "Remove" or index == "Destroy" then
  693. return function()
  694. screenGui:Destroy()
  695. screenGuiObj:Remove()
  696. end
  697. end
  698. return screenGuiObj[index]
  699. end,
  700. __tostring = function() return "Drawing" end
  701. })
  702. end
  703.  
  704.  
  705.  
  706. function DrawingLib.createTextButton()
  707. local buttonObj = ({
  708. Text = "Button",
  709. Font = DrawingLib.Fonts.UI,
  710. Size = 20,
  711. Position = UDim2.new(0, 0, 0, 0),
  712. Color = Color3.new(1, 1, 1),
  713. BackgroundColor = Color3.new(0.2, 0.2, 0.2),
  714. Transparency = 0,
  715. Visible = true,
  716. ZIndex = 1,
  717. MouseButton1Click = nil
  718. } + baseDrawingObj)
  719.  
  720. local button = Instance.new("TextButton")
  721. button.Name = drawingIndex
  722. button.Text = buttonObj.Text
  723. button.FontFace = getFontFromIndex(buttonObj.Font)
  724. button.TextSize = buttonObj.Size
  725. button.Position = buttonObj.Position
  726. button.TextColor3 = buttonObj.Color
  727. button.BackgroundColor3 = buttonObj.BackgroundColor
  728. button.BackgroundTransparency = convertTransparency(buttonObj.Transparency)
  729. button.Visible = buttonObj.Visible
  730. button.ZIndex = buttonObj.ZIndex
  731.  
  732. button.Parent = drawingUI
  733.  
  734. local buttonEvents = {}
  735.  
  736. return setmetatable({
  737. Parent = drawingUI,
  738. Connect = function(_, eventName, callback)
  739. if eventName == "MouseButton1Click" then
  740. if buttonEvents["MouseButton1Click"] then
  741. buttonEvents["MouseButton1Click"]:Disconnect()
  742. end
  743. buttonEvents["MouseButton1Click"] = button.MouseButton1Click:Connect(callback)
  744. else
  745. warn("Invalid event: " .. tostring(eventName))
  746. end
  747. end
  748. }, {
  749. __newindex = function(_, index, value)
  750. if buttonObj[index] == nil then
  751. warn("Invalid property: " .. tostring(index))
  752. return
  753. end
  754.  
  755. if index == "Text" then
  756. button.Text = value
  757. elseif index == "Font" then
  758. button.FontFace = getFontFromIndex(math.clamp(value, 0, 3))
  759. elseif index == "Size" then
  760. button.TextSize = value
  761. elseif index == "Position" then
  762. button.Position = value
  763. elseif index == "Color" then
  764. button.TextColor3 = value
  765. elseif index == "BackgroundColor" then
  766. button.BackgroundColor3 = value
  767. elseif index == "Transparency" then
  768. button.BackgroundTransparency = convertTransparency(value)
  769. elseif index == "Visible" then
  770. button.Visible = value
  771. elseif index == "ZIndex" then
  772. button.ZIndex = value
  773. elseif index == "Parent" then
  774. button.Parent = value
  775. elseif index == "MouseButton1Click" then
  776. if typeof(value) == "function" then
  777. if buttonEvents["MouseButton1Click"] then
  778. buttonEvents["MouseButton1Click"]:Disconnect()
  779. end
  780. buttonEvents["MouseButton1Click"] = button.MouseButton1Click:Connect(value)
  781. else
  782. warn("Invalid value for MouseButton1Click: expected function, got " .. typeof(value))
  783. end
  784. end
  785. buttonObj[index] = value
  786. end,
  787. __index = function(self, index)
  788. if index == "Remove" or index == "Destroy" then
  789. return function()
  790. button:Destroy()
  791. buttonObj:Remove()
  792. end
  793. end
  794. return buttonObj[index]
  795. end,
  796. __tostring = function() return "Drawing" end
  797. })
  798. end
  799.  
  800. function DrawingLib.createTextLabel()
  801. local labelObj = ({
  802. Text = "Label",
  803. Font = DrawingLib.Fonts.UI,
  804. Size = 20,
  805. Position = UDim2.new(0, 0, 0, 0),
  806. Color = Color3.new(1, 1, 1),
  807. BackgroundColor = Color3.new(0.2, 0.2, 0.2),
  808. Transparency = 0,
  809. Visible = true,
  810. ZIndex = 1
  811. } + baseDrawingObj)
  812.  
  813. local label = Instance.new("TextLabel")
  814. label.Name = drawingIndex
  815. label.Text = labelObj.Text
  816. label.FontFace = getFontFromIndex(labelObj.Font)
  817. label.TextSize = labelObj.Size
  818. label.Position = labelObj.Position
  819. label.TextColor3 = labelObj.Color
  820. label.BackgroundColor3 = labelObj.BackgroundColor
  821. label.BackgroundTransparency = convertTransparency(labelObj.Transparency)
  822. label.Visible = labelObj.Visible
  823. label.ZIndex = labelObj.ZIndex
  824.  
  825. label.Parent = drawingUI
  826.  
  827. return setmetatable({Parent = drawingUI}, {
  828. __newindex = function(_, index, value)
  829. if labelObj[index] == nil then
  830. warn("Invalid property: " .. tostring(index))
  831. return
  832. end
  833.  
  834. if index == "Text" then
  835. label.Text = value
  836. elseif index == "Font" then
  837. label.FontFace = getFontFromIndex(math.clamp(value, 0, 3))
  838. elseif index == "Size" then
  839. label.TextSize = value
  840. elseif index == "Position" then
  841. label.Position = value
  842. elseif index == "Color" then
  843. label.TextColor3 = value
  844. elseif index == "BackgroundColor" then
  845. label.BackgroundColor3 = value
  846. elseif index == "Transparency" then
  847. label.BackgroundTransparency = convertTransparency(value)
  848. elseif index == "Visible" then
  849. label.Visible = value
  850. elseif index == "ZIndex" then
  851. label.ZIndex = value
  852. elseif index == "Parent" then
  853. label.Parent = value
  854. end
  855. labelObj[index] = value
  856. end,
  857. __index = function(self, index)
  858. if index == "Remove" or index == "Destroy" then
  859. return function()
  860. label:Destroy()
  861. labelObj:Remove()
  862. end
  863. end
  864. return labelObj[index]
  865. end,
  866. __tostring = function() return "Drawing" end
  867. })
  868. end
  869.  
  870. function DrawingLib.createTextBox()
  871. local boxObj = ({
  872. Text = "",
  873. Font = DrawingLib.Fonts.UI,
  874. Size = 20,
  875. Position = UDim2.new(0, 0, 0, 0),
  876. Color = Color3.new(1, 1, 1),
  877. BackgroundColor = Color3.new(0.2, 0.2, 0.2),
  878. Transparency = 0,
  879. Visible = true,
  880. ZIndex = 1
  881. } + baseDrawingObj)
  882.  
  883. local textBox = Instance.new("TextBox")
  884. textBox.Name = drawingIndex
  885. textBox.Text = boxObj.Text
  886. textBox.FontFace = getFontFromIndex(boxObj.Font)
  887. textBox.TextSize = boxObj.Size
  888. textBox.Position = boxObj.Position
  889. textBox.TextColor3 = boxObj.Color
  890. textBox.BackgroundColor3 = boxObj.BackgroundColor
  891. textBox.BackgroundTransparency = convertTransparency(boxObj.Transparency)
  892. textBox.Visible = boxObj.Visible
  893. textBox.ZIndex = boxObj.ZIndex
  894.  
  895. textBox.Parent = drawingUI
  896.  
  897. return setmetatable({Parent = drawingUI}, {
  898. __newindex = function(_, index, value)
  899. if boxObj[index] == nil then
  900. warn("Invalid property: " .. tostring(index))
  901. return
  902. end
  903.  
  904. if index == "Text" then
  905. textBox.Text = value
  906. elseif index == "Font" then
  907. textBox.FontFace = getFontFromIndex(math.clamp(value, 0, 3))
  908. elseif index == "Size" then
  909. textBox.TextSize = value
  910. elseif index == "Position" then
  911. textBox.Position = value
  912. elseif index == "Color" then
  913. textBox.TextColor3 = value
  914. elseif index == "BackgroundColor" then
  915. textBox.BackgroundColor3 = value
  916. elseif index == "Transparency" then
  917. textBox.BackgroundTransparency = convertTransparency(value)
  918. elseif index == "Visible" then
  919. textBox.Visible = value
  920. elseif index == "ZIndex" then
  921. textBox.ZIndex = value
  922. elseif index == "Parent" then
  923. textBox.Parent = value
  924. end
  925. boxObj[index] = value
  926. end,
  927. __index = function(self, index)
  928. if index == "Remove" or index == "Destroy" then
  929. return function()
  930. textBox:Destroy()
  931. boxObj:Remove()
  932. end
  933. end
  934. return boxObj[index]
  935. end,
  936. __tostring = function() return "Drawing" end
  937. })
  938. end
  939.  
  940. local drawingFunctions = {}
  941.  
  942. function drawingFunctions.isrenderobj(drawingObj)
  943. local success, isrenderobj = pcall(function()
  944. return drawingObj.Parent == drawingUI
  945. end)
  946. if not success then return false end
  947. return isrenderobj
  948. end
  949.  
  950. function drawingFunctions.getrenderproperty(drawingObj, property)
  951. local success, drawingProperty = pcall(function()
  952. return drawingObj[property]
  953. end)
  954. if not success then return end
  955.  
  956. if drawingProperty ~= nil then
  957. return drawingProperty
  958. end
  959. end
  960.  
  961. function drawingFunctions.setrenderproperty(drawingObj, property, value)
  962. assert(drawingFunctions.getrenderproperty(drawingObj, property), "'" .. tostring(property) .. "' is not a valid property of " .. tostring(drawingObj) .. ", " .. tostring(typeof(drawingObj)))
  963. drawingObj[property] = value
  964. end
  965.  
  966. function drawingFunctions.cleardrawcache()
  967. for _, drawing in drawingUI:GetDescendants() do
  968. drawing:Remove()
  969. end
  970. end
  971.  
  972. return {Drawing = DrawingLib, functions = drawingFunctions}
Add Comment
Please, Sign In to add comment