Skip to content

Commit

Permalink
Merge branch 'window-manager'
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusGuy committed Jun 3, 2022
2 parents 461aafa + 94cd833 commit 9bc7f86
Showing 1 changed file with 174 additions and 35 deletions.
209 changes: 174 additions & 35 deletions Mt.rbxlx
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<CoordinateFrame name="CFrame">
<X>-175.490524</X>
<Y>51.1783447</Y>
<Z>78.4593201</Z>
<R00>-0.851734102</R00>
<R01>-0.0765281171</R01>
<R02>0.518355668</R02>
<R10>-7.45058149e-09</R10>
<R11>0.989276826</R11>
<R12>0.14605312</R12>
<R20>-0.523974478</R20>
<R21>0.124398418</R21>
<R22>-0.842600644</R22>
<X>-217.754074</X>
<Y>55.0020561</Y>
<Z>49.8049469</Z>
<R00>0.438246489</R00>
<R01>-0.56198597</R01>
<R02>0.701506793</R02>
<R10>-0</R10>
<R11>0.780445039</R11>
<R12>0.625224411</R12>
<R20>-0.898854852</R20>
<R21>-0.274002403</R21>
<R22>0.342027307</R22>
</CoordinateFrame>
<Ref name="CameraSubject">null</Ref>
<token name="CameraType">0</token>
<float name="FieldOfView">70</float>
<token name="FieldOfViewMode">0</token>
<CoordinateFrame name="Focus">
<X>-176.527237</X>
<Y>50.8862381</Y>
<Z>80.1445236</Z>
<X>-219.157089</X>
<Y>53.751606</Y>
<Z>49.1208916</Z>
<R00>1</R00>
<R01>0</R01>
<R02>0</R02>
Expand Down Expand Up @@ -559,6 +559,7 @@ local MWindowManager = require(repstrg.Mt.MtCore.MWindowManager)
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList,false)

local screen = MWindowManager:Init()
--screen:SetOverrideTopbar(false)

function putStuffOnWindow(window,stuff:{GuiObject})
for i,v in ipairs(stuff) do
Expand Down Expand Up @@ -1454,6 +1455,9 @@ local uis = game:GetService("UserInputService")
local MWidget = {
ClassName = "MWidget", -- See Mt.MtCore.MObject
Name = "widget", -- ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^

Size = {X=0,Y=0},
Position = {X=0,Y=0}
}

MWidget.Init = function(self,parent,_obj)
Expand All @@ -1473,32 +1477,80 @@ MWidget.Init = function(self,parent,_obj)
return _obj
end

MWidget.LimitCoordinate = function(self,coor:Vector2,min:Vector2,max:Vector2): Vector2
function MWidget.IsCoordinateBelowMax(self,coor:Vector2,max:Vector2): boolean
max=max or self:GetMaximumSize()
return coor.X < max.X and coor.Y < max.Y
end

function MWidget.IsCoordinateAboveMin(self,coor:Vector2,min:Vector2): boolean
min=min or self:GetMinimumSize()
return coor.X > 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()

if coor.X > max.X then coor = Vector2.new(max.X,coor.Y) end
if coor.Y > max.Y then coor = Vector2.new(coor.X,max.Y) end
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 coor = Vector2.new(min.X,coor.Y) end
if coor.Y < min.Y then coor = Vector2.new(coor.X,min.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

return coor
end

MWidget.SetSize = function(self,newsize:Vector2)
local limitedsize = self:LimitCoordinate(newsize)
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))
Expand All @@ -1508,6 +1560,7 @@ 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
Expand Down Expand Up @@ -1708,10 +1761,6 @@ 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
Expand Down Expand Up @@ -2464,6 +2513,8 @@ MWindowResizeRegion.Init = function(self,x,y,side,sx,sy,osx,osy,window,_obj)

_obj.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
Expand Down Expand Up @@ -2537,11 +2588,10 @@ MWindowResizeRegion.Init = function(self,x,y,side,sx,sy,osx,osy,window,_obj)
_obj.DraggingValue.Value = nil

_obj.ResizeEnded:Fire()
]]
end
end)

--MWindowResizeRegion.SetXRayEnabled(_obj,true)

return _obj
end

