User Tools

Site Tools



minionlib

This is an old revision of the document!


MinionLib Lua

GUI API & Functions

With our GUI API you can easily build your own UI purely in LUA. Each rendered frame the “Gameloop.Draw” - Event gets called. You need to register a function for this event and let it draw/build your UI. There are no c++ sided objects created or maintained, everything you have to do in LUA.

GUI Overview:
To get an overview what is possible with the UI, open the ingame console (CTRL + C) and execute this command:
ml_gui.showtestwindow = true

If you find in that testwindow what you need but you are unsure how to build the same in lua, you can have a look in the c++ source of this testwindow : https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp, the used function names and syntax in there are 99% the same, just the arguments may be slightly different due to lua not supporting references.

IMPORTANT INFO:
Underlined function arguments are optional!
Example:
GUI:Begin(string name, bool open, windowflags flags)

IMPORTANT INFO:
Most UI Elemet “names” or “labels” are at the same time their internal identifier.

Example: Name is internal identifier
GUI:Begin(“Banana”, true)
Example: Same name in UI, different internal identifier
GUI:Begin(“Banana##123hohoho”, true)
GUI:Begin(“Banana##hohoho456”, true)
Example: Different name in UI, same internal identifier
GUI:Begin(“Banana###123hohoho”, true)
GUI:Begin(“Pineapple###123hohoho”, true)


To get you started, let's draw a simple window with a slider, create a new .lua file, add it to your addon's module.def and put the following code into that new lua file:

-- Draws a Window with a Slider:
my_gui = {}
my_gui.open = true
my_gui.visible = true
my_gui.hue = 125
 
function my_gui.Draw( event, ticks ) 	
 
	if ( my_gui.open ) then 
 
           GUI:SetNextWindowSize(250,400,GUI.SetCond_FirstUseEver) -- set the next window size, only on first ever, GUI.SetCond_FirstUseEver is one of many possible enums.
 
           --GUI:Begin takes in two arguments, the name of the window and the current "is open" bool. It returns "is visible/is not collapsed" and the "is open" bool again.
           --If the user would close our Window, "is open" would return "false", else it will keep returning "true" as long as the window is open.
	   my_gui.visible, my_gui.open = GUI:Begin("My Fancy GUI", my_gui.open)
 
           if ( my_gui.visible ) then -- visible is true/false depending if the window is collapsed or not, we don't have to render anything in it when it is collapsed
                -- Again the typical syntax, passing the current value "hue" to the function as argument and receiving back the (un-)changed value. 
	   	my_gui.hue = GUI:SliderInt("Master HUE",my_gui.hue,0,255)
	        d(my_gui.hue)  -- spam print out the current value
	   end
	   GUI:End()  -- THIS IS IMPORTANT! For EVERY BEGIN() you NEED to ALWAYS call END(), it does not matter if the window is visible/open or not! Same goes with BeginChild() & EndChild() and others !
        end	
end
RegisterEventHandler("Gameloop.Draw", my_gui.Draw)



Main

Usage: GUI:ShowTestWindow( true )

  • GUI:ShowTestWindow(bool isopen)
    • Returns: bool isopen
    • Test window, demonstrates GUI features
  • GUI:ShowMetricsWindow(bool isopen)
    • Returns: bool isopen
    • Metrics window for debuggings

Utility

  • RenderManager:WorldToScreen(table worldpos)
    • Returns: table screenpos
    • Converts a worldposition x,y,z to a screenposition x,y , IF that point is currently visible on the screen

Window

Usage: GUI:Begin( … )

  • Begin(string name, bool open, windowflags flags)
    • Returns bool visible, bool open
    • visible means “not collapsed”, so can opt out early when window is collapsed. For WindowFlags, check the Enums & Flags further below on this page.
  • End()
    • For every GUI:Begin(..) call, you need to call GUI:End(), independent if the the window is opened/shown or not.
  • BeginChild(string name, int sizeX, int sizeY, bool border, windowflags flags
    • Begin a scrolling region. size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). size>0.0f: fixed size. each axis can use a different mode, e.g. sizeX=0 & sizeY=400.
  • EndChild()
    • For every GUI:BeginChild(..) call, you need to call GUI:EndChild().
  • GetWindowFontSize()
    • Returns: number size
    • size (also height in pixels) of current font with current scale applied
  • SetWindowFontScale( number scale)
    • per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows
  • SetNextWindowPos( number X, number Y, SetCondflags flags)
    • set next window position. call before Begin()
  • SetNextWindowPosCenter( SetCondflags flags)
    • set next window position to be centered on screen. call before Begin()
  • SetNextWindowSize( number X, number Y, SetCondflags flags)
    • set next window size. set axis to 0.0f to force an auto-fit on this axis. call before Begin()
  • SetNextWindowContentSize( number X, number Y)
    • set next window content size (enforce the range of scrollbars). set axis to 0.0f to leave it automatic. call before Begin()
  • SetNextWindowContentWidth( number width)
    • set next window content width (enforce the range of horizontal scrollbar). call before Begin()
  • SetNextWindowCollapsed( bool collapsed, SetCondflags flags)
    • set next window collapsed state. call before Begin()
  • SetNextWindowFocus()
    • set next window to be focused / front-most. call before Begin()
  • SetWindowPos( number X, number Y, SetCondflags flags)
    • set current window position - call within Begin()/End().
  • SetWindowPos( string name, number X, number Y, SetCondflags flags)
    • set current window position - call within Begin()/End(). may incur tearing
  • SetWindowSize( number X, number Y, SetCondflags flags)
    • set current window size. set X,Y to 0 to force an auto-fit.
  • SetWindowSize( string name, number X, number Y, SetCondflags flags)
    • set named window size. set X,Y to 0 to force an auto-fit on this axis.
  • SetWindowCollapsed( bool collapsed, SetCondflags flags)
    • set current window collapsed state
  • SetWindowCollapsed( string name, bool collapsed, SetCondflags flags)
    • set named window collapsed state
  • SetWindowFocus( string name)
    • set current/named window to be focused / front-most
  • GetScrollX()
    • Returns: get scrolling amount [0..GetScrollMaxX()]
  • GetScrollY()
    • Returns: get scrolling amount [0..GetScrollMaxY()]
  • GetScrollMaxX()
    • Returns: get maximum scrolling amount ~~ ContentSize.X - WindowSize.X
  • GetScrollMaxY()
    • Returns: get maximum scrolling amount ~~ ContentSize.Y - WindowSize.Y
  • SetScrollX( number scrollX)
    • set scrolling amount [0..GetScrollMaxX()]
  • SetScrollY( number scrollX)
    • set scrolling amount [0..GetScrollMaxY()]
  • SetScrollHere( number center_y_ratio)
    • adjust scrolling amount to make current cursor position visible. center_y_ratio=0.0: top, 0.5: center, 1.0: bottom.
  • SetScrollFromPosY( number pos_y, number center_y_ratio)
    • adjust scrolling amount to make given position valid. use GetCursorPos() or GetCursorStartPos()+offset to get valid positions.
  • SetKeyboardFocusHere(number offset)
    • focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget

Style

Usage: GUI:PushStyleColor( … )

  • PushStyleColor(ImGuiCol flags, number R, number G, number B, number A)
    • sets the color for the following elements
  • PopStyleColor( number count )
    • removes the last pushed color style(s)
  • PushStyleVar(StyleVar flags, number val, number val2)
    • sets the style for the following elements
  • PopStyleVar( number count )
    • removes the last pushed style var(s)
  • GetColorU32( number r, number g, number b, number a )
    • Returns: number color
  • PushItemWidth( number item_width )
    • width of items for the common item+label case, pixels. 0.0f = default to ~2/3 of windows width, >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side))
  • PopItemWidth( )
    • removes the last pushed item width
  • CalcItemWidth( )
    • width of item given pushed settings and current cursor position
  • PushTextWrapPos( number wrap_pos_x )
    • word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space
  • PopTextWrapPos( )
    • removes the last pushed wrap pos
  • PushAllowKeyboardFocus( bool val )
    • allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets
  • PopAllowKeyboardFocus( )
    • removes the last pushed keyboard focus setting
  • PushButtonRepeat( bool repeat)
    • in 'repeat' mode, Button functions return repeated true in a typematic manner.
  • PopButtonRepeat( )
    • removes the last pushed button repeat setting

Layout

Usage: GUI:BeginGroup( … )

  • BeginGroup( )
    • lock horizontal starting position. once closing a group it is seen as a single item (so you can use IsItemHovered() on a group, SameLine() between groups, etc.
  • EndGroup( )
    • Needs to be called for each BeginGroup()
  • Separator( )
    • horizontal line
  • SameLine( number local_pos_x, number spacing_w )
    • call between widgets or groups to layout them horizontally
  • NewLine()
    • undo a SameLine()
  • Spacing( )
    • add spacing
  • Dummy( number sizeX, number sizeY )
    • add a dummy item of given size
  • Indent( )
    • move content position toward the right by style.IndentSpacing pixels
  • Unindent( )
    • move content position back to the left (cancel Indent)
  • Columns( number count, string name, bool border )
    • setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1).
  • NextColumn( )
    • next column
  • GetColumnIndex( )
    • Returns: number current column index
  • GetColumnOffset( int column_index )
    • Returns: number get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetcolumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this
  • SetColumnOffset( int column_index, number offset_x )
    • set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column
  • GetColumnWidth( int column_index )
    • Returns: number column width (== GetColumnOffset(GetColumnIndex()+1) - GetColumnOffset(GetColumnOffset())
  • GetColumnsCount( )
    • Returns: number number of columns (what was passed to Columns())
  • AlignFirstTextHeightToWidgets( )
    • call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets
  • GetTextLineHeight( )
    • Returns: number height of font == GetWindowFontSize()
  • GetTextLineHeightWithSpacing( )
    • Returns: number height of font == GetWindowFontSize()
  • GetItemsLineHeightWithSpacing( )
    • Returns: number distance (in pixels) between 2 consecutive lines of standard height widgets == GetWindowFontSize() + GetStyle().FramePadding.y*2 + GetStyle().ItemSpacing.y

ID Scopes

If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. You can also use “##extra” within your widget name to distinguish them from each others. Usage: GUI:PushID( … )

  • PushID( string id)
    • push identifier into the ID stack.
  • PopID( )
    • pops the last pushed identifier from the ID stack.
  • GetID( string id)
    • calculate unique ID

Cursor

Usage: GUI:GetCursorPos( … )

  • GetCursorPos( )
    • Returns: number x, number y
    • cursor position is relative to window position
  • GetCursorPosX( )
    • Returns: number x
  • GetCursorPosY( )
    • Returns: number y
  • SetCursorPos( number x, number y )
    • sets cursor position is relative to window position
  • SetCursorPosX( number x )
    • sets cursor position x
  • SetCursorPosY( number y )
    • sets cursor position y
  • GetCursorStartPos( )
    • Returns: number x, number y
    • initial cursor position
  • GetCursorScreenPos( )
    • Returns: number x, number y
    • cursor position in absolute screen coordinates [0..io.DisplaySize]
  • SetCursorScreenPos( number x, number y )
    • cursor position in absolute screen coordinates [0..io.DisplaySize]

Custom Drawing

Usage: GUI:AddCircleFilled( 300, 300, 475,GUI:ColorConvertFloat4ToU32(0.9,0.1,0.12,0.5)) IMPORTANT: Use GUI:ColorConvertFloat4ToU32() to calculatethe required numbercolor argument!!

  • AddLine( number X1, number Y1, number X2, number Y2, number color, number thickness = 1.0,)
  • AddRect( number X1, number Y1, number X2, number Y2, number color, number rounding= 0.0, number rounding_corners = 0.0)
  • AddRectFilled( number X1, number Y1, number X2, number Y2, number color, number rounding= 0.0, number rounding_corners = 0.0)
  • AddTriangleFilled( number X1, number Y1, number X2, number Y2, number X3, number Y3, number color)
  • AddCircle( number X1, number Y1, number radius, number color, number num_segments= 12)
  • AddCircleFilled( number X1, number Y1, number radius, number color, number num_segments= 12)
  • AddText( number X1, number Y1, number color, string text)
  • AddImage( string texturepath, number X1, number Y1, number X2, number Y2)

Widgets Basic

Usage: GUI:Text( … )

  • Text( string text)
    • creates a text element
  • TextColored( number R, number G, number B, number A,string text)
    • creates a colored text element, number range is 0.0 - 1.0
  • TextDisabled( string text)
    • creates a disabled text element
  • TextWrapped( string text)
    • creates a text element which wraps
  • TextUnformatted( string text)
    • creates an unformatted text element
  • LabelText( string label, string text)
    • display text+label aligned the same way as value+label widgets
  • Bullet( )
    • creates a bullet element
  • BulletText( string text)
    • creates a bullet text element
  • Button( string label, number sizeX, number sizeY)
    • creates a buttom element
  • SmallButton( string label)
    • creates a smaller button element
  • InvisibleButton( string label, number sizeX, number sizeY)
    • creates an invisible button element
  • FreeButton( string label, number posX, number posY, number sizeX, number sizeY)
    • creates a freely placable buttom element
  • FreeImageButton( /string internalid, string filepath, number posX, number posY, number sizeX, number sizeY)
    • creates a freely placable image buttom element
  • ImageButton(string internalid, string filepath, number sizeX, number sizeY, number UV0_x, number UV0_y, number UV1_x, number UV1_y, number framepadding,number bg_col_R, number bg_col_G, number bg_col_B, number bg_col_A, number tint_col_R, number tint_col_G, number tint_col_B, number tint_col_A )
    • creates an image button, scary eh ;) ? Simple usage: GUI:ImageButton( string internalid, string filepath, number sizeX, number sizeY).
    • < 0 frame_padding uses default frame padding settings. 0 for no padding
  • Image(string filepath, number sizeX, number sizeY, number UV0_x, number UV0_y, number UV1_x, number UV1_y, number bg_col_R, number bg_col_G, number bg_col_B, number bg_col_A, number tint_col_R, number tint_col_G, number tint_col_B, number tint_col_A )
    • Simple Usage: GUI:Image(string filepath, number sizeX, number sizeY)
  • CollapsingHeader( string label, string id, bool display_frame, bool default_open)
    • Returns: bool collapsed
  • Checkbox( string label, bool checked)
    • Returns: bool checked, bool pressed
  • CheckboxFlags( string label, number flags, number flags_value)
    • Returns: number flags, bool pressed
  • RadioButton( string label, bool active)
    • Returns: bool active
  • RadioButton( string label, bool active, number val)
    • Returns: number val, bool pressed
  • Combo( string label, number current_item_listindex, table itemlist, number height_in_items)
    • Returns: number current_item_listindex, bool changed
  • ColorButton( number R, number G, number B, number A, bool small_height, bool outline_border)
    • Returns: bool pressed
  • ColorEdit3( string label, number R, number G, number B)
    • Returns: number R, number G, number B, bool changed
  • ColorEdit4( string label, number R, number G, number B, number A)
    • Returns: number R, number G, number B, number A, bool changed
  • ColorEditMode( ColorEditMode mode)
    • sets ColorEditMode
  • ProgressBar( number fraction, number SizeX, number SizeY, string overlay )
    • Guess what it draws ;)

Widgets Drags

(tip: ctrl+click on a drag box to input text) Usage: GUI:Text( … )

  • DragFloat( string label, number val, number v_speed, number v_min, number v_max, string display_format, number power)
    • Returns: number val, bool changed
    • display_format example “%.3f”, *If v_min >= v_max we have no bound
  • DragFloatRange2( string label, number v_current_min, number v_current_max, number v_speed, number v_min, number v_max, string display_format, string display_format_max, number power)
    • Returns: number val_min, number val_max, bool changed
    • display_format example “%.3f”, *If v_min >= v_max we have no bound
  • DragInt( string label, number val, number v_speed, number v_min, number v_max, string display_format)
    • Returns: number val, bool changed
    • display_format example “%.3f”, *If v_min >= v_max we have no bound
  • DragIntRange2( string label, number v_current_min, number v_current_max, number v_speed, number v_min, number v_max, string display_format, string display_format_max)
    • Returns: number val_min, number val_max, bool changed
    • display_format example “%.3f”, *If v_min >= v_max we have no bound

Widgets Input

Usage: GUI:InputText( … )

  • InputText( string label, string text, InputTextFlags flags)
    • Returns: string text, bool changed
  • InputTextMultiline( string label, string text, number sizeX, number sizeY , InputTextFlags flags)
    • Returns: string text, bool changed
  • InputFloat( string label, number val, number step, number step_fast, number decimal_precision, InputTextFlags flags)
    • Returns: number val, bool changed
  • InputFloat2( string label, number val, number val2, number decimal_precision, InputTextFlags flags)
    • Returns: number val, number val2, bool changed
    • Draws 2 Input fields behind each other in the same line
  • InputFloat3( string label, number val, number val2, number val3, number decimal_precision, InputTextFlags flags)
    • Returns: number val, number val2, number val3, bool changed
    • Draws 3 Input fields behind each other in the same line
  • InputFloat4( string label, number val, number val2, number val3, number val4, number decimal_precision, InputTextFlags flags)
    • Returns: number val, number val2, number val3, number val4, bool changed
    • Draws 4 Input fields behind each other in the same line
  • InputInt( string label, number val, number step, number step_fast, InputTextFlags flags)
    • Returns: number val, bool changed
  • InputInt2( string label, number val, number val2, InputTextFlags flags)
    • Returns: number val, number val2, bool changed
    • Draws 2 Input fields behind each other in the same line
  • InputInt3( string label, number val, number val2, number val3, InputTextFlags flags)
    • Returns: number val, number val2, number val3, bool changed
    • Draws 3 Input fields behind each other in the same line
  • InputInt4( string label, number val, number val2, number val3, number val4, InputTextFlags flags)
    • Returns: number val, number val2, number val3, number val4, bool changed
    • Draws 4 Input fields behind each other in the same line

Widgets Sliders

Usage: GUI:SliderFloat( … )

  • SliderFloat( string label, number val, number v_min, number v_max, string display_format, number power)
    • Returns: number val, bool changed
  • SliderFloat2( string label, number val, number val2, number v_min, number v_max, string display_format, number power)
    • Returns: number val, number val2, bool changed
    • Draws 2 Input fields behind each other in the same line
  • SliderFloat3( string label, number val, number val2, number val3, number v_min, number v_max, string display_format, number power)
    • Returns: number val, number val2, number val3, bool changed
    • Draws 3 Input fields behind each other in the same line
  • SliderFloat4( string label, number val, number val2, number val3, number val4, number v_min, number v_max, string display_format, number power)
    • Returns: number val, number val2, number val3, number val4, bool changed
    • Draws 4 Input fields behind each other in the same line
  • SliderAngle( string label, number v_rad, number v_degrees_min, number v_degrees_max)
    • Returns: number val, bool changed
  • SliderInt( string label, number val, number v_min, number v_max, string display_format)
    • Returns: number val, bool changed
  • SliderInt2( string label, number val, number val2, number v_min, number v_max, string display_format)
    • Returns: number val, number val2, bool changed
  • SliderInt3( string label, number val, number val2, number val3, number v_min, number v_max, string display_format)
    • Returns: number val, number val2, number val3, bool changed
  • SliderInt4( string label, number val, number val2, number val3, number val4, number v_min, number v_max, string display_format)
    • Returns: number val, number val2, number val3, number val4, bool changed
  • VSliderFloat( string label, number sizeX, number sizeY, number val, number v_min, number v_max, string display_format, number power)
    • Returns: number val, bool changed
  • VSliderInt( string label, number sizeX, number sizeY, number val, number v_min, number v_max, string display_format)
    • Returns: number val, bool changed

Widgets Trees

Usage: GUI:TreeNode( … )

  • TreeNode( string label)
    • Returns: bool changed
    • if returning 'true' the node is open and the user is responsible for calling TreePop()
  • TreePush( string id)
    • already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
  • TreePop( )
    • needs to be callled at the end of TreePush()
  • SetNextTreeNodeOpened( bool opened, SetCond cond )
    • set next tree node to be opened.

Widgets Lists

Usage: GUI:Selectable( … )

  • Selectable( string label, bool selected, SelectableFlags flags, number sizeX, number sizeY )
    • Returns: bool changed
    • size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height
  • ListBox( string label, number current_listitem_index, table itemlist, number height_in_items )
    • Returns: number current_item_index, bool changed
  • ListBoxHeader( string label, number items_count, number height_in_items )
    • Returns: bool
    • use if you want to reimplement ListBox() will custom data or interactions. make sure to call ListBoxFooter() afterwards.
  • ListBoxFooter( )
    • terminate the scrolling region

Widgets Tooltip

Usage: GUI:SetTooltip( … )

  • SetTooltip( string label )
    • set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins
  • BeginTooltip( )
    • use to create full-featured tooltip windows that aren't just text
  • EndTooltip( )
    • use to create full-featured tooltip windows that aren't just text

Widgets Menus

Usage: GUI:BeginMainMenuBar( … )

  • BeginMainMenuBar( )
    • Returns: bool opened
    • create and append to a full screen menu-bar. only call EndMainMenuBar() if this returns true!
  • EndMainMenuBar( )
    • End Menubar drawing
  • BeginMenuBar( )
    • Returns: bool opened
    • append to menu-bar of current window (requires ImGuiWindowFlags_MenuBar flag set). only call EndMenuBar() if this returns true!
  • EndMenuBar( )
    • End Menubar drawing
  • BeginMenu( string label, bool enabled )
    • Returns: bool opened
    • create a sub-menu entry. only call EndMenu() if this returns true!
  • EndMenu( )
    • End Menubar drawing
  • MenuItem( string label, string shortcut, bool selected, bool enabled)
    • Returns: bool activated, bool selected
    • Shortcuts are currently only visual, aka not working, you need to add that yourself

Widgets Popup

Usage: GUI:OpenPopup( … )

  • OpenPopup( string id)
    • mark popup as open. popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
  • BeginPopup( string id)
    • Returns: bool open
    • return true if popup if opened and start outputting to it. only call EndPopup() if BeginPopup() returned true!
  • BeginPopupModal( string name, bool opened, WindowFlags flags)
    • Returns bool visible, bool open
    • modal dialog (can't close them by clicking outside)
  • BeginPopupContextItem( string id, number mouse_button)
    • Returns bool open
    • helper to open and begin popup when clicked on last item
  • BeginPopupContextWindow( bool also_over_items, string id, number mouse_button)
    • Returns bool open
    • helper to open and begin popup when clicked on current window
  • BeginPopupContextVoid( string id, number mouse_button)
    • Returns bool open
    • helper to open and begin popup when clicked in void (no window)
  • EndPopup( )
    • needs to be called on opened popups
  • CloseCurrentPopup( )
    • close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup.

Widgets Utilities

Usage: GUI:IsItemHovered( … )

  • IsItemHovered( )
    • Results: bool
    • was the last item hovered by mouse?
  • IsItemHoveredRect( )
    • Results: bool
    • was the last item hovered by mouse? even if another item is active while we are hovering this
  • IsItemClicked( int mousebutton == 0)
    • Results: bool
    • was the last item clicked? (e.g. button/node just clicked on)
  • IsItemActive( )
    • Results: bool
    • was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false)
  • IsItemVisible( )
    • Results: bool
    • was the last item visible? (aka not out of sight due to clipping/scrolling.)
  • IsAnyItemHovered( )
    • Results: bool
  • IsAnyItemActive( )
    • Results: bool
  • GetItemRectMin( )
    • Results: number x, number y
    • get bounding rect of last item in screen space
  • GetItemRectMax( )
    • Results: number x, number y
    • get bounding rect of last item in screen space
  • GetItemRectSize( )
    • Results: number x, number y
  • SetItemAllowOverlap( )
    • Allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area.
  • IsWindowHovered( )
    • Results: bool
    • is current window hovered and hoverable (not blocked by a popup) (differentiate child windows from each others)
  • IsWindowFocused( )
    • Results: bool
    • is current window focused
  • IsRootWindowFocused( )
    • Results: bool
    • is current root window focused (top parent window in case of child windows)
  • IsRootWindowOrAnyChildFocused( )
    • Results: bool
    • is current root window or any of its child (including current window) focused
  • IsRectVisible( number x, number y)
    • Results: bool
    • test if rectangle of given size starting from cursor pos is visible (not clipped). to perform coarse clipping on user's side
  • IsPosHoveringAnyWindow( number x, number y)
    • Results: bool
    • is given position hovering any active imgui window
  • GetTime( )
    • Results: number
  • GetFrameCount( )
    • Results: number
  • CalcItemRectClosestPoint( number x, number y, bool on_edge, number outward)
    • Results: number x, number y
    • utility to find the closest point the last item bounding rectangle edge. useful to visually link items
  • CalcTextSize( string text)
    • Results: number sizex, number sizey
  • CalcListClipping( number items_count, number items_height, number out_items_display_start, number out_items_display_end)
    • Results: number out1, number out2
    • calculate coarse clipping for large list of evenly sized items. Prefer using the ImGuiListClipper higher-level helper if you can.
  • BeginChildFrame( number guiID, number sizex, number sizey, WindowFlags flags)
    • Results: bool
    • helper to create a child window / scrolling region that looks like a normal widget frame
  • EndChildFrame( )
    • needs to be called at the end of BeginChildFrame.
  • ColorConvertU32ToFloat4( number U32val)
    • Returns: number val1,number val2,number val3,number val4
  • ColorConvertFloat4ToU32( number val1,number val2,number val3,number val4 )
    • Returns: number U32val
  • ColorConvertRGBtoHSV( number r, number g, number b)
    • Returns: number h, number s, number v
  • ColorConvertHSVtoRGB( number h, number s, number v)
    • Returns: number r, number g, number b
  • GetScreenSize()
    • Returns: number x, number y
  • IsKeyDown( number virtualkey)
  • IsKeyPressed( number virtualkey, bool repeat)
  • IsKeyReleased( number virtualkey)
  • IsMouseDown( number button)
    • Returns: bool
  • IsMouseClicked( number button, bool repeat)
    • Returns: bool
  • IsMouseDoubleClicked( number button)
    • Returns: bool
  • IsMouseReleased( number button)
    • Returns: bool
  • IsMouseHoveringWindow( number button)
    • Returns: bool
    • is mouse hovering current window (“window” in API names always refer to current window). disregarding of any consideration of being blocked by a popup. (unlike IsWindowHovered() this will return true even if the window is blocked because of a popup)
  • IsMouseHoveringAnyWindow( number button)
    • Returns: bool
  • IsMouseHoveringAnyWindow( number pos_minX, number pos_minY, number pos_maxX, number pos_maxY, bool clip)
    • Returns: bool
    • is mouse hovering given bounding rect (in screen space). clipped by current clipping settings. disregarding of consideration of focus/window ordering/blocked by a popup.
  • IsMouseDragging( number button, number lock_threshold)
    • Returns: bool
  • GetMousePos( )
    • Returns: number x, number y
  • GetMousePosOnOpeningCurrentPopup( )
    • Returns: number x, number y
    • retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into
  • GetMouseDragDelta( number button, number lock_threshold)
    • Returns: number x, number y
    • dragging amount since clicking.
  • ResetMouseDragDelta( number button)
    • Banana ;)


