DgsCreateWindow

From Multi Theft Auto: Wiki

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 titleBarText, bool relative[, int titlenamecolor = 0xFFFFFFFF, float titsize = 25, element titimg = nil, int titcolor = 0xC8141414, element bgimg = nil, int bgcolor = 0x96141414, float sidesize = 5, bool nooffbutton = 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.
  • titleBarText: 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.

  • titlenamecolor: An int of the color of the title text of the window.
  • titsize: A float of the height of the title of the window.
  • titimg: A texture element of the background of the title of the window.
  • titcolor: An int of the color of the title of the window.
  • bgimg: A texture element of the background of the body of the window.
  • bgcolor: An int of the background color of the body of the window.
  • sidesize: A float of the side of the window that affects window sizing.
  • nooffbutton : 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.

DGS = exports.dgs --get exported functions from dgs
--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 = DGS: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 = DGS:dgsCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, spawnScreenMenu )
      -- ensure the user can't move or resize our spawnscreen.
      DGS:dgsWindowSetMovable ( spawnScreenMenu, false )
      DGS:dgsWindowSetSizable ( spawnScreenMenu, false )
      -- create our gridlist, which fills up most of the window.
      spawnScreenGridList = DGS: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
      DGS:dgsGridListAddColumn ( spawnScreenGridList, "Shotguns", 0.3 )
      DGS: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 = DGS:dgsGridListAddRow ( spawnScreenGridList )
            -- next, we set that row's text to the weapon name. Column is 1 since the "Shotguns" column was created first.
            DGS:dgsGridListSetItemText ( spawnScreenGridList, row, 1, weaponName )
      end
      -- we repeat the process for other weapon list, changing the column number
      row = 0
      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.
            DGS:dgsGridListSetItemText ( spawnScreenGridList, row, 2, weaponName )
            row = row + 1 -- increase the row number
      end
end
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), setupWeaponSelection )

See Also

Multi Language Supports

Animation

3D Interface

3D Text

Arrow List

Browser

Button

Check Box

Combo Box

Edit

Ellipse Detect Area

Detect Area

Grid List

Image

Memo

Label

Progress Bar

Radio Button

Scroll Bar

Scroll Pane

Switch Button

Tab Panel

Window

Plugin

Media Browser

Rounded Rectangle

Color Picker

Blur Box

Effect 3D