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

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
