function WeaponsGui.getWeightedScaleAmount(Q,H,G,n)return(((1-Q.scaleWeight)*H)*n)/G+Q.scaleWeight*H end function WeaponsGui.updateScale(n,H,G)if H:IsA("\071\117\105\079\098\106\101\099\116")then local Q=H.Size.X.Scale local O=H.Size.Y.Scale if Q~=0 or O~=0 or n.originalScaleAmounts[H]~=nil then if n.originalScaleAmounts[H]==nil then n.originalScaleAmounts[H]=Vector2.new(Q,O)end Q=n:getWeightedScaleAmount(n.originalScaleAmounts[H].X,G.X,n.referenceViewportSize.X)O=n:getWeightedScaleAmount(n.originalScaleAmounts[H].Y,G.Y,n.referenceViewportSize.Y)H.Size=UDim2.new(Q,0,O,0)end return end for H,Q in ipairs(H:GetChildren())do n:updateScale(Q,G)end end function WeaponsGui.setEnabled(G,H)if G.enabled==H then return end G.enabled=H if G.enabled then G.connections.renderStepped=RunService.RenderStepped:Connect(function(H)G:onRenderStepped(H)end)else G:setZoomed(false)for H,G in pairs(G.connections)do G:Disconnect()end G.connections={}end if G.gui then G.gui.Enabled=G.enabled end end function WeaponsGui.setCrosshairEnabled(G,H)if G.crosshairEnabled==H then return end G.crosshairEnabled=H if G.crosshairFrame then G.crosshairFrame.Visible=G.crosshairEnabled end if G.hitMarker then G.hitMarker.ImageTransparency=1 G.hitMarker.Visible=G.crosshairEnabled end end function WeaponsGui.setScopeEnabled(G,H)if G.scopeEnabled==H then return end G.scopeEnabled=H if G.scopeFrame then G.scopeFrame.Visible=G.scopeEnabled end local n=getJumpButton()if G.scopeEnabled then G.smallFireButton.Visible=true G.largeFireButton.Visible=true if n then n.Visible=false end else G.smallFireButton.Visible=false G.largeFireButton.Visible=false if n then n.Visible=true end end end function WeaponsGui.setCrosshairWeaponScale(G,H)if G.crosshairWeaponScale==H then return end G.crosshairWeaponScale=H end function WeaponsGui.setCrosshairScaleTarget(Q,H,G,n)if typeof(G)=="\110\117\109\098\101\114"then Q.crosshairDampingRatio=G end if typeof(n)=="\110\117\109\098\101\114"then Q.crosshairFrequency=n end if Q.crosshairScaleTarget==H then return end Q.crosshairScaleTarget=H SpringService:Target(Q,Q.crosshairDampingRatio,Q.crosshairFrequency,{crosshairScale=Q.crosshairScaleTarget})end function WeaponsGui.setCrosshairScale(G,H)if G.crosshairScale==H then return end G.crosshairScale=H SpringService:Target(G,G.crosshairDampingRatio,G.crosshairFrequency,{crosshairScale=G.crosshairScaleTarget})end function WeaponsGui.OnHitOtherPlayer(n,H,G)n.hitMarker.ImageTransparency=0 local Q=TweenInfo.new(.8)local O={}O.ImageTransparency=1 local Y=TweenService:Create(n.hitMarker,Q,O)Y:Play()DamageBillboardHandler:ShowDamageBillboard(H,G.Parent:FindFirstChild("\072\101\097\100"))end function WeaponsGui.onRenderStepped(G,H)if not G.enabled then return end if not G.gui then return end if G.crosshairFrame and G.crosshairEnabled then local H=(G.crosshairNormalSize*G.crosshairScale)*G.crosshairWeaponScale G.crosshairFrame.Size=UDim2.new(0,H.X,0,H.Y)end end function WeaponsGui.setZoomed(G,H)if H==G.isZoomed then return end G.isZoomed=H local n=G.isZoomed and AIM_OFF_NORMAL or AIM_ON_NORMAL local Q=G.isZoomed and AIM_OFF_PRESSED or AIM_ON_PRESSED if G.smallAimButton then G.smallAimButton.Image=n G.smallAimButton.PressedImage=Q end if G.largeAimButton then G.largeAimButton.Image=n G.largeAimButton.PressedImage=Q end if G.weaponsSystem.camera then G.weaponsSystem.camera:setForceZoomed(G.isZoomed)end end function WeaponsGui.onTouchAimButtonActivated(H)H:setZoomed(not H.isZoomed)end function WeaponsGui.onTouchFireButton(n,H,G)local Q=n.weaponsSystem.currentWeapon if Q and(Q.instance and Q.instance:IsA("\084\111\111\108"))then if H.UserInputState==Enum.UserInputState.Begin then Q.instance:Activate()if n.smallFireButton then n.smallFireButton.Image=FIRE_PRESSED end if n.largeFireButton then n.largeFireButton.Image=FIRE_PRESSED end;(H:GetPropertyChangedSignal("\085\115\101\114\073\110\112\117\116\083\116\097\116\101")):Connect(function()if H.UserInputState==Enum.UserInputState.End then Q.instance:Deactivate()if n.smallFireButton then n.smallFireButton.Image=FIRE_NORMAL end if n.largeFireButton then n.largeFireButton.Image=FIRE_NORMAL end end end)end end end return WeaponsGui
-- This scales the scale amount non-linearly according to scaleWeight
function WeaponsGui:getWeightedScaleAmount(originalScaleAmount, newScreenDim, referenceScreenDim)
	return (1 - self.scaleWeight) * originalScaleAmount * referenceScreenDim / newScreenDim
		+ self.scaleWeight * originalScaleAmount
