Naev

Module tk

Bindings for interacting with the Toolkit.

These toolkit bindings are all blocking, meaning that your Lua code won't continue executing until the user closes the dialogue that popped up.

A typical example would be:

  tk.msg( "Title", "This is a message." )
  if tk.yesno( "YesNo popup box", "Click yes to do something." ) then
    -- Player clicked yes, do something
  else
    -- Player clicked no
  end
 

Functions

isOpen () Gets if the toolkit is open.
query (wdwname[, wgtname]) Gets the position and dimensions of either a window or a widget.
msg (title, message[, image=-1[, width=-1[, height=-1]]]) Creates a window with an ok button, and optionally an image.
yesno (title, message) Displays a window with Yes and No buttons.
input (title, min, max, str) Creates a window that allows player to write text input.
choice (title, msg, choices) Creates a window with a number of selectable options
list (title, msg, choices) Creates a window with an embedded list of choices.
merchantOutfit (name, outfits, blackmarket) Opens an outfit merchant window.
custom (title, width, height, update, draw, keyboard, mouse, resize, textinput, nodynamic) Creates a custom widget window.
customRename (displayname) Renames the custom widget window.
customFullscreen (enable) Sets the custom widget fullscreen.
customResize (width, height) Sets the custom widget fullscreen.
customSize () Gets the size of a custom widget.
customDone () Ends the execution of a custom widget.


Functions

isOpen ()
Gets if the toolkit is open. This include any love2d windows.

Returns:

    boolean Whether or not the toolkit is open.
query (wdwname[, wgtname])
Gets the position and dimensions of either a window or a widget.

Parameters:

  • wdwname string Name of the window.
  • wgtname string Name of the widget to get dimensions of. If not specified, the dimensions of the window are returned. (optional)

Returns:

  1. number X position of the window/widget.
  2. number Y position of the window/widget.
  3. number Width of the window/widget.
  4. number Height of the window/widget.
msg (title, message[, image=-1[, width=-1[, height=-1]]])
Creates a window with an ok button, and optionally an image.

Parameters:

  • title string Title of the window.
  • message string Message to display in the window.
  • image string Image file to display in the window. (default -1)
  • width number width of the image to display. Negative values use image width. (default -1)
  • height number height of the image to display. Negative values use image height. (default -1)

Usage:

  • tk.msg( "Title", "This is a message." )
    
  • tk.msg( "Title", "This is a message.", "character.png" )
    
yesno (title, message)
Displays a window with Yes and No buttons.

Parameters:

  • title string Title of the window.
  • message string Message to display in the window.

Returns:

    boolean true if yes was clicked, false if no was clicked.

Usage:

    if tk.yesno( "YesNo popup box", "Click yes to do something." ) then --
    Clicked yes
    
input (title, min, max, str)
Creates a window that allows player to write text input.

Parameters:

  • title string Title of the window.
  • min number Minimum characters to accept (must be greater than 0).
  • max number Maximum characters to accept.
  • str string Text to display in the window.

Returns:

    string or nil nil if input was canceled or a string with the text written.

Usage:

    name = tk.input( "Name", 3, 20, "Enter your name:" )
    
choice (title, msg, choices)
Creates a window with a number of selectable options

Parameters:

  • title string Title of the window.
  • msg string Message to display.
  • choices string Option choices.

Returns:

  1. number The number of the choice chosen.
  2. string The name of the choice chosen.

Usage:

    num, chosen = tk.choice( "Title", "Ready to go?", "Yes", "No" ) -- If
    "No" was clicked it would return 2, "No"
    
list (title, msg, choices)
Creates a window with an embedded list of choices.

Parameters:

  • title string Title of the window.
  • msg string Message to display.
  • choices string Option choices.

Returns:

  1. number The number of the choice chosen.
  2. string The name of the choice chosen.

Usage:

    num, chosen = tk.list( "Title", "Foo or bar?", "Foo", "Bar" ) -- If
    "Bar" is clicked, it would return 2, "Bar"
    
merchantOutfit (name, outfits, blackmarket)
Opens an outfit merchant window.

Parameters:

  • name String Name of the window.
  • outfits Table Table of outfits to sell/buy. It is possible to use either outfits or outfit names (strings).
  • blackmarket boolean Whether or not the merchant is a black market merchant.

Usage:

  • tk.merchantOutfit( 'Laser Merchant', {'Laser Cannon MK0', 'Laser
     Cannon MK1'} )
    
  • tk.merchantOutfit( 'Laser Merchant', {outfit.get('Laser Cannon MK0'),
    outfit.get('Laser Cannon MK1')} )
    
custom (title, width, height, update, draw, keyboard, mouse, resize, textinput, nodynamic)
Creates a custom widget window.

Parameters:

  • title String Title of the window.
  • width Number Width of the drawable area of the widget.
  • height Number Height of the drawable area of the widget.
  • update Function Function to call when updating. Should take a single parameter which is a number indicating how many seconds passed from previous update.
  • draw Function Function to call when drawing.
  • keyboard Function Function to call when keyboard events are received.
  • mouse Function Function to call when mouse events are received.
  • resize Function Function to call when mouse events are received.
  • textinput Function Function to call when textinput events are received.
  • nodynamic boolean Whether or not the dialogue should be not dynamic, or use tk.refresh to force rerenders.
customRename (displayname)
Renames the custom widget window.

Parameters:

  • displayname string Name to give the custom widget window.
customFullscreen (enable)
Sets the custom widget fullscreen.

Parameters:

  • enable boolean Enable fullscreen or not.
customResize (width, height)
Sets the custom widget fullscreen.

Parameters:

  • width number Width of the widget to resize to.
  • height number Height of the widget to resize to.
customSize ()
Gets the size of a custom widget.

Returns:

  1. number Width of the window.
  2. number Height of the window.
customDone ()
Ends the execution of a custom widget.
generated by LDoc 1.5.0 Last updated 2024-04-19 15:38:17