Enums & Flags

These are registered values in the GUI metatable. Usage: d(GUI.WindowFlags_NoMove) will print “2” into the console.

WindowFlags
  • GUI.WindowFlags_NoTitleBar
  • GUI.WindowFlags_NoResize
  • GUI.WindowFlags_NoMove
  • GUI.WindowFlags_NoScrollbar
  • GUI.WindowFlags_NoScrollWithMouse
  • GUI.WindowFlags_NoCollapse
  • GUI.WindowFlags_AlwaysAutoResize
  • GUI.WindowFlags_ShowBorders
  • GUI.WindowFlags_NoSavedSettings
  • GUI.WindowFlags_NoInputs
  • GUI.WindowFlags_MenuBar
  • GUI.WindowFlags_HorizontalScrollbar
  • GUI.WindowFlags_NoFocusOnAppearing
  • GUI.WindowFlags_NoBringToFrontOnFocus
  • GUI.WindowFlags_ForceVerticalScrollbar
  • GUI.WindowFlags_ForceHorizontalScrollbar
InputTextFlags
  • GUI.InputTextFlags_CharsDecimal
  • GUI.InputTextFlags_CharsHexadecimal
  • GUI.InputTextFlags_CharsUppercase
  • GUI.InputTextFlags_CharsNoBlank
  • GUI.InputTextFlags_AutoSelectAll
  • GUI.InputTextFlags_EnterReturnsTrue
  • GUI.InputTextFlags_CallbackCompletion
  • GUI.InputTextFlags_CallbackHistory
  • GUI.InputTextFlags_CallbackAlways
  • GUI.InputTextFlags_CallbackCharFilter
  • GUI.InputTextFlags_AllowTabInput
  • GUI.InputTextFlags_CtrlEnterForNewLine
  • GUI.InputTextFlags_NoHorizontalScroll
  • GUI.InputTextFlags_AlwaysInsertMode
  • GUI.InputTextFlags_ReadOnly
  • GUI.InputTextFlags_Password
