DgsCreateWindow: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Client function}} This function is for creating a new DGS window. This provides a base for other dgs elements to be created within. However, windows do not have...")
 
m (fix mistake)
 
(13 intermediate revisions by 3 users not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element guiCreateWindow ( float x, float y, float width, float height, string titleBarText, bool relative )
element dgsCreateWindow ( float x, float y, float width, float height, string text, bool relative[, int textColor = 0xFFFFFFFF, float titleHeight = 25, element titleImage = nil, int titleColor = 0xC8141414, element image = nil, int color = 0x96141414, float borderSize = 5, bool noCloseButton = false ] )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===
===Required Arguments===
[[Image:gui-window.png|frame|Example Window.]]
[[Image:Dx_6.PNG|frame|Example Dx Window.]]
*'''x:''' A float of the 2D x position of the GUI window on a player's screen. This is affected by the ''relative'' argument.
*'''x:''' A float of the 2D x position of the window on a player's screen. This is affected by the ''relative'' argument.
*'''y:''' A float of the 2D y position of the GUI window on a player's screen. This is affected by the ''relative'' argument.
*'''y:''' A float of the 2D y position of the window on a player's screen. This is affected by the ''relative'' argument.
*'''width:''' A float of the width of the GUI window. This is affected by the ''relative'' argument.
*'''width:''' A float of the width of the window. This is affected by the ''relative'' argument.
*'''height:''' A float of the height of the GUI window. This is affected by the ''relative'' argument.
*'''height:''' A float of the height of the window. This is affected by the ''relative'' argument.
*'''titleBarText:''' A string of the text that will be displayed in the title bar of the window.
*'''text:''' A string of the text that will be displayed in the title bar of the window.
*'''relative:''' This is whether sizes and positioning are relative.  If this is ''true'', then all x,y,width,height floats must be between 0 and 1, representing sizes/positions as a fraction of the screen size. If ''false'', then the size and co-ordinates are based on client's resolution, accessible using [[guiGetScreenSize]].
*'''relative:''' This is whether sizes and positioning are relative.  If this is ''true'', then all x,y,width,height floats must be between 0 and 1, representing sizes/positions as a fraction of the screen size. If ''false'', then the size and co-ordinates are based on client's resolution, accessible using [[guiGetScreenSize]].
===Optional Arguments===
{{OptionalArg}}
*'''textColor:''' An int of the color of the title text of the window.
*'''titleHeight:''' A float of the height of the title of the window.
*'''titleImage:''' A texture element of the background of the title of the window.
*'''titleColor:''' An int of the color of the title of the window.
*'''image:''' A texture element of the background of the body of the window.
*'''color:''' An int of the background color of the body of the window.
*'''borderSize:''' A float of the side of the window that affects window sizing.
*'''noCloseButton:''' A bool of whether the window is created without close button.


===Returns===
===Returns===
Line 21: Line 32:


==Example==  
==Example==  
'''Example 1:''' This example creates a information window and adds two tabs to a "tabPanel" tabpanel, and adds some other gui elements to it.
This example creates a weapon selection screen, complete with a window, gridlist and a button. Users can select a shotgun or a machine gun. The window is not movable or sizable.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local myWindow = guiCreateWindow ( 0, 0, 0.5, 0.4, "Information", true )  -- create a window which has "Information" in the title bar.
loadstring(exports.dgs:dgsImportFunction())()
local tabPanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, myWindow )       -- 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 label (text) to each tab
guiCreateLabel(0.02, 0.04, 0.94, 0.2, "This is information about the current map", true, tabMap)
guiCreateLabel(0.02, 0.04, 0.94, 0.92, "This is help text.", true, tabHelp)
</syntaxhighlight>
'''Example 2:''' This example creates a weapon selection screen, complete with a window, gridlist and a button. Users can select a shotgun or a machine gun. The window is not movable or sizable.
<syntaxhighlight lang="lua">
--Setup some tables
--Setup some tables
shotguns = {
shotguns = {
       "chrome",
       "chrome",
Line 51: Line 51:
       -- getResourceRootElement(getThisResource()) at the bottom means it will only create the gui on this resource start
       -- getResourceRootElement(getThisResource()) at the bottom means it will only create the gui on this resource start
       -- Create a window for our spawnscreen, with the title "Select your weapons".
       -- Create a window for our spawnscreen, with the title "Select your weapons".
       spawnScreenMenu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Select your weapons", true )
       spawnScreenMenu = dgsCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Select your weapons", true )
       -- create an OK button to allow the user to confirm their selections, and attach it to the confirmSelection function
       -- create an OK button to allow the user to confirm their selections, and attach it to the confirmSelection function
       spawnScreenOKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, spawnScreenMenu )
       spawnScreenOKButton = dgsCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, spawnScreenMenu )
       -- ensure the user can't move or resize our spawnscreen.
       -- ensure the user can't move or resize our spawnscreen.
       guiWindowSetMovable ( spawnScreenMenu, false )
       dgsWindowSetMovable ( spawnScreenMenu, false )
       guiWindowSetSizable ( spawnScreenMenu, false )
       dgsWindowSetSizable ( spawnScreenMenu, false )
       -- create our gridlist, which fills up most of the window.
       -- create our gridlist, which fills up most of the window.
       spawnScreenGridList = guiCreateGridList ( 0, 0.1, 1, 0.9, true, spawnScreenMenu )
       spawnScreenGridList = dgsCreateGridList ( 0, 0.1, 1, 0.9, true, spawnScreenMenu )
      guiGridListSetSelectionMode ( spawnScreenGridList, 2 ) -- ensure the selection mode is one per column
       -- Since we have 2 sets of weapons, create a column for shotguns and one for machine guns
       -- Since we have 2 sets of weapons, create a column for shotguns and one for machine guns
       guiGridListAddColumn ( spawnScreenGridList, "Shotguns", 0.3 )
       dgsGridListAddColumn ( spawnScreenGridList, "Shotguns", 0.3 )
       guiGridListAddColumn ( spawnScreenGridList, "Machine guns", 0.3 )
       dgsGridListAddColumn ( spawnScreenGridList, "Machine guns", 0.3 )
       -- next, we loop through our handguns table to add handgun items to the gridlist
       -- next, we loop through our handguns table to add handgun items to the gridlist
       for key,weaponName in pairs(shotguns) do
       for key,weaponName in pairs(shotguns) do
             -- add a new row to our gridlist each time
             -- add a new row to our gridlist each time
             local row = guiGridListAddRow ( spawnScreenGridList )
             local row = dgsGridListAddRow ( spawnScreenGridList )
             -- next, we set that row's text to the weapon name. Column is 1 since the "Shotguns" column was created first.
             -- next, we set that row's text to the weapon name. Column is 1 since the "Shotguns" column was created first.
             guiGridListSetItemText ( spawnScreenGridList, row, 1, weaponName, false, false )
             dgsGridListSetItemText ( spawnScreenGridList, row, 1, weaponName )
       end
       end
       -- we repeat the process for other weapon list, changing the column number
       -- we repeat the process for other weapon list, changing the column number
       row = 0
       row = 1
       for key,weaponName in pairs(machineGun) do
       for key,weaponName in pairs(machineGun) do
             -- we don't need to create new rows as that was done in the previous loop
             -- we don't need to create new rows as that was done in the previous loop
             -- we just set the row's text to the weapon name. Column is 2 since the "Machine guns" column was created second.
             -- we just set the row's text to the weapon name. Column is 2 since the "Machine guns" column was created second.
             guiGridListSetItemText ( spawnScreenGridList, row, 2, weaponName, false, false )
             dgsGridListSetItemText ( spawnScreenGridList, row, 2, weaponName )
             row = row + 1 -- increase the row number
             row = row + 1 -- increase the row number
       end
       end
