ToxicTheBoss

wally ui lib

May 21st, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.41 KB | None | 0 0
  1. local library = {
  2. windowcount = 0;
  3. }
  4.  
  5. local dragger = {};
  6. local resizer = {};
  7.  
  8. do
  9. local mouse = game:GetService("Players").LocalPlayer:GetMouse();
  10. local inputService = game:GetService('UserInputService');
  11. local heartbeat = game:GetService("RunService").Heartbeat;
  12. -- // credits to Ririchi / Inori for this cute drag function :)
  13. function dragger.new(frame)
  14. local s, event = pcall(function()
  15. return frame.MouseEnter
  16. end)
  17.  
  18. if s then
  19. frame.Active = true;
  20.  
  21. event:connect(function()
  22. local input = frame.InputBegan:connect(function(key)
  23. if key.UserInputType == Enum.UserInputType.MouseButton1 then
  24. local objectPosition = Vector2.new(mouse.X - frame.AbsolutePosition.X, mouse.Y - frame.AbsolutePosition.Y);
  25. while heartbeat:wait() and inputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
  26. frame:TweenPosition(UDim2.new(0, mouse.X - objectPosition.X + (frame.Size.X.Offset * frame.AnchorPoint.X), 0, mouse.Y - objectPosition.Y + (frame.Size.Y.Offset * frame.AnchorPoint.Y)), 'Out', 'Quad', 0.1, true);
  27. end
  28. end
  29. end)
  30.  
  31. local leave;
  32. leave = frame.MouseLeave:connect(function()
  33. input:disconnect();
  34. leave:disconnect();
  35. end)
  36. end)
  37. end
  38. end
  39.  
  40. function resizer.new(p, s)
  41. p:GetPropertyChangedSignal('AbsoluteSize'):connect(function()
  42. s.Size = UDim2.new(s.Size.X.Scale, s.Size.X.Offset, s.Size.Y.Scale, p.AbsoluteSize.Y);
  43. end)
  44. end
  45. end
  46.  
  47.  
  48. local defaults = {
  49. txtcolor = Color3.fromRGB(255, 255, 255),
  50. underline = Color3.fromRGB(0, 255, 140),
  51. barcolor = Color3.fromRGB(40, 40, 40),
  52. bgcolor = Color3.fromRGB(30, 30, 30),
  53. }
  54.  
  55. function library:Create(class, props)
  56. local object = Instance.new(class);
  57.  
  58. for i, prop in next, props do
  59. if i ~= "Parent" then
  60. object[i] = prop;
  61. end
  62. end
  63.  
  64. object.Parent = props.Parent;
  65. return object;
  66. end
  67.  
  68. function library:CreateWindow(options)
  69. assert(options.text, "no name");
  70. local window = {
  71. count = 0;
  72. toggles = {},
  73. closed = false;
  74. }
  75.  
  76. local options = options or {};
  77. setmetatable(options, {__index = defaults})
  78.  
  79. self.windowcount = self.windowcount + 1;
  80.  
  81. library.gui = library.gui or self:Create("ScreenGui", {Name = "UILibrary", Parent = game:GetService("CoreGui")})
  82. window.frame = self:Create("Frame", {
  83. Name = options.text;
  84. Parent = self.gui,
  85. Active = true,
  86. BackgroundTransparency = 0,
  87. Size = UDim2.new(0, 190, 0, 30),
  88. Position = UDim2.new(0, (15 + ((200 * self.windowcount) - 200)), 0, 15),
  89. BackgroundColor3 = options.barcolor,
  90. BorderSizePixel = 0;
  91. })
  92.  
  93. window.background = self:Create('Frame', {
  94. Name = 'Background';
  95. Parent = window.frame,
  96. BorderSizePixel = 0;
  97. BackgroundColor3 = options.bgcolor,
  98. Position = UDim2.new(0, 0, 1, 0),
  99. Size = UDim2.new(1, 0, 0, 25),
  100. ClipsDescendants = true;
  101. })
  102.  
  103. window.container = self:Create('Frame', {
  104. Name = 'Container';
  105. Parent = window.frame,
  106. BorderSizePixel = 0;
  107. BackgroundColor3 = options.bgcolor,
  108. Position = UDim2.new(0, 0, 1, 0),
  109. Size = UDim2.new(1, 0, 0, 25),
  110. ClipsDescendants = true;
  111. })
  112.  
  113. window.organizer = self:Create('UIListLayout', {
  114. Name = 'Sorter';
  115. --Padding = UDim.new(0, 0);
  116. SortOrder = Enum.SortOrder.LayoutOrder;
  117. Parent = window.container;
  118. })
  119.  
  120. window.padder = self:Create('UIPadding', {
  121. Name = 'Padding';
  122. PaddingLeft = UDim.new(0, 10);
  123. PaddingTop = UDim.new(0, 5);
  124. Parent = window.container;
  125. })
  126.  
  127. self:Create("Frame", {
  128. Name = 'Underline';
  129. Size = UDim2.new(1, 0, 0, 1),
  130. Position = UDim2.new(0, 0, 1, -1),
  131. BorderSizePixel = 0;
  132. BackgroundColor3 = options.underline;
  133. Parent = window.frame
  134. })
  135.  
  136. local togglebutton = self:Create("TextButton", {
  137. Name = 'Toggle';
  138. ZIndex = 2,
  139. BackgroundTransparency = 1;
  140. Position = UDim2.new(1, -25, 0, 0),
  141. Size = UDim2.new(0, 25, 1, 0),
  142. Text = "-",
  143. TextSize = 17,
  144. TextColor3 = options.txtcolor,
  145. Font = Enum.Font.SourceSans;
  146. Parent = window.frame,
  147. });
  148.  
  149. togglebutton.MouseButton1Click:connect(function()
  150. window.closed = not window.closed
  151. togglebutton.Text = (window.closed and "+" or "-")
  152. if window.closed then
  153. window:Resize(true, UDim2.new(1, 0, 0, 0))
  154. else
  155. window:Resize(true)
  156. end
  157. end)
  158.  
  159. self:Create("TextLabel", {
  160. Size = UDim2.new(1, 0, 1, 0),
  161. BackgroundTransparency = 1;
  162. BorderSizePixel = 0;
  163. TextColor3 = options.txtcolor,
  164. TextColor3 = (options.bartextcolor or Color3.fromRGB(255, 255, 255));
  165. TextSize = 17,
  166. Font = Enum.Font.SourceSansSemibold;
  167. Text = options.text or "window",
  168. Name = "Window",
  169. Parent = window.frame,
  170. })
  171.  
  172. do
  173. dragger.new(window.frame)
  174. resizer.new(window.background, window.container);
  175. end
  176.  
  177. local function getSize()
  178. local ySize = 0;
  179. for i, object in next, window.container:GetChildren() do
  180. if (not object:IsA('UIListLayout')) and (not object:IsA('UIPadding')) then
  181. ySize = ySize + object.AbsoluteSize.Y
  182. end
  183. end
  184. return UDim2.new(1, 0, 0, ySize + 10)
  185. end
  186.  
  187. function window:Resize(tween, change)
  188. local size = change or getSize()
  189. self.container.ClipsDescendants = true;
  190.  
  191. if tween then
  192. self.background:TweenSize(size, "Out", "Sine", 0.5, true)
  193. else
  194. self.background.Size = size
  195. end
  196. end
  197.  
  198. function window:AddToggle(text, callback)
  199. self.count = self.count + 1
  200.  
  201. callback = callback or function() end
  202. local label = library:Create("TextLabel", {
  203. Text = text,
  204. Size = UDim2.new(1, -10, 0, 20);
  205. --Position = UDim2.new(0, 5, 0, ((20 * self.count) - 20) + 5),
  206. BackgroundTransparency = 1;
  207. TextColor3 = Color3.fromRGB(255, 255, 255);
  208. TextXAlignment = Enum.TextXAlignment.Left;
  209. LayoutOrder = self.Count;
  210. TextSize = 16,
  211. Font = Enum.Font.SourceSans,
  212. Parent = self.container;
  213. })
  214.  
  215. local button = library:Create("TextButton", {
  216. Text = "OFF",
  217. TextColor3 = Color3.fromRGB(255, 25, 25),
  218. BackgroundTransparency = 1;
  219. Position = UDim2.new(1, -25, 0, 0),
  220. Size = UDim2.new(0, 25, 1, 0),
  221. TextSize = 17,
  222. Font = Enum.Font.SourceSansSemibold,
  223. Parent = label;
  224. })
  225.  
  226. button.MouseButton1Click:connect(function()
  227. self.toggles[text] = (not self.toggles[text])
  228. button.TextColor3 = (self.toggles[text] and Color3.fromRGB(0, 255, 140) or Color3.fromRGB(255, 25, 25))
  229. button.Text =(self.toggles[text] and "ON" or "OFF")
  230.  
  231. callback(self.toggles[text])
  232. end)
  233.  
  234. self:Resize()
  235. return button
  236. end
  237.  
  238. function window:AddBox(text, callback)
  239. self.count = self.count + 1
  240. callback = callback or function() end
  241.  
  242. local box = library:Create("TextBox", {
  243. PlaceholderText = text,
  244. Size = UDim2.new(1, -10, 0, 20);
  245. --Position = UDim2.new(0, 5, 0, ((20 * self.count) - 20) + 5),
  246. BackgroundTransparency = 0.75;
  247. BackgroundColor3 = options.boxcolor,
  248. TextColor3 = Color3.fromRGB(255, 255, 255);
  249. TextXAlignment = Enum.TextXAlignment.Center;
  250. TextSize = 16,
  251. Text = "",
  252. Font = Enum.Font.SourceSans,
  253. LayoutOrder = self.Count;
  254. BorderSizePixel = 0;
  255. Parent = self.container;
  256. })
  257.  
  258. box.FocusLost:connect(function(...)
  259. callback(box, ...)
  260. end)
  261.  
  262. self:Resize()
  263. return box
  264. end
  265.  
  266. function window:AddButton(text, callback)
  267. self.count = self.count + 1
  268.  
  269. callback = callback or function() end
  270. local button = library:Create("TextButton", {
  271. Text = text,
  272. Size = UDim2.new(1, -10, 0, 20);
  273. --Position = UDim2.new(0, 5, 0, ((20 * self.count) - 20) + 5),
  274. BackgroundTransparency = 1;
  275. TextColor3 = Color3.fromRGB(255, 255, 255);
  276. TextXAlignment = Enum.TextXAlignment.Left;
  277. TextSize = 16,
  278. Font = Enum.Font.SourceSans,
  279. LayoutOrder = self.Count;
  280. Parent = self.container;
  281. })
  282.  
  283. button.MouseButton1Click:connect(callback)
  284. self:Resize()
  285. return button
  286. end
  287.  
  288. function window:AddLabel(text)
  289. self.count = self.count + 1;
  290.  
  291. local tSize = game:GetService('TextService'):GetTextSize(text, 16, Enum.Font.SourceSans, Vector2.new(math.huge, math.huge))
  292.  
  293. local button = library:Create("TextLabel", {
  294. Text = text,
  295. Size = UDim2.new(1, -10, 0, tSize.Y + 5);
  296. TextScaled = false;
  297. BackgroundTransparency = 1;
  298. TextColor3 = Color3.fromRGB(255, 255, 255);
  299. TextXAlignment = Enum.TextXAlignment.Left;
  300. TextSize = 16,
  301. Font = Enum.Font.SourceSans,
  302. LayoutOrder = self.Count;
  303. Parent = self.container;
  304. })
  305.  
  306. self:Resize()
  307. return button
  308. end
  309.  
  310. function window:AddDropdown(options, callback)
  311. self.count = self.count + 1
  312. local default = options[1] or "";
  313.  
  314. callback = callback or function() end
  315. local dropdown = library:Create("TextLabel", {
  316. Size = UDim2.new(1, -10, 0, 20);
  317. BackgroundTransparency = 0.75;
  318. BackgroundColor3 = options.boxcolor,
  319. TextColor3 = Color3.fromRGB(255, 255, 255);
  320. TextXAlignment = Enum.TextXAlignment.Center;
  321. TextSize = 16,
  322. Text = default,
  323. Font = Enum.Font.SourceSans,
  324. BorderSizePixel = 0;
  325. LayoutOrder = self.Count;
  326. Parent = self.container;
  327. })
  328.  
  329. local button = library:Create("ImageButton",{
  330. BackgroundTransparency = 1;
  331. Image = 'rbxassetid://3234893186';
  332. Size = UDim2.new(0, 18, 1, 0);
  333. Position = UDim2.new(1, -20, 0, 0);
  334. Parent = dropdown;
  335. })
  336.  
  337. local frame;
  338.  
  339. local function isInGui(frame)
  340. local mloc = game:GetService('UserInputService'):GetMouseLocation();
  341. local mouse = Vector2.new(mloc.X, mloc.Y - 36);
  342.  
  343. local x1, x2 = frame.AbsolutePosition.X, frame.AbsolutePosition.X + frame.AbsoluteSize.X;
  344. local y1, y2 = frame.AbsolutePosition.Y, frame.AbsolutePosition.Y + frame.AbsoluteSize.Y;
  345.  
  346. return (mouse.X >= x1 and mouse.X <= x2) and (mouse.Y >= y1 and mouse.Y <= y2)
  347. end
  348.  
  349. local function count(t)
  350. local c = 0;
  351. for i, v in next, t do
  352. c = c + 1
  353. end
  354. return c;
  355. end
  356.  
  357. button.MouseButton1Click:connect(function()
  358. if count(options) == 0 then
  359. return
  360. end
  361.  
  362. if frame then
  363. frame:Destroy();
  364. frame = nil;
  365. end
  366.  
  367. self.container.ClipsDescendants = false;
  368.  
  369. frame = library:Create('Frame', {
  370. Position = UDim2.new(0, 0, 1, 0);
  371. BackgroundColor3 = Color3.fromRGB(40, 40, 40);
  372. Size = UDim2.new(0, dropdown.AbsoluteSize.X, 0, (count(options) * 21));
  373. BorderSizePixel = 0;
  374. Parent = dropdown;
  375. ClipsDescendants = true;
  376. ZIndex = 2;
  377. })
  378.  
  379. library:Create('UIListLayout', {
  380. Name = 'Layout';
  381. Parent = frame;
  382. })
  383.  
  384. for i, option in next, options do
  385. local selection = library:Create('TextButton', {
  386. Text = option;
  387. BackgroundColor3 = Color3.fromRGB(40, 40, 40);
  388. TextColor3 = Color3.fromRGB(255, 255, 255);
  389. BorderSizePixel = 0;
  390. TextSize = 16;
  391. Font = Enum.Font.SourceSans;
  392. Size = UDim2.new(1, 0, 0, 21);
  393. Parent = frame;
  394. ZIndex = 2;
  395. })
  396.  
  397. selection.MouseButton1Click:connect(function()
  398. dropdown.Text = option;
  399. callback(option)
  400. frame.Size = UDim2.new(1, 0, 0, 0);
  401. game:GetService('Debris'):AddItem(frame, 0.1)
  402. end)
  403. end
  404. end);
  405.  
  406. game:GetService('UserInputService').InputBegan:connect(function(m)
  407. if m.UserInputType == Enum.UserInputType.MouseButton1 then
  408. if frame and (not isInGui(frame)) then
  409. game:GetService('Debris'):AddItem(frame);
  410. end
  411. end
  412. end)
  413.  
  414. callback(default);
  415. self:Resize()
  416. return {
  417. Refresh = function(self, array)
  418. game:GetService('Debris'):AddItem(frame);
  419. options = array
  420. dropdown.Text = options[1];
  421. end
  422. }
  423. end;
  424.  
  425.  
  426. return window
  427. end
  428.  
  429. return library
Add Comment
Please, Sign In to add comment