Class mct_option
MCT Option Object
Methods
mct_option:new (mod, option_key, type) | For internal use only. |
mct_option:get_local_only () | Read whether this mct_option is edited exclusively for the client, instead of passed between both PC's. |
mct_option:set_local_only (enabled) | Set whether this mct_option is edited for just the local PC, or sent to both PC's. |
mct_option:get_mp_disabled () | Read whether this mct_option is available in multiplayer. |
mct_option:set_mp_disabled (enabled) | Set whether this mct_option exists for MP campaigns. |
mct_option:get_read_only () | Read whether this mct_option can be edited or not at the moment. |
mct_option:set_read_only (enabled) | Set whether this mct_option can be edited or not at the moment. |
mct_option:set_assigned_section (section_key) | Assigns the section_key that this option is a member of. |
mct_option:get_assigned_section () | Reads the assigned_section for this option. |
mct_option:get_mod () | Get the mct_mod object housing this option. |
mct_option:clear_uics (kill_selected) | Internal use only. |
mct_option:set_uics (uic_obj) | Internal use only. |
mct_option:set_uic_with_key (key, uic, force_override) | Add a UIC to this mctoption with supplied key (doesn't have to be the UIC ID) Easily grab the UIC with getuicwithkey. |
mct_option:get_uics () | Internal use only. |
mct_option:set_uic_visibility (visibility, keep_in_ui) | Set a UIC as visible or invisible, dynamically. |
mct_option:get_uic_visibility () | Get the current visibility for this mct_option. |
mct_option:get_border_image_path () | Getter for the image path for this mct_option's border. |
mct_option:set_border_image_path (border_path) | Setter for the image path. |
mct_option:set_border_visibility (is_visible) | Setter for the visibility for this mct_option's border. |
mct_option:get_border_visibility () | Get the current visibility for this mct_option's border. |
mct_option:add_option_set_callback (callback, is_context) | Create a callback triggered whenever this option's setting changes within the MCT UI. |
mct_option:set_selected_setting (val, is_creation) | Triggered via the UI object. |
mct_option:override_position (x, y) | Manually set the x/y position for this option, within its section. |
mct_option:get_position () | Get the x/y coordinates of the mct_option Returns two vals, comma delimited (ie. |
mct_option:get_wrapped_type () | Returns the underlying "wrapped_type" object. |
mct_option:is_val_valid_for_type (val) | Internal checker to see if the values passed through mct_option methods are valid. |
mct_option:check_validity (val) | Internal checker to see if the values passed through mct_option methods are valid. |
mct_option:set_default () | Sets an automatic default for this mct_option, if a modder didn't. |
mct_option:ui_select_value (val, is_new_version) | Internal function that calls the operation to change an option's selected value. |
mct_option:ui_change_state () | Internal function to set the option UIC as disabled or enabled, for read-only/mp-disabled. |
mct_option:ui_create_option (dummy_parent) | Creates the UI component in the UI. |
mct_option:slider_get_precise_value (...) | Slider-specific function. |
mct_option:slider_set_step_size (...) | Slider-specific function. |
mct_option:slider_set_precision (...) | Slider-specific function. |
mct_option:slider_set_min_max (...) | Slider-specific function. |
mct_option:add_dropdown_values (...) | Dropdown-specific function. |
mct_option:add_dropdown_value (...) | Dropdown-specific function. |
mct_option:refresh_dropdown_box () | Dropdown-specific function. |
mct_option:text_input_add_validity_test (...) | Text-input-specific function. |
mct_option:get_finalized_setting () | Getter for the "finalized_setting" for this mct_option. |
mct_option:set_finalized_setting (val, is_first_load) | Internal use only. |
mct_option:set_default_value (val) | Set the default setting when the mct_mod is first created and loaded. |
mct_option:get_default_value () | Getter for the default setting for this mct_option. |
mct_option:get_uic_locked () | Getter for whether this UIC is currently locked. |
mct_option:set_uic_locked (should_lock, lock_reason, is_localised) | Set this option as disabled in the UI, so the user can't interact with it. |
mct_option:get_selected_setting () | Getter for the current selected setting. |
mct_option:get_values () | Getter for the available values for this mct_option - true/false for checkboxes, different stuff for sliders/dropdowns/etc. |
mct_option:get_type () | Getter for this mct_option's type; slider, dropdown, checkbox |
mct_option:get_uic_template () | Getter for this option's UIC template for quick reference. |
mct_option:get_key () | Getter for this option's key. |
mct_option:set_text (text, is_localised) | Setter for this option's text, which displays next to the dropdown box/checkbox. |
mct_option:set_tooltip_text (text, is_localised) | Setter for this option's tooltip, which displays when hovering over the option or the text. |
mct_option:get_text () | Getter for this option's text. |
mct_option:get_tooltip_text () | Getter for this option's text. |
Methods
- mct_option:new (mod, option_key, type)
-
For internal use only. Called by mct_mod:add_new_option.
Parameters:
- mod mct_mod
- option_key string
- type string | "'slider'" | "'dropdown'" | "'checkbox'"
- mct_option:get_local_only ()
-
Read whether this mct_option is edited exclusively for the client, instead of passed between both PC's.
Returns:
-
boolean
local_only Whether this option is only edited on the local PC, instead of both.
- mct_option:set_local_only (enabled)
-
Set whether this mct_option is edited for just the local PC, or sent to both PC's.
For instance, this is useful for settings that don't edit the model, like enabling script logging.
Parameters:
- enabled boolean True for local-only, false for passed-in-MP-and-only-editable-by-the-host.
- mct_option:get_mp_disabled ()
-
Read whether this mct_option is available in multiplayer.
Returns:
-
boolean
mpdisabled Whether this mctoption is available in multiplayer or completely disabled.
- mct_option:set_mp_disabled (enabled)
-
Set whether this mct_option exists for MP campaigns.
If set to true, this option is invisible for MP and completely untracked by MCT.
Parameters:
- enabled boolean True for MP-disabled, false to MP-enabled
- mct_option:get_read_only ()
- Read whether this mctoption can be edited or not at the moment. -- @treturn boolean readonly Whether this option is uneditable or not.
- mct_option:set_read_only (enabled)
-
Set whether this mct_option can be edited or not at the moment.
Parameters:
- enabled boolean True for non-editable, false for editable.
- mct_option:set_assigned_section (section_key)
-
Assigns the section_key that this option is a member of.
Calls mct_section:assign_option internally.
Parameters:
- section_key string The key for the section this option is being added to.
- mct_option:get_assigned_section ()
-
Reads the assigned_section for this option.
Returns:
-
string
section_key The key of the section this option is assigned to.
- mct_option:get_mod ()
-
Get the mct_mod object housing this option.
Returns:
-
mct_mod mct_mod
- mct_option:clear_uics (kill_selected)
-
Internal use only. Clears all the UIC objects attached to this boy.
Parameters:
- kill_selected self.selectedsetting = nil
- mct_option:set_uics (uic_obj)
-
Internal use only. Set UICs through the uic_obj
k/v table of key=uic
Parameters:
- uic_obj check if it's a table of UIC's
- mct_option:set_uic_with_key (key, uic, force_override)
-
Add a UIC to this mctoption with supplied key (doesn't have to be the UIC ID)
Easily grab the UIC with getuicwithkey.
Parameters:
- key string The key to save this UIC as
- uic uicomponent The UIC to save locally.
- force_override boolean Whether this function will override an existing UIC with this key or skip it.
- mct_option:get_uics ()
- Internal use only. Get all UICs.
- mct_option:set_uic_visibility (visibility, keep_in_ui)
-
Set a UIC as visible or invisible, dynamically. If the UIC isn't created yet, it will get the applied setting when it is created.
Parameters:
- visibility boolean True for visible, false for invisible.
- keep_in_ui boolean This boolean determines whether this mct_option will exist at all in the UI. Tick this to true to make the option invisible but still have a "gap" in the UI where it would be placed. Set this to false to make that spot be taken by the next otion. ONLY AFFECTS INITIAL UI CREATION.
- mct_option:get_uic_visibility ()
-
Get the current visibility for this mct_option.
Returns:
-
boolean
visibility True for visible, false for invisible.
- mct_option:get_border_image_path ()
-
Getter for the image path for this mct_option's border.
Returns:
-
string
border_path The image path for the .png for the border.
- mct_option:set_border_image_path (border_path)
-
Setter for the image path. Provide the path from the base structure - ie., "ui/skins/default/panelbackborder.png" is the default image. Make sure to include the directory path and the .png!
Parameters:
- border_path string The image path for the border.
- mct_option:set_border_visibility (is_visible)
-
Setter for the visibility for this mct_option's border. Set this to false if you want to not have a border img around it!
Parameters:
- is_visible boolean True to set it visible, opposite for opposite.
- mct_option:get_border_visibility ()
-
Get the current visibility for this mct_option's border. Always true unless changed with mct_option:set_border_visibility.
Returns:
-
boolean
visibility True for visible, false for the opposite of that.
- mct_option:add_option_set_callback (callback, is_context)
-
Create a callback triggered whenever this option's setting changes within the MCT UI.
You can alternatively do this through core:addlistener(), using the "MctOptionSelectedSettingSet" event. The reason this callback is here, is for backwards compatibility.
The function will automatically be passed a context object (methods listed below) so you can read state of everything and go from there.
ex:
when the "enable" button is checked on or off, all other options are set visible or invisible
enable:addoptionsetcallback(
function(context) local option = context:option() local mct_mod = option:get_mod() local val = context:setting() local options = options_list for i = 1, #options do local i_option_key = options[i] local i_option = mct_mod:get_option_by_key(i_option_key) i_option:set_uic_visibility(val) end end
)
Parameters:
- callback
function
The callback triggered whenever this option is changed. Callback will be passed one argument - the
context
object for the listener.context:mct()
,context:option()
,context:setting()
, andcontext:is_creation()
(for if this was triggered on the UI being created) are the valid methods on context. - is_context boolean Set this to true if you want to treat this function with the new method of passing a context. If this is false or nil, it will pass the mct_option like before. For backwards compatibility - I'll probably take this out eventually.
- callback
function
The callback triggered whenever this option is changed. Callback will be passed one argument - the
- mct_option:set_selected_setting (val, is_creation)
-
Triggered via the UI object. Change the mct_option's selected value, and trigger the script event "MctOptionSelectedSettingSet". Can be listened through a listener, or by using mct_option:add_option_set_callback.
Parameters:
- val any Set the selected setting as the passed value, tested with mct_option:is_val_valid_for_type
- is_creation boolean Whether this is being set on the option's UI creation, or being set somewhere else.
- mct_option:override_position (x, y)
-
Manually set the x/y position for this option, within its section.
Parameters:
- x number x-coord
- y number y-coord
- mct_option:get_position ()
-
Get the x/y coordinates of the mctoption
Returns two vals, comma delimited (ie. local x,y = option:getposition())
Returns:
- number x x-coord
- number y y-coord
- mct_option:get_wrapped_type ()
- Returns the underlying "wrapped_type" object. Under no circumstances should a modder need to use this. Probably.
- mct_option:is_val_valid_for_type (val)
-
Internal checker to see if the values passed through mctoption methods are valid.
This remains because I renamed the function to "checkvalidity" but didn't want to ruin backwards compatibility.
Parameters:
- val any Value being tested for type.
Returns:
-
any
valid Returns true if valid; returns a valid default value if the one passed isn't valid.
- mct_option:check_validity (val)
-
Internal checker to see if the values passed through mct_option methods are valid.
Parameters:
- val any Value being tested for type.
Returns:
-
any
valid Returns true if valid; returns a valid default value if the one passed isn't valid.
- mct_option:set_default ()
- Sets an automatic default for this mctoption, if a modder didn't. Automatic default depends on the type of the mctoption; ie., booleans automatically default to false.
- mct_option:ui_select_value (val, is_new_version)
-
Internal function that calls the operation to change an option's selected value. Exposed here so it can be called through presets and the like. Use set_selected_setting instead, please!
Parameters:
- val any Set the selected setting as the passed value, tested with mct_option:is_val_valid_for_type
- is_new_version boolean Set this to true to skip calling mctoption:setselectedsetting from within. This is done to keep the mod backwards compatible with the last patch, where the Order of Operations went uiselect_value -> setselectedsetting; the new Order of Operations is the inverse.
See also:
- mct_option:ui_change_state ()
-
Internal function to set the option UIC as disabled or enabled, for read-only/mp-disabled.
Use
mct_option:set_uic_locked()
for the external version of this; this just reads the uic_locked boolean and changes the UI.See also:
- mct_option:ui_create_option (dummy_parent)
-
Creates the UI component in the UI. Shouldn't be used externally!
Parameters:
- dummy_parent uicomponent The parent component for the new option.
- mct_option:slider_get_precise_value (...)
-
Slider-specific function. Calls mct_slider:slider_get_precise_value.
Parameters:
- ...
- mct_option:slider_set_step_size (...)
-
Slider-specific function. Calls mct_slider:slider_set_step_size.
Parameters:
- ...
- mct_option:slider_set_precision (...)
-
Slider-specific function. Calls mct_slider:slider_set_precision.
Parameters:
- ...
- mct_option:slider_set_min_max (...)
-
Slider-specific function. Calls mct_slider:slider_set_min_max.
Parameters:
- ...
- mct_option:add_dropdown_values (...)
-
Dropdown-specific function. Calls mct_dropdown:add_dropdown_values
Parameters:
- ...
- mct_option:add_dropdown_value (...)
-
Dropdown-specific function. Calls mct_dropdown:add_dropdown_value
Parameters:
- ...
- mct_option:refresh_dropdown_box ()
- Dropdown-specific function. Calls mct_dropdown:refresh_dropdown_box
- mct_option:text_input_add_validity_test (...)
-
Text-input-specific function. Calls mct_text_input:add_validity_test
Parameters:
- ...
- mct_option:get_finalized_setting ()
-
Getter for the "finalized_setting" for this mct_option.
Returns:
-
any
finalized_setting Finalized setting for this mct_option - either the default value set via mct_option:set_default_value, or the latest saved value if in a campaign, or the latest mct_settings.lua - value if in a new campaign or in frontend.
- mct_option:set_finalized_setting (val, is_first_load)
-
Internal use only. Sets the finalized setting and triggers the event "MctOptionSettingFinalized".
Parameters:
- val any Set the finalized setting as the passed value, tested with mct_option:is_val_valid_for_type
- is_first_load boolean This is set to "true" for the first-load version of this function, when the mct_settings.lua file is loaded.
- mct_option:set_default_value (val)
-
Set the default setting when the mct_mod is first created and loaded. Also used for the "Revert to Defaults" option.
Parameters:
- val any Set the default setting as the passed value, tested with mct_option:is_val_valid_for_type
- mct_option:get_default_value ()
-
Getter for the default setting for this mct_option.
Returns:
-
any
The modder-set default value.
- mct_option:get_uic_locked ()
-
Getter for whether this UIC is currently locked.
Returns:
-
boolean uic_locked Whether the UIC is set as locked.
- mct_option:set_uic_locked (should_lock, lock_reason, is_localised)
-
Set this option as disabled in the UI, so the user can't interact with it.
This will result in
mct_option:ui_change_state()
being called later on.Parameters:
- should_lock boolean Lock this UI option, preventing it from being interacted with.
- lock_reason string The text to supply to the tooltip, to show the player why this is locked. This argument is ignored if should_lock is false.
- is_localised boolean Set to true if lock_reason is a localised key; else, set it to false or leave it blank. Ignored ditto above.
- mct_option:get_selected_setting ()
-
Getter for the current selected setting. This is the value set in mct_option:set_default_value if nothing has been selected yet in the UI.
Used when finalizing settings.
Returns:
-
any
val The value set as the selectedsetting for this mctoption.
- mct_option:get_values ()
- Getter for the available values for this mct_option - true/false for checkboxes, different stuff for sliders/dropdowns/etc.
- mct_option:get_type ()
- Getter for this mct_option's type; slider, dropdown, checkbox
- mct_option:get_uic_template ()
- Getter for this option's UIC template for quick reference.
- mct_option:get_key ()
-
Getter for this option's key.
Returns:
-
string
key mct_option's unique identifier
- mct_option:set_text (text, is_localised)
-
Setter for this option's text, which displays next to the dropdown box/checkbox.
MCT will automatically read for text if there's a loc key with the format
mct_[mct_mod_key]_[mct_option_key]_text
.Parameters:
- text
string
The text string for this option. You can either supply hard text - ie., "My Cool Option" - or a loc key - ie., "
ui_text_replacements_my_cool_option
". - is_localised boolean True if a loc key was supplied for the text parameter.
- text
string
The text string for this option. You can either supply hard text - ie., "My Cool Option" - or a loc key - ie., "
- mct_option:set_tooltip_text (text, is_localised)
-
Setter for this option's tooltip, which displays when hovering over the option or the text.
MCT will automatically read for text if there's a loc key with the format
mct_[mct_mod_key]_[mct_option_key]_tooltip
.Parameters:
- text
string
The tootlip string for this option. You can either supply hard text - ie., "My Cool Option's Tooltip" - or a loc key - ie., "
ui_text_replacements_my_cool_option_tt
". - is_localised boolean True if a loc key was supplied for the text parameter.
- text
string
The tootlip string for this option. You can either supply hard text - ie., "My Cool Option's Tooltip" - or a loc key - ie., "
- mct_option:get_text ()
-
Getter for this option's text. Will read the loc key,
mct_[mct_mod_key]_[mct_option_key]_text
, before seeing if any was supplied through mct_option:set_text. - mct_option:get_tooltip_text ()
-
Getter for this option's text. Will read the loc key,
mct_[mct_mod_key]_[mct_option_key]_tooltip
, before seeing if any was supplied through mct_option:set_tooltip_text.