Jump to content

Creating close Button.


ramzi

Recommended Posts

Hi guys,i had a big problem with creating an exit button for my panel!

should i use this function?:

this is the original button to create:

editorForm.createBtn = guiCreateButton ( 32, 410, 124, 28, "Create", false, editorForm.wnd )

But i want to create Close button,like this:

editorForm.createBtn = guiCreateButton ( 32, 410, 124, 28, "Close", false, "problem is here!wht funsciton i use to close the Gui? )

plz help me

Link to comment

Here is the full lua:

addEvent ( "onClientTCTToggle", true ) 
  
editorForm = { 
    settings = { } 
} 
  
function createMainWindow ( ) 
    editorForm.wnd = guiCreateWindow(42, 73, 717, 462, "Building Panel", false) 
    guiWindowSetSizable ( editorForm.wnd, false ) 
     
    Meme = guiCreateMemo(9, 39, 171, 303, "This panel is used for events/rps.", false, editorForm.wnd) 
    guiMemoSetReadOnly(Meme, true)  
    editorForm.leftPanel = guiCreateTabPanel ( 185, 17, 294, 435, false, editorForm.wnd ) 
     
    createEntityTab ( "Object", "objects.xml" ) 
    createEntityTab ( "Vehicle", "vehicles.xml" ) 
    createEntityTab ( "Ped", "peds.xml" ) 
     
    editorForm.createEdit = guiCreateEdit ( 10, 370, 166, 30, "ID", false, editorForm.wnd ) 
    editorForm.createBtn = guiCreateButton ( 32, 410, 124, 28, "Create", false, editorForm.wnd ) 
        editorForm.createBtn = guiCreateButton ( 28, 385, 115, 20, "Create", false, editorForm.wnd ) 
     
    editorForm.rightPanel = guiCreateTabPanel ( 479, 17, 228, 435, false, editorForm.wnd ) 
  
    editorForm.toolsTab = guiCreateTab ( "TooL Hack", editorForm.rightPanel ) 
    editorForm.toolsList = guiCreateGridList ( 0.02, 0.02, 0.42, 0.96, true, editorForm.toolsTab ) 
    guiGridListAddColumn ( editorForm.toolsList, "Editor Gate", 0.8 ) 
    guiGridListSetSortingEnabled ( editorForm.toolsList, false ) 
    guiGridListSetSelectionMode ( editorForm.toolsList, 0 ) 
      
    editorForm.optionsTab = guiCreateTab ( "Settings", editorForm.rightPanel ) 
    editorForm.optionsScrollPane = guiCreateScrollPane ( 0.04, 0.02, 0.92, 0.96, true, editorForm.optionsTab ) 
  
    createSetting ( "s_step", {  
        "edit", 
         
        text = "Step",  
        value = 0.1 
    } ) 
    createSetting ( "s_saveOffs", {  
        "checkbox", 
         
        text = "Save offsets",  
        selected = true 
    } ) 
    createSetting ( "s_thelp", {  
        "checkbox", 
         
        text = "Tool helper",  
        selected = true 
    } ) 
    createSetting ( "s_resetOffs", {  
        "button", 
         
        text = "Reset offsets",  
        onClick = function ( ) 
            g_entityOffset.reset ( ) 
        end 
    } ) 
   
    addEventHandler ( "onClientGUIClick", editorForm.wnd, click ) 
   
    guiSetVisible ( editorForm.wnd, false ) 
end 
  
function click ( ) 
    if getElementType ( source ) == "gui-gridlist" then 
        local selectedRow = guiGridListGetSelectedItem ( source ) 
         
        if selectedRow < 0 then 
            setSelectedTool ( getToolFromName ( "Default" ) ) 
                 
            for element, _ in pairs ( bindedGridLists ) do 
                guiGridListSetSelectedItem ( element, -1, 0 ) 
            end 
                         
            guiGridListSetSelectedItem ( editorForm.toolsList, -1, 0 ) 
             
            return 
        end 
    end 
     
    if source == editorForm.createBtn then 
        local model = tonumber ( guiGetText ( editorForm.createEdit ) ) 
         
        if model then 
            setSelectedTool ( getToolFromName ( "Default" ) ) 
             
            for gridlist, _ in pairs ( bindedGridLists ) do 
                guiGridListSetSelectedItem ( gridlist, -1, 0 ) 
            end 
             
            guiGridListSetSelectedItem ( editorForm.toolsList, -1, 0 ) 
    
            local element = createEntity ( model, g_entityOffset.calcPosition ( ) ) 
            if element then 
                setEditorTarget ( element ) 
            else 
                outputChatBox ( "WBO: Incorrect object model" ) 
            end 
        else 
            outputChatBox ( "WBO: Incorrect object model" ) 
        end 
    elseif source == editorForm.toolsList then   
        for gridlist, _ in pairs ( bindedGridLists ) do 
            guiGridListSetSelectedItem ( gridlist, -1, 0 ) 
        end 
   
        local selectedItem = guiGridListGetSelectedItem ( source ) 
        if selectedItem > -1 then 
            local toolName = guiGridListGetItemText ( source, selectedItem, 1 ) 
            setSelectedTool ( getToolFromName ( toolName ) ) 
        end 
    end 
end 
  
addEventHandler ( "onClientTCTToggle", resourceRoot, 
    function ( ) 
        local visible = not guiGetVisible ( editorForm.wnd ) 
     
        guiSetInputEnabled ( visible ) 
        guiSetVisible ( editorForm.wnd, visible ) 
        showCursor ( visible ) 
    end 
, false ) 
  
function editorCreateEntity ( gridlist, model ) 
    setSelectedTool ( getToolFromName ( "Default" ) ) 
                         
    for element, _ in pairs ( bindedGridLists ) do 
        if element ~= gridlist then 
            guiGridListSetSelectedItem ( element, -1, 0 ) 
        end 
    end 
                         
    guiGridListSetSelectedItem ( editorForm.toolsList, -1, 0 ) 
                     
    local element = createEntity ( tonumber ( model ), g_entityOffset.calcPosition ( ) ) 
    if element then 
        setEditorTarget ( element ) 
    end 
end 
  
function createEntityTab ( name, xmlfile ) 
    local entityTab = {  
        tab = guiCreateTab ( name, editorForm.leftPanel ) 
    } 
    entityTab.gridlist = guiCreateGridList ( 0.02, 0.02, 0.96, 0.96, true, entityTab.tab ) 
     
    guiGridListSetSortingEnabled ( entityTab.gridlist, false ) 
    guiGridListSetSelectionMode ( entityTab.gridlist, 0 ) 
    guiGridListAddColumn ( entityTab.gridlist, "Object Creator", 0.8 ) 
     
     
    guiGridListLoadTable ( entityTab.gridlist, loadList ( "conf\\" .. xmlfile ), editorCreateEntity ) 
     
    return entityTab 
end 
  
function createSetting ( id, tbl ) 
    editorForm.settings [ id ] = createControl ( tbl, editorForm.optionsScrollPane ) 
     
    return editorForm.settings [ id ] 
end 
  
function getSettingByID ( id ) 
    return editorForm.settings [ id ] 
end 

should i add this line?:

btnClose = guiCreateButton(28, 385, 115, 20, "Close", true )

function changeVisibility ( )

-- we check if the gui element is visible

guiSetVisible (MainWindow, not guiGetVisible ( MainWindow ) )

end

or:

addEventHandler ( "onClientGUIClick", editorForm.wnd, click )

guiSetVisible ( editorForm.wnd, false )

Link to comment

That 'full code' clearly shows you're not a newbie in scripting, but whatever...

btnClose = guiCreateButton(28, 385, 115, 20, "Close", true ) 
addEventHandler ( "onClientGUIClick", btnClose,  
  function ( ) 
    guiSetVisible (MainWindow, not guiGetVisible ( MainWindow ) ) 
  end 
)  

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