end

function WeaponsGui:updateScale(guiObject, viewportSize)
	if guiObject:IsA("GuiObject") then
		local xScale = guiObject.Size.X.Scale
		local yScale = guiObject.Size.Y.Scale
		if xScale ~= 0 or yScale ~= 0 or self.originalScaleAmounts[guiObject] ~= nil then
			if self.originalScaleAmounts[guiObject] == nil then
				self.originalScaleAmounts[guiObject] = Vector2.new(xScale, yScale)
			end

			xScale = self:getWeightedScaleAmount(
				self.originalScaleAmounts[guiObject].X,
				viewportSize.X,
				self.referenceViewportSize.X
			)
			yScale = self:getWeightedScaleAmount(
				self.originalScaleAmounts[guiObject].Y,
				viewportSize.Y,
				self.referenceViewportSize.Y
			)
			guiObject.Size = UDim2.new(xScale, 0, yScale, 0)
		end
		return -- makes it so only the most outer container will be scaled
	end

	for _, child in ipairs(guiObject:GetChildren()) do
		self:updateScale(child, viewportSize)
	end
end

function WeaponsGui:setEnabled(enabled)
	if self.enabled == enabled then
		return
	end

	self.enabled = enabled
	if self.enabled then
		self.connections.renderStepped = RunService.RenderStepped:Connect(function(dt)
			self:onRenderStepped(dt)
		end)
	else
		self:setZoomed(false)

		for _, v in pairs(self.connections) do
			v:Disconnect()
		end
		self.connections = {}
	end

	if self.gui then
		self.gui.Enabled = self.enabled
	end
end

function WeaponsGui:setCrosshairEnabled(crosshairEnabled)
	if self.crosshairEnabled == crosshairEnabled then
		return
	end

	self.crosshairEnabled = crosshairEnabled
	if self.crosshairFrame then
		self.crosshairFrame.Visible = self.crosshairEnabled
	end
	if self.hitMarker then
		self.hitMarker.ImageTransparency = 1
		self.hitMarker.Visible = self.crosshairEnabled
	end
end

function WeaponsGui:setScopeEnabled(scopeEnabled)
	if self.scopeEnabled == scopeEnabled then
		return
	end

	self.scopeEnabled = scopeEnabled
	if self.scopeFrame then
		self.scopeFrame.Visible = self.scopeEnabled
	end

	local jumpButton = getJumpButton()

	if self.scopeEnabled then
		self.smallFireButton.Visible = true
		self.largeFireButton.Visible = true

		if jumpButton then
			jumpButton.Visible = false
		end
	else
		self.smallFireButton.Visible = false
		self.largeFireButton.Visible = false

		if jumpButton then
			jumpButton.Visible = true
		end
	end
