Jump to content

[help] Dx Window bind


Artenos

Recommended Posts

Hey guys so I'm trying to create a window made out of dx drawings, I want to be able to use the same bind to open it and close it, But I also want it to be animated when it opens and closes. So far its not working.

This is what I got so far:

Client

local screenW, screenH = guiGetScreenSize() 
local start = getTickCount() 
  
---Variables----- 
local one, one1 = screenW * 1.0000, screenH * 0.0000 ---- The coordinates of the beginning 
local two, two1 = screenW * 0.8477, screenH * 0.0000 ---- The coordinates of the end 
-------------------------------------- 
  
----DxDrawings and Animations----- 
function PanelOpen() 
    local width, height = screenW * 0.1523, screenH * 1.0000 ---- The size of the dx rectangle  
    local now = getTickCount() 
    local x,y = interpolateBetween(one, one1, 0, two, two1, 0, (now - start) / ((start + 1000) - start), "OutBounce") 
    dxDrawRectangle(x,y, width, height, tocolor(0, 0, 0, 164), false) 
end 
  
function PanelClose() 
    local width, height = screenW * 0.1523, screenH * 1.0000 ---- The size of the dx rectangle  
    local now = getTickCount() 
    local x,y = interpolateBetween(two, two1, 0, one, one1, 0, (now - start) / ((start + 1000) - start), "Linear") 
    dxDrawRectangle(x,y, width, height, tocolor(0, 0, 0, 164), false) 
end 
------------------------------ 
  
-------Render of the drawings------------- 
function RenderPanel() 
    addEventHandler("onClientRender", root, PanelOpen) 
end 
  
function RenderPanel2() 
    addEventHandler("onClientRender", root, PanelClose) 
end 
------------------------------------------ 
  
---------Binds----------- 
bindKey("U", "down", RenderPanel) 
bindKey("U", "up", RenderPanel2) 

Link to comment
local bind = {State=false,KeyHere="u"} 
bindKey(bind.KeyHere,"down", 
function() 
    if bind.State == false then 
       -- addEventHandler Here your code 
  
        bind.State= true 
    else 
-- removeEventHandler Here your code 
        bind.State = false 
    end 
end) 

it works but it's not doing the animations

Link to comment

Phyton already answered you, add also the addEventHandlers about animations

function() 
    if bind.State == false then 
       -- addEventHandler Here your code 
  
        bind.State= true 
    else 
-- removeEventHandler Here your code 
        bind.State = false 
    end 
end 

Link to comment

hard to write ?

    local bind = {State=false,KeyHere="u"} 
    bindKey(bind.KeyHere,"down", 
    function() 
        if bind.State == false then 
           addEventHandler("onClientRender", root, PanelOpen) 
      
            bind.State= true 
        else 
    removeEventHandler("onClientRender", root, PanelClose) 
            bind.State = false 
        end 
    end) 
  

Closing animation

local bind = {State=false,KeyHere="u"} 
    bindKey(bind.KeyHere,"down", 
    function() 
        if bind.State == false then 
           addEventHandler("onClientRender", root, PanelOpen) 
      
            bind.State= true 
        else 
    addEventHandler("onClientRender", root, PanelClose) 
            bind.State = false 
        end 
    end) 
  
  

Link to comment

you can use in Anim :#

interpolateBetween or setTimer 

example for interpolateBetween :#

local start = getTickCount() 
function dxDrawLoading (x, y, width, height, x2, y2, size, color, color2, second) ---- i use Useful Function dxDrawLoading 
    local now = getTickCount() 
    local seconds = second 
    local with = interpolateBetween(0,0,0,width,0,0, (now - start) / ((start + seconds) - start), "Linear") 
    local text = interpolateBetween(0,0,0,100,0,0,(now - start) / ((start + seconds) - start),"Linear") 
        dxDrawText ( "Loading ... "..math.floor(text).."%", x2, y2 , width, height, tocolor ( 0, 255, 0, 255 ), size, "pricedown" ) 
        dxDrawRectangle(x, y ,width ,height -10, color) 
        dxDrawRectangle(x, y, with ,height -10, color2) 