SelectableFlags
  • GUI.SelectableFlags_DontClosePopups
  • GUI.SelectableFlags_SpanAllColumns
  • GUI.SelectableFlags_AllowDoubleClick
SelectableFlags
  • GUI.SelectableFlags_DontClosePopups
  • GUI.SelectableFlags_SpanAllColumns
  • GUI.SelectableFlags_AllowDoubleClick
PushStyleColor
  • GUI.Col_Text
  • GUI.Col_TextDisabled
  • GUI.Col_WindowBg
  • GUI.Col_ChildWindowBg
  • GUI.Col_Border
  • GUI.Col_BorderShadow
  • GUI.Col_FrameBg
  • GUI.Col_FrameBgHovered
  • GUI.Col_FrameBgActive
  • GUI.Col_TitleBg
  • GUI.Col_TitleBgCollapsed
  • GUI.Col_TitleBgActive
  • GUI.Col_MenuBarBg
  • GUI.Col_ScrollbarBg
  • GUI.Col_ScrollbarGrab
  • GUI.Col_ScrollbarGrabHovered
  • GUI.Col_ScrollbarGrabActive
  • GUI.Col_ComboBg
  • GUI.Col_CheckMark
  • GUI.Col_SliderGrab
  • GUI.Col_SliderGrabActive
  • GUI.Col_Button
  • GUI.Col_ButtonHovered
  • GUI.Col_ButtonActive
  • GUI.Col_Header
  • GUI.Col_HeaderHovered
  • GUI.Col_HeaderActive
  • GUI.Col_Column
  • GUI.Col_ColumnHovered
  • GUI.Col_ColumnActive
  • GUI.Col_ResizeGrip
  • GUI.Col_ResizeGripHovered
  • GUI.Col_ResizeGripActive
  • GUI.Col_CloseButton
  • GUI.Col_CloseButtonHovered
  • GUI.Col_CloseButtonActive
  • GUI.Col_PlotLines
  • GUI.Col_PlotLinesHovered
  • GUI.Col_PlotHistogram
  • GUI.Col_PlotHistogramHovered
  • GUI.Col_TextSelectedBg
  • GUI.Col_TooltipBg
  • GUI.Col_ModalWindowDarkening
