SHOW:
|
|
- or go back to the newest paste.
1 | -- | |
2 | -- | |
3 | -- | |
4 | ||
5 | local function ResizeSystem (frame, mouse, options) | |
6 | if (not options) then | |
7 | options = { | |
8 | MAX_WIDTH = 500, | |
9 | MIN_WIDTH = 50, | |
10 | ||
11 | MAX_HEIGHT = 100, | |
12 | MIN_HEIGHT = 50, | |
13 | ||
14 | ENABLED_DIRECTIONS = { | |
15 | UP = true, | |
16 | RIGHT = true | |
17 | } | |
18 | }; | |
19 | end; | |
20 | if (not mouse) then | |
21 | mouse = game:service 'Players'.localPlayer:GetMouse(); | |
22 | end; | |
23 | ||
24 | options.MouseIconState = false; | |
25 | options.MouseButton1Down = false; | |
26 | options.MouseIconPrevious = mouse.Icon; | |
27 | ||
28 | options.ResizeBindable = Instance.new 'BindableEvent'; | |
29 | options.MouseBindable = Instance.new 'BindableEvent'; | |
30 | ||
31 | options.OnInputBegan = game:service 'UserInputService'.InputBegan:connect (function (obj) | |
32 | if (obj and obj.UserInputType == Enum.UserInputType.MouseButton1) then | |
33 | options.MouseButton1Down = true; | |
34 | options.MouseBindable:Fire (true); | |
35 | end; | |
36 | end); | |
37 | options.OnInputEnded = game:service 'UserInputService'.InputEnded:connect (function (obj) | |
38 | if (obj and obj.UserInputType == Enum.UserInputType.MouseButton1) then | |
39 | options.MouseButton1Down = false; | |
40 | options.MouseBindable:Fire (false); | |
41 | end; | |
42 | end); | |
43 | ||
44 | coroutine.wrap (function() | |
45 | while true do | |
46 | local mouseX, mouseY = mouse.X, mouse.Y; | |
47 | local screenX, screenY = mouse.ViewSizeX, mouse.ViewSizeY; | |
48 | local framePosX, framePosY = frame.AbsolutePosition.X, frame.AbsolutePosition.Y; | |
49 | local frameSizeX, frameSizeY = frame.AbsoluteSize.X, frame.AbsoluteSize.Y; | |
50 | ||
51 | local frameXOffset1, frameXOffset2 = framePosX, screenX - (framePosX + frameSizeX); | |
52 | local frameYOffset1, frameYOffset2 = framePosY, screenY - (framePosY + frameSizeY); | |
53 | ||
54 | local isInResizeY = (mouseX > framePosX and mouseX < (framePosX + frameSizeX) and --Y1 Resizing | |
55 | (mouseY > (framePosY - 5) and (mouseY < (framePosY + 5)))); | |
56 | local isInResizeX = (mouseX > (framePosX + frameSizeX - 5) and mouseX < (framePosX + frameSizeX + 5) and --X2 Resizing | |
57 | (mouseY > framePosY and mouseY < (framePosY + frameSizeY))); | |
58 | local isInResizeXY = (mouseX > (framePosX + frameSizeX - 5) and mouseX < (framePosX + frameSizeX + 5) and | |
59 | (mouseY > (framePosY - 5) and mouseY < (framePosY + 5))); | |
60 | ||
61 | if (isInResizeY) then | |
62 | options.MouseIconState = true; | |
63 | options.MouseIconPrevious = mouse.Icon; | |
64 | mouse.Icon = 'rbxassetid://1195128791'; | |
65 | ||
66 | while (options.MouseButton1Down) do | |
67 | local mouseX, mouseY = mouse.X, math.max (math.min (mouse.Y, framePosY + frameSizeY - options.MAX_HEIGHT), options.MAX_HEIGHT); | |
68 | local resizeY = (framePosY + frameSizeY) - mouseY; | |
69 | ||
70 | frame.Size = UDim2.new ( | |
71 | 0, frameSizeX, | |
72 | 0, resizeY | |
73 | ); | |
74 | ||
75 | frame.Position = UDim2.new ( | |
76 | 0, framePosX, | |
77 | 0, framePosY + (frameSizeY - frame.AbsoluteSize.Y) | |
78 | ); | |
79 | ||
80 | options.ResizeBindable:Fire(); | |
81 | ||
82 | wait (0); | |
83 | end; | |
84 | elseif (isInResizeX) then | |
85 | options.MouseIconState = true; | |
86 | options.MouseIconPrevious = mouse.Icon; | |
87 | mouse.Icon = 'rbxassetid://1243635772'; | |
88 | ||
89 | while (options.MouseButton1Down) do | |
90 | local mouseX, mouseY = mouse.X, mouse.Y; | |
91 | local resizeX = mouseX - (frameSizeX + frameXOffset1) + frameSizeX; | |
92 | resizeX = math.min (math.max (resizeX, options.MIN_WIDTH), options.MAX_WIDTH); | |
93 | ||
94 | frame.Size = UDim2.new ( | |
95 | 0, resizeX, | |
96 | 0, frame.AbsoluteSize.Y | |
97 | ); | |
98 | ||
99 | options.ResizeBindable:Fire(); | |
100 | wait (0); | |
101 | end; | |
102 | else | |
103 | if (options.MouseIconState) then | |
104 | options.MouseIconState = false; | |
105 | ||
106 | mouse.Icon = options.MouseIconPrevious; | |
107 | end; | |
108 | end; | |
109 | ||
110 | game:service 'RunService'.RenderStepped:wait(); | |
111 | end; | |
112 | end)(); | |
113 | ||
114 | return options; | |
115 | end; | |
116 | ||
117 | ||
118 | ||
119 | users = game:service 'Players'; | |
120 | user = users.localPlayer; | |
121 | gui = user.PlayerGui; | |
122 | ||
123 | mouse = user:getMouse (); | |
124 | create = LoadLibrary 'RbxUtility'.Create; | |
125 | ||
126 | runService = game:service 'RunService'; | |
127 | userInputService = game:service 'UserInputService'; | |
128 | ||
129 | ||
130 | frame = create 'Frame' { | |
131 | Size = UDim2.new (0, 100, 0, 100), | |
132 | Position = UDim2.new (0.5, -50, 0.5, -50), | |
133 | ||
134 | Parent = create 'ScreenGui' { Parent = gui }, | |
135 | ||
136 | create 'TextLabel' { | |
137 | Size = UDim2.new (1, 0, 0, 30), | |
138 | Text = 'AAAAAAA' | |
139 | } | |
140 | }; | |
141 | ||
142 | local function oc (f) | |
143 | local w, d = nil, false; | |
144 | w = function (...) | |
145 | if (d) then return end; | |
146 | ||
147 | local ret = { ypcall (f, ...) }; | |
148 | ||
149 | if (table.remove (ret, 1)) then | |
150 | return unpack (ret); | |
151 | else | |
152 | d = true; | |
153 | error (ret [2], 2); | |
154 | end; | |
155 | end; | |
156 | ||
157 | return w; | |
158 | end; | |
159 | local function connectEvent (c, f, ...) | |
160 | if (... ~= nil) then | |
161 | c:connect (f); | |
162 | else | |
163 | while true do | |
164 | f (c:wait (...)); | |
165 | end; | |
166 | end; | |
167 | end; | |
168 | ||
169 | connectEvent (userInputService.InputBegan, function (c) | |
170 | if (c and c.UserInputType == Enum.UserInputType.MouseButton1) then | |
171 | mouse1Down = true; | |
172 | end; | |
173 | end, 1); | |
174 | connectEvent (userInputService.InputEnded, function (c) | |
175 | if (c and c.UserInputType == Enum.UserInputType.MouseButton1) then | |
176 | mouse1Down = false; | |
177 | end; | |
178 | end, 1); | |
179 | ||
180 | connectEvent (runService.RenderStepped, function() | |
181 | local mouseX, mouseY = mouse.X, mouse.Y; | |
182 | local screenX, screenY = mouse.ViewSizeX, mouse.ViewSizeY; | |
183 | local framePosX, framePosY = frame.AbsolutePosition.X, frame.AbsolutePosition.Y; | |
184 | local frameSizeX, frameSizeY = frame.AbsoluteSize.X, frame.AbsoluteSize.Y; | |
185 | ||
186 | --XOffset <---X1---><frame><---X2---> | |
187 | --YOffset ^---Y1---v^framev^---Y2---v | |
188 | ||
189 | --OFFSETS ^ | |
190 | -- Y1 | |
191 | -- v | |
192 | -- < X1 >FRAME< X2 > | |
193 | -- ^ | |
194 | -- Y2 | |
195 | -- v | |
196 | ||
197 | local frameXOffset1, frameXOffset2 = framePosX, screenX - (framePosX + frameSizeX); | |
198 | local frameYOffset1, frameYOffset2 = framePosY, screenY - (framePosY + frameSizeY); | |
199 | ||
200 | local isInResizeY = (mouseX > framePosX and mouseX < (framePosX + frameSizeX) and --Y1 Resizing | |
201 | (mouseY > (framePosY - 5) and (mouseY < (framePosY + 5)))); | |
202 | local isInResizeX = (mouseX > (framePosX + frameSizeX - 5) and mouseX < (framePosX + frameSizeX + 5) and --X2 Resizing | |
203 | (mouseY > framePosY and mouseY < (framePosY + frameSizeY))); | |
204 | local isInResizeXY = (mouseX > (framePosX + frameSizeX - 5) and mouseX < (framePosX + frameSizeX + 5) and | |
205 | (mouseY > (framePosY - 5) and mouseY < (framePosY + 5))); | |
206 | ||
207 | if (isInResizeY) then | |
208 | mouse.Icon = 'rbxassetid://1195128791'; | |
209 | ||
210 | while (mouse1Down) do | |
211 | local mouseX, mouseY = mouse.X, math.max (math.min (mouse.Y, framePosY + frameSizeY - 50), 100); | |
212 | local resizeY = (framePosY + frameSizeY) - mouseY; | |
213 | ||
214 | frame.Size = UDim2.new ( | |
215 | 0, frameSizeX, | |
216 | 0, resizeY | |
217 | ); | |
218 | ||
219 | frame.Position = UDim2.new ( | |
220 | 0, framePosX, | |
221 | 0, framePosY + (frameSizeY - frame.AbsoluteSize.Y) | |
222 | ) | |
223 | ||
224 | wait (0); | |
225 | end; | |
226 | elseif (isInResizeX) then | |
227 | mouse.Icon = 'rbxassetid://1243635772'; | |
228 | ||
229 | while (mouse1Down) do | |
230 | local mouseX, mouseY = mouse.X, mouse.Y; | |
231 | local resizeX = mouseX - (frameSizeX + frameXOffset1) + frameSizeX; | |
232 | resizeX = math.min (math.max (resizeX, 50), 500); | |
233 | ||
234 | frame.Size = UDim2.new ( | |
235 | 0, resizeX, | |
236 | 0, frame.AbsoluteSize.Y | |
237 | ); | |
238 | wait (0); | |
239 | end; | |
240 | else | |
241 | mouse.Icon = ""; | |
242 | end; | |
243 | end); |