Expand Down Expand Up @@ -2781,7 +2831,7 @@ return MObject]]></ProtectedString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">MScreen</string>
<string name="ScriptGuid">{E113FF64-7C1B-432B-A92B-99BB89843598}</string>
<ProtectedString name="Source"><![CDATA[ local MObject = require(script.Parent.MObject)
<ProtectedString name="Source"><![CDATA[local MObject = require(script.Parent.MObject)
local MWidget = require(script.Parent.Parent.MtWidgets.MWidget)
local _getObjFromId = require(script.Parent.MtCoreFunctions)._getObjFromId

Expand Down Expand Up @@ -2935,6 +2985,7 @@ local _getMouseButton1Pressed = require(script.Parent.MtCoreFunctions)._getMouse
local _getObjFromId = require(script.Parent.MtCoreFunctions)._getObjFromId
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local MtMouseController = require(script.Parent.MtMouseController)

local MWindowManager = {
Name = "windowmanager",
Expand Down Expand Up @@ -2969,6 +3020,7 @@ MWindowManager.InitResize = function(self,window)
v.ResizeBegan.Event:Connect(function()
self:ToggleWindowBeingInteractedState()
window.WindowInteractionState = MtEnum.WindowInteractionState.Resizing
self:StartResizingWindow(window,v)
end)

v.ResizeEnded.Event:Connect(function()
Expand All @@ -2980,7 +3032,7 @@ end

MWindowManager.ToggleWindowBeingInteractedState = function(self)
self.WindowBeingInteracted = not self.WindowBeingInteracted
print(self.WindowBeingInteracted)
--print(self.WindowBeingInteracted)
end

MWindowManager.InitWindowFunctionality = function(self,window)
Expand Down Expand Up @@ -3100,6 +3152,90 @@ function MWindowManager.StartMovingWindow(self,window)
self:ToggleWindowBeingInteractedState()
end

function MWindowManager.GetVector2FromUDim2Offset(udim2:UDim2): Vector2
-- static function
return Vector2.new(udim2.X.Offset,udim2.Y.Offset)
end

function MWindowManager.StartResizingWindow(self,window,region)
local cl=uis:GetMouseLocation()
local wp=window.GetVector2FromUDim2Offset(window.Frame.Position)
local ws=window.GetVector2FromUDim2Offset(window.Frame.Size)

local sidex,sidey = self.GetResizeSidesFromLocation(cl,wp,ws)

region.DraggingValue.Value = region.Region

while _getMouseButton1Pressed(uis:GetMouseButtonsPressed()) and self.WindowBeingInteracted do

local ml = uis:GetMouseLocation()
local inc = Vector2.new(ml.X-cl.X,ml.Y-cl.Y)

local nsx,nsy
if sidex==MtEnum.ResizeSide.None then
nsx=ws.X
end
if sidex==MtEnum.ResizeSide.Left then
nsx=ws.X-(inc.X)
end
if sidex==MtEnum.ResizeSide.Right then
nsx=ws.X+(inc.X)
end
if sidey==MtEnum.ResizeSide.None then
nsy=ws.Y
end
if sidey==MtEnum.ResizeSide.Top then
nsy=ws.Y-(inc.Y)
end
if sidey==MtEnum.ResizeSide.Bottom then
nsy=ws.Y+(inc.Y)
end

window:SetSize(Vector2.new(nsx,nsy),sidex==MtEnum.ResizeSide.Left or sidey==MtEnum.ResizeSide.Top)

region.Resizing:Fire(window.Frame.Size,window.Frame.Position,ml)
MtMouseController:ChangeCursor(self.GetCursorFromResizeSide(sidex,sidey))

task.wait(.025)


end

MtMouseController:ResetCursor()
region.DraggingValue.Value = nil

region.ResizeEnded:Fire()
end

function MWindowManager.GetResizeSidesFromLocation(click:Vector2, winPos:Vector2, winSize:Vector2, regThickness:number): (string, string)
-- static function

regThickness = regThickness or 5 -- resize region thickness

local sidex=MtEnum.ResizeSide.None
local sidey=MtEnum.ResizeSide.None

if math.abs(click.X-winPos.X)<regThickness then sidex=MtEnum.ResizeSide.Left end
if math.abs(click.X-(winPos.X+winSize.X))<regThickness then sidex=MtEnum.ResizeSide.Right end
if math.abs(click.Y-winPos.Y)<regThickness then sidey=MtEnum.ResizeSide.Top end
if math.abs(click.Y-(winPos.Y+winSize.Y))<regThickness then sidey=MtEnum.ResizeSide.Bottom end

return sidex,sidey
end

function MWindowManager.GetCursorFromResizeSide(x:number,y:number):string
-- static function
-- haha no x and y aren't coordinates they're MtEnum.ResizeSide enums.

if x==0 and y==0 then return "" end -- none

if x~=0 and y==0 then return "rbxasset://textures/StudioUIEditor/icon_resize2.png" end -- horizontal
if y~=0 and x==0 then return "rbxasset://textures/StudioUIEditor/icon_resize4.png" end -- vertical

if x==y then return "rbxasset://textures/StudioUIEditor/icon_resize3.png" end -- diagonal north-east
if x~=y then return "rbxasset://textures/StudioUIEditor/icon_resize1.png" end -- diagonal north-west
end

function MWindowManager.TriggerInteraction(self,window)
self:ToggleWindowBeingInteractedState()
window.Interacted:Fire()
Expand Down Expand Up @@ -3227,27 +3363,30 @@ return funcs]]></ProtectedString>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">MtMouseController</string>
<string name="ScriptGuid">{3C027CF8-11D2-42A6-BA8E-E523E83EC614}</string>
<ProtectedString name="Source"><![CDATA[repeat task.wait() until game:IsLoaded()
<ProtectedString name="Source"><![CDATA[repeat task.wait() until game:IsLoaded() -- can't use game.Loaded because after the game is loaded, it won't fire the event again
local plr = game:GetService("Players").LocalPlayer
if not plr then error("Mt error: MtMouseController must be required by the client!") end
if not plr then error("Mt error: MtMouseController must be required by the client! (couldn't get player)") end
local mouse = plr:GetMouse()

local MtMouseController = {}

--[[
local cursor = ""


game:GetService("RunService").RenderStepped:Connect(function()
mouse.Icon=cursor
end)
]]

function MtMouseController:GetCursor(): string
return cursor
return mouse.Icon
end

function MtMouseController:ChangeCursor(icon: string)
icon=icon or ""
cursor=icon
--cursor=icon
mouse.Icon = icon
end

function MtMouseController:ResetCursor()
Expand Down

0 comments on commit 9bc7f86

Please sign in to comment.