PushStyleVar
  • GUI.StyleVar_Alpha
  • GUI.StyleVar_WindowPadding
  • GUI.StyleVar_WindowRounding
  • GUI.StyleVar_WindowMinSize
  • GUI.StyleVar_ChildWindowRounding
  • GUI.StyleVar_FramePadding
  • GUI.StyleVar_FrameRounding
  • GUI.StyleVar_ItemSpacing
  • GUI.StyleVar_ItemInnerSpacing
  • GUI.StyleVar_IndentSpacing
  • GUI.StyleVar_GrabMinSize
Align
  • GUI.Align_Left
  • GUI.Align_Center
  • GUI.Align_Right
  • GUI.Align_Top
  • GUI.Align_VCenter
  • GUI.Align_Default
SetCondFlags
  • GUI.SetCond_Always
  • GUI.SetCond_Once
  • GUI.SetCond_FirstUseEver
  • GUI.SetCond_Appearing

Core Functions & Helper Functions

This minionlib library is holding the core functionality on which all our bots are running. You can freely use the available functions for your Addon, in order to do that, you just need to open your module.def and set the dependency of your Addon to the minionlib:

[Module]
Name=YourAddon
Dependencies=minionlib
Version=1
Files=myluacode.lua
Enabled=1

Minion Menu