end

function WeaponsGui:setCrosshairWeaponScale(scale)
	if self.crosshairWeaponScale == scale then
		return
	end

	self.crosshairWeaponScale = scale
end

function WeaponsGui:setCrosshairScaleTarget(target, dampingRatio, frequency)
	if typeof(dampingRatio) == "number" then
		self.crosshairDampingRatio = dampingRatio
	end
	if typeof(frequency) == "number" then
		self.crosshairFrequency = frequency
	end
	if self.crosshairScaleTarget == target then
		return
	end

	self.crosshairScaleTarget = target
	SpringService:Target(
		self,
		self.crosshairDampingRatio,
		self.crosshairFrequency,
		{ crosshairScale = self.crosshairScaleTarget }
	)
end

function WeaponsGui:setCrosshairScale(scale)
	if self.crosshairScale == scale then
		return
	end

	self.crosshairScale = scale
	SpringService:Target(
		self,
		self.crosshairDampingRatio,
		self.crosshairFrequency,
		{ crosshairScale = self.crosshairScaleTarget }
	)
end

function WeaponsGui:OnHitOtherPlayer(damage, humanoidHit) -- show hit indicator, then fade
	self.hitMarker.ImageTransparency = 0
	local tweenInfo = TweenInfo.new(0.8)
	local goal = {}
	goal.ImageTransparency = 1
	local tween = TweenService:Create(self.hitMarker, tweenInfo, goal)
	tween:Play()

	DamageBillboardHandler:ShowDamageBillboard(damage, humanoidHit.Parent:FindFirstChild("Head"))
end

function WeaponsGui:onRenderStepped(dt)
	if not self.enabled then
		return
	end
	if not self.gui then
		return
	end

	if self.crosshairFrame and self.crosshairEnabled then
		local crosshairSize = self.crosshairNormalSize * self.crosshairScale * self.crosshairWeaponScale
		self.crosshairFrame.Size = UDim2.new(0, crosshairSize.X, 0, crosshairSize.Y)
	end
end

function WeaponsGui:setZoomed(zoomed)
	if zoomed == self.isZoomed then
		return
	end

	self.isZoomed = zoomed
	local normalImage = self.isZoomed and AIM_OFF_NORMAL or AIM_ON_NORMAL
	local pressedImage = self.isZoomed and AIM_OFF_PRESSED or AIM_ON_PRESSED

	if self.smallAimButton then
		self.smallAimButton.Image = normalImage
		self.smallAimButton.PressedImage = pressedImage
	end
	if self.largeAimButton then
		self.largeAimButton.Image = normalImage
		self.largeAimButton.PressedImage = pressedImage
	end

	if self.weaponsSystem.camera then
		self.weaponsSystem.camera:setForceZoomed(self.isZoomed)
	end
end

function WeaponsGui:onTouchAimButtonActivated()
	self:setZoomed(not self.isZoomed)
end

function WeaponsGui:onTouchFireButton(inputObj, inputState)
	local currentWeapon = self.weaponsSystem.currentWeapon
	if currentWeapon and currentWeapon.instance and currentWeapon.instance:IsA("Tool") then
		if inputObj.UserInputState == Enum.UserInputState.Begin then
			currentWeapon.instance:Activate()
			if self.smallFireButton then
				self.smallFireButton.Image = FIRE_PRESSED
			end
			if self.largeFireButton then
				self.largeFireButton.Image = FIRE_PRESSED
			end

			inputObj:GetPropertyChangedSignal("UserInputState"):Connect(function()
				if inputObj.UserInputState == Enum.UserInputState.End then
					currentWeapon.instance:Deactivate()
					if self.smallFireButton then
						self.smallFireButton.Image = FIRE_NORMAL
					end
					if self.largeFireButton then
						self.largeFireButton.Image = FIRE_NORMAL
					end
				end
			end)
		end
	end
end

return WeaponsGui
