DolphinX

Custom Wallys Lib

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