The Minion Menu is the main menu used by minion to access all settings and addons. 3rd-party developers may add custom options to the menu in several different ways.

Structure

The minion is layered into 3 distinct parts, components, members, and submembers.

All components must have a header and (optionally) members, which are displayed when the header is clicked (and the menu is open).
All component headers require the following properties: bool expanded, string name, string id
All component headers optionally contain the following properties: string texture

Members are displayed below their component containers, and they represent the rows that appear directly below the header.
Members may optionally contain submembers.
All members require the following properties: string name, string id
All members optionally contain the following properties: string texture, string tooltip, function onClick, bool sort

Submembers are displayed to the right and grow vertically downward. They are useful if you wish to section off a large amount of events.
Submembers will be sorted in alphabetical order by name if the sort tag is specified on the parent member.
All submembers require the following properties: string name, string id
All submembers optionally contain the following properties: string texture, string tooltip, function onClick

API
  • ml_gui.ui_mgr:AddComponent( table component)
  • ml_gui.ui_mgr:AddMember( table member, string componentid)
  • ml_gui.ui_mgr:AddComponent( table submember, string componentid, string memberid)
Example
local ffxiv_mainmenu = {
	header = { id = "FFXIVMINION##MENU_HEADER", expanded = false, name = "FFXIVMinion", texture = GetStartupPath().."\\GUI\\UI_Textures\\ffxiv_shiny.png"},
	members = {	}
}
 
