Jump to content

GUI isn't working as it's supposed to


laurens

Recommended Posts

Looks like the complete GUI environment in MTA is behaving odd. I created a script that pops up when you load the resource. But it just aint working.

popup.lua (client side)

  
popupWindow = guiCreateWindow ( 0.15, 0.2, 0.7, 0.6, "Information", true )  -- Create a window which has "Information" in the title bar. 
  
guiWindowSetMovable ( popupWindow, true ) -- Allow movement of the window 
guiWindowSetSizable ( popupWindow, false ) -- Disallow size change of the window 
showCursor ( true ) 
  
local tabPanel = guiCreateTabPanel ( 0, 0.075, 1, 0.8, true, popupWindow )       -- Create a tab panel which fills the whole window 
local tabMap = guiCreateTab( "Map Information", tabPanel )                -- Create a tab named "Map Information" on 'tabPanel' 
local tabHelp = guiCreateTab( "Help", tabPanel )                          -- Create another tab named "Help" on 'tabPanel' 
  
-- adds a close button 
button = guiCreateButton( 0.1, 0.9, 0.8, 0.1, "click here to close", true, popupWindow ) -- Create a pretty button 
  
-- adds a label (text) to each tab 
guiCreateLabel(0.02, 0.04, 0.94, 0.2, "This is information about the current map", true, tabMap) -- Text to be shown in the map-tab 
guiCreateLabel(0.02, 0.04, 0.94, 0.92, "This is help text.", true, tabHelp) -- Text to be shown in the help-tab 
  
function changeVisibility ( ) -- This function toggles the GUI from visible to invisible and vice versa 
outputChatBox ( "The changeVisibility function has been started." ) -- debugging 
        if guiGetVisible ( popupWindow ) then 
                guiSetVisible ( popupWindow, false ) 
                showCursor ( false ) 
                outputChatBox ( "PopupWindow was visible, but not anymore" ) -- debugging 
        else 
                guiSetVisible ( popupWindow, true ) 
                showCursor ( true ) 
                outputChatBox ( "PopupWindow was invisible, but not anymore" ) -- debugging 
        end 
end 
  
  
bindKey ( "F1", "down", changeVisibility ) -- Toggle the GUI using F1 
addEventHandler ( "onClientGUIClick", button, changeVisibility) -- Close the GUI using the button  
addCommandHandler ( "commands", changeVisibility) -- Toggle the GUI by typing "commands" (without the quotes) 

What does not work properly in this script?

  • The window is still resizable
  • The close-button does not close the window
  • The F1 key does not toggle the visibility

Any ideas about what's wrong?

Edited by Guest
Link to comment
Looks like I get the following error:

WARNING: popup.lua: Bad 'element' pointer @ 'addEventHandler'(2) - line 34

I think that is where your "error" lies also.

My buttons do not work for some reason also, when I implement it the way you did.

"# addEventHandler ( "onClientGUIClick", button, changeVisibility) -- Close the GUI using the button "

the second argument doesn't seem to be taken correctly by the event handler for a weird reason.

My temporary solution was to change the addEventHandler() to:

addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), changeVisibility)

and add an extra check inside the triggered function:

if ( source == button) then

...

end

Link to comment

Thanks, that tip worked!

I made the eventHandler like this now:

addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()), 
        function () 
            if (source == closeButton) then 
                changeVisibility() 
            end 
        end 
        ) 

But I'm still confused about why the window is still resizable.

Link to comment
Thanks, that tip worked!

I made the eventHandler like this now:

addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()), 
        function () 
            if (source == closeButton) then 
                changeVisibility() 
            end 
        end 
        ) 

But I'm still confused about why the window is still resizable.

Try this: guiWindowSetSisable

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