Jump to content

Potential oversight/bug in FrontEnd:DoHoverFocusUpdate function


hoxi
  • Pending
function FrontEnd:DoHoverFocusUpdate(manual_update)
    if self.tracking_mouse and not self.focus_locked then
		if manual_update then
			--something has been manually moved, so we want to update the entities under the mouse and re-evaluate the hover/focus state
			TheInput:UpdateEntitiesUnderMouse()
		end
	    local entitiesundermouse = TheInput:GetAllEntitiesUnderMouse() -- HERE
        local hover_inst = entitiesundermouse[1] -- HERE
        if hover_inst and hover_inst.widget then
            hover_inst.widget:SetFocus()
        elseif #self.screenstack > 0 then
            self.screenstack[#self.screenstack]:SetFocus()
        end
    end
end

TheInput:GetAllEntitiesUnderMouse simply returns the table with entities under the mouse and grabs the first one without filtering, so a mouse-through one might be used here.

Wouldn't it make more sense if Input had a function like:

-- name could also be "GetWorldOrHUDEntityUnderMouse", but that might be too long
function Input:GetEntityUnderMouse()
    return self.mouse_enabled and
        self.hoverinst ~= nil and
        self.hoverinst.entity:IsValid() and
        self.hoverinst.entity:IsVisible() and
        -- here there would normally be a Transform check to distinguish between World and HUD entities
        self.hoverinst or nil
end

And the FrontEnd function was changed to:

function FrontEnd:DoHoverFocusUpdate(manual_update)
    if self.tracking_mouse and not self.focus_locked then
        if manual_update then
            --something has been manually moved, so we want to update the entities under the mouse and re-evaluate the hover/focus state -- vanilla comment
            TheInput:UpdateEntitiesUnderMouse()
        end
        local hover_inst = TheInput:GetEntityUnderMouse()
        if hover_inst and hover_inst.widget then
            hover_inst.widget:SetFocus()
        elseif #self.screenstack > 0 then
            self.screenstack[#self.screenstack]:SetFocus()
        end
    end
end

 


Steps to Reproduce

Unsure if this is causing issues or could cause issues, but I get the feel it might not be intended.




User Feedback


There are no comments to display.



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...