ml_gui.ui_mgr:AddComponent(ffxiv_mainmenu)
ml_gui.ui_mgr:AddMember({ id = "FFXIVMINION##MENU_DEV1", name = "Dev1", onClick = function() Dev.GUI.open = not Dev.GUI.open end, tooltip = "Open the Dev monitor."},"FFXIVMINION##MENU_HEADER")
ml_gui.ui_mgr:AddMember({ id = "FFXIVMINION##MENU_DEV2", name = "Dev2", onClick = function() Dev.GUI.open = not Dev.GUI.open end, tooltip = "Open the Dev monitor."},"FFXIVMINION##MENU_HEADER")
ml_gui.ui_mgr:AddMember({ id = "FFXIVMINION##MENU_DEV3", name = "Dev3", onClick = function() Dev.GUI.open = not Dev.GUI.open end, tooltip = "Open the Dev monitor."},"FFXIVMINION##MENU_HEADER")
ml_gui.ui_mgr:AddMember({ id = "FFXIVMINION##MENU_DEV4", name = "Dev4", onClick = function() Dev.GUI.open = not Dev.GUI.open end, tooltip = "Open the Dev monitor."},"FFXIVMINION##MENU_HEADER")
ml_gui.ui_mgr:AddMember({ id = "FFXIVMINION##MENU_DEV5", name = "Dev5", onClick = function() Dev.GUI.open = not Dev.GUI.open end, sort = true},"FFXIVMINION##MENU_HEADER")
ml_gui.ui_mgr:AddSubMember({ id = "FFXIVMINION##DEV_1", name = "DevA", onClick = function() Dev.GUI.open = not Dev.GUI.open end, tooltip = "Open the Dev monitor."},"FFXIVMINION##MENU_HEADER","FFXIVMINION##MENU_DEV5")
ml_gui.ui_mgr:AddSubMember({ id = "FFXIVMINION##DEV_2", name = "DevE", onClick = function() Dev.GUI.open = not Dev.GUI.open end, tooltip = "Open the Dev monitor."},"FFXIVMINION##MENU_HEADER","FFXIVMINION##MENU_DEV5")
ml_gui.ui_mgr:AddSubMember({ id = "FFXIVMINION##DEV_3", name = "DevM", onClick = function() Dev.GUI.open = not Dev.GUI.open end, tooltip = "Open the Dev monitor."},"FFXIVMINION##MENU_HEADER","FFXIVMINION##MENU_DEV5")
ml_gui.ui_mgr:AddSubMember({ id = "FFXIVMINION##DEV_4", name = "DevC", onClick = function() Dev.GUI.open = not Dev.GUI.open end, tooltip = "Open the Dev monitor."},"FFXIVMINION##MENU_HEADER","FFXIVMINION##MENU_DEV5")

