From 39f90c6dc933636a8716e2a4e6e7e2e52c5d049b Mon Sep 17 00:00:00 2001 From: MatusGuy Date: Tue, 19 Jul 2022 13:04:19 +0100 Subject: [PATCH] refactoring mt objects --- Mt.rbxlx | 1159 ++++++++++++++++++++++++++---------------------------- 1 file changed, 565 insertions(+), 594 deletions(-) diff --git a/Mt.rbxlx b/Mt.rbxlx index 0110a35..09d9c7e 100644 --- a/Mt.rbxlx +++ b/Mt.rbxlx @@ -59,6 +59,7 @@ true false + 0 0b401e85ede42a620247f9fa00019ad8 @@ -81,27 +82,27 @@ - -217.754074 - 55.0020561 - 49.8049469 - 0.438246489 - -0.56198597 - 0.701506793 + -38.7727661 + 21.1391563 + -101.471115 + -0.559310853 + -0.476656705 + 0.678210735 -0 - 0.780445039 - 0.625224411 - -0.898854852 - -0.274002403 - 0.342027307 + 0.818148494 + 0.575007021 + -0.828958035 + 0.321607679 + -0.457599312 null 0 70 0 - -219.157089 - 53.751606 - 49.1208916 + -40.1291885 + 19.9891415 + -100.555916 1 0 0 @@ -569,6 +570,7 @@ gcLgc4RKxr21zq2UlJSM]]> true MtRemotes + 0 {A7C6D0D5-14AA-4B8C-AFE7-FFB33C4115B6} true MtWindowTest + 0 {6458014A-116B-482E-8D8B-AE889E404B10} - - - - false - - MtProgressBarTest - {5F3728E5-2388-4161-9565-DB53D4DDC893} - - -1 - - 2c4fe3e3f18b662702abd6620002b592 - - @@ -1509,6 +1446,7 @@ end) false MtObjectTest + 0 {31C12EE3-55B0-4EF6-9438-8CFB85B43254} 05c44930bd9fb73402486df700201f5d - - - - - MWidget - {6C7FCB0E-3E63-4CEB-A66E-534210256E09} - min.X and coor.Y > min.Y -end - -MWidget.CalcLimitedSize = function(self,coor:Vector2,min:Vector2,max:Vector2): (Vector2, boolean) - min=min or self:GetMinimumSize() - max=max or self:GetMaximumSize() - - local newX=coor.X - local newY=coor.Y - - if coor.X > max.X then newX=max.X end - if coor.Y > max.Y then newY=max.Y end - - if coor.X < min.X then newX=min.X end - if coor.Y < min.Y then newY=min.Y end - - if coor.X==newX and coor.Y==newY then - return coor, false - else - return Vector2.new(newX,newY), true - end - -end - -function MWidget.GetVector2FromUDim2Offset(udim2:UDim2): Vector2 - -- static function - return Vector2.new(udim2.X.Offset,udim2.Y.Offset) -end - -MWidget.ChangeSize = function(self, deltaX, deltaY ,anchor: boolean): boolean - local nsx=self.Size.X+deltaX - local nsy=self.Size.Y+deltaY - self:SetSize(Vector2.new(nsx,nsy),anchor) -end - -MWidget.SetSize= function(self,newsize:Vector2,anchor: boolean): boolean - anchor=anchor or false - local oldSize = table.clone(self.Size) - local limitedsize, onlimit = self:CalcLimitedSize(newsize) - local currentScale: Vector2 = self:GetSizeScale() - - self.Size.X, self.Size.Y = limitedsize.X, limitedsize.Y - self.Frame.Size = UDim2.new( - currentScale.X, - limitedsize.X, - currentScale.Y, - limitedsize.Y - ) - if anchor then - self:SetPosition(Vector2.new(self.Position.X+(oldSize.X-self.Size.X),self.Position.Y+(oldSize.Y-self.Size.Y))) - end - - --print (onlimit ,self.Size.X,oldSize.X) - --return not(onlimit and self.Size.X==oldSize.X ) - return not(onlimit) -end - - - - -MWidget.Resize = MWidget.SetSize - -function MWidget.GetSize(self): {} - --return self.Frame.AbsoluteSize - return self.Size -end - -MWidget.SetSizeFromScale = function(self,newscale:Vector2) - local screenSize = self.Screen:GetScreenSize() - self:SetSize(Vector2.new(newscale.X*screenSize.X,newscale.Y*screenSize.Y)) -end - -MWidget.Rescale = MWidget.SetSizeFromScale - -MWidget.SetPosition = function(self,newpos:Vector2) - self.Frame.Position = UDim2.fromOffset(newpos.X,newpos.Y) - self.Position.X, self.Position.Y = newpos.X, newpos.Y -end - -MWidget.GoTo = MWidget.SetPosition -MWidget.Move = MWidget.SetPosition - -MWidget.SetPositionFromScale = function(self,newscale:Vector2) - local screenSize = self.Screen:GetScreenSize() - self:SetPosition(Vector2.new(newscale.X*screenSize.X,newscale.Y*screenSize.Y)) -end - -MWidget.GetSizeScale = function(self): Vector2 - return Vector2.new(self.Frame.Size.X.Scale,self.Frame.Size.Y.Scale) -end - -MWidget.SetSizeLimit = function(self,min:Vector2,max:Vector2) - self.MinSize = min - self.MaxSize = max -end - -MWidget.SetMinimumSize = function(self,size:Vector2) - self:SetSizeLimit(size,self.MaxSize) -end - -MWidget.SetMinimumWidth= function(self,width:number) - self:SetMinimumSize(Vector2.new( - width, - self.MinSize.Y - )) -end - -MWidget.SetMinimumHeight=function(self,height:number) - self:SetMinimumSize(Vector2.new( - self.MinSize.X, - height - )) -end - -MWidget.SetMaximumSize = function(self,size:Vector2) - self:SetSizeLimit(self.MinSize,size) -end - -MWidget.SetMaximumWidth= function(self,width:number) - self:SetMaximumSize(Vector2.new( - width, - self.MinSize.Y - )) -end - -MWidget.SetMaxmimumHeight=function(self,height:number) - self:SetMaximumSize(Vector2.new( - self.MaxSize.X, - height - )) -end - -MWidget.GetMaximumWidth=function(self): number - return self.MaxSize.X -end - -MWidget.GetMinimumWidth=function(self): number - return self.MinSize.X -end - -MWidget.GetMaximumHeight=function(self): number - return self.MaxSize.Y -end - -MWidget.GetMinimumHeight=function(self): number - return self.MinSize.Y -end - -MWidget.GetMinimumSize=function(self): Vector2 - return self.MinSize -end - -MWidget.GetMaximumSize=function(self): Vector2 - return self.MaxSize -end - -MWidget.GetSizeLimit=function(self): Rect - return Rect.new(self:GetMinimumSize(),self:GetMaximumSize()) -end - -MWidget.SetName = function(self,name) - self.Frame.Name = name - MObject.SetName(self,name) -end - -MWidget.SetHidden = function(self,hidden) - self.Frame.Visible = not hidden -end - -MWidget.IsPointTouchingArea = function(self,point: Vector2,areaPos: UDim2,areaSize: UDim2): boolean - local px = point.X - local py = point.Y - local apx = areaPos.X.Offset - local apy = areaPos.Y.Offset - local asx = areaSize.X.Offset - local asy = areaSize.X.Offset - - return - (px >= apx-asx and px <= (apx + asx)) and - (py >= apy-asy and py <= (apy + asy)) -end - -MWidget.IsPointInsideWidget = function(self,point:Vector2): boolean - self:PointTouchingArea(point,self.Frame.AbsolutePosition,self.Frame.AbsoluteSize) -end - -MWidget.IsBeingHovered = function(self):boolean - self:IsPointInsideWidget(uis:GetMouseLocation()) -end - -MWidget = MObject:Init({},MWidget,-1) - -return MWidget]]> - -1 - - 05c44930bd9fb73402486df700201f98 - - @@ -1866,21 +1564,23 @@ local MWindow = { WindowInteractionState = MtEnum.WindowInteractionState.None, -- Window interaction state (string (enum)) (Read-only) Maximized = false, -- Is maximized? (boolean) (Read-only) } +MWindow = setmetatable(MWindow, MWidget) +rawset(MWindow, "__index", MWindow) -MWindow.Init = function(self,screen,_obj) - local _obj = MWidget.Init(self,screen,_obj) +MWindow.Init = function(self,screen) + local self = setmetatable(MWidget.Init(self,screen), MWindow) - _obj.Interacted=Instance.new("BindableEvent") - _obj.Resizing = Instance.new("BindableEvent") - _obj.Moving = Instance.new("BindableEvent") + self.Interacted=Instance.new("BindableEvent") + self.Resizing = Instance.new("BindableEvent") + self.Moving = Instance.new("BindableEvent") - _obj.Screen = screen - MWindow.InitGui(_obj) - _obj.Screen:AddWidget(_obj) + self.Screen = screen + MWindow.InitGui(self) + self.Screen:AddWidget(self) - --MWindow.InitWindowFunctionality(_obj) + --MWindow.InitWindowFunctionality(self) - return _obj + return self end function MWindow.InitGui(self) @@ -1918,6 +1618,10 @@ function MWindow.InitGui(self) self:SetMinimumSize(Vector2.new(150,handle.Size.Y.Offset)) end +function MWindow.ResizeBySide(self, side: string, inc: number): boolean + +end + MWindow.GetZIndex = function(self): number return table.find(self.Screen.Widgets,self.OBJID) end @@ -1927,8 +1631,6 @@ MWindow.SetTitle = function(self,title) self.TitleLabel.Text = self.Title end -local MWindow = MWidget:Init({},MWindow) - return MWindow]]> -1 @@ -2612,80 +2314,80 @@ local MWindowResizeRegion = { Name = "ResizeRegion", ClassName = "MWindowResizeRegion", } +MWindowResizeRegion = setmetatable(MWindowResizeRegion, MObject) +rawset(MWindowResizeRegion, "__index", MWindowResizeRegion) -MWindowResizeRegion.Init = function(self,x,y,side,sx,sy,osx,osy,window,_obj) +MWindowResizeRegion.Init = function(self,x,y,side,sx,sy,osx,osy,window) if window.ClassName ~= "MWindow" then error("Mt error: MWindowResizeRegions must be parented to an MWindow.") end - local _obj = MObject.Init(self,window,_obj) - _obj.Resizing = Instance.new("BindableEvent") - _obj.ResizeEnded = Instance.new("BindableEvent") - _obj.ResizeBegan = Instance.new("BindableEvent") + local self = setmetatable(MObject.Init(self,window), MWindowResizeRegion) + self.Resizing = Instance.new("BindableEvent") + self.ResizeEnded = Instance.new("BindableEvent") + self.ResizeBegan = Instance.new("BindableEvent") - _obj.Window = window + self.Window = window - if not _obj.Window.Frame:FindFirstChild("resizeRegions") then - _obj.ResizeRegionsFolder = Instance.new("Folder") - _obj.ResizeRegionsFolder.Parent = _obj.Window.Frame - _obj.ResizeRegionsFolder.Name = "resizeRegions" + if not self.Window.Frame:FindFirstChild("resizeRegions") then + self.ResizeRegionsFolder = Instance.new("Folder") + self.ResizeRegionsFolder.Parent = self.Window.Frame + self.ResizeRegionsFolder.Name = "resizeRegions" else - _obj.ResizeRegionsFolder = _obj.Window.Frame.resizeRegions + self.ResizeRegionsFolder = self.Window.Frame.resizeRegions end - if not _obj.ResizeRegionsFolder:FindFirstChild("Dragging") then - _obj.DraggingValue = Instance.new("ObjectValue") - _obj.DraggingValue.Parent = _obj.ResizeRegionsFolder - _obj.DraggingValue.Name = "Dragging" + if not self.ResizeRegionsFolder:FindFirstChild("Dragging") then + self.DraggingValue = Instance.new("ObjectValue") + self.DraggingValue.Parent = self.ResizeRegionsFolder + self.DraggingValue.Name = "Dragging" else - _obj.DraggingValue = _obj.ResizeRegionsFolder.Dragging + self.DraggingValue = self.ResizeRegionsFolder.Dragging end osx = osx or 0 osy = osy or 0 - _obj.Region = Instance.new("Frame") - _obj.Region.Parent = _obj.ResizeRegionsFolder - _obj.Region.Name = side.._obj.Name - _obj.Region.BackgroundTransparency = 1 - _obj.Region.BorderSizePixel = 0 - _obj.Region.BorderColor3 = Color3.new(0,1,0) - _obj.Region.Position = UDim2.fromScale(x,y) - _obj.Region.Size = UDim2.new(sx,osx,sy,osy) + self.Region = Instance.new("Frame") + self.Region.Parent = self.ResizeRegionsFolder + self.Region.Name = side..self.Name + self.Region.BackgroundTransparency = 1 + self.Region.BorderSizePixel = 0 + self.Region.BorderColor3 = Color3.new(0,1,0) + self.Region.Position = UDim2.fromScale(x,y) + self.Region.Size = UDim2.new(sx,osx,sy,osy) - _obj.XRay = script.XRay:Clone() - MWindowResizeRegion.SetXRayEnabled(_obj,false) - _obj.XRay.Parent = _obj.Region + self.XRay = script.XRay:Clone() + MWindowResizeRegion.SetXRayEnabled(self,false) + self.XRay.Parent = self.Region - _obj.Cursor = cursors[side] + self.Cursor = cursors[side] - _obj.Region.MouseEnter:Connect(function() - if MWindowResizeRegion.CanChangeCursor(_obj) then + self.Region.MouseEnter:Connect(function() + if MWindowResizeRegion.CanChangeCursor(self) then local mouse = plr:GetMouse() - MtMouseController:ChangeCursor(_obj.Cursor) + MtMouseController:ChangeCursor(self.Cursor) end end) - _obj.Region.MouseLeave:Connect(function() - if MWindowResizeRegion.CanChangeCursor(_obj) then + self.Region.MouseLeave:Connect(function() + if MWindowResizeRegion.CanChangeCursor(self) then local mouse = plr:GetMouse() MtMouseController:ResetCursor() end end) - _obj.Region.InputBegan:Connect(function(input) + self.Region.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then - _obj.ResizeBegan:Fire() - --[[ local clickLocation = uis:GetMouseLocation() - local wx=_obj.Window.Frame.Position.X.Offset - local wy=_obj.Window.Frame.Position.Y.Offset - local wsx=_obj.Window.Frame.Size.X.Offset - local wsy=_obj.Window.Frame.Size.Y.Offset + local wx=self.Window.Frame.Position.X.Offset + local wy=self.Window.Frame.Position.Y.Offset + local wsx=self.Window.Frame.Size.X.Offset + local wsy=self.Window.Frame.Size.Y.Offset local imx=clickLocation.X local imy=clickLocation.Y - _obj.DraggingValue.Value = _obj.Region + self.DraggingValue.Value = self.Region local sidex=MtEnum.ResizeSide.None local sidey=MtEnum.ResizeSide.None @@ -2696,9 +2398,9 @@ MWindowResizeRegion.Init = function(self,x,y,side,sx,sy,osx,osy,window,_obj) if math.abs(imy-(wy+wsy))<5 then sidey=MtEnum.ResizeSide.Bottom end end - _obj.ResizeBegan:Fire() + self.ResizeBegan:Fire() - while _getMouseButton1Pressed(uis:GetMouseButtonsPressed()) and _obj.Window.Screen.WindowBeingInteracted do + while _getMouseButton1Pressed(uis:GetMouseButtonsPressed()) and self.Window.Screen.WindowBeingInteracted do local location = uis:GetMouseLocation() local mx=location.X local my=location.Y @@ -2733,13 +2435,13 @@ MWindowResizeRegion.Init = function(self,x,y,side,sx,sy,osx,osy,window,_obj) ----- Check if the y < min y ------ if yes then do nothing - local newsize = _obj.Window:LimitCoordinate(Vector2.new(nsx,nsy),Vector2.new(0,0)) - if newsize == _obj.Window:LimitCoordinate(newsize) then - _obj.Window:SetPosition(Vector2.new(nx,ny)) + local newsize = self.Window:LimitCoordinate(Vector2.new(nsx,nsy),Vector2.new(0,0)) + if newsize == self.Window:LimitCoordinate(newsize) then + self.Window:SetPosition(Vector2.new(nx,ny)) end - _obj.Window:SetSize(newsize) + self.Window:SetSize(newsize) - _obj.Resizing:Fire(_obj.Window.Frame.Size,_obj.Window.Frame.Position,location) + self.Resizing:Fire(self.Window.Frame.Size,self.Window.Frame.Position,location) MtMouseController:ChangeCursor(MWindowResizeRegion.GetCursorFromResizeSide(sidex,sidey)) task.wait(.025) @@ -2747,14 +2449,15 @@ MWindowResizeRegion.Init = function(self,x,y,side,sx,sy,osx,osy,window,_obj) end MtMouseController:ResetCursor() - _obj.DraggingValue.Value = nil + self.DraggingValue.Value = nil - _obj.ResizeEnded:Fire() - ]] + self.ResizeEnded:Fire() end end) - --MWindowResizeRegion.SetXRayEnabled(_obj,true) - return _obj + + --MWindowResizeRegion.SetXRayEnabled(self,true) + + return self end MWindowResizeRegion.CanChangeCursor = function(self): boolean @@ -2778,8 +2481,6 @@ MWindowResizeRegion.GetCursorFromResizeSide = function(x:number,y:number):string if x~=y then return "rbxasset://textures/StudioUIEditor/icon_resize1.png" end -- diagonal north-west end -MWindowResizeRegion = MObject:Init({},MWindowResizeRegion,-1) - return MWindowResizeRegion]]> -1 @@ -2805,7 +2506,7 @@ return MWindowResizeRegion]]> - + @@ -2839,21 +2540,23 @@ local MProgressBar = { [MtEnum.Orientation.Vertical] = -90, }, } +MProgressBar = setmetatable(MProgressBar, MWidget) +rawset(MProgressBar, "__index", MProgressBar) -function MProgressBar.Init(self,parent,_obj) - local _obj = MWidget.Init(self,parent,_obj) - _obj.Frame:Destroy() +function MProgressBar.Init(self,parent) + local self = setmetatable(MWidget.Init(self,parent), MProgressBar) + self.Frame:Destroy() local clone = script.progressbar:Clone() - _obj.Filling = clone.filling - _obj.Label = clone.label - _obj.Gradient = _obj.Filling.Gradient - _obj.UndefGradient = clone.filling.UndefinedGradient - _obj.Frame = clone + self.Filling = clone.filling + self.Label = clone.label + self.Gradient = self.Filling.Gradient + self.UndefGradient = clone.filling.UndefinedGradient + self.Frame = clone - _obj.UndefTweenGoal = {Offset = Vector2.new(1,0)} - _obj.UndefTween = ts:Create( - _obj.UndefGradient, + self.UndefTweenGoal = {Offset = Vector2.new(1,0)} + self.UndefTween = ts:Create( + self.UndefGradient, TweenInfo.new( 3, Enum.EasingStyle.Quad, @@ -2861,16 +2564,16 @@ function MProgressBar.Init(self,parent,_obj) 0, true ), - _obj.UndefTweenGoal + self.UndefTweenGoal ) - _obj.DragUndefGradCoro = coroutine.create(function() - MProgressBar.DragUndefGradient(_obj) + self.DragUndefGradCoro = coroutine.create(function() + MProgressBar.DragUndefGradient(self) end) - MProgressBar.SetProgress(_obj,24) + MProgressBar.SetProgress(self,24) - return _obj + return self end function MProgressBar.GetFormattedText(self,progress:number,format:string): string @@ -3058,14 +2761,12 @@ function MProgressBar.GetProgressLimit(self): (number,number) return self:GetMinimum(), self:GetMaximum() end -MProgressBar = MWidget:Init({},MProgressBar,-1) - return MProgressBar]]> -1 - 2c4fe3e3f18b662702abd6620004cffe + 4b78783951982c7702dac31d001c2780 - + false @@ -3122,11 +2823,11 @@ return MProgressBar]]> -1 0 - 2c4fe3e3f18b662702abd6620004cffa + 4b78783951982c7702dac31d001c277c true 1 - + 0 @@ -3142,10 +2843,10 @@ return MProgressBar]]> 5 0 - 2c4fe3e3f18b662702abd6620004d007 + 4b78783951982c7702dac31d001c2789 - + @@ -3155,10 +2856,10 @@ return MProgressBar]]> UICorner -1 - 2c4fe3e3f18b662702abd6620004d001 + 4b78783951982c7702dac31d001c2783 - + false @@ -3215,11 +2916,11 @@ return MProgressBar]]> -1 0 - 2c4fe3e3f18b662702abd6620004cffb + 4b78783951982c7702dac31d001c277d true 1 - + 0 @@ -3235,10 +2936,10 @@ return MProgressBar]]> 5 0 - 2c4fe3e3f18b662702abd6620004d008 + 4b78783951982c7702dac31d001c278a - + 0 0.333333 1 0 0 1 0.607843 1 0.411765 0 @@ -3252,10 +2953,10 @@ return MProgressBar]]> -1 0 0 0 1 0 0 - 2c4fe3e3f18b662702abd6620004d004 + 4b78783951982c7702dac31d001c2786 - + 0 0.313726 0.313726 0.313726 0 0.499168 0.333333 1 0 0 1 0.313726 0.313726 0.313726 0 @@ -3269,11 +2970,11 @@ return MProgressBar]]> -1 0 0 0 1 0 0 - 2c4fe3e3f18b662702abd6620004d005 + 4b78783951982c7702dac31d001c2787 - + false @@ -3299,7 +3000,12 @@ return MProgressBar]]> false false 4 - + + rbxasset://fonts/families/SourceSansPro.json + 700 + + rbxasset://fonts/SourceSansPro-Bold.ttf + 0 1 -1 @@ -3353,11 +3059,11 @@ return MProgressBar]]> true 2 1 - 2c4fe3e3f18b662702abd6620004cfff + 4b78783951982c7702dac31d001c2781 true 1 - + 0 @@ -3373,12 +3079,12 @@ return MProgressBar]]> 2 0 - 2c4fe3e3f18b662702abd6620004d009 + 4b78783951982c7702dac31d001c278b - + false @@ -3435,11 +3141,11 @@ return MProgressBar]]> -1 0 - 2c4fe3e3f18b662702abd6620004cffc + 4b78783951982c7702dac31d001c277e true 1 - + 0 @@ -3455,10 +3161,10 @@ return MProgressBar]]> 5 0 - 2c4fe3e3f18b662702abd6620004d00a + 4b78783951982c7702dac31d001c278c - + @@ -3468,10 +3174,10 @@ return MProgressBar]]> UICorner -1 - 2c4fe3e3f18b662702abd6620004d002 + 4b78783951982c7702dac31d001c2784 - + false @@ -3528,11 +3234,11 @@ return MProgressBar]]> -1 0 - 2c4fe3e3f18b662702abd6620004cffd + 4b78783951982c7702dac31d001c277f true 1 - + @@ -3542,10 +3248,10 @@ return MProgressBar]]> UICorner -1 - 2c4fe3e3f18b662702abd6620004d003 + 4b78783951982c7702dac31d001c2785 - + 0 @@ -3561,10 +3267,10 @@ return MProgressBar]]> 5 0 - 2c4fe3e3f18b662702abd6620004d00b + 4b78783951982c7702dac31d001c278d - + 0 0.313726 0.313726 0.313726 0 0.499168 0.333333 1 0 0 1 0.313726 0.313726 0.313726 0 @@ -3578,11 +3284,11 @@ return MProgressBar]]> -1 0 0 0 1 0 0 - 2c4fe3e3f18b662702abd6620004d006 + 4b78783951982c7702dac31d001c2788 - + false @@ -3608,7 +3314,12 @@ return MProgressBar]]> false false 3 - + + rbxasset://fonts/families/SourceSansPro.json + 400 + + rbxasset://fonts/SourceSansPro-Regular.ttf + 0 1 -1 @@ -3662,11 +3373,11 @@ return MProgressBar]]> true 2 1 - 2c4fe3e3f18b662702abd6620004d000 + 4b78783951982c7702dac31d001c2782 false 1 - + 0 @@ -3682,12 +3393,252 @@ return MProgressBar]]> 2 0 - 2c4fe3e3f18b662702abd6620004d00c + 4b78783951982c7702dac31d001c278e + + + + + MWidget + {E51D6FC4-95AF-4394-8156-5E9214B4BFBF} + min.X and coor.Y > min.Y +end + +MWidget.CalcLimitedSize = function(self,coor:Vector2,min:Vector2,max:Vector2): (Vector2, boolean) + min=min or self:GetMinimumSize() + max=max or self:GetMaximumSize() + + local newX=coor.X + local newY=coor.Y + + if coor.X > max.X then newX=max.X end + if coor.Y > max.Y then newY=max.Y end + + if coor.X < min.X then newX=min.X end + if coor.Y < min.Y then newY=min.Y end + + if coor.X==newX and coor.Y==newY then + return coor, false + else + return Vector2.new(newX,newY), true + end + +end + +function MWidget.GetVector2FromUDim2Offset(udim2:UDim2): Vector2 + -- static function + return Vector2.new(udim2.X.Offset,udim2.Y.Offset) +end + +MWidget.ChangeSize = function(self, deltaX, deltaY ,anchor: boolean): boolean + local nsx=self.Size.X+deltaX + local nsy=self.Size.Y+deltaY + self:SetSize(Vector2.new(nsx,nsy),anchor) +end + +MWidget.SetSize= function(self,newsize:Vector2,anchor: boolean): boolean + anchor=anchor or false + local oldSize = table.clone(self.Size) + local limitedsize, onlimit = self:CalcLimitedSize(newsize) + local currentScale: Vector2 = self:GetSizeScale() + + self.Size.X, self.Size.Y = limitedsize.X, limitedsize.Y + self.Frame.Size = UDim2.new( + currentScale.X, + limitedsize.X, + currentScale.Y, + limitedsize.Y + ) + if anchor then + self:SetPosition(Vector2.new(self.Position.X+(oldSize.X-self.Size.X),self.Position.Y+(oldSize.Y-self.Size.Y))) + end + + --print (onlimit ,self.Size.X,oldSize.X) + --return not(onlimit and self.Size.X==oldSize.X ) + return not(onlimit) +end + + + + +MWidget.Resize = MWidget.SetSize + +function MWidget.GetSize(self): {} + --return self.Frame.AbsoluteSize + return self.Size +end + +MWidget.SetSizeFromScale = function(self,newscale:Vector2) + local screenSize = self.Screen:GetScreenSize() + self:SetSize(Vector2.new(newscale.X*screenSize.X,newscale.Y*screenSize.Y)) +end + +MWidget.Rescale = MWidget.SetSizeFromScale + +MWidget.SetPosition = function(self,newpos:Vector2) + self.Frame.Position = UDim2.fromOffset(newpos.X,newpos.Y) + self.Position.X, self.Position.Y = newpos.X, newpos.Y +end + +MWidget.GoTo = MWidget.SetPosition +MWidget.Move = MWidget.SetPosition + +MWidget.SetPositionFromScale = function(self,newscale:Vector2) + local screenSize = self.Screen:GetScreenSize() + self:SetPosition(Vector2.new(newscale.X*screenSize.X,newscale.Y*screenSize.Y)) +end + +MWidget.GetSizeScale = function(self): Vector2 + return Vector2.new(self.Frame.Size.X.Scale,self.Frame.Size.Y.Scale) +end + +MWidget.SetSizeLimit = function(self,min:Vector2,max:Vector2) + self.MinSize = min + self.MaxSize = max +end + +MWidget.SetMinimumSize = function(self,size:Vector2) + self:SetSizeLimit(size,self.MaxSize) +end + +MWidget.SetMinimumWidth= function(self,width:number) + self:SetMinimumSize(Vector2.new( + width, + self.MinSize.Y + )) +end + +MWidget.SetMinimumHeight=function(self,height:number) + self:SetMinimumSize(Vector2.new( + self.MinSize.X, + height + )) +end + +MWidget.SetMaximumSize = function(self,size:Vector2) + self:SetSizeLimit(self.MinSize,size) +end + +MWidget.SetMaximumWidth= function(self,width:number) + self:SetMaximumSize(Vector2.new( + width, + self.MinSize.Y + )) +end + +MWidget.SetMaxmimumHeight=function(self,height:number) + self:SetMaximumSize(Vector2.new( + self.MaxSize.X, + height + )) +end + +MWidget.GetMaximumWidth=function(self): number + return self.MaxSize.X +end + +MWidget.GetMinimumWidth=function(self): number + return self.MinSize.X +end + +MWidget.GetMaximumHeight=function(self): number + return self.MaxSize.Y +end + +MWidget.GetMinimumHeight=function(self): number + return self.MinSize.Y +end + +MWidget.GetMinimumSize=function(self): Vector2 + return self.MinSize +end + +MWidget.GetMaximumSize=function(self): Vector2 + return self.MaxSize +end + +MWidget.GetSizeLimit=function(self): Rect + return Rect.new(self:GetMinimumSize(),self:GetMaximumSize()) +end + +MWidget.SetName = function(self,name) + self.Frame.Name = name + MObject.SetName(self,name) +end + +MWidget.SetHidden = function(self,hidden) + self.Frame.Visible = not hidden +end + +MWidget.IsPointTouchingArea = function(self,point: Vector2,areaPos: UDim2,areaSize: UDim2): boolean + local px = point.X + local py = point.Y + local apx = areaPos.X.Offset + local apy = areaPos.Y.Offset + local asx = areaSize.X.Offset + local asy = areaSize.X.Offset + + return + (px >= apx-asx and px <= (apx + asx)) and + (py >= apy-asy and py <= (apy + asy)) +end + +MWidget.IsPointInsideWidget = function(self,point:Vector2): boolean + self:PointTouchingArea(point,self.Frame.AbsolutePosition,self.Frame.AbsoluteSize) +end + +MWidget.IsBeingHovered = function(self):boolean + self:IsPointInsideWidget(uis:GetMouseLocation()) +end + +return MWidget]]> + -1 + + 4b78783951982c7702dac31d001c27d9 + + @@ -3754,6 +3705,7 @@ local OBJIDS = 0 local MObject = { -- Properties (Read-only (use their functions)) Name = "object", -- Object name (string) + __name = "object", ClassName = "MObject", -- Object class name (string) OBJID = 0, Parent = {}, -- Object parent (MObject) @@ -3765,34 +3717,45 @@ local MObject = { -- Events (Read-only) Destroyed = Instance.new("BindableEvent"), -- Fires when the object is destroyed } +MObject.__index = MObject --- Functions -MObject.Init = function(self,parent,_obj,_id) +-- Methods +function MObject.Init(parent,_id) -- new object -- Creates object and returns it - - _obj = _obj or {} - setmetatable(_obj, self) - self.__index = self - - for k,v in pairs(self) do - if not _keyInTableExists(_obj,k) then - _obj[k] = v - end - end + local self = setmetatable({}, MObject) if _id then - _obj.OBJID = _id + rawset(self, "OBJID", _id) else - _obj.OBJID = OBJIDS + rawset(self, "OBJID", OBJIDS) OBJIDS += 1 end - parent = parent or {} - MObject.SetParent(_obj,parent) + self:SetParent(parent) - _storeObj(_obj) + _storeObj(self) + + return self +end + +function MObject:__call(...) + return self.Init(...) +end + +function MObject:__tostring() + return self.Name +end - return _obj +function MObject:__newindex(key, value) + local setter = self["Set"..key] + + if setter then + setter(self,value) + elseif not (self[key] and self.__index[key]) or type(value) == "function" then -- if key never existed then create a key + rawset(self, key, value) + else + error(string.format('Property "%s" is not a member of %s\nTraceback:\n%s', key, self.ClassName, debug.traceback())) + end end MObject.FireEvent = function(self,event,...) @@ -3821,29 +3784,26 @@ MObject.Clone = function(self) return self end -MObject.SetName = function(self,name) - self.Name = name +function MObject:SetName(name) + rawset(self, "Name", name) + rawset(self, "__name", name) end -MObject.SetParent = function(self,parent) +function MObject:SetParent(parent) -- Sets parent for the object - parent = parent or {} - - if self.Parent == {} then + if self.Parent and self.Parent == {} then table.remove(self.Parent.Children,table.find(self.Parent.Children,self)) end - self.Parent = parent + rawset(self, "Parent", parent) - if parent == {} then + if parent then table.insert(parent.Children,self) end - - return nil end -MObject.FindFirstChild = function(self,child) +function MObject:FindFirstChild(child) -- Finds the inputted child in the object's children list and returns it for i,v in ipairs(self.Children) do @@ -3855,12 +3815,20 @@ MObject.FindFirstChild = function(self,child) return nil end -MObject.PrintMembers = function(self) +function MObject:PrintMembers() -- Prints all members of the metatable and their types print(self.Name.."'s members:") for k,v in pairs(self) do - print(k..": "..typeof(v).." = "..tostring(v)) + if not string.match(k,"__") then + print(k..": "..typeof(v).." = "..tostring(v)) + end + end + + for k,v in pairs(MObject) do + if not _keyInTableExists(self, k) and not string.match(k,"__") then + print(k..": "..typeof(v).." = "..tostring(v)) + end end end @@ -3883,16 +3851,17 @@ local _getObjFromId = require(script.Parent.MtCoreFunctions)._getObjFromId local MScreen = { Name = "screen", ClassName = "MScreen", + Widgets = {}, ScrX=1, ScrY=1, } +MScreen = setmetatable(MScreen, MObject) +rawset(MScreen,"__index", MScreen) -MScreen.Init = function(self,plr,parent,_obj) - local _obj = MObject.Init(self,parent,_obj) +function MScreen.Init(plr,parent: MObject) + local self = setmetatable(MObject.Init(parent), MScreen) - _obj.Player = plr or game:GetService("Players").LocalPlayer - - _obj.Widgets = {} + self.Player = plr or game:GetService("Players").LocalPlayer self.ScreenGui = Instance.new("ScreenGui") self.ScreenGui.Name = self.Name @@ -4015,12 +3984,112 @@ return MtEnum]]> 1fb9260fbeb8d7670258d1710006e58c - + + + + + MtCoreFunctions + {F70202B2-6C88-4E15-8BB2-A0D5EE289272} + + -1 + + 66fbffa5fa0aab38027702e20006304d + + + + + + + MtMouseController + {3C027CF8-11D2-42A6-BA8E-E523E83EC614} + + -1 + + 11014c28a2288ea7028eebe900029785 + + + MWindowManager - {5B2151AF-CC1E-4E89-A573-18E369841E89} + {C3D46337-6823-4BAB-B056-CDDB6AFEEB45} -1 - 66fbffa5fa0aab38027702e200044834 - - - - - - - MtCoreFunctions - {F70202B2-6C88-4E15-8BB2-A0D5EE289272} - - -1 - - 66fbffa5fa0aab38027702e20006304d - - - - - - - MtMouseController - {3C027CF8-11D2-42A6-BA8E-E523E83EC614} - - -1 - - 11014c28a2288ea7028eebe900029785 + 4b78783951982c7702dac31d001c27b6 @@ -4450,6 +4418,7 @@ return MtMouseController]]> true About + 0 {BF5775B2-25FE-4381-85DD-F7E0988FB689} false MtWindowTest + 0 {8BF522F9-887D-43EB-9400-D32749AB7991} false MtObjectMngTest + 0 {5DFD374C-1DC4-426C-8343-1EFE2C8FFEF8}