Skip to content

Function Documentation

offyerrocker edited this page Jun 28, 2020 · 7 revisions

Functions

new()

RadialMouseMenu:new(params,callback)

Used to create a new RadialMouseMenu object.

new() takes constructor arguments, which are fed to init(). In other words, you should always add arguments for your custom RadialMouseMenu object when constructing it, unless you want to use purely default appearance settings.

Multiple RadialMouseMenu objects can be created with this method, and are stored and controlled separately, as separate instances; however, due to the nature of the control/input scheme, only one should ever be active (visible + interact-able) at any given time.

Argument params: type table. Describes parameters with which to construct this RadialMouseMenu object.

Argument callback: type function. Used as a "setter"- in case of delayed menu creation, this callback function is called when the menu is successfully completed.

Example:

local items = {
	{
		name = "use ladder",
		icon = {
			texture = tweak_data.hud_icons.pd2_ladder.texture,
			texture_rect = tweak_data.hud_icons.pd2_ladder.texture_rect,
			layer = 3,
			w = 16,
			h = 16,
			alpha = 0.7,
			color = Color.purple
		},
		stays_open = true,
		callback = callback(Console,Console,"cmd_say","ladder? i 'ardly even know 'er!")
	},
	{
		name = "drink soda",
		icon = {
			texture = tweak_data.hud_icons.equipment_soda.texture,
			texture_rect = tweak_data.hud_icons.equipment_soda.texture_rect,
			layer = 3,
			w = 16,
			h = 16,
			alpha = 0.7,
			color = Color(0.9,0.1,0.1)
		},
		stays_open = true,
		callback = callback(Console,Console,"cmd_say","refreshing!")
	}
}
local params = {
	name = "1",
	radius = 200,
	items = items
}
myNewRMenu = RadialMouseMenu:new(params)

Please refer to the [Basic Tutorial] for an example and explanation of using the callback parameter in case of delayed menu creation.

Show()

RadialMouseMenu:Show()

Activates and visually displays the calling RadialMouseMenu object. This will lock mouse and keyboard input until this menu object is closed. (The notable exception is that BLT Keybinds will continue to run, as they operate on a different level from the rest of the game's input.)

Hide()

RadialMouseMenu:Hide()

De-activates and visually hides the calling RadialMouseMenu object. This will release mouse and keyboard input. Hide() is called by default when any item in the RadialMouseMenu object is clicked on, unless that item has the value stays_open set to true.

Toggle()

RadialMouseMenu:Toggle(state)

argument state: type boolean. If state is nil, then the menu's visibility is inverted. If state is not nil, the menu's visibility is set to that value.

Either way, Show() or Hide() is called accordingly.

active()

RadialMouseMenu:active()

Returns boolean: _active Used to determine whether or not the calling RadialMouseMenu object is currently visible and intercepting keyboard/mouse input.

add_item(data)

RadialMouseObject:add_item(data)

Argument data: type table. See [Usage] for a more detailed example. add_item() is used to create one selectable option for your RadialMouseMenu object. As items in RadialMouseMenu use several Panel type UI objects, it is recommended to use this if you want greater control over what is displayed for your menu, and how it is displayed (eg. any uncommon panel options such as render templates, or even simple things like color). Please note that name, x, and y values are calculated independently by RadialMouseMenu, so you should not bother adding them for individual elements inside your item, other than your item's main name itself.

create_item(data)

RadialMouseMenu:create_item(data)

Argument data: type table. See [Usage] for a more detailed example.

Where add_item() is used for the thorough and absolute description of an item, create_item() should be used when you want an item with mostly default values (size, width, alpha, layer), but with some custom values of your own.

Newly created items are automatically added to the RadialMouseMenu object; no value is returned.

create_item() operates on a "whitelist" basis: that is, only certain parameters from your data argument are allowed; the rest are discarded. If you are a more advanced Lua user, you should use add_item().

get_item()

RadialMouseMenu:get_item(index)

Argument index: type integer. Returns the item data (table) of the indicated index.

reset_items()

RadialMouseMenu:reset_items()

Removes all items' UI Panels from your RadialMouseMenu object. However, your items' original data is untouched. This is useful if you need to dynamically change individual attributes of an item after the menu is loaded or used, and update your menu object.

clear_items()

RadialMouseMenu:clear_items()

Removes all items' UI panels from your RadialMouseMenu object, as well as removing all of the selectable items within that object.

populate_items()

RadialMouseMenu:populate_items()

Reads the item data within your RadialMouseMenu object and creates and aligns its UI objects accordingly. This is called once automatically, during init(). If you need to make changes to your RadialMouseMenu object after you have created it, you will need to call this function again in order for any visual changes to take place. In such a case, it is recommended to use clear_items() beforehand.

Clone this wiki locally