Line 84: Line 83:
==See Also==
==See Also==
{{DGSFUNCTIONS}}
{{DGSFUNCTIONS}}
[[ZH-CN:dgsDxCreateWindow]]
[[ZH-CN:dgsCreateWindow]]

Latest revision as of 15:14, 21 April 2021

This function is for creating a new DGS window. This provides a base for other dgs elements to be created within. However, windows do not have a parent and cannot be created in any DGS elements.

Syntax

element dgsCreateWindow ( float x, float y, float width, float height, string text, bool relative[, int textColor = 0xFFFFFFFF, float titleHeight = 25, element titleImage = nil, int titleColor = 0xC8141414, element image = nil, int color = 0x96141414, float borderSize = 5, bool noCloseButton = false ] )

Required Arguments

Example Dx Window.
  • x: A float of the 2D x position of the window on a player's screen. This is affected by the relative argument.
  • y: A float of the 2D y position of the window on a player's screen. This is affected by the relative argument.
  • width: A float of the width of the window. This is affected by the relative argument.
  • height: A float of the height of the window. This is affected by the relative argument.
  • text: A string of the text that will be displayed in the title bar of the window.
  • relative: This is whether sizes and positioning are relative. If this is true, then all x,y,width,height floats must be between 0 and 1, representing sizes/positions as a fraction of the screen size. If false, then the size and co-ordinates are based on client's resolution, accessible using guiGetScreenSize.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • textColor: An int of the color of the title text of the window.
  • titleHeight: A float of the height of the title of the window.
  • titleImage: A texture element of the background of the title of the window.
  • titleColor: An int of the color of the title of the window.
  • image: A texture element of the background of the body of the window.
  • color: An int of the background color of the body of the window.
  • borderSize: A float of the side of the window that affects window sizing.
  • noCloseButton: A bool of whether the window is created without close button.

