..:D&G:.. Posted June 12, 2016 Posted June 12, 2016 So I made this dx window and I've drawn an "X" to be used as a button to close the window. function isCursorOverText(posX, posY, sizeX, sizeY) if(isCursorShowing()) then local cX, cY = getCursorPosition() local screenWidth, screenHeight = guiGetScreenSize() local cX, cY = (cX*screenWidth), (cY*screenHeight) if(cX >= posX and cX <= posX+(sizeX - posX)) and (cY >= posY and cY <= posY+(sizeY - posY)) then return true else return false end else return false end end function renderCmdsPanel() dxDrawText("X", s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080, tocolor(255, 255, 255, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) end addEventHandler("onClientRender", getRootElement(), renderCmdsPanel) addEventHandler("onClientClick", getRootElement(), closeXButton) function closeXButton(button, state) local xButton = isCursorOverText(s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080) if (button == "left" and state == "down" and xButton) then guiSetVisible(tabPanel, false) showCursor (false) guiSetInputEnabled(false) tabPanel = nil removeEventHandler("onClientRender", getRootElement(), renderCmdsPanel) removeEventHandler("onClientClick", getRootElement(), closeXButton) end end I've used the same method for for my other windows and it works, but here, it only works when I have gui editor active, as if the "onClientClick" event is triggered only when in guieditor... Any ideas? Thanks.
Castillo Posted June 12, 2016 Posted June 12, 2016 You added the event handler before the function was even defined.
..:D&G:.. Posted June 12, 2016 Author Posted June 12, 2016 That was just the main things I have in the code, but it goes like this: function closeXButton(button, state) local xButton = isCursorOverText(s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080) if (button == "left" and state == "down" and xButton) then guiSetVisible(tabPanel, false) showCursor (false) guiSetInputEnabled(false) tabPanel = nil removeEventHandler("onClientRender", getRootElement(), renderCmdsPanel) removeEventHandler("onClientClick", getRootElement(), closeXButton) end end function commandsHelp() local loggedIn = getElementData(sourcePlayer, "loggedin") if (loggedIn == 1) then guiSetInputEnabled(true) addEventHandler("onClientRender", getRootElement(), renderCmdsPanel) addEventHandler("onClientClick", getRootElement(), closeXButton) ............. So I don't think that would be the problem.
Castillo Posted June 13, 2016 Posted June 13, 2016 Well, if you post incomplete code, how I'm supposed to know?
..:D&G:.. Posted June 13, 2016 Author Posted June 13, 2016 [quote name=..&G:..] local s = {guiGetScreenSize()} function renderCmdsPanel() textFont2 = 1.30/1920*s[1] textFont = 1.00/1920*s[1] local r, g, b = exports.gui:getPlayerBaseColor(getLocalPlayer()) dxDrawText("X", s[1]*(1265 - 1)/1920, s[2]*(239 - 1)/1080, s[1]*(1318 - 1)/1920, s[2]*(260 - 1)/1080, tocolor(0, 0, 0, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) dxDrawText("X", s[1]*(1265 + 1)/1920, s[2]*(239 - 1)/1080, s[1]*(1318 + 1)/1920, s[2]*(260 - 1)/1080, tocolor(0, 0, 0, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) dxDrawText("X", s[1]*(1265 - 1)/1920, s[2]*(239 + 1)/1080, s[1]*(1318 - 1)/1920, s[2]*(260 + 1)/1080, tocolor(0, 0, 0, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) dxDrawText("X", s[1]*(1265 + 1)/1920, s[2]*(239 + 1)/1080, s[1]*(1318 + 1)/1920, s[2]*(260 + 1)/1080, tocolor(0, 0, 0, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) dxDrawText("X", s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080, tocolor(255, 255, 255, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) dxDrawText("Welcome to the commands panel!", s[1]*574/1920, s[2]*271/1080, s[1]*1243/1920, s[2]*318/1080, tocolor(255, 255, 255, 255), textFont2, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("Commands Panel", s[1]*849/1920, s[2]*239/1080, s[1]*969/1920, s[2]*261/1080, tocolor(255, 255, 255, 255), textFont, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("© World Gaming", s[1]*497/1920, s[2]*239/1080, s[1]*665/1920, s[2]*261/1080, tocolor(255, 255, 255, 255), textFont, "default", "center", "center", false, false, false, false, false) end function closeXButton(button, state) local xButton = isCursorOverText(s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080) if (button == "left" and state == "down" and xButton) then guiSetVisible(tabPanel, false) showCursor (false) guiSetInputEnabled(false) tabPanel = nil removeEventHandler("onClientRender", getRootElement(), renderCmdsPanel) removeEventHandler("onClientClick", getRootElement(), closeXButton) end end function commandsHelp() local loggedIn = getElementData(sourcePlayer, "loggedin") if (loggedIn == 1) then guiSetInputEnabled(true) addEventHandler("onClientRender", getRootElement(), renderCmdsPanel) addEventHandler("onClientClick", getRootElement(), closeXButton) ............. This IS the complete code. The bit with dots is just a gridlist ...
Castillo Posted June 13, 2016 Posted June 13, 2016 Apart from guiSetInputEnabled, did you use showCursor?
..:D&G:.. Posted June 13, 2016 Author Posted June 13, 2016 Apart from guiSetInputEnabled, did you use showCursor? Lol, after I read your post, I noticed that I didn't use showCursor when opening the window, as I have an external script which shows the cursor when I press M, but after adding showCursor to the window, it works Thanks!
KariiiM Posted June 13, 2016 Posted June 13, 2016 Also, showCursor is a resource based, if you use showCursor in another resource you have to hide it from the same resource else it won't be hidden.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now