end 
sx ,sy = guiGetScreenSize() 
cx, cy = 1440, 900 
button = guiCreateButton(313*sx/cx, 354*sy/cy, 162*sx/cx, 24*sy/cy,"",false) 
guiSetVisible(button, false) 
  
local start = getTickCount() 
    function dxx () 
    local now = getTickCount() 
    local wi, hi = interpolateBetween(0,0,0,757*sx/cx,682*sy/cy,0, ( now - start ) / (( start + 5000 ) - start),  "Linear") 
    local wit, hit = interpolateBetween(0, 0, 0, b1, b2, 0, (now - start) / ((start + 5000) - start), "Linear") 
    dxDrawRectangle(319*sx/cx, 109*sy/cy, wi, hi, tocolor(0, 0, 0, 130), false) 
    if now > start + 5000 then 
    addEventHandler("onClientRender",root,dd) 
    addEventHandler("onClientClick",root,Buton) 
    showCursor(true) 
    guiSetVisible(button, true) 
    guiSetAlpha(button, 0) 
    end 
end 
    function dd () 
    dxDrawRectangle(313*sx/cx, 354*sy/cy, 162*sx/cx, 24*sy/cy, tocolor(255,255,255, 255), false) 
    end 
function dxxx () 
    now = getTickCount() 
    local wi, hi = interpolateBetween(757*sx/cx,682*sy/cy,0,0,0,0, ( now - start ) / (( start + 5000 ) - start),  "Linear") 
    dxDrawRectangle(319*sx/cx, 109*sy/cy, wi, hi, tocolor(0, 0, 0, 130), false) 
    end 
        function dxLoad () 
            local now = getTickCount() 
        dxDrawLoading(196*sx/800, 482*sy/600,422*sx/800, 58*sy/600, 196*sx/800 , 450*sy/600 ,1.00*sx/800,tocolor(255,255,255,170),tocolor(0,0,255,170),5000) ---- i use Useful Function dxDrawLoading 
        if now > start + 5000 then 
        start = getTickCount() 
        outputChatBox("Done Downloading",0,255,0) 
        removeEventHandler("onClientRender",root,dxLoad) 
        addEventHandler("onClientRender",root,dxx) 
            end 
        end 
    addEventHandler("onClientRender",root,dxLoad) 
    addEventHandler("onClientGUIClick",button, 
        function () 
        now = getTickCount() 
        playSoundFrontEnd(3) 
        start = getTickCount() 
            addEventHandler("onClientRender",root,dxxx) 
            removeEventHandler("onClientRender",root,dxx) 
            removeEventHandler("onClientRender",root,dd) 
            removeEventHandler("onClientClick",root,Buton) 
            showCursor(false) 
            guiSetVisible(button, false) 
            if now > start + 5000 then 
            removeEventHandler("onClientRender",root,dxxx) 
        end 
end) 

Link to comment
hard to write ?
    local bind = {State=false,KeyHere="u"} 
    bindKey(bind.KeyHere,"down", 
    function() 
        if bind.State == false then 
           addEventHandler("onClientRender", root, PanelOpen) 
      
            bind.State= true 
        else 
    removeEventHandler("onClientRender", root, PanelClose) 
            bind.State = false 
        end 
    end) 
  

Closing animation

local bind = {State=false,KeyHere="u"} 
    bindKey(bind.KeyHere,"down", 
    function() 
        if bind.State == false then 
           addEventHandler("onClientRender", root, PanelOpen) 
      
            bind.State= true 
        else 
    addEventHandler("onClientRender", root, PanelClose) 
            bind.State = false 
        end 
    end) 
  
  

Didn't you read my other comment?

Link to comment
you can use in Anim :#
interpolateBetween or setTimer 

example for interpolateBetween :#