Returns

Returns a dgs window element if it was created successfully, false otherwise.

Example

This example creates a weapon selection screen, complete with a window, gridlist and a button. Users can select a shotgun or a machine gun. The window is not movable or sizable.

loadstring(exports.dgs:dgsImportFunction())()

--Setup some tables
shotguns = {
      "chrome",
      "sawn-off",
      "combat"
}

machineGun = {
      "m4",
      "ak-47"
}

function setupWeaponSelection ( theResource )
      -- getResourceRootElement(getThisResource()) at the bottom means it will only create the gui on this resource start
      -- Create a window for our spawnscreen, with the title "Select your weapons".
      spawnScreenMenu = dgsCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Select your weapons", true )
      -- create an OK button to allow the user to confirm their selections, and attach it to the confirmSelection function
      spawnScreenOKButton = dgsCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, spawnScreenMenu )
      -- ensure the user can't move or resize our spawnscreen.
      dgsWindowSetMovable ( spawnScreenMenu, false )
      dgsWindowSetSizable ( spawnScreenMenu, false )
      -- create our gridlist, which fills up most of the window.
      spawnScreenGridList = dgsCreateGridList ( 0, 0.1, 1, 0.9, true, spawnScreenMenu )
      -- Since we have 2 sets of weapons, create a column for shotguns and one for machine guns
      dgsGridListAddColumn ( spawnScreenGridList, "Shotguns", 0.3 )
      dgsGridListAddColumn ( spawnScreenGridList, "Machine guns", 0.3 )
      -- next, we loop through our handguns table to add handgun items to the gridlist
      for key,weaponName in pairs(shotguns) do
            -- add a new row to our gridlist each time
            local row = dgsGridListAddRow ( spawnScreenGridList )
            -- next, we set that row's text to the weapon name. Column is 1 since the "Shotguns" column was created first.
            dgsGridListSetItemText ( spawnScreenGridList, row, 1, weaponName )
      end
      -- we repeat the process for other weapon list, changing the column number
      row = 1
      for key,weaponName in pairs(machineGun) do
            -- we don't need to create new rows as that was done in the previous loop
            -- we just set the row's text to the weapon name. Column is 2 since the "Machine guns" column was created second.
            dgsGridListSetItemText ( spawnScreenGridList, row, 2, weaponName )
            row = row + 1 -- increase the row number
      end
end
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), setupWeaponSelection )

See Also

Custom Cursor Functions

Multi Language Supports

Animation

3D Element

3D Interface

3D Line

3D Image

3D Text

Browser

Button

Check Box

Combo Box

Custom Renderer

Edit

Detect Area

Drag'N Drop

Grid List

Image

Memo

Menu

Label

Layout

Line

Progress Bar

Radio Button

Scale Pane

Scroll Bar

Scroll Pane

Selector

Style

Switch Button

Tab Panel

Window

Basic Shape Plugins

Circle

Quadrilateral

Rounded Rectangle

Other Plugins

Blur Box

Canvas

Chart

Color Picker

Effect 3D

Gradient

Mask

Media Browser

Nine Slice

Object Preview Supports

Paste Handler

QRCode

Remote Image

Screen Source

SVG

Tooltips