Jump to content

Help Nedded About DGS


BogdanRTB

Recommended Posts

dgs = exports.dgs
local startup = true
local ladderState = false
local ladderHgt = 0
local ladderExt = 0
local ladderRot = 180

function makeGUI()
	if not getPedOccupiedVehicle(localPlayer) then
		outputChatBox( "Aceasta comanda nu functioneaza daca nu esti intr-o masina de tip ladder!", 255, 194, 14 )
		return
	end
		if getElementModel(getPedOccupiedVehicle(localPlayer)) == 544 and (not controlPanel) then
			local firetruckElement = getPedOccupiedVehicle (localPlayer)

			local ladderHeight = 0
			local ladderExt = 0
			local ladderRot = 0
			if getElementData(firetruckElement, "fdladder:height") then ladderHeight = getElementData(firetruckElement, "fdladder:height") end
			if getElementData(firetruckElement, "fdladder:extend") then ladderExt = getElementData(firetruckElement, "fdladder:extend") end
			if getElementData(firetruckElement, "fdladder:rotation") then ladderRot = getElementData(firetruckElement, "fdladder:rotation") end

			local width, height = 195, 210
			local sx, sy = guiGetScreenSize()
			local posX = (sx/2)-(width/2)
			local posY = (sy/2)-(height/2)

			local screenW, screenH = guiGetScreenSize()
			controlPanel = dgs:dgsCreateWindow((screenW - 262) / 2, (screenH - 339) / 2, 262, 339, "Meniu Control Scara", false)
			dgs:dgsWindowSetSizable(controlPanel, false)

			imageUp = dgs:dsgCreateImage(96, 72, 59, 63, "ladder_truck/img/ladder-upc.png", false, controlPanel)
			imageLeft = dgs:dgsCreateImage(36, 135, 60, 63, "ladder_truck/img/ladder-leftc.png", false, controlPanel)
			imageDown = dgs:dgsCreateImage(96, 198, 59, 63, "ladder_truck/img/ladder-downc.png", false, controlPanel)
			imageRight = dgs:dgsCreateImage(155, 135, 59, 63, "ladder_truck/img/ladder-rightc.png", false, controlPanel)
			closeButton = dgs:dgsCreateButton(204, 301, 34, 19, "X", false, controlPanel)
			guiSetProperty(closeButton, "NormalTextColour", "FFAAAAAA")
			imageIn = dgs:dgsCreateImage(96, 261, 60, 63, "ladder_truck/img/ladder-inc.png", false, controlPanel)
			imageOut = dgs:dgsCreateImage(95, 10, 60, 63, "ladder_truck/img/ladder-outc.png", false, controlPanel)
			
			showCursor(true)
			dgs:dgsWindowSetSizable (controlPanel, false)
			dgs:dgsWindowSetMovable (controlPanel, true)
		elseif (controlPanel and (not dgs:dgsGetVisible(controlPanel))) then
			dgs:dgsSetVisible(controlPanel, true)
			showCursor(true)
		elseif (controlPanel and dgs:dgsGetVisible(controlPanel)) then
			dgs:dgsSetVisible(controlPanel, false)
			showCursor(false)
	end
end
addCommandHandler("lc", makeGUI)


addEventHandler( "onClientMouseEnter", root,
    function()
        if (source == imageUp) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-up.png")
		elseif (source == imageRight) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-right.png")
		elseif (source == imageLeft) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-left.png")
		elseif (source == imageDown) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-down.png")
		elseif (source == imageIn) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-in.png")
		elseif (source == imageOut) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-out.png")	
		end
    end
)

addEventHandler( "onClientMouseLeave", root,
    function()
        if (source == imageUp) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-upc.png")
		elseif (source == imageRight) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-rightc.png")
		elseif (source == imageLeft) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-leftc.png")
		elseif (source == imageDown) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-downc.png")
		elseif (source == imageIn) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-inc.png")
		elseif (source == imageOut) then
			dgs:dgsImageSetImage( source, "ladder_truck/img/ladder-outc.png")		
		end	
	end
)

function closeGUI ()
	if (source == closeButton) then
	destroyElement(guiRoot)
	showCursor(false)
	controlPanel = nil
	end
end
addEventHandler ( "onClientGUIClick", getRootElement(), closeGUI)

function ladderControl(btn, state)
	if (source == imageUp) then	
		if (ladderHgt == -69) then return end
		ladderHgt = ladderHgt - 3
		triggerServerEvent("changeHeight", localPlayer, ladderHgt, true)
	elseif (source == imageDown) then	
		if (ladderHgt == 0) then return end
		ladderHgt = ladderHgt + 3
		triggerServerEvent("changeHeight", localPlayer, ladderHgt, true)	
	elseif (source == imageLeft) then	
		ladderRot = ladderRot + 5
		triggerServerEvent("changeRotation", localPlayer, ladderRot, true)	
	elseif (source == imageRight) then	
		ladderRot = ladderRot - 5
		triggerServerEvent("changeRotation", localPlayer, ladderRot, true)	
	elseif (source == imageIn) then	
		if (ladderExt == 0) then return end
		ladderExt = ladderExt + 0.5
		triggerServerEvent("changeLength", localPlayer, ladderExt, true)	
	elseif (source == imageOut) then	
		if (ladderExt == -6) then return end
		ladderExt = ladderExt - 0.5
		triggerServerEvent("changeLength", localPlayer, ladderExt, true)			
	end	
end
addEventHandler( "onClientGUIClick", root, ladderControl)

I just heard out about dgs and this is my first script I tried to translate to DGS but some of the DGS GUI doesn't load, what I did wrong in the code?

Okay, I resolved the events but I can't resolve a thing

spacer.png

There is now appearing a new close button on the panel and The bottom one doesn't work, how can I configure the button up on the pannel?

 

Or how to dezactivate it

Link to comment

Hello BogdanRTB,

I would like to comment on some things I noticed based on your script.

  • Did you mean to use guiSetProperty in your script? Take a look at the following line:
			guiSetProperty(closeButton, "NormalTextColour", "FFAAAAAA")

There is of course the dgsSetProperty function and the DGS automatic function-call translation layer. You should change the function call to make it proper.

  • I am wondering if passing size-dimensions (width, height) to dgsCreateWindow makes the content-area OR the entire window the provided size. And what start position do child elements take inside the DGS window element? Based on your finding I think that the (0,0) position for DGS window child elements is the top-left corner just-below the DGS window title bar. Maybe you have to adjust your layout code to be conformant of this finding!
Edited by The_GTA
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...