local start = getTickCount() 
function dxDrawLoading (x, y, width, height, x2, y2, size, color, color2, second) ---- i use Useful Function dxDrawLoading 
    local now = getTickCount() 
    local seconds = second 
    local with = interpolateBetween(0,0,0,width,0,0, (now - start) / ((start + seconds) - start), "Linear") 
    local text = interpolateBetween(0,0,0,100,0,0,(now - start) / ((start + seconds) - start),"Linear") 
        dxDrawText ( "Loading ... "..math.floor(text).."%", x2, y2 , width, height, tocolor ( 0, 255, 0, 255 ), size, "pricedown" ) 
        dxDrawRectangle(x, y ,width ,height -10, color) 
        dxDrawRectangle(x, y, with ,height -10, color2) 
end 
sx ,sy = guiGetScreenSize() 
cx, cy = 1440, 900 
button = guiCreateButton(313*sx/cx, 354*sy/cy, 162*sx/cx, 24*sy/cy,"",false) 
guiSetVisible(button, false) 
  
local start = getTickCount() 
    function dxx () 
    local now = getTickCount() 
    local wi, hi = interpolateBetween(0,0,0,757*sx/cx,682*sy/cy,0, ( now - start ) / (( start + 5000 ) - start),  "Linear") 
    local wit, hit = interpolateBetween(0, 0, 0, b1, b2, 0, (now - start) / ((start + 5000) - start), "Linear") 
    dxDrawRectangle(319*sx/cx, 109*sy/cy, wi, hi, tocolor(0, 0, 0, 130), false) 
    if now > start + 5000 then 
    addEventHandler("onClientRender",root,dd) 
    addEventHandler("onClientClick",root,Buton) 
    showCursor(true) 
    guiSetVisible(button, true) 
    guiSetAlpha(button, 0) 
    end 
end 
    function dd () 
    dxDrawRectangle(313*sx/cx, 354*sy/cy, 162*sx/cx, 24*sy/cy, tocolor(255,255,255, 255), false) 
    end 
function dxxx () 
    now = getTickCount() 
    local wi, hi = interpolateBetween(757*sx/cx,682*sy/cy,0,0,0,0, ( now - start ) / (( start + 5000 ) - start),  "Linear") 
    dxDrawRectangle(319*sx/cx, 109*sy/cy, wi, hi, tocolor(0, 0, 0, 130), false) 
    end 
        function dxLoad () 
            local now = getTickCount() 
        dxDrawLoading(196*sx/800, 482*sy/600,422*sx/800, 58*sy/600, 196*sx/800 , 450*sy/600 ,1.00*sx/800,tocolor(255,255,255,170),tocolor(0,0,255,170),5000) ---- i use Useful Function dxDrawLoading 
        if now > start + 5000 then 
        start = getTickCount() 
        outputChatBox("Done Downloading",0,255,0) 
        removeEventHandler("onClientRender",root,dxLoad) 
        addEventHandler("onClientRender",root,dxx) 
            end 
        end 
    addEventHandler("onClientRender",root,dxLoad) 
    addEventHandler("onClientGUIClick",button, 
        function () 
        now = getTickCount() 
        playSoundFrontEnd(3) 
        start = getTickCount() 
            addEventHandler("onClientRender",root,dxxx) 
            removeEventHandler("onClientRender",root,dxx) 
            removeEventHandler("onClientRender",root,dd) 
            removeEventHandler("onClientClick",root,Buton) 
            showCursor(false) 
            guiSetVisible(button, false) 
            if now > start + 5000 then 
            removeEventHandler("onClientRender",root,dxxx) 
        end 
end) 

I'm doing the animations like you showed me in one of my other posts:

local start = getTickCount() 
local one, one1 = 0, 0 ---- The coordinates of the beginning 
local two, two1 = 319, 109 ---- The coordinates of the end 
  
addEventHandler("onClientRender", root, 
function() 
    local now = getTickCount() 
    local x,y = interpolateBetween(one, one1, 0, two, two1, 0, (now - start) / ((start + 1500) - start), "Linear") 
    dxDrawRectangle(x,y, 680, 750, tocolor(0, 0, 0, 130), false) 
end) 

something simple

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...