Jump to content

Why createWindow is triggering on click event?


Hiding

Recommended Posts

Hello, I created a window panel, but every time when the cursore is showing, for example if I open the admin panel and click somewhere then this createWindow() is triggering, I mean it appears for a second.. I don't know how to avoid this
 

addEventHandler("onClientClick", root, function(button, state, absoluteX, absoluteY)
	if button == "left" and state == "down" then
		local panelX, panelY, buttonHeight, sidebarWidth, screenScale = createWindow()
		for i, buttonData in ipairs(settingsTitles) do
			local buttonX = panelX + 4
			local buttonY = panelY + (i - 1) * (buttonHeight + 2)
			local buttonWidth = sidebarWidth - 8
			local buttonHeight = 50 * screenScale
			if absoluteX >= buttonX and absoluteX <= buttonX + buttonWidth and absoluteY >= buttonY and absoluteY <= buttonY + buttonHeight then
				activeButton = i
			end
		end
	end
end)

function handleButtonCloseWindow(button, state, absoluteX, absoluteY)
    if button == "left" and state == "down" then
        local _ , _ , _ , _ , _ , closeButtonWidth, closeButtonHeight, closeButtonX, closeButtonY = createWindow()
        if absoluteX >= closeButtonX and absoluteX <= closeButtonX + closeButtonWidth and absoluteY >= closeButtonY and absoluteY <= closeButtonY + closeButtonHeight then
            isRendering = false
            showCursor(false)
            removeEventHandler("onClientRender", root, createWindow)
        end
    end
end
addEventHandler("onClientClick", root, handleButtonCloseWindow)


local function addBindKey()
    isRendering = not isRendering

    if (isRendering) then
        addEventHandler("onClientRender", root, createWindow)
        showCursor(true)
    else
        showCursor(false)
        removeEventHandler("onClientRender", root, createWindow)
    end
end
bindKey("F1", "down", addBindKey)

 

Link to comment

u can solve this by checking if the cursor is already showing when onClientClick is triggered 

addEventHandler("onClientClick", root, function(button, state, absoluteX, absoluteY)
    if button == "left" and state == "down" then
        if not isCursorShowing() then -- Added this line
            local panelX, panelY, buttonHeight, sidebarWidth, screenScale = createWindow()
            for i, buttonData in ipairs(settingsTitles) do
                local buttonX = panelX + 4
                local buttonY = panelY + (i - 1) * (buttonHeight + 2)
                local buttonWidth = sidebarWidth - 8
                local buttonHeight = 50 * screenScale
                if absoluteX >= buttonX and absoluteX <= buttonX + buttonWidth and absoluteY >= buttonY and absoluteY <= buttonY + buttonHeight then
                    activeButton = i
                end
            end
        end -- Added this line
    end
end)

function handleButtonCloseWindow(button, state, absoluteX, absoluteY)
    if button == "left" and state == "down" then
        local _ , _ , _ , _ , _ , closeButtonWidth, closeButtonHeight, closeButtonX, closeButtonY = createWindow()
        if absoluteX >= closeButtonX and absoluteX <= closeButtonX + closeButtonWidth and absoluteY >= closeButtonY and absoluteY <= closeButtonY + closeButtonHeight then
            isRendering = false
            showCursor(false)
            removeEventHandler("onClientRender", root, createWindow)
        end
    end
end
addEventHandler("onClientClick", root, handleButtonCloseWindow)


local function addBindKey()
    isRendering = not isRendering

    if (isRendering) then
        addEventHandler("onClientRender", root, createWindow)
        showCursor(true)
    else
        showCursor(false)
        removeEventHandler("onClientRender", root, createWindow)
    end
end
bindKey("F1", "down", addBindKey)

 

Link to comment
1 hour ago, FLUSHBICEPS said:

u can solve this by checking if the cursor is already showing when onClientClick is triggered 

addEventHandler("onClientClick", root, function(button, state, absoluteX, absoluteY)
    if button == "left" and state == "down" then
        if not isCursorShowing() then -- Added this line
            local panelX, panelY, buttonHeight, sidebarWidth, screenScale = createWindow()
            for i, buttonData in ipairs(settingsTitles) do
                local buttonX = panelX + 4
                local buttonY = panelY + (i - 1) * (buttonHeight + 2)
                local buttonWidth = sidebarWidth - 8
                local buttonHeight = 50 * screenScale
                if absoluteX >= buttonX and absoluteX <= buttonX + buttonWidth and absoluteY >= buttonY and absoluteY <= buttonY + buttonHeight then
                    activeButton = i
                end
            end
        end -- Added this line
    end
end)

function handleButtonCloseWindow(button, state, absoluteX, absoluteY)
    if button == "left" and state == "down" then
        local _ , _ , _ , _ , _ , closeButtonWidth, closeButtonHeight, closeButtonX, closeButtonY = createWindow()
        if absoluteX >= closeButtonX and absoluteX <= closeButtonX + closeButtonWidth and absoluteY >= closeButtonY and absoluteY <= closeButtonY + closeButtonHeight then
            isRendering = false
            showCursor(false)
            removeEventHandler("onClientRender", root, createWindow)
        end
    end
end
addEventHandler("onClientClick", root, handleButtonCloseWindow)


local function addBindKey()
    isRendering = not isRendering

    if (isRendering) then
        addEventHandler("onClientRender", root, createWindow)
        showCursor(true)
    else
        showCursor(false)
        removeEventHandler("onClientRender", root, createWindow)
    end
end
bindKey("F1", "down", addBindKey)

 

Thank you, but now the activeButton is not working as well, so it didn't help

Link to comment
addEventHandler("onClientClick", root, function(button, state, absoluteX, absoluteY)
    if button == "left" and state == "down" then
        if isRendering and isCursorShowing() then
            local panelX, panelY, buttonHeight, sidebarWidth, screenScale = createWindow()
            for i, buttonData in ipairs(settingsTitles) do
                local buttonX = panelX + 4
                local buttonY = panelY + (i - 1) * (buttonHeight + 2)
                local buttonWidth = sidebarWidth - 8
                local buttonHeight = 50 * screenScale
                if absoluteX >= buttonX and absoluteX <= buttonX + buttonWidth and absoluteY >= buttonY and absoluteY <= buttonY + buttonHeight then
                    activeButton = i
                end
            end
        elseif not isCursorShowing() then
            local panelX, panelY, buttonHeight, sidebarWidth, screenScale = createWindow()
        end
    end
end)

function handleButtonCloseWindow(button, state, absoluteX, absoluteY)
    if button == "left" and state == "down" then
        local _ , _ , _ , _ , _ , closeButtonWidth, closeButtonHeight, closeButtonX, closeButtonY = createWindow()
        if absoluteX >= closeButtonX and absoluteX <= closeButtonX + closeButtonWidth and absoluteY >= closeButtonY and absoluteY <= closeButtonY + closeButtonHeight then
            isRendering = false
            showCursor(false)
            removeEventHandler("onClientRender", root, createWindow)
        end
    end
end
addEventHandler("onClientClick", root, handleButtonCloseWindow)

local function addBindKey()
    isRendering = not isRendering

    if (isRendering) then
        addEventHandler("onClientRender", root, createWindow)
        showCursor(true)
    else
        showCursor(false)
        removeEventHandler("onClientRender", root, createWindow)
    end
end
bindKey("F1", "down", addBindKey)

 

  • Like 1
Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...