Jump to content

Destroy DX Gui?


rusztamas

Recommended Posts

Hi! I made a dxDraw Gui and it contains 3 texts, and 3 rectangles. All of them has been defined, as values/instructions, so they could be used as variables.
Script:
 

function dxDraw()
showCursor(true)
local mX, mY = 1366, 768
local jX, jY = guiGetScreenSize()
hatter = dxDrawRectangle (jX/3.2, jY/4, 500, 350, tocolor(0, 0, 0, 150)) -- háttér
hattertext = dxDrawText ("Csatlakozol?", jX/3.2+130, jY/4+75, _, _, _, 3, "sans", "left", "top") -- háttér szöveg
igen = dxDrawRectangle (jX/3, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- igen
igentext = dxDrawText ("Igen", jX/2-195, jY-300, _, _, _, 3, "sans", "left", "top") -- igen szöveg
nem = dxDrawRectangle (jX/3+295, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- nem
nemtext = dxDrawText ("Nem", jX/3+325, jY-297, _, _, _, 3, "sans", "left", "top") -- nem szöveg
end
addEventHandler ("onClientRender", getRootElement(), dxDraw)

function nemclick()
destroyElement (hatter)
end
addEventHandler("onClientGUIClick", nem, nemclick) 

my problem, is when i click on rectangle "nem" the rectangle "hatter" is not getting destroyed, but stays the same. what the problem could be?

Link to comment

you can not use 'destroyElement' to destroy/hide dx drawing function 'cause it's not an element. You have to use some kind of variable to know if that dx drawing need to be draw. Also don't use 'guiGetScreenSize' or 'showCursor' function in 'onClientRender' eventHandler. It's no need for that it will do fine if you call it once not constantly when player updates frames.

local mX, mY = 1366, 768
local jX, jY = guiGetScreenSize()

local showDxDrawing = false;

function dxDraw()
  if (not showDxDrawing) then return; end
  hatter = dxDrawRectangle (jX/3.2, jY/4, 500, 350, tocolor(0, 0, 0, 150)) -- háttér
  hattertext = dxDrawText ("Csatlakozol?", jX/3.2+130, jY/4+75, _, _, _, 3, "sans", "left", "top") -- háttér szöveg
  igen = dxDrawRectangle (jX/3, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- igen
  igentext = dxDrawText ("Igen", jX/2-195, jY-300, _, _, _, 3, "sans", "left", "top") -- igen szöveg
  nem = dxDrawRectangle (jX/3+295, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- nem
  nemtext = dxDrawText ("Nem", jX/3+325, jY-297, _, _, _, 3, "sans", "left", "top") -- nem szöveg
end
addEventHandler ("onClientRender", getRootElement(), dxDraw)

function nemclick()
  showDxDrawing = not showDxDrawing;
  showCursor(not isCursorShowing())
end
addEventHandler("onClientGUIClick", nem, nemclick) 

 

EDIT: @rusztamas just noticed, you used GUI event handler to detect DX click. You CAN NOT use GUI events to detect DX 'cause DX is not same as GUI. You can use "useful function" from wiki 'isMouseInPosition' and event 'onClientKey' to detect dx click.

correct code would be this

local mX, mY = 1366, 768
local jX, jY = guiGetScreenSize()

local showDxDrawing = false;

function dxDraw()
  if (not showDxDrawing) then return; end
  dxDrawRectangle (jX/3.2, jY/4, 500, 350, tocolor(0, 0, 0, 150)) -- háttér
  dxDrawText ("Csatlakozol?", jX/3.2+130, jY/4+75, _, _, _, 3, "sans", "left", "top") -- háttér szöveg
  dxDrawRectangle (jX/3, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- igen
  dxDrawText ("Igen", jX/2-195, jY-300, _, _, _, 3, "sans", "left", "top") -- igen szöveg
  dxDrawRectangle (jX/3+295, jY-300, 150, 50, tocolor(0, 200, 0, 150)) -- nem
  dxDrawText ("Nem", jX/3+325, jY-297, _, _, _, 3, "sans", "left", "top") -- nem szöveg
end
addEventHandler ("onClientRender", getRootElement(), dxDraw)

-- function from wiki.multitheftauto.com (not written by me)
function isMouseInPosition ( x, y, width, height )
	if ( not isCursorShowing( ) ) then
		return false
	end
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
        return true
    else
        return false
    end
end

function nemclick(button,press)
  if (isMouseInPosition(jX/3+295, jY-300, 150, 50)) then
    if (button == "mouse1" and press) then
      showDxDrawing = not showDxDrawing;
      showCursor(not isCursorShowing());
    end
  end
end
addEventHandler("onClientKey", root, nemclick);

 

Edited by Fist
  • 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...