Utility Functions

File I/O

For every I/O function, you need to use double dashes! Example: FolderExists(“c:\\minionapp\\ILikeBeer\\Folder”)

  • GetStartupPath()
    • Returns string, filepath to the root bot folder
  • GetLuaModsPath()
    • Returns string, filepath to the ..MinionApp/Bots/xxxx/LuaMods folder, where all Lua addon folders are
  • FileExists(string fullpathtofile)
    • Returns bool
  • FileLoad(string fullpathtofile)
    • Returns variant , loads a file which was saved before with FileSave
  • FileSave(string fullpathtofile, variant data)
    • Returns bool , can take in a luatable, will save the whole table structure in a “human readable file”
  • FileWrite(string fullpathtofile, string data)
    • Returns bool , writes the string into the file.
  • FileWrite(string fullpathtofile, string data, bool arg)
    • Returns bool , writes the string into the file. If 3rd arg is true, it will add the data to the end of the file.
  • FileDelete(string fullpathtofile)
    • Returns bool
  • FolderExists(string fullpathtofolder)
    • Returns bool
  • FolderCreate(string fullpathtofolder)
    • Returns bool
  • FolderDelete(string fullpathtofolder)
    • Returns bool
  • FolderList(string fullpathtofolder, string pattern=““, bool includeFolders=false)
    • Where pattern is normal regex and should be put in double brackets in lua. Eg. [[(.*)lua$]]
    • Returns table with all files in that directory.
String

The following functions extend the default string from the lua library. Usage: string.contains(..)

  • contains(string arg, string arg2)
    • Returns bool, if arg2 was found in arg
  • empty(string arg)
    • Returns bool, if arg is type(string) and length is 0
  • ends(string arg, string arg2)
    • Returns bool, if arg ends with arg2
  • split(string arg, string seperator)
    • Returns iterator, seperates arg, Usage: for moochable in string.split(moochables, ”,”) do … end
  • starts(string arg, string arg2)
    • Returns bool, if arg starts with arg2
  • toboolean(string arg)
    • Returns bool
  • totable(string arg, string seperator)
    • Returns table, seperates arg
  • trim(string arg, int num)
    • Returns bool, trims arg by num characters
  • valid(string arg)
    • Returns bool, if arg is type(string)
  • starts(string str, string starts)
    • Returns bool, if the str begins with “starts”
  • ends(string str, string ends)
    • Returns bool, if the str ends with “ends”
  • hash(string arg)
    • Returns number, a md5 encoded number for the passed string
Table

The following functions extend the default table from the lua library. Usage: table.valid(..)

  • clear(table arg )
    • Sets all values in the table to nil.
  • contains(table table, value)
    • Returns bool if the value exists in the table
  • deepcopy(table arg, bool skipMetaTable )
    • Returns table, makes a deepcopy of the passed table. Pass “true” as 2nd arg to not duplicate the metatable.
  • deepcompare(table table1, table table2, bool ignore_metatable)
    • Returns bool, compares two tables if they are equal.
  • delete(table table, variant object)
    • Returns bool if the object was removed from the table
  • find(table table, value)
    • Returns number if the value exists in the table, it returns the key position, else nil
  • invert(table arg )
    • Returns table, flips a table so keys become values
  • merge(table table1, table table2, bool keepexistingentries)
    • Returns table1, merged with table 2. If keepexistingentries is not passed, all existing keys&values in table1 will be overwritten with the ones from table2, else the values of table2 are just inserted into table1.
  • pairsbykeys(table table1, function sort)
    • Returns iterator over the table which is default sorted by its keys. Optionally pass your custom sort function as 2nd arg. Usage: “for key,value in table.pairsbykeys(table) do..”
  • pairsbyvalue(table table1, function sort)
    • Returns iterator over the table which is default sorted by its values. Optionally pass your custom sort function as 2nd arg. Usage: “for key,value in table.pairsbyvalue(table) do..”
  • print(table arg )
    • Prints the table content line by line into the minion console.
  • randomvalue(table arg )
    • Returns a random value from the table.
  • shallowcopy(table arg )
    • Returns table
  • size(table arg )
    • Returns number, of elements the table contains. Returns 0 if the arg is no table.
  • valid(table arg )
    • Returns bool, if the passed arg is a valid table with at least 1 entry
Math

The following functions extend the default math from the lua library. Usage: math.distance3d(..)

  • angle(table heading1, table heading2)
    • Returns number, calculates the shortest angle between two headings ( 2x table with x,y,z ) Result is angle between 0 - 180 degree
  • approxequal(number num1, number num2)
    • Returns bool
  • crossproduct(table pos1, table pos2)
    • Returns table
  • distance2d(number x, number y, number x1, number y1)
    • Returns number
  • distance3d(table pos1, table pos2)
    • Returns number
  • distance3d(number x, number y, number z, number x1, number y1, number z1)
    • Returns number
  • distancepointline(table p1, table p2, table p3)
    • Returns number, takes in 3 points, first two are the “line” defining points, last one is the point we want to get the distance to that line from
  • magnitude(table pos)
    • Returns number
  • round(number num, integer decimals)
    • Returns number
  • randomize(integer int)
    • Returns integer , takes in a percentage from 0-100 and gives back a random number “near” that value
General
  • d(…)
    • Prints our the passed variable or the result of a function into the console.
  • Exit()
    • Closes the current game instance
  • ml_debug( string str )
    • Prints our the passed variable or the result of a function into the console when gEnableLog == “1”.
  • ml_error( string str )
    • Prints our the passed variable or the result of a function into the console.
  • ml_log( string str )
    • Adds the string to the statusbar-line which gets shown on each pulse.
  • Now()
    • Returns tickcount from ml_global_information.Now
  • RegisterEventHandler(string eventtoregisterfor,function handler)
    • Registers a local handler to an event
  • Reload()
    • Returns bool , reloads all lua modules
  • TimeSince(integer previousTime)
    • Returns integer ml_global_information.Now - previousTime
  • Unload()
    • Returns bool , tries to unload the bot
  • QueueEvent( string eventname, string args, …)
    • Queues and Fires the Event with 1-n arguments. Eventname and arguments need to be strings.
    • Use RegisterEventHandler(“eventname”, handlerfunc) , to register a lua function which will handle the fired event.
  • PathDistance(table posTable)
    • Returns number distance, usage: PathDistance(NavigationManager:GetPath(myPos.x,myPos.y,myPos.z,p.x,p.y,p.z))
minionlib.1523983708.txt.gz · Last modified: 2018/04/17